'; } function page_footer() { global $baseurl; global $vers; echo "

UrlGreyHot | GraphViz Sitemap Generator

"; } ################################################################################ # do stuff ################################################################################ page_header(); global $baseurl; global $filedir; // execute modules if ($q) { $a1 = sanitize($a1,SYSTEM); $a2 = sanitize($a2,SYSTEM); $a3 = sanitize($a3,SYSTEM); $mod = sanitize($q,SYSTEM); module_invoke($mod, $a1, $a2, $a3); } else { // show the submit form if(!$submit=="Submit"){ print <<< END

GraphViz Site Map Generator

About this application
This web application accepts uploaded tab delimmited text files and converts them into clickable site maps using the GraphViz application. The application was created to demonstrate how GraphViz can be used as a tool for Information Architecture work.

Getting started
To get started you will have to prepare your upload file.

If you're interested in seeing the output of this application, take a look at the demo diagrams.

NOTE: Because of the memory limitation on this shared server, presently this demonstration can only render GIFs for files containing about 438 lines, although SVGs should be generated above that limit. Remember that this is a demonstration and that your mileage will vary. Better results can be expected on your system.

Download

Feel free to send me feedback.

Please note. The output from the site map generator is now being expunged regularly, so you MUST SAVE YOUR WORK, including all GIFs, SVGs and .map files. Lost work is not recoverable once it has been expunged. -Michael Angeles

1. Upload your file (required)
This should be one word with no spaces. Underscores and hyphens are ok. Used to identify your diagram.



This is your file describing nodes in the tree. How to prepare your upload file.


2. Set graph attributes (optional)
This URL is used for mis-clicks in the image map.



Hierarchical Radial


Box Circle


3. Click and start the automagic
END; } // error checking elseif ( ($submit=="Submit") && (($fname=='') || ($fupload=='')) ){ echo '

GraphViz sitemap generator / Error

The following errors were detected:

'; if ($fname=='') { echo '

You need to enter a name for your diagram.

'; } if ($fupload=='') { echo '

You need to select a tab delimmited file to submit.

'; } echo '

« Go back and try again.

'; } else { // process submitted form // while we have uploaded file foreach( $HTTP_POST_FILES as $file_name => $file_array ) { // process file if ( (is_uploaded_file( $file_array['tmp_name'] )) // && (!eregi("application", $file_array['type'])) // && (!eregi("image", $file_array['type'])) && (!eregi(" ", $fname)) ) { // move uploaded file to new location move_uploaded_file( $file_array['tmp_name'], "$filedir/$file_name") or die ("Couldn't copy"); chmod ("$filedir/$file_name", 0775); copy ("$filedir/$file_name", "$filedir/$fname"); chmod ("$filedir/$fname", 0775); // now create the dot file dot_create_dot_file($fname, $defaulturl, $shape, $edge); // create image and image map dot_create_images($fname, $layout); // create image and image map modify_svg($fname); // link to image view($fname); } else { error("Sorry. Your diagram cannot be processed. Likely cause may be that you have a space in your project name or your file is not in ASCII (plain text) format"); } // end process file } // end while we have uploaded file } // submit form } page_footer(); ################################################################################ # modules ################################################################################ // invoke module $name with optional arguments: function module_invoke($name, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL, $a5 = NULL, $a6 = NULL) { $function = $name; if (function_exists($function)) { return $function($a1, $a2, $a3, $a4, $a5, $a6); } else { error("Sorry. You got here by mistake."); } } // create dot files in ./input/ function dot_create_dot_file($a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL, $a5 = NULL, $a6 = NULL) { global $base; global $fontbase; // get arguments, assign var values $infilename = "$base/input/$a1"; $outfilename = "$base/input/$a1.dot"; // get arguments, set defaults $defaulturl = $a2; $shape = ($a3 == "box") ? "box" : "circle"; $edge = $a4; // read uploaded file $fhin = fopen($infilename, "r"); $file_contents = @fread($fhin, filesize($infilename)); $line = explode("\n", $file_contents); fclose($fhin); // convert lines to dot format $i = 0; $size = sizeof($line) - 1; while($i <= $size) { # split lines and assign values to fields $dat = explode("\t", $line[$i]); $datid = rtrim($dat[0]); $datparent = rtrim($dat[1]); ($dat[2] == '') ? $datlabel = addslashes(rtrim($dat[3])) : $datlabel = addslashes(rtrim($dat[2])); $datlabel = eregi_replace ("", "\\n ", $datlabel); $daturl = addslashes(rtrim($dat[3])); $datcolor = rtrim($dat[4]); $datfontcolor = rtrim($dat[5]); $datstyle = rtrim($dat[6]); # output the nav links if ($datid != ''){ $dotlines .= " $datid [label=\"$datlabel\", URL=\"$daturl\", fillcolor=\"$datcolor\", fontcolor=\"$datfontcolor\", style=\"$datstyle\", fontsize=\"10\", fontname=\"Verdana Bold\"];\n"; } if ($datid != $datparent){ $dotlines .= " $datparent -> $datid;\n"; } $i++; } // prepare dot options $dotfile = "digraph G {\n"; $dotfile .= " URL=\"$defaulturl\";\n"; $dotfile .= " fontpath=\"$fontbase\";\n"; $dotfile .= " overlap=\"false\";\n"; $dotfile .= " node [shape=\"$shape\",color=\"#cccccc\",fontname=\"Verdana Bold\", fontsize=\"10\",fontcolor=\"#000000\"];\n"; $dotfile .= " edge [color=\"#cccccc\",arrowhead=\"none\"];\n"; $dotfile .= $dotlines; $dotfile .= "}"; // write everything to the dot input file $fhout = fopen($outfilename, 'w'); fwrite($fhout, $dotfile); fclose($fhout); chmod ($infilename, 0775); chmod ($outfilename, 0775); } // create the dot files in ./output/ function dot_create_images($a1 = NULL, $a2 = NULL) { global $base; global $dotbase; ($a2 == 'hierarchical') ? $layout = 'dot' : $layout = 'twopi'; // create gif and image map passthru("touch $base/output/$a1.gif"); passthru("touch $base/output/$a1.map"); passthru("cp $base/output/$a1.map $base/output/$a1.txt"); passthru("$dotbase/$layout -o $base/output/$a1.gif -Tgif $base/input/$a1.dot"); passthru("$dotbase/$layout -o $base/output/$a1.map -Timap $base/input/$a1.dot"); // passthru("$dotbase/$layout -Tcmap $base/input/$a1.dot > $base/output/$a1.cmap"); // create svg passthru("$dotbase/$layout -o $base/output/$a1.svg -Tsvg $base/input/$a1.dot"); /* open file, remove comment and rewrite file */ //change permissions on files chmod ("$base/output/$a1.gif", 0775); chmod ("$base/output/$a1.svg", 0775); chmod ("$base/output/$a1.map", 0775); } function view($a1) { global $baseurl; echo "

GraphViz sitemap generator / $a1



Please note. All files generated by this application are removed DAILY at midnight, Eastern Time. You must save your work locally. No files will be archived.

GIF: $baseurl/output/$a1.gif
SVG: $baseurl/output/$a1.svg
Image Map: $baseurl/output/$a1.map
"; } function viewsitemap($a1) { global $baseurl; echo "

"; } // modify svg files in ./output/ function modify_svg($a1 = NULL) { global $base; // get arguments, assign var values $infilename = "$base/output/$a1.svg"; $outfilename = $infilename; // read uploaded file $fhin = fopen($infilename, "r"); $file_contents = @fread($fhin, filesize($infilename)); $outfile = preg_replace('//', '', $file_contents); fclose($fhin); // write everything to the dot input file $fhout = fopen($outfilename, 'w'); fwrite($fhout, $outfile); fclose($fhout); } // version info function vers(){ global $baseurl; echo "

GraphViz sitemap generator / Version info

0.1
First version released with minimal configuration options.

0.1.1
Fixed bug caused by single and double quotes in upload files.

0.2
Added layout, shape and style attributes.

0.3
Fixed bug that was producing unusable SVG output. SVG files should now work, but font size is rather large.

0.4
Added minor feature to break up labels by using a newline marker in tab delimmited file.

0.5
Added error recovery messages.

0.5.1
Added direct links to view a) image map, b) gif and c) sitemap without navigation links. Set SVG files with smaller fonts to make more readable. Released under GPL.

0.5.2
Added some installation documentation and import_request_variables('GPC'); per Gilbert Grosdidier's suggestion.

0.5.3
Fixed bug when using tab character instead of \t in replacement string.

"; } // error messages function error($msg) { echo "

Error

$msg

"; } ################################################################################ ?>