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