]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/stdlib.php
Strip 'mailto:' prefix from linktext. Stub for filetype icon in IconForLink.
[SourceForge/phpwiki.git] / lib / stdlib.php
1 <?php rcs_id('$Id: stdlib.php,v 1.107 2002-02-08 17:49:37 carstenklapp Exp $');
2
3 /*
4   Standard functions for Wiki functionality
5     WikiURL($pagename, $args, $get_abs_url)
6     IconForLink($protocol_or_url)
7     LinkURL($url, $linktext)
8     LinkImage($url, $alt)
9
10     MakeWikiForm ($pagename, $args, $class, $button_text)
11     SplitQueryArgs ($query_args)
12     LinkPhpwikiURL($url, $text)
13     LinkBracketLink($bracketlink)
14     ExtractWikiPageLinks($content)
15     ConvertOldMarkup($content)
16     
17     class Stack { push($item), pop(), cnt(), top() }
18
19     split_pagename ($page)
20     NoSuchRevision ($request, $page, $version)
21     TimezoneOffset ($time, $no_colon)
22     Iso8601DateTime ($time)
23     Rfc2822DateTime ($time)
24     CTime ($time)
25     __printf ($fmt)
26     __sprintf ($fmt)
27     __vsprintf ($fmt, $args)
28     better_srand($seed = '')
29
30   function: LinkInterWikiLink($link, $linktext)
31   moved to: lib/interwiki.php
32   function: linkExistingWikiWord($wikiword, $linktext, $version)
33   moved to: lib/Theme.php
34   function: LinkUnknownWikiWord($wikiword, $linktext)
35   moved to: lib/Theme.php
36   function: UpdateRecentChanges($dbi, $pagename, $isnewpage) 
37   gone see: lib/plugin/RecentChanges.php
38 */
39
40
41 function WikiURL($pagename, $args = '', $get_abs_url = false) {
42     if (is_object($pagename)) {
43         if (isa($pagename, 'WikiDB_Page')) {
44             $pagename = $pagename->getName();
45         }
46         elseif (isa($pagename, 'WikiDB_PageRevision')) {
47             $page = $pagename->getPage();
48             $args['version'] = $pagename->getVersion();
49             $pagename = $page->getName();
50         }
51     }
52     
53     if (is_array($args)) {
54         $enc_args = array();
55         foreach  ($args as $key => $val) {
56             $enc_args[] = urlencode($key) . '=' . urlencode($val);
57         }
58         $args = join('&', $enc_args);
59     }
60
61     if (USE_PATH_INFO) {
62         $url = $get_abs_url ? SERVER_URL . VIRTUAL_PATH . "/" : "";
63         $url .= preg_replace('/%2f/i', '/', rawurlencode($pagename));
64         if ($args)
65             $url .= "?$args";
66     }
67     else {
68         $url = $get_abs_url ? SERVER_URL . SCRIPT_NAME : basename(SCRIPT_NAME);
69         $url .= "?pagename=" . rawurlencode($pagename);
70         if ($args)
71             $url .= "&$args";
72     }
73     return $url;
74 }
75
76 function IconForLink($protocol_or_url) {
77     global $Theme;
78     if ($filename_suffix = false) {
79         // display apache style icon for file type instead of protocol icon
80         // - archive: unix:gz,bz2,tgz,tar,z; mac:dmg,dmgz,bin,img,cpt,sit; pc:zip;
81         // - document: html, htm, text, txt, rtf, pdf, doc
82         // - non-inlined image: jpg,jpeg,png,gif,tiff,tif,swf,pict,psd,eps,ps
83         // - audio: mp3,mp2,aiff,aif,au
84         // - multimedia: mpeg,mpg,mov,qt
85     } else {
86         list ($proto) = explode(':', $protocol_or_url, 2);
87         $src = $Theme->getLinkIconURL($proto);
88         if ($src)
89             return HTML::img(array('src' => $src, 'alt' => $proto, 'class' => 'linkicon', 'border' => 0));
90         else
91             return false;
92     }
93 }
94
95 function LinkURL($url, $linktext = '') {
96     // FIXME: Is this needed (or sufficient?)
97     if(ereg("[<>\"]", $url)) {
98         $link = HTML::strong(HTML::u(array('class' => 'baduri'),
99                                      _("BAD URL -- remove all of <, >, \"")));
100     }
101     else {
102         $link = HTML::a(array('href' => $url/*, 'type' => 'application/x-gzip'*/),
103                                             // do any browsers support use of <a href= type=?/?
104                                             // (instead of wiki creating an IconForLink for the doc type?)
105                         IconForLink($url),
106                         $linktext ? $linktext : str_replace("mailto:", "", $url));
107     }
108     $link->setAttr('class', $linktext ? 'namedurl' : 'rawurl');
109     return $link;
110 }
111
112
113 function LinkImage($url, $alt = '[External Image]') {
114     // FIXME: Is this needed (or sufficient?)
115     if(ereg("[<>\"]", $url)) {
116         $link = HTML::strong(HTML::u(array('class' => 'baduri'),
117                                      _("BAD URL -- remove all of <, >, \"")));
118     }
119     else {
120         $link = HTML::img(array('src' => $url, 'alt' => $alt));
121     }
122     $link->setAttr('class', 'inlineimage');
123     return $link;
124 }
125
126
127
128 class Stack {
129     var $items = array();
130     var $size = 0;
131     
132     function push($item) {
133         $this->items[$this->size] = $item;
134         $this->size++;
135         return true;
136     }  
137     
138     function pop() {
139         if ($this->size == 0) {
140             return false; // stack is empty
141         }  
142         $this->size--;
143         return $this->items[$this->size];
144     }  
145     
146     function cnt() {
147         return $this->size;
148     }  
149     
150     function top() {
151         if($this->size)
152             return $this->items[$this->size - 1];
153         else
154             return '';
155     }
156     
157 }  
158 // end class definition
159
160
161 function MakeWikiForm ($pagename, $args, $class, $button_text = '') {
162     // HACK: so as to not completely break old PhpWikiAdministration pages.
163     trigger_error("MagicPhpWikiURL forms are no longer supported.  "
164                   . "Use the WikiFormPlugin instead.", E_USER_NOTICE);
165
166     global $request;
167     $loader = new WikiPluginLoader;
168     @$action = (string)$args['action'];
169     return $loader->expandPI("<?plugin WikiForm action=$action ?>", $request);
170 }
171
172 function SplitQueryArgs ($query_args = '') 
173 {
174     $split_args = split('&', $query_args);
175     $args = array();
176     while (list($key, $val) = each($split_args))
177         if (preg_match('/^ ([^=]+) =? (.*) /x', $val, $m))
178             $args[$m[1]] = $m[2];
179     return $args;
180 }
181
182 function LinkPhpwikiURL($url, $text = '') {
183     $args = array();
184     
185     if (!preg_match('/^ phpwiki: ([^?]*) [?]? (.*) $/x', $url, $m)) {
186         return HTML::strong(array('class' => 'rawurl'),
187                             HTML::u(array('class' => 'baduri'),
188                                     _("BAD phpwiki: URL")));
189     }
190
191     if ($m[1])
192         $pagename = urldecode($m[1]);
193     $qargs = $m[2];
194     
195     if (empty($pagename) &&
196         preg_match('/^(diff|edit|links|info)=([^&]+)$/', $qargs, $m)) {
197         // Convert old style links (to not break diff links in
198         // RecentChanges).
199         $pagename = urldecode($m[2]);
200         $args = array("action" => $m[1]);
201     }
202     else {
203         $args = SplitQueryArgs($qargs);
204     }
205
206     if (empty($pagename))
207         $pagename = $GLOBALS['request']->getArg('pagename');
208
209     if (isset($args['action']) && $args['action'] == 'browse')
210         unset($args['action']);
211     
212     /*FIXME:
213       if (empty($args['action']))
214       $class = 'wikilink';
215       else if (is_safe_action($args['action']))
216       $class = 'wikiaction';
217     */
218     if (empty($args['action']) || is_safe_action($args['action']))
219         $class = 'wikiaction';
220     else {
221         // Don't allow administrative links on unlocked pages.
222         $page = $GLOBALS['request']->getPage();
223         if (!$page->get('locked'))
224             return HTML::span(array('class' => 'wikiunsafe'),
225                               HTML::u(_("Lock page to enable link")));
226         $class = 'wikiadmin';
227     }
228     
229     // FIXME: ug, don't like this
230     if (preg_match('/=\d*\(/', $qargs))
231         return MakeWikiForm($pagename, $args, $class, $text);
232     if (!$text)
233         $text = HTML::span(array('class' => 'rawurl'), $url);
234
235     return HTML::a(array('href'  => WikiURL($pagename, $args),
236                          'class' => $class),
237                    $text);
238 }
239
240 function LinkBracketLink($bracketlink) {
241     global $request, $AllowedProtocols, $InlineImages;
242
243     include_once("lib/interwiki.php");
244     $intermap = InterWikiMap::GetMap($request);
245     
246     // $bracketlink will start and end with brackets; in between will
247     // be either a page name, a URL or both separated by a pipe.
248     
249     // strip brackets and leading space
250     preg_match("/(\[\s*)(.+?)(\s*\])/", $bracketlink, $match);
251     // match the contents 
252     preg_match("/([^|]+)(\|)?([^|]+)?/", $match[2], $matches);
253     
254     if (isset($matches[3])) {
255         // named link of the form  "[some link name | http://blippy.com/]"
256         $URL = trim($matches[3]);
257         $linkname = trim($matches[1]);
258     } else {
259         // unnamed link of the form "[http://blippy.com/] or [wiki page]"
260         $URL = trim($matches[1]);
261         $linkname = false;
262     }
263
264     $dbi = $request->getDbh();
265     if ($dbi->isWikiPage($URL))
266         return WikiLink($URL, 'known', $linkname);
267     elseif (preg_match("#^($AllowedProtocols):#", $URL)) {
268         // if it's an image, embed it; otherwise, it's a regular link
269         if (preg_match("/($InlineImages)$/i", $URL))
270             return LinkImage($URL, $linkname);
271         else
272             return LinkURL($URL, $linkname);
273     }
274     elseif (preg_match("/^phpwiki:/", $URL))
275         return LinkPhpwikiURL($URL, $linkname);
276     elseif (preg_match("/^" . $intermap->getRegexp() . ":/", $URL))
277         return $intermap->link($URL, $linkname);
278     else {
279         return WikiLink($URL, 'unknown', $linkname);
280     }
281     
282 }
283
284 /* FIXME: this should be done by the transform code */
285 function ExtractWikiPageLinks($content) {
286     global $WikiNameRegexp;
287     
288     if (is_string($content))
289         $content = explode("\n", $content);
290     
291     $wikilinks = array();
292     foreach ($content as $line) {
293         // remove plugin code
294         $line = preg_replace('/<\?plugin\s+\w.*?\?>/', '', $line);
295         // remove escaped '['
296         $line = str_replace('[[', ' ', $line);
297         // remove footnotes
298         $line = preg_replace('/[\d+]/', ' ', $line);
299         
300         // bracket links (only type wiki-* is of interest)
301         $numBracketLinks = preg_match_all("/\[\s*([^\]|]+\|)?\s*(\S.*?)\s*\]/",
302                                           $line, $brktlinks);
303         for ($i = 0; $i < $numBracketLinks; $i++) {
304             $link = LinkBracketLink($brktlinks[0][$i]);
305             if (preg_match('/^(named-)?wiki(unknown)?$/', $link->getAttr('class')))
306                 $wikilinks[$brktlinks[2][$i]] = 1;
307             
308             $brktlink = preg_quote($brktlinks[0][$i]);
309             $line = preg_replace("|$brktlink|", '', $line);
310         }
311         
312         // BumpyText old-style wiki links
313         if (preg_match_all("/!?$WikiNameRegexp/", $line, $link)) {
314             for ($i = 0; isset($link[0][$i]); $i++) {
315                 if($link[0][$i][0] <> '!')
316                     $wikilinks[$link[0][$i]] = 1;
317             }
318         }
319     }
320     return array_keys($wikilinks);
321 }      
322
323 /**
324  * Convert old page markup to new-style markup.
325  *
326  * @param $text string Old-style wiki markup.
327  *
328  * @param $just_links bool Only convert old-style links.
329  * (Really this only converts escaped old-style links.)
330  *
331  * @return string New-style wiki markup.
332  *
333  * @bugs FIXME: footnotes and old-style tables are known to be broken.
334  */
335 function ConvertOldMarkup ($text, $just_links = false) {
336
337     static $orig, $repl, $link_orig, $link_repl;
338
339     if (empty($orig)) {
340         /*****************************************************************
341          * Conversions for inline markup:
342          */
343
344         // escape tilde's
345         $orig[] = '/~/';
346         $repl[] = '~~';
347
348         // escape escaped brackets
349         $orig[] = '/\[\[/';
350         $repl[] = '~[';
351
352         // change ! escapes to ~'s.
353         global $AllowedProtocols, $WikiNameRegexp, $request;
354         include_once('lib/interwiki.php');
355         $map = InterWikiMap::GetMap($request);
356         $bang_esc[] = "(?:$AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]";
357         $bang_esc[] = $map->getRegexp() . ":[^\\s.,;?()]+"; // FIXME: is this really needed?
358         $bang_esc[] = $WikiNameRegexp;
359         $orig[] = '/!((?:' . join(')|(', $bang_esc) . '))/';
360         $repl[] = '~\\1';
361
362
363         $link_orig = $orig;
364         $link_repl = $repl;
365         
366         /*****************************************************************
367          * Conversions for block markup
368          */
369         // convert indented blocks to <pre></pre>.
370         $orig[] = '/^[ \t]+\S.*\n(?:(?:\s*\n)?^[ \t]+\S.*\n)*/m';
371         $repl[] = "<pre>\n\\0</pre>\n";
372
373         // convert lists
374         $orig[] = '/^([#*;]*)([*#]|;.*?:) */me';
375         $repl[] = "_ConvertOldListMarkup('\\1', '\\2')";
376     }
377     
378
379     if ($just_links)
380         return preg_replace($link_orig, $link_repl, $text);
381     else
382         return preg_replace($orig, $repl, $text);
383 }
384
385 function _ConvertOldListMarkup ($indent, $bullet) {
386     $indent = str_repeat('     ', strlen($indent));
387     if ($bullet[0] == ';') {
388         $term = ltrim(substr($bullet, 1));
389         return $indent . $term . "\n" . $indent . '     ';
390     }
391     else
392         return $indent . $bullet . ' ';
393 }
394
395
396
397 /**
398  * Split WikiWords in page names.
399  *
400  * It has been deemed useful to split WikiWords (into "Wiki Words") in
401  * places like page titles. This is rumored to help search engines
402  * quite a bit.
403  *
404  * @param $page string The page name.
405  *
406  * @return string The split name.
407  */
408 function split_pagename ($page) {
409     
410     if (preg_match("/\s/", $page))
411         return $page;           // Already split --- don't split any more.
412     
413     // FIXME: this algorithm is Anglo-centric.
414     static $RE;
415     if (!isset($RE)) {
416         // This mess splits between a lower-case letter followed by
417         // either an upper-case or a numeral; except that it wont
418         // split the prefixes 'Mc', 'De', or 'Di' off of their tails.
419         $RE[] = '/([[:lower:]])((?<!Mc|De|Di)[[:upper:]]|\d)/';
420         // This the single-letter words 'I' and 'A' from any following
421         // capitalized words.
422         $RE[] = '/(?: |^)([AI])([[:upper:]][[:lower:]])/';
423         // Split numerals from following letters.
424         $RE[] = '/(\d)([[:alpha:]])/';
425         
426         foreach ($RE as $key => $val)
427             $RE[$key] = pcre_fix_posix_classes($val);
428     }
429     
430     foreach ($RE as $regexp)
431         $page = preg_replace($regexp, '\\1 \\2', $page);
432     return $page;
433 }
434
435 function NoSuchRevision (&$request, $page, $version) {
436     $html = HTML(HTML::h2(_("Revision Not Found")),
437                  HTML::p(fmt("I'm sorry.  Version %d of %s is not in my database.",
438                              $version, WikiLink($page, 'auto'))));
439     include_once('lib/Template.php');
440     GeneratePage($html, _("Bad Version"), $page->getCurrentRevision());
441     $request->finish();
442 }
443
444
445 /**
446  * Get time offset for local time zone.
447  *
448  * @param $time time_t Get offset for this time. Default: now.
449  * @param $no_colon boolean Don't put colon between hours and minutes.
450  * @return string Offset as a string in the format +HH:MM.
451  */
452 function TimezoneOffset ($time = false, $no_colon = false) {
453     if ($time === false)
454         $time = time();
455     $secs = date('Z', $time);
456     return seconds2zoneOffset($secs, $no_colon);
457 }
458
459 /**
460  * Format a timezone offset from seconds to ±HH:MM format.
461  */
462 function seconds2zoneOffset ($secs, $no_colon = false) {
463     if ($secs < 0) {
464         $sign = '-';
465         $secs = -$secs;
466     }
467     else {
468         $sign = '+';
469     }
470     $colon = $no_colon ? '' : ':';
471     $mins = intval(($secs + 30) / 60);
472     return sprintf("%s%02d%s%02d",
473                    $sign, $mins / 60, $colon, $mins % 60);
474 }
475
476 /**
477  * Returns the user's offset time in seconds.
478  */
479 function PrefTimezoneOffset () {
480     global $request;
481     $userOffset = $request->getPref('timeOffset');
482     $offset_secs = 60 * (floor($userOffset/100)*60 + substr($userOffset,-2));
483     return $offset_secs;
484 }
485
486 function istoday($time_secs) {
487     return date("Ymd", time()) == date("Ymd", $time_secs);
488 }
489 function isyesterday($time_secs) {
490     return date("Ymd", time()-60*60*24) == date("Ymd", $time_secs);
491 }
492
493 /**
494  * Format time in ISO-8601 format.
495  *
496  * @param $time time_t Time.  Default: now.
497  * @return string Date and time in ISO-8601 format.
498  */
499 function Iso8601DateTime ($time = false) {
500     if ($time === false)
501         $time = time();
502     $tzoff = TimezoneOffset($time);
503     $date  = date('Y-m-d', $time);
504     $time  = date('H:i:s', $time);
505     return $date . 'T' . $time . $tzoff;
506 }
507
508 /**
509  * Format time in RFC-2822 format.
510  *
511  * @param $time time_t Time.  Default: now.
512  * @return string Date and time in RFC-2822 format.
513  */
514 function Rfc2822DateTime ($time = false) {
515     if ($time === false)
516         $time = time();
517     return date('D, j M Y H:i:s ', $time) . TimezoneOffset($time, 'no colon');
518 }
519
520 /**
521  * Format time to standard 'ctime' format.
522  *
523  * @param $time time_t Time.  Default: now.
524  * @return string Date and time.
525  */
526 function CTime ($time = false)
527 {
528     if ($time === false)
529         $time = time();
530     return date("D M j H:i:s Y", $time);
531 }
532
533
534
535 /**
536  * Internationalized printf.
537  *
538  * This is essentially the same as PHP's built-in printf
539  * with the following exceptions:
540  * <ol>
541  * <li> It passes the format string through gettext().
542  * <li> It supports the argument reordering extensions.
543  * </ol>
544  *
545  * Example:
546  *
547  * In php code, use:
548  * <pre>
549  *    __printf("Differences between versions %s and %s of %s",
550  *             $new_link, $old_link, $page_link);
551  * </pre>
552  *
553  * Then in locale/po/de.po, one can reorder the printf arguments:
554  *
555  * <pre>
556  *    msgid "Differences between %s and %s of %s."
557  *    msgstr "Der Unterschiedsergebnis von %3$s, zwischen %1$s und %2$s."
558  * </pre>
559  *
560  * (Note that while PHP tries to expand $vars within double-quotes,
561  * the values in msgstr undergo no such expansion, so the '$'s
562  * okay...)
563  *
564  * One shouldn't use reordered arguments in the default format string.
565  * Backslashes in the default string would be necessary to escape the
566  * '$'s, and they'll cause all kinds of trouble....
567  */ 
568 function __printf ($fmt) {
569     $args = func_get_args();
570     array_shift($args);
571     echo __vsprintf($fmt, $args);
572 }
573
574 /**
575  * Internationalized sprintf.
576  *
577  * This is essentially the same as PHP's built-in printf with the
578  * following exceptions:
579  *
580  * <ol>
581  * <li> It passes the format string through gettext().
582  * <li> It supports the argument reordering extensions.
583  * </ol>
584  *
585  * @see __printf
586  */ 
587 function __sprintf ($fmt) {
588     $args = func_get_args();
589     array_shift($args);
590     return __vsprintf($fmt, $args);
591 }
592
593 /**
594  * Internationalized vsprintf.
595  *
596  * This is essentially the same as PHP's built-in printf with the
597  * following exceptions:
598  *
599  * <ol>
600  * <li> It passes the format string through gettext().
601  * <li> It supports the argument reordering extensions.
602  * </ol>
603  *
604  * @see __printf
605  */ 
606 function __vsprintf ($fmt, $args) {
607     $fmt = gettext($fmt);
608     // PHP's sprintf doesn't support variable with specifiers,
609     // like sprintf("%*s", 10, "x"); --- so we won't either.
610     
611     if (preg_match_all('/(?<!%)%(\d+)\$/x', $fmt, $m)) {
612         // Format string has '%2$s' style argument reordering.
613         // PHP doesn't support this.
614         if (preg_match('/(?<!%)%[- ]?\d*[^- \d$]/x', $fmt))
615             // literal variable name substitution only to keep locale
616             // strings uncluttered
617             trigger_error(sprintf(_("Can't mix '%s' with '%s' type format strings"),
618                                   '%1\$s','%s'), E_USER_WARNING); //php+locale error
619         
620         $fmt = preg_replace('/(?<!%)%\d+\$/x', '%', $fmt);
621         $newargs = array();
622         
623         // Reorder arguments appropriately.
624         foreach($m[1] as $argnum) {
625             if ($argnum < 1 || $argnum > count($args))
626                 trigger_error(sprintf(_("%s: argument index out of range"), 
627                                       $argnum), E_USER_WARNING);
628             $newargs[] = $args[$argnum - 1];
629         }
630         $args = $newargs;
631     }
632     
633     // Not all PHP's have vsprintf, so...
634     array_unshift($args, $fmt);
635     return call_user_func_array('sprintf', $args);
636 }
637
638
639 class fileSet {
640     /**
641      * Build an array in $this->_fileList of files from $dirname.
642      * Subdirectories are not traversed.
643      *
644      * (This was a function LoadDir in lib/loadsave.php)
645      * See also http://www.php.net/manual/en/function.readdir.php
646      */
647     function getFiles() {
648         return $this->_fileList;
649     }
650
651     function _filenameSelector($filename) {
652         // Default selects all filenames, override as needed.
653         return true;
654     }
655
656     function fileSet($directory) {
657         $this->_fileList = array();
658
659         if (empty($directory)) {
660             trigger_error(sprintf(_("%s is empty."), 'directoryname'),
661                           E_USER_NOTICE);
662             return; // early return
663         }
664
665         @ $dir_handle = opendir($dir=$directory);
666         if (empty($dir_handle)) {
667             trigger_error(sprintf(_("Unable to open directory '%s' for reading"),
668                                   $dir), E_USER_NOTICE);
669             return; // early return
670         }
671
672         while ($filename = readdir($dir_handle)) {
673             if ($filename[0] == '.' || filetype("$dir/$filename") != 'file')
674                 continue;
675             if ($this->_filenameSelector($filename)) {
676                 array_push($this->_fileList, "$filename");
677                 //trigger_error(sprintf(_("found file %s"), $filename),
678                 //                      E_USER_NOTICE); //debugging
679             }
680         }
681         closedir($dir_handle);
682     }
683 };
684
685
686 // Class introspections
687
688 /** Determine whether object is of a specified type.
689  *
690  * @param $object object An object.
691  * @param $class string Class name.
692  * @return bool True iff $object is a $class
693  * or a sub-type of $class. 
694  */
695 function isa ($object, $class) 
696 {
697     $lclass = strtolower($class);
698
699     return is_object($object)
700         && ( get_class($object) == strtolower($lclass)
701              || is_subclass_of($object, $lclass) );
702 }
703
704 /** Determine whether (possible) object has method.
705  *
706  * @param $object mixed Object
707  * @param $method string Method name
708  * @return bool True iff $object is an object with has method $method.
709  */
710 function can ($object, $method) 
711 {
712     return is_object($object) && method_exists($object, strtolower($method));
713 }
714
715 /**
716  * Seed the random number generator.
717  *
718  * better_srand() ensures the randomizer is seeded only once.
719  * 
720  * How random do you want it? See:
721  * http://www.php.net/manual/en/function.srand.php
722  * http://www.php.net/manual/en/function.mt-srand.php
723  */
724 function better_srand($seed = '') {
725     static $wascalled = FALSE;
726     if (!$wascalled) {
727         $seed = $seed === '' ? (double) microtime() * 1000000 : $seed;
728         srand($seed);
729         $wascalled = TRUE;
730         //trigger_error("new random seed", E_USER_NOTICE); //debugging
731     }
732 }
733
734 // (c-file-style: "gnu")
735 // Local Variables:
736 // mode: php
737 // tab-width: 8
738 // c-basic-offset: 4
739 // c-hanging-comment-ender-p: nil
740 // indent-tabs-mode: nil
741 // End:   
742 ?>