ผู้เขียน หัวข้อ: ทำให้โพสวีดีโอจาก youtube ได้,YouTube BBCode SMF 2.0.2  (อ่าน 3942 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ Admin

  • Administrator
  • *****
  • กระทู้: 1415
  • Level:
    0%
  • Thank : 61
  • เพศ: ชาย
    • ดูรายละเอียด
    • สะกิดข่าว
ทำให้โพสวีดีโอจาก youtube ได้,YouTube BBCode SMF 2.0.2
« เมื่อ: ตุลาคม 13, 2012, 11:46:21 pm »
ทำ SMF ให้โพสต์วีดีโอจาก youtube ได้
YouTube BBCode smf 2.0.2 ทดสอบแล้วใช้ได้ 100%
ปกติเว็บบอร์ดของ SMF จะไม่มีออฟชั่นนี้มาให้ ดังนั้นหากเราต้องการจะนำวีดีโอยูทูปมาใส่โชว์ที่เว็บบอร์ดของเรา จึงจำเป็นต้องหา mod มาติดตั้งหรือเพิ่มโค้ดแบบแมนวล manual เอง และโค้ดนี้เป็นแบบ manual คือทำด้วยมือเองครับ


File Edits เปิดไฟล์ที่จะต้องแก้ไข  /Sources/Subs.php

Find : ค้นหา

โค๊ด: [Select]
array(
'tag' => 'white',
'before' => '<span style="color: white;" class="bbc_color">',
'after' => '</span>',
),


Add After : เติมต่อท้ายที่หา

โค๊ด: [Select]
array(
'tag' => 'youtube',
'type' => 'unparsed_content',
'validate' => create_function('&$tag, &$data, $disabled', '
// Access globals
global $txt, $context;
// Determine which variable is the link
$link = !is_array($data) ? $data : $data[0] ;
// Remove linebreaks & trim
$link = trim(strtr($link, array(\'<br />\' => \'\')));
// Parse the ID of video or playlist safely
if  (preg_match(\'~^(?:http://((?:www|au|br|ca|es|fr|de|hk|ie|in|il|it|jp|kr|mx|nl|nz|pl|ru|tw|uk)\.)?youtube\.com/(?:[^"]*?)(?:(?:video_)?id=|(?:v|p)(?:/|=)))?([0-9a-f]{16}|[0-9a-z-_]{11})~i\'.($context[\'utf8\'] ? \'u\' : \'\'), $link, $matches))
{
// Localised youtube site?  If not use www.
$site = !empty($matches[1]) ? strtolower($matches[1]) : \'www.\' ;
// Video or Playlist ID?
$type = strlen($matches[2]) == 11 ? 1 : 0 ;
// Set sizes Or Normalise sizes (If sizes are <100 or > 780)
if(!is_array($data) || ($data[1] > 780 || $data[1] < 100 || $data[2] > 780 || $data[2] < 100))
$data = array(0, 425, ($type ? 350 : 355));
// Set ID in the array
$data[0] = $matches[2];
// Tidy up
unset($matches, $link);

// Set the Content (With conditions on disabled types of BBCode)
if (isset($disabled[\'url\']) && isset($disabled[\'youtube\']))
// Youtube & Url bbc disabled? (eg Printer friendly pages)
$tag[\'content\'] = "http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p") ."=". $data[0];
elseif(isset($disabled[\'youtube\']))
// Only Youtube is disabled, So make an active link
$tag[\'content\'] = "<a href=\"http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p") ."=". $data[0]."\" target=\"_blank\">http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p") ."=". $data[0]."</a>";
else
{
// Empty content
$tag[\'content\'] = \'\';

// Build the <object> (Non-Mac IE Only)
if($context[\'browser\'][\'is_ie\'] && !$context[\'browser\'][\'is_mac_ie\'])
$tag[\'content\'] = \'<object width="\'.$data[1].\'px" height="\'.$data[2].\'px">\'
.\'<param name="movie" value="http://www.youtube.com/\'.($type ? "v" : "p").\'/\'.$data[0].\'&amp;rel=1&amp;fs=1" />\'
.\'<param name="wmode" value="transparent" /><param name="allowFullScreen" value="true" />\'
.\'<param name="allowScriptAccess" value="never" />\';
// Build the <embed>
$tag[\'content\'] .= \'<embed src="http://www.youtube.com/\'.($type ? "v" : "p").\'/\'.$data[0].\'&amp;rel=1&amp;fs=1" \'
.\'type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="never" \'
.\'wmode="transparent" width="\'.$data[1].\'px" height="\'.$data[2].\'px">\';
// Build the <noembed>
$tag[\'content\'] .= "<noembed><a href=\"http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p" ) ."=". $data[0]."\" target=\"_blank\">http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p") ."=". $data[0]."</a></noembed>";
// Closing <embed>
$tag[\'content\'] .= \'</embed>\';
// Close the <object> (Non-Mac IE Only)
if($context[\'browser\'][\'is_ie\'] && !$context[\'browser\'][\'is_mac_ie\'])
$tag[\'content\'] .= \'</object>\';
}
}
else
// Invalid link
$tag[\'content\'] = $txt[\'youtube_invalid\'];
'),
'disabled_content' => '$1',
            ),
array(
'tag' => 'youtube',
'type' => 'unparsed_commas_content',
'test' => '\d+,\d+\]',
'validate' => create_function('&$tag, &$data, $disabled', '
// Access globals
global $txt, $context;
// Determine which variable is the link
$link = !is_array($data) ? $data : $data[0] ;
// Remove linebreaks & trim
$link = trim(strtr($link, array(\'<br />\' => \'\')));
// Parse the ID of video or playlist safely
if  (preg_match(\'~^(?:http://((?:www|au|br|ca|es|fr|de|hk|ie|in|il|it|jp|kr|mx|nl|nz|pl|ru|tw|uk)\.)?youtube\.com/(?:[^"]*?)(?:(?:video_)?id=|(?:v|p)(?:/|=)))?([0-9a-f]{16}|[0-9a-z-_]{11})~i\'.($context[\'utf8\'] ? \'u\' : \'\'), $link, $matches))
{
// Localised youtube site?  If not use www.
$site = !empty($matches[1]) ? strtolower($matches[1]) : \'www.\' ;
// Video or Playlist ID?
$type = strlen($matches[2]) == 11 ? 1 : 0 ;
// Set sizes Or Normalise sizes (If sizes are <100 or > 780)
if(!is_array($data) || ($data[1] > 780 || $data[1] < 100 || $data[2] > 780 || $data[2] < 100))
$data = array(0, 425, ($type ? 350 : 355));
// Set ID in the array
$data[0] = $matches[2];
// Tidy up
unset($matches, $link);

// Set the Content (With conditions on disabled types of BBCode)
if (isset($disabled[\'url\']) && isset($disabled[\'youtube\']))
// Youtube & Url bbc disabled? (eg Printer friendly pages)
$tag[\'content\'] = "http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p") ."=". $data[0];
elseif(isset($disabled[\'youtube\']))
// Only Youtube is disabled, So make an active link
$tag[\'content\'] = "<a href=\"http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p") ."=". $data[0]."\" target=\"_blank\">http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p") ."=". $data[0]."</a>";
else
{
// Empty content
$tag[\'content\'] = \'\';

// Build the <object> (Non-Mac IE Only)
if($context[\'browser\'][\'is_ie\'] && !$context[\'browser\'][\'is_mac_ie\'])
$tag[\'content\'] = \'<object width="\'.$data[1].\'px" height="\'.$data[2].\'px">\'
.\'<param name="movie" value="http://www.youtube.com/\'.($type ? "v" : "p").\'/\'.$data[0].\'&amp;rel=1&amp;fs=1" />\'
.\'<param name="wmode" value="transparent" /><param name="allowFullScreen" value="true" />\'
.\'<param name="allowScriptAccess" value="never" />\';
// Build the <embed>
$tag[\'content\'] .= \'<embed src="http://www.youtube.com/\'.($type ? "v" : "p").\'/\'.$data[0].\'&amp;rel=1&amp;fs=1" \'
.\'type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="never" \'
.\'wmode="transparent" width="\'.$data[1].\'px" height="\'.$data[2].\'px">\';
// Build the <noembed>
$tag[\'content\'] .= "<noembed><a href=\"http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p" ) ."=". $data[0]."\" target=\"_blank\">http://". $site ."youtube.com/". ($type ? "watch?v" : "view_play_list?p") ."=". $data[0]."</a></noembed>";
// Closing <embed>
$tag[\'content\'] .= \'</embed>\';
// Close the <object> (Non-Mac IE Only)
if($context[\'browser\'][\'is_ie\'] && !$context[\'browser\'][\'is_mac_ie\'])
$tag[\'content\'] .= \'</object>\';
}
}
else
// Invalid link
$tag[\'content\'] = $txt[\'youtube_invalid\'];
'),
'disabled_content' => '$1',
),

Find:ค้นหา
โค๊ด: [Select]

$disabled['email'] = true;
$disabled['flash'] = true;

Add After : เติมต่อท้ายที่หา

โค๊ด: [Select]
// Disable youtube if on 'printer friendly page'
$disabled['youtube'] = true;

File Edits เปิดไฟล์ที่จะต้องแก้ไข /Sources/Subs-Editor.php

Find : ค้นหา

โค๊ด: [Select]
array(
'image' => 'flash',
'code' => 'flash',
'before' => '[flash=200,200]',
'after' => '[/flash]',
'description' => $txt['flash']
),

Add Before : วางก่อนหน้าที่หา

โค๊ด: [Select]
array(
'image' => 'youtube',
'code' => 'youtube',
'before' => '[youtube]',
'after' => '[/youtube]',
'description' => $txt['youtube']
),


File Edits เปิดไฟล์ที่จะต้องแก้ไข Themes/default/languages/Modifications.thai-utf8.php
หรือถ้าเป็นอังกฤษก็ Modifications.english.php

Find (at the end of the file): ค้นหาแท็กปิดตัวสุดท้าย

โค๊ด: [Select]
?>

Add Before: เพิ่มโค้ดนี้ไว้ก่อน tag ปิดของ php

โค๊ด: [Select]
$txt['youtube'] = 'YouTube';
$txt['youtube_invalid'] = '#ลิงค์ของ YouTube ไม่ถูกต้อง#';


อัพโหลดรูป  "youtube.gif" ไปไว้ใน Themes/default หรือธีมที่ใช้ในปัจจุบัน/images/bbc

วิธีใช้งาน เมื่อคลิ๊กที่รูป Youtube ตรงคอมเม้นแล้วจะได้ #ลิ้งค์ของ Youtube ไม่ถูกต้อง#

นี่คือ URL ที่เราต้องการ

youtube.com/watch?v=BYoFiNNA8Aw

ให้นำ URL ตรงสีแดงมาใส่ตรงกลางของ Tag Youtube จะได้เป็น

โค๊ด: [Select]
[youtube]BYoFiNNA8Aw[/youtube]
ได้สมบูรณ์

 
แชร์บทความ...
โค้ดแบบ forum
(BBCode)
โค้ดแบบ site/blog
(HTML)