【问题标题】:Allowing YouTube embed with HTMLPurifier on Laravel 4 and mewebstudio/Purifier允许 YouTube 在 Laravel 4 和 mewebstudio/Purifier 上嵌入 HTMLPurifier
【发布时间】:2014-09-01 02:57:47
【问题描述】:

我在 Laravel 4.2 上使用 mewebstudio/Purifier 包服务提供商 HTMLPurifier。

由于某种原因,我无法使 youtube iframe 功能正常工作。我什至尝试了作者的示例,但没有成功。

这是我的 HTMLPurifier 捆绑配置:

return array(
    'encoding' => 'UTF-8',
    'finalize' => true,
    'preload'  => false,
    'settings' => array(
        'default' => array(
            'HTML.Doctype'             => 'XHTML 1.0 Strict',
            'HTML.Allowed'             => 'div[style],b,strong,i,em,a[href|title|style],ul,ol,li,p[style],br,span[style],
                                            img[width|height|alt|src],h1[style],h2[style],h3[style],h4[style],h5[style],table[class|style|summary],tr,td[abbr],tbody,thead',
            'CSS.AllowedProperties'    => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
            'HTML.SafeObject'          => true,
            'Output.FlashCompat'       => true,
            'HTML.SafeIframe'          => true,
            'URI.SafeIframeRegexp'     => '%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%',
            'AutoFormat.AutoParagraph' => true,
            'AutoFormat.RemoveEmpty'   => true,
            'HTML.Nofollow'            => true,
            'URI.Host'                 => 'domain.com',
        ),
    ),
);

这是我在路线上的测试:

Route::get('/clean', function() {
    $pured = Purifier::clean('<iframe src="//www.youtube.com/embed/gLUdqi8J0mQ" width="640" height="360" frameborder="0"></iframe>', 'default');
    return $pured;
});

其他一切都有效,但这个。

感谢各位勇士:)

【问题讨论】:

    标签: php iframe youtube laravel-4 htmlpurifier


    【解决方案1】:

    HTMLPurifier 已经为 Youtube 视频准备了一个过滤器,请确保使用它。

    要使用它,请确保您的配置中有这一行:

    'Filter.YouTube' => true
    

    您的最终配置文件如下所示:

    return array(
        'encoding' => 'UTF-8',
        'finalize' => true,
        'preload'  => false,
        'settings' => array(
            'default' => array(
                'HTML.Doctype'             => 'XHTML 1.0 Strict',
                'HTML.Allowed'             => 'div[style],b,strong,i,em,a[href|title|style],ul,ol,li,p[style],br,span[style],
                                                img[width|height|alt|src],h1[style],h2[style],h3[style],h4[style],h5[style],table[class|style|summary],tr,td[abbr],tbody,thead',
                'CSS.AllowedProperties'    => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
                'HTML.SafeObject'          => true,
                'Output.FlashCompat'       => true,
                'HTML.SafeIframe'          => true,
                'URI.SafeIframeRegexp'     => '%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%',
                'AutoFormat.AutoParagraph' => true,
                'AutoFormat.RemoveEmpty'   => true,
                'HTML.Nofollow'            => true,
                'URI.Host'                 => 'domain.com',
                'Filter.YouTube'           => true
            ),
        ),
    );
    

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 2011-05-28
      • 1970-01-01
      • 2022-06-30
      • 1970-01-01
      相关资源
      最近更新 更多