ravel123
07-13-2011, 06:22 PM
Hi,
iam trying to use this code to create a thread via vBulletin cron job:
<?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', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
// Set some variable and information
$forumid = 7; // The id of the forum we are posting to
$userid = 1; // The user id of the person posting
$title = addslashes($_POST["test title bla bla test"]); // The title of the thread
$pagetext = addslashes($_POST["test content bla bla test 123 this is long enough"]); // 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_uni( fetch_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);
}
?>
It always return that the message is too short. I has to be at least 10 characters long.
Exact error message (in german): "array(2) { [0]=> string(110) "Der Text, den du eingegeben hast, ist zu kurz. Bitte erweitere den Text auf die minimale L?nge von 10 Zeichen." [1]=> string(49) "Bitte f?lle das Titel- und das Nachrichtfeld aus." } "
What am I doing wrong?
Edit: I would like to create a query to my database in this script with "$db->query_first" but there is no $db-object so i get an error. can i get the db-object from vbulletin somehow?
Thanks in advance
iam trying to use this code to create a thread via vBulletin cron job:
<?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', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
// Set some variable and information
$forumid = 7; // The id of the forum we are posting to
$userid = 1; // The user id of the person posting
$title = addslashes($_POST["test title bla bla test"]); // The title of the thread
$pagetext = addslashes($_POST["test content bla bla test 123 this is long enough"]); // 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_uni( fetch_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);
}
?>
It always return that the message is too short. I has to be at least 10 characters long.
Exact error message (in german): "array(2) { [0]=> string(110) "Der Text, den du eingegeben hast, ist zu kurz. Bitte erweitere den Text auf die minimale L?nge von 10 Zeichen." [1]=> string(49) "Bitte f?lle das Titel- und das Nachrichtfeld aus." } "
What am I doing wrong?
Edit: I would like to create a query to my database in this script with "$db->query_first" but there is no $db-object so i get an error. can i get the db-object from vbulletin somehow?
Thanks in advance