1<?php
2
3/**
4 * flowplayer: Allows to embed a flash video into Wiki pages
5 *
6 * This plugin is based on the flowplay2 plugin by bspot and flashplayer plugin by Arno Welzel
7 *
8 * Syntax:
9 *   {{flowplayer>video.flv [width,height] [[no]param] [param:value]}}
10 *
11 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
12 * @author     Alexey Markov <redrat@mail.ru>
13 * @version    0.5
14 */
15
16if(!defined('DOKU_INC')) die();
17if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
18define('FLOWPLAYER', DOKU_BASE.'lib/plugins/flowplayer/player/flowplayer-3.2.16.swf');
19require_once(DOKU_PLUGIN.'syntax.php');
20
21class syntax_plugin_flowplayer extends DokuWiki_Syntax_Plugin {
22
23    function getType() { return 'substition'; }
24
25    function getSort() { return 32; }
26
27    function connectTo($mode) { $this->Lexer->addSpecialPattern('{{flowplayer>.*?}}',$mode,'plugin_flowplayer'); }
28
29    function handle($match, $state, $pos, &$handler) {
30        $width = 320;
31        $height = 240;
32        $params['scaling'] = '"fit"';
33        $params['autoPlay'] = 'false';
34        $params['urlEncoding'] = 'true';
35        list($url, $attr) = explode(" ", hsc(trim(substr($match, 13, -2))), 2);
36        foreach (explode(" ", $attr) as $param) {
37            if (preg_match('/(\d+),(\d+)/', $param, $res)) {
38                $width = intval($res[1]);
39                $height = intval($res[2]);
40            }
41            else if (preg_match('/([^:]+):(.*)$/', $param, $res))
42                $params[strtolower(substr($res[1], 0, 1)).substr($res[1], 1)] = '"'.$res[2].'"';
43            else if (preg_match('/no(\w+)/', $param, $res))
44                $params[strtolower(substr($res[1], 0, 1)).substr($res[1], 1)] = 'false';
45            else if (preg_match('/(\w+)/', $param, $res))
46                $params[strtolower(substr($res[1], 0, 1)).substr($res[1], 1)] = 'true';
47        }
48        if (strpos($url,'://')===false) { $url = ml($url); }
49        return array('url' => $url, 'width' => $width, 'height' => $height, 'fid' => uniqid(), 'attr' => $params);
50    }
51
52    function render($mode, &$renderer, $data) {
53        if($mode == 'xhtml'){
54            $renderer->doc .= '<object type="application/x-shockwave-flash"';
55            $renderer->doc .= ' id="fp-'.$data['fid'].'"';
56            $renderer->doc .= ' data="'.FLOWPLAYER.'"';
57            $renderer->doc .= ' width="'.$data['width'].'"';
58            $renderer->doc .= ' height="'.$data['height'].'"';
59            $renderer->doc .= '>'."\n";
60            $renderer->doc .= '<param name="movie" value="'.FLOWPLAYER.'" />'."\n";
61            $renderer->doc .= '<param name="allowfullscreen" value="true" />'."\n";
62            $renderer->doc .= '<param name="flashvars" value='."'";
63            $renderer->doc .= 'config={"clip":{"url":"'.$data['url'].'"';
64            foreach ($data['attr'] as $key => $value) {
65                $renderer->doc .= ',"'.$key.'":'.$value;
66            }
67            $renderer->doc .= "}}'".' />'."\n";
68            $renderer->doc .= '<b>'.$this->getLang('GetFlash').'</b>'."\n";
69            $renderer->doc .= '</object>'."\n";
70            return true;
71        }
72        return false;
73    }
74}
75