1<?php
2/**
3 *
4 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
5 * @author     Andreas Gohr <andi@splitbrain.org>
6 */
7
8if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10require_once(DOKU_PLUGIN.'syntax.php');
11
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_flash extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * return some info
21     */
22    function getInfo(){
23        return confTohash(dirname(__FILE__).'/plugin.info.txt');
24    }
25
26    /**
27     * What kind of syntax are we?
28     */
29    function getType(){
30        return 'substition';
31    }
32
33    function getPType(){
34        return 'block';
35    }
36
37    /**
38     * Where to sort in?
39     */
40    function getSort(){
41        return 160;
42    }
43
44    /**
45     * Connect pattern to lexer
46     */
47    function connectTo($mode) {
48      $this->Lexer->addSpecialPattern('<flash.*?>\n.*?\n</flash>',$mode,'plugin_flash');
49    }
50
51    /**
52     * Handle the match
53     */
54    function handle($match, $state, $pos, Doku_Handler $handler){
55
56        // prepare default data
57        $return = array(
58                     'data'   => $data,
59                     'width'  => 425,
60                     'height' => 350,
61                     'align'  => 'center',
62                    );
63
64        // prepare input
65        $lines = explode("\n",$match);
66        $conf = array_shift($lines);
67        $conf = substr($conf,6,-1);
68        array_pop($lines);
69
70        // parse adhoc configs
71        if(preg_match('/\b(left|center|right)\b/i',$conf,$match)) $return['align'] = $match[1];
72        if(preg_match('/\b(\d+)x(\d+)\b/',$conf,$match)){
73            $return['width']  = $match[1];
74            $return['height'] = $match[2];
75        }
76
77        // strip configs to find swf
78        $conf = preg_replace('/\b(left|center|right|(\d+)x(\d+))\b/i','',$conf);
79        $conf = trim($conf);
80        $return['swf'] = ml($conf,'',true,'&');
81
82        // parse parameters
83        $return['data'] = linesToHash($lines);
84        foreach($return['data'] as $key => $val){
85            if($key{0} == '!') {
86                $return['data'][substr($key,1)] = ml($val,'',true,'&');
87                unset($return['data'][$key]);
88            }
89        }
90
91        return $return;
92    }
93
94    /**
95     * Create output
96     */
97    function render($mode, Doku_Renderer $R, $data) {
98        if($mode != 'xhtml') return false;
99
100        $att = array();
101        $att['class'] = 'media'.$data['align'];
102        if($data['align'] == 'right') $att['align'] = 'right';
103        if($data['align'] == 'left')  $att['align'] = 'left';
104
105        $R->doc .= html_flashobject($data['swf'],$data['width'],$data['height'],$data['data'],$data['data'],$att);
106
107        return true;
108    }
109
110
111}
112
113//Setup VIM: ex: et ts=4 enc=utf-8 :
114