Chủ đề: Mod BBCode Youtube Cho JohnCMS
![]() | ![]() ![]() ![]() 17:42 / 05.12.2015 |
Code này bạn chỉ việc post cả url của video muốn nhúng vào trong code là được.
Tính năng cho PC và Mobile:
+ Khi truy cập bằng pc sẽ hiển thị video bạn nhúng.
+ Khi truy cập bằng mobile sẽ hiển thị tấm ảnh của video đó và link để xem cho mobile.
Code chỉ nhận link video của youtube, các link khác đều không hoạt động.
Nào bắt đầu:
Mở file incfiles\classes\bbcode.php.
Thêm function sau vào trong file này:
''.highlight('/*
-----------------------------------------------------------------
Youtube
-----------------------------------------------------------------
*/
public static function youtube($var)
{
if (!function_exists('process_youtube')) {
function process_youtube($id)
{
global $is_mobile;
if (!$is_mobile)
return '<iframe width="560" height="315" src="http://www.youtube.com/embed/' . $id[4] . '" frameborder="0"></iframe>';
else
return '<a target="_blank" href="http://m.youtube.com/watch?v=' . $id[4] . '"><img src="http://img.youtube.com/vi/' . $id[4] . '/1.jpg" alt=""/></a>';
}
}
return preg_replace_callback('~\\[youtube\\](https?:\/\/|www.)(.*)youtube.com(.*)v=(.*)\/?\\[/youtube\\]~i', 'process_youtube', $var);
}').''
Tiếp tục thêm vào bên trong funct này:
''.highlight('public static function tags($var) {').''
dòng sau:
''.highlight('$var = self::youtube($var);').''
Thứ tự hiển thị tốt nhất là như sau:
''.highlight('$var = self::youtube($var);
$var = self::highlight_url($var);
$var = self:
LD_highlight_url($var);').''
Vậy là xong. code của bạn đã hoạt động. Test luôn đê
Tính năng cho PC và Mobile:
+ Khi truy cập bằng pc sẽ hiển thị video bạn nhúng.
+ Khi truy cập bằng mobile sẽ hiển thị tấm ảnh của video đó và link để xem cho mobile.
Code chỉ nhận link video của youtube, các link khác đều không hoạt động.
Nào bắt đầu:
Mở file incfiles\classes\bbcode.php.
Thêm function sau vào trong file này:
''.highlight('/*
-----------------------------------------------------------------
Youtube
-----------------------------------------------------------------
*/
public static function youtube($var)
{
if (!function_exists('process_youtube')) {
function process_youtube($id)
{
global $is_mobile;
if (!$is_mobile)
return '<iframe width="560" height="315" src="http://www.youtube.com/embed/' . $id[4] . '" frameborder="0"></iframe>';
else
return '<a target="_blank" href="http://m.youtube.com/watch?v=' . $id[4] . '"><img src="http://img.youtube.com/vi/' . $id[4] . '/1.jpg" alt=""/></a>';
}
}
return preg_replace_callback('~\\[youtube\\](https?:\/\/|www.)(.*)youtube.com(.*)v=(.*)\/?\\[/youtube\\]~i', 'process_youtube', $var);
}').''
Tiếp tục thêm vào bên trong funct này:
''.highlight('public static function tags($var) {').''
dòng sau:
''.highlight('$var = self::youtube($var);').''
Thứ tự hiển thị tốt nhất là như sau:
''.highlight('$var = self::youtube($var);
$var = self::highlight_url($var);
$var = self:
![](https://ovigame.ngatngay.net/images/smileys/simply/O.png)
Vậy là xong. code của bạn đã hoạt động. Test luôn đê
Bạn vui lòng Like bài viết để không xem được nội dung