Skip to content

Commit

Permalink
streamlined code with graphviz plugin
Browse files Browse the repository at this point in the history
ODT export should work now
  • Loading branch information
splitbrain committed Nov 15, 2010
1 parent 05cbae8 commit 95615d6
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 76 deletions.
57 changes: 0 additions & 57 deletions ditaa.php

This file was deleted.

32 changes: 32 additions & 0 deletions img.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/

if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../../');
define('NOSESSION',true);
require_once(DOKU_INC.'inc/init.php');

// let the syntax plugin do the work
$data = $_REQUEST;
$plugin = plugin_load('syntax','ditaa');
$cache = $plugin->_imgfile($data);
if(!$cache) _fail();

header('Content-Type: image/png;');
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');
http_conditionalRequest($time);
echo io_readFile($cache,false);


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

//Setup VIM: ex: et ts=4 enc=utf-8 :
2 changes: 1 addition & 1 deletion plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
base ditaa
author Andreas Gohr
email andi@splitbrain.org
date 2010-08-29
date 2010-11-15
name Ditaa-Plugin (ditaa 0.9)
desc Renders ASCII flowcharts contained in a DokuWiki page to images
url http://www.dokuwiki.org/plugin:ditaa
Expand Down
77 changes: 59 additions & 18 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,78 @@ function handle($match, $state, $pos, &$handler) {
return $return;
}

/**
* Cache file is based on parameters that influence the result image
*/
function _cachename($data,$ext){
unset($data['width']);
unset($data['height']);
unset($data['align']);
return getcachename(join('x',array_values($data)),'.ditaa.'.$ext);
}

/**
* Create output
*/
function render($format, &$R, $data) {
if($format != 'xhtml') return;
$img = DOKU_BASE.'lib/plugins/ditaa/ditaa.php?'.buildURLparams($data,'&');

$R->doc .= '<img src="'.$img.'" class="media'.$data['align'].'" alt=""';
if($data['width']) $R->doc .= ' width="'.$data['width'].'"';
if($data['height']) $R->doc .= ' height="'.$data['height'].'"';
if($data['align'] == 'right') $ret .= ' align="right"';
if($data['align'] == 'left') $ret .= ' align="left"';
$R->doc .= '/>';
if($format == 'xhtml'){
$img = DOKU_BASE.'lib/plugins/ditaa/img.php?'.buildURLparams($data);
$R->doc .= '<img src="'.$img.'" class="media'.$data['align'].'" alt=""';
if($data['width']) $R->doc .= ' width="'.$data['width'].'"';
if($data['height']) $R->doc .= ' height="'.$data['height'].'"';
if($data['align'] == 'right') $ret .= ' align="right"';
if($data['align'] == 'left') $ret .= ' align="left"';
$R->doc .= '/>';
return true;
}elseif($format == 'odt'){
$src = $this->_imgfile($data);
$R->_odtAddImage($src,$data['width'],$data['height'],$data['align']);
return true;
}
return false;
}


/**
* Cache file is based on data
* Return path to the rendered image on our local system
*/
function _cachename($data,$ext){
unset($data['width']);
unset($data['height']);
unset($data['align']);
return getcachename(join('x',array_values($data)),'.ditaa.'.$ext);
function _imgfile($data){
$cache = $this->_cachename($data,'png');

// create the file if needed
if(!file_exists($cache)){
$in = $this->_cachename($data,'txt');
if($this->getConf('java')){
$ok = $this->_run($data,$in,$cache);
}else{
$ok = $this->_remote($data,$in,$cache);
}
if(!$ok) return false;
clearstatcache();
}

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

// something went wrong, we're missing the file
if(!file_exists($cache)) return false;

return $cache;
}

/**
* Render the output remotely at ditaa.org
*/
function _remote($data,$in,$out){
if(!file_exists($in)){
if($conf['debug']){
dbglog($in,'no such ditaa input file');
}
return false;
}

$http = new DokuHTTPClient();
$http->timeout=30;

Expand All @@ -137,11 +180,9 @@ function _remote($data,$in,$out){
$img = $http->post('http://ditaa.org/ditaa/render',$pass);
if(!$img) return false;

io_saveFile($out,$img);
return true;
return io_saveFile($out,$img);
}


/**
* Run the ditaa Java program
*/
Expand Down

0 comments on commit 95615d6

Please sign in to comment.