1<?php 2 3/** 4 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 5 * @author Andreas Gohr <gohr@cosmocode.de> 6 */ 7 8if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../../../') . '/'); 9define('DOKU_DISABLE_GZIP_OUTPUT', 1); 10require_once(DOKU_INC . 'inc/init.php'); 11session_write_close(); 12 13global $conf; 14 15 16/** @var syntax_plugin_panoview $pl */ 17$pl = plugin_load('syntax', 'panoview'); 18 19$data = []; 20// get parameters 21[$data['zoom'], $data['col'], $data['row']] = explode('-', $_GET['tile']); 22$data['id'] = cleanID($_GET['image']); 23$data['file'] = mediaFN($data['id']); 24$data['mtime'] = @filemtime($data['file']); 25 26// check auth and existance 27if (auth_quickaclcheck(getNS($data['id']) . ':X') < AUTH_READ) $pl->gfxError('noauth'); 28if (!$data['mtime']) $pl->gfxError('notfound'); 29 30// calculate zoom level scaling 31$data['ts'] = 256; 32[$data['width'], $data['height']] = getimagesize($data['file']); 33$data['scale'] = (int) 2 ** $data['zoom']; 34$data['max'] = max($data['width'], $data['height']); 35$data['inv'] = $data['max'] / ($data['ts'] * $data['scale']); 36 37if ($data['inv'] < 0.5) $pl->gfxError('maxzoom'); 38if ($data['inv'] < 1.0) $data['inv'] = 1.0; // original size, no upscaling 39 40// calculate tile boundaries 41$data['tlx'] = (int) ($data['col'] * $data['ts'] * $data['inv']); 42$data['tly'] = (int) ($data['row'] * $data['ts'] * $data['inv']); 43$data['brx'] = (int) ($data['tlx'] + ($data['ts'] * $data['inv'])); 44$data['bry'] = (int) ($data['tly'] + ($data['ts'] * $data['inv'])); 45if ($data['tlx'] > $data['width'] || $data['tly'] > $data['height']) $pl->gfxError('blank'); 46 47// cache times 48$data['cache'] = getCacheName($data['file'], '.pv.' . $data['zoom'] . '-' . $data['col'] . '-' . $data['row'] . '.jpg'); 49$data['cachet'] = @filemtime($data['cache']); 50 51// (re)generate 52if ($data['cachet'] < $data['mtime']) { 53 $pl->tileLock($data); 54 if ($conf['im_convert']) { 55 $pl->tileIM($data); 56 } else { 57 $pl->tileGD($data); 58 } 59 $pl->tileUnlock($data); 60} 61 62// send 63header('Content-type: image/jpeg'); 64http_conditionalRequest(max($data['mtime'], $data['cachet'])); 65 66//use x-sendfile header to pass the delivery to compatible webservers 67http_sendfile($data['cache']); 68 69// send file contents 70$fp = @fopen($data['cache'], "rb"); 71if ($fp) { 72 http_rangeRequest($fp, filesize($data['cache']), 'image/jpeg'); 73} else { 74 header("HTTP/1.0 500 Internal Server Error"); 75 echo "Could not read tile - bad permissions?"; 76} 77