Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Creating a New Thread using vBulletins API
megamoose's Avatar
megamoose
Join Date: Feb 2007
Posts: 19

 

Northern Ireland
Show Printable Version Email this Page Subscription
megamoose megamoose is offline 12-05-2009, 10:00 PM

I really hope this will help some of you, as I spent ages searching the Internet tring to find something to do this, and ended up having to write my own.

This basically does exactly what the title says. It creates a new thread in a forum on your vbulletin forum.

It works for me in the latest version of vBulletin, but I'm not sure how far back it will work. But you should have your vBulletin up to date anyway.

If you notice any bugs/problems or anything I have done wrong, please correct me.

PHP Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # Create a new thread                                              # ||
|| # ---------------------------------------------------------------- # ||
|| # Hopefully this will help some of you people who are needing to   # ||
|| # create a new thread externally using vBulletins API. Good luck!  # ||
|| #################################################################### ||
\*======================================================================*/

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE & ~8192);

// Include vBulletin runtime files
require_once('./global.php');
require_once(
'./includes/functions_databuild.php');

// Create a new datamanager for posting
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');

// Set some variable and information
$forumid 43;                                                                  // The id of the forum we are posting to
$userid 125500;                                                                 // The user id of the person posting
$title addslashes($_POST["title"]);                                           // The title of the thread
$pagetext addslashes($_POST["content"]);                                      // The content of the thread
$allowsmilie '1';                                                             // Are we allowing smilies in our post
$visible '1';                                                                 // If the post visible (ie, moderated or not)

// Parse, retrieve and process the information we need to post
$foruminfo fetch_foruminfo($forumid);
$threadinfo = array();
$user htmlspecialchars_unifetch_userinfo($userid) );

$threaddm->set_info('forum'$foruminfo);
$threaddm->set_info('thread'$threadinfo);
$threaddm->setr('forumid'$forumid);
$threaddm->setr('userid'$userid);
$threaddm->setr('pagetext'$pagetext);
$threaddm->setr('title'$title);
$threaddm->set('allowsmilie'$allowsmilie);
$threaddm->set('visible'$visible);

// Lets see what happens if we save the page
$threaddm->pre_save();
if(
count($threaddm->errors) < 1) {
    
// Basically if the page will save without errors then let do it for real this time
    
$threadid $threaddm->save();
    unset(
$threaddm);
} else {
    
// There was errors in the practice run, so lets display them
    
var_dump ($threaddm->errors);
}

?>
Thanks to ragtek for the revised code!
Reply With Quote
  #12  
Old 04-21-2010, 05:05 PM
Digma Digma is offline
 
Join Date: Nov 2004
Location: Netherlands
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there a way to add:
1. The signature of the 'set' poster?
2. a Prefix to a title?
Reply With Quote
  #13  
Old 05-20-2010, 02:54 PM
pein87's Avatar
pein87 pein87 is offline
 
Join Date: Sep 2008
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

works perfectly
thanks a bunch

/gibigbig
Reply With Quote
  #14  
Old 05-20-2010, 02:56 PM
Brandon Sheley's Avatar
Brandon Sheley Brandon Sheley is offline
 
Join Date: Mar 2005
Location: Google Kansas
Posts: 4,678
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks for this, now to think of how I can use it
Reply With Quote
  #15  
Old 10-24-2010, 01:45 PM
kesandal kesandal is offline
 
Join Date: Oct 2010
Posts: 36
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there a way to have the code outside of the vB-directory?

e.g.

[root]
_[non-public]
___create_thread_external.php
_[folder1]
_[folder2]
_[vB]

I've tried to change thoose two lines:

PHP Code:
require_once('../vB/global.php'); 
require_once(
'../vB/includes/functions_databuild.php'); 
The result:
PHP Code:
Warning: require(./includes/class_bootstrap.php) [function.require]: failed to open streamNo such file or directory in /home/x/public_html/d/vB/global.php on line 15

Warning
: require(./includes/class_bootstrap.php) [function.require]: failed to open streamNo such file or directory in /home/x/public_html/d/vB/global.php on line 15

Fatal error
: require() [function.require]: Failed opening required './includes/class_bootstrap.php' (include_path='.:/usr/lib/php:/usr/local/lib/php'in /home/x/public_html/d/vB/global.php on line 15 
Any ideas?
Thansk in advance

Kesandal


Edit
I could fix the problem.

For thoose who are getting the same problem;
Just add thoose few lines above your page:

PHP Code:
$curdir getcwd (); 
chdir('../path_to_your_board/'); 
require_once(
'../path_to_your_board/global.php'); 
chdir ($curdir); 
Reply With Quote
  #16  
Old 10-27-2010, 03:02 PM
FortressGamers FortressGamers is offline
 
Join Date: Oct 2010
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry to bump an old thread....

is addslashes() for title & content necessary? I'm just curious if it's redundant. When I use the above, in my posts I get slashes along with my quotes

Thanks!
Reply With Quote
  #17  
Old 11-12-2010, 10:26 AM
leitel leitel is offline
 
Join Date: Mar 2003
Location: Costa Rica
Posts: 118
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can a similar approach be used to create CMS articles in 4+?
Reply With Quote
  #18  
Old 12-15-2010, 09:40 PM
squishi squishi is offline
 
Join Date: May 2006
Location: Frankfurt
Posts: 282
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much for this thread. Worked perfectly.
Reply With Quote
  #19  
Old 04-18-2011, 08:41 AM
kesandal kesandal is offline
 
Join Date: Oct 2010
Posts: 36
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by leitel View Post
Can a similar approach be used to create CMS articles in 4+?
same question here..
Reply With Quote
  #20  
Old 01-16-2012, 05:33 AM
4x4 Mecca 4x4 Mecca is offline
 
Join Date: Feb 2007
Posts: 396
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks! You helped me a ton!
Reply With Quote
  #21  
Old 04-17-2012, 08:39 AM
qos qos is offline
 
Join Date: Apr 2012
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i try it on version 4.1.12 and it create new thread, so it works on 4+.
thx for the script
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 03:23 AM.


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.08505 seconds
  • Memory Usage 2,331KB
  • Queries Executed 25 (?)
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
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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_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