1<?php 2/* 3description : Display Airtight Simpleviewer 4author : TTy32 (Original by Ikuo Obataya) 5email : randy@tty32.org 6lastupdate : 2011-04-15 7depends : cache (2008-03-22 or later) 8license : GPL 2 (http://www.gnu.org/licenses/gpl.html) 9*/ 10 11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 12 require_once(DOKU_INC.'inc/init.php'); 13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 14 require_once(DOKU_PLUGIN.'syntax.php'); 15if (!class_exists('JpegMeta')) @require(DOKU_INC.'inc/JpegMeta.php'); 16 17if(!file_exists(DOKU_PLUGIN.'cache/plugin_cache.php')){ 18 echo '<b>sviewer plugin requires <a href="http://www.dokuwiki.org/plugin:cache" target="_blank">cache plugin.</b>'; 19 exit; 20} 21if (!class_exists('plugin_cache')) @require(DOKU_PLUGIN.'cache/plugin_cache.php'); 22 23class syntax_plugin_sviewer extends DokuWiki_Syntax_Plugin { 24 var $xmlCache; 25 var $attrPattern; 26 var $listPattern; 27 var $swfLoc; 28 var $swfObjPath; 29 // Constructor 30 function syntax_plugin_sviewer(){ 31 $this->xmlCache = new plugin_cache("sviewer",'',"xml"); 32 33 //By TTy32 34 35 $this->attrPattern = '/(\d+) (\d+) (\w+) (\w+) (\w+) (\w+) (\d*) (\w+) (\d*) (\d*) (\w+) (\w+) (\d+) (\d+) (\d*) "([^"]*)"?>|(clear_cache)>|(remove_dir)>/'; 36 37 $this->listPattern = '/\{\{([^}|]+)\|?([^}]*)\}\}/'; 38 $this->swfLoc = DOKU_BASE.'lib/plugins/sviewer/simpleviewer/simpleviewer.swf'; 39 $this->swfJsPath = DOKU_BASE.'lib/plugins/sviewer/simpleviewer/simpleviewer.js'; 40 } 41 function getInfo(){ 42 return array( 43 'author' => 'TTy32 (Original by Ikuo Obataya)', 44 'email' => 'randy@tty32.org', 45 'date' => '2011-04-15', 46 'name' => 'Airtight Simpleviewer plugin', 47 'desc' => 'Create Simpleviewer by www.airtightinteractive.com 48 <sviewer> 49 image files or media namespace 50 </sviewer>', 51 'url' => 'http://tty32.org', 52 ); 53 } 54 function getType(){ return 'protected'; } 55 function getSort(){ return 917; } 56 // Entry 57 function connectTo($mode) { 58 $this->Lexer->addEntryPattern('<sviewer(?=.*?>.*?</sviewer>)',$mode,'plugin_sviewer'); 59 } 60 // Exit 61 function postConnect() { 62 $this->Lexer->addExitPattern('</sviewer>','plugin_sviewer'); 63 } 64 // Handler 65 function handle($match, $state, $pos) { 66 global $ID; 67 global $conf; 68 switch ($state) { 69 case DOKU_LEXER_UNMATCHED : 70 $m = preg_match_all($this->attrPattern,$match,$cmd); 71 72 if ($m!=1){ 73 $width = $this->getConf('width'); 74 $height = $this->getConf('height'); 75 76 }else{ 77 // extra commands - Mod By TTy32 78 if (strtolower($cmd[17][0])=='clear_cache'){$this->xmlCache->ClearCache();return array($state,'');} 79 if (strtolower($cmd[18][0])=='remove_dir') {$this->xmlCache->RemoveDir(); return array($state,'');} 80 81 // width/height/alignment 82 $width = $cmd[1][0]; 83 $height = $cmd[2][0]; 84 $align = $cmd[3][0]; 85 86 // By TTy32 87 $option_galleryStyle = strtoupper($cmd[4][0]); 88 $option_textColor = $cmd[5][0]; 89 $option_frameColor = $cmd[6][0]; 90 $option_frameWidth = $cmd[7][0]; 91 $option_thumbPosition = strtoupper($cmd[8][0]); 92 $option_thumbColumns = $cmd[9][0]; 93 $option_thumbRows = $cmd[10][0]; 94 $option_showOpenButton = strtoupper($cmd[11][0]); 95 $option_showFullscreenButton = strtoupper($cmd[12][0]); 96 $option_maxImageWidth = $cmd[13][0]; 97 $option_maxImageHeight = $cmd[14][0]; 98 $option_captionMode = $cmd[15][0]; 99 $option_title = $cmd[16][0]; 100 } 101 if(empty($align)) $align = $this->getConf('align'); 102 103 // By TTy32 104 if(empty($option_galleryStyle)) $option_galleryStyle = $this->getConf('galleryStyle'); 105 if(empty($option_textColor)) $option_textColor = $this->getConf('textColor'); 106 if(empty($option_frameColor)) $option_frameColor = $this->getConf('frameColor'); 107 if(empty($option_frameWidth)) $option_frameWidth = $this->getConf('frameWidth'); 108 if(empty($option_thumbPosition)) $option_thumbPosition = $this->getConf('thumbPosition'); 109 if(empty($option_thumbColumns)) $option_thumbColumns = $this->getConf('thumbColumns'); 110 if(empty($option_thumbRows)) $option_thumbRows = $this->getConf('thumbRows'); 111 if(empty($option_showOpenButton)) $option_showOpenButton = $this->getConf('showOpenButton'); 112 if(empty($option_showFullscreenButton)) $option_showFullscreenButton = $this->getConf('showFullscreenButton'); 113 if(empty($option_maxImageWidth)) $option_maxImageWidth = $this->getConf('maxImageWidth'); 114 if(empty($option_maxImageHeight)) $option_maxImageHeight = $this->getConf('maxImageHeight'); 115 if(empty($option_captionMode)) $option_captionMode = $this->getConf('captionMode'); 116 if(empty($option_title)) $option_title = $this->getConf('title'); 117 118 119 $sz = preg_match_all($this->listPattern,$match,$img); 120 if ($sz==0){ 121 $img = array(); 122 $img[1][0] = getNS($ID); 123 $img[2][0] = $ID; 124 $sz = 1; 125 } 126 127 // By TTy32 128 $xml.=sprintf('<?xml version="1.0" encoding="UTF-8"?> 129 130 <simpleviewergallery 131 132 galleryStyle="%s" 133 title="%s" 134 textColor="%s" 135 frameColor="%s" 136 frameWidth="%s" 137 thumbPosition="%s" 138 thumbColumns="%s" 139 thumbRows="%s" 140 showOpenButton="%s" 141 showFullscreenButton="%s" 142 maxImageWidth="%s" 143 maxImageHeight="%s" 144 useFlickr="false" 145 flickrUserName="" 146 flickrTags="" 147 languageCode="AUTO" 148 languageList="" 149 imagePath="images/" 150 thumbPath="thumbs/" 151 152 >', 153 154 $option_galleryStyle, 155 $option_title, 156 $option_textColor, 157 $option_frameColor, 158 $option_frameWidth, 159 $option_thumbPosition, 160 $option_thumbColumns, 161 $option_thumbRows, 162 $option_showOpenButton, 163 $option_showFullscreenButton, 164 $option_maxImageWidth, 165 $option_maxImageHeight); 166 167 168 169 for($i=0;$i<$sz;$i++){ 170 171 // build filepaths from an input line 172 $mediaID = (substr($mediaID,0,1)==':')?substr($img[1][$i],1):$img[1][$i]; 173 $path = mediaFN($mediaID); 174 $mlink = ml($mediaID,'',true,'',true); 175 $caption = $img[2][$i]; 176 $paths = array(); 177 $urls = array(); 178 179 if(is_dir($path)){ 180 // get file paths from a namespace 181 $d = $conf['useslash']?'/':':'; 182 $dir_handle = @opendir($path); 183 $caption = '(in '.$mediaID.')'; 184 while(($f = readdir($dir_handle))!==false){ 185 $p = $path.'/'.$f; 186 if ($f=='.'||$f=='..'||is_dir($p)) continue; 187 $paths[] = $p; 188 $urls[] = $mlink.$d.$f; 189 } 190 @closedir($dir_handle); 191 }else{ 192 // get file path 193 $paths[] = $path; 194 $urls[] = $mlink; 195 } 196 197 $fsz = count($paths); 198 for($j=0;$j<$fsz;$j++){ 199 $path = $paths[$j]; 200 /* By SuicideFunky >> */ 201 $caption2 = ""; 202 $filename = substr($path, strrpos($path, "/")+1, 99); //Filename with extension - By SuicideFunky 203 $filename2 = substr($filename, 1,strrpos($filename, ".")-1); //Filename without extension - By SuicideFunky 204 if ($option_captionMode == 0) { 205 $caption2 = ""; 206 } else if ($option_captionMode == 1) { 207 $caption2 = $filename; 208 } else { 209 $caption2 = $filename2; 210 } 211 /* end */ 212 $url = $urls[$j]; 213 $title = (empty($caption))?$path:$caption; 214 if(!file_exists($path))continue; 215 $jm = new JpegMeta($path); 216 $f = @$jm->getResizeRatio($width,$height); 217 $info = @$jm->getBasicInfo(); 218 $rwidth = floor($info['Width']*$f); 219 $rheight = floor($info['Height']*$f); 220 221 // By TTy32 222 $xml.='<image '.NL; 223 $xml.='imageURL="'.$url.'" '; 224 $xml.='thumbURL="'.$url.'" '; 225 $xml.='linkURL="" '; 226 $xml.='linkTarget="" >'.NL; 227 $xml.=' <caption>'.$caption2.'</caption>'.NL; 228 $xml.='</image>'.NL; 229 230 } 231 } 232 $xml.='</simpleviewergallery>'.NL; //By TTy32 233 return array($state, array($xml,$width,$height,$align)); 234 235 case DOKU_LEXER_ENTER :return array($state,$match); 236 case DOKU_LEXER_EXIT :return array($state, ''); 237 } 238 } 239 // Render 240 function render($mode, Doku_Renderer $renderer, $data){ 241 if ($mode!='xhtml') return false; 242 global $conf; 243 list($state, $match) = $data; 244 switch ($state) { 245 case DOKU_LEXER_ENTER: break; 246 case DOKU_LEXER_UNMATCHED: 247 if (empty($match)) 248 return; 249 250 list($xml,$width,$height,$align)=$match; 251 $hash = md5(serialize($match)); 252 $savePath = $this->xmlCache->GetMediaPath($hash); 253 if (!file_exists($savePath)){ 254 if(io_saveFile($savePath, $xml)){ 255 chmod($savePath,$conf['fmode']); 256 } 257 } 258 $fetchPath = ml('sviewer:'.$hash.'.xml','',true,'',true); 259 260 // By TTy32 261 $renderer->doc.=sprintf('<div class="sviewer"> 262 263 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="%s" height="%s" id="header1" align="%s"> 264 <param name="allowScriptAccess" value="sameDomain" /> 265 <param name="allowFullScreen" value="true" /> 266 267 <param name="movie" value="%s?galleryURL=%s" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="scale" value="exactfit" /><param name="salign" value="t" /><param name="wmode" value="transparent" /><param name="bgcolor" value="" /> <embed src="%s?galleryURL=%s" menu="false" quality="best" scale="exactfit" salign="t" wmode="transparent" bgcolor="" width="%s" height="%s" name="header1" align="%s" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" /> 268 </object> 269 270 </div>', 271 272 $width, 273 $height, 274 $align, 275 $this->swfLoc, 276 $fetchPath, 277 $this->swfLoc, 278 $fetchPath, 279 $width, 280 $height, 281 $align); 282 283 break; 284 case DOKU_LEXER_EXIT: break; 285 } 286 return true; 287 } 288 /** 289 * Build <image> element by fetch url and caption 290 */ 291 function getImageElement($url,$caption){ 292 $path = $paths[$j]; 293 $url = $urls[$j]; 294 $title = (empty($caption))?$path:$caption; 295 if(!file_exists($path))continue; 296 $jm = new JpegMeta($path); 297 $f = @$jm->getResizeRatio($width,$height); 298 $info = @$jm->getBasicInfo(); 299 $rwidth = floor($info['Width']*$f); 300 $rheight = floor($info['Height']*$f); 301 302 // By TTy32 303 $xml.='<image '.NL; 304 $xml.='imageURL="'.$url.'" '; 305 $xml.='thumbURL="'.$url.'" '; 306 $xml.='linkURL="" '; 307 $xml.='linkTarget="" >'.NL; 308 $xml.=' <caption>'.$title.'</caption>'.NL; 309 $xml.='</image>'.NL; 310 return $xml; 311 } 312 313 /** 314 * print debug info 315 */ 316 function _sviewer_debug($msg){ 317 global $conf; 318 if($conf['allowdebug']!=0){ 319 echo '<!-- sviewer plugin debug:'.$msg.'-->'.NL; 320 } 321 } 322} 323?>