liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file data.graphviz.php

Documentation is available at data.graphviz.php

  1. <?php
  2. /**
  3.  * @version  $Revision$
  4.  * @package  liberty
  5.  * @subpackage plugins_data
  6.  */
  7. // +----------------------------------------------------------------------+
  8. // | Copyright (c) 2004, bitweaver.org
  9. // +----------------------------------------------------------------------+
  10. // | All Rights Reserved. See below for details and a complete list of authors.
  11. // | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  12. // |
  13. // | For comments, please use phpdocu.sourceforge.net documentation standards!!!
  14. // | -> see http://phpdocu.sourceforge.net/
  15. // +----------------------------------------------------------------------+
  16. // | Author: StarRider starrrider@sourceforge.net
  17. // +----------------------------------------------------------------------+
  18. // $id: data.example.php,v 1.4.2.9 2005/07/14 09:03:36 starrider Exp $
  19.  
  20. /******************
  21.  * Initialization *
  22.  ******************/
  23.  
  24. define'PLUGIN_GUID_DATAGRAPHVIZ''graphviz' );
  25. global $gLibertySystem;
  26. $pluginParams array 'tag' => 'GRAPHVIZ',
  27.     'auto_activate' => FALSE,
  28.     'requires_pair' => TRUE,
  29.     'load_function' => 'data_graphviz',
  30.     'title' => 'GraphViz',
  31.     'help_page' => 'DataPluginExample',
  32.     'description' => 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"),
  33.     'help_function' => 'data_graphviz_help',
  34.     'syntax' => "{GRAPHVIZ}digraph  ... {/GRAPHVIZ}",
  35.     'plugin_type' => DATA_PLUGIN
  36. );
  37. $gLibertySystem->registerPluginPLUGIN_GUID_DATAGRAPHVIZ$pluginParams );
  38. $gLibertySystem->registerDataTag$pluginParams['tag']PLUGIN_GUID_DATAGRAPHVIZ );
  39. /*****************
  40.  * Help Function *
  41.  *****************/
  42. function data_graphviz_help({
  43.     $help =
  44.         '<table class="data help">'
  45.             .'<tr>'
  46.                 .'<th>' tra"Key" '</th>'
  47.                 .'<th>' tra"Type" '</th>'
  48.                 .'<th>' tra"Comments" '</th>'
  49.             .'</tr>'
  50.             .'<tr class="odd">'
  51.                 .'<td>x1</td>'
  52.                 .'<td>' tra"string"'<br />' tra("(optional)"'</td>'
  53.                 .'<td>' tra"Specifies something / probably to be displayed.")
  54.                     .'<br />' tra"The Default = <strong>Sorry About That</strong>")
  55.                 .'</td>'
  56.             .'</tr>'
  57.             .'<tr class="even">'
  58.                 .'<td>XXX</td>'
  59.                 .'<td>' tra"number"'<br />' tra("(optional)"'</td>'
  60.                 .'<td>' tra"Specifies something / probably to be displayed.")
  61.                     .'<br />' tra"The Default ="' <strong>3</strong> ' tra"Which means - What")
  62.                 .'</td>'
  63.             .'</tr>'
  64.          .'</table>'
  65.         . tra("Example: ""{EXAM x1=' ' x2=5 }<br />"
  66.         . tra("This will display");
  67.     return $help;
  68. }
  69. /****************
  70. * Load Function *
  71.  ****************/
  72. function data_graphviz($data$params{
  73.     $data trim($data);
  74.     $data html_entity_decode$data );
  75.     $storageurl STORAGE_PKG_URL.'GraphViz/';
  76.     $storagepath STORAGE_PKG_PATH.'GraphViz/';
  77.     $temppath TEMP_PKG_PATH.'GraphViz/';
  78.             
  79.     if!is_dir$temppath ) ) {
  80.         mkdir_p$temppath );
  81.     }
  82.     if!is_dir$storagepath ) ) {
  83.         mkdir_p$storagepath );
  84.     }
  85.     
  86.     $file md5$data );
  87.     $dotFile $temppath $file '.dot';
  88.     $pngFile $storagepath $file '.png';
  89.     $pngURL $storageurl $file '.png';
  90.     
  91.     if!file_exists$pngFile ) ) {
  92.         if@include_once('PEAR.php') ) {
  93.             if(@include_once'Image/GraphViz.php' ) ) {
  94.                 $graph new Image_GraphViz;
  95.                 $error '<div class=error>'.tra("Unable to write temporary file. Please check your server configuration.").'</div>';    
  96.                 if (!$fp fopen($dotFile'w')) {
  97.                     return $error;
  98.                 }
  99.                 if (fwrite($fp$data)===false{
  100.                     return $error;
  101.                 }
  102.                 fclose($fp);
  103.                 $graph->renderDotFile$dotFile$pngFile'png' );
  104.                 // No need to keep this lying around
  105.                 unlink($dotFile);
  106.                 
  107.                 // If it still isn't there....
  108.                 if (!file_exists($pngFile)) {
  109.                     return '<div class=error>'.tra("Unable to generate graphviz image file. Please check your data.").'</div>';
  110.                 }
  111.             }
  112.             else {
  113.                 return "<div class=error>".tra("The Image_Graphviz pear plugin is not installed. Install with `pear install Image_Graphviz`.")."</div>";
  114.             }
  115.         }
  116.         else {           
  117.             return "<div class=error>".tra("PEAR and the Image_Graphviz pear plugin are not installed.")."</div>";
  118.         }
  119.     }
  120.     return "<img src=\"$pngURL\"/> ";
  121.  
  122. }
  123. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:19 +0000 by phpDocumentor 1.5.0-lsces