My day-job requires me to create code that will talk to vBulletin web sites we run. My latest task involves taking data that we get from PA Sportsticker and create posts in one of our forums. Lucky for me, somebody smarter than me figured out how to do this. It's very simple, and I've taken their work and modified it for our needs.
-
<?php
-
-
/**
-
* Script that posts info sent to it by the Sportsticker parser as a thread in a forum
-
* Based on code found in http://www.vbulletin.org/forum/showthread.php?t=97283&page=2
-
*
-
* @author Chris Hartjes
-
*/
-
-
require './global.php';
-
require './includes/class_dm.php';
-
require './includes/class_dm_threadpost.php';
-
require './includes/functions_databuild.php';
-
-
$threaddm = new vB_DataManager_Thread_FirstPost($vbulletin, ERRTYPE_STANDARD);
-
$post_userid = 1; // Admin
-
$userid = 1;
-
$user_name = 'chartjes';
-
$allow_smilie = '1';
-
$visible = '1';
-
-
-
$threaddm->do_set('forumid', $forum_id);
-
$threaddm->do_set('postuserid', $post_userid);
-
$threaddm->do_set('userid', $userid);
-
$threaddm->do_set('username', $user_name);
-
$threaddm->do_set('posttext', $post_text);
-
$threaddm->do_set('title', $title);
-
$threaddm->do_set('allowsmilie', $allow_smilie);
-
$threaddm->do_set('visible', $visible);
-
$threaddm->save();
-
build_forum_counters($forum_id);
-
-
?>
I did see some talk abot how using that do_set method is not recommended as it bypasses the data manager object vBulletin uses. I tried using that datamanager by actually looking at the code that does posts, but couldn't get it to work. I suspect part of the problem is that the data manager assumes you are logged in, while you can post without being logged in with the method above. At least it sure looks that way. More testing is obviously required but I think I'm on the right track.
In a nutshell, the script that I wrote to parse the XML feed that Sportsticker provides will grab all the necessary info from the stream and then send that data to the above code via a POST request. Nice and simple. Hope this code sample helps.


Chris Hartjes' Blog: Tutorial: How to create a thread in vBulletin with a script
Hi all!
Very Interesting...
Thanks
Hey Chris,
do you know of any articles on how I could integrate CakePHP and vBulletin? I'm developing my main site with CakePHP 1.2 and I need the vBulletin to share the same userbase etc.
Thank you in advance!
@Nasko
I haven't seen any articles covering this, but I suspect it *can* be done but will be a lot of work. Sort of similar to the Drake (Drupal + Cake) and Jake (Joomla + Cake) projects. I guess a lot depends on what exact functionality you need from vBulletin in your Cake app
@Chris: Thank you for your quick reply!
Well, I don't need any common functionality. I even don't need either application to be wrapped by the other one's layout - I just need the forum to supplement the main website on a separate autonomous screen. User registration and login should be done via Cake actions and I think I couldn't do without programatically adding the users record in vBulletin's core user DB tables and setting the appropriate session and cookie variables that vBulletin would need to recognize a logged user.
I'm well aware that my comments may not be relevant for this post, the only reason I wrote here is because I spotted a common thing with programatically adding a thread and I was thinking similar about registration and log-in.
If you think this is way off-topic, feel free to remove my comments and I'd be happy to direct my inquiries to the CakePHP Google group (although I'm not hoping for any huge success in doing this, because I've searched the group messages and have only been able to find several inquiries similar to mine with hardly any follow ups).