Skip to content
Open
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
69 changes: 68 additions & 1 deletion syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, Doku_Renderer $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 name="'.$data['md5'].'" id="'.$data['md5'].'">'.$map.'</map>';
}
$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') $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'){
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}

Expand Down