![]() |
|
Multiple Video Service Support from one bbcode! - Printable Version +- Anarchy Live (https://anarchylive.com) +-- Forum: Other (https://anarchylive.com/forumdisplay.php?fid=19) +-- Thread: Multiple Video Service Support from one bbcode! (/showthread.php?tid=460) |
Multiple Video Service Support from one bbcode! - CJ Jackson - 12-14-2009 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 Multiple Video Service Support from one bbcode! - Gnashvar - 12-14-2009 Members · 1,324 posts · joined 27-November 07 Thanks for sharing I'm not sure how to implement this to the forum, so I'll tell ryder to take a look.
Multiple Video Service Support from one bbcode! - CJ Jackson - 12-15-2009 Members · 150 posts · joined 26-November 07 Gnashvar, on Dec 14 2009, 06:47 PM, said: Thanks for sharing I'm not sure how to implement this to the forum, so I'll tell ryder to take a look.You welcome! I just release my first plugin for mybb. http://mods.mybboard...w/autoembed-api
Multiple Video Service Support from one bbcode! - Streaking Guy - 12-15-2009 Members · 458 posts · joined 26-November 07 That's really neat. Multiple Video Service Support from one bbcode! - CJ Jackson - 12-29-2009 Members · 150 posts · joined 26-November 07 Here a new version under a New BSD License, a lot more has been done. =) <?php /** * Autoembed MyCode Plugin for MyBB * Allows multiple video services to be embedded by just one tag [vid][/vid] * * Copyright © 2009, Christopher John Jackson * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the cj-jackson.com nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 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('toolbar_container_collect', 'autoembed_collect'); $plugins->add_hook("parse_message", "autoembed_mycode"); $plugins->add_hook("pre_output_page", "autoembed_javascript"); function autoembed_info() { return array( "name" => "Autoembed MyCode Plugin for MyBB", "description" => "Allows multiple videos services to be embedded by just one tag [vid][/vid]'", "website" => "http://www.autoembed.com/", "author" => "Christopher John Jackson", "authorsite" => "http://cj-jackson.com/", "version" => "1.3.0", "guid" => "a1f7fb491448e5b0300944ab4f6371f6", "compatibility" => "*" ); } function autoembed_activate() { //Do nothing } function autoembed_deactivate() { //Do nothing } class AutoEmbedMyBB { private $_width; private $_height; private $_url; private $_data; private $_AE; public function __construct() { if(file_exists(MYBB_ROOT."AutoEmbed.class.php")) { include_once MYBB_ROOT."AutoEmbed.class.php"; $this->_AE = new AutoEmbed(); } else { $this->_AE = false; } } public function setData($data){ $this->_data = $data; } public function mycodeReplace() { $data = $this->_data; $data = preg_replace_callback("#\[vid\](.+?)\[/vid\]#i", array(&$this,"_embedVideo"), $data); $data = preg_replace_callback("#\[vid ([0-9]{1,3}?)x([0-9]{1,3}?)\](.+?)\[/vid\]#i", array(&$this,"_embedVideoBySize"), $data); $this->_data = $data; return $this->_data; } private function _embedVideo($matches) { $this->_width = -1; $this->_height = -1; $this->_url = $matches[1]; return $this->_getHTMLcode(); } private function _embedVideoBySize($matches) { $this->_width = $matches[1]; $this->_height = $matches[2]; $this->_url = $matches[3]; $this->_checkSize(); return $this->_getHTMLcode(); } private function _checkSize() { if($this->_width < 240 || $this->_height < 240 || $this->_width > 860 || $this->_height > 600){ $this->_width = -1; $this->_height = -1; } } private function _getHTMLcode() { if(!preg_match("#(^http://|^https://)#i",$this->_url)) { return $this->_errorHandler("Not a valid URL"); } if($this->_jwplayerCompatibilityCheck()) { $data = $this->_getJWPlayerCode(); } elseif($this->_windowsMediaCompatibilityCheck()) { $data = $this->_getWindowsMediaCode(); } else { $data = $this->_getAutoEmbedCode(); } return '<div class="autoembed">'.$data.'</div>'; } private function _jwplayerCompatibilityCheck() { $swfPlayerExists = file_exists(MYBB_ROOT."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; } private function _windowsMediaCompatibilityCheck() { $wmPlayerExists = file_exists(MYBB_ROOT."wmvplayer.xaml"); $fileinfo = parse_url($this->_url); $fileinfo = pathinfo($fileinfo['path']); $extention = $fileinfo['extension']; if(preg_match("#^(wmv|wma|asf)$#i",$extention)){ $fileCompatible = true; if(preg_match("#^(wma)$#i",$extention)){ $this->_width = 300; $this->_height = 20; } } else { $fileCompatible = false; } return $wmPlayerExists && $fileCompatible; } private function _errorHandler($string) { $uri = $_SERVER['REQUEST_URI']; if(preg_match("#(processed=1$)#i",$uri)){ return $string; } else { return "..."; } } private function _getJWPlayerCode() { if($this->_width == -1){ $this->_width = 425; $this->_height = 344 + 24; } else { $this->_height = $this->_height + 24; } $image = $this->_url.".jpg"; $image = preg_replace("#^http://#","http/",$image); $image = preg_replace("#^https://#","https/",$image); $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="flashvars" value="file='.urlencode($this->_url).'&image=imagepreview.php/'.$image.'" />'; $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 .= 'allowfullscreen="true" '; $data .= 'flashvars="file='.urlencode($this->_url).'&image=imagepreview.php/'.$image.'" '; $data .= '/>'; $data .= '</object>'; return $data; } private function _getWindowsMediaCode() { if($this->_width == -1){ $this->_width = 425; $this->_height = 344 + 20; } else { $this->_height = $this->_height + 20; } $image = $this->_url.".jpg"; $image = preg_replace("#^http://#","http/",$image); $image = preg_replace("#^https://#","https/",$image); $hash = hash('ripemd160',microtime()); $data = '<div name="'.$hash.'" id="'.$hash.'"></div>'; $data .= '<script type="text/javascript">'; $data .= 'var cnt = document.getElementById("'.$hash.'");'; $data .= 'var src = \'wmvplayer.xaml\';'; $data .= 'var cfg = {'; $data .= ' file:\''.$this->_url.'\','; $data .= ' image:\'imagepreview.php/'.$image.'\','; $data .= ' height:\''.$this->_height.'\','; $data .= ' width:\''.$this->_width.'\''; $data .= '};'; $data .= 'var ply = new jeroenwijering.Player(cnt,src,cfg);'; $data .= '</script> '; return $data; } private function _getAutoEmbedCode() { if($this->_AE){ if($this->_AE->parseUrl($this->_url)){ if($this->_width != -1){ $this->_AE->setWidth($this->_width); $this->_AE->setHeight($this->_height); } $thestub = $this->_AE->getStub(); if($thestub['title'] != 'Last.fm (Audio)'){ $this->_AE->setParam('wmode','window'); $this->_AE->setObjectParam('wmode','window'); } $data = $this->_AE->getEmbedCode(); $data .= "<!-- Autoembed Class -->"; } else { $data = ""; } } else { $data = file_get_contents("http://autoembed.com/api/index.php?url=".urlencode($this->_url)); if($data != "") { if(!preg_match("#last\.fm/webclient#",$data)){ $data = str_replace("transparent","window",$data); } if($this->_width != -1){ $data = preg_replace("#width=\"([0-9]+)\"#","width=\"".$this->_width."\"",$data); $data = preg_replace("#height=\"([0-9]+)\"#","height=\"".$this->_height."\"",$data); } $data .= "<!-- Autoembed API -->"; } } if($data == "") { $data = '<a href="'.urlencode($this->url).'">'.urlencode($this->url).'</a>'; } return $data; } } function autoembed_mycode($message) { $autoembedmycode = new AutoEmbedMyBB(); $autoembedmycode->setData($message); return $autoembedmycode->mycodeReplace(); } function autoembed_javascript($page) { if(file_exists(MYBB_ROOT."wmvplayer.xaml")) { $page = str_replace("</head>","<script type='text/javascript' src=\"jscripts/silverlight.js\"></script>\n<script type='text/javascript' src=\"jscripts/wmvplayer.js\"></script>\n</head>",$page); } return $page; } function autoembed_collect(&$ic) { $callback = " var ask_loc = prompt('Enter a url from video sharing site such as youtube or directly to a video file URL\\ne.g http://www.youtube.com/watch?v=xxxxxx or http://www.example.com/video.mp4', ''); if (ask_loc == null) return; var ask_resolution = prompt('Enter resolution eg: 800x600, if you do wish to specify then click cancel or leave blank!', ''); var if_resolution = ask_resolution.match(/(^[0-9]{1,3})x([0-9]{1,3}$)/); if ((ask_resolution != null || ask_resolution != '') && if_resolution != null){ clickableEditor.performInsert('[vid ' + ask_resolution + ']' + ask_loc + '[/vid]', '', true, false); } else { clickableEditor.performInsert('[vid]' + ask_loc + '[/vid]', '', true, false); } "; $toolbar = array( 'id' => 'autoembed', 'name' => 'autoembed', 'image' => 'autoembed.gif', 'callback' => $callback, 'title' => 'Embed video from sharing site from URL' ); $ic->collect_item($toolbar); } ?> Multiple Video Service Support from one bbcode! - CJ Jackson - 01-02-2010 Members · 150 posts · joined 26-November 07 I just created the wordpress version. ![]() http://file.therocke...0-wordpress.zip |