External post


Active member
From an external script how would I go about creating a thread with the initial post in it?

And the post would be in a forum where I (as the user) don't have access?

(A newly registered user will use an external script to answer a few questions and the results will be posted in the staff section of my forum)
Take a look at how it's done in: /library/XenForo/ControllerPublic/Forum.php

This method, in particular:
You can use the datawriter for this;)

I've created an Helper Class for my Add-ons which helps me creating users,threads,posts, etc..

 * This is my helper collection, to make coders live easier;)
 * @copyright ragtek
 * @version 1.0.2
 * @package ragtek/helper

class Ragtek_Helper_DataWriter
     * @param XenForo_Visitor $user
     * @param <int> $forumId
     * @param <str> $subject
     * @param <str> $message
     * @return <array> Thread Information
    static public function createThread(XenForo_Visitor $user, $forumId, $subject, $message)
        $writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
        $writer->set('user_id', $user['user_id']);
        $writer->set('username', $user['username']);
        $writer->set('title', $subject);
            $postWriter = $writer->getFirstMessageDw();
            $postWriter->set('message', $message);
        $writer->set('node_id', $forumId);
        return $writer->getMergedData();


                            $input['subject'], $input['message']);
YOu can see it here in action => http://xenforo.com/community/posts/88981/
Data writers, Models, etc. can be utilized outside of your conventional MVC environment as well. You just need to set up the autoloader and initialize the xf Framework from your script; to make use of xf classes.

// Required? Not sure.

$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

// Cannot confirm if starting the application is required or not
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);
Top Bottom