1. 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

Discussion in 'XenForo Development Discussions' started by Walky, Sep 17, 2014.

  1. Walky

    Walky Member

    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
     
  2. cclaerhout

    cclaerhout Well-Known Member

    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. Walky

    Walky Member

    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 :)
     
  4. cclaerhout

    cclaerhout Well-Known Member

    Then just extend directly the renderTagUser function.
     
  5. Walky

    Walky Member

    Ok, I deleted the getTags function but it doesn't work too with just the renderTagUser :(
     
  6. cclaerhout

    cclaerhout Well-Known Member

    Use the correct listener "load_class_bb_code" (or load_class - from XenForo 1.2).
     
    Walky likes this.
  7. Walky

    Walky Member

    Ohhh... I used load_class_controller :/

    Thanks you :D
     
    cclaerhout likes this.

Share This Page