User talk:Hummel-riegel

GraphViz-Version by Bytesmiths
Hi, you left a note on my talk page about the GraphVis extension.
 * Date: 2011-01-18

Here is the version I modified and use. Hope this is helpful to you!

execPath = '/sw/bin/';

$wgExtensionFunctions[] = 'wfGraphVizExtension';

function wfGraphVizExtension { global $wgParser; $wgParser->setHook('graphviz', 'renderGraphviz'); $wgParser->setHook('graphvizl', 'renderGraphvizLeft'); $wgParser->setHook('graphvizr', 'renderGraphvizRight'); }

function renderGraphvizLeft($dotsrc) { return renderGraphviz($dotsrc, 'style="float:left"'); }

function renderGraphvizRight($dotsrc) { return renderGraphviz($dotsrc, 'style="float:right"'); }

function renderGraphviz($dotsrc, $style='') {	$cmd = ''; global $wgUploadDirectory, $wgUploadPath, $IP, $wgGraphVizSettings, $wgArticlePath, $wgTmpDirectory; $hash = md5($dotsrc); $dest = $wgUploadDirectory. '/graphviz/'; if(!is_dir($dest)) mkdir($dest, 0777); if(!is_dir($wgTmpDirectory)) mkdir($wgTmpDirectory, 0777);

if(!strncmp($dotsrc, '#!/', 3)) $cmd = substr($dotsrc, 2, strpos($dotsrc, ' ') -2);   switch($cmd) { case $wgGraphVizSettings->execPath. 'circo': case $wgGraphVizSettings->execPath. 'dot': case $wgGraphVizSettings->execPath. 'fdp': case $wgGraphVizSettings->execPath. 'neato': case $wgGraphVizSettings->execPath. 'twopi': break; default: $cmd = $wgGraphVizSettings->execPath. 'dot'; }	$fname = $dest. $hash; if(!(file_exists($fname . '.png') || file_exists($fname . '.err'))) {		$handle = fopen($fname, 'w'); fwrite($handle, $dotsrc); fclose($handle);

$cmdline = wfEscapeShellArg($cmd) . ' -Tpng -o ' . wfEscapeShellArg($fname . '.png') . ' '		     . wfEscapeShellArg($fname); $cmdlinemap = wfEscapeShellArg($cmd) . ' -Tcmapx -o ' . wfEscapeShellArg($fname. '.map') . ' '		     . wfEscapeShellArg($fname); $ret = shell_exec($cmdline); $ret = `{$cmdlinemap}`;

unlink($fname); }	@$err=file_get_contents($fname . '.err');

if($err != '') { $txt = "$err "; } else { @$map = file_get_contents($fname . '.map'); $map = preg_replace('##', ' ', $map);

if(substr(php_uname, 0, 7) == 'Windows') { $ext = 'gif'; } else { $ext = 'png'; }		$txt = "{$map}" . ""; }	return $txt; } ?>