GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WikiPlugin_VisualWiki::getColor()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
1
<?php // -*-php-*-
2
rcs_id('$Id: VisualWiki.php,v 1.19 2005/10/12 06:19:31 rurban Exp $');
3
/*
4
 Copyright (C) 2002 Johannes Gro�e (Johannes Gro&szlig;e)
5
6
 This file is part of PhpWiki.
7
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.
12
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.
17
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
21
 */
22
23
/**
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
29
 * @version 0.9
30
 */
31
define('VISUALWIKI_ALLOWOPTIONS', true);
32
if (!defined('VISUALWIKI_ALLOWOPTIONS'))
33
    define('VISUALWIKI_ALLOWOPTIONS', false);
34
35
require_once "lib/plugin/GraphViz.php";
36
37
class WikiPlugin_VisualWiki
38
extends WikiPlugin_GraphViz
39
{
40
    /**
41
     * Sets plugin type to map production
42
     */
43
    function getPluginType() {
44
        return ($GLOBALS['request']->getArg('debug')) ? PLUGIN_CACHED_IMG_ONDEMAND : PLUGIN_CACHED_MAP;
45
    }
46
47
    /**
48
     * Sets the plugin's name to VisualWiki. It can be called by
49
     * <code>&lt;?plugin VisualWiki?&gt;</code>, now. This
50
     * name must correspond to the filename and the class name.
51
     */
52
    function getName() {
53
        return "VisualWiki";
54
    }
55
56
    function getVersion() {
57
        return preg_replace("/[Revision: $]/", '',
58
                            "\$Revision: 1.19 $");
59
    }
60
61
    /**
62
     * Sets textual description.
63
     */
64
    function getDescription() {
65
        return _("Visualizes the Wiki structure in a graph using the 'dot' commandline tool from graphviz.");
66
    }
67
68
    /**
69
     * Returns default arguments. This is put into a separate
70
     * function to allow its usage by both <code>getDefaultArguments</code>
71
     * and <code>checkArguments</code>
72
     */
73
    function defaultarguments() {
74
        return array('imgtype'        => 'png',
75
                     'width'          => false, // was 5, scale it automatically
76
                     'height'         => false, // was 7, scale it automatically
77
                     'colorby'        => 'age', // sort by 'age' or 'revtime'
78
                     'fillnodes'      => 'off',
79
                     'label'          => 'name',
80
                     'shape'          => 'ellipse',
81
                     'large_nb'       => 5,
82
                     'recent_nb'      => 5,
83
                     'refined_nb'     => 15,
84
                     'backlink_nb'    => 5,
85
                     'neighbour_list' => '',
86
                     'exclude_list'   => '',
87
                     'include_list'   => '',
88
                     'fontsize'       => 9,
89
                     'debug'          => false,
90
                     'help'           => false );
91
    }
92
93
    /**
94
     * Sets the default arguments. WikiPlugin also regards these as
95
     * the allowed arguments. Since WikiPluginCached stores an image
96
     * for each different set of parameters, there can be a lot of
97
     * these (large) graphs if you allow different parameters.
98
     * Set <code>VISUALWIKI_ALLOWOPTIONS</code> to <code>false</code>
99
     * to allow no options to be set and use only the default parameters.
100
     * This will need an disk space of about 20 Kbyte all the time.
101
     */
102
    function getDefaultArguments() {
103
        if (VISUALWIKI_ALLOWOPTIONS)
104
            return $this->defaultarguments();
0 ignored issues
show
Best Practice introduced by
The expression return $this->defaultarguments(); seems to be an array, but some of its elements' types (integer) are incompatible with the return type of the parent method WikiPlugin_GraphViz::getDefaultArguments of type array<string,string|false>.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
105
        else
106
            return array();
107
    }
108
109
    /**
110
     * Substitutes each forbidden parameter value by the default value
111
     * defined in <code>defaultarguments</code>.
112
     */
113
    function checkArguments(&$arg) {
114
        extract($arg);
115
        $def = $this->defaultarguments();
116
        if (($width < 3) || ($width > 15))
117
            $arg['width'] = $def['width'];
118
        if (($height < 3) || ($height > 20))
119
            $arg['height'] = $def['height'];
120
        if (($fontsize < 8) || ($fontsize > 24))
121
            $arg['fontsize'] = $def['fontsize'];
122
        if (!in_array($label, array('name', 'number')))
123
            $arg['label'] = $def['label'];
124
125
        if (!in_array($shape, array('ellipse', 'box', 'point', 'circle',
126
                                    'plaintext')))
127
            $arg['shape'] = $def['shape'];
128
        if (!in_array($colorby, array('age', 'revtime')))
129
            $arg['colorby'] = $def['colorby'];
130
        if (!in_array($fillnodes, array('on', 'off')))
131
            $arg['fillnodes'] = $def['fillnodes'];
132
        if (($large_nb < 0) || ($large_nb > 50))
133
            $arg['large_nb'] = $def['large_nb'];
134
        if (($recent_nb < 0)  || ($recent_nb > 50))
135
            $arg['recent_nb'] = $def['recent_nb'];
136
        if (($refined_nb < 0 ) || ( $refined_nb > 50))
137
            $arg['refined_nb'] = $def['refined_nb'];
138
        if (($backlink_nb < 0) || ($backlink_nb > 50))
139
            $arg['backlink_nb'] = $def['backlink_nb'];
140
        // ToDo: check if "ImageCreateFrom$imgtype"() exists.
141
        if (!in_array($imgtype, $GLOBALS['PLUGIN_CACHED_IMGTYPES']))
142
            $arg['imgtype'] = $def['imgtype'];
143
        if (empty($fontname))
144
            $arg['fontname'] = VISUALWIKIFONT;
145
    }
146
147
    /**
148
     * Checks options, creates help page if necessary, calls both
149
     * database access and image map production functions.
150
     * @return array($map,$html)
0 ignored issues
show
Documentation introduced by
The doc-type array($map,$html) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
151
     */
152
    function getMap($dbi, $argarray, $request) {
153
        if (!VISUALWIKI_ALLOWOPTIONS)
154
            $argarray = $this->defaultarguments();
155
        $this->checkArguments($argarray);
156
        $request->setArg('debug',$argarray['debug']);
157
        //extract($argarray);
158
        if ($argarray['help'])
159
            return array($this->helpImage(), ' '); // FIXME
160
        $this->createColors();
161
        $this->extract_wikipages($dbi, $argarray);
162
        /* ($dbi,  $large, $recent, $refined, $backlink,
163
            $neighbour, $excludelist, $includelist, $color); */
164
        return $this->invokeDot($argarray);
165
        /* => ($width, $height, $color, $shape, $text); */
166
	
167
    }
168
169
    // ------------------------------------------------------------------------------------------
170
171
    /**
172
     * Returns an image containing a usage description of the plugin.
173
     * @return string image handle
174
     */
175
    function helpImage() {
176
        $def = $this->defaultarguments();
177
        $other_imgtypes = $GLOBALS['PLUGIN_CACHED_IMGTYPES'];
178
        unset ($other_imgtypes[$def['imgtype']]);
179
        $helparr = array(
180
            '<?plugin '.$this->getName() .
181
            ' img'             => ' = "' . $def['imgtype'] . "(default)|" . join('|',$GLOBALS['PLUGIN_CACHED_IMGTYPES']).'"',
182
            'width'            => ' = "width in inches"',
183
            'height'           => ' = "height in inches"',
184
            'fontname'         => ' = "font family"',
185
            'fontsize'         => ' = "fontsize in points"',
186
            'colorby'          => ' = "age|revtime|none"',
187
            'fillnodes'        => ' = "on|off"',
188
            'shape'            => ' = "ellipse(default)|box|circle|point"',
189
            'label'            => ' = "name|number"',
190
            'large_nb'         => ' = "number of largest pages to be selected"',
191
            'recent_nb'        => ' = "number of youngest pages"',
192
            'refined_nb'       => ' = "#pages with smallest time between revisions"',
193
            'backlink_nb'      => ' = "number of pages with most backlinks"',
194
            'neighbour_list'   => ' = "find pages linked from and to these pages"',
195
            'exclude_list'     => ' = "colon separated list of pages to be excluded"',
196
            'include_list'     => ' = "colon separated list"     ?>'
197
            );
198
        $length = 0;
199
        foreach($helparr as $alignright => $alignleft) {
200
            $length = max($length, strlen($alignright));
201
        }
202
        $helptext ='';
203
        foreach($helparr as $alignright => $alignleft) {
204
            $helptext .= substr('                                                        '
205
                                . $alignright, -$length).$alignleft."\n";
206
        }
207
        return $this->text2img($helptext, 4, array(1, 0, 0),
208
                               array(255, 255, 255));
209
    }
210
211
212
    /**
213
     * Selects the first (smallest or biggest) WikiPages in
214
     * a given category.
215
     *
216
     * @param  number   integer  number of page names to be found
217
     * @param  category string   attribute of the pages which is used
218
     *                           to compare them
219
     * @param  minimum  boolean  true finds smallest, false finds biggest
220
     * @return array             list of page names found to be the best
221
     */
222
    function findbest($number, $category, $minimum ) {
223
        // select the $number best in the category '$category'
224
        $pages = &$this->pages;
225
        $names = &$this->names;
226
227
        $selected = array();
228
        $i = 0;
229
        foreach($names as $name) {
230
            if ($i++>=$number)
231
                break;
232
            $selected[$name] = $pages[$name][$category];
233
        }
234
        //echo "<pre>$category "; var_dump($selected); "</pre>";
235
        $compareto = $minimum ? 0x79999999 : -0x79999999;
236
237
        $i = 0;
238
        foreach ($names as $name) {
239
            if ($i++<$number)
240
                continue;
241
            if ($minimum) {
242
                if (($crit = $pages[$name][$category]) < $compareto) {
243
                    $selected[$name] = $crit;
244
                    asort($selected, SORT_NUMERIC);
245
                    array_pop($selected);
246
                    $compareto = end($selected);
247
                }
248
            } elseif (($crit = $pages[$name][$category]) > $compareto)  {
249
                $selected[$name] = $crit;
250
                arsort($selected, SORT_NUMERIC);
251
                array_pop($selected);
252
                $compareto = end($selected);
253
            }
254
        }
255
        //echo "<pre>$category "; var_dump($selected); "</pre>";
256
257
        return array_keys($selected);
258
    }
259
260
261
    /**
262
    * Extracts a subset of all pages from the wiki and find their
263
    * connections to other pages. Also collects some page features
264
    * like size, age, revision number which are used to find the
265
    * most attractive pages.
266
    *
267
    * @param  dbi         WikiDB   database handle to access all Wiki pages
268
    * @param  LARGE       integer  number of largest pages which should
269
    *                              be included
270
    * @param  RECENT      integer  number of the youngest pages to be included
271
    * @param  REFINED     integer  number of the pages with shortes revision
272
    *                              interval
273
    * @param  BACKLINK    integer  number of the pages with most backlinks
274
    * @param  EXCLUDELIST string   colon ':' separated list of page names which
275
    *                              should not be displayed (like PhpWiki, for
276
    *                              example)
277
    * @param  INCLUDELIST string   colon separated list of pages which are
278
    *                              always included (for example your own
279
    *                              page :)
280
    * @param  COLOR       string   'age', 'revtime' or 'none'; Selects which
281
    *                              page feature is used to determine the
282
    *                              filling color of the nodes in the graph.
283
    * @return void
284
    */
285
    function extract_wikipages($dbi, $argarray) {
286
        // $LARGE, $RECENT, $REFINED, $BACKLINK, $NEIGHBOUR,
287
        // $EXCLUDELIST, $INCLUDELIST,$COLOR
288
        $now = time();
289
290
        extract($argarray);
291
        // FIXME: gettextify?
292
        $exclude_list   = $exclude_list ? explode(':', $exclude_list) : array();
293
        $include_list   = $include_list ? explode(':', $include_list) : array();
294
        $neighbour_list = $neighbour_list ? explode(':', $neighbour_list) : array();
295
296
        // remove INCLUDED from EXCLUDED, includes override excludes.
297
        if ($exclude_list and $include_list) {
298
        	$diff = array_diff($exclude_list, $include_list);
299
        	if ($diff)
0 ignored issues
show
Bug Best Practice introduced by
The expression $diff of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
300
        	    $exclude_list = $diff;
301
        }
302
303
        // collect all pages
304
        $allpages = $dbi->getAllPages(false, false, false, $exclude_list);
305
        $pages = &$this->pages;
306
        $countpages = 0;
307
        while ($page = $allpages->next()) {
308
            $name = $page->getName();
309
310
            // skip excluded pages
311
            if (in_array($name, $exclude_list)) {
312
            	$page->free();	
313
                continue;
314
            }
315
316
            // false = get links from actual page
317
            // true  = get links to actual page ("backlinks")
318
            $backlinks = $page->getLinks(true);
319
            unset($bconnection);
320
            $bconnection = array();
321
            while ($blink = $backlinks->next()) {
322
                array_push($bconnection, $blink->getName());
323
            }
324
            $backlinks->free();
325
            unset($backlinks);
326
327
            // include all neighbours of pages listed in $NEIGHBOUR
328
            if (in_array($name, $neighbour_list)) {
329
                $ln = $page->getLinks(false);
330
                $con = array();
331
                while ($link = $ln->next()) {
332
                    array_push($con, $link->getName());
333
                }
334
                $include_list = array_merge($include_list, $bconnection, $con);
335
                $ln->free();
336
                unset($l);
337
                unset($con);
338
            }
339
340
            unset($rev);
341
            $rev = $page->getCurrentRevision();
342
343
            $pages[$name] = array(
344
                'age'         => $now - $rev->get('mtime'),
345
                'revnr'       => $rev->getVersion(),
346
                'links'       => array(),
347
                'backlink_nb' => count($bconnection),
348
                'backlinks'   => $bconnection,
349
                'size'        => 1000 // FIXME
350
                );
351
            $pages[$name]['revtime'] = $pages[$name]['age'] / ($pages[$name]['revnr']);
352
353
            unset($page);
354
        }
355
        $allpages->free();
356
        unset($allpages);
357
        $this->names = array_keys($pages);
358
359
        $countpages = count($pages);
360
361
        // now select each page matching to given parameters
362
        $all_selected = array_unique(array_merge(
363
            $this->findbest($recent_nb,   'age',         true),
364
            $this->findbest($refined_nb,  'revtime',     true),
365
            $x = $this->findbest($backlink_nb, 'backlink_nb', false),
366
//          $this->findbest($large_nb,    'size',        false),
367
            $include_list));
368
369
        foreach($all_selected as $name)
370
            if (isset($pages[$name]))
371
                $newpages[$name] = $pages[$name];
372
        unset($this->names);
373
        unset($this->pages);
374
        $this->pages = $newpages;
375
        $pages = &$this->pages;
376
        $this->names = array_keys($pages);
377
        unset($newpages);
378
        unset($all_selected);
379
380
        $countpages = count($pages);
381
382
        // remove dead links and collect links
383
        reset($pages);
384
        while( list($name, $page) = each($pages) ) {
385
            if (is_array($page['backlinks'])) {
386
                reset($page['backlinks']);
387
                while ( list($index, $link) = each( $page['backlinks'] ) ) {
388
                    if ( !isset($pages[$link]) || $link == $name ) {
389
                        unset($pages[$name]['backlinks'][$index]);
390
                    } else {
391
                        array_push($pages[$link]['links'],$name);
392
                        //array_push($this->everylink, array($link,$name));
393
                    }
394
                }
395
            }
396
        }
397
398
        if ($colorby == 'none')
399
            return;
400
        list($oldestname) = $this->findbest(1, $colorby, false);
401
        $this->oldest = $pages[$oldestname][$colorby];
402
        foreach($this->names as $name)
403
            $pages[$name]['color'] = $this->getColor($pages[$name][$colorby] / $this->oldest);
404
    }
405
406
    /**
407
     * Creates the text file description of the graph needed to invoke
408
     * <code>dot</code>.
409
     *
410
     * @param filename  string  name of the dot file to be created
411
     * @param width     float   width of the output graph in inches
412
     * @param height    float   height of the graph in inches
413
     * @param colorby   string  color sceme beeing used ('age', 'revtime',
414
     *                                                   'none')
415
     * @param shape     string  node shape; 'ellipse', 'box', 'circle', 'point'
416
     * @param label     string  'name': label by name,
417
     *                          'number': label by unique number
418
     * @return boolean          error status; true=ok; false=error
419
     */
420
    function createDotFile($filename, $argarray) {
421
        extract($argarray);
422
        if (!$fp = fopen($filename, 'w'))
423
            return false;
424
425
        $fillstring = ($fillnodes == 'on') ? 'style=filled,' : '';
426
427
        $ok = true;
428
        $names = &$this->names;
429
        $pages = &$this->pages;
430
        if ($names)
431
            $nametonumber = array_flip($names);
432
433
        $dot = "digraph VisualWiki {\n" // }
434
            . (!empty($fontpath) ? "    fontpath=\"$fontpath\"\n" : "");
435
        if ($width and $height)
436
            $dot .= "    size=\"$width,$height\";\n    ";
437
438
439
        switch ($shape) {
440
        case 'point':
441
            $dot .= "edge [arrowhead=none];\nnode [shape=$shape,fontname=$fontname,width=0.15,height=0.15,fontsize=$fontsize];\n";
442
            break;
443
        case 'box':
444
            $dot .= "node [shape=$shape,fontname=$fontname,width=0.4,height=0.4,fontsize=$fontsize];\n";
445
            break;
446
        case 'circle':
447
            $dot .= "node [shape=$shape,fontname=$fontname,width=0.25,height=0.25,fontsize=$fontsize];\n";
448
            break;
449
        default :
450
            $dot .= "node [fontname=$fontname,shape=$shape,fontsize=$fontsize];\n" ;
451
        }
452
        $dot .= "\n";
453
        $i = 0;
454
        foreach ($names as $name) {
455
456
            $url = rawurlencode($name);
457
            // patch to allow Page/SubPage
458
            $url = str_replace(urlencode(SUBPAGE_SEPARATOR), SUBPAGE_SEPARATOR, $url);
459
            $nodename = ($label != 'name' ? $nametonumber[$name] + 1 : $name);
460
461
            $dot .= "    \"$nodename\" [URL=\"$url\"";
462
            if ($colorby != 'none') {
463
                $col = $pages[$name]['color'];
464
                $dot .= sprintf(',%scolor="#%02X%02X%02X"', $fillstring,
465
                                $col[0], $col[1], $col[2]);
466
            }
467
            $dot .= "];\n";
468
469
            if (!empty($pages[$name]['links'])) {
470
                unset($linkarray);
471
                if ($label != 'name')
472
                    foreach($pages[$name]['links'] as $linkname)
473
                        $linkarray[] = $nametonumber[$linkname] + 1;
474
                else
475
                    $linkarray = $pages[$name]['links'];
476
                $linkstring = join('"; "', $linkarray );
477
478
                $c = count($pages[$name]['links']);
479
                $dot .= "        \"$nodename\" -> "
480
                     . ($c>1?'{':'')
481
                     . "\"$linkstring\";"
482
                     . ($c>1?'}':'')
483
                     . "\n";
484
            }
485
        }
486
        if ($colorby != 'none') {
487
            $dot .= "\n    subgraph cluster_legend {\n"
488
                 . "         node[fontname=$fontname,shape=box,width=0.4,height=0.4,fontsize=$fontsize];\n"
489
                 . "         fillcolor=lightgrey;\n"
490
                 . "         style=filled;\n"
491
                 . "         fontname=$fontname;\n"
492
                 . "         fontsize=$fontsize;\n"
493
                 . "         label=\"".gettext("Legend")."\";\n";
494
            $oldest= ceil($this->oldest / (24 * 3600));
495
            $max = 5;
496
            $legend = array();
497
            for($i = 0; $i < $max; $i++) {
498
                $time = floor($i / $max * $oldest);
499
                $name = '"' . $time .' '. _("days") .'"';
500
                $col = $this->getColor($i/$max);
501
                $dot .= sprintf('       %s [%scolor="#%02X%02X%02X"];',
502
                                $name, $fillstring, $col[0], $col[1], $col[2])
503
                    . "\n";
504
                $legend[] = $name;
505
            }
506
            $dot .= '        '. join(' -> ', $legend)
507
		. ";\n    }\n";
508
        }
509
510
        // {
511
        $dot .= "}\n";
512
        $this->source = $dot;
513
        // write a temp file
514
        $ok = fwrite($fp, $dot);
515
        $ok = fclose($fp) && $ok;  // close anyway
516
517
        return $ok;
518
    }
519
520
521
    /** 
522
     * static workaround on broken Cache or broken dot executable, 
523
     * called only if debug=static.
524
     *
525
     * @access private
526
     * @param  url      string  url pointing to the image part of the map
527
     * @param  map      string  &lt;area&gt; tags defining active
528
     *                          regions in the map
529
     * @param  dbi      WikiDB  database abstraction class
530
     * @param  argarray array   complete (!) arguments to produce 
531
     *                          image. It is not necessary to call 
532
     *                          WikiPlugin->getArgs anymore.
533
     * @param  request  Request ??? 
534
     * @return          string  html output
535
     */
536
    function embedImg($url,&$dbi,$argarray,&$request) {
537
        if (!VISUALWIKI_ALLOWOPTIONS)
538
            $argarray = $this->defaultarguments();
539
        $this->checkArguments($argarray);
540
        //extract($argarray);
541
        if ($argarray['help'])
542
            return array($this->helpImage(), ' '); // FIXME
543
        $this->createColors();
544
        $this->extract_wikipages($dbi, $argarray);
545
        list($imagehandle, $content['html']) = $this->invokeDot($argarray);
546
        // write to uploads and produce static url
547
        $file_dir = defined('PHPWIKI_DIR') ? 
548
            PHPWIKI_DIR . "/uploads" : "uploads";
549
        $upload_dir = SERVER_URL . ((substr(DATA_PATH,0,1)=='/') ? '' : "/") . DATA_PATH . '/uploads/';
550
        $tmpfile = tempnam($file_dir,"VisualWiki").".".$argarray['imgtype'];
551
        WikiPluginCached::writeImage($argarray['imgtype'], $imagehandle, $tmpfile);             
552
        ImageDestroy($imagehandle);
553
        return WikiPluginCached::embedMap(1,$upload_dir.basename($tmpfile),$content['html'],
0 ignored issues
show
Bug introduced by
The variable $content does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
554
                                          $dbi,$argarray,$request);
555
    }
556
557
    /**
558
     * Prepares some rainbow colors for the nodes of the graph
559
     * and stores them in an array which may be accessed with
560
     * <code>getColor</code>.
561
     */
562
    function createColors() {
563
        $predefcolors = array(
564
             array('red' => 255, 'green' =>   0, 'blue' =>   0),
565
             array('red' => 255, 'green' => 255, 'blue' =>   0),
566
             array('red' =>   0, 'green' => 255, 'blue' =>   0),
567
             array('red' =>   0, 'green' => 255, 'blue' => 255),
568
             array('red' =>   0, 'green' =>   0, 'blue' => 255),
569
             array('red' => 100, 'green' => 100, 'blue' => 100)
570
             );
571
572
        $steps = 2;
573
        $numberofcolors = count($predefcolors) * $steps;
574
575
        $promille = -1;
576
        foreach($predefcolors as $color) {
577
            if ($promille < 0) {
578
                $oldcolor = $color;
579
                $promille = 0;
580
                continue;
581
            }
582
            for ($i = 0; $i < $steps; $i++)
583
                $this->ColorTab[++$promille / $numberofcolors * 1000] = array(
584
                    floor(interpolate( $oldcolor['red'],   $color['red'],   $i/$steps )),
585
                    floor(interpolate( $oldcolor['green'], $color['green'], $i/$steps )),
586
                    floor(interpolate( $oldcolor['blue'],  $color['blue'],  $i/$steps ))
587
                );
588
            $oldcolor = $color;
589
        }
590
//echo"<pre>";  var_dump($this->ColorTab); echo "</pre>";
591
    }
592
593
    /**
594
     * Translates a value from 0.0 to 1.0 into rainbow color.
595
     * red -&gt; orange -&gt; green -&gt; blue -&gt; gray
596
     *
597
     * @param promille float value between 0.0 and 1.0
598
     * @return array(red,green,blue)
0 ignored issues
show
Documentation introduced by
The doc-type array(red,green,blue) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
599
     */
600
    function getColor($promille) {
601
        foreach( $this->ColorTab as $pro => $col ) {
602
            if ($promille*1000 < $pro)
603
                return $col;
604
        }
605
        $lastcol = end($this->ColorTab);
606
        return $lastcol;
607
    }
608
}
609
610
/**
611
 * Linear interpolates a value between two point a and b
612
 * at a value pos.
613
 * @return float  interpolated value
614
 */
615
function interpolate($a, $b, $pos) {
616
    return $a + ($b - $a) * $pos;
617
}
618
619
// $Log: VisualWiki.php,v $
620
// Revision 1.19  2005/10/12 06:19:31  rurban
621
// remove INCLUDED from EXCLUDED, includes override excludes.
622
//
623
// Revision 1.18  2004/12/17 16:49:52  rurban
624
// avoid Invalid username message on Sign In button click
625
//
626
// Revision 1.17  2004/10/14 19:19:34  rurban
627
// loadsave: check if the dumped file will be accessible from outside.
628
// and some other minor fixes. (cvsclient native not yet ready)
629
//
630
// Revision 1.16  2004/10/12 15:34:47  rurban
631
// redirect stderr to display the failing msg
632
//
633
// Revision 1.15  2004/09/08 13:38:00  rurban
634
// improve loadfile stability by using markup=2 as default for undefined markup-style.
635
// use more refs for huge objects.
636
// fix debug=static issue in WikiPluginCached
637
//
638
// Revision 1.14  2004/09/07 13:26:31  rurban
639
// new WikiPluginCached option debug=static and some more sf.net defaults for VisualWiki
640
//
641
// Revision 1.13  2004/09/06 12:13:00  rurban
642
// provide sf.net default dotbin
643
//
644
// Revision 1.12  2004/09/06 12:08:50  rurban
645
// memory_limit on unix workaround
646
// VisualWiki: default autosize image
647
//
648
// Revision 1.11  2004/09/06 10:10:27  rurban
649
// fixed syntax error
650
//
651
// Revision 1.10  2004/06/19 10:06:38  rurban
652
// Moved lib/plugincache-config.php to config/*.ini
653
// use PLUGIN_CACHED_* constants instead of global $CacheParams
654
//
655
// Revision 1.9  2004/06/03 09:40:57  rurban
656
// WikiPluginCache improvements
657
//
658
// Revision 1.8  2004/01/26 09:18:00  rurban
659
// * changed stored pref representation as before.
660
//   the array of objects is 1) bigger and 2)
661
//   less portable. If we would import packed pref
662
//   objects and the object definition was changed, PHP would fail.
663
//   This doesn't happen with an simple array of non-default values.
664
// * use $prefs->retrieve and $prefs->store methods, where retrieve
665
//   understands the interim format of array of objects also.
666
// * simplified $prefs->get() and fixed $prefs->set()
667
// * added $user->_userid and class '_WikiUser' portability functions
668
// * fixed $user object ->_level upgrading, mostly using sessions.
669
//   this fixes yesterdays problems with loosing authorization level.
670
// * fixed WikiUserNew::checkPass to return the _level
671
// * fixed WikiUserNew::isSignedIn
672
// * added explodePageList to class PageList, support sortby arg
673
// * fixed UserPreferences for WikiUserNew
674
// * fixed WikiPlugin for empty defaults array
675
// * UnfoldSubpages: added pagename arg, renamed pages arg,
676
//   removed sort arg, support sortby arg
677
//
678
// Revision 1.7  2003/03/03 13:57:31  carstenklapp
679
// Added fontpath (see PhpWiki:VisualWiki), tries to be smart about which OS.
680
// (This plugin still doesn't work for me on OS X, but at least image files
681
// are actually being created now in '/tmp/cache'.)
682
//
683
// Revision 1.6  2003/01/18 22:11:45  carstenklapp
684
// Code cleanup:
685
// Reformatting & tabs to spaces;
686
// Added copyleft, getVersion, getDescription, rcs_id.
687
//
688
689
// Local Variables:
690
// mode: php
691
// tab-width: 8
692
// c-basic-offset: 4
693
// c-hanging-comment-ender-p: nil
694
// indent-tabs-mode: nil
695
// End:
696
?>
697