From a00d96c80fb0ab09a00c6f4c7cb0129cc87310a0 Mon Sep 17 00:00:00 2001 From: MichaelKling Date: Sat, 1 Oct 2011 18:06:28 +0300 Subject: [PATCH] Adding mapfiles in order to make graphviz diagrams "clickable" --- syntax.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/syntax.php b/syntax.php index 518d027..1bb9ba8 100644 --- a/syntax.php +++ b/syntax.php @@ -96,15 +96,23 @@ function _cachename($data,$ext){ /** * Create output + * Edited by Michael Kling for the MAP patch. + * @todo ODT format doesnt support maps */ function render($format, &$R, $data) { if($format == 'xhtml'){ $img = DOKU_BASE.'lib/plugins/graphviz/img.php?'.buildURLparams($data); + $mapcache = $this->_mapfile($data); + $map = io_readFile($mapcache,false); + if ($mapcache !== false) { + $R->doc .= ''.$map.''; + } $R->doc .= 'doc .= ' width="'.$data['width'].'"'; if($data['height']) $R->doc .= ' height="'.$data['height'].'"'; if($data['align'] == 'right') $R->doc .= ' align="right"'; if($data['align'] == 'left') $R->doc .= ' align="left"'; + if($mapcache !== false) $R->doc .= ' usemap="#'.$data['md5'].'"'; $R->doc .= '/>'; return true; }elseif($format == 'odt'){ @@ -144,6 +152,33 @@ function _imgfile($data){ return $cache; } + /** + * Return path to the rendered map on our local system + * @Todo: Doesnt resize the map in case the image was resized + * @Todo: Remotehandling on google isnt realized + * @Author: Michael Kling + */ + function _mapfile($data){ + $cache = $this->_cachename($data,'map'); + + // create the file if needed + if(!file_exists($cache)){ + $in = $this->_cachename($data,'txt'); + if($this->getConf('path')){ + $ok = $this->_map($data,$in,$cache); + }else{ + //Dont handle it remote at google cause i dont know how to do + } + if(!$ok) return false; + clearstatcache(); + } + + // something went wrong, we're missing the file + if(!file_exists($cache)) return false; + + return $cache; + } + /** * Render the output remotely at google */ @@ -194,7 +229,39 @@ function _run($data,$in,$out) { dbglog(join("\n",$output),'graphviz command failed: '.$cmd); } return false; - } + } + + return true; + } + + /** + * Run the graphviz program to generate the map + * @Author: Michael Kling + */ + function _map($data,$in,$out) { + global $conf; + + if(!file_exists($in)){ + if($conf['debug']){ + dbglog($in,'no such graphviz input file'); + } + return false; + } + + $cmd = $this->getConf('path'); + $cmd .= ' -Tcmap'; + $cmd .= ' -K'.$data['layout']; + $cmd .= ' -o'.escapeshellarg($out); //output + $cmd .= ' '.escapeshellarg($in); //input + + $result = exec($cmd, $output, $error); + + if ($error != 0){ + if($conf['debug']){ + dbglog(join("\n",$output),'graphviz command failed: '.$cmd); + } + return false; + } return true; }