YouTube와 Vimeo에 대해 iframe
을 허용하도록 HTMLPurifier를 구성하려고했습니다. 이와 관련된 많은 게시물이 오래되어 보이지 않으며 단순히 작동하지 않습니다. 내가 얻을 수 있었던 가장 가까운 것은 iframe
을 보존하지만 src
은 삭제됩니다.HTMLPurifier가 YouTube를 벗기기
여기에 제가 현재 가지고있는 것이 있습니다 (출력시에는 iframe
이 제거되었습니다). 나는이 질문이 무수한 시간에 물었지만 아무것도 나를 위해 일한다는 것을 깨닫는다. 미리 감사드립니다!
UPDATE
는 또한 심지어 YouTube에 기본 구성 설정이 mewebstudio/Purifier
, https://github.com/mewebstudio/Purifier을 시도했다. iframe이 아직 스트립되고 있습니다. 내가 뭘 놓치고 있니?
// HTMLPurifier
$config = \HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
$config->set('AutoFormat.RemoveEmpty.Predicate', [
'colgroup' =>
[],
'th' =>
[],
'td' =>
[],
'o:p' =>
[]
]);
$config->set('AutoFormat.RemoveEmpty', true);
$config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
$config->set('HTML.Allowed', 'p,span[style|class],a[href|title],abbr[title],acronym[title],b,strong,blockquote[cite],code,em,i,iframe[src|width|height],img[alt|title|class|src|height|width],h1,h2,h3,h3,ol,ul,li,table[class|style],tr,td,hr');
$config->set('HTML.SafeIframe', true);
$config->set('URI.SafeIframeRegexp', '%^(\/\/www\.youtube(?:-nocookie)?\.com\/embed\/|\/\/player\.vimeo\.com\/)%');
$def = $config->getHTMLDefinition(true);
$def->addAttribute('iframe', 'allowfullscreen', 'Bool');
$purifier = new \HTMLPurifier($config);
$input['body'] = $purifier->purify($input['body']);