video plugin by Jason Byrne
Embed video into the page
Last updated on 2005-10-18. Provides Syntax.
No compatibility info given!
Similar to dailymotion, flashplayer, flowplay, flowplay2, google_video, visio, youtube, youtubev2.
I have been working on making a documentation page for some software I am writing. It seemed logical then that it would be beneficial to have some guided tutorials about how to do certain things in the software. Seeing as I could not find any video capabilities or other plugins for this feature in DokuWiki, I decided to write one!
I borrowed the syntax and some code from the iframe plugin.
{{video>http://www.yourpage.com/yourmovie.avi [width,height]|Alternate text}}
The alternate text is very important because if the browser does not support the embedded video it will show the alt text as a link to the video url so that they can download it.
<?php /** * video: embeds a video * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Jason Byrne <jbyrne@floridascale.com> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); //------------------------[ Settings ] --------------------------------------------- global $js_ok; // enable/disable javascript urls $js_ok = false; /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_video extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author' => 'Jason Byrne', 'email' => 'jbyrne@floridascale.com', 'date' => '2005-10-18', 'name' => 'video', 'desc' => 'Embeds video into a page', 'url' => 'http://www.dokuwiki.org/plugin:video', ); } function getType() { return 'substition'; } function getSort(){ return 306; } function connectTo($mode) { $this->Lexer->addSpecialPattern('{{video>.*?}}',$mode,'plugin_video'); } function handle($match, $state, $pos, &$handler){ $match = html_entity_decode(substr($match, 8, -2)); list($url, $alt) = explode('|',$match,2); if (preg_match('/(.*)\[(.*)\]$/',trim($url),$matches=array())) { $url = $matches[1]; if (strpos($matches[2],',') !== false) { list($w, $h) = explode(',',$matches[2],2); } else { $h = $matches[2]; $w = '98%'; } } else { $w = '98%'; $h = '400px'; } if (!isset($alt)) $alt = ''; if (!$js_ok && substr($url,0,11) == 'javascript:') $url = 'error'; return array(hsc(trim($url)), hsc(trim($alt)), hsc(trim($w)), hsc(trim($h))); } function render($mode, &$renderer, $data) { list($url, $alt, $w, $h) = $data; if($mode == 'xhtml'){ if ($url != 'error') { $renderer->doc .= '<object CLASSID="CLSID:05589FA1-C356-11CE-BF01-00AA0055595A" class="plugin_video" height="'.$h.'" width="'.$w.'" style="width:'.$w.'; height: '.$h.';">'; $renderer->doc .= '<param name="FileName" value="'.$url.'">'; $renderer->doc .= '<embed type="application/x-mplayer2" class="plugin_video" src="'.$url.'" height="'.$h.'" width="'.$w.'" controller="true">'; $renderer->doc .= '<div><img src="lib/images/fileicons/avi.png" alt="avi" align="absmiddle" /><a href="'.$url.'">'.$alt.'</a></div>'; $renderer->doc .= '</embed>'; $renderer->doc .= '</object>'; } else { $renderer->doc .= '<div><img src="lib/images/fileicons/avi.png" alt="avi" align="absmiddle" /><a href="'.$url.'">'.$alt.'</a></div>'; } return true; } return false; } } ?>
I thought about tweaking the script where you can upload images and allow you to upload the video and pick it from that window menu… but then I decided that required far too much thought. But I do think it would be cool for the videos to be uploaded through dokuwiki and be in the media menu.
Add the file extension for the video files toconf/mine.conf(for more details see mime). You can also add/reuse an icon inlib/images/filetypes(of the formext.png) for an icon to be displayed to the left of the link when the link to the file is displayed. — Christopher Smith 2005-10-19 01:21
The plugin works well for avi, wmv files. Thanks. It will be good if there is a plugin for quicktime movies. Thanks in advance.
See below extended version of plugin, which supports, Quicktime, Mpeg & Flash. — Christopher Smith 2005-10-23 19:00
<?php /** * video: embeds a video * * Syntax: * {{video>http://www.yourpage.com/yourmovie.avi [width,height]|Alternate text}} * {{flash>http://www.yoursite.com/yourflash.swf [width,height]|Alternate text}} * etc for each defined type * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Jason Byrne <jbyrne@floridascale.com> * @author Chris Smith <chris@jalakai.co.uk> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); if (!function_exists('hsc')) { function hsc($string){ return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); } } //------------------------[ Settings ] --------------------------------------------- global $js_ok; // enable/disable javascript urls $js_ok = false; /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_video extends DokuWiki_Syntax_Plugin { var $settings = array( 'flash' => array( 'classid' => 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000', 'mime' => '', 'codebase' => 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab', 'plugin' => 'http://www.macromedia.com/go/getflashplayer', 'param' => array('quality' => 'high') ), 'movie' => array( 'classid' => 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B', 'mime' => 'video/quicktime', 'codebase' => 'http://www.apple.com/qtactivex/qtplugin.cab', 'plugin' => 'http://www.apple.com/quicktime/download/', 'param' => array('autoplay' => 'true') ), 'mpeg' => array( 'classid' => 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B', 'mime' => 'video/mpeg', 'codebase' => 'http://www.apple.com/qtactivex/qtplugin.cab', 'plugin' => 'http://www.apple.com/quicktime/download/', 'param' => array() ), 'realvideo' => array( 'classid' => 'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA', 'mime' => '', 'codebase' => '', 'plugin' => '', 'param' => array('autostart' => 'true') ), 'video' => array( 'classid' => 'CLSID:05589FA1-C356-11CE-BF01-00AA0055595A', 'mime' => 'application/x-mplayer2', 'codebase' => '', 'plugin' => '', 'param' => array('autostart' => 'true') ), ); function getInfo(){ return array( 'author' => 'Jason Byrne', 'email' => 'jbyrne@floridascale.com', 'date' => '2005-10-18', 'name' => 'video', 'desc' => 'Embeds video into a page', 'url' => 'http://www.dokuwiki.org/plugin:video', ); } function getType() { return 'substition'; } function getSort(){ return 306; } function connectTo($mode) { $types = array_keys($this->settings); foreach ($types as $type) $this->Lexer->addSpecialPattern('{{'.$type.'>.*?}}',$mode,'plugin_video'); } function handle($match, $state, $pos, &$handler){ list($type, $data) = explode('>',substr($match, 2,-2),2); $data = html_entity_decode($data); list($url, $alt) = explode('|',$data,2); if (preg_match('/(.*)\[(.*)\]$/',trim($url),$matches=array())) { $url = $matches[1]; if (strpos($matches[2],',') !== false) { list($w, $h) = explode(',',$matches[2],2); } else { $h = $matches[2]; $w = '640'; } } else { $w = '640'; $h = '480'; } if (!isset($alt)) $alt = $type.' file: '.$url; if (!$js_ok && substr($url,0,11) == 'javascript:') $url = 'error'; return array(trim($type), hsc(trim($url)), hsc(trim($alt)), hsc(trim($w)), hsc(trim($h))); } function render($mode, &$renderer, $data) { list($type, $url, $alt, $w, $h) = $data; $config = $this->settings[$type]; if($mode == 'xhtml'){ if ($url != 'error') { $param = ''; $attr = ''; if ($config['mime']) $attr .= ' type="'.$config['mime'].'"'; if ($config['plugin']) $attr .= ' pluginspage="'.$config['plugin'].'"'; foreach ($config['param'] as $name => $value) { $param .= " <param name=\"$name\" value=\"$value\">\n"; $attr .= " $name=\"$value\""; } $renderer->doc .= "<object classid=\"".$config['classid']."\" codebase=\"".$config['codebase']."\" class=\"plugin_video\" width=\"$w\" height=\"$h\" >\n"; $renderer->doc .= " <param name=\"src\" value=\"$url\">\n"; $renderer->doc .= $param; $renderer->doc .= " <embed $attr class=\"plugin_video\" src=\"$url\" width=\"$w\" height=\"$h\" controller=\"true\">\n"; $renderer->doc .= " <div><img src=\"lib/images/fileicons/avi.png\" alt=\"\" /><a href=\"$url\">$alt</a></div>\n"; $renderer->doc .= " </embed>\n"; $renderer->doc .= "</object>\n"; } else { $renderer->doc .= "<div><img src=\"lib/images/fileicons/avi.png\" alt=\"\" /><a href=\"$url\">$alt</a></div>\n"; } return true; } return false; } } ?>
Add these two to the$settingsarray to embed midi and mp3 sounds in a wiki page.'midi' => array( 'classid' => 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B', 'mime' => 'audio/midi', 'codebase' => 'http://www.apple.com/qtactivex/qtplugin.cab', 'plugin' => 'http://www.apple.com/quicktime/download/', 'param' => array(), ), 'mp3' => array( 'classid' => 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B', 'mime' => 'audio/mpeg', 'codebase' => 'http://www.apple.com/qtactivex/qtplugin.cab', 'plugin' => 'http://www.apple.com/quicktime/download/', 'param' => array(), ),— Christopher Smith 2005-11-01 15:10
How can I install (Setup) it?
you can install this by creating a folder in your lib\plugin directory and name it movie and copypaste this code into a new file named movie.php and upload it there.
>i still couldnt get this plgin to work, btw. i get a download for a fetch.php file
The directory needs to be calledvideo. The file to paste the code into is calledsyntax.php. You will probably need to add the file types to Dokuwiki'sconf/mime.conffile. — Christopher Smith 2006-03-29 16:36thank you Christopher, i changed the setup as you described, i also chmod the new dir to 755 and added the mime for .mov files. but when i try to call the “info” box in the plugin manager i get a blank page. and untill i deleted this dir and the new syntex.php file in it, all my wiki pages were rendered blank.I'm not sure what the problem could be. Using the code I posted above, I have created plugin manager compatible files for automated installation. They are available here. — Christopher Smith 2006-03-30 01:59thank you, i use the sidebar plugin and it is great. for now i cant load plugins using the plugin manager, i get an error without explenation and i chmod my lib\plugin folder to 775. i will try this latter.
Does this plugin work with the new version (2006-03-09) of DokuWiki? — Sergei 2006-04-05 9:58
Nevermind, it does… I couldn't get it to work because I was using {{video>… when I should've used {{movie>… — Sergei 2006-04-05 10:15yes, thank you, the code in the syntex section above is missleading , it should be {{movie> and not {{video> . (for quicktime) consider adding a note, the correct syntex for each filetype is listed in the code section.yair 2006-04-20 9:00
Bug with feed.php?
After I install the video plugin I got an error when running feed.php
Fatal error: Call to undefined function: hsc() in /lib/plugins/video/syntax.php on line 145
and that line is
return array(trim($type), hsc(trim($url)), hsc(trim($alt)), hsc(trim($w)), hsc(trim($h)));
Any suggestions? Thanks!
Upgrade to a recent nightly build of DokuWiki, move the function definition from its current location toinc/common.php(its new location in the nightly builds) or add the following lines to the plugin script (outside of the class definition block)if (!function_exists('hsc')) { function hsc($string){ return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); } }I have amended the code shown above to include these lines and updated the installable plugin packages I host. — Christopher Smith 2006-06-14 09:57
Will this plugin support internal wiki links? Something like
{{video>:wiki:mymovie.avi}}
no, this won't work as the adress is not resolved into a URL address (you can check this by looking into the source code of the rendered page)
you should just be able to wrap any spots it outputs the URL to the video withml()(I'm still testing this myself)
it's actually quite easy to add this support
put this code in the “handle(…)” function, after the code that resolves width and height// test if url is a protocol if(strpos($url,'://')===false){ //if not, we consider this is a media from the media library $url = ml($url); }
WARNING this is just a trick not a production validated code
Do also modify mime.conf to allow video file upload…
Colin LORRAIN 2008-05-06 20:04
If you add the following code into syntax.php of the video plugin, you can include divX videos as well:
'video' => array(
'classid' => 'clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616',
'mime' => 'video/x-divx',
'codebase' => 'http://go.divx.com/plugin/DivXBrowserPlugin.cab',
'plugin' => 'http://go.divx.com/plugin/download/',
'param' => array('autostart' => 'true'),
'icon' => 'lib/images/fileicons/avi.png'
),
Add the following to mime.conf in the conf directory of your wiki:
divx video/x-divx
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported