xref: /plugin/graphviz/img.php (revision 517bd8367891ed3eeda89c7608688f50ccdd0d7a)
1*517bd836SAndreas Gohr<?php
2*517bd836SAndreas Gohr/**
3*517bd836SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4*517bd836SAndreas Gohr * @author     Andreas Gohr <gohr@cosmocode.de>
5*517bd836SAndreas Gohr */
6*517bd836SAndreas Gohr
7*517bd836SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../../');
8*517bd836SAndreas Gohrdefine('NOSESSION',true);
9*517bd836SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php');
10*517bd836SAndreas Gohrrequire_once(DOKU_INC.'inc/pageutils.php');
11*517bd836SAndreas Gohrrequire_once(DOKU_INC.'inc/httputils.php');
12*517bd836SAndreas Gohrrequire_once(DOKU_INC.'inc/io.php');
13*517bd836SAndreas Gohr
14*517bd836SAndreas Gohr$data = $_REQUEST;
15*517bd836SAndreas Gohr$w = (int) $data['width'];
16*517bd836SAndreas Gohr$h = (int) $data['height'];
17*517bd836SAndreas Gohrunset($data['width']);
18*517bd836SAndreas Gohrunset($data['height']);
19*517bd836SAndreas Gohrunset($data['align']);
20*517bd836SAndreas Gohr
21*517bd836SAndreas Gohr$cache = getcachename(join('x',array_values($data)),'graphviz.png');
22*517bd836SAndreas Gohr
23*517bd836SAndreas Gohr// create the file if needed
24*517bd836SAndreas Gohrif(!file_exists($cache)){
25*517bd836SAndreas Gohr    $plugin = plugin_load('syntax','graphviz');
26*517bd836SAndreas Gohr    $plugin->_run($data,$cache);
27*517bd836SAndreas Gohr    clearstatcache();
28*517bd836SAndreas Gohr}
29*517bd836SAndreas Gohr
30*517bd836SAndreas Gohr// resized version
31*517bd836SAndreas Gohrif($w) $cache = media_resize_image($cache,'png',$w,$h);
32*517bd836SAndreas Gohr
33*517bd836SAndreas Gohr// something went wrong, we're missing the file
34*517bd836SAndreas Gohrif(!file_exists($cache)){
35*517bd836SAndreas Gohr    header("HTTP/1.0 404 Not Found");
36*517bd836SAndreas Gohr    header('Content-Type: image/png');
37*517bd836SAndreas Gohr    echo io_readFile('broken.png',false);
38*517bd836SAndreas Gohr    exit;
39*517bd836SAndreas Gohr}
40*517bd836SAndreas Gohr
41*517bd836SAndreas Gohrheader('Content-Type: image/png;');
42*517bd836SAndreas Gohrheader('Expires: '.gmdate("D, d M Y H:i:s", time()+max($conf['cachetime'], 3600)).' GMT');
43*517bd836SAndreas Gohrheader('Cache-Control: public, proxy-revalidate, no-transform, max-age='.max($conf['cachetime'], 3600));
44*517bd836SAndreas Gohrheader('Pragma: public');
45*517bd836SAndreas Gohrhttp_conditionalRequest($time);
46*517bd836SAndreas Gohrecho io_readFile($cache,false);
47*517bd836SAndreas Gohr
48*517bd836SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
49