테스트 사이트 - 개발 중인 베타 버전입니다

게시판 list에서 유튜브 썸네일을 만들고 싶은데.. 채택완료

다조아해 2년 전 조회 1,924

write.skin.php에서

wr_10에 유튜브 주소를 입력하면 리스트에서 썸네일을 보여주게 하고 싶은데 어찌 수정을 해야 할까요?

 

</strong></p>

<p><div class="bo_w_link write_div">

   <label for="wr_link<?php echo $i ?>"><i class="fa fa-youtube-play" aria-hidden="true"></i><span class="sound_only">동영상<?php echo $i ?></span></label>

   <input type="text" name="wr_10" value="<?php echo $write['wr_10'] ?>" id="wr_10" class="frm_input full_input" placeholder="예) <a href="https://www.youtube.com/watch?v=9bZkp7q19f0">" target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=9bZkp7q19f0"></a>

</div></p>

<p><strong>

 

list.skin.php 상단에 아래 소스를 상단에 넣고

 

</strong></p>

<p><?php

if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

include_once G5_LIB_PATH."/thumbnail.lib.php";

include_once($board_skin_path.'/skin.config.php');</p>

<p>// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨

add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.css">', 0);

$_img_rate=round($board['bo_gallery_height'] / $board['bo_gallery_width']*100);

if($_img_rate<0 || $_img_rate>1000) $_img_rate=75;</p>

<p>/* 유투브 주소에서 Video ID를 추출합니다.  */

if ( ! function_exists( 'get_video_id' ) )

{

    function get_video_id( $str )

    {

        if( substr( $str, 0, 4 ) == 'http' )

        {

            if( strpos( $str, 'youtu.be' ) )

            {

                return array_pop( explode( '/', $str ) );

            }

            else if( strpos( $str, '/embed/' ) )

            {

                return array_pop( explode( '/', $str ) );

            }

            else if( strpos( $str, '/v/' ) )

            {

                return array_pop( explode( '/', $str ) );

            }

            else

            {

                $params = explode( '&', array_shift( explode( '#', array_pop( explode( '?', $str ) ) ) ) );

                foreach( $params as $data )

                {

                    $arr = explode( '=', $data );

                    if( $arr[ 0 ] == 'v' )

                    {

                        return $arr[ 1 ];

                    }

                }

            }

        }

        else

        {

            return $str;

        }

 

        return '';

    }

}

 

/* 썸네일 주소를 가져옵니다. 기본값은 default 입니다. */

if ( ! function_exists( 'get_yt_thumb' ) )

{

    function get_yt_thumb( $url_or_id, $type )

    {

        switch( $type )

        {

            case '0' :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/0.jpg';

                break;

            case '1' :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/1.jpg';

                break;

            case '2' :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/2.jpg';

                break;

            case '3' :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/3.jpg';

                break;

            case 'hq' :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/hqdefault.jpg';

                break;

            case 'mq' :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/mqdefault.jpg';

                break;

            case 'sd' :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/sddefault.jpg';

                break;

            case 'maxres' :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/maxresdefault.jpg';

                break;

            default :

                return '//img.youtube.com/vi/'.get_video_id( $url_or_id ).'/default.jpg';

        }

    }

}

?></p>

<p><strong>

 

아래 소스를 어찌 수정해야 할까요?

 

</strong></p>

<p>        <?php

        for ($i=0; $i<count($list); $i++) {

            if($list[$i]['is_notice']) $list[$i]['icon_pack'].="<span class='list-icon icon-notice'>Notice</span>";

            if($list[$i]['icon_new']) $list[$i]['icon_pack'].= "<span class='list-icon icon-new'>New</span>";</p>

<p>            $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true);

            if($list[$i]['icon_secret']){

                $img_content = '<div class="secret-box"></div>';

                $list[$i]['icon_bg']=true;

            }else{ 

                if($thumb['src']){

                    $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" class="gallery-img-content">';

                } else {

                    $img_content = '<div class="no-image"></div>';

                }

            }

            $list[$i]['content_text']=$list[$i]['icon_secret'] ? "<span class='list-content-secret'>비밀글입니다.</span>" : cut_str(strip_tags($list[$i]['wr_content']), 120);

         ?></p>

<p><strong>

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

채택된 답변
+20 포인트

        <?php

        for ($i=0; $i<count($list); $i++) {

            if($list[$i]['is_notice']) $list[$i]['icon_pack'].="<span class='list-icon icon-notice'>Notice</span>";

            if($list[$i]['icon_new']) $list[$i]['icon_pack'].= "<span class='list-icon icon-new'>New</span>";

            $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true);

            if($list[$i]['icon_secret']){

                $img_content = '<div class="secret-box"></div>';

                $list[$i]['icon_bg']=true;

            }else{ 

                if($thumb['src']){

                    $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" class="gallery-img-content">';

        } else if($list[$i]['wr_10']){

            preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $list[$i]['wr_10'], $matches);

                    $img_content = '<img src="<a href="https://img.youtube.com/vi/'.$matches[1].'/maxresdefault.jpg"" target="_blank" rel="noopener noreferrer">https://img.youtube.com/vi/'.$matches[1].'/maxresdefault.jpg"</a> class="gallery-img-content">';

                } else {

                    $img_content = '<div class="no-image"></div>';

                }

            }

            $list[$i]['content_text']=$list[$i]['icon_secret'] ? "<span class='list-content-secret'>비밀글입니다.</span>" : cut_str(strip_tags($list[$i]['wr_content']), 120);

         ?>

    

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

다조아해
2년 전
답변 주셔서 수정했더니 잘 되네요.
혼자 안되서 낑낑거렸는데 잘 해결했습니다.
다시 한번 감사 인사 드립니다.

댓글을 작성하려면 로그인이 필요합니다.

</p>

<p><?php</p>

<p>        for ($i=0; $i<count($list); $i++) {</p>

<p>            if($list[$i]['is_notice']) $list[$i]['icon_pack'].="<span class='list-icon icon-notice'>Notice</span>";</p>

<p>            if($list[$i]['icon_new']) $list[$i]['icon_pack'].= "<span class='list-icon icon-new'>New</span>";</p>

<p>            $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true);</p>

<p>            if($list[$i]['icon_secret']){</p>

<p>                $img_content = '<div class="secret-box"></div>';</p>

<p>                $list[$i]['icon_bg']=true;</p>

<p>            }else{ </p>

<p>                if($thumb['src']){</p>

<p>                    $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" class="gallery-img-content">';</p>

<p>                } else { </p>

<p>                    $youtube_thumb_url = get_yt_thumb($list[$i]['wr_10'], 0) // 유튜브 함수를 이용하여 썸네일 링크 가져옴.</p>

<p>                    $img_content = '<img src="https:'.$youtube_thumb_url.'" class="gallery-img-content">';</p>

<p>                }</p>

<p>            }</p>

<p>            $list[$i]['content_text']=$list[$i]['icon_secret'] ? "<span class='list-content-secret'>비밀글입니다.</span>" : cut_str(strip_tags($list[$i]['wr_content']), 120);</p>

<p> </p>

<p>?></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인