*/
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
require_once(DOKU_INC.'inc/search.php');
require_once(DOKU_INC.'inc/JpegMeta.php');
class syntax_plugin_panoview extends DokuWiki_Syntax_Plugin {
/**
* What kind of syntax are we?
*/
function getType() {
return 'substition';
}
/**
* What about paragraphs?
*/
function getPType() {
return 'block';
}
/**
* Where to sort in?
*/
function getSort() {
return 301;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{panoview>[^}]*\}\}', $mode, 'plugin_panoview');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler) {
global $ID;
$data = array(
'width' => 500,
'height' => 250,
'align' => 0,
'initialZoom' => 1,
'tileBaseUri' => DOKU_BASE.'lib/plugins/panoview/tiles.php',
'tileSize' => 256,
'maxZoom' => 10,
'blankTile' => DOKU_BASE.'lib/plugins/panoview/gfx/blank.gif',
'loadingTile' => DOKU_BASE.'lib/plugins/panoview/gfx/progress.gif',
);
$match = substr($match, 11, -2); //strip markup from start and end
// alignment
$data['align'] = 0;
if(substr($match, 0, 1) == ' ') $data['align'] += 1;
if(substr($match, -1, 1) == ' ') $data['align'] += 2;
// extract params
list($img, $params) = explode('?', $match, 2);
$img = trim($img);
// resolving relatives
$data['image'] = resolve_id(getNS($ID), $img);
$file = mediaFN($data['image']);
list($data['imageWidth'], $data['imageHeight']) = @getimagesize($file);
// calculate maximum zoom
$data['maxZoom'] = ceil(sqrt(max($data['imageWidth'], $data['imageHeight']) / $data['tileSize']));
// size
if(preg_match('/\b(\d+)[xX](\d+)\b/', $params, $match)) {
$data['width'] = $match[1];
$data['height'] = $match[2];
}
// initial zoom
if(preg_match('/\b[zZ](\d+)\b/', $params, $match)) {
$data['initialZoom'] = $match[1];
}
if($data['initialZoom'] < 0) $data['initialZoom'] = 0;
if($data['initialZoom'] > $data['maxZoom']) $data['initialZoom'] = $data['maxZoom'];
return $data;
}
/**
* Create output
*/
function render($mode, &$R, $data) {
if($mode != 'xhtml') return false;
global $ID;
require_once(DOKU_INC.'inc/JSON.php');
$json = new JSON();
$img = '';
if($data['align'] == 1) {
$align = 'medialeft';
} elseif($data['align'] == 2) {
$align = 'mediaright';
} else {
$align = 'mediacenter';
}
$R->doc .= '