vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   New Forum via PHP, however.... Need help (https://vborg.vbsupport.ru/showthread.php?t=316800)

Medi0cr3 01-20-2015 06:14 PM

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.

kh99 01-20-2015 06:47 PM

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.

bridge2heyday 01-20-2015 07:41 PM

PHP Code:

$vbulletin->forumcache 

is pulled from datastore ..
You should run function
PHP Code:

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

Quote:

Originally Posted by kh99 (Post 2533583)
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 (Post 2533591)
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 (Post 2533661)
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.

kh99 01-21-2015 10:10 AM

Quote:

Originally Posted by Medi0cr3 (Post 2533706)
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.

kh99 01-21-2015 10:24 AM

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();


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 [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.


All times are GMT. The time now is 04:02 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01042 seconds
  • Memory Usage 1,760KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (4)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete