View Full Version : Script to add thread?
DisasterDotCom
08-26-2014, 06:59 PM
Does anyone have a sample PHP script I can build off of that let's you add a thread? I'm not an advanced coder, but I can hack through a script once I have it to make it do what I need. I REALLY appreciate it. Thanks!
Dead Eddie
08-26-2014, 09:49 PM
From the script:
$result = array();
$textData = array(
'title' => $input['title'],
'parentid' => $input['parentid'],
'rawtext' => $input['text'],
'userid' => $user['userid'],
'authorname' => $user['username'],
'created' => $time,
'iconid' => $input['iconid'],
'prefixid' => $input['prefixid'],
'hvinput' => $input['hvinput'],
);
// sets publishdate
$textData += $this->getArticleInput();
if (!empty($_POST['setfor']))
{
$textData['setfor'] = intval($_POST['setfor']);
}
$options = array(
'facebook' => $this->getFacebookOptionsForAddNode(),
);
// We need to convert WYSIWYG html here and run the img check
if (isset($textData['rawtext']))
{
$tmpText = $api->callApi('bbcode', 'convertWysiwygTextToBbcode', array($textData['rawtext'], $options));
if (($phrase = vB5_Frontend_Controller_Bbcode::verifyImgCheck($tm pText)) !== true)
{
$results['error'] = $phrase;
$this->sendAsJson($results);
return;
}
}
$nodeId = $api->callApi('content_text', 'add', array($textData, $options));
$this->handleErrorsForAjax($result, $nodeId);
DisasterDotCom
08-28-2014, 02:58 AM
Thanks! I guess I was looking to see if anyone had a complete script, including the wrapper to allow the security access to do the post.
Dead Eddie
08-28-2014, 03:27 AM
including the wrapper to allow the security access to do the post.
Maybe it's late and I'm tired, but I'm not sure what you're looking for here.
Dead Eddie
09-01-2014, 02:38 AM
Here's basically the same thing being called from an internal script.
<?php
//stolen from index.php
define('VB_ENTRY', 1);
require_once('includes/vb5/autoloader.php');
vB5_Autoloader::register(dirname(__FILE__));
$app = vB5_Frontend_Application::init('config.php');
error_reporting(E_ALL | E_STRICT);
$config = vB5_Config::instance();
if (!$config->report_all_php_errors) {
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT));
}
$api = Api_InterfaceAbstract::instance();
$input = [
'title' => 'Posting through the API',
'rawtext' => 'My really cool API Post',
'nodeid' => 0,
'parentid' => 3,
'channelid' => 3,
'ret' => '',
'tags' => '',
'reason' => '',
'iconid' => '',
'prefixid' => '',
'hvinput' => '',
'subtype' => '',
'userid' => '1',
'username' => 'User',
];
$options = [];
$nodeId = $api->callApi('content_text', 'add', [$input, $options]);
if(!is_int($nodeId))
{
print_r($nodeId);
exit;
}
print 'Node '. $nodeId . ' created successfully';
This is still just an example of the frontend calling the API. Is this what you're looking for? Or are you trying to call it externally?
DisasterDotCom
09-08-2014, 02:11 AM
I'm trying to call it externally. Basically, I have a third party that wants to automatically post notifications to a specific forum on our site. These notifications will include a title and content, and will all be posted by the same user. I'd like them to post a JSON object to a script, and have that script post it into vBulletin.
Dead Eddie
09-13-2014, 11:17 AM
I don't *see* anything internal to the application that accepts a JSON request and converts it to something the API can consume.
That's not to say it's not there, I just haven't come across it.
So, you'd have to write your own code to accept the request & convert it from JSON to something the API can chew on if you wanted to go that route. If you do that, you'd likely have to manage security with them. Or, have them call the API in the traditional way.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.