]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/stdlib.php
Fix-up/restore <base href=""> usage.
[SourceForge/phpwiki.git] / lib / stdlib.php
1 <?php rcs_id('$Id: stdlib.php,v 1.79 2002-01-17 23:14:22 dairiki Exp $');
2
3 /*
4   Standard functions for Wiki functionality
5     WikiURL($pagename, $args, $get_abs_url)
6     StartTag($tag, $args)
7     Element($tag, $args, $content)
8     QElement($tag, $args, $content)
9     IconForLink($protocol_or_url)
10     LinkURL($url, $linktext)
11     LinkWikiWord($wikiword, $linktext)
12     LinkExistingWikiWord($wikiword, $linktext)
13     LinkUnknownWikiWord($wikiword, $linktext)
14     LinkImage($url, $alt)
15     class Stack { push($item), pop(), cnt(), top() }
16     CookSpaces($pagearray)
17     MakeWikiForm ($pagename, $args, $class, $button_text)
18     SplitQueryArgs ($query_args)
19     LinkPhpwikiURL($url, $text)
20     ParseAndLink($bracketlink)
21     ExtractWikiPageLinks($content)
22     LinkRelatedPages($dbi, $pagename)
23     split_pagename ($page)
24     NoSuchRevision ($page, $version)
25     TimezoneOffset ($time, $no_colon)
26     Iso8601DateTime ($time)
27     Rfc2822DateTime ($time)
28     CTime ($time)
29     __printf ($fmt)
30     __sprintf ($fmt)
31     __vsprintf ($fmt, $args)
32
33   function moved => LinkInterWikiLink($link, $linktext)
34     (see /lib/interwiki.php)
35   function gone  => UpdateRecentChanges($dbi, $pagename, $isnewpage) 
36     (see /lib/plugin/RecentChanges.php)
37
38 */
39
40
41 function WikiURL($pagename, $args = '', $get_abs_url = false) {
42     if (is_array($args)) {
43         $enc_args = array();
44         foreach  ($args as $key => $val) {
45             $enc_args[] = urlencode($key) . '=' . urlencode($val);
46         }
47         $args = join('&', $enc_args);
48     }
49     
50     if (USE_PATH_INFO) {
51         $url = $get_abs_url ? SERVER_URL . VIRTUAL_PATH . "/" : "";
52         $url .= rawurlencode($pagename);
53         if ($args)
54             $url .= "?$args";
55     }
56     else {
57         $url = $get_abs_url ? SERVER_URL . SCRIPT_NAME : basename(SCRIPT_NAME);
58         $url .= "?pagename=" . rawurlencode($pagename);
59         if ($args)
60             $url .= "&$args";
61     }
62     return $url;
63 }
64
65 define('NO_END_TAG_PAT',
66        '/^' . join('|', array('area', 'base', 'basefont',
67                               'br', 'col', 'frame',
68                               'hr', 'img', 'input',
69                               'isindex', 'link', 'meta',
70                               'param')) . '$/i');
71
72 function StartTag($tag, $args = '') {
73     $s = "<$tag";
74     if (is_array($args)) {
75         while (list($key, $val) = each($args))
76             {
77                 if (is_string($val) || is_numeric($val))
78                     $s .= sprintf(' %s="%s"', $key, htmlspecialchars($val));
79                 else if ($val)
80                     $s .= " $key=\"$key\"";
81             }
82     }
83     return "$s>";
84 }
85
86
87 function Element($tag, $args = '', $content = '') {
88     $html = "<$tag";
89     if (!is_array($args)) {
90         $content = $args;
91         $args = false;
92     }
93     $html = StartTag($tag, $args);
94     if (preg_match(NO_END_TAG_PAT, $tag)) {
95         assert(! $content);
96         return preg_replace('/>$/', " />", $html);
97     } else {
98         $html .= $content;
99         $html .= "</$tag>";//FIXME: newline might not always be desired.
100     }
101     return $html;
102 }
103
104 function QElement($tag, $args = '', $content = '')
105 {
106     if (is_array($args))
107         return Element($tag, $args, htmlspecialchars($content));
108     else {
109         $content = $args;
110         return Element($tag, htmlspecialchars($content));
111     }
112 }
113
114 function IconForLink($protocol_or_url) {
115     global $Theme;
116
117     list ($proto) = explode(':', $protocol_or_url, 2);
118     $src = $Theme->getLinkIconURL($proto);
119     if (empty($src))
120         return '';
121     
122     return Element('img', array('src'   => $src,
123                                 'alt'   => $proto,
124                                 'class' => 'linkicon'));
125 }
126
127
128 function LinkURL($url, $linktext = '') {
129     // FIXME: Is this needed (or sufficient?)
130     if(ereg("[<>\"]", $url)) {
131         return Element('strong',
132                        QElement('u', array('class' => 'baduri'),
133                                 _("BAD URL -- remove all of <, >, \"")));
134     }
135     
136     $attr['href'] = $url;
137     
138     if (empty($linktext)) {
139         $linktext = $url;
140         $attr['class'] = 'rawurl';
141     } else
142         $attr['class'] = 'namedurl';
143     
144     return Element('a', $attr,
145                    IconForLink($url) . htmlspecialchars($linktext));
146 }
147
148 function LinkWikiWord($wikiword, $linktext = '', $version = false) {
149     global $dbi;
150     if ($dbi->isWikiPage($wikiword))
151         return LinkExistingWikiWord($wikiword, $linktext);
152     else
153         return LinkUnknownWikiWord($wikiword, $linktext);
154 }
155
156 function LinkExistingWikiWord($wikiword, $linktext = '', $version = false) {
157     if (empty($linktext)) {
158         $linktext = $wikiword;
159         if (defined("autosplit_wikiwords"))
160             $linktext = split_pagename($linktext);
161         $class = 'wiki';
162     }
163     else
164         $class = 'named-wiki';
165
166     $attr = array();
167     if ($version !== false)
168         $attr['version'] = $version;
169
170     return QElement('a', array('href'  => WikiURL($wikiword, $attr),
171                                'class' => $class),
172                     $linktext);
173 }
174
175 function LinkUnknownWikiWord($wikiword, $linktext = '', $version = false) {
176     if (empty($linktext)) {
177         $linktext = $wikiword;
178         if (defined("autosplit_wikiwords"))
179             $linktext=split_pagename($linktext);
180         $class = 'wikiunknown';
181     } else
182         $class = 'named-wikiunknown';
183     
184     $attr = array('action' => 'edit');
185     if ($version !== false)
186         $attr['version'] = $version;
187
188     $qmark = QElement('a', array('href' => WikiURL($wikiword, $attr)),
189                       '?');
190     $text = QElement('u', $linktext);
191
192     if (defined('WIKIMARK_AFTER') && WIKIMARK_AFTER)
193         $text .= $qmark;
194     else 
195         $text = $qmark . $text;
196     
197     return Element('span', array('class' => $class), $text);
198 }
199
200 function LinkImage($url, $alt = '[External Image]') {
201     // FIXME: Is this needed (or sufficient?)
202     //  As long as the src in htmlspecialchars()ed I think it's safe.
203     if(ereg("[<>\"]", $url)) {
204         return Element('strong',
205                        QElement('u', array('class' => 'baduri'),
206                                 _("BAD URL -- remove all of <, >, \"")));
207     }
208     return Element('img', array('src' => $url, 'alt' => $alt));
209 }
210
211 // converts spaces to tabs
212 function CookSpaces($pagearray) {
213     return preg_replace("/ {3,8}/", "\t", $pagearray);
214 }
215
216
217 class Stack {
218     var $items = array();
219     var $size = 0;
220     
221     function push($item) {
222         $this->items[$this->size] = $item;
223         $this->size++;
224         return true;
225     }  
226     
227     function pop() {
228         if ($this->size == 0) {
229             return false; // stack is empty
230         }  
231         $this->size--;
232         return $this->items[$this->size];
233     }  
234     
235     function cnt() {
236         return $this->size;
237     }  
238     
239     function top() {
240         if($this->size)
241             return $this->items[$this->size - 1];
242         else
243             return '';
244     }
245     
246 }  
247 // end class definition
248
249
250 function MakeWikiForm ($pagename, $args, $class, $button_text = '') {
251     $formargs['action'] = USE_PATH_INFO ? WikiURL($pagename) : SCRIPT_NAME;
252     $formargs['method'] = 'get';
253     $formargs['class']  = $class;
254     
255     $contents = '';
256     $input_seen = 0;
257     
258     while (list($key, $val) = each($args)) {
259         $a = array('name' => $key, 'value' => $val, 'type' => 'hidden');
260         
261         if (preg_match('/^ (\d*) \( (.*) \) ((upload)?) $/xi', $val, $m)) {
262             $input_seen++;
263             $a['type'] = 'text';
264             $a['size'] = $m[1] ? $m[1] : 30;
265             $a['value'] = $m[2];
266             if ($m[3])
267                 {
268                     $a['type'] = 'file';
269                     $formargs['enctype'] = 'multipart/form-data';
270                     $contents .= Element('input',
271                                          array('name'  => 'MAX_FILE_SIZE',
272                                                'value' =>  MAX_UPLOAD_SIZE,
273                                                'type'  => 'hidden'));
274                     $formargs['method'] = 'post';
275                 }
276         }
277         
278         $contents .= Element('input', $a);
279     }
280     
281     $row = Element('td', $contents);
282     
283     if (!empty($button_text)) {
284         $row .= Element('td',
285                         Element('input', array('type'  => 'submit',
286                                                'class' => 'button',
287                                                'value' => $button_text)));
288     }
289     
290     return Element('form', $formargs,
291                    Element('table', array('cellspacing' => 0,
292                                           'cellpadding' => 2,
293                                           'border'      => 0),
294                            Element('tr', $row)));
295 }
296
297 function SplitQueryArgs ($query_args = '') 
298 {
299     $split_args = split('&', $query_args);
300     $args = array();
301     while (list($key, $val) = each($split_args))
302         if (preg_match('/^ ([^=]+) =? (.*) /x', $val, $m))
303             $args[$m[1]] = $m[2];
304     return $args;
305 }
306
307 function LinkPhpwikiURL($url, $text = '') {
308     $args = array();
309     
310     if (!preg_match('/^ phpwiki: ([^?]*) [?]? (.*) $/x', $url, $m))
311         return Element('strong',
312                        QElement('u', array('class' => 'baduri'),
313                                 'BAD phpwiki: URL'));
314     if ($m[1])
315         $pagename = urldecode($m[1]);
316     $qargs = $m[2];
317     
318     if (empty($pagename) &&
319         preg_match('/^(diff|edit|links|info)=([^&]+)$/', $qargs, $m))
320         {
321             // Convert old style links (to not break diff links in
322             // RecentChanges).
323             $pagename = urldecode($m[2]);
324             $args = array("action" => $m[1]);
325         }
326     else {
327         $args = SplitQueryArgs($qargs);
328     }
329     
330     if (empty($pagename))
331         $pagename = $GLOBALS['pagename'];
332     
333     if (isset($args['action']) && $args['action'] == 'browse')
334         unset($args['action']);
335     /*FIXME:
336       if (empty($args['action']))
337       $class = 'wikilink';
338       else if (is_safe_action($args['action']))
339       $class = 'wikiaction';
340     */
341     if (empty($args['action']) || is_safe_action($args['action']))
342         $class = 'wikiaction';
343     else {
344         // Don't allow administrative links on unlocked pages.
345         // FIXME: Ugh: don't like this...
346         global $dbi;
347         $page = $dbi->getPage($GLOBALS['pagename']);
348         if (!$page->get('locked'))
349             return QElement('u', array('class' => 'wikiunsafe'),
350                             _("Lock page to enable link"));
351         
352         $class = 'wikiadmin';
353     }
354     
355     // FIXME: ug, don't like this
356     if (preg_match('/=\d*\(/', $qargs))
357         return MakeWikiForm($pagename, $args, $class, $text);
358     if ($text)
359         $text = htmlspecialchars($text);
360     else
361         $text = QElement('span', array('class' => 'rawurl'), $url);
362     
363     return Element('a', array('href'  => WikiURL($pagename, $args),
364                               'class' => $class),
365                    $text);
366 }
367
368 function ParseAndLink($bracketlink) {
369     global $dbi, $AllowedProtocols, $InlineImages;
370     global $InterWikiLinkRegexp;
371     
372     // $bracketlink will start and end with brackets; in between will
373     // be either a page name, a URL or both separated by a pipe.
374     
375     // strip brackets and leading space
376     preg_match("/(\[\s*)(.+?)(\s*\])/", $bracketlink, $match);
377     // match the contents 
378     preg_match("/([^|]+)(\|)?([^|]+)?/", $match[2], $matches);
379     
380     if (isset($matches[3])) {
381         // named link of the form  "[some link name | http://blippy.com/]"
382         $URL = trim($matches[3]);
383         $linkname = trim($matches[1]);
384           $linktype = 'named';
385     } else {
386         // unnamed link of the form "[http://blippy.com/] or [wiki page]"
387         $URL = trim($matches[1]);
388         $linkname = '';
389         $linktype = 'simple';
390     }
391     
392     if ($dbi->isWikiPage($URL)) {
393         $link['type'] = "wiki-$linktype";
394         $link['link'] = LinkExistingWikiWord($URL, $linkname);
395     } elseif (preg_match("#^($AllowedProtocols):#", $URL)) {
396         // if it's an image, embed it; otherwise, it's a regular link
397         if (preg_match("/($InlineImages)$/i", $URL)) {
398             $link['type'] = "image-$linktype";
399               $link['link'] = LinkImage($URL, $linkname);
400         } else {
401             $link['type'] = "url-$linktype";
402             $link['link'] = LinkURL($URL, $linkname);
403         }
404     } elseif (preg_match("#^phpwiki:(.*)#", $URL, $match)) {
405         $link['type'] = "url-wiki-$linktype";
406         $link['link'] = LinkPhpwikiURL($URL, $linkname);
407     } elseif (preg_match("#^\d+$#", $URL)) {
408         $link['type'] = "footnote-$linktype";
409         $link['link'] = $URL;
410     } elseif (function_exists('LinkInterWikiLink') &&
411               preg_match("#^$InterWikiLinkRegexp:#", $URL)) {
412           $link['type'] = "interwiki-$linktype";
413           $link['link'] = LinkInterWikiLink($URL, $linkname);
414       } else {
415           $link['type'] = "wiki-unknown-$linktype";
416           $link['link'] = LinkUnknownWikiWord($URL, $linkname);
417       }
418     
419     return $link;
420 }
421
422
423 function ExtractWikiPageLinks($content) {
424     global $WikiNameRegexp;
425     
426     if (is_string($content))
427         $content = explode("\n", $content);
428     
429     $wikilinks = array();
430     foreach ($content as $line) {
431         // remove plugin code
432         $line = preg_replace('/<\?plugin\s+\w.*?\?>/', '', $line);
433         // remove escaped '['
434         $line = str_replace('[[', ' ', $line);
435         
436         // bracket links (only type wiki-* is of interest)
437         $numBracketLinks = preg_match_all("/\[\s*([^\]|]+\|)?\s*(\S.*?)\s*\]/",
438                                           $line, $brktlinks);
439         for ($i = 0; $i < $numBracketLinks; $i++) {
440             $link = ParseAndLink($brktlinks[0][$i]);
441             if (preg_match("#^wiki#", $link['type']))
442                 $wikilinks[$brktlinks[2][$i]] = 1;
443             
444             $brktlink = preg_quote($brktlinks[0][$i]);
445             $line = preg_replace("|$brktlink|", '', $line);
446         }
447         
448         // BumpyText old-style wiki links
449         if (preg_match_all("/!?$WikiNameRegexp/", $line, $link)) {
450             for ($i = 0; isset($link[0][$i]); $i++) {
451                 if($link[0][$i][0] <> '!')
452                     $wikilinks[$link[0][$i]] = 1;
453             }
454         }
455     }
456     return array_keys($wikilinks);
457 }      
458
459 function LinkRelatedPages($dbi, $pagename)
460 {
461     // currently not supported everywhere
462     if(!function_exists('GetWikiPageLinks'))
463         return '';
464     
465     //FIXME: fix or toss?
466     $links = GetWikiPageLinks($dbi, $pagename);
467     
468     $txt = QElement('strong',
469                     sprintf (_("%d best incoming links:"), NUM_RELATED_PAGES));
470     for($i = 0; $i < NUM_RELATED_PAGES; $i++) {
471         if(isset($links['in'][$i])) {
472             list($name, $score) = $links['in'][$i];
473             $txt .= LinkExistingWikiWord($name) . " ($score), ";
474         }
475     }
476     
477     $txt .= "\n" . Element('br');
478     $txt .= Element('strong',
479                     sprintf (_("%d best outgoing links:"), NUM_RELATED_PAGES));
480     for($i = 0; $i < NUM_RELATED_PAGES; $i++) {
481         if(isset($links['out'][$i])) {
482             list($name, $score) = $links['out'][$i];
483         if($dbi->isWikiPage($name))
484                 $txt .= LinkExistingWikiWord($name) . " ($score), ";
485         }
486     }
487     
488     $txt .= "\n" . Element('br');
489     $txt .= Element('strong',
490                     sprintf (_("%d most popular nearby:"), NUM_RELATED_PAGES));
491     for($i = 0; $i < NUM_RELATED_PAGES; $i++) {
492         if(isset($links['popular'][$i])) {
493             list($name, $score) = $links['popular'][$i];
494         $txt .= LinkExistingWikiWord($name) . " ($score), ";
495         }
496     }
497     
498     return $txt;
499 }
500
501
502 /**
503  * Split WikiWords in page names.
504  *
505  * It has been deemed useful to split WikiWords (into "Wiki Words") in
506  * places like page titles. This is rumored to help search engines
507  * quite a bit.
508  *
509  * @param $page string The page name.
510  *
511  * @return string The split name.
512  */
513 function split_pagename ($page) {
514     
515     if (preg_match("/\s/", $page))
516         return $page;           // Already split --- don't split any more.
517     
518     // FIXME: this algorithm is Anglo-centric.
519     static $RE;
520     if (!isset($RE)) {
521         // This mess splits between a lower-case letter followed by
522         // either an upper-case or a numeral; except that it wont
523         // split the prefixes 'Mc', 'De', or 'Di' off of their tails.
524         $RE[] = '/([[:lower:]])((?<!Mc|De|Di)[[:upper:]]|\d)/';
525         // This the single-letter words 'I' and 'A' from any following
526         // capitalized words.
527         $RE[] = '/(?: |^)([AI])([[:upper:]][[:lower:]])/';
528         // Split numerals from following letters.
529         $RE[] = '/(\d)([[:alpha:]])/';
530         
531         foreach ($RE as $key => $val)
532             $RE[$key] = pcre_fix_posix_classes($val);
533     }
534     
535     foreach ($RE as $regexp)
536         $page = preg_replace($regexp, '\\1 \\2', $page);
537     return $page;
538 }
539
540 function NoSuchRevision ($page, $version) {
541     $html = Element('p', QElement('strong', gettext("Bad Version"))) . "\n";
542     $html .= QElement('p',
543                       sprintf(_("I'm sorry.  Version %d of %s is not in my database."),
544                               $version, $page->getName())) . "\n";
545     
546     include_once('lib/Template.php');
547     echo GeneratePage('MESSAGE', $html, _("Bad Version"));
548     ExitWiki ("");
549 }
550
551
552 /**
553  * Get time offset for local time zone.
554  *
555  * @param $time time_t Get offset for this time. Default: now.
556  * @param $no_colon boolean Don't put colon between hours and minutes.
557  * @return string Offset as a string in the format +HH:MM.
558  */
559 function TimezoneOffset ($time = false, $no_colon = false) {
560     if ($time === false)
561         $time = time();
562     $secs = date('Z', $time);
563     if ($secs < 0) {
564         $sign = '-';
565         $secs = -$secs;
566     }
567     else {
568         $sign = '+';
569     }
570     $colon = $no_colon ? '' : ':';
571     $mins = intval(($secs + 30) / 60);
572     return sprintf("%s%02d%s%02d",
573                    $sign, $mins / 60, $colon, $mins % 60);
574 }
575
576 /**
577  * Format time in ISO-8601 format.
578  *
579  * @param $time time_t Time.  Default: now.
580  * @return string Date and time in ISO-8601 format.
581  */
582 function Iso8601DateTime ($time = false) {
583     if ($time === false)
584         $time = time();
585     $tzoff = TimezoneOffset($time);
586     $date  = date('Y-m-d', $time);
587     $time  = date('H:i:s', $time);
588     return $date . 'T' . $time . $tzoff;
589 }
590
591 /**
592  * Format time in RFC-2822 format.
593  *
594  * @param $time time_t Time.  Default: now.
595  * @return string Date and time in RFC-2822 format.
596  */
597 function Rfc2822DateTime ($time = false) {
598     if ($time === false)
599         $time = time();
600     return date('D, j M Y H:i:s ', $time) . TimezoneOffset($time, 'no colon');
601 }
602
603 /**
604  * Format time to standard 'ctime' format.
605  *
606  * @param $time time_t Time.  Default: now.
607  * @return string Date and time in RFC-2822 format.
608  */
609 function CTime ($time = false)
610 {
611     if ($time === false)
612         $time = time();
613     return date("D M j H:i:s Y", $time);
614 }
615
616
617
618 /**
619  * Internationalized printf.
620  *
621  * This is essentially the same as PHP's built-in printf
622  * with the following exceptions:
623  * <ol>
624  * <li> It passes the format string through gettext().
625  * <li> It supports the argument reordering extensions.
626  * </ol>
627  *
628  * Example:
629  *
630  * In php code, use:
631  * <pre>
632  *    __printf("Differences between versions %s and %s of %s",
633  *             $new_link, $old_link, $page_link);
634  * </pre>
635  *
636  * Then in locale/po/de.po, one can reorder the printf arguments:
637  *
638  * <pre>
639  *    msgid "Differences between %s and %s of %s."
640  *    msgstr "Der Unterschiedsergebnis von %3$s, zwischen %1$s und %2$s."
641  * </pre>
642  *
643  * (Note that while PHP tries to expand $vars within double-quotes,
644  * the values in msgstr undergo no such expansion, so the '$'s
645  * okay...)
646  *
647  * One shouldn't use reordered arguments in the default format string.
648  * Backslashes in the default string would be necessary to escape the
649  * '$'s, and they'll cause all kinds of trouble....
650  */ 
651 function __printf ($fmt) {
652     $args = func_get_args();
653     array_shift($args);
654     echo __vsprintf($fmt, $args);
655 }
656
657 /**
658  * Internationalized sprintf.
659  *
660  * This is essentially the same as PHP's built-in printf with the
661  * following exceptions:
662  *
663  * <ol>
664  * <li> It passes the format string through gettext().
665  * <li> It supports the argument reordering extensions.
666  * </ol>
667  *
668  * @see __printf
669  */ 
670 function __sprintf ($fmt) {
671     $args = func_get_args();
672     array_shift($args);
673     return __vsprintf($fmt, $args);
674 }
675
676 /**
677  * Internationalized vsprintf.
678  *
679  * This is essentially the same as PHP's built-in printf with the
680  * following exceptions:
681  *
682  * <ol>
683  * <li> It passes the format string through gettext().
684  * <li> It supports the argument reordering extensions.
685  * </ol>
686  *
687  * @see __printf
688  */ 
689 function __vsprintf ($fmt, $args) {
690     $fmt = gettext($fmt);
691     // PHP's sprintf doesn't support variable with specifiers,
692     // like sprintf("%*s", 10, "x"); --- so we won't either.
693     
694     if (preg_match_all('/(?<!%)%(\d+)\$/x', $fmt, $m)) {
695         // Format string has '%2$s' style argument reordering.
696         // PHP doesn't support this.
697         if (preg_match('/(?<!%)%[- ]?\d*[^- \d$]/x', $fmt))
698             // literal variable name substitution only to keep locale
699             // strings uncluttered
700             trigger_error(sprintf(_("Can't mix '%s' with '%s' type format strings"),
701                                   '%1\$s','%s'), E_USER_WARNING);
702         
703         $fmt = preg_replace('/(?<!%)%\d+\$/x', '%', $fmt);
704         $newargs = array();
705         
706         // Reorder arguments appropriately.
707         foreach($m[1] as $argnum) {
708             if ($argnum < 1 || $argnum > count($args))
709                 trigger_error(sprintf(_("%s: argument index out of range"), 
710                                       $argnum), E_USER_WARNING);
711             $newargs[] = $args[$argnum - 1];
712         }
713         $args = $newargs;
714     }
715     
716     // Not all PHP's have vsprintf, so...
717     array_unshift($args, $fmt);
718     return call_user_func_array('sprintf', $args);
719 }
720
721
722 // Class introspections
723
724 /** Determine whether object is of a specified type.
725  *
726  * @param $object object An object.
727  * @param $class string Class name.
728  * @return bool True iff $object is a $class
729  * or a sub-type of $class. 
730  */
731 function isa ($object, $class) 
732 {
733     $lclass = strtolower($class);
734
735     return get_class($object) == strtolower($lclass)
736         || is_subclass_of($object, $lclass);
737 }
738
739 // (c-file-style: "gnu")
740 // Local Variables:
741 // mode: php
742 // tab-width: 8
743 // c-basic-offset: 4
744 // c-hanging-comment-ender-p: nil
745 // indent-tabs-mode: nil
746 // End:   
747 ?>