Parsing BBcode on external page, attachments problem

Hi there,

Having *.php file in the same dir as Xenforo Installation.
It's getting last posts from mySQL, and rendering their BBcode. Code is below.

Everything works smoothly, except for image attachments.
They`re appearing as:
View attachment 13210
View attachment 13211
View attachment 13212​

Guests have permission to view attachments.

I tried to play with "$this->_view", but didn't understand what can be done here to make render show picture.

Would be glad for any advice. Thanks!
Have a good day.

PHP:
require '/var/www/domain.com/web/library/XenForo/Autoloader.php';
XenForo_Autoloader::getInstance()->setupAutoloader('/var/www/domain.com/web/library');

XenForo_Application::initialize('/var/www/domain.com/web/library', '/var/www/externaldomain.com/cron');
XenForo_Application::set('page_start_time', $startTime);

$formatter = XenForo_BbCode_Formatter_Base::create();
$parser = new XenForo_BbCode_Parser($formatter);
$parsed_message = $parser->render($message);

echo $parsed_message;
 
You need to look at the Thread functions in XenForo, you effectively need to do the same thing.

Specifically the Thread controller actionIndex and the Thread view renderHtml.

You'll notice that when the posts are fetched for the thread, they are then run through a function that fetches the attachments and merges the attachment records into the post records.

Then a few things are passed to the View such as the viewAttachments state. That then makes the attachment data available to the BB Code parser to render the [ATTACH ] BB code.
 
You need to look at the Thread functions in XenForo, you effectively need to do the same thing.

Specifically the Thread controller actionIndex and the Thread view renderHtml.

You'll notice that when the posts are fetched for the thread, they are then run through a function that fetches the attachments and merges the attachment records into the post records.

Then a few things are passed to the View such as the viewAttachments state. That then makes the attachment data available to the BB Code parser to render the [ATTACH ] BB code.
Gee, that's what I call a quick answer :eek: Didn't expected that.
Would try right away!
 
@Abracadaniel, I did it with @Yoskaldyr help! :)

You must:
  1. Create your own extended bbcode formatter class (class will be named like
    class OldGamesIntegration_Extend_BBCode_Formatter_Base extends XFCP_OldGamesIntegration_Extend_BBCode_Formatter_Base
    ).
  2. Call bbcode parser with your own param in renderer (in example below param is 'myRender').
  3. Then in extended bbcode formatter class extend renderTagAttach method.
Explanation of paragraph 2:
PHP:
$formatter = XenForo_BbCode_Formatter_Base::create( '', $options );
$parser = new XenForo_BbCode_Parser( $formatter );
return $parser->render( $text, array('myRender' => true));

Explanation of paragraph 3:
PHP:
public function renderTagAttach(array $tag, array $rendererStates)
{
    if (!empty($rendererStates['myRender']))
    {
        $id = intval($this->stringifyTree($tag['children']));
        if (!$id)
        {
            return '';
        }
        return '<img alt="'.$id.'" src="' . XenForo_Link::buildPublicLink('full:attachments', array('attachment_id' => $id)) . '"/>';
    }
    return parent::renderTagAttach($tag, $rendererStates);
}
 
@Abracadaniel, Proposed above method is a simplest method to display attachments in third party scripts. But this method does not check existence of a attachment. And it will work only if you don't need to check attachment permissions in bbcodes and you want to display a full images only.
Otherwise, method suggested by @Chris D is much better.
 
Back
Top Bottom