2016-08-10 12 views
2

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']); 

답변

1

원본 코드에는 두 가지 문제가 있습니다. 첫째, 정규 표현식은 유효하지 않습니다 - http:을 고려하지 않았습니다. 그 대신 '%^(https?:)?(\/\/www\.youtube(?:-nocookie)?\.com\/embed\/|\/\/player\.vimeo\.com\/)%'

으로 바뀌 었습니다. 둘째, $config->set('AutoFormat.RemoveEmpty', true);iframe을 제거한 것처럼 보입니다. 다음을 수정하면 다음이 추가됩니다.

$config->set('AutoFormat.RemoveEmpty.Predicate', [ 
      'iframe' => 
       array (
        0 => 'src', 
       ) 
     ]); 

에드워드 양에게 감사드립니다.