这是怎么样的,我想允许HTMLPurifier标签一支专兼结合的,但似乎无法得到的结合工作。如何在HTMLPurifier中允许脚本,对象,参数,嵌入和iframe标签?
我可以得到脚本标签工作,但随后嵌入标记获取删除(我支持与HTML.Trusted =真正的脚本标记)。当我嵌入标签时,脚本标签被剥离(我删除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
UPDATE
我发现了一个解决方案,在螺纹的底部在这里添加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));
}
“不要使用HTML净化器”。 :-) – 2011-01-19 17:53:10
HTML净化器岩石!为什么我不想使用它? ;) – shmuel613 2011-02-14 09:03:43
要真正正确,你应该扩展'HTMLPurifier_Filter'。不过,解决方案还是很棒的。我正在使用这个功能,但将我信任的域列入白名单(例如,youtube的新iframe嵌入)。 – 2011-03-15 00:48:18