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', dirname(__FILE__) . '/../../../');
8define('NOSESSION', true);
9require_once(DOKU_INC . 'inc/init.php');
10global $conf;
11
12$cache = getCacheName($_GET['img'], '.mathpublish.png');
13if(!file_exists($cache)) _fail();
14$time = filemtime($cache);
15
16header('Content-Type: image/png;');
17header('Expires: ' . gmdate("D, d M Y H:i:s", time() + max($conf['cachetime'], 3600)) . ' GMT');
18header('Cache-Control: public, proxy-revalidate, no-transform, max-age=' . max($conf['cachetime'], 3600));
19header('Pragma: public');
20http_conditionalRequest($time);
21http_sendfile($cache); // exits if x-sendfile support
22$fp = @fopen($cache, "rb");
23if($fp) {
24    http_rangeRequest($fp, filesize($cache), 'image/png');
25} else {
26    http_status(500);
27    print 'Could not read file - bad permissions?';
28}
29
30function _fail() {
31    http_status(404);
32    header('Content-Type: image/png');
33    echo io_readFile(__DIR__ . '/broken.png', false);
34    exit;
35}
36
37