swfLoc = DOKU_BASE.'lib/plugins/slideshow/slideshow.swf';
$this->xmlCache = new plugin_cache("slideshow",'',"xml");
}
function getInfo(){
return array(
'author' => 'Ikuo Obataya',
'email' => 'ikuo_obataya@symplus.co.jp',
'date' => '2008-03-22',
'name' => 'XML/SWF Slideshow Plugin',
'desc' => 'Create SWF Slideshow by www.maani.us
script',
'url' => 'http://wiki.symplus.co.jp/computer/en/slideshow_plugin',
);
}
function getType(){ return 'protected'; }
function getSort(){ return 917; }
function connectTo($mode) {
$this->Lexer->addEntryPattern('(?=.*?)',$mode,'plugin_slideshow');
}
// Exit
function postConnect() {
$this->Lexer->addExitPattern('','plugin_slideshow');
}
// Handling lexer
function handle($match, $state, $pos) {
switch ($state) {
case DOKU_LEXER_ENTER :
return array($state, substr($match,9,-1));
case DOKU_LEXER_UNMATCHED : return array($state, $match);
case DOKU_LEXER_EXIT : return array($state, '');
}
return array();
}
// Render
function render($mode, &$renderer, $data){
if ($mode!='xhtml')
return false;
global $conf;
@list($state, $match) = $data;
$args = explode(" ",$match);
$license = $this->getConf('license');
$tryFN = preg_replace("/{{([^|}]+).*}}/",'$1',$args[1]);
$filename = mediaFN($tryFN);
if(is_Dir($filename) || !file_exists($filename)){
$idx = 1;
$filename="";
}else{
$idx = 2;
}
switch ($state) {
case DOKU_LEXER_ENTER:
if ($args[1]=="image_list") { return true;}
else if ($args[1]=="clear_cache"){$this->xmlCache->ClearCache(); return true;}
$width = (!empty($args[$idx])) ? urlencode($args[$idx]) : $this->getConf('default_width');$idx++;
$height = (!empty($args[$idx])) ? urlencode($args[$idx]) : $this->getConf('default_height');$idx++;
$oid = (!empty($args[$idx])) ? urlencode($args[$idx]) : 'slideshow';$idx++;
$bgcolor = (!empty($args[$idx])) ? urlencode($args[$idx]) : $this->getConf('default_bgcolor');$idx++;
$align = (!empty($args[$idx])) ? urlencode($args[$idx]) : '';
$width_height = sprintf(' WIDTH="%s" HEIGHT="%s" '.NL,$width,$height);
$align_def = sprintf(' ALIGN="%s" ',$align);
$id_def = sprintf(' id="%s" '.NL,$oid);
$renderer->doc.= NL.'';
}
break;
case DOKU_LEXER_UNMATCHED:
if (empty($match))
return;
// direct content
$fetchPath = $this->createXmlFile($renderer->_xmlEntities($match),$width,$height,true);
$src = $this->swfLoc.'?xml_source='.urlencode($fetchPath).'&license='.$license;
$renderer->doc.= ' src="'.$src.'">'.NL;
$renderer->doc.= '';
break;
case DOKU_LEXER_EXIT:
break;
}
return true;
}
/**
* Replace Media file link of {{XXX}} to fetchable URL
*/
function replaceMediaLinks($content){
$new_content = preg_replace_callback(
"/{{([^|}]+).*}}/",
create_function('$matches','return ml($matches[1],"cache=nocache");'),
$content);
return $new_content;
}
/**
* Replace Wiki link of [[XXX]] to URL
*/
function replaceWikiLinks($content){
$new_content = preg_replace_callback(
"/\[\[([^|\]]+).*\]\]/",
create_function('$matches','return wl($matches[1]);'),
$content);
return $new_content;
}
/**
* Replace included source
*/
function replaceIncludedSrc($content){
$new_content = preg_replace_callback(
"/([^<]+?)<\/include>/",
create_function('$matches','return @include $matches[1];'),
$content);
return $new_content;
}
/**
* Create XML content in the plugin's media directory
*/
function createXmlFile(&$data,$w,$h,$needTag) {
global $conf;
$hash = md5(serialize($data).$w.$h);
$savePath = $this->xmlCache->GetMediaPath($hash);
if (!file_exists($savePath)){
$content = $this->cleanXml($data);
$content = $this->replaceMediaLinks($content);
$content = $this->replaceWikiLinks($content);
$content = $this->replaceIncludedSrc($content);
if ($needTag===true){
$content = sprintf('%s',$content);
}
if(io_saveFile($savePath, $content)){
chmod($savePath,$conf['fmode']);
}
}
return $this->xmlCache->GetMediaLink($hash);
}
/**
* Convert Xml entity
*/
function cleanXml($content){
$s = array("<",">","'",""","'");
$r = array("<",">","'","'",'"');
$cx = str_replace($s,$r,$content);
return $cx;
}
}
?>