views:

100

answers:

1

I'm trying to add extra tags to the PEAR package BBCodeParser http://pear.php.net/package/HTML_BBCodeParser/docs/latest/li_HTML_BBCodeParser.html, to do this, I believe I need to place Object.php in \php5.3.0\PEAR\pear\HTML\BBCodeParser\Filter and call addFilter.

Object.php

<?php
/*
 New filter
 @todo Lots
*/
require_once 'HTML/BBCodeParser/Filter.php';

class HTML_BB_CodeParser_Filter_Object extends HTML_BBCodeParser_Filter {

var $_definedTags = array( 'object' => array ( 'htmlopen' => 'object',
          'htmlclose' => 'object',
          'allowed' => 'all',
          'attributes' => array()
              )
    )

}
?>

extbbcode.php

<?php
/*
 The test display page
*/
error_reporting(E_STRICT); 
require_once('HTML/BBCodeParser.php');

$parser = new HTML_BBCodeParser();

$parser->addFilter('object');

$parser->setText('[b]bold[/b] [object]test[/object]');
$parser->parse();
$parsed = $parser->getParsed();

echo htmlentities($parsed, ENT_QUOTES). ' | ';
echo $parsed;
?>

When I view extbbcode.php I just get this error

Strict Standards: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in D:\wamp\bin\php\php5.3.0\PEAR\pear\HTML\BBCodeParser.php on line 169

If I comment out the $parser->addFilter('object'); line then it works as expected, ie, produces valid output. I can also specify an existing filter, ie

$parser->addFilter('basic');
$parser->addFilter('images');

Basic.php , Images.php

If I call addFilter with an invalid filter (ie, the file doesn't exist) I get the "Failed to load filter $filter" message.

Can someone spot what I'm doing wrong? It seems to me that Object.php is included, but produces those weird STRICT messages. So my problem is definitely with that file.

If anyone has experience with this class or that error message and can point me in the right direction, I'd be very happy :)

BBCodeParser.php

function addFilter($filter)
{
    $filter = ucfirst($filter);
    if (!array_key_exists($filter, $this->_filters)) {
        $class = 'HTML_BBCodeParser_Filter_'.$filter;
        @include_once 'HTML/BBCodeParser/Filter/'.$filter.'.php';
        if (!class_exists($class)) {
            PEAR::raiseError("Failed to load filter $filter", null, PEAR_ERROR_DIE);
        }
        $this->_filters[$filter] = new $class;
        $this->_definedTags = array_merge(
            $this->_definedTags,
            $this->_filters[$filter]->_definedTags
        );
    }
}

edit: managed to get PEAR working on my local WAMP, so I can simplify the question by ruling out another problem I was having.

A: 

You can add your filter directly to the BBCode class.

class HTML_BBCodeParser_Custom_Filter extends HTML_BBCodeParser  
{  
    var $_definedTags =   
        array('block' => array( 'htmlopen'  => 'blockquote',  
                    'htmlclose' => 'blockquote',  
                    'allowed'   => 'all',  
                    'attributes'=> array()  
                  ),  
              'line' =>  array( 'htmlopen'  => 'hr',  
                    'htmlclose' => '',  
                    'allowed'   => 'all',  
                    'attributes'=> array()  
                  ),
            );  

}

$BBCodeParser = new HTML_BBCodeParser();

$FilterName = 'Custom_Filter';
$BBCodeParser->_filters[$FilterName] = new HTML_BBCodeParser_Custom_Filter();
    $BBCodeParser->_definedTags = array_merge(
            $BBCodeParser->_definedTags,
            $BBCodeParser->_filters[$FilterName]->_definedTags);

echo $BBCodeParser->qparse("[block]This is a blockquote. [line][/block]");

Disclosure: The custom tags class were taken from here while the code to put the tags directly into the class were taken from the actual PEAR source code (HTML_BBCodeParser::addfilter).

MrValdez