代码之家  ›  专栏  ›  技术社区  ›  TheWelshManc

HTMLPurifier从YouTube视频中删除Allowfullscreen

  •  0
  • TheWelshManc  · 技术社区  · 6 年前

    出于某种原因,HTMLPurifier似乎要从iframes中删除allowfullscreen元素,我不知道为什么,我做了一些研究,似乎找不到一个不到几年的答案。下面是我如何启动我的净化器。

    require 'htmlpurify/library/HTMLPurifier.auto.php';
    $config = HTMLPurifier_Config::createDefault();
    
    $config->set('HTML.TargetBlank', 'true');
    $config->set('HTML.SafeIframe', true);
    $config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%');
    $config->set('HTML.DefinitionID', 'usertag');
    $config->set('HTML.DefinitionRev', 1);
    if ($def = $config->maybeGetRawHTMLDefinition()) {
        $def->addElement('user', 'Block', 'Flow', 'Common', array('name' => 'ID'));
    }
    
    $purifier = new HTMLPurifier($config);
    

    <iframe title="YouTube Player" src="https://www.youtube.com/embed/J---aiyznGQ" width="560" height="315" frameborder="0" allowfullscreen></iframe>

    0 回复  |  直到 6 年前
        1
  •  1
  •   pinkgothic sudip    6 年前

    “allowfullscreen”不是 an attribute HTML Purifier inherently recognises for IFrames customise

    $config = HTMLPurifier_Config::createDefault();
    // ...
    $config->set('HTML.DefinitionID', 'enduser-customize.html tutorial');
    $config->set('HTML.DefinitionRev', 1);
    $config->set('Cache.DefinitionImpl', null); // remove this later!
    $def = $config->getHTMLDefinition(true);
    $def->addAttribute('iframe', 'allowfullscreen', 'Bool');
    

    看看这对你有没有帮助?一些额外的考虑被张贴在 this answer from 2016 HTML.AllowedElements HTML.AllowedAttributes iframe ,任何其他HTML标记将被剥离)。