see http://phpdocu.sourceforge.net/ // +----------------------------------------------------------------------+ // | Author: StarRider starrrider@sourceforge.net // +----------------------------------------------------------------------+ // $id: data.example.php,v 1.4.2.9 2005/07/14 09:03:36 starrider Exp $ /****************** * Initialization * ******************/ define( 'PLUGIN_GUID_DATAGRAPHVIZ', 'graphviz' ); global $gLibertySystem; $pluginParams = [ 'tag' => 'GRAPHVIZ', 'auto_activate' => false, 'requires_pair' => true, 'load_function' => '\data_graphviz', 'title' => 'GraphViz', 'help_page' => 'DataPluginExample', 'description' => KernelTools::tra("This plugin renders it's content as a graphviz image (dot or neato). It requies the Image_GraphViz pear plugin and graphviz to be installed: pear install Image_GraphViz"), 'help_function' => '\data_graphviz_help', 'syntax' => "{GRAPHVIZ}digraph ... {/GRAPHVIZ}", 'plugin_type' => DATA_PLUGIN, ]; $gLibertySystem->registerPlugin( PLUGIN_GUID_DATAGRAPHVIZ, $pluginParams ); $gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAGRAPHVIZ ); /***************** * Help Function * *****************/ function data_graphviz_help() { $help = '' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'
' . KernelTools::tra( "Key" ) . '' . KernelTools::tra( "Type" ) . '' . KernelTools::tra( "Comments" ) . '
x1' . KernelTools::tra( "string") . '
' . KernelTools::tra("(optional)") . '
' . KernelTools::tra( "Specifies something / probably to be displayed.") .'
' . KernelTools::tra( "The Default = Sorry About That") .'
XXX' . KernelTools::tra( "number") . '
' . KernelTools::tra("(optional)") . '
' . KernelTools::tra( "Specifies something / probably to be displayed.") .'
' . KernelTools::tra( "The Default =") . ' 3 ' . KernelTools::tra( "Which means - What") .'
' . KernelTools::tra("Example: ") . "{EXAM x1=' ' x2=5 }
" . KernelTools::tra("This will display"); return $help; } /**************** * Load Function * ****************/ 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 ) ) { KernelTools::mkdir_p( $temppath ); } if( !is_dir( $storagepath ) ) { KernelTools::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 UTIL_PKG_INCLUDE_PATH.'pear/Image/GraphViz.php' ) { $graph = new \Image_GraphViz; $error = '
'.KernelTools::tra("Unable to write temporary file. Please check your server configuration.").'
'; 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 '
'.KernelTools::tra("Unable to generate graphviz image file. Please check your data.").'
'; } } else { return "
".KernelTools::tra("The Image_Graphviz pear plugin is not installed. Install with `pear install Image_Graphviz`.")."
"; } } else { return "
".KernelTools::tra("PEAR and the Image_Graphviz pear plugin are not installed.")."
"; } } return " "; }