1<?php 2/** 3 * Embed an image gallery 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'); 12require_once(DOKU_INC.'inc/search.php'); 13require_once(DOKU_INC.'inc/JpegMeta.php'); 14 15class syntax_plugin_panoview extends DokuWiki_Syntax_Plugin { 16 /** 17 * return some info 18 */ 19 function getInfo(){ 20 return confToHash(dirname(__FILE__).'/info.txt'); 21 } 22 23 /** 24 * What kind of syntax are we? 25 */ 26 function getType(){ 27 return 'substition'; 28 } 29 30 /** 31 * What about paragraphs? 32 */ 33 function getPType(){ 34 return 'block'; 35 } 36 37 /** 38 * Where to sort in? 39 */ 40 function getSort(){ 41 return 301; 42 } 43 44 45 /** 46 * Connect pattern to lexer 47 */ 48 function connectTo($mode) { 49 $this->Lexer->addSpecialPattern('\{\{panoview>[^}]*\}\}',$mode,'plugin_panoview'); 50 } 51 52 /** 53 * Handle the match 54 */ 55 function handle($match, $state, $pos, &$handler){ 56 global $ID; 57 58 $data = array( 59 'width' => 500, 60 'height' => 250, 61 'align' => 0, 62 'initialZoom' => 2, 63 'tileBaseUri' => DOKU_BASE.'lib/plugins/panoview/tiles.php', 64 'tileSize' => 256, 65 'maxZoom' => 10, 66 'blankTile' => DOKU_BASE.'lib/plugins/panoview/gfx/blank.gif', 67 'loadingTile' => DOKU_BASE.'lib/plugins/panoview/gfx/progress.gif', 68 ); 69 70 $match = substr($match,11,-2); //strip markup from start and end 71 72 // alignment 73 $data['align'] = 0; 74 if(substr($match,0,1) == ' ') $data['align'] += 1; 75 if(substr($match,-1,1) == ' ') $data['align'] += 2; 76 77 // extract params 78 list($img,$params) = explode('?',$match,2); 79 $img = trim($img); 80 81 // resolving relatives 82 $data['image'] = resolve_id(getNS($ID),$img); 83 84 $file = mediaFN($data['image']); 85 list($data['imageWidth'],$data['imageHeight']) = @getimagesize($file); 86 87 // size 88 if(preg_match('/^(\d+)[xX](\d+)$/',$params,$match)){ 89 $data['width'] = $match[1]; 90 $data['height'] = $match[2]; 91 } 92 93 return $data; 94 } 95 96 /** 97 * Create output 98 */ 99 function render($mode, &$R, $data) { 100 if($mode != 'xhtml') return false; 101 102 require_once(DOKU_INC.'inc/JSON.php'); 103 $json = new JSON(); 104 105 $img = '<a href="'.ml($data['image']).'"><img src="'. 106 ml($data['image'], array('w'=>$data['width'],'h'=>$data['height'])).'" width="'. 107 $data['width'].'" height="'.$data['height'].'" alt="" /></a>'; 108 109 110 $R->doc .= ' 111 <div class="panoview_plugin" style="width: '.$data['width'].'px; height: '.$data['height'].'px;"> 112 <div class="well"><!-- --></div> 113 <div class="surface">'.$img.'</div> 114 <p class="controls" style="display: none"> 115 <span class="zoomIn" title="Zoom In">+</span> 116 <span class="zoomOut" title="Zoom Out">-</span> 117 </p> 118 <div class="options" style="display:none">'.hsc($json->encode($data)).'</div> 119 </div> 120 '; 121 122 123 return true; 124 } 125 126 127} 128 129//Setup VIM: ex: et ts=4 enc=utf-8 : 130