View Full Version : New Forum via PHP, however.... Need help
Medi0cr3
01-20-2015, 06:14 PM
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.
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:
// ###################### 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.
bridge2heyday
01-20-2015, 07:41 PM
$vbulletin->forumcache is pulled from datastore ..
You should run function build_forum_permissions() after your query to update datastore
Zachery
01-20-2015, 08:56 PM
Can I ask what your plans are? Adding forums/tables directly via the database isn't ideal.
ozzy47
01-21-2015, 01:15 AM
Yeah I don't get it, if you want to add forums, why not just use the forum manager?
Medi0cr3
01-21-2015, 09:04 AM
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:
// ###################### 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.
$vbulletin->forumcache is pulled from datastore ..
You should run function 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.
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.
ozzy47
01-21-2015, 09:21 AM
Gotcha, sounds logical. :) Thanks for the explanation.
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:
$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
$forumdata->set('displayorder', $value);
and if it's named like forum[options][moderatenewpost] then that corresponds to
$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.
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:
$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();
Medi0cr3
01-21-2015, 10:39 AM
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 1421845661 at 1421845661 ---------------
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.
Where did you put your code for creating a forum? If you are already including vbulletin's global.php, or if you are writing a plugin, then you probably don't have to explicitly include anything. If this is a custom script that doesn't include vbulletin's global.php then that's more of a problem. In that case it may turn out to be too difficult to use any vbulletin code since it mostly depends on having included global.php, which has a lot of overhead associate with it.
ETA: OK, I see you said above that you're creating a custom page. So if you're not already including vbulletin global.php then you'd have to think about adding it if you want to use the above code.
Medi0cr3
01-21-2015, 12:40 PM
I have made it practice to include global.php. There's a lot of usage I've done with that one included.
Fatal error: Call to undefined function can_administer() in /home/xxxxxxxxx/xxxxxxxx/forum/admincp/forum.php on line 31
http://pastebin.com/TrUkdZKE
This is a fully functional custom template and I'm logged in. This is close to the developed page. However, I would like to use it on a separate page for the Jquery function to send header requests to, due to my liking of Jquery.
You should not be including admincp/forum.php. If you're trying the code I posted above, try it without including anything (ETA: I mean anything more than you are already). The one thing you might need before that code, if your code is inside a function, is
global $vbulletin;
Medi0cr3
01-21-2015, 01:17 PM
It works great. I need to figure out how to edit it next haha.
I had to add the global variable and all is good.
Here's an example for others to follow if interested
<?php
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ############### CUSTOM TEMPLATE FOR YOUR USE ##########################
// ############### COMMENTED FOR READABILITY ##########################
// ############### IF YOU WANT THE AUTH FUNC ##########################
// ############### CONTACT ME ON THE VBULLETIN.ORG FORUM: Medi0cr3 ##########################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ################################################## #####################
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL);
ini_set("display_errors","true");
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'A_Atest'); //Not sure if using the extension is required. I utilze A_ in the filename for my php file as its easy to find in the /forum directory. Ex. "A_test"
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('Atest',); //Not totally required.. Style & Template -> Style Manager -> Edit/Add Custom Template -> Custom Template Name Must be This.
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');
require_once('A_p.php'); //I have database connection code here.
require_once('A_fnc.php'); // I keep all my functions here.
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
global $vbulletin;
$navbits = construct_navbits(array('' => 'Atest')); //Style & Template -> Style Manager -> Edit/Add Custom Template -> Custom Template Name Must be This.
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'Atest'; //I have an Authorization function that looks at usergroupids in the database and allows access based off that. If this name is not the same name as in the database, the code will not run.
$templateColor = 'silver'; //Main template text color.
// ########## START DATABASE CONNECTION ##############
if(!$con) { die("Database connection services failed connection: <font size='4'> $pagetitle</font> " . mysql_error()); }
mysql_select_db("xxxxxxxxxxxxxxx", $con) or die("Database selection name fail: <font size='4'> $pagetitle</font> " . mysql_error());
// ########## END DATABASE CONNECTION ##############
$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();
//########################### START AUTHORIZATION FUNCTION ###########################
//################################################## ##################################
//if $pagetitle var, up top, is not exactly what is in the database, it will not load the Authorization.
$usergroupfield = $vbulletin->userinfo[usergroupid]; //Gets the usergroupid before authorization function is ran.
$NavAuth = getAuth($pagetitle,$usergroupfield,$con); //Runs the Authorization function.
//################################################## ##################################
//################################################## ##################################
//********* END DATABASE CONNECTION ***************
mysql_close($con);
//********* END DATABASE CONNECTION ***************
$templater = vB_Template::create('Atest'); //Style & Template -> Style Manager -> Edit/Add Custom Template -> Custom Template Name Must be This.
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('NavAuth', $NavAuth);
$templater->register('templateColor', $templateColor);
//$template_hook[parse_templates] .= $templater->render();
print_output($templater->render());
?>
Zachery
01-21-2015, 03:10 PM
I figured you were trying to automate the creation of forums. Be aware that the system will start to break down around 2000 total forums + usergroups, in any combination. By break down, I mean have too much overhead for data to be processed reguarlly.
Medi0cr3
01-21-2015, 04:38 PM
I figured you were trying to automate the creation of forums. Be aware that the system will start to break down around 2000 total forums + usergroups, in any combination. By break down, I mean have too much overhead for data to be processed reguarlly.
Haha, Sounds great. I don't ever think I'll be that high up. However this is a pretty interesting project as I do a lot of other customized pages that apply and utilize things that people do in the fourm. So I might find a breaking point in something along the way. I'm glad that you're pointing that out now. Its a good fact.
*update: I'm still working on systematic stuff for the above code I pushed. I'm trying to figure out exactly what the minimum requirement of code of the "template". You'll see how I broke down a lot of it already. I would like to know break it down further to use the datamanager like I'm expecting to.
squidsk
01-21-2015, 06:19 PM
I figured you were trying to automate the creation of forums. Be aware that the system will start to break down around 2000 total forums + usergroups, in any combination. By break down, I mean have too much overhead for data to be processed reguarlly.
It's a forumcache issue, the forumcache as programmed into vb by default is horribly inefficient in that it loads the entire forumcache into memory (i.e. permissions for all groups for all forums) even if you only are looking at one forum for a small subset of groups. We ran into this bottleneck a while back and had to rewrite the forumcache to not have the massive overhead.
Medi0cr3
01-21-2015, 06:36 PM
Thanks for everybody's help on this. I know have a decent understanding of the datamanagers. And the overhead issue with the forumcache.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.