127bbde00SAndreas Gohr<?php 227bbde00SAndreas Gohr/** 327bbde00SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 427bbde00SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 527bbde00SAndreas Gohr */ 627bbde00SAndreas Gohr 727bbde00SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../../../').'/'); 827bbde00SAndreas Gohrdefine('DOKU_DISABLE_GZIP_OUTPUT', 1); 927bbde00SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 1027bbde00SAndreas Gohrsession_write_close(); 1127bbde00SAndreas Gohr 12*7242a9edSAndreas Gohrglobal $conf; 13*7242a9edSAndreas Gohr 14*7242a9edSAndreas Gohr 15d6577f0fSAndreas Gohr/** @var syntax_plugin_panoview $pl */ 16*7242a9edSAndreas Gohr$pl = plugin_load('syntax', 'panoview'); 171faa1ff0SAndreas Gohr 1827bbde00SAndreas Gohr$data = array(); 1927bbde00SAndreas Gohr// get parameters 2027bbde00SAndreas Gohrlist($data['zoom'], $data['col'], $data['row']) = explode('-', $_GET['tile']); 2127bbde00SAndreas Gohr$data['id'] = cleanID($_GET['image']); 2227bbde00SAndreas Gohr$data['file'] = mediaFN($data['id']); 2327bbde00SAndreas Gohr$data['mtime'] = @filemtime($data['file']); 2427bbde00SAndreas Gohr 2527bbde00SAndreas Gohr// check auth and existance 26d6577f0fSAndreas Gohrif(auth_quickaclcheck(getNS($data['id']).':X') < AUTH_READ) $pl->gfx_error('noauth'); 271faa1ff0SAndreas Gohrif(!$data['mtime']) $pl->gfx_error('notfound'); 2827bbde00SAndreas Gohr 2927bbde00SAndreas Gohr// calculate zoom level scaling 3027bbde00SAndreas Gohr$data['ts'] = 256; 3127bbde00SAndreas Gohrlist($data['width'], $data['height']) = getimagesize($data['file']); 3227bbde00SAndreas Gohr$data['scale'] = (int) pow(2, $data['zoom']); 3327bbde00SAndreas Gohr$data['max'] = max($data['width'], $data['height']); 3427bbde00SAndreas Gohr$data['inv'] = $data['max'] / ($data['ts'] * $data['scale']); 35359cb25cSAndreas Gohr 36359cb25cSAndreas Gohrif($data['inv'] < 0.5) $pl->gfx_error('maxzoom'); 37359cb25cSAndreas Gohrif($data['inv'] < 1.0) $data['inv'] = 1.0; // original size, no upscaling 3827bbde00SAndreas Gohr 3927bbde00SAndreas Gohr// calculate tile boundaries 4027bbde00SAndreas Gohr$data['tlx'] = (int) ($data['col'] * $data['ts'] * $data['inv']); 4127bbde00SAndreas Gohr$data['tly'] = (int) ($data['row'] * $data['ts'] * $data['inv']); 4227bbde00SAndreas Gohr$data['brx'] = (int) ($data['tlx'] + ($data['ts'] * $data['inv'])); 4327bbde00SAndreas Gohr$data['bry'] = (int) ($data['tly'] + ($data['ts'] * $data['inv'])); 441faa1ff0SAndreas Gohrif($data['tlx'] > $data['width'] || $data['tly'] > $data['height']) $pl->gfx_error('blank'); 4527bbde00SAndreas Gohr 4627bbde00SAndreas Gohr// cache times 4727bbde00SAndreas Gohr$data['cache'] = getCacheName($data['file'], '.pv.'.$data['zoom'].'-'.$data['col'].'-'.$data['row'].'.jpg'); 4827bbde00SAndreas Gohr$data['cachet'] = @filemtime($data['cache']); 4927bbde00SAndreas Gohr 5027bbde00SAndreas Gohr// (re)generate 51c131b324SAndreas Gohrif($data['cachet'] < $data['mtime']) { 521faa1ff0SAndreas Gohr $pl->tile_lock($data); 53dc838624SAndreas Gohr if($conf['im_convert']) { 541faa1ff0SAndreas Gohr $pl->tile_im($data); 55dc838624SAndreas Gohr } else { 561faa1ff0SAndreas Gohr $pl->tile_gd($data); 5727bbde00SAndreas Gohr } 581faa1ff0SAndreas Gohr $pl->tile_unlock($data); 59dc838624SAndreas Gohr} 6027bbde00SAndreas Gohr 6127bbde00SAndreas Gohr// send 6227bbde00SAndreas Gohrheader('Content-type: image/jpeg'); 63*7242a9edSAndreas Gohrhttp_conditionalRequest(max($data['mtime'], $data['cachet'])); 64d6577f0fSAndreas Gohr 65d6577f0fSAndreas Gohr//use x-sendfile header to pass the delivery to compatible webservers 66*7242a9edSAndreas Gohrhttp_sendfile($data['cache']); 67d6577f0fSAndreas Gohr 68d6577f0fSAndreas Gohr// send file contents 69d6577f0fSAndreas Gohr$fp = @fopen($data['cache'], "rb"); 70d6577f0fSAndreas Gohrif($fp) { 71d6577f0fSAndreas Gohr http_rangeRequest($fp, filesize($data['cache']), 'image/jpeg'); 72d6577f0fSAndreas Gohr} else { 73d6577f0fSAndreas Gohr header("HTTP/1.0 500 Internal Server Error"); 74d6577f0fSAndreas Gohr print "Could not read tile - bad permissions?"; 75d6577f0fSAndreas Gohr} 76