SMF Development > SMF Coding Discussion

มาทำปุ่ม YouTube BBCode กัน

(1/2) > >>

chaotoob.com:
มาทำปุ่ม YouTube BBCode  ติดตั้งแบบ manual

--- อ้างถึง ---http://custom.simplemachines.org/mods/index.php?mod=936
--- ปิดอ้างถึง ---

เริ่มกันเลย

File Edits

เปิด ./Sources/Subs.php

หา Code นี้

--- โค้ด: ---array(
'tag' => 'white',
'before' => '<span style="color: white;">',
'after' => '</span>',
),

--- ปิดโค้ด ---

Copy Code นี้ไปวางไว้หลังที่ให้หา


--- โค้ด: ---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',
            ),

--- ปิดโค้ด ---

หา Code นี้


--- โค้ด: --- $disabled['email'] = true;
$disabled['flash'] = true;


--- ปิดโค้ด ---

Copy Code นี้ไปวางไว้หลังที่ให้หา


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

--- ปิดโค้ด ---

เปิด ./Themes/default/Post.template.php

หา Code นี้


--- โค้ด: ---'flash' => array('code' => 'flash',
--- ปิดโค้ด ---

Copy Code นี้ไปวางก่อนหน้าที่ให้หา


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

--- ปิดโค้ด ---

เปิด ./Themes/default/languages/Modifications.english.php

หา Code นี้


--- โค้ด: ---?>
--- ปิดโค้ด ---

Copy Code นี้ไปวางก่อนหน้าที่ให้หา


--- โค้ด: ---$txt['youtube'] = 'YouTube';
$txt['youtube_invalid'] = '#Invalid YouTube Link#';

--- ปิดโค้ด ---

สุดท้ายCopy Icon "youtube.gif" ไปไว้ใน"./Themes/default/images/bbc ก็เป็นอันเสร็จสิ้น

ก็จะได้แบบนี้

Fansai:
ทำตามทุกขั้นตอนแล้ว แต่รูปมันเสียนะครับ ช่วยหน่อยนะ

chaotoob.com:
ดาวน์โหลดรูปที่แนบให้ไปไว้แล้วหรือยังครับ
Icon "youtube.gif" ไปไว้ใน"./Themes/default/images/bbc ก็เป็นอันเสร็จสิ้น

Fansai:
เอาไปไว้ตามที่บอกแล้วครับ แต่มันก็ยังขึ้นอยู่

chaotoob.com:
ลองคลิกขวาดูที่รูปนะครับ (คลิกขาวที่รูปแล้วเลือกProperties ดูว่ามันอยู่ตำแหน่งไหน แล้วก็เอารูปไปไว้ตามตำแหน่งที่มันฟ้อง เช่น http://?????????.com/Themes/default/images/bbc/youtube.gif)

ออ...แล้วได้ใช้ธีม default หรือเปล่า ถ้าใช้ธีมไหนก็เอาไปไว้ในธีมนั้นๆนะครับ ใน Folder bbc

นำร่อง

[0] ดัชนีข้อความ

[#] หน้าถัดไป

ไปที่เวอร์ชันเต็ม