Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions broken.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$meta['path'] = array('string');
$meta['svg'] = array('onoff');

9 changes: 6 additions & 3 deletions img.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
$data = $_REQUEST;
$plugin = plugin_load('syntax','graphviz');
$cache = $plugin->_imgfile($data);
$content_type = $plugin->_format == 'png' ? 'Content-Type: image/png' : 'Content-Type: image/svg+xml';

if(!$cache) _fail();

header('Content-Type: image/png;');
header($content_type);

header('Expires: '.gmdate("D, d M Y H:i:s", time()+max($conf['cachetime'], 3600)).' GMT');
header('Cache-Control: public, proxy-revalidate, no-transform, max-age='.max($conf['cachetime'], 3600));
header('Pragma: public');
Expand All @@ -24,8 +27,8 @@

function _fail(){
header("HTTP/1.0 404 Not Found");
header('Content-Type: image/png');
echo io_readFile('broken.png',false);
header($content_type);
echo io_readFile('broken.' . $plugin->_format, false);
exit;
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php

$lang['path'] = 'The path to your local graphviz dot binary (eg. <code>/usr/bin/dot</code>). Leave empty to use remote rendering at google.com.';
$lang['svg'] = 'Render the result to svg format. Only works when using local graphviz dot binary.';
12 changes: 9 additions & 3 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ function render($format, &$R, $data) {
* Return path to the rendered image on our local system
*/
function _imgfile($data){
$cache = $this->_cachename($data,'png');
if ($this->getConf('path') && $this->getConf('svg')) {
$this->_format = 'svg';
} else {
$this->_format = 'png';
}

$cache = $this->_cachename($data, $this->_format);

// create the file if needed
if(!file_exists($cache)){
Expand All @@ -135,7 +141,7 @@ function _imgfile($data){

// resized version
if($data['width']){
$cache = media_resize_image($cache,'png',$data['width'],$data['height']);
$cache = media_resize_image($cache,$this->_format,$data['width'],$data['height']);
}

// something went wrong, we're missing the file
Expand Down Expand Up @@ -182,7 +188,7 @@ function _run($data,$in,$out) {
}

$cmd = $this->getConf('path');
$cmd .= ' -Tpng';
$cmd .= ' -T' . $this->_format;
$cmd .= ' -K'.$data['layout'];
$cmd .= ' -o'.escapeshellarg($out); //output
$cmd .= ' '.escapeshellarg($in); //input
Expand Down