xref: /plugin/panoview/tiles.php (revision d6577f0fa1e9ac9cb06e93a0c568951309a03e57)
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 Gohrrequire_once(DOKU_INC.'inc/common.php');
1127bbde00SAndreas Gohrrequire_once(DOKU_INC.'inc/pageutils.php');
1227bbde00SAndreas Gohrrequire_once(DOKU_INC.'inc/httputils.php');
131faa1ff0SAndreas Gohrrequire_once(DOKU_INC.'inc/pluginutils.php');
1427bbde00SAndreas Gohrrequire_once(DOKU_INC.'inc/auth.php');
1527bbde00SAndreas Gohrsession_write_close();
1627bbde00SAndreas Gohr
17*d6577f0fSAndreas Gohr/** @var syntax_plugin_panoview $pl */
181faa1ff0SAndreas Gohr$pl =& plugin_load('syntax', 'panoview');
191faa1ff0SAndreas Gohr
2027bbde00SAndreas Gohr$data = array();
2127bbde00SAndreas Gohr// get parameters
2227bbde00SAndreas Gohrlist($data['zoom'], $data['col'], $data['row']) = explode('-', $_GET['tile']);
2327bbde00SAndreas Gohr$data['id']    = cleanID($_GET['image']);
2427bbde00SAndreas Gohr$data['file']  = mediaFN($data['id']);
2527bbde00SAndreas Gohr$data['mtime'] = @filemtime($data['file']);
2627bbde00SAndreas Gohr
2727bbde00SAndreas Gohr// check auth and existance
28*d6577f0fSAndreas Gohrif(auth_quickaclcheck(getNS($data['id']).':X') < AUTH_READ) $pl->gfx_error('noauth');
291faa1ff0SAndreas Gohrif(!$data['mtime']) $pl->gfx_error('notfound');
3027bbde00SAndreas Gohr
3127bbde00SAndreas Gohr// calculate zoom level scaling
3227bbde00SAndreas Gohr$data['ts'] = 256;
3327bbde00SAndreas Gohrlist($data['width'], $data['height']) = getimagesize($data['file']);
3427bbde00SAndreas Gohr$data['scale'] = (int) pow(2, $data['zoom']);
3527bbde00SAndreas Gohr$data['max']   = max($data['width'], $data['height']);
3627bbde00SAndreas Gohr$data['inv']   = $data['max'] / ($data['ts'] * $data['scale']);
37359cb25cSAndreas Gohr
38359cb25cSAndreas Gohrif($data['inv'] < 0.5) $pl->gfx_error('maxzoom');
39359cb25cSAndreas Gohrif($data['inv'] < 1.0) $data['inv'] = 1.0; // original size, no upscaling
4027bbde00SAndreas Gohr
4127bbde00SAndreas Gohr// calculate tile boundaries
4227bbde00SAndreas Gohr$data['tlx'] = (int) ($data['col'] * $data['ts'] * $data['inv']);
4327bbde00SAndreas Gohr$data['tly'] = (int) ($data['row'] * $data['ts'] * $data['inv']);
4427bbde00SAndreas Gohr$data['brx'] = (int) ($data['tlx'] + ($data['ts'] * $data['inv']));
4527bbde00SAndreas Gohr$data['bry'] = (int) ($data['tly'] + ($data['ts'] * $data['inv']));
461faa1ff0SAndreas Gohrif($data['tlx'] > $data['width'] || $data['tly'] > $data['height']) $pl->gfx_error('blank');
4727bbde00SAndreas Gohr
4827bbde00SAndreas Gohr// cache times
4927bbde00SAndreas Gohr$data['cache']  = getCacheName($data['file'], '.pv.'.$data['zoom'].'-'.$data['col'].'-'.$data['row'].'.jpg');
5027bbde00SAndreas Gohr$data['cachet'] = @filemtime($data['cache']);
5127bbde00SAndreas Gohr
5227bbde00SAndreas Gohr// (re)generate
53c131b324SAndreas Gohrif($data['cachet'] < $data['mtime']) {
541faa1ff0SAndreas Gohr    $pl->tile_lock($data);
55dc838624SAndreas Gohr    if($conf['im_convert']) {
561faa1ff0SAndreas Gohr        $pl->tile_im($data);
57dc838624SAndreas Gohr    } else {
581faa1ff0SAndreas Gohr        $pl->tile_gd($data);
5927bbde00SAndreas Gohr    }
601faa1ff0SAndreas Gohr    $pl->tile_unlock($data);
61dc838624SAndreas Gohr}
6227bbde00SAndreas Gohr
6327bbde00SAndreas Gohr// send
6427bbde00SAndreas Gohrheader('Content-type: image/jpeg');
6527bbde00SAndreas Gohrhttp_conditionalRequest(max($data['mtime'], $data['selft']));
66*d6577f0fSAndreas Gohr
67*d6577f0fSAndreas Gohr//use x-sendfile header to pass the delivery to compatible webservers
68*d6577f0fSAndreas Gohrif(http_sendfile($file)) exit;
69*d6577f0fSAndreas Gohr
70*d6577f0fSAndreas Gohr// send file contents
71*d6577f0fSAndreas Gohr$fp = @fopen($data['cache'], "rb");
72*d6577f0fSAndreas Gohrif($fp) {
73*d6577f0fSAndreas Gohr    http_rangeRequest($fp, filesize($data['cache']), 'image/jpeg');
74*d6577f0fSAndreas Gohr} else {
75*d6577f0fSAndreas Gohr    header("HTTP/1.0 500 Internal Server Error");
76*d6577f0fSAndreas Gohr    print "Could not read tile - bad permissions?";
77*d6577f0fSAndreas Gohr}
7827bbde00SAndreas Gohr
7927bbde00SAndreas Gohr
8027bbde00SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
81