1<?php
2/*
3 * DokuWiki mp3play plugin
4 * 2011 Zahno Silvan
5 * Usage:
6 *
7 * {{mp3play>place_of_playlist.xml}}
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the LGNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * LGNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the LGNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 */
23
24
25if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
26if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
27require_once(DOKU_PLUGIN.'syntax.php');
28
29/**
30 * All DokuWiki plugins to extend the parser/rendering mechanism
31 * need to inherit from this class
32 */
33class syntax_plugin_mp3play extends DokuWiki_Syntax_Plugin {
34
35    /**
36     * return some info
37     */
38    function getInfo(){
39        return array(
40            'author' => 'Zahno Silvan',
41            'email'  => 'zaswiki@gmail.com',
42            'date'   => '2011-02-17',
43            'name'   => 'Mp3Play2 Plugin',
44            'desc'   => 'Embedding MP3 Player for Files and Streams',
45            'url'    => 'http://zawiki.zapto.org/doku.php/tschinz:dw_mp3play',
46        );
47    }
48
49    /**
50     * What kind of syntax are we?
51     */
52    function getType(){
53        return 'substition';
54    }
55
56    /**
57     * Where to sort in?
58     */
59    function getSort(){
60        return 299;
61    }
62
63
64    /**
65     * Connect pattern to lexer
66     */
67    function connectTo($mode) {
68      $this->Lexer->addSpecialPattern('\{\{mp3play>.*?\}\}',$mode,'plugin_mp3play');
69    }
70
71    /**
72     * Handle the match
73     */
74    function handle($match, $state, $pos, &$handler){
75        switch ($state) {
76          case DOKU_LEXER_ENTER :
77            break;
78          case DOKU_LEXER_MATCHED :
79            break;
80          case DOKU_LEXER_UNMATCHED :
81            break;
82          case DOKU_LEXER_EXIT :
83            break;
84          case DOKU_LEXER_SPECIAL :
85            return $match;
86            break;
87        }
88        return array();
89    }
90
91    /**
92     * Create output
93     */
94    function render($mode, &$renderer, $data) {
95		if($mode == 'xhtml'){
96
97			$options['showplaylist'] = $this->getConf('showplaylist');
98			$options['showeq']       = $this->getConf('showeq');
99			$options['firsttrack']   = $this->getConf('firsttrack');
100			$options['initvol']      = $this->getConf('initvol');
101			$options['width']        = $this->getConf('width');
102			$options['height']       = $this->getConf('height');
103
104			$params['menu']        = 'false';
105			$params['quality']     = 'high';
106			$params['name']        = 'Plugin Mp3Play';
107			$params['allowScriptAccess'] = 'always';
108			$params['type']        = 'application/x-shockwave-flash';
109			$params['pluginspage'] = 'http://www.macromedia.com/go/getflashplayer';
110			$params['wmode']       = 'transparent';
111			$params['border']      = '0';
112
113			// strip {{mp3play> from start
114			$data     = substr($data,10);
115			// strip }} from end
116			$data     = substr($data,0,-2);
117
118			if (empty($data))
119			{
120				$renderer->doc .= 'No playlist given';
121				return true;
122			}
123
124			// get current url
125			$url = wl($ID,'',true);
126			// cut doku.php at the end
127            $url = substr($url,0,-9);
128
129			$data = $url.'/lib/exe/fetch.php/'.$data;
130			$playlist = $data;
131
132			$flashvars  = $playlist.'&ShowPlaylist='.$options['showplaylist'].'&ShowEQ='.$options['showeq'].'&firstTrack='.$options['firsttrack'].'&initVol='.$options['initvol'];
133			$alt        = '';
134
135			$movie = $url.'/lib/plugins/mp3play/flashplayer/player.swf';
136			$renderer->doc .= '<embed src="'.$movie.'" menu="'.$params['menu'].'" quality="'.$params['quality'].'" width="'.$options['width'].'" height="'.$options['height'].'" name="'.$params['name'].'" allowScriptAccess="'.$params['allowScriptAccess'].'" type="'.$params['type'].'" pluginspage="'.$params['pluginspage'].'" flashvars="playList='.$flashvars.'" wmode="'.$params['wmode'].'" border="'.$params['border'].'" / >';
137
138			return true;
139        }
140        return false;
141    }
142}
143