这是我想在 HTMLPurifier 中允许的一种特殊的标签组合,但似乎无法使该组合发挥作用。
我可以让脚本标签工作,但随后嵌入标签被删除(我使用 HTML.Trusted = true 启用脚本标签)。当我重新嵌入标签时,脚本标签被删除(我删除了 HTML.Trusted)。以下是我的配置:
$config->set('HTML.Trusted', true);
$config->set('HTML.SafeEmbed', true);
$config->set('HTML.SafeObject', true);
$config->set('Output.FlashCompat', true);
我什至尝试添加以下内容,这让事情变得更糟:
$config->set('HTML.Allowed', 'object[width|height|data],param[name|value],embed[src|type|allowscriptaccess|allowfullscreen|width|height],script[src|type]');
此外,无论如何,我似乎都无法让 iframe 工作。我尝试添加:
$config->set('HTML.DefinitionID', 'enduser-customize.html iframe');
$config->set('HTML.DefinitionRev', 1);
$config->set('Cache.DefinitionImpl', null); // remove this later!
$def = $config->getHTMLDefinition(true);
$iframe = $def->addElement(
'iframe', // name
'Block', // content set
'Empty', // allowed children
'Common', // attribute collection
array( // attributes
'src*' => 'URI#embedded',
'width' => 'Pixels#1000',
'height' => 'Pixels#1000',
'frameborder=' => 'Number',
'name' => 'ID',
)
);
$iframe->excludes = array('iframe' => true);
任何关于让整个组合工作的帮助,甚至是带有对象/参数和嵌入的脚本标签都将不胜感激!!!
哦,是的,这显然不适合所有用户,只是“特殊”用户。
谢谢!
PS - 请不要将我链接到http://htmlpurifier.org/docs/enduser-customize.html
更新
我在这里找到了在线程底部添加 iframe 的解决方案:http: //htmlpurifier.org/phorum/read.php? 3,4646
现在的配置是:
$config->set('HTML.Trusted', true);
$config->set('HTML.SafeEmbed', true);
$config->set('HTML.SafeObject', true);
$config->set('Output.FlashCompat', true);
$config->set('Filter.Custom', array( new HTMLPurifier_Filter_MyIframe() ));
更新到更新
如果您对我在 HTMLPurifier 论坛中的评论有疑问,可能是因为我的意思是让方法看起来像这样:
public function preFilter($html, $config, $context) {
return preg_replace("/iframe/", "img class=\"MyIframe\" ", preg_replace("/<\/iframe>/", "", $html));
}