DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:video

Plugin: Video

Compatible with DokuWiki

No compatibility info given!

plugin Embed video into the page

Last updated on
2005-10-18
Provides
Syntax

Background

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!

Acknowledgement

I borrowed the syntax and some code from the iframe plugin.

Syntax

{{video>http://www.yourpage.com/yourmovie.avi|Alternate text}}

Replace the word 'video' at the beginning with the appropriate word, depending on the format of the media you want to display, ie:
video for .AVI
flash for .swf
movie for .mov
mp3 for .mp3
mpeg for .mpeg
realvideo for .ram
midi for .midi

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.

To specify the height and width of the movie, you will need to apply the fix listed below in the discussion for 2010.4.10.

Code

<?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;
    }
 
}
 
?>

Additional Installation Steps

  • When the browser cannot display the video, it shows alternate text that links to download the video instead. Beside that it displays an icon. Place the icon you want to use for this at lib/images/fileicons/avi.png . You can download one here if you don't have another one to use.
  • The plugin (including tweaks from Chris Smith) can be downloaded in either zip (2K) or in tar.gz (2K) formats.

Release Notes

  • 10/20/2005 - Update: Added an avi icon that displays by the alternate text link (if movie cannot display). Also tweaked the embed tag and now it works naively in Firefox. — Jason Byrne 2005-10-20 18:32

Other Thoughts

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 to conf/mine.conf (for more details see mime). You can also add/reuse an icon in lib/images/filetypes (of the form ext.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

Discussion

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, and 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 $settings array 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 copy/paste this code into a new file named movie.php and upload it there.
>i still couldn't get this plugin to work, by the way. I get a download for a fetch.php file
The directory needs to be called video. The file to paste the code into is called syntax.php. You will probably need to add the file types to DokuWiki's conf/mime.conf file. — Christopher Smith 2006-03-29 16:36
thank 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 until 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:59
thank you, I use the sidebar plugin and it is great. for now I can't load plugins using the plugin manager, I get an error without explanation 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:15
yes, thank you, the code in the syntax section above is misleading , it should be {{movie> and not {{video> . (for QuickTime) consider adding a note, the correct syntax 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 to inc/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 address 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 with
ml()

(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

2009.07.13 - Is it possible to render a video uploaded in the Upload File option of DokuWiki. For example to use some line like:

{{video>:wiki:movie.avi}} 

Robert

It doesn't work for me, but I'd really like it if someone could explain how to achieve this

2010.04.10
The syntax

{{flash>http://www.yoursite.com/yourflash.swf 640,480|Alternate text}}

Does not work, as the preg_match syntax doesn't parse it correctly. Replacing the line 126 (within the function $handle):

      if (preg_match('/(.*)\[(.*)\]$/',trim($url),$matches=array())) {

with this

      if (preg_match('/(.*) ([0-9]+,[0-9]+)$/',trim($url),$matches)) {

fixes it, and allows you to specify width and height, provided you specify both. ie:

both:

{{flash>http://www.yoursite.com/yourflash.swf 400,300|Alternate text}}

and:

{{flash>http://www.yoursite.com/yourflash.swf|Alternate text}}

will work. The latter will use the default sizes 640×480.

- Noel

plugin/video.txt · Last modified: 2013/03/05 10:02 by Aleksandr