xref: /plugin/graphviz/img.php (revision 517bd8367891ed3eeda89c7608688f50ccdd0d7a)
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');
10require_once(DOKU_INC.'inc/pageutils.php');
11require_once(DOKU_INC.'inc/httputils.php');
12require_once(DOKU_INC.'inc/io.php');
13
14$data = $_REQUEST;
15$w = (int) $data['width'];
16$h = (int) $data['height'];
17unset($data['width']);
18unset($data['height']);
19unset($data['align']);
20
21$cache = getcachename(join('x',array_values($data)),'graphviz.png');
22
23// create the file if needed
24if(!file_exists($cache)){
25    $plugin = plugin_load('syntax','graphviz');
26    $plugin->_run($data,$cache);
27    clearstatcache();
28}
29
30// resized version
31if($w) $cache = media_resize_image($cache,'png',$w,$h);
32
33// something went wrong, we're missing the file
34if(!file_exists($cache)){
35    header("HTTP/1.0 404 Not Found");
36    header('Content-Type: image/png');
37    echo io_readFile('broken.png',false);
38    exit;
39}
40
41header('Content-Type: image/png;');
42header('Expires: '.gmdate("D, d M Y H:i:s", time()+max($conf['cachetime'], 3600)).' GMT');
43header('Cache-Control: public, proxy-revalidate, no-transform, max-age='.max($conf['cachetime'], 3600));
44header('Pragma: public');
45http_conditionalRequest($time);
46echo io_readFile($cache,false);
47
48//Setup VIM: ex: et ts=4 enc=utf-8 :
49