1<?php
2/**
3 * flowplay: embeds a video stream player flash applet into your page
4 *
5 * Syntax:
6 *   {{flowplay>yourvideo.flv [width,height]}}
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @version    0.2
10 * @author     Dave Kliczbor <maligree@gmx.de>
11 * @author     Jason Byrne <jbyrne@floridascale.com>
12 * @author     Chris Smith <chris@jalakai.co.uk>
13 */
14
15if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
16if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
17define('PLUGIN_FLOW', DOKU_BASE.'lib/plugins/flowplay/flowplayer/');
18require_once(DOKU_PLUGIN.'syntax.php');
19
20if (!function_exists('hsc')) {
21  function hsc($string){ return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); }
22}
23
24class syntax_plugin_flowplay extends DokuWiki_Syntax_Plugin {
25
26    function getInfo(){
27        return array(
28            'author' => 'Dave Kliczbor',
29            'email'  => 'maligree@gmx.de',
30            'date'   => '2007-02-22',
31            'version'=> '0.2',
32            'name'   => 'flowplay',
33            'desc'   => 'Embeds a video stream player flash applet into your page',
34            'url'    => 'http://wiki.splitbrain.org/plugin:flowplay',
35	    'ack'    => 'Parts of this plugin were copied from the video plugin by Jason Byrne and Chris Smith',
36        );
37    }
38
39    function getType() {
40        return 'substition';
41    }
42
43    function getSort(){
44        return 305;
45    }
46
47    function connectTo($mode) {
48        $this->Lexer->addSpecialPattern('{{flowplay>.*?}}',$mode,'plugin_flowplay');
49    }
50
51    function handle($match, $state, $pos, &$handler){
52      list($type, $data) = explode('>',substr($match, 2,-2),2);
53      $data = html_entity_decode($data);
54      list($url, $alt) = explode('|',$data,2);
55
56      if (preg_match('/(.*)\[(.*)\]$/',trim($url),$matches=array())) {
57        $url = $matches[1];
58        if (strpos($matches[2],',') !== false) {
59          list($w, $h) = explode(',',$matches[2],2);
60        } else {
61          $h = $matches[2];
62          $w = '320';
63        }
64      } else {
65        $w = '320';
66        $h = '240';
67      }
68      $h += 23; //add the height of the control bar
69
70      if (!isset($alt)) $alt = $type.' file: '.$url;
71
72      return array(hsc(trim($url)), hsc(trim($alt)), hsc(trim($w)), hsc(trim($h)));
73    }
74
75    function render($mode, &$renderer, $data) {
76
77      list($url, $alt, $param['width'], $param['height']) = $data;
78
79      if($mode == 'xhtml'){
80
81        if( strlen($this->getConf('player_base_url')) > 0 ) {
82          $prefix = $this->getConf('player_base_url');
83        } else {
84          $prefix = PLUGIN_FLOW;
85        }
86        if( $prefix{strlen($prefix)-1} !== '/' ) $prefix .= '/';
87	$renderer->doc .= '<object type="application/x-shockwave-flash" data="'.$prefix.'FlowPlayer.swf" width="'.$param['width'].'" height="'.$param['height'].'" id="FlowPlayer"> '."\n";
88	$renderer->doc .= '	<param name="allowScriptAccess" value="sameDomain" /> '."\n";
89	$renderer->doc .= '	<param name="movie" value="'.$prefix.'FlowPlayer.swf" /> '."\n";
90	$renderer->doc .= '	<param name="quality" value="high" /> '."\n";
91	$renderer->doc .= '	<param name="scale" value="noScale" /> '."\n";
92	$renderer->doc .= '	<param name="wmode" value="transparent" /> '."\n";
93	$renderer->doc .= '	<param name="flashvars" value="config={videoFile:\''. ml($url) .'\', autoPlay:false, loop:false, showLoopButton:false}" /> '."\n";
94	$renderer->doc .= '</object>'."\n";
95
96        return true;
97      }
98      return false;
99    }
100
101}
102
103?>