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

Reply
 
Thread Tools Display Modes
  #1  
Old 03-05-2009, 04:17 AM
myHybridcar.com myHybridcar.com is offline
 
Join Date: Feb 2009
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 03-05-2009, 04:34 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 03-05-2009, 04:28 PM
myHybridcar.com myHybridcar.com is offline
 
Join Date: Feb 2009
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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); 
Reply With Quote
  #4  
Old 03-06-2009, 04:01 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to include vBulletin's global.php for the code to work. Also, you should use datamanager_init() to instantiate DMs.
Reply With Quote
  #5  
Old 03-06-2009, 04:04 PM
myHybridcar.com myHybridcar.com is offline
 
Join Date: Feb 2009
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 03-07-2009, 10:26 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$threaddm =& datamanager_init('Thread_FirstPost', &$vbulletinERRTYPE_ARRAY'threadpost'); 
Reply With Quote
  #7  
Old 03-07-2009, 02:52 PM
myHybridcar.com myHybridcar.com is offline
 
Join Date: Feb 2009
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

*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); 
Reply With Quote
  #8  
Old 03-08-2009, 04:48 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And $vbulletin exists in its form generated by global.php?
Reply With Quote
  #9  
Old 03-08-2009, 05:29 AM
myHybridcar.com myHybridcar.com is offline
 
Join Date: Feb 2009
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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'
Reply With Quote
  #10  
Old 03-08-2009, 10:33 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Paste the output of this (add it above your data manager call):
PHP Code:
print_r($vbulletin);
exit; 
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:15 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.16785 seconds
  • Memory Usage 2,296KB
  • 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
  • (7)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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete