PhaxeNor wrote:Gizzmo wrote:wouldn't it be simpler to just use [video] and have it detect what player to use via the url?
yea, some coding but it should work. Will add it to the list and try get it working.
Just wondering if you're still aiming to do this? I could do with a video bbcode for my site, if you're planning on making it work using just [video] then that is great, otherwise I'll code my own that does.
Cheers
Edit: Nevermind, decided to edit your code myself because I was bored
Here is the updated code, also with a few security issues fixed, and I renamed your hook to follow guidelines (should start with xn_).
<?xml version="1.0" encoding="UTF-8"?>
<extension engine="1.0">
<id>video_bbcode</id>
<title>VideoBBCodes</title>
<version>1.1.2</version>
<description>Adds VideoBBCodes to allow video embeding on your forum.</description>
<author>PhaxeNor, Lamonte Harris</author>
<minversion>1.3 Beta</minversion>
<maxtestedon>1.3 Beta</maxtestedon>
<hooks>
<hook id="ps_start"><![CDATA[
function do_video($url)
{
//custom hook if you want to add your own video parser
($hook = get_hook('xn_video_bbcode_parser')) ? eval($hook) : null;
if(preg_match('#http://www\.videovat\.com/videos/(\d+)/.*#', $url, $matches))
return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="424" height="373" id="videovatPlayer"><param name="allowScriptAccess" value="always" /><param name="movie" value="http://www.videovat.com/videoPlayer.swf" /><param name="quality" value="high" /><param name="flashvars" value="videoId='.forum_htmlencode($matches[1]).'" /><param name="allowFullscreen" value="true" /><param name="wmode" value="transparent" /><embed src="http://www.videovat.com/videoPlayer.swf" quality="high" wmode="transparent" flashvars="videoId=16816" width="424" height="373" name="videovatPlayer" align="middle" allowScriptAccess="always" allowFullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></embed></object>';
else if(preg_match('#http://.*youtube\.com/watch\?v=(\w+)#s', $url, $matches))
return '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/'.forum_htmlencode($matches[1]).'" /><param name="wmode" value="transparent" /><embed src="http://www.youtube.com/v/'.forum_htmlencode($matches[1]).'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
else if(preg_match('#http://www\.veoh\.com/videos/(.*)#', $url, $matches))
return '<embed src="http://www.veoh.com/videodetails2.swf?permalinkId='.forum_htmlencode($matches[1]).'&id=anonymous&player=videodetailsembedded&videoAutoPlay=0" allowFullScreen="true" width="540" height="438" bgcolor="#FFFFFF" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
else if(preg_match('#http://tinypic\.com/player\.php\?v=(.*)#s', $url, $matches))
return '<embed width="440" height="380" type="application/x-shockwave-flash" src="http://v3.tinypic.com/player.swf?file='.forum_htmlencode($matches[1]).'"></embed>';
else if(preg_match('#http://www\.metacafe\.com/watch/(\d+)/(.*)/#', $url, $matches))
return '<embed src="http://www.metacafe.com/fplayer/'.forum_htmlencode($matches[1]).'/'.forum_htmlencode($matches[2]).'.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';
else if(preg_match('#http://www\.gametrailers\.com/player/(\d+)\.html#s', $url, $matches))
return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="gtembed" width="480" height="392"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /> <param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid='.forum_htmlencode($matches[1]).'"/> <param name="quality" value="high" /> <embed src="http://www.gametrailers.com/remote_wrap.php?mid='.forum_htmlencode($matches[1]).'" swLiveConnect="true" name="gtembed" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="480" height="392"></embed> </object>';
else if(preg_match('#http://video.yahoo.com/watch/(\d+)/(\d+)#', $url, $matches))
return '<object width="512" height="323"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.2" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="id='.forum_htmlencode($matches[2]).'&vid='.forum_htmlencode($matches[1]).'&lang=en-us&intl=us&embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.2" type="application/x-shockwave-flash" width="512" height="323" allowFullScreen="true" flashVars="id='.forum_htmlencode($matches[2]).'&vid='.forum_htmlencode($matches[1]).'&lang=en-us&intl=us&embed=1" ></embed></object>';
else if(preg_match('#http://v\.youku\.com/v_show/id_ca00XMj([a-zA-Z0-9]+)=\.html#s', $url, $matches))
return '<embed src="http://player.youku.com/player.php/sid/XMj'.forum_htmlencode($matches[1]).'=/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>';
else if(preg_match('#http://vids\.myspace\.com/index\.cfm\?fuseaction=vids\.individual\&VideoID=(\d+)#s', $url, $matches))
return '<embed pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://lads.myspace.com/videos/vplayer.swf" width="430" height="346" type=application/x-shockwave-flash allownetworking="internal" allowscriptaccess="never" flashvars="m='.forum_htmlencode($matches[1]).'&v=2&type=video" wmode="opaque">';
else if(preg_match('#http://video\.google\.com/videoplay\?docid=(-?\d+)(.*)?#s', $url, $matches))
return '<embed id="VideoPlayback" style="width:400px;height:326px" flashvars="" src="http://video.google.com/googleplayer.swf?docid='.forum_htmlencode($matches[1]).'&hl=en" type="application/x-shockwave-flash"></embed>';
else if(preg_match('#http://www\.dailymotion\.com/video/(.*?)_#', $url, $matches))
return '<object width="520" height="406" align="top" data="http://www.dailymotion.com/swf/'.forum_htmlencode($matches[1]).'.swf" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://www.dailymotion.com/swf/'.forum_htmlencode($matches[1]).'.swf" /><param name="quality" value="best" /><embed src="http://www.dailymotion.com/swf/'.forum_htmlencode($matches[1]).'" width="520" height="406" quality="best" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></embed></object>';
else if(preg_match('#http://www\.collegehumor\.com/video:([0-9]+)#', $url, $matches))
return '<object id="video_1820056" type="application/x-shockwave-flash" data="http://www.collegehumor.com/moogaloop/moogaloop.internal.swf?clip_id='.forum_htmlencode($matches[1]).'&autostart=true&fullscreen=1" width="480" height="360"><param name="allowfullscreen" value="true" /><param name="movie" quality="best" value="http://www.collegehumor.com/moogaloop/moogaloop.internal.swf?clip_id='.forum_htmlencode($matches[1]).'&autostart=true&fullscreen=1" /></object>';
else if(preg_match('#http://www\.vimeo\.com/([0-9]+)#', $url, $matches))
return '<object class="swf_holder" type="application/x-shockwave-flash" width="506" height="382" data="http://www.vimeo.com/moogaloop_local.swf?clip_id='.forum_htmlencode($matches[1]).'&server=www.vimeo.com&autoplay=0&fullscreen=1&show_portrait=0&show_title=0&show_byline=0&md5=&color=&context=&context_id=&hd_off=0"><param name="quality" value="high" /><param name="allowfullscreen" value="true" /><param name="AllowScriptAccess" value="always" /><param name="scale" value="showAll" /><param name="movie" value="http://www.vimeo.com/moogaloop_local.swf?clip_id='.forum_htmlencode($matches[1]).'&server=www.vimeo.com&autoplay=0&fullscreen=1&show_portrait=0&show_title=0&show_byline=0&md5=&color=&context=&context_id=&hd_off=0" /></object>';
else
return forum_htmlencode($url);
}
]]></hook>
<hook id="ps_preparse_tags_start"><![CDATA[
$tags[] = 'video';
$tags_opened[] = 'video';
$tags_closed[] = 'video';
]]></hook>
<hook id="ps_do_bbcode_replace"><![CDATA[
$pattern[] = '#\[video\](.+)\[/video\]#e';
$replace[] = 'do_video(\'$1\')';
]]></hook>
</hooks>
</extension>
Might also be a good idea to make it add the [video] to the help page, though I can't be bothered doing that for you 
Edit: Also added support for collegehumor and vimeo.
Last edited by Reines (2008-06-24 21:15:35)