Php 扩展HTML_BBCodeParser_过滤器
我正在尝试向PEAR包BBCodeParser添加额外的标记,为此,我认为需要将Object.php放在\php5.3.0\PEAR\PEAR\HTML\BBCodeParser\Filter中,并调用addFilter Object.phpPhp 扩展HTML_BBCodeParser_过滤器,php,overriding,pear,bbcode,extends,Php,Overriding,Pear,Bbcode,Extends,我正在尝试向PEAR包BBCodeParser添加额外的标记,为此,我认为需要将Object.php放在\php5.3.0\PEAR\PEAR\HTML\BBCodeParser\Filter中,并调用addFilter Object.php <?php /* New filter @todo Lots */ require_once 'HTML/BBCodeParser/Filter.php'; class HTML_BB_CodeParser_Filter_Object exte
<?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()
)
)
}
?>
,
如果我使用无效的筛选器(即,该文件不存在)调用addFilter,我会收到“加载筛选器失败$filter”消息
有人能看出我做错了什么吗?在我看来,Object.php包含在内,但会生成那些奇怪的严格消息。所以我的问题肯定是这个文件
如果有人有过此类或错误消息的经验,并能为我指出正确的方向,我将非常高兴:)
编辑:设法让PEAR处理我的本地WAMP,这样我就可以通过排除我遇到的另一个问题来简化问题。您可以直接将过滤器添加到BBCode类中
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]");
披露:自定义标记类取自,而将标记直接放入类中的代码取自实际的PEAR源代码(HTML_BBCodeParser::addfilter)。您可以将过滤器直接添加到BBCode类中
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]");
披露:自定义标记类取自,而将标记直接放入类中的代码取自实际的PEAR源代码(HTML_BBCodeParser::addfilter)。我终于发现了如何返回一些错误消息,而不是返回空白屏幕。错误报告(E_严格);现在我看到了这个错误:严格标准:非静态方法PEAR::getStaticProperty()不应该静态调用,假设$this来自D:\wamp\bin\php\php5.3.0\PEAR\PEAR\HTML\BBCodeParser.php第169行的不兼容上下文,有什么想法吗?我终于发现了如何返回一些错误消息,而不是返回空白屏幕。错误报告(E_严格);现在我看到了这个错误:严格标准:非静态方法PEAR::getStaticProperty()不应该静态调用,假设$this来自D:\wamp\bin\php\php5.3.0\PEAR\PEAR\HTML\BBCodeParser.php第169行的不兼容上下文,有什么想法吗?非常感谢,很抱歉我花了很长时间才接受这个答案!非常感谢,很抱歉我花了很长时间才接受这个答案!
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
);
}
}
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]");