기본 콘텐트 위젯으로 유튜브 RSS 썸네일을 불러와보자
1. content.class.php 오픈
2. 위 소스를 아래 소스로 대체
$content_item->setThumbnail($this->_getRssThumbnail($item->description));
변경전
$content_item->setThumbnail($this->_getRssThumbnail($item->link));
변경후
3. 위 소스를 아래 소스로 대체
function _getRssThumbnail($content)
{
@preg_match('@<img[^>]+src\s*=\s*(?:"(.+)"|\'(.+)\'|([^\s>(?:/>)]+))@', $content, $matches);
if($matches[1])
{
return $matches[1];
}
elseif($matches[2])
{
return $matches[2];
}
elseif($matches[3])
{
return $matches[3];
}
else
{
return NULL;
}
}
{
@preg_match('@<img[^>]+src\s*=\s*(?:"(.+)"|\'(.+)\'|([^\s>(?:/>)]+))@', $content, $matches);
if($matches[1])
{
return $matches[1];
}
elseif($matches[2])
{
return $matches[2];
}
elseif($matches[3])
{
return $matches[3];
}
else
{
return NULL;
}
}
변경전
function _getRssThumbnail($content)
{
// if it is not an embed code, get the video code from the youtube URL
if($match[1] == '')
preg_match('#^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v=|/watch\?.+&v=))([\w-]{11})(?:.+)?$#x', $content, $match);
// get the corresponding thumbnail images
$full_size_thumbnail_image = "https://img.youtube.com/vi/".$match[1]."/hqdefault.jpg";
$small_thumbnail_image1 = "https://img.youtube.com/vi/".$match[1]."/mqdefault.jpg";
$small_thumbnail_image2 = "https://img.youtube.com/vi/".$match[1]."/default.jpg";
$small_thumbnail_image3 = "https://img.youtube.com/vi/".$match[1]."/0.jpg";
$small_thumbnail_image4 = "https://img.youtube.com/vi/".$match[1]."/1.jpg";
$small_thumbnail_image5 = "https://img.youtube.com/vi/".$match[1]."/2.jpg";
$small_thumbnail_image6 = "https://img.youtube.com/vi/".$match[1]."/3.jpg";
// return whichever thumbnail image you would like to retrieve
return $full_size_thumbnail_image;
}
{
// if it is not an embed code, get the video code from the youtube URL
if($match[1] == '')
preg_match('#^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v=|/watch\?.+&v=))([\w-]{11})(?:.+)?$#x', $content, $match);
// get the corresponding thumbnail images
$full_size_thumbnail_image = "https://img.youtube.com/vi/".$match[1]."/hqdefault.jpg";
$small_thumbnail_image1 = "https://img.youtube.com/vi/".$match[1]."/mqdefault.jpg";
$small_thumbnail_image2 = "https://img.youtube.com/vi/".$match[1]."/default.jpg";
$small_thumbnail_image3 = "https://img.youtube.com/vi/".$match[1]."/0.jpg";
$small_thumbnail_image4 = "https://img.youtube.com/vi/".$match[1]."/1.jpg";
$small_thumbnail_image5 = "https://img.youtube.com/vi/".$match[1]."/2.jpg";
$small_thumbnail_image6 = "https://img.youtube.com/vi/".$match[1]."/3.jpg";
// return whichever thumbnail image you would like to retrieve
return $full_size_thumbnail_image;
}
변경후
빈엔터테인먼트
Lv. 4
댓글 0