The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
![]()
Hi everyone, I'm currently trying to find a workaround to be able to create threads from an external website. The website is on the same server but it has another domain name. I've found a code in this forum (I cannot find the url) for creating a thread from an external form in VB3. This server has VB4 installed, so I took it as a base to do some testing.
Here is the code for the test page (which is the code provided in the thread I mentioned adapted to my needs): Code:
<?php // ####################### SET PHP ENVIRONMENT ########################### error_reporting(E_ALL & ~E_NOTICE & ~8192); // Include vBulletin runtime files chdir("../../foro/foro"); require_once('./global.php'); require_once('./includes/functions_databuild.php'); /* TEST - handle a new session $newsession = new vB_Session($vbulletin, '', 0, '', $vbulletin->session->vars['styleid']); $newsession->set('userid', 292); $newsession->set('loggedin', 1); $newsession->set_session_visibility(($vbulletin->superglobal_size['_COOKIE'] > 0)); $vbulletin->session =& $newsession; */ // Create a new datamanager for posting $threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost'); // Set some variable and information $forumid = 81; // The id of the forum we are posting to $userid = 292; // The user id of the person posting $title = addslashes($_POST["titulo"]); // The title of the thread $pagetext = addslashes($_POST["contenido"]); // 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); echo "Posteado correctamente"; } else { // There was errors in the practice run, so lets display them var_dump ($threaddm->errors); echo "Error"; } } ?> Fatal error: Call to undefined method stdClass::set() in <route here>/includes/functions.php on line 7344. The line which throws an error is the following in functions.php: Code:
$vbulletin->session->set('inforum', (!empty($foruminfo['forumid']) ? $foruminfo['forumid'] : 0)); class_core.php is called before functions.php, which makes sense, but somehow it is not working, so I have no way to know if this code works or not. Any ideas/suggestions? Thanks in advance! ---------------------------------------------------------------------- EDIT: Ok, after reading more threads and docs around there as I am outside of Vbulletin backend I need to define some constants first in order to make this work: Code:
define('VB_AREA', 'External'); define('SKIP_SESSIONCREATE', 1); define('SKIP_USERINFO', 1); ---------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------- Added [DATE]1303763119[/DATE] at [TIME]1303763119[/TIME] --------------- Ok, I've managed to do it, here is the right code: Code:
// Include vBulletin runtime files chdir("../../foro/foro"); // Move to where the forum is stored require_once('./global.php'); require_once('./includes/functions_databuild.php'); //=============SET ENVIRONMENT====================== error_reporting(E_ALL & ~E_NOTICE & ~8192); define('VB_AREA', 'External'); define('SKIP_SESSIONCREATE', 1); define('SKIP_USERINFO', 1); // Create a new datamanager for posting $threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost'); // Set some variable and information $forumid = 81; // The id of the forum we are posting to $userid = 292; // The user id of the person posting $title = addslashes($_POST["titulo"]); // The title of the thread $pagetext = addslashes($_POST["contenido"]); // 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->set('forumid', $forumid); $threaddm->set('userid', $userid); $threaddm->set('pagetext', $pagetext); $threaddm->set('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); echo "The thread was created succesfully"; } else { // There was errors in the practice run, so lets display them var_dump ($threaddm->errors); echo "Error! The thread couldn't be created"; } I leave this workaround for those who are interested. Hope it helps someone. This was the thread I got the code from: https://vborg.vbsupport.ru/showthread.php?t=229654. Thanks megamoose for creating it! It probed to be really helpful. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|