2 rcs_id('$Id: VisualWiki.php,v 1.15 2004-09-08 13:38:00 rurban Exp $');
4 Copyright (C) 2002 Johannes Große (Johannes Große)
6 This file is (not yet) part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Produces graphical site map of PhpWiki
25 * Example for an image map creating plugin. It produces a graphical
26 * sitemap of PhpWiki by calling the <code>dot</code> commandline tool
27 * from graphviz (http://www.graphviz.org).
28 * @author Johannes Große
31 define('VISUALWIKI_ALLOWOPTIONS', true);
33 if (PHP_OS == "Darwin") { // Mac OS X
34 $dotbin = '/sw/bin/dot'; // graphviz via Fink
35 //$dotbin = '/usr/local/bin/dot';
37 // Name of the Truetypefont - at least LucidaSansRegular.ttf is always present on OS X
38 define('VISUALWIKIFONT', 'LucidaSansRegular');
40 // The default font paths do not find your fonts, set the path here:
41 $fontpath = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/";
42 //$fontpath = "/usr/X11R6/lib/X11/fonts/TTF/";
44 elseif (isWindows()) {
46 define('VISUALWIKIFONT', 'Arial');
48 $dotbin = '/usr/local/bin/dot';
50 if ($_SERVER["SERVER_NAME"] == 'phpwiki.sourceforge.net') {
51 $dotbin = '/home/groups/p/ph/phpwiki/bin/dot';
52 define('VISUALWIKIFONT', 'luximr');
54 // Name of the Truetypefont - Helvetica is probably easier to read
55 define('VISUALWIKIFONT', 'Helvetica');
56 //define('VISUALWIKIFONT', 'Times');
57 //define('VISUALWIKIFONT', 'Arial');
59 // The default font paths do not find your fonts, set the path here:
60 //$fontpath = "/usr/X11R6/lib/X11/fonts/TTF/";
61 //$fontpath = "/usr/share/fonts/default/TrueType/";
64 if (!defined('VISUALWIKI_ALLOWOPTIONS'))
65 define('VISUALWIKI_ALLOWOPTIONS', false);
67 require_once "lib/WikiPluginCached.php";
69 class WikiPlugin_VisualWiki
70 extends WikiPluginCached
73 * Sets plugin type to map production
75 function getPluginType() {
76 return ($GLOBALS['request']->getArg('debug')) ? PLUGIN_CACHED_IMG_ONDEMAND : PLUGIN_CACHED_MAP;
80 * Sets the plugin's name to VisualWiki. It can be called by
81 * <code><?plugin VisualWiki?></code>, now. This
82 * name must correspond to the filename and the class name.
88 function getVersion() {
89 return preg_replace("/[Revision: $]/", '',
90 "\$Revision: 1.15 $");
94 * Sets textual description.
96 function getDescription() {
97 return _("Visualizes the Wiki structure in a graph using the 'dot' commandline tool from graphviz.");
101 * Returns default arguments. This is put into a separate
102 * function to allow its usage by both <code>getDefaultArguments</code>
103 * and <code>checkArguments</code>
105 function defaultarguments() {
106 return array('imgtype' => 'png',
107 'width' => false, // was 5, scale it automatically
108 'height' => false, // was 7, scale it automatically
109 'colorby' => 'age', // sort by 'age' or 'revtime'
110 'fillnodes' => 'off',
112 'shape' => 'ellipse',
117 'neighbour_list' => '',
118 'exclude_list' => '',
119 'include_list' => '',
126 * Sets the default arguments. WikiPlugin also regards these as
127 * the allowed arguments. Since WikiPluginCached stores an image
128 * for each different set of parameters, there can be a lot of
129 * these (large) graphs if you allow different parameters.
130 * Set <code>VISUALWIKI_ALLOWOPTIONS</code> to <code>false</code>
131 * to allow no options to be set and use only the default paramters.
132 * This will need an disk space of about 20 Kbyte all the time.
134 function getDefaultArguments() {
135 if (VISUALWIKI_ALLOWOPTIONS)
136 return $this->defaultarguments();
142 * Substitutes each forbidden parameter value by the default value
143 * defined in <code>defaultarguments</code>.
145 function checkArguments(&$arg) {
147 $def = $this->defaultarguments();
149 if (($width < 3) || ($width > 15))
150 $arg['width'] = $def['width'];
152 if (($height < 3) || ($height > 20))
153 $arg['height'] = $def['height'];
155 if (($fontsize < 8) || ($fontsize > 24))
156 $arg['fontsize'] = $def['fontsize'];
158 if (!in_array($label, array('name', 'number')))
159 $arg['label'] = $def['label'];
161 if (!in_array($shape, array('ellipse', 'box', 'point', 'circle',
163 $arg['shape'] = $def['shape'];
165 if (!in_array($colorby, array('age', 'revtime')))
166 $arg['colorby'] = $def['colorby'];
168 if (!in_array($fillnodes, array('on', 'off')))
169 $arg['fillnodes'] = $def['fillnodes'];
171 if (($large_nb < 0) || ($large_nb > 50))
172 $arg['large_nb'] = $def['large_nb'];
174 if (($recent_nb < 0) || ($recent_nb > 50))
175 $arg['recent_nb'] = $def['recent_nb'];
177 if (($refined_nb < 0 ) || ( $refined_nb > 50))
178 $arg['refined_nb'] = $def['refined_nb'];
180 if (($backlink_nb < 0) || ($backlink_nb > 50))
181 $arg['backlink_nb'] = $def['backlink_nb'];
183 // ToDo: check if "ImageCreateFrom$imgtype"() exists.
184 if (!in_array($imgtype, $GLOBALS['PLUGIN_CACHED_IMGTYPES']))
185 $arg['imgtype'] = $def['imgtype'];
186 if (empty($fontname))
187 $arg['fontname'] = VISUALWIKIFONT;
191 * Checks options, creates help page if necessary, calls both
192 * database access and image map production functions.
193 * @return array($map,$html)
195 function getMap($dbi, $argarray, $request) {
196 if (!VISUALWIKI_ALLOWOPTIONS)
197 $argarray = $this->defaultarguments();
198 $this->checkArguments($argarray);
199 $request->setArg('debug',$argarray['debug']);
200 //extract($argarray);
201 if ($argarray['help'])
202 return array($this->helpImage(), ' '); // FIXME
203 $this->createColors();
204 $this->extract_wikipages($dbi, $argarray);
205 /* ($dbi, $large, $recent, $refined, $backlink,
206 $neighbour, $excludelist, $includelist, $color); */
207 return $this->invokeDot($argarray);
208 /* ($width, $height, $color, $shape, $text); */
212 * Sets the expire time to one day (so the image producing
213 * functions are called seldomly) or to about two minutes
214 * if a help screen is created.
216 function getExpire($dbi, $argarray, $request) {
217 if ($argarray['help'])
218 return '+120'; // 2 minutes
219 return sprintf('+%d', 3*86000); // approx 3 days
223 * Sets the imagetype according to user wishes and
224 * relies on WikiPluginCached to catch illegal image
226 * (I feel unsure whether this option is reasonable in
227 * this case, because png will definitely have the
230 * @return string 'png', 'gif', 'jpeg'
232 function getImageType($dbi, $argarray, $request) {
233 return $argarray['imgtype'];
237 * This gives an alternative text description of
238 * the image map. I do not know whether it interferes
239 * with the <code>title</code> attributes in <area>
240 * tags of the image map. Perhaps this will be removed.
243 function getAlt($dbi, $argstr, $request) {
244 return $this->getDescription();
247 // ------------------------------------------------------------------------------------------
250 * Returns an image containing a usage description of the plugin.
251 * @return string image handle
253 function helpImage() {
254 $def = $this->defaultarguments();
255 $other_imgtypes = $GLOBALS['PLUGIN_CACHED_IMGTYPES'];
256 unset ($other_imgtypes[$def['imgtype']]);
258 '<?plugin '.$this->getName() .
259 ' img' => ' = "' . $def['imgtype'] . "(default)|" . join('|',$GLOBALS['PLUGIN_CACHED_IMGTYPES']).'"',
260 'width' => ' = "width in inches"',
261 'height' => ' = "height in inches"',
262 'fontname' => ' = "font family"',
263 'fontsize' => ' = "fontsize in points"',
264 'colorby' => ' = "age|revtime|none"',
265 'fillnodes' => ' = "on|off"',
266 'shape' => ' = "ellipse(default)|box|circle|point"',
267 'label' => ' = "name|number"',
268 'large_nb' => ' = "number of largest pages to be selected"',
269 'recent_nb' => ' = "number of youngest pages"',
270 'refined_nb' => ' = "#pages with smallest time between revisions"',
271 'backlink_nb' => ' = "number of pages with most backlinks"',
272 'neighbour_list' => ' = "find pages linked from and to these pages"',
273 'exclude_list' => ' = "colon separated list of pages to be excluded"',
274 'include_list' => ' = "colon separated list" ?>'
277 foreach($helparr as $alignright => $alignleft) {
278 $length = max($length, strlen($alignright));
281 foreach($helparr as $alignright => $alignleft) {
282 $helptext .= substr(' '
283 . $alignright, -$length).$alignleft."\n";
285 return $this->text2img($helptext, 4, array(1, 0, 0),
286 array(255, 255, 255));
291 * Selects the first (smallest or biggest) WikiPages in
294 * @param number integer number of page names to be found
295 * @param category string attribute of the pages which is used
297 * @param minimum boolean true finds smallest, false finds biggest
298 * @return array list of page names found to be the best
300 function findbest($number, $category, $minimum ) {
301 // select the $number best in the category '$category'
302 $pages = &$this->pages;
303 $names = &$this->names;
307 foreach($names as $name) {
310 $selected[$name] = $pages[$name][$category];
312 //echo "<pre>$category "; var_dump($selected); "</pre>";
313 $compareto = $minimum ? 0x79999999 : -0x79999999;
316 foreach ($names as $name) {
320 if (($crit = $pages[$name][$category]) < $compareto) {
321 $selected[$name] = $crit;
322 asort($selected, SORT_NUMERIC);
323 array_pop($selected);
324 $compareto = end($selected);
326 } elseif (($crit = $pages[$name][$category]) > $compareto) {
327 $selected[$name] = $crit;
328 arsort($selected, SORT_NUMERIC);
329 array_pop($selected);
330 $compareto = end($selected);
333 //echo "<pre>$category "; var_dump($selected); "</pre>";
335 return array_keys($selected);
340 * Extracts a subset of all pages from the wiki and find their
341 * connections to other pages. Also collects some page features
342 * like size, age, revision number which are used to find the
343 * most attractive pages.
345 * @param dbi WikiDB database handle to access all Wiki pages
346 * @param LARGE integer number of largest pages which should
348 * @param RECENT integer number of the youngest pages to be included
349 * @param REFINED integer number of the pages with shortes revision
351 * @param BACKLINK integer number of the pages with most backlinks
352 * @param EXCLUDELIST string colon ':' separated list of page names which
353 * should not be displayed (like PhpWiki, for
355 * @param INCLUDELIST string colon separated list of pages which are
356 * allways included (for example your own
358 * @param COLOR string 'age', 'revtime' or 'none'; Selects which
359 * page feature is used to determine the
360 * filling color of the nodes in the graph.
363 function extract_wikipages($dbi, $argarray) {
364 // $LARGE, $RECENT, $REFINED, $BACKLINK, $NEIGHBOUR,
365 // $EXCLUDELIST, $INCLUDELIST,$COLOR
369 // FIXME: gettextify?
370 $exclude_list = explode(':', $exclude_list);
371 $include_list = explode(':', $include_list);
372 $neighbour_list = explode(':', $neighbour_list);
374 // FIXME remove INCLUDED from EXCLUDED
377 $allpages = $dbi->getAllPages();
378 $pages = &$this->pages;
380 while ($page = $allpages->next()) {
381 $name = $page->getName();
383 // skip exluded pages
384 if (in_array($name, $exclude_list)) {
389 // false = get links from actual page
390 // true = get links to actual page ("backlinks")
391 $backlinks = $page->getLinks(true);
393 $bconnection = array();
394 while ($blink = $backlinks->next()) {
395 array_push($bconnection, $blink->getName());
400 // include all neighbours of pages listed in $NEIGHBOUR
401 if (in_array($name,$neighbour_list)) {
402 $l = $page->getLinks(false);
404 while ($link = $l->next()) {
405 array_push($con, $link->getName());
407 $include_list = array_merge($include_list, $bconnection, $con);
414 $currev = $page->getCurrentRevision();
416 $pages[$name] = array(
417 'age' => $now-$currev->get('mtime'),
418 'revnr' => $currev->getVersion(),
420 'backlink_nb' => count($bconnection),
421 'backlinks' => $bconnection,
422 'size' => 1000 // FIXME
424 $pages[$name]['revtime'] = $pages[$name]['age'] / ($pages[$name]['revnr']);
430 $this->names = array_keys($pages);
432 $countpages = count($pages);
434 // now select each page matching to given parameters
435 $all_selected = array_unique(array_merge(
436 $this->findbest($recent_nb, 'age', true),
437 $this->findbest($refined_nb, 'revtime', true),
438 $x = $this->findbest($backlink_nb, 'backlink_nb', false),
439 // $this->findbest($large_nb, 'size', false),
442 foreach($all_selected as $name)
443 if (isset($pages[$name]))
444 $newpages[$name] = $pages[$name];
447 $this->pages = $newpages;
448 $pages = &$this->pages;
449 $this->names = array_keys($pages);
451 unset($all_selected);
453 $countpages = count($pages);
455 // remove dead links and collect links
457 while( list($name,$page) = each($pages) ) {
458 if (is_array($page['backlinks'])) {
459 reset($page['backlinks']);
460 while ( list($index, $link) = each( $page['backlinks'] ) ) {
461 if ( !isset($pages[$link]) || $link == $name ) {
462 unset($pages[$name]['backlinks'][$index]);
464 array_push($pages[$link]['links'],$name);
465 //array_push($this->everylink, array($link,$name));
471 if ($colorby == 'none')
473 list($oldestname) = $this->findbest(1, $colorby, false);
474 $this->oldest = $pages[$oldestname][$colorby];
475 foreach($this->names as $name)
476 $pages[$name]['color'] = $this->getColor($pages[$name][$colorby] / $this->oldest);
477 } // extract_wikipages
480 * Creates the text file description of the graph needed to invoke
483 * @param filename string name of the dot file to be created
484 * @param width float width of the output graph in inches
485 * @param height float height of the graph in inches
486 * @param colorby string color sceme beeing used ('age', 'revtime',
488 * @param shape string node shape; 'ellipse', 'box', 'circle', 'point'
489 * @param label string 'name': label by name,
490 * 'number': label by unique number
491 * @return boolean error status; true=ok; false=error
493 function createDotFile($filename, $argarray) {
495 if (!$fp = fopen($filename, 'w'))
498 $fillstring = ($fillnodes == 'on') ? 'style=filled,' : '';
501 $names = &$this->names;
502 $pages = &$this->pages;
504 $nametonumber = array_flip($names);
506 $dot = "digraph VisualWiki {\n" // }
507 . (!empty($fontpath) ? " fontpath=\"$fontpath\"\n" : "");
508 if ($width and $height)
509 $dot .= " size=\"$width,$height\";\n ";
514 $dot .= "edge [arrowhead=none];\nnode [shape=$shape,fontname=$fontname,width=0.15,height=0.15,fontsize=$fontsize];\n";
517 $dot .= "node [shape=$shape,fontname=$fontname,width=0.4,height=0.4,fontsize=$fontsize];\n";
520 $dot .= "node [shape=$shape,fontname=$fontname,width=0.25,height=0.25,fontsize=$fontsize];\n";
523 $dot .= "node [fontname=$fontname,shape=$shape,fontsize=$fontsize];\n" ;
527 foreach ($names as $name) {
529 $url = rawurlencode($name);
530 // patch to allow Page/SubPage
531 $url = preg_replace('/' . urlencode(SUBPAGE_SEPARATOR) . '/',
532 SUBPAGE_SEPARATOR, $url);
533 $nodename = ($label != 'name' ? $nametonumber[$name] + 1 : $name);
535 $dot .= " \"$nodename\" [URL=\"$url\"";
536 if ($colorby != 'none') {
537 $col = $pages[$name]['color'];
538 $dot .= sprintf(',%scolor="#%02X%02X%02X"', $fillstring,
539 $col[0], $col[1], $col[2]);
543 if (!empty($pages[$name]['links'])) {
545 if ($label != 'name')
546 foreach($pages[$name]['links'] as $linkname)
547 $linkarray[] = $nametonumber[$linkname] + 1;
549 $linkarray = $pages[$name]['links'];
550 $linkstring = join('"; "', $linkarray );
552 $c = count($pages[$name]['links']);
553 $dot .= " \"$nodename\" -> "
560 if ($colorby != 'none') {
561 $dot .= "\n subgraph cluster_legend {\n"
562 . " node[fontname=$fontname,shape=box,width=0.4,height=0.4,fontsize=$fontsize];\n"
563 . " fillcolor=lightgrey;\n"
565 . " fontname=$fontname;\n"
566 . " fontsize=$fontsize;\n"
567 . " label=\"".gettext("Legend")."\";\n";
568 $oldest= ceil($this->oldest / (24 * 3600));
571 for($i = 0; $i < $max; $i++) {
572 $time = floor($i / $max * $oldest);
573 $name = '"' . $time .' '. _("days") .'"';
574 $col = $this->getColor($i/$max);
575 $dot .= sprintf(' %s [%scolor="#%02X%02X%02X"];',
576 $name, $fillstring, $col[0], $col[1], $col[2])
580 $dot .= ' '. join(' -> ', $legend)
588 $ok = fwrite($fp, $dot);
589 $ok = fclose($fp) && $ok; // close anyway
595 * Execute system command.
597 * @param cmd string command to be invoked
598 * @return boolean error status; true=ok; false=error
600 function execute($cmd, $until = false) {
601 $errstr = exec($cmd); //, $outarr, $returnval); // normally 127
602 // $errstr = join('',$outarr);
603 $ok = empty($errstr);
605 trigger_error("\n".$cmd." failed: $errstr", E_USER_WARNING);
606 } elseif ($GLOBALS['request']->getArg('debug'))
607 trigger_error("\n".$cmd.": success\n", E_USER_NOTICE);
611 while (!file_exists($until) and $loop > 0) {
620 return file_exists($until);
625 * Produces a dot file, calls dot twice to obtain an image and a
626 * text description of active areas for hyperlinking and returns
627 * an image and an html map.
629 * @param width float width of the output graph in inches
630 * @param height float height of the graph in inches
631 * @param colorby string color sceme beeing used ('age', 'revtime',
633 * @param shape string node shape; 'ellipse', 'box', 'circle', 'point'
634 * @param label string not used anymore
636 function invokeDot($argarray) {
638 //$cacheparams = $GLOBALS['CacheParams'];
639 $tempfiles = $this->tempnam('VisualWiki');
640 $gif = $argarray['imgtype'];
641 $ImageCreateFromFunc = "ImageCreateFrom$gif";
642 $outfile = $tempfiles.".".$gif;
643 $debug = $GLOBALS['request']->getArg('debug');
645 $tempdir = dirname($tempfiles);
646 $tempout = $tempdir . "/.debug";
649 && $this->createDotFile($tempfiles.'.dot',$argarray)
650 // && $this->filterThroughCmd('',"$dotbin -T$gif $tempfiles.dot -o $outfile")
651 // && $this->filterThroughCmd('',"$dotbin -Timap $tempfiles.dot -o ".$tempfiles.".map")
652 && $this->execute("$dotbin -T$gif $tempfiles.dot -o $outfile" . ($debug ? " > $tempout 2>&1" : ""), $outfile)
653 && $this->execute("$dotbin -Timap $tempfiles.dot -o ".$tempfiles.".map" . ($debug ? " > $tempout 2>&1" : ""), $tempfiles.".map")
654 && file_exists( $outfile )
655 && file_exists( $tempfiles.'.map' )
656 && ($img = $ImageCreateFromFunc($outfile))
657 && ($fp = fopen($tempfiles.'.map', 'r'));
660 if ($debug == 'static') {
661 // workaround for misconfigured WikiPluginCached (sf.net) or dot.
662 // present a static png and map file.
663 if (file_exists($outfile) and filesize($outfile) > 900)
666 $img = $tempdir . "/VisualWiki.".$gif;
667 if (file_exists( $tempfiles.".map") and filesize($tempfiles.".map") > 20)
668 $map = $tempfiles.".map";
670 $map = $tempdir . "/VisualWiki.map";
671 $img = $ImageCreateFromFunc($img);
672 $fp = fopen($map, 'r');
678 $line = fgets($fp, 1000);
679 if (substr($line, 0, 1) == '#')
681 list($shape, $url, $e1, $e2, $e3, $e4) = sscanf($line,
682 "%s %s %d,%d %d,%d");
683 if ($shape != 'rect')
686 // dot sometimes gives not allways the right order so
687 // so we have to sort a bit
692 $map->pushContent(HTML::area(array(
694 'coords' => "$x1,$y1,$x2,$y2",
696 'title' => rawurldecode($url),
700 //trigger_error("url=".$url);
703 $outfile: ".(file_exists($outfile) ? filesize($outfile):'missing')."
704 $tempfiles.map: ".(file_exists("$tempfiles.map") ? filesize("$tempfiles.map"):'missing'), E_USER_WARNING);
707 // clean up tempfiles
708 if ($ok and !$argarray['debug'])
709 foreach (array('',".$gif",'.map','.dot') as $ext) {
710 if (file_exists($tempfiles.$ext))
711 unlink($tempfiles.$ext);
715 return array($img, $map);
717 return array(false, false);
722 * static workaround on broken Cache or broken dot executable,
723 * called only if debug=static.
726 * @param url string url pointing to the image part of the map
727 * @param map string <area> tags defining active
729 * @param dbi WikiDB database abstraction class
730 * @param argarray array complete (!) arguments to produce
731 * image. It is not necessary to call
732 * WikiPlugin->getArgs anymore.
733 * @param request Request ???
734 * @return string html output
736 function embedImg($url,&$dbi,$argarray,&$request) {
737 if (!VISUALWIKI_ALLOWOPTIONS)
738 $argarray = $this->defaultarguments();
739 $this->checkArguments($argarray);
740 //extract($argarray);
741 if ($argarray['help'])
742 return array($this->helpImage(), ' '); // FIXME
743 $this->createColors();
744 $this->extract_wikipages($dbi, $argarray);
745 list($imagehandle, $content['html']) = $this->invokeDot($argarray);
746 // write to uploads and produce static url
747 $file_dir = defined('PHPWIKI_DIR') ?
748 PHPWIKI_DIR . "/uploads" : "uploads";
749 $upload_dir = SERVER_URL . ((substr(DATA_PATH,0,1)=='/') ? '' : "/") . DATA_PATH . '/uploads/';
750 $tmpfile = tempnam($file_dir,"VisualWiki").".".$argarray['imgtype'];
751 WikiPluginCached::writeImage($argarray['imgtype'], $imagehandle, $tmpfile);
752 ImageDestroy($imagehandle);
753 return WikiPluginCached::embedMap(1,$upload_dir.basename($tmpfile),$content['html'],$dbi,$argarray,$request);
758 * Prepares some rainbow colors for the nodes of the graph
759 * and stores them in an array which may be accessed with
760 * <code>getColor</code>.
762 function createColors() {
763 $predefcolors = array(
764 array('red' => 255, 'green' => 0, 'blue' => 0),
765 array('red' => 255, 'green' => 255, 'blue' => 0),
766 array('red' => 0, 'green' => 255, 'blue' => 0),
767 array('red' => 0, 'green' => 255, 'blue' => 255),
768 array('red' => 0, 'green' => 0, 'blue' => 255),
769 array('red' => 100, 'green' => 100, 'blue' => 100)
773 $numberofcolors = count($predefcolors) * $steps;
776 foreach($predefcolors as $color) {
782 for ($i = 0; $i < $steps; $i++)
783 $this->ColorTab[++$promille / $numberofcolors * 1000] = array(
784 floor(interpolate( $oldcolor['red'], $color['red'], $i/$steps )),
785 floor(interpolate( $oldcolor['green'], $color['green'], $i/$steps )),
786 floor(interpolate( $oldcolor['blue'], $color['blue'], $i/$steps ))
790 //echo"<pre>"; var_dump($this->ColorTab); echo "</pre>";
794 * Translates a value from 0.0 to 1.0 into rainbow color.
795 * red -> orange -> green -> blue -> gray
797 * @param promille float value between 0.0 and 1.0
798 * @return array(red,green,blue)
800 function getColor($promille) {
801 foreach( $this->ColorTab as $pro => $col ) {
802 if ($promille*1000 < $pro)
805 $lastcol = end($this->ColorTab);
808 } // WikiPlugin_VisualWiki
811 * Linear interpolates a value between two point a and b
813 * @return float interpolated value
816 function interpolate($a, $b, $pos) {
817 return $a + ($b - $a) * $pos;
820 // $Log: not supported by cvs2svn $
821 // Revision 1.14 2004/09/07 13:26:31 rurban
822 // new WikiPluginCached option debug=static and some more sf.net defaults for VisualWiki
824 // Revision 1.13 2004/09/06 12:13:00 rurban
825 // provide sf.net default dotbin
827 // Revision 1.12 2004/09/06 12:08:50 rurban
828 // memory_limit on unix workaround
829 // VisualWiki: default autosize image
831 // Revision 1.11 2004/09/06 10:10:27 rurban
832 // fixed syntax error
834 // Revision 1.10 2004/06/19 10:06:38 rurban
835 // Moved lib/plugincache-config.php to config/*.ini
836 // use PLUGIN_CACHED_* constants instead of global $CacheParams
838 // Revision 1.9 2004/06/03 09:40:57 rurban
839 // WikiPluginCache improvements
841 // Revision 1.8 2004/01/26 09:18:00 rurban
842 // * changed stored pref representation as before.
843 // the array of objects is 1) bigger and 2)
844 // less portable. If we would import packed pref
845 // objects and the object definition was changed, PHP would fail.
846 // This doesn't happen with an simple array of non-default values.
847 // * use $prefs->retrieve and $prefs->store methods, where retrieve
848 // understands the interim format of array of objects also.
849 // * simplified $prefs->get() and fixed $prefs->set()
850 // * added $user->_userid and class '_WikiUser' portability functions
851 // * fixed $user object ->_level upgrading, mostly using sessions.
852 // this fixes yesterdays problems with loosing authorization level.
853 // * fixed WikiUserNew::checkPass to return the _level
854 // * fixed WikiUserNew::isSignedIn
855 // * added explodePageList to class PageList, support sortby arg
856 // * fixed UserPreferences for WikiUserNew
857 // * fixed WikiPlugin for empty defaults array
858 // * UnfoldSubpages: added pagename arg, renamed pages arg,
859 // removed sort arg, support sortby arg
861 // Revision 1.7 2003/03/03 13:57:31 carstenklapp
862 // Added fontpath (see PhpWiki:VisualWiki), tries to be smart about which OS.
863 // (This plugin still doesn't work for me on OS X, but at least image files
864 // are actually being created now in '/tmp/cache'.)
866 // Revision 1.6 2003/01/18 22:11:45 carstenklapp
868 // Reformatting & tabs to spaces;
869 // Added copyleft, getVersion, getDescription, rcs_id.
876 // c-hanging-comment-ender-p: nil
877 // indent-tabs-mode: nil