/
syntax.php
159 lines (130 loc) · 4.53 KB
/
syntax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Embed a flash Jukebox
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_jukebox extends DokuWiki_Syntax_Plugin {
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
/**
* What about paragraphs?
*/
function getPType(){
return 'block';
}
/**
* Where to sort in?
*/
function getSort(){
return 301;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{jukebox>[^}]*\}\}',$mode,'plugin_jukebox');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler){
global $ID;
$match = substr($match,10,-2); //strip markup from start and end
$data = array();
// extract params
list($ns,$params) = explode(' ',$match,2);
$ns = trim($ns);
// namespace (including resolving relatives)
$data['ns'] = resolve_id(getNS($ID),$ns);
$data['skin'] = 'original';
// alignment
$data['align'] = 'left';
if(preg_match('/\bleft\b/i',$params)){
$data['align'] = 'left';
$params = preg_replace('/\bleft\b/i','',$params);
}
if(preg_match('/\bcenter\b/i',$params)){
$data['align'] = 'center';
$params = preg_replace('/\bcenter\b/i','',$params);
}
if(preg_match('/\bright\b/i',$params)){
$data['align'] = 'right';
$params = preg_replace('/\bright\b/i','',$params);
}
$data['shuffle'] = false;
if(preg_match('/\bshuffle\b/i',$params)){
$data['shuffle'] = true;
$params = preg_replace('/\bshuffle\b/i','',$params);
}
$data['repeat'] = false;
if(preg_match('/\brepeat\b/i',$params)){
$data['repeat'] = true;
$params = preg_replace('/\brepeat\b/i','',$params);
}
$data['autoplay'] = false;
if(preg_match('/\bautoplay\b/i',$params)){
$data['autoplay'] = true;
$params = preg_replace('/\bautoplay\b/i','',$params);
}
// the rest is the skin
$data['skin'] = trim($params);
list($data['skin'],$data['width'],$data['height']) = $this->_skininfo($data['skin']);
return $data;
}
/**
* Create output
*/
function render($mode, Doku_Renderer $R, $data) {
if($mode != 'xhtml') return false;
$att = array();
$att['class'] = 'media'.$data['align'];
if($data['align'] == 'right') $att['align'] = 'right';
if($data['align'] == 'left') $att['align'] = 'left';
$params = array(
'skin_url' => DOKU_REL.'lib/plugins/jukebox/skins/'.$data['skin'].'/',
'playlist_url' => DOKU_REL.'lib/plugins/jukebox/list.php?ns='.$data['ns'].'&t=',
'mainurl' => 'http://www.dokuwiki.org/plugin:jukebox',
'infourl' => 'http://www.dokuwiki.org/plugin:jukebox',
'autoload' => 'true',
'findImage' => 'true',
'useId3' => 'true'
);
if($data['shuffle']) $params['shuffle'] = 'true';
if($data['autoplay']) $params['autoplay'] = 'true';
if($data['repeat']) $params['repeat'] = 'true';
$swf = DOKU_REL.'lib/plugins/jukebox/xspf_jukebox.swf';
$R->doc .= html_flashobject($swf,$data['width'],$data['height'],null,$params,$att);
return true;
}
function _skininfo($skin){
$skin = strtolower($skin);
$skin = preg_replace('/[^a-z]+/','',$skin);
if(!$skin) $skin = 'original';
if(@file_exists(dirname(__FILE__).'/skins/'.$skin.'/skin.xml')){
$data = @file_get_contents(dirname(__FILE__).'/skins/'.$skin.'/skin.xml');
}else{
return array('original',400,170);
}
if(preg_match('/<width>(\d+)<\/width>/',$data,$match)){
$width = $match[1];
}else{
$width = 400;
}
if(preg_match('/<height>(\d+)<\/height>/',$data,$match)){
$height = $match[1];
}else{
$height = 170;
}
return array($skin,$width,$height);
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :