Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2015, 06:14 PM
Medi0cr3 Medi0cr3 is offline
 
Join Date: Aug 2014
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default New Forum via PHP, however.... Need help

I'm able to add a row to the "forum" table via PHP, however the newly created database entry for the forum only actually shows up anywhere in the forum and in the admin control panel is if you are in Forum Management And you click "save display order".

Does anybody know if there is another table that needs an entry or is it a data manager issue?
There has to be a way to do it.

Any help would be appreciated.
Reply With Quote
  #2  
Old 01-20-2015, 06:47 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you're doing your add in a plugin or a custom page using vbulletin code, then you should use the forum datamanager (in includes/class_dm_forum.php). You can see how to use it in by looking in admincp/forum.php, the section that starts with:
Code:
// ###################### Start update #######################
if ($_POST['do'] == 'update')

I don't know the answer to your question offhand, but looking at that code a little bit and when the datamanager saves a forum it calls build_forum_permissions() in includes/adminfunctions.php, and I believe that also rebuilds the forumcache, which is probably your problem. If you can't include the vbulletin code so that you can use those fucntions, then you might want to look in there and see what it's doing.
Reply With Quote
  #3  
Old 01-20-2015, 07:41 PM
bridge2heyday's Avatar
bridge2heyday bridge2heyday is offline
 
Join Date: Aug 2014
Location: Egypt
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$vbulletin->forumcache 
is pulled from datastore ..
You should run function
PHP Code:
build_forum_permissions() 
after your query to update datastore
Reply With Quote
  #4  
Old 01-20-2015, 08:56 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can I ask what your plans are? Adding forums/tables directly via the database isn't ideal.
Reply With Quote
  #5  
Old 01-21-2015, 01:15 AM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah I don't get it, if you want to add forums, why not just use the forum manager?
Reply With Quote
  #6  
Old 01-21-2015, 09:04 AM
Medi0cr3 Medi0cr3 is offline
 
Join Date: Aug 2014
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
If you're doing your add in a plugin or a custom page using vbulletin code, then you should use the forum datamanager (in includes/class_dm_forum.php). You can see how to use it in by looking in admincp/forum.php, the section that starts with:
Code:
// ###################### Start update #######################
if ($_POST['do'] == 'update')

I don't know the answer to your question offhand, but looking at that code a little bit and when the datamanager saves a forum it calls build_forum_permissions() in includes/adminfunctions.php, and I believe that also rebuilds the forumcache, which is probably your problem. If you can't include the vbulletin code so that you can use those fucntions, then you might want to look in there and see what it's doing.
Thanks kh99,
The I saw the do:update thing last night as I was cruisin through the code. I'm just not sure how to supply information to the datamanager and haven't yet tried to utilize it via PHP only. It looks like it should be included in my custom page and then supplied the do=update (however I am going to guess that update is an array with all the data I want in it.) This is just a theory right now and I've got a lack of knowledge basis of how to interact with the datamanager to do a practical test. Looking at class_dm_forum.php I see how its done, but still not sure how to interact with the manager.


Quote:
Originally Posted by bridge2heyday View Post
PHP Code:
$vbulletin->forumcache 
is pulled from datastore ..
You should run function
PHP Code:
build_forum_permissions() 
after your query to update datastore
So after I do an INSERT INTO in the "forum" table, i should include adminfunctions.php and call build_forum_permissions() ??? Not quite sure where you are going with that.

Quote:
Originally Posted by ozzy47 View Post
Yeah I don't get it, if you want to add forums, why not just use the forum manager?
Ozzy, I have a custom coded page where I can add a "clan" and assign a usergroup ('leader') to that clan as well as have it automatically generate an X amount of forums and child forums for it. A lot less work and more automation means much more time spent elsewhere.
Reply With Quote
  #7  
Old 01-21-2015, 09:21 AM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Gotcha, sounds logical. Thanks for the explanation.
Reply With Quote
  #8  
Old 01-21-2015, 10:10 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Medi0cr3 View Post
Thanks kh99,
The I saw the do:update thing last night as I was cruisin through the code. I'm just not sure how to supply information to the datamanager and haven't yet tried to utilize it via PHP only. It looks like it should be included in my custom page and then supplied the do=update (however I am going to guess that update is an array with all the data I want in it.) This is just a theory right now and I've got a lack of knowledge basis of how to interact with the datamanager to do a practical test. Looking at class_dm_forum.php I see how its done, but still not sure how to interact with the manager..

You would do something like this:
Code:
	$forumdata =& datamanager_init('Forum', $vbulletin, ERRTYPE_SILENT);

        // set info with calls like
        // $forumdata->set_bitfield('options', $varname, $value); or
	// $forumdata->set($varname, $value);

	$forumid = $forumdata->save();

And that should take care of everything. For the info part, you would make multiple calls to $forumdata->set() or $forumdata->set_bitfield(), and of course what to use as $varname and $value is the question. You can find out by looking at the html for the form you fill out when creating a forum in the admincp. If a field is named like name="forum[displayorder]" that corresponds to
Code:
	$forumdata->set('displayorder', $value);

and if it's named like forum[options][moderatenewpost] then that corresponds to
Code:
        $forumdata->set_bitfield('options', 'moderatenewpost', $value);

The 'set' names probably correspond to database column names, so it's really the options that might be difficult to figure out.

Anyway, I hope that helps.
Reply With Quote
Благодарность от:
ozzy47
  #9  
Old 01-21-2015, 10:24 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, I went ahead and added a couple of lines to print out what gets set when you create a forum from the forum manager, so here's the complete code that should create a forum with the defaults:
Code:
$forumdata =& datamanager_init('Forum', $vbulletin, ERRTYPE_SILENT);

$forumdata->set(title, 'test forum');
$forumdata->set(description, 'This is a test');
$forumdata->set(link, '');
$forumdata->set(displayorder, 1);
$forumdata->set(parentid, -1);
$forumdata->set(daysprune, -1);
$forumdata->set(defaultsortfield, 'lastpost');
$forumdata->set(defaultsortorder, 'desc');
$forumdata->set(showprivate, 0);
$forumdata->set(newpostemail, '');
$forumdata->set(newthreademail, '');
$forumdata->set_bitfield('options', moderatenewpost, 0);
$forumdata->set_bitfield('options', moderatenewthread, 0);
$forumdata->set_bitfield('options', moderateattach, 0);
$forumdata->set_bitfield('options', styleoverride, 0);
$forumdata->set_bitfield('options', canhavepassword, 1);
$forumdata->set_bitfield('options', cancontainthreads, 1);
$forumdata->set_bitfield('options', active, 1);
$forumdata->set_bitfield('options', allowposting, 1);
$forumdata->set_bitfield('options', indexposts, 1);
$forumdata->set_bitfield('options', bypassdp, 0);
$forumdata->set_bitfield('options', allowhtml, 0);
$forumdata->set_bitfield('options', allowbbcode, 1);
$forumdata->set_bitfield('options', allowimages, 1);
$forumdata->set_bitfield('options', allowvideos, 1);
$forumdata->set_bitfield('options', allowsmilies, 1);
$forumdata->set_bitfield('options', allowicons, 1);
$forumdata->set_bitfield('options', allowratings, 1);
$forumdata->set_bitfield('options', countposts, 1);
$forumdata->set_bitfield('options', showonforumjump, 1);
$forumdata->set_bitfield('options', prefixrequired, 0);
$forumdata->set_bitfield('options', displaywrt, 1);
$forumdata->set_bitfield('options', canreputation, 1);
$forumdata->set(styleid, 0);
$forumdata->set(imageprefix, '');
$forumdata->set(password, '');

$forumid = $forumdata->save();
Reply With Quote
Благодарность от:
bridge2heyday
  #10  
Old 01-21-2015, 10:39 AM
Medi0cr3 Medi0cr3 is offline
 
Join Date: Aug 2014
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

sweet deal man. Much appreciation. The options actually wont be to much of a problem. I've figured out that the options column in the forum table are a bit when it is saved. So I made a forum with the options I wanted and I will be using that bit value.

I will try it out and post here my results, if any. haha

--------------- Added [DATE]1421845661[/DATE] at [TIME]1421845661[/TIME] ---------------

That's pretty nice of you KH99. One last thing I have a question about, what files do I need to include for that code.

here's what I have now, and I'm assuming:
admincp/forum.php as require_once('./admincp/forum.php');

Another thought... Is how do I overcome the fact that a login is required and ability to admin is requried.... Is there anything else I need to include so that it can look at session ID of the USER that is executing the script as such? this is all pretty new to me.

The datamanager looks like a pretty interesting way to input data to the forum.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:31 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04725 seconds
  • Memory Usage 2,284KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (2)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete