【问题标题】:HTMLPurifier custom filter configurationHTMLPurifier 自定义过滤器配置
【发布时间】:2015-05-14 21:48:59
【问题描述】:

我在各种网站上看到了很多关于添加“到您的 HTML Purifier 配置”的帖子,例如 Sonny 对这个问题的出色回答:HTMLPurifier iframe Vimeo and Youtube video

但是,尽我所能,我似乎无法确切地发现如何设置我的 HTML Purifier 配置。我实际上是在尝试添加自定义过滤器a la Sonny 的评论,但我最接近的发现如何在我的 Drupal 7 环境中设置我的 HTML 净化器配置来自 /sites/all/模块/htmlpurifier/config/sample.php:

<?php

/**
 * @file
 * This file is a sample advanced PHP configuration file for the HTML Purifier
 * filter module. In reality, this file would be named N.php, where N is the
 * integer identifying the filter this is configuring. The configure page
 * for HTML Purifier (advanced) will tell you what file to copy this to.
 *
 * See this URI:
 *
 *    http://htmlpurifier.org/live/configdoc/plain.html
 *
 * For full information about permitted directives. The most interesting ones
 * for custom configuration are ones with the 'mixed' type, as they cannot
 * be configured using the webform.

但这对我没有任何帮助 - 我在 HTML Purifier(高级)配置页面(在文本过滤器配置页面上?我没有看到任何东西......)上没有看到任何内容,并且上面 URI 中的文档也没有帮助。

编辑:非常感谢@Chris 对我最初问题的回答。后来我发现创建filtered_html.php 文件让我无法从UI 中为过滤后的HTML 配置HTML Purifier!这应该发生吗?

在查看 HTML Purifier(高级)时,我从 UI 中看到的只是“显示帮助文本”复选框。 (我已经在下面添加了这个作为评论,但我想我也会修改我的问题,希望更多的人会看到这个......)

【问题讨论】:

    标签: drupal-7 htmlpurifier


    【解决方案1】:

    首先,确保您已安装 HTML 净化器库,如 INSTALL.txt 文件中所示。如果安装正确,状态报告页面会显示版本。

    在 Drupal 7 中,过滤器系统现在使用字符串键而不是整数。因此,要在sites/all/modules/htmlpurifier/config/下创建格式为“Filtered HTML”的配置文件,将sample.php复制到filtered_html.php,并像这样更新钩子函数名称:

    function htmlpurifier_config_filtered_html($config) {
    

    上面教程的其余部分对我有用,现在我的 preFilter 和 postFilter 函数正在被调用。

    我认为您可以通过 UI 执行此操作,但看起来“过滤器”自定义配置框未评估为 PHP。

    【讨论】:

    • 感谢您的快速回复,克里斯!我已经安装了 HTML 过滤器并且运行良好,这可以通过它过滤掉我的 YouTube 嵌入来证明:-) 如果您查看我提供的链接并查看 Sonny 的回复,您会看到他提到“添加以下内容到您的 HTML Purifier 配置:"
    • code $config->set('Filter.Custom', array(new HTMLPurifier_Filter_MyIframe()));code 我尝试将该行添加到“HTML Purifier (高级)”设置在 Drupal 管理面板中,但这会导致 HTML Purifier 出现 PHP 错误,所以我认为这不是添加该语句的合适位置。
    • 另外,我刚刚确认状态报告页面显示我安装了 4.4.0 版的 HTML Purifier,没有报告任何问题。此外,我可以在 UI 中的 HTML Purifier(高级)配置的 HTML - Allowed 部分添加标签,然后允许这些标签 - 所以我已经能够毫无问题地做到这一点。跨度>
    • 好的,看起来“过滤器”标题下的“自定义”文本区域应该执行 $config->set('Filter.Custom'... 所以在那个框中,尝试粘贴
    • array(new HTMLPurifier_Filter_MyIframe());单击字段标签以查看该字段的帮助。它说它应该是一个数组。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 2019-09-17
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    相关资源
    最近更新 更多