Members · 150 posts · joined 26-November 07
I been working on a script using PHP 5 that allows multiple video service to be used from just one tag, yes similar to how the [vid] tag works over at A@H the only different is that the script uses an API from autoembed.com and also the flash jwplayer if detected by the script, anyway here a script that I made for mybb (best open source forum yet) and I'm sure ryder will be able to rewire the code to work with IPB and PHP4. I have tested this over at
http://forums.cj-jac...d-4-post-6.html , so have a look for yourself. Save you from using different video tags!
<?php
/**
* Autoembed.com API
* Allows multiple video services to be embed by just one tag [vid][/vid]
*
* Copyright � 2009 Christopher John Jackson, All Right Reserved
* Website:
http://cj-jackson.com
* License:
http://www.gnu.org/licenses/gpl-3.0.html
*/
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("parse_message", "autoembed_mycode");
function autoembed_info()
{
return array(
"name" => "Autoembed.com API",
"description" => "Allows multiply video services to be embed by just one tag [vid][/vid]'",
"website" => "http://cj-jackson.com",
"author" => "Christopher John Jackson",
"authorsite" => "http://cj-jackson.com",
"version" => "1.0",
"guid" => "a1f7fb491448e5b0300944ab4f6371f6",
"compatibility" => "*"
);
}
function autoembed_activate()
{
//Do nothing
}
function autoembed_deactivate()
{
//Do nothing
}
class autoembed
{
private $width;
private $height;
private $url;
public function __construct($width, $height, $url)
{
$this->width = $width;
$this->height = $height + 24;
$this->url = $url;
}
public function embed()
{
if($this->directCompatibilityCheck())
{
$data = '<object id="player" classid="clsid

27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="'.$this->width.'" height="'.$this->height.'">';
$data .= '<param name="movie" value="jwplayer.swf" />';
$data .= '<param name="allowfullscreen" value="true" />';
$data .= '<param name="allowscriptaccess" value="always" />';
$data .= '<param name="flashvars" value="file='.urlencode($this->url).'" />';
$data .= '<embed ';
$data .= 'type="application/x-shockwave-flash" ';
$data .= 'id="player2" ';
$data .= 'name="player2" ';
$data .= 'src="jwplayer.swf" ';
$data .= 'width="'.$this->width.'" ';
$data .= 'height="'.$this->height.'" ';
$data .= 'allowscriptaccess="always" ';
$data .= 'allowfullscreen="true" ';
$data .= 'flashvars="file='.urlencode($this->url).'" ';
$data .= '/>';
$data .= '</object>';
} else {
$data = implode("", file("http://autoembed.com/api/index.php?url=".urlencode($this->url)));
if($data == "")
{
$data = '<a href="'.$this->url.'">'.$this->url.'</a>';
}
}
return $data;
}
private function directCompatibilityCheck()
{
$swfPlayerExists = file_exists("jwplayer.swf");
$fileinfo = parse_url($this->url);
$fileinfo = pathinfo($fileinfo['path']);
$extention = $fileinfo['extension'];
if(preg_match("#(^flv$|^f4v$|^mp4$|^m4a$|^m4v$|^aac$|^mp3$)#i",$extention)){
$fileCompatible = true;
if(preg_match("#(^m4a$|^aac$|^mp3$)#i",$extention)){
$this->width = 300;
$this->height = 24;
}
} else {
$fileCompatible = false;
}
return $swfPlayerExists && $fileCompatible;
}
}
function autoembed_mycode($message)
{
$message = preg_replace_callback("#\[vid\](.*?)\[/vid\]#i", "embedVideo", $message);
$message = preg_replace_callback("#\[vid ([0-9]{2,3})x([0-9]{2,3})\](.*?)\[/vid\]#i", "embedVideoSize", $message);
return $message;
}
function embedVideo($matches)
{
$embedVideo = new autoembed(640, 480, $matches[1]);
return $embedVideo->embed();
}
function embedVideoSize($matches)
{
$embedVideo = new autoembed($matches[1], $matches[2], $matches[3]);
return $embedVideo->embed();
}
?>
API are the future, enjoy!
This post has been edited by CJ Jackson: 15 December 2009 - 11:24 AM