2010-11-09 43 views
6

这是怎么样的,我想允许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)); 
} 
+0

“不要使用HTML净化器”。 :-) – 2011-01-19 17:53:10

+0

HTML净化器岩石!为什么我不想使用它? ;) – shmuel613 2011-02-14 09:03:43

+0

要真正正确,你应该扩展'HTMLPurifier_Filter'。不过,解决方案还是很棒的。我正在使用这个功能,但将我信任的域列入白名单(例如,youtube的新iframe嵌入)。 – 2011-03-15 00:48:18

回答

5

通过HTMLPurifier Google小组发现解决方案(谢谢Edward Z. Yang !!!)。允许同时在页面上存在对象,嵌入和脚本标记的解决方案是从HTMLModuleManager.php __construct()方法中的$ common数组中移除“object”。这当然会使它无法添加对象标签,除非您在配置中指定它。

我最后设置现在是:

 $config->set('HTML.Trusted', true); 
     $config->set('HTML.SafeObject', true); 
     $config->set('Output.FlashCompat', true); 
     $config->set('Filter.Custom', array(new HTMLPurifier_Filter_SafeIframe())); 

我真的希望这些内容可以帮助其他开发人员想使用HTMLPurifier谁。与我们最初用来清理和清理我们的wysiwyg编辑器收到的文本相比,HTMLPurifier大约快了85%!

+1

如何获得'HTMLPurifier_Filter_SafeIframe'类的副本? – Sonny 2011-09-13 14:32:34

+0

看到这个[问题](http://stackoverflow.com/questions/4739284/htmlpurifier-iframe-vimeo-and-youtube-video) – Piero 2012-10-14 17:41:02

相关问题