2014-07-10 44 views
0

我在Laravel 4.2上使用mewebstudio/Purifier程序包服务提供商HTMLPurifier。允许YouTube在Laravel 4和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; 
}); 

其他一切作品,但这个。

感谢同胞的战士:)

回答

-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 
     ), 
    ), 
); 
+1

试过它已经,没有工作:/ –

+0

它在这里也不起作用。 –