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