Instantiate parser on external page

fishb6nes

Member
I'm attempting to instantiate a XenForo parser on an external page using the following code as suggested in this thread.
Code:
require_once('community/library/XenForo/Application.php');
require_once('community/library/XenForo/BbCode/Formatter/Base.php');
require_once('community/library/XenForo/BbCode/Parser.php');
$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?
 
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:

PHP:
<?php

$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();
$dependencies->preLoadData();

$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.
 
Back
Top Bottom