Video Url Embed Script v1
I wanted to test out some OOP(Object Oriented Programming) in PHP so I created a video embed class.
To embed a video from youtube, google video, revver, or metacafe simply use this template:
Here is a temporary demo page: [url]http://1.nystic.com/t3h_bin/oop/video_embed.php/url]
Instead of adding embed code for each one I used a one line function with the url in it:
- Code: Select all
class video_embed{
var $raw;
var $code;
var $host = "";
var $error = false;
function embed($raw)
{
//clean the rawdata
$raw = trim($raw);
//get the code
$hosts = array("http://youtube.com/watch?v=", "http://video.google.com/videoplay?docid=-",
"http://one.revver.com/watch/", "http://www.metacafe.com/watch/");
$code = str_replace($hosts, "", $raw);
//find host
$host1 = strpos($raw, "youtube.com", 1);
$host2 = strpos($raw, "video.google.com", 1);
$host3 = strpos($raw, "one.revver.com", 1);
$host4 = strpos($raw, "www.metacafe.com", 1);
if($host1 != null) {$host .= "youtube";}
if($host2 != null) {$host .= "google";}
if($host3 != null) {$host .= "revver";}
if($host4 != null) {$host .= "metacafe";}
//error
if($host != "youtube" && $host != "google" && $host != "revver" && $host != "metacafe")
{
$error = true;
echo "Error Embedding ";
}
if($host == "youtube")
{
echo "
<object width='425' height='353'><param name='movie' value='http://www.youtube.com/v/$code'></param>
<param name='wmode' value='transparent'></param>
<embed src='http://www.youtube.com/v/$code' type='application/x-shockwave-flash' wmode='transparent' width='425' height='353'>
</embed></object><br/>";
}
if($host == "google")
{
echo "
<embed style='width:400px; height:326px;' id='VideoPlayback' type='application/x-shockwave-flash'
src='http://video.google.com/googleplayer.swf?docId=-$code&hl=en' flashvars=''></embed><br/><br/>";
}
if($host == "revver")
{
//clean the code
$code = str_replace("/flv", "", $code);
echo "<script src='http://flash.revver.com/player/1.0/player.js?mediaId:$code;affiliateId:0;height:392;width:480;' type='text/javascript'>
</script><br/>";
}
if($host == "metacafe")
{
//clean the code
$code = strrev($code);
$code = trim($code, "/");
$code = strrev($code);
echo "<embed src='http://www.metacafe.com/fplayer/$code.swf'
width='400' height='345' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer'
type='application/x-shockwave-flash'> </embed><br>";
}
}
}
To embed a video from youtube, google video, revver, or metacafe simply use this template:
- Code: Select all
$video=new video_embed();
$video->embed("video url or permalink");
Here is a temporary demo page: [url]http://1.nystic.com/t3h_bin/oop/video_embed.php/url]
Instead of adding embed code for each one I used a one line function with the url in it:
- Code: Select all
$video=new video_embed();
$video->embed("http://youtube.com/watch?v=MgV0PjNw3Qw");
$video->embed("http://video.google.com/videoplay?docid=-6511716987227605917");
$video->embed("http://one.revver.com/watch/421951");
$video->embed("http://one.revver.com/watch/421951/flv");
$video->embed("http://www.metacafe.com/watch/854726/photoshop_match_color_simple_and_amazing_results/");