1<?php 2/* 3description : Display XML/SWF Slideshow 4author : Ikuo Obataya 5email : ikuo_obataya@symplus.co.jp 6lastupdate : 2008-03-22 7depends : cache (2008-03-22) 8license : GPL 2 (http://www.gnu.org/licenses/gpl.html) 9*/ 10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 11 require_once(DOKU_INC.'inc/init.php'); 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 require_once(DOKU_PLUGIN.'syntax.php'); 14if (!class_exists('plugin_cache')) @require(DOKU_PLUGIN.'cache/plugin_cache.php'); 15 16class syntax_plugin_slideshow extends DokuWiki_Syntax_Plugin { 17 var $swfLoc = ''; 18 var $xmlCache; 19 // Constructor 20 function syntax_plugin_slideshow(){ 21 $this->swfLoc = DOKU_BASE.'lib/plugins/slideshow/slideshow.swf'; 22 $this->xmlCache = new plugin_cache("slideshow",'',"xml"); 23 } 24 function getInfo(){ 25 return array( 26 'author' => 'Ikuo Obataya', 27 'email' => 'ikuo_obataya@symplus.co.jp', 28 'date' => '2008-03-22', 29 'name' => 'XML/SWF Slideshow Plugin', 30 'desc' => 'Create SWF Slideshow by www.maani.us 31 <slideshow (filename)>script</slideshow>', 32 'url' => 'http://wiki.symplus.co.jp/computer/en/slideshow_plugin', 33 ); 34 } 35 function getType(){ return 'protected'; } 36 function getSort(){ return 917; } 37 function connectTo($mode) { 38 $this->Lexer->addEntryPattern('<slideshow.*?>(?=.*?</slideshow>)',$mode,'plugin_slideshow'); 39 } 40 41 // Exit 42 function postConnect() { 43 $this->Lexer->addExitPattern('</slideshow>','plugin_slideshow'); 44 } 45 46 // Handling lexer 47 function handle($match, $state, $pos) { 48 switch ($state) { 49 case DOKU_LEXER_ENTER : 50 return array($state, substr($match,9,-1)); 51 case DOKU_LEXER_UNMATCHED : return array($state, $match); 52 case DOKU_LEXER_EXIT : return array($state, ''); 53 } 54 return array(); 55 } 56 // Render 57 function render($mode, &$renderer, $data){ 58 if ($mode!='xhtml') 59 return false; 60 61 global $conf; 62 @list($state, $match) = $data; 63 $args = explode(" ",$match); 64 $license = $this->getConf('license'); 65 66 $tryFN = preg_replace("/{{([^|}]+).*}}/",'$1',$args[1]); 67 $filename = mediaFN($tryFN); 68 if(is_Dir($filename) || !file_exists($filename)){ 69 $idx = 1; 70 $filename=""; 71 }else{ 72 $idx = 2; 73 } 74 75 switch ($state) { 76 case DOKU_LEXER_ENTER: 77 if ($args[1]=="image_list") { return true;} 78 else if ($args[1]=="clear_cache"){$this->xmlCache->ClearCache(); return true;} 79 80 $width = (!empty($args[$idx])) ? urlencode($args[$idx]) : $this->getConf('default_width');$idx++; 81 $height = (!empty($args[$idx])) ? urlencode($args[$idx]) : $this->getConf('default_height');$idx++; 82 $oid = (!empty($args[$idx])) ? urlencode($args[$idx]) : 'slideshow';$idx++; 83 $bgcolor = (!empty($args[$idx])) ? urlencode($args[$idx]) : $this->getConf('default_bgcolor');$idx++; 84 $align = (!empty($args[$idx])) ? urlencode($args[$idx]) : ''; 85 86 $width_height = sprintf(' WIDTH="%s" HEIGHT="%s" '.NL,$width,$height); 87 $align_def = sprintf(' ALIGN="%s" ',$align); 88 $id_def = sprintf(' id="%s" '.NL,$oid); 89 90 $renderer->doc.= NL.'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '.NL; 91 $renderer->doc.= 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '.NL; 92 $renderer->doc.= $width_height; 93 $renderer->doc.= $id_def; 94 $renderer->doc.= $align_def.'>'.NL; 95 $renderer->doc.= '<PARAM NAME=quality VALUE=high>'.NL; 96 $renderer->doc.= '<PARAM NAME=bgcolor VALUE='.$bgcolor.'>'.NL; 97 $renderer->doc.= '<EMBED quality=high'.NL; 98 $renderer->doc.= ' bgcolor='.$bgcolor.''.NL; 99 $renderer->doc.= $width_height; 100 $renderer->doc.= ' NAME="'.$oid.'" ALIGN="'.$align.'"'.NL; 101 $renderer->doc.= ' TYPE="application/x-shockwave-flash"'.NL; 102 $renderer->doc.= ' PLUGINSPAGE="http://www.macromedia.com/getflashplayer"'.NL; 103 if (!empty($filename)){ 104 // static file 105 $content = @io_readFile($filename,false); 106 $fetchPath = $this->createXmlFile($renderer->_xmlEntities($content),$width,$height,false); 107 $src = $this->swfLoc.'?xml_source='.urlencode($fetchPath).'&license='.$license; 108 109 $renderer->doc.= ' src="'.$src.'"></EMBED>'; 110 $renderer->doc.='<PARAM NAME=movie VALUE="'.$src.'"></OBJECT>'; 111 } 112 break; 113 case DOKU_LEXER_UNMATCHED: 114 if (empty($match)) 115 return; 116 // direct content 117 $fetchPath = $this->createXmlFile($renderer->_xmlEntities($match),$width,$height,true); 118 $src = $this->swfLoc.'?xml_source='.urlencode($fetchPath).'&license='.$license; 119 120 $renderer->doc.= ' src="'.$src.'"></EMBED>'.NL; 121 $renderer->doc.= '<PARAM NAME=movie VALUE="'.$src.'"></OBJECT>'; 122 break; 123 case DOKU_LEXER_EXIT: 124 break; 125 } 126 return true; 127 } 128 129 /** 130 * Replace Media file link of {{XXX}} to fetchable URL 131 */ 132 function replaceMediaLinks($content){ 133 $new_content = preg_replace_callback( 134 "/{{([^|}]+).*}}/", 135 create_function('$matches','return ml($matches[1],"cache=nocache");'), 136 $content); 137 return $new_content; 138 } 139 /** 140 * Replace Wiki link of [[XXX]] to URL 141 */ 142 function replaceWikiLinks($content){ 143 $new_content = preg_replace_callback( 144 "/\[\[([^|\]]+).*\]\]/", 145 create_function('$matches','return wl($matches[1]);'), 146 $content); 147 return $new_content; 148 } 149 /** 150 * Replace included source 151 */ 152 function replaceIncludedSrc($content){ 153 $new_content = preg_replace_callback( 154 "/<include>([^<]+?)<\/include>/", 155 create_function('$matches','return @include $matches[1];'), 156 $content); 157 return $new_content; 158 } 159 /** 160 * Create XML content in the plugin's media directory 161 */ 162 function createXmlFile(&$data,$w,$h,$needTag) { 163 global $conf; 164 $hash = md5(serialize($data).$w.$h); 165 $savePath = $this->xmlCache->GetMediaPath($hash); 166 if (!file_exists($savePath)){ 167 $content = $this->cleanXml($data); 168 $content = $this->replaceMediaLinks($content); 169 $content = $this->replaceWikiLinks($content); 170 $content = $this->replaceIncludedSrc($content); 171 if ($needTag===true){ 172 $content = sprintf('<slideshow>%s</slideshow>',$content); 173 } 174 if(io_saveFile($savePath, $content)){ 175 chmod($savePath,$conf['fmode']); 176 } 177 } 178 return $this->xmlCache->GetMediaLink($hash); 179 } 180 181 /** 182 * Convert Xml entity 183 */ 184 function cleanXml($content){ 185 $s = array("<",">","'",""","'"); 186 $r = array("<",">","'","'",'"'); 187 $cx = str_replace($s,$r,$content); 188 return $cx; 189 } 190} 191?>