1<?php
2/**
3 * flowplay2: embeds a video stream player flash applet into your page
4 *
5 * This is mostly based on the flowplay-plugin by Dave Kliczbor et al.
6 *
7 * Syntax:
8 *   Please look at the README
9 *
10 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
11 * @version    0.3
12 * @author     bSpot <blind@bspot.de>
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/flowplay2/flowplayer/');
18require_once(DOKU_PLUGIN.'syntax.php');
19
20if (!function_exists('hsc'))
21{
22	function hsc($string){ return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); }
23}
24
25class syntax_plugin_flowplay2 extends DokuWiki_Syntax_Plugin
26{
27
28	function getInfo()
29	{
30		return array (
31			'author' => 'bSpot',
32			'email'  => 'blind@bspot.de',
33			'date'   => '2008-04-16',
34			'version'=> '0.3',
35			'name'   => 'flowplay2',
36			'desc'   => 'Embeds a video stream player flash applet into your page',
37			'url'    => 'http://wiki.splitbrain.org/plugin:flowplay2',
38			'ack'    => 'This is mostly based on the flowplay-plugin by Dave Kliczbor et al.',
39		);
40	}
41
42	function getType() { return 'protected';}
43	function getAllowedTypes() { return array('container','substition','protected','disabled','formatting','paragraphs'); }
44	function getPType() { return 'normal';}
45
46
47	function getSort()
48	{
49		return 191;
50	}
51
52	function connectTo($mode)
53	{
54		// pattern for the flashplayer
55		$this->Lexer->addSpecialPattern('{{flowplay>.*?}}', $mode, 'plugin_flowplay2');
56		// entry pattern for playlist-items
57		$this->Lexer->addEntryPattern('\[\[flowplay>[^|]*\|',$mode,'plugin_flowplay2');
58	}
59
60	function postConnect()
61	{
62		// exit pattern for playlist-items
63		$this->Lexer->addExitPattern('\]\]','plugin_flowplay2');
64	}
65
66	function handle($match, $state, $pos, &$handler)
67	{
68		$m = array();
69
70		switch ($state)
71		{
72			// player
73			case DOKU_LEXER_SPECIAL:
74				list($url, $paramStr) = explode('?', substr($match, strlen('{{flowplay>'), -2), 2);
75				// prepare parameter list
76				foreach (explode(" ", $paramStr) as $param)
77				{
78					// width/height parameter
79					if ( preg_match('/(\d+)x(\d+)/', $param, $m) )
80					{
81						$params['width'] = $m[1];
82						$params['height'] = $m[2];
83					}
84					// non-boolean parameter
85					else if ( preg_match('/([^:]+):(.*)$/', $param, $m) )
86						$params[$m[1]] = $m[2];
87					// boolean parameter set to false
88					else if (substr($param, 0, 2) == "no")
89						$params[strtolower(substr($param, 2, 1)) . substr($param, 3)] = False;
90					// boolean parameter set to true
91					else
92						$params[$param] = True;
93				}
94
95				return array('type' => 'player', 'url' => $url, 'paramStr' => $paramStr, 'params' => $params);
96
97			// playlist
98			case DOKU_LEXER_ENTER:
99				$url = substr($match, strlen('[[flowplay>'), -1);
100				return array('type' => 'playlist_open', 'url' => $url);
101
102			case DOKU_LEXER_MATCHED:
103				return array('type' => 'data', 'match' => $match);
104
105			case DOKU_LEXER_UNMATCHED:
106				return array('type' => 'data', 'match' => $match);
107
108			case DOKU_LEXER_EXIT:
109				return array('type' => 'playlist_close', 'match' => $match);
110        	}
111		return false;
112	}
113
114	function render($mode, &$renderer, $indata)
115	{
116		if($mode == 'xhtml')
117		{
118			switch ($indata['type'])
119			{
120				// player
121				case 'player' :
122					/*
123					// DISABLED DEBUG OUTPUT
124					$renderer->doc .= "<ul>";
125					$renderer->doc .= "<b>url => " . $indata['url'] . " (" . ml($indata['url']) . ")</b>";
126					foreach ($indata['params'] as $k => $v)
127						$renderer->doc .= "<li>" . $k . " => " . $v. "</li>";
128					$renderer->doc .= "</ul>";*/
129
130					$renderer->doc .= $this->_renderPlayer($indata);
131					break;
132
133				// playlist
134				case 'playlist_open' :
135					$renderer->doc .= "<a href='" . ml($indata["url"]) . "' class='flowplayitem'>";
136					break;
137
138				case 'data':
139					$renderer->doc .= $renderer->_xmlEntities($indata['match']);
140					break;
141
142				case 'playlist_close' :
143					$renderer->doc .= "</a>";
144					break;
145			}
146
147			return true;
148		}
149		return false;
150	}
151
152	function _renderPlayer($indata)
153	{
154		// determine player url
155		if( strlen($this->getConf('player_base_url')) > 0 )
156			$prefix = $this->getConf('player_base_url');
157		else
158			$prefix = PLUGIN_FLOW;
159		if( $prefix{strlen($prefix)-1} !== '/' ) $prefix .= '/';
160
161		$params = $indata["params"];
162
163		// embed javascript
164		$r = '<script language="javascript" src="' . $prefix . 'html/flashembed.min.js"></script>';
165		$r .= '<script language="javascript" src="' . $prefix . '../playlist.js"></script>';
166
167		// player configuration
168		$r .= 	"<script language='javascript'>" . DOKU_LF .
169			"var playerConfig =   " . DOKU_LF .
170			"{   " . DOKU_LF .
171			"	controlBarBackgroundColor: '0x99cddc',   " . DOKU_LF;
172
173		// add params
174		foreach ($indata['params'] as $k => $v)
175			$r .= $k . ": " . ($v === True ? "true" : ($v === False ? "false" : "'" . $v . "'")) . ",";
176
177		// run player on startup if a url is given
178		if ($indata["url"] != "")
179			$r .= "videoFile: '" . ml($indata["url"]) . "'";
180
181		$r .= 	"}   " . DOKU_LF;
182
183		// EMBED configuration
184		$r .= "var embedConfig =   " . DOKU_LF .
185			"{   " . DOKU_LF .
186			($params["width"] ? "width: " . $params["width"] . ",   " . DOKU_LF : "") .
187			($params["height"] ? "height: " . $params["height"] . ",   " . DOKU_LF : "") .
188			"	src:'" . $prefix . $this->getConf('player_swf') . "',   " . DOKU_LF .
189			"	bgcolor:'#6F7485'   " . DOKU_LF .
190			"}   " . DOKU_LF .
191			"</script>" . DOKU_LF;
192
193		// add the player-div
194		$r .= "<div id='flowplayer'></div>";
195
196		return $r;
197	}
198}
199
200?>