2 rcs_id('$Id: VisualWiki.php,v 1.17 2004-10-14 19:19:34 rurban Exp $');
4 Copyright (C) 2002 Johannes Große (Johannes Große)
6 This file is 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');
47 } elseif ($_SERVER["SERVER_NAME"] == 'phpwiki.sourceforge.net') { // sf.net hack
48 $dotbin = '/home/groups/p/ph/phpwiki/bin/dot';
49 define('VISUALWIKIFONT', 'luximr');
51 $dotbin = '/usr/local/bin/dot';
52 // Name of the Truetypefont - Helvetica is probably easier to read
53 define('VISUALWIKIFONT', 'Helvetica');
54 //define('VISUALWIKIFONT', 'Times');
55 //define('VISUALWIKIFONT', 'Arial');
57 // The default font paths do not find your fonts, set the path here:
58 //$fontpath = "/usr/X11R6/lib/X11/fonts/TTF/";
59 //$fontpath = "/usr/share/fonts/default/TrueType/";
62 if (!defined('VISUALWIKI_ALLOWOPTIONS'))
63 define('VISUALWIKI_ALLOWOPTIONS', false);
65 require_once "lib/WikiPluginCached.php";
67 class WikiPlugin_VisualWiki
68 extends WikiPluginCached
71 * Sets plugin type to map production
73 function getPluginType() {
74 return ($GLOBALS['request']->getArg('debug')) ? PLUGIN_CACHED_IMG_ONDEMAND : PLUGIN_CACHED_MAP;
78 * Sets the plugin's name to VisualWiki. It can be called by
79 * <code><?plugin VisualWiki?></code>, now. This
80 * name must correspond to the filename and the class name.
86 function getVersion() {
87 return preg_replace("/[Revision: $]/", '',
88 "\$Revision: 1.17 $");
92 * Sets textual description.
94 function getDescription() {
95 return _("Visualizes the Wiki structure in a graph using the 'dot' commandline tool from graphviz.");
99 * Returns default arguments. This is put into a separate
100 * function to allow its usage by both <code>getDefaultArguments</code>
101 * and <code>checkArguments</code>
103 function defaultarguments() {
104 return array('imgtype' => 'png',
105 'width' => false, // was 5, scale it automatically
106 'height' => false, // was 7, scale it automatically
107 'colorby' => 'age', // sort by 'age' or 'revtime'
108 'fillnodes' => 'off',
110 'shape' => 'ellipse',
115 'neighbour_list' => '',
116 'exclude_list' => '',
117 'include_list' => '',
124 * Sets the default arguments. WikiPlugin also regards these as
125 * the allowed arguments. Since WikiPluginCached stores an image
126 * for each different set of parameters, there can be a lot of
127 * these (large) graphs if you allow different parameters.
128 * Set <code>VISUALWIKI_ALLOWOPTIONS</code> to <code>false</code>
129 * to allow no options to be set and use only the default paramters.
130 * This will need an disk space of about 20 Kbyte all the time.
132 function getDefaultArguments() {
133 if (VISUALWIKI_ALLOWOPTIONS)
134 return $this->defaultarguments();
140 * Substitutes each forbidden parameter value by the default value
141 * defined in <code>defaultarguments</code>.
143 function checkArguments(&$arg) {
145 $def = $this->defaultarguments();
147 if (($width < 3) || ($width > 15))
148 $arg['width'] = $def['width'];
150 if (($height < 3) || ($height > 20))
151 $arg['height'] = $def['height'];
153 if (($fontsize < 8) || ($fontsize > 24))
154 $arg['fontsize'] = $def['fontsize'];
156 if (!in_array($label, array('name', 'number')))
157 $arg['label'] = $def['label'];
159 if (!in_array($shape, array('ellipse', 'box', 'point', 'circle',
161 $arg['shape'] = $def['shape'];
163 if (!in_array($colorby, array('age', 'revtime')))
164 $arg['colorby'] = $def['colorby'];
166 if (!in_array($fillnodes, array('on', 'off')))
167 $arg['fillnodes'] = $def['fillnodes'];
169 if (($large_nb < 0) || ($large_nb > 50))
170 $arg['large_nb'] = $def['large_nb'];
172 if (($recent_nb < 0) || ($recent_nb > 50))
173 $arg['recent_nb'] = $def['recent_nb'];
175 if (($refined_nb < 0 ) || ( $refined_nb > 50))
176 $arg['refined_nb'] = $def['refined_nb'];
178 if (($backlink_nb < 0) || ($backlink_nb > 50))
179 $arg['backlink_nb'] = $def['backlink_nb'];
181 // ToDo: check if "ImageCreateFrom$imgtype"() exists.
182 if (!in_array($imgtype, $GLOBALS['PLUGIN_CACHED_IMGTYPES']))
183 $arg['imgtype'] = $def['imgtype'];
184 if (empty($fontname))
185 $arg['fontname'] = VISUALWIKIFONT;
189 * Checks options, creates help page if necessary, calls both
190 * database access and image map production functions.
191 * @return array($map,$html)
193 function getMap($dbi, $argarray, $request) {
194 if (!VISUALWIKI_ALLOWOPTIONS)
195 $argarray = $this->defaultarguments();
196 $this->checkArguments($argarray);
197 $request->setArg('debug',$argarray['debug']);
198 //extract($argarray);
199 if ($argarray['help'])
200 return array($this->helpImage(), ' '); // FIXME
201 $this->createColors();
202 $this->extract_wikipages($dbi, $argarray);
203 /* ($dbi, $large, $recent, $refined, $backlink,
204 $neighbour, $excludelist, $includelist, $color); */
205 return $this->invokeDot($argarray);
206 /* ($width, $height, $color, $shape, $text); */
210 * Sets the expire time to one day (so the image producing
211 * functions are called seldomly) or to about two minutes
212 * if a help screen is created.
214 function getExpire($dbi, $argarray, $request) {
215 if ($argarray['help'])
216 return '+120'; // 2 minutes
217 return sprintf('+%d', 3*86000); // approx 3 days
221 * Sets the imagetype according to user wishes and
222 * relies on WikiPluginCached to catch illegal image
224 * (I feel unsure whether this option is reasonable in
225 * this case, because png will definitely have the
228 * @return string 'png', 'gif', 'jpeg'
230 function getImageType($dbi, $argarray, $request) {
231 return $argarray['imgtype'];
235 * This gives an alternative text description of
236 * the image map. I do not know whether it interferes
237 * with the <code>title</code> attributes in <area>
238 * tags of the image map. Perhaps this will be removed.
241 function getAlt($dbi, $argstr, $request) {
242 return $this->getDescription();
245 // ------------------------------------------------------------------------------------------
248 * Returns an image containing a usage description of the plugin.
249 * @return string image handle
251 function helpImage() {
252 $def = $this->defaultarguments();
253 $other_imgtypes = $GLOBALS['PLUGIN_CACHED_IMGTYPES'];
254 unset ($other_imgtypes[$def['imgtype']]);
256 '<?plugin '.$this->getName() .
257 ' img' => ' = "' . $def['imgtype'] . "(default)|" . join('|',$GLOBALS['PLUGIN_CACHED_IMGTYPES']).'"',
258 'width' => ' = "width in inches"',
259 'height' => ' = "height in inches"',
260 'fontname' => ' = "font family"',
261 'fontsize' => ' = "fontsize in points"',
262 'colorby' => ' = "age|revtime|none"',
263 'fillnodes' => ' = "on|off"',
264 'shape' => ' = "ellipse(default)|box|circle|point"',
265 'label' => ' = "name|number"',
266 'large_nb' => ' = "number of largest pages to be selected"',
267 'recent_nb' => ' = "number of youngest pages"',
268 'refined_nb' => ' = "#pages with smallest time between revisions"',
269 'backlink_nb' => ' = "number of pages with most backlinks"',
270 'neighbour_list' => ' = "find pages linked from and to these pages"',
271 'exclude_list' => ' = "colon separated list of pages to be excluded"',
272 'include_list' => ' = "colon separated list" ?>'
275 foreach($helparr as $alignright => $alignleft) {
276 $length = max($length, strlen($alignright));
279 foreach($helparr as $alignright => $alignleft) {
280 $helptext .= substr(' '
281 . $alignright, -$length).$alignleft."\n";
283 return $this->text2img($helptext, 4, array(1, 0, 0),
284 array(255, 255, 255));
289 * Selects the first (smallest or biggest) WikiPages in
292 * @param number integer number of page names to be found
293 * @param category string attribute of the pages which is used
295 * @param minimum boolean true finds smallest, false finds biggest
296 * @return array list of page names found to be the best
298 function findbest($number, $category, $minimum ) {
299 // select the $number best in the category '$category'
300 $pages = &$this->pages;
301 $names = &$this->names;
305 foreach($names as $name) {
308 $selected[$name] = $pages[$name][$category];
310 //echo "<pre>$category "; var_dump($selected); "</pre>";
311 $compareto = $minimum ? 0x79999999 : -0x79999999;
314 foreach ($names as $name) {
318 if (($crit = $pages[$name][$category]) < $compareto) {
319 $selected[$name] = $crit;
320 asort($selected, SORT_NUMERIC);
321 array_pop($selected);
322 $compareto = end($selected);
324 } elseif (($crit = $pages[$name][$category]) > $compareto) {
325 $selected[$name] = $crit;
326 arsort($selected, SORT_NUMERIC);
327 array_pop($selected);
328 $compareto = end($selected);
331 //echo "<pre>$category "; var_dump($selected); "</pre>";
333 return array_keys($selected);
338 * Extracts a subset of all pages from the wiki and find their
339 * connections to other pages. Also collects some page features
340 * like size, age, revision number which are used to find the
341 * most attractive pages.
343 * @param dbi WikiDB database handle to access all Wiki pages
344 * @param LARGE integer number of largest pages which should
346 * @param RECENT integer number of the youngest pages to be included
347 * @param REFINED integer number of the pages with shortes revision
349 * @param BACKLINK integer number of the pages with most backlinks
350 * @param EXCLUDELIST string colon ':' separated list of page names which
351 * should not be displayed (like PhpWiki, for
353 * @param INCLUDELIST string colon separated list of pages which are
354 * allways included (for example your own
356 * @param COLOR string 'age', 'revtime' or 'none'; Selects which
357 * page feature is used to determine the
358 * filling color of the nodes in the graph.
361 function extract_wikipages($dbi, $argarray) {
362 // $LARGE, $RECENT, $REFINED, $BACKLINK, $NEIGHBOUR,
363 // $EXCLUDELIST, $INCLUDELIST,$COLOR
367 // FIXME: gettextify?
368 $exclude_list = explode(':', $exclude_list);
369 $include_list = explode(':', $include_list);
370 $neighbour_list = explode(':', $neighbour_list);
372 // FIXME remove INCLUDED from EXCLUDED
375 $allpages = $dbi->getAllPages();
376 $pages = &$this->pages;
378 while ($page = $allpages->next()) {
379 $name = $page->getName();
381 // skip exluded pages
382 if (in_array($name, $exclude_list)) {
387 // false = get links from actual page
388 // true = get links to actual page ("backlinks")
389 $backlinks = $page->getLinks(true);
391 $bconnection = array();
392 while ($blink = $backlinks->next()) {
393 array_push($bconnection, $blink->getName());
398 // include all neighbours of pages listed in $NEIGHBOUR
399 if (in_array($name,$neighbour_list)) {
400 $l = $page->getLinks(false);
402 while ($link = $l->next()) {
403 array_push($con, $link->getName());
405 $include_list = array_merge($include_list, $bconnection, $con);
412 $currev = $page->getCurrentRevision();
414 $pages[$name] = array(
415 'age' => $now-$currev->get('mtime'),
416 'revnr' => $currev->getVersion(),
418 'backlink_nb' => count($bconnection),
419 'backlinks' => $bconnection,
420 'size' => 1000 // FIXME
422 $pages[$name]['revtime'] = $pages[$name]['age'] / ($pages[$name]['revnr']);
428 $this->names = array_keys($pages);
430 $countpages = count($pages);
432 // now select each page matching to given parameters
433 $all_selected = array_unique(array_merge(
434 $this->findbest($recent_nb, 'age', true),
435 $this->findbest($refined_nb, 'revtime', true),
436 $x = $this->findbest($backlink_nb, 'backlink_nb', false),
437 // $this->findbest($large_nb, 'size', false),
440 foreach($all_selected as $name)
441 if (isset($pages[$name]))
442 $newpages[$name] = $pages[$name];
445 $this->pages = $newpages;
446 $pages = &$this->pages;
447 $this->names = array_keys($pages);
449 unset($all_selected);
451 $countpages = count($pages);
453 // remove dead links and collect links
455 while( list($name,$page) = each($pages) ) {
456 if (is_array($page['backlinks'])) {
457 reset($page['backlinks']);
458 while ( list($index, $link) = each( $page['backlinks'] ) ) {
459 if ( !isset($pages[$link]) || $link == $name ) {
460 unset($pages[$name]['backlinks'][$index]);
462 array_push($pages[$link]['links'],$name);
463 //array_push($this->everylink, array($link,$name));
469 if ($colorby == 'none')
471 list($oldestname) = $this->findbest(1, $colorby, false);
472 $this->oldest = $pages[$oldestname][$colorby];
473 foreach($this->names as $name)
474 $pages[$name]['color'] = $this->getColor($pages[$name][$colorby] / $this->oldest);
475 } // extract_wikipages
478 * Creates the text file description of the graph needed to invoke
481 * @param filename string name of the dot file to be created
482 * @param width float width of the output graph in inches
483 * @param height float height of the graph in inches
484 * @param colorby string color sceme beeing used ('age', 'revtime',
486 * @param shape string node shape; 'ellipse', 'box', 'circle', 'point'
487 * @param label string 'name': label by name,
488 * 'number': label by unique number
489 * @return boolean error status; true=ok; false=error
491 function createDotFile($filename, $argarray) {
493 if (!$fp = fopen($filename, 'w'))
496 $fillstring = ($fillnodes == 'on') ? 'style=filled,' : '';
499 $names = &$this->names;
500 $pages = &$this->pages;
502 $nametonumber = array_flip($names);
504 $dot = "digraph VisualWiki {\n" // }
505 . (!empty($fontpath) ? " fontpath=\"$fontpath\"\n" : "");
506 if ($width and $height)
507 $dot .= " size=\"$width,$height\";\n ";
512 $dot .= "edge [arrowhead=none];\nnode [shape=$shape,fontname=$fontname,width=0.15,height=0.15,fontsize=$fontsize];\n";
515 $dot .= "node [shape=$shape,fontname=$fontname,width=0.4,height=0.4,fontsize=$fontsize];\n";
518 $dot .= "node [shape=$shape,fontname=$fontname,width=0.25,height=0.25,fontsize=$fontsize];\n";
521 $dot .= "node [fontname=$fontname,shape=$shape,fontsize=$fontsize];\n" ;
525 foreach ($names as $name) {
527 $url = rawurlencode($name);
528 // patch to allow Page/SubPage
529 $url = preg_replace('/' . urlencode(SUBPAGE_SEPARATOR) . '/',
530 SUBPAGE_SEPARATOR, $url);
531 $nodename = ($label != 'name' ? $nametonumber[$name] + 1 : $name);
533 $dot .= " \"$nodename\" [URL=\"$url\"";
534 if ($colorby != 'none') {
535 $col = $pages[$name]['color'];
536 $dot .= sprintf(',%scolor="#%02X%02X%02X"', $fillstring,
537 $col[0], $col[1], $col[2]);
541 if (!empty($pages[$name]['links'])) {
543 if ($label != 'name')
544 foreach($pages[$name]['links'] as $linkname)
545 $linkarray[] = $nametonumber[$linkname] + 1;
547 $linkarray = $pages[$name]['links'];
548 $linkstring = join('"; "', $linkarray );
550 $c = count($pages[$name]['links']);
551 $dot .= " \"$nodename\" -> "
558 if ($colorby != 'none') {
559 $dot .= "\n subgraph cluster_legend {\n"
560 . " node[fontname=$fontname,shape=box,width=0.4,height=0.4,fontsize=$fontsize];\n"
561 . " fillcolor=lightgrey;\n"
563 . " fontname=$fontname;\n"
564 . " fontsize=$fontsize;\n"
565 . " label=\"".gettext("Legend")."\";\n";
566 $oldest= ceil($this->oldest / (24 * 3600));
569 for($i = 0; $i < $max; $i++) {
570 $time = floor($i / $max * $oldest);
571 $name = '"' . $time .' '. _("days") .'"';
572 $col = $this->getColor($i/$max);
573 $dot .= sprintf(' %s [%scolor="#%02X%02X%02X"];',
574 $name, $fillstring, $col[0], $col[1], $col[2])
578 $dot .= ' '. join(' -> ', $legend)
586 $ok = fwrite($fp, $dot);
587 $ok = fclose($fp) && $ok; // close anyway
593 * Execute system command.
595 * @param cmd string command to be invoked
596 * @return boolean error status; true=ok; false=error
598 function execute($cmd, $until = false) {
599 // cmd must redirect stderr to stdout though!
600 $errstr = exec($cmd); //, $outarr, $returnval); // normally 127
601 //$errstr = join('',$outarr);
602 $ok = empty($errstr);
604 trigger_error("\n".$cmd." failed: $errstr", E_USER_WARNING);
605 } elseif ($GLOBALS['request']->getArg('debug'))
606 trigger_error("\n".$cmd.": success\n", E_USER_NOTICE);
610 while (!file_exists($until) and $loop > 0) {
619 return file_exists($until);
624 * Produces a dot file, calls dot twice to obtain an image and a
625 * text description of active areas for hyperlinking and returns
626 * an image and an html map.
628 * @param width float width of the output graph in inches
629 * @param height float height of the graph in inches
630 * @param colorby string color sceme beeing used ('age', 'revtime',
632 * @param shape string node shape; 'ellipse', 'box', 'circle', 'point'
633 * @param label string not used anymore
635 function invokeDot($argarray) {
637 $tempfiles = $this->tempnam('VisualWiki');
638 $gif = $argarray['imgtype'];
639 $ImageCreateFromFunc = "ImageCreateFrom$gif";
640 $outfile = $tempfiles.".".$gif;
641 $debug = $GLOBALS['request']->getArg('debug');
643 $tempdir = dirname($tempfiles);
644 $tempout = $tempdir . "/.debug";
647 && $this->createDotFile($tempfiles.'.dot',$argarray)
648 // && $this->filterThroughCmd('',"$dotbin -T$gif $tempfiles.dot -o $outfile")
649 // && $this->filterThroughCmd('',"$dotbin -Timap $tempfiles.dot -o ".$tempfiles.".map")
650 && $this->execute("$dotbin -T$gif $tempfiles.dot -o $outfile" .
651 ($debug ? " > $tempout 2>&1" : " 2>&1"), $outfile)
652 && $this->execute("$dotbin -Timap $tempfiles.dot -o ".$tempfiles.".map" .
653 ($debug ? " > $tempout 2>&1" : " 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')."\n".
704 "$tempfiles.map: ".(file_exists("$tempfiles.map") ? filesize("$tempfiles.map"):'missing'));
705 $this->_errortext .= ("\ncmd-line: $dotbin -T$gif $tempfiles.dot -o $outfile");
706 trigger_error($this->_errortext, E_USER_WARNING);
707 return array(false, false);
710 // clean up tempfiles
711 if ($ok and !$argarray['debug'])
712 foreach (array('',".$gif",'.map','.dot') as $ext) {
713 if (file_exists($tempfiles.$ext))
714 unlink($tempfiles.$ext);
718 return array($img, $map);
720 return array(false, false);
725 * static workaround on broken Cache or broken dot executable,
726 * called only if debug=static.
729 * @param url string url pointing to the image part of the map
730 * @param map string <area> tags defining active
732 * @param dbi WikiDB database abstraction class
733 * @param argarray array complete (!) arguments to produce
734 * image. It is not necessary to call
735 * WikiPlugin->getArgs anymore.
736 * @param request Request ???
737 * @return string html output
739 function embedImg($url,&$dbi,$argarray,&$request) {
740 if (!VISUALWIKI_ALLOWOPTIONS)
741 $argarray = $this->defaultarguments();
742 $this->checkArguments($argarray);
743 //extract($argarray);
744 if ($argarray['help'])
745 return array($this->helpImage(), ' '); // FIXME
746 $this->createColors();
747 $this->extract_wikipages($dbi, $argarray);
748 list($imagehandle, $content['html']) = $this->invokeDot($argarray);
749 // write to uploads and produce static url
750 $file_dir = defined('PHPWIKI_DIR') ?
751 PHPWIKI_DIR . "/uploads" : "uploads";
752 $upload_dir = SERVER_URL . ((substr(DATA_PATH,0,1)=='/') ? '' : "/") . DATA_PATH . '/uploads/';
753 $tmpfile = tempnam($file_dir,"VisualWiki").".".$argarray['imgtype'];
754 WikiPluginCached::writeImage($argarray['imgtype'], $imagehandle, $tmpfile);
755 ImageDestroy($imagehandle);
756 return WikiPluginCached::embedMap(1,$upload_dir.basename($tmpfile),$content['html'],$dbi,$argarray,$request);
761 * Prepares some rainbow colors for the nodes of the graph
762 * and stores them in an array which may be accessed with
763 * <code>getColor</code>.
765 function createColors() {
766 $predefcolors = array(
767 array('red' => 255, 'green' => 0, 'blue' => 0),
768 array('red' => 255, 'green' => 255, 'blue' => 0),
769 array('red' => 0, 'green' => 255, 'blue' => 0),
770 array('red' => 0, 'green' => 255, 'blue' => 255),
771 array('red' => 0, 'green' => 0, 'blue' => 255),
772 array('red' => 100, 'green' => 100, 'blue' => 100)
776 $numberofcolors = count($predefcolors) * $steps;
779 foreach($predefcolors as $color) {
785 for ($i = 0; $i < $steps; $i++)
786 $this->ColorTab[++$promille / $numberofcolors * 1000] = array(
787 floor(interpolate( $oldcolor['red'], $color['red'], $i/$steps )),
788 floor(interpolate( $oldcolor['green'], $color['green'], $i/$steps )),
789 floor(interpolate( $oldcolor['blue'], $color['blue'], $i/$steps ))
793 //echo"<pre>"; var_dump($this->ColorTab); echo "</pre>";
797 * Translates a value from 0.0 to 1.0 into rainbow color.
798 * red -> orange -> green -> blue -> gray
800 * @param promille float value between 0.0 and 1.0
801 * @return array(red,green,blue)
803 function getColor($promille) {
804 foreach( $this->ColorTab as $pro => $col ) {
805 if ($promille*1000 < $pro)
808 $lastcol = end($this->ColorTab);
811 } // WikiPlugin_VisualWiki
814 * Linear interpolates a value between two point a and b
816 * @return float interpolated value
819 function interpolate($a, $b, $pos) {
820 return $a + ($b - $a) * $pos;
823 // $Log: not supported by cvs2svn $
824 // Revision 1.16 2004/10/12 15:34:47 rurban
825 // redirect stderr to display the failing msg
827 // Revision 1.15 2004/09/08 13:38:00 rurban
828 // improve loadfile stability by using markup=2 as default for undefined markup-style.
829 // use more refs for huge objects.
830 // fix debug=static issue in WikiPluginCached
832 // Revision 1.14 2004/09/07 13:26:31 rurban
833 // new WikiPluginCached option debug=static and some more sf.net defaults for VisualWiki
835 // Revision 1.13 2004/09/06 12:13:00 rurban
836 // provide sf.net default dotbin
838 // Revision 1.12 2004/09/06 12:08:50 rurban
839 // memory_limit on unix workaround
840 // VisualWiki: default autosize image
842 // Revision 1.11 2004/09/06 10:10:27 rurban
843 // fixed syntax error
845 // Revision 1.10 2004/06/19 10:06:38 rurban
846 // Moved lib/plugincache-config.php to config/*.ini
847 // use PLUGIN_CACHED_* constants instead of global $CacheParams
849 // Revision 1.9 2004/06/03 09:40:57 rurban
850 // WikiPluginCache improvements
852 // Revision 1.8 2004/01/26 09:18:00 rurban
853 // * changed stored pref representation as before.
854 // the array of objects is 1) bigger and 2)
855 // less portable. If we would import packed pref
856 // objects and the object definition was changed, PHP would fail.
857 // This doesn't happen with an simple array of non-default values.
858 // * use $prefs->retrieve and $prefs->store methods, where retrieve
859 // understands the interim format of array of objects also.
860 // * simplified $prefs->get() and fixed $prefs->set()
861 // * added $user->_userid and class '_WikiUser' portability functions
862 // * fixed $user object ->_level upgrading, mostly using sessions.
863 // this fixes yesterdays problems with loosing authorization level.
864 // * fixed WikiUserNew::checkPass to return the _level
865 // * fixed WikiUserNew::isSignedIn
866 // * added explodePageList to class PageList, support sortby arg
867 // * fixed UserPreferences for WikiUserNew
868 // * fixed WikiPlugin for empty defaults array
869 // * UnfoldSubpages: added pagename arg, renamed pages arg,
870 // removed sort arg, support sortby arg
872 // Revision 1.7 2003/03/03 13:57:31 carstenklapp
873 // Added fontpath (see PhpWiki:VisualWiki), tries to be smart about which OS.
874 // (This plugin still doesn't work for me on OS X, but at least image files
875 // are actually being created now in '/tmp/cache'.)
877 // Revision 1.6 2003/01/18 22:11:45 carstenklapp
879 // Reformatting & tabs to spaces;
880 // Added copyleft, getVersion, getDescription, rcs_id.
887 // c-hanging-comment-ender-p: nil
888 // indent-tabs-mode: nil