Instantiate parser on external page

I'm attempting to instantiate a XenForo parser on an external page using the following code as suggested in this thread.
$parser = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink', false));

// To then parse the $message retrieved from the database as follow
$message = $parser->render($message);
However it just prints out 'No access'. Am I missing something?

Chris D

XenForo developer
Staff member
You need to instantiate XF including the XF autoloader. If the autoloader hasn't been instantiated you will hit this.

Typically the best way to do what you're trying to do is:


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

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

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$dependencies = new XenForo_Dependencies_Public();

$formatter = XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink', false);
$parser = XenForo_BbCode_Parser::create($formatter);

// To then parse the $message retrieved from the database as follow

$message = $parser->render($message);
Thank you Chris, works like a charm.

Instantiating a 'XenForo_BbCode_Formatter_BbCode_AutoLink' formatter didn't seem to do anything for me, but a 'XenForo_BbCode_Formatter_Base' formatter turns out to do everything I'm looking for.