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

Extend BbCode don't work

#1
Hi !

I want to extend XenForo BBCOde ! SO I created a Listener and a Bcode file but this don't work :/

Here is my Listener.php file :
PHP:
<?php

class TaggedUsers_Listener 
{
    public static function loadClassController($class, array &$extend)
    {
       if($class == "XenForo_BbCode_Formatter_Base")
        {
           $extend[] = "TaggedUsers_BbCode_Formatter_Base";
        }
    }
}
And my BbCode_Formatter_Base File
PHP:
<?php

class TaggedUsers_BbCode_Formatter_Base extends XFCP_TaggedUsers_BbCode_Formatter_Base
{

    protected static $_taggedUsers = array();
   
    public function getTags()
    {
        if ($this->_tags !== null)
        {
            return $this->_tags;
        }
       
        return array(
           'user' => array(
                'hasOption' => true,
                'stopSmilies' => true,
                'callback' => array($this, 'renderTagUser')
            )
       );
    }

    public function renderTagUser(array $tag, array $rendererStates)
    {
        $content = $this->renderSubTree($tag['children'], $rendererStates);
        if ($content === '')
        {
            return '';
        }

        $userId = intval($tag['option']);
        if (!$userId)
        {
            return $content;
        }

        $link = XenForo_Link::buildPublicLink('full:members', array('user_id' => $userId));
        $username = $this->stringifyTree($tag['children']);
       
        if (empty(self::$_taggedUsers[$userId])) {
           $userModel = XenForo_Model::create('XenForo_Model_User');
           $user = $userModel->getUserById($userId, array());
           self::$_taggedUsers[$userId] = $user;
       } else {
           $user = self::$_taggedUsers[$userId];
       }
       $content = '<span class="style' . $user['display_style_group_id'] . '">' . $content . '</span>';

        return $this->_wrapInHtml('<a href="' . htmlspecialchars($link) . '" class="username" data-user="' . $userId . ', ' . htmlspecialchars($username) . '">', '</a>', $content);
    }
}
Where is the error ? Thanks
 

cclaerhout

Well-known member
#2
PHP:
  public function getTags()
   {
     //If you find that the tags configuration is not null, return it
     if ($this->_tags !== null)
     {
       //Well, it's not null...
       return $this->_tags;
     }

     //I will never be called then... and fortunately. Otherwise I will only return my custom tag and none of the parents
     return array(
      'user' => array(
         'hasOption' => true,
         'stopSmilies' => true,
         'callback' => array($this, 'renderTagUser')
       )
    );
   }
Try this:
PHP:
  public function getTags()
   {
     $parentTags = parent::getTags();

     if(is_array($parentTags))
     {
       $parentTags += array(
         'user' => array(
           'hasOption' => true,
           'stopSmilies' => true,
           'callback' => array($this, 'renderTagUser')
         )
       );       
     }

     return $parentTags;
   }
 
#3
PHP:
  public function getTags()
   {
     //If you find that the tags configuration is not null, return it
     if ($this->_tags !== null)
     {
       //Well, it's not null...
       return $this->_tags;
     }

     //I will never be called then... and fortunately. Otherwise I will only return my custom tag and none of the parents
     return array(
      'user' => array(
         'hasOption' => true,
         'stopSmilies' => true,
         'callback' => array($this, 'renderTagUser')
       )
    );
   }
Try this:
PHP:
  public function getTags()
   {
     $parentTags = parent::getTags();

     if(is_array($parentTags))
     {
       $parentTags += array(
         'user' => array(
           'hasOption' => true,
           'stopSmilies' => true,
           'callback' => array($this, 'renderTagUser')
         )
       );     
     }

     return $parentTags;
   }
Don't work :( The tag is not in color :/
And it's not a custom tag it's a code to extend the USER BBCode :)