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

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

QA

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

본문

write.skin.php에서

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

 


<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="예) https://www.youtube.com/watch?v=9bZkp7q19f0">
</div>

 

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

 


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once G5_LIB_PATH."/thumbnail.lib.php";
include_once($board_skin_path.'/skin.config.php');
// 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;
/* 유투브 주소에서 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';
        }
    }
}
?>

 

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

 


        <?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 {
                    $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);
         ?>

이 질문에 댓글 쓰기 :

답변 2


        <?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="https://img.youtube.com/vi/'.$matches[1].'/maxresdefault.jpg" 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);
         ?>
     

<?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 { 
                    $youtube_thumb_url = get_yt_thumb($list[$i]['wr_10'], 0) // 유튜브 함수를 이용하여 썸네일 링크 가져옴.
                    $img_content = '<img src="https:'.$youtube_thumb_url.'" class="gallery-img-content">';
                }
            }
            $list[$i]['content_text']=$list[$i]['icon_secret'] ? "<span class='list-content-secret'>비밀글입니다.</span>" : cut_str(strip_tags($list[$i]['wr_content']), 120);
 
?>
답변을 작성하시기 전에 로그인 해주세요.
전체 194
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT