그누보드 video 태그 안나올때 > IT 기술백서

IT 기술백서

직접 알아내거나 검색하기 귀찮아서 모아 둔 것

php | 그누보드 video 태그 안나올때

본문

/lib/common.lib.php 에서 html_purifier() 함수를 다음으로 교체한다.

[code]

function html_purifier($html)

{

    $f = file(G5_PLUGIN_PATH.'/htmlpurifier/safeiframe.txt');

    $domains = array();

    foreach($f as $domain){

        // 첫행이 # 이면 주석 처리

        if (!preg_match("/^#/", $domain)) {

            $domain = trim($domain);

            if ($domain)

                array_push($domains, $domain);

        }

    }

    // 내 도메인도 추가

    array_push($domains, $_SERVER['HTTP_HOST'].'/');

    $safeiframe = implode('|', $domains);


    include_once(G5_PLUGIN_PATH.'/htmlpurifier/HTMLPurifier.standalone.php');

    include_once(G5_PLUGIN_PATH.'/htmlpurifier/extend.video.php');

    $config = HTMLPurifier_Config::createDefault();

    // data/cache 디렉토리에 CSS, HTML, URI 디렉토리 등을 만든다.

    $config->set('Cache.SerializerPath', G5_DATA_PATH.'/cache');

    $config->set('HTML.SafeEmbed', false);

    $config->set('HTML.SafeObject', false);

    $config->set('Output.FlashCompat', false);

    $config->set('HTML.SafeIframe', true);

    if( (function_exists('check_html_link_nofollow') && check_html_link_nofollow('html_purifier')) ){

        $config->set('HTML.Nofollow', true);    // rel=nofollow 으로 스팸유입을 줄임

    }

    $config->set('URI.SafeIframeRegexp','%^(https?:)?//('.$safeiframe.')%');

    $config->set('HTML.DefinitionID', 'html5-definitions'); // unqiue id

    $config->set('HTML.DefinitionRev', 1);


    $config->set('HTML.Doctype', 'HTML 4.01 Transitional');

    $config->set('Attr.AllowedFrameTargets', array('_blank'));

    //유튜브, 비메오 전체화면 가능하게 하기

    $config->set('Filter.Custom', array(new HTMLPurifier_Filter_Iframevideo()));


    if ($def = $config->maybeGetRawHTMLDefinition()) {

    // http://developers.whatwg.org/the-video-element.html#the-video-element

        $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array(

            'src' => 'URI',

            'type' => 'Text',

            'width' => 'Length',

            'height' => 'Length',

            'poster' => 'URI',

            'preload' => 'Enum#auto,metadata,none',

            'controls' => 'Bool',

        ));

        $def->addElement('source', 'Block', 'Flow', 'Common', array(

            'src' => 'URI',

            'type' => 'Text',

        ));

    }


    $purifier = new HTMLPurifier($config);

    return $purifier->purify($html);

}

[/code]

 

스킨 view.skin.php 에서 내용보여주는 부분을 다음으로 교체한다.

[code]

<?php

 

 

$content = get_view_thumbnail($view['content']);

$content = preg_replace('~<video\s(((?!src)).)*>~is', '<video controls autostart="true" autoplay="true" loop="loop" muted="true">', $content);

preg_match_all('~<video\s[^>]*src=["']([^"']+)["'][^>]*>~is', $content, $matches);


for ($i=0; $i<count($matches[0]); $i++) {

    $target_tag = $matches[0][$i];

    $replace_tag = '<video controls autostart="true" autoplay="true" loop="loop" muted="true" src="'.$matches[1][$i].'">';

    $content = str_replace($target_tag, $replace_tag, $content);

}

echo $content;

[/code]

댓글 0개

등록된 댓글이 없습니다.

Menu