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

Trying to extend the ordered list BBcode, running into errors

Discussion in 'XenForo Development Discussions' started by Nikolaos, May 17, 2012.

  1. Nikolaos

    Nikolaos Member

    Hello,

    I have made several edits to the BBcode related scripts in order to accommodate special ordered lists, such as:

    I. foo
    II. bar

    But, I am running into trouble with the HTML interpretation.

    Here is what I did in /library/XenForo/Html/Renderer/BbCode.php:, which is throwing the error:

    PHP:
        protected $_handlers = array(
            
    'b'          => array('wrap' => '[B]%s[/B]'),
            
    'strong'     => array('wrap' => '[B]%s[/B]'),
            [...]
            
    'a'          => array('filterCallback' => array('$this''handleTagA')),
            
    'img'        => array('filterCallback' => array('$this''handleTagImg')),
            
    'ul'         => array('wrap' => "[LIST]\n%s\n[/LIST]"'skipCss' => true),
            
    // Following line is edited
            
    'ol'         => array('filterCallback' => array('$this''handleTagOl')),
            
    'li'         => array('filterCallback' => array('$this''handleTagLi')),
            [...]
    Here is the referenced handleTagOl:

    PHP:
        public function handleTagOl($textXenForo_Html_Tag $tag)
        {
            
    $listType trim($tag->attribute('style'));
            if(
    $listType)
            {
                if(
    preg_match('/^list-style-type: decimal/'$listType))
                    
    $target '1';
                elseif(
    preg_match('/^list-style-type: lower-alpha'$listType))
                    
    $target 'a';
                elseif(
    preg_match('/^list-style-type: upper-alpha'$listType))
                    
    $target 'A';
                elseif(
    preg_match('/^list-style-type: lower-roman'$listType))
                    
    $target 'i';
                elseif(
    preg_match('/^list-style-type: upper-roman'$listType))
                    
    $target 'I';
                return 
    "[LIST=$target]{$text}[/LIST]";
            }
            else return 
    "[LIST=1]{$text}[/LIST]";
        }
    The error thrown (when trying to preview the post) is as follows:

    I don't see where it is going wrong. Could anyone enlighten me?
     
  2. Nikolaos

    Nikolaos Member

    Note: Line 478 of my BbCode.php is this one:

    PHP:
            $listType trim($tag->attribute('style'));
     
  3. Nikolaos

    Nikolaos Member

    I had it print the contents of the attribute "style", and found that the problem is that the attribute itself has an attribute:

    Code:
    [15:37:25.654] PHP Array
    (
        [style] => Array
            (
                [list-style-type] => upper-alpha
            )
     
    )
    I have no idea how to make the function retrieve "upper-alpha" from two layers of arrays. Could someone more experienced with PHP lend me a hand?

    Thank you.
     
  4. Jeremy P

    Jeremy P Well-Known Member

    Hmm..
    PHP:
      $listType trim($tag->attribute('style')['list-style-type']);
    or

    PHP:
      $listType trim($tag->attribute('style')['style']['list-style-type']);
    ?
     
  5. Nikolaos

    Nikolaos Member

    Hm, I'm afraid that neither of those work. They don't throw a forum error, but the preview simply doesn't load. Thanks for giving it a shot, though.

    The class XenForo_Html_Tag is defined in /library/XenForo/Html/Tag.php. Does anyone know how to create a quick and dirty method to return the value of a nested array? To be frank, I wouldn't know how to do it even if the variables weren't protected - I simply haven't done this before.
     
  6. Nikolaos

    Nikolaos Member

    Solved. I did this:

    PHP:
        public function handleTagOl($textXenForo_Html_Tag $tag)
        {
            
    $listStyle $tag->attribute('style');

            if(
    $listStyle)
            {
                if(
    preg_match('/^decimal/'$listStyle['list-style-type']))
                    
    $target '1';
                elseif(
    preg_match('/^lower-alpha/'$listStyle['list-style-type']))
                    
    $target 'a';
                elseif(
    preg_match('/^upper-alpha/'$listStyle['list-style-type']))
                    
    $target 'A';
                elseif(
    preg_match('/^lower-roman/'$listStyle['list-style-type']))
                    
    $target 'i';
                elseif(
    preg_match('/^upper-roman/'$listStyle['list-style-type']))
                    
    $target 'I';
                else 
    $target '1';
                return 
    "[LIST=$target]{$text}[/LIST]";
            }
            else return 
    "[LIST=1]{$text}[/LIST]";

        }
     
    CurveGotti and ragtek like this.
  7. Nikolaos

    Nikolaos Member

    I hate to post in this thread again, for fear that it will be ignored, but I think that it would be profitable for any others who should try to do this in future if I post here.

    Now, with various template edits, ending with the one above, I have managed to get the HTML to publish correctly. But, there is one final problem - the <li> element has a predefined list-style-type in the CSS:

    Code:
    .baseHtml ol li
        { list-style: decimal outside; } 
    Now, my question is as follows - what purpose does this rule serve in the big picture? What would be damaged if I simply erased it?

    Thank you!
     
  8. Nikolaos

    Nikolaos Member

    The above post was a bad idea. I replaced "decimal outside" with "inherit" instead of removing it.

    The change works completely now. Anyone who wants to know how I did it can feel free to ask me for a log of all the final changes.
     

Share This Page