vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Create New Thread with Non-vB Script (https://vborg.vbsupport.ru/showthread.php?t=207400)

myHybridcar.com 03-05-2009 04:17 AM

Create New Thread with Non-vB Script
 
I'd like to be able to create a new thread in a specific forum using a non-vB script (though I'd be logged in). What would I need as the necessary code to insert a new post/thread into the database using vB's built-in functions?

Thanks.

Dismounted 03-05-2009 04:34 AM

You can use the vBulletin Data Managers to insert/edit thread data. Some documentation can be found in the manual, as well as from articles that exist.

myHybridcar.com 03-05-2009 04:28 PM

Okay, thanks. I think I'm 90% there. The following code works when it's on its own page, but when I include it in the rest of my script I get the following error:
Quote:

Fatal error: Database object is not an object in [path]/includes/class_dm.php on line 172
Do you know why this might be happening?
PHP Code:

error_reporting(E_ALL & ~E_NOTICE); 

        require_once(
'/home/myhybrid/www/forums/includes/functions_misc.php');
        require_once(
'/home/myhybrid/www/forums/includes/class_dm.php');
        require_once(
'/home/myhybrid/www/forums/includes/class_dm_threadpost.php');

        
$forumid=36;
        
$vb_username=$vbulletin->userinfo['username'];
        
$body='body';
        
        global 
$botpermissons$vbphrase;
        
$userinfo=fetch_userinfo($vb_uid);
        
$threadinfo=array(); 
        
$foruminfo=fetch_foruminfo($forumid); 
        
$threaddm=new vB_DataManager_Thread_FirstPost($vbulletinERRTYPE_STANDARD); 
        
$threaddm->set_info('forum'$foruminfo); 
        
$threaddm->set('forumid'$forumid);
        
$threaddm->set('userid'1); 
        
$threaddm->set('title'$name); 
        
$threaddm->set('pagetext'$body);  
        
$threaddm->set('open'1); 
        
$threaddm->set('allowsmilie'1); 
        
$threaddm->set('visible'1); 
        
$threaddm->pre_save(); 
        
$threadid $threaddm->save(); 
        unset(
$threaddm); 


Dismounted 03-06-2009 04:01 AM

You need to include vBulletin's global.php for the code to work. Also, you should use datamanager_init() to instantiate DMs.

myHybridcar.com 03-06-2009 04:04 PM

global.php is included earlier in the script. Interestingly, on my test page without global.php, it worked.

This time I added the following:
PHP Code:

$classtype='Thread_FirstPost';
        
datamanager_init($classtype, &$vbulletin$errtype ERRTYPE_STANDARD$forcefile ''); 

and got the following error:
Quote:

Warning: require_once([path]/includes/class_dm_thread_firstpost.php) [function.require-once]: failed to open stream: No such file or directory in [path]/includes/functions.php on line 118
Why does it say "[path]" rather than the directory? (I'm not in the forums directory but can chdir() if need be.)

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

Okay, I had a little progress by changing $classtype to ThreadPost. Now I'm getting the following.
Quote:

Fatal error: Direct Instantiation of vB_DataManager_ThreadPost class prohibited. in [path]/includes/class_dm_threadpost.php on line 54

Dismounted 03-07-2009 10:26 AM

PHP Code:

$threaddm =& datamanager_init('Thread_FirstPost', &$vbulletinERRTYPE_ARRAY'threadpost'); 


myHybridcar.com 03-07-2009 02:52 PM

*Sigh*
Quote:

Fatal error: Database object is not an object in [path]/includes/class_dm.php on line 172
PHP Code:

error_reporting(E_ALL & ~E_NOTICE); 

        require_once(
'/home/myhybrid/www/forums/includes/functions_misc.php');
        require_once(
'/home/myhybrid/www/forums/includes/class_dm.php');
        require_once(
'/home/myhybrid/www/forums/includes/class_dm_threadpost.php');
        
        
$threaddm =& datamanager_init('Thread_FirstPost', &$vbulletinERRTYPE_ARRAY'threadpost'); 

        
$forumid=36;
        
$vb_username=$vbulletin->userinfo['username'];
        
$body="Comments for $vb_username\'s $year $make $model, <a href=\'/fueleconomy/view_car.php?cid=$cid\'>\"$name\"</a>.";
        
        global 
$botpermissons$vbphrase;
        
$userinfo=fetch_userinfo($vb_uid);
        
$threadinfo=array(); 
        
$foruminfo=fetch_foruminfo($forumid); 
        
$threaddm=new vB_DataManager_Thread_FirstPost($vbulletinERRTYPE_STANDARD); 
        
$threaddm->set_info('forum'$foruminfo); 
        
$threaddm->set('forumid'$forumid);
        
$threaddm->set('userid'1); 
        
$threaddm->set('title'$name); 
        
$threaddm->set('pagetext'$body);  
        
$threaddm->set('open'1); 
        
$threaddm->set('allowsmilie'1); 
        
$threaddm->set('visible'1); 
        
$threaddm->pre_save(); 
        
$threadid $threaddm->save(); 
        unset(
$threaddm); 


Dismounted 03-08-2009 04:48 AM

And $vbulletin exists in its form generated by global.php?

myHybridcar.com 03-08-2009 05:29 AM

Yes, the following is at the top of the script.
PHP Code:

$cwd=getcwd();
chdir ('/home/myhybrid/www/forums/');
require_once(
'./global.php');
chdir ($cwd); 

and I use the following variable just fine.
PHP Code:

$vbulletin->userinfo['userid'


Dismounted 03-08-2009 10:33 AM

Paste the output of this (add it above your data manager call):
PHP Code:

print_r($vbulletin);
exit; 



All times are GMT. The time now is 07:12 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.01318 seconds
  • Memory Usage 1,772KB
  • 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
  • (7)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