1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Parsing BBcode on external page, attachments problem

Discussion in 'XenForo Development Discussions' started by Abracadaniel, Jul 9, 2014.

  1. Abracadaniel

    Abracadaniel Member

    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.

    require '/var/www/domain.com/web/library/XenForo/Autoloader.php';


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

  2. Chris D

    Chris D XenForo Developer Staff Member

    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.
    Abracadaniel likes this.
  3. Abracadaniel

    Abracadaniel Member

    Gee, that's what I call a quick answer :eek: Didn't expected that.
    Would try right away!
  4. SAS1024

    SAS1024 Member

    @Abracadaniel, are you solved this problem? I have same problem, but I don't understand what i must do to fix it :/
  5. Abracadaniel

    Abracadaniel Member

    Actually no luck here.
    I guess OOP is just not for me, at least for now. :unsure:
  6. SAS1024

    SAS1024 Member

    @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:
    $formatter XenForo_BbCode_Formatter_Base::create''$options );
    $parser = new XenForo_BbCode_Parser$formatter );
    $parser->render$text, array('myRender' => true));
    Explanation of paragraph 3:
    public function renderTagAttach(array $tag, array $rendererStates)
        if (!empty(
    $id intval($this->stringifyTree($tag['children']));
            if (!
    '<img alt="'.$id.'" src="' XenForo_Link::buildPublicLink('full:attachments', array('attachment_id' => $id)) . '"/>';
    Abracadaniel and Yoskaldyr like this.
  7. Yoskaldyr

    Yoskaldyr Well-Known Member

    @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.
    Abracadaniel likes this.

Share This Page