function data_graphviz($data, $params) { $data = trim($data); $data = html_entity_decode($data); $storageurl = STORAGE_PKG_URL . 'GraphViz/'; $storagepath = STORAGE_PKG_PATH . 'GraphViz/'; $temppath = TEMP_PKG_PATH . 'GraphViz/'; if (!is_dir($temppath)) { mkdir_p($temppath); } if (!is_dir($storagepath)) { mkdir_p($storagepath); } $file = md5($data); $dotFile = $temppath . $file . '.dot'; $pngFile = $storagepath . $file . '.png'; $pngURL = $storageurl . $file . '.png'; if (!file_exists($pngFile)) { if (@(include_once 'PEAR.php')) { if (@(include_once 'Image/GraphViz.php')) { $graph = new Image_GraphViz(); $error = '<div class=error>' . tra("Unable to write temporary file. Please check your server configuration.") . '</div>'; if (!($fp = fopen($dotFile, 'w'))) { return $error; } if (fwrite($fp, $data) === false) { return $error; } fclose($fp); $graph->renderDotFile($dotFile, $pngFile, 'png'); // No need to keep this lying around unlink($dotFile); // If it still isn't there.... if (!file_exists($pngFile)) { return '<div class=error>' . tra("Unable to generate graphviz image file. Please check your data.") . '</div>'; } } else { return "<div class=error>" . tra("The Image_Graphviz pear plugin is not installed. Install with `pear install Image_Graphviz`.") . "</div>"; } } else { return "<div class=error>" . tra("PEAR and the Image_Graphviz pear plugin are not installed.") . "</div>"; } } return "<img src=\"{$pngURL}\"/> "; }