Yazdığım birkaç scriptte kullandığım bu fonksiyonu şöyle kullandırtıyordum
kontrol panelinden video linki ve video tipi (youtube,google vs.) girildiğinde
Video URL'sini ve tipini veritabanına kaydediyor, videolar sayfasındaysa aşağıda
vereceğim fonksiyonla video, embed kodu gibi çıkıyor..
Fonksiyon:
Kullanımı:
Çıkış
kontrol panelinden video linki ve video tipi (youtube,google vs.) girildiğinde
Video URL'sini ve tipini veritabanına kaydediyor, videolar sayfasındaysa aşağıda
vereceğim fonksiyonla video, embed kodu gibi çıkıyor..
Fonksiyon:
PHP:
# Silverday @ Hackhell #
function EmbedIt($url, $type, $w="400", $h="326") {
// @Params : Video Url : Video Type
// @type
// 0 => Google Video
// 1 => Youtube
// 2 => MetaCafe
// @url
// Input Url
// @w - @h
// Width - Height (px)
switch($type) {
case "1"; $regexp = '#(?:<\>]+href=\")?(?:http://)?((?:[a-zA-Z]{1,4}\.)?youtube.com/(?:watch)?\?v=(.{11}?))[^"]*(?:\"[^\<\>]*>)?([^\<\>]*)(?:)?#';break;
case "2": $regexp = '#metacafe.com/watch/([0-9]+)/([A-Za-z0-9_]+)#';break;
default: $regexp = '#(?:<\>]+href=\")?(?:http://)?(video.google.(?:[A-Za-z\.]{2,5})/videoplay\?docid=([0-9\-]+)(?:[^"]+)?)[^"]*(?:\"[^\<\>]*>)?([^\<\>]*)(?:)?#';
}
preg_match($regexp, $url, $match);
if(count($match) != 0) {
switch($type) {
case "1": $vid = $match['2'];$embed = '<object width="'.$w.'" height="'.$h.'"><param name="movie" value="http://www.youtube.com/v/'.$vid.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$vid.'" type="application/x-shockwave-flash" wmode="transparent" width="'.$w.'" height="'.$h.'"></embed></object>';break;
case "2": $vid = $match['1'];$embed = '<embed src="http://www.metacafe.com/fplayer/'.$vid.'/'.str_replace(array("/",$vid),array("",""),$match['2']).'.swf" width="'.$w.'" height="'.$h.'" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_'.$vid.'"> </embed>';break;
default: $vid = $match['2'];$embed = "<embed id=VideoPlayback src=http://video.google.com/googleplayer.swf?docid=".$vid."&hl=tr&fs=true style=width:".$w."px;height:".$h."px allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash> </embed>";
}
return $embed;
}
else {
return false;
}
}
Kullanımı:
PHP:
// URL Tipleri
// 0: Google Video, 1: Youtube, 2: Metacafe
$url = "http://www.youtube.com/watch?v=zEuZc_dn-oI";
print EmbedIt($url, "1");
Çıkış
HTML:
<object width="400" height="326"><param name="movie" value="http://www.youtube.com/v/zEuZc_dn-oI"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/zEuZc_dn-oI" type="application/x-shockwave-flash" wmode="transparent" width="400" height="326"></embed></object>