]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/Theme.php
Workaround absence of %e date format specifier in Windows strftime function.
[SourceForge/phpwiki.git] / lib / Theme.php
1 <?php rcs_id('$Id: Theme.php,v 1.44 2002-02-26 11:08:41 lakka Exp $');
2
3 require_once('lib/HtmlElement.php');
4
5
6 /**
7  * Make a link to a wiki page (in this wiki).
8  *
9  * This is a convenience function.
10  *
11  * @param $page_or_rev mixed
12  * Can be:<dl>
13  * <dt>A string</dt><dd>The page to link to.</dd>
14  * <dt>A WikiDB_Page object</dt><dd>The page to link to.</dd>
15  * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page to link to.</dd>
16  * </dl>
17  *
18  * @param $type string
19  * One of:<dl>
20  * <dt>'unknown'</dt><dd>Make link appropriate for a non-existant page.</dd>
21  * <dt>'known'</dt><dd>Make link appropriate for an existing page.</dd>
22  * <dt>'auto'</dt><dd>Either 'unknown' or 'known' as appropriate.</dd>
23  * <dt>'button'</dt><dd>Make a button-style link.</dd>
24  * </dl>
25  * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown',
26  * 'named-wiki', or 'named-wikiunknown', as appropriate.
27  *
28  * @param $label mixed (string or XmlContent object)
29  * Label for the link.  If not given, defaults to the page name.
30  * (Label is ignored for $type == 'button'.)
31  */
32 function WikiLink ($page_or_rev, $type = 'known', $label = false) {
33     global $Theme;
34
35     if ($type == 'button') {
36         return $Theme->makeLinkButton($page_or_rev);
37     }
38
39     $version = false;
40
41     if (isa($page_or_rev, 'WikiDB_PageRevision')) {
42         $version = $page_or_rev->getVersion();
43         $page = $page_or_rev->getPage();
44         $pagename = $page->getName();
45         $exists = true;
46     }
47     elseif (isa($page_or_rev, 'WikiDB_Page')) {
48         $page = $page_or_rev;
49         $pagename = $page->getName();
50     }
51     else {
52         $pagename = $page_or_rev;
53     }
54
55     if ($type == 'auto') {
56         if (isset($page)) {
57             $current = $page->getCurrentRevision();
58             $exists = ! $current->hasDefaultContents();
59         }
60         else {
61             global $request;
62             $dbi = $request->getDbh();
63             $exists = $dbi->isWikiPage($pagename);
64         }
65     }
66     elseif ($type == 'unknown') {
67         $exists = false;
68     }
69     else {
70         $exists = true;
71     }
72
73
74     if ($exists)
75         return $Theme->linkExistingWikiWord($pagename, $label, $version);
76     else
77         return $Theme->linkUnknownWikiWord($pagename, $label);
78 }
79
80
81
82 /**
83  * Make a button.
84  *
85  * This is a convenience function.
86  *
87  * @param $action string
88  * One of <dl>
89  * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
90  * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
91  * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
92  *      ([name] can be blank for a nameless submit button.)</dd>
93  * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
94  *      array('action' => 'diff', 'previous' => 'author')
95  * </pre></dd>
96  * </dl>
97  *
98  * @param $label string
99  * A label for the button.  If ommited, a suitable default (based on the valued of $action)
100  * will be picked.
101  *
102  * @param $page_or_rev mixed
103  * Which page (& version) to perform the action on.
104  * Can be one of:<dl>
105  * <dt>A string</dt><dd>The pagename.</dd>
106  * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
107  * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
108  * </dl>
109  * ($Page_or_rev is ignored for submit buttons.)
110  */
111 function Button ($action, $label = false, $page_or_rev = false) {
112     global $Theme;
113
114     if (!is_array($action) && preg_match('/submit:(.*)/A', $action, $m))
115         return $Theme->makeSubmitButton($label, $m[1], $class = $page_or_rev);
116     else
117         return $Theme->makeActionButton($action, $label, $page_or_rev);
118 }
119
120
121
122
123 class Theme {
124     function Theme ($theme_name = 'default') {
125         $this->_name = $theme_name;
126         $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes";
127
128         $this->_path  = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/" : "";
129         $this->_theme = "themes/$theme_name";
130
131         if ($theme_name != 'default')
132             $this->_default_theme = new Theme;
133     }
134
135     function file ($file) {
136         return $this->_path . "$this->_theme/$file";
137     }
138
139     function _findFile ($file, $missing_okay = false) {
140         if (file_exists($this->_path . "$this->_theme/$file"))
141             return "$this->_theme/$file";
142
143         // FIXME: this is a short-term hack.  Delete this after all files
144         // get moved into themes/...
145         if (file_exists($this->_path . $file))
146             return $file;
147
148
149         if (isset($this->_default_theme)) {
150             return $this->_default_theme->_findFile($file, $missing_okay);
151         }
152         else if (!$missing_okay) {
153             trigger_error("$file: not found", E_USER_NOTICE);
154         }
155         return false;
156     }
157
158     function _findData ($file, $missing_okay = false) {
159         $path = $this->_findFile($file, $missing_okay);
160         if (!$path)
161             return false;
162
163         if (defined('DATA_PATH'))
164             return DATA_PATH . "/$path";
165         return $path;
166     }
167
168     ////////////////////////////////////////////////////////////////
169     //
170     // Date and Time formatting
171     //
172     ////////////////////////////////////////////////////////////////
173
174     // Note:  Windows' implemetation of strftime does not include certain
175         // format specifiers, such as %e (for date without leading zeros).  In
176         // general, see:
177         // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
178         // As a result, we have to use %d, and strip out leading zeros ourselves.
179
180     var $_dateFormat = "%B %d, %Y";
181     var $_timeFormat = "%I:%M %p";
182
183     var $_showModTime = true;
184
185     /**
186      * Set format string used for dates.
187      *
188      * @param $fs string Format string for dates.
189      *
190      * @param $show_mod_time bool If true (default) then times
191      * are included in the messages generated by getLastModifiedMessage(),
192      * otherwise, only the date of last modification will be shown.
193      */
194     function setDateFormat ($fs, $show_mod_time = true) {
195         $this->_dateFormat = $fs;
196         $this->_showModTime = $show_mod_time;
197     }
198
199     /**
200      * Set format string used for times.
201      *
202      * @param $fs string Format string for times.
203      */
204     function setTimeFormat ($fs) {
205         $this->_timeFormat = $fs;
206     }
207
208     /**
209      * Format a date.
210      *
211      * Any time zone offset specified in the users preferences is
212      * taken into account by this method.
213      *
214      * @param $time_t integer Unix-style time.
215      *
216      * @return string The date.
217      */
218     function formatDate ($time_t) {
219         global $request;
220         
221         $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
222         // strip leading zeros from date elements (ie space followed by zero)
223         return preg_replace('/ 0/', ' ', 
224                             strftime($this->_dateFormat, $offset_time));
225     }
226
227     /**
228      * Format a date.
229      *
230      * Any time zone offset specified in the users preferences is
231      * taken into account by this method.
232      *
233      * @param $time_t integer Unix-style time.
234      *
235      * @return string The time.
236      */
237     function formatTime ($time_t) {
238         //FIXME: make 24-hour mode configurable?
239         global $request;
240         $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
241         return preg_replace('/^0/', ' ',
242                             strtolower(strftime($this->_timeFormat, $offset_time)));
243     }
244
245     /**
246      * Format a date and time.
247      *
248      * Any time zone offset specified in the users preferences is
249      * taken into account by this method.
250      *
251      * @param $time_t integer Unix-style time.
252      *
253      * @return string The date and time.
254      */
255     function formatDateTime ($time_t) {
256         return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
257     }
258
259     /**
260      * Format a (possibly relative) date.
261      *
262      * If enabled in the users preferences, this method might
263      * return a relative day (e.g. 'Today', 'Yesterday').
264      *
265      * Any time zone offset specified in the users preferences is
266      * taken into account by this method.
267      *
268      * @param $time_t integer Unix-style time.
269      *
270      * @return string The day.
271      */
272     function getDay ($time_t) {
273         global $request;
274         
275         if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
276             return ucfirst($date);
277         }
278         return $this->formatDate($time_t);
279     }
280     
281     /**
282      * Format the "last modified" message for a page revision.
283      *
284      * @param $revision object A WikiDB_PageRevision object.
285      *
286      * @param $show_version bool Should the page version number
287      * be included in the message.  (If this argument is omitted,
288      * then the version number will be shown only iff the revision
289      * is not the current one.
290      *
291      * @return string The "last modified" message.
292      */
293     function getLastModifiedMessage ($revision, $show_version = 'auto') {
294         global $request;
295
296         $mtime = $revision->get('mtime');
297         
298         if ($show_version == 'auto')
299             $show_version = !$revision->isCurrent();
300             
301         if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
302             if ($this->_showModTime)
303                 $date =  sprintf(_("%s at %s"),
304                                  $date, $this->formatTime($mtime));
305             
306             if ($show_version)
307                 return fmt("Version %s, saved %s.", $revision->getVersion(), $date);
308             else
309                 return fmt("Last edited %s.", $date);
310         }
311
312         if ($this->_showModTime)
313             $date = $this->formatDateTime($mtime);
314         else
315             $date = $this->formatDate($mtime);
316         
317         if ($show_version)
318             return fmt("Version %s, saved on %s.", $revision->getVersion(), $date);
319         else
320             return fmt("Last edited on %s.", $date);
321     }
322     
323     function _relativeDay ($time_t) {
324         global $request;
325         $offset = 3600 * $request->getPref('timeOffset');
326
327         $now = time() + $offset;
328         $today = localtime($now, true);
329         $time = localtime($time_t + $offset, true);
330
331         if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
332             return _("today");
333         
334         // Note that due to daylight savings chages (and leap seconds), $now minus
335         // 24 hours is not guaranteed to be yesterday.
336         $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
337         if ($time['tm_yday'] == $yesterday['tm_yday'] && $time['tm_year'] == $yesterday['tm_year'])
338             return _("yesterday");
339
340         return false;
341     }
342
343     ////////////////////////////////////////////////////////////////
344     //
345     // Hooks for other formatting
346     //
347     ////////////////////////////////////////////////////////////////
348
349     //FIXME: PHP 4.1 Warnings
350     //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
351     //use the call_user_func variety with the array(&$obj, "method") syntax instead
352
353     function getFormatter ($type, $format) {
354         $method = strtolower("get${type}Formatter");
355         if (method_exists($this, $method))
356             return $this->{$method}($format);
357         return false;
358     }
359
360     ////////////////////////////////////////////////////////////////
361     //
362     // Links
363     //
364     ////////////////////////////////////////////////////////////////
365
366     var $_autosplitWikiWords = false;
367
368     function setAutosplitWikiWords($autosplit=false) {
369         $this->_autosplitWikiWords = $autosplit ? true : false;
370     }
371
372     function maybeSplitWikiWord ($wikiword) {
373         if ($this->_autosplitWikiWords)
374             return split_pagename($wikiword);
375         else
376             return $wikiword;
377     }
378
379     function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
380         if ($version !== false)
381             $url = WikiURL($wikiword, array('version' => $version));
382         else
383             $url = WikiURL($wikiword);
384
385         $link = HTML::a(array('href' => $url));
386
387         if (!empty($linktext)) {
388             $link->pushContent($linktext);
389             $link->setAttr('class', 'named-wiki');
390             $link->setAttr('title', $this->maybeSplitWikiWord($wikiword));
391         }
392         else {
393             $link->pushContent($this->maybeSplitWikiWord($wikiword));
394             $link->setAttr('class', 'wiki');
395         }
396         return $link;
397     }
398
399     function linkUnknownWikiWord($wikiword, $linktext = '') {
400         $url = WikiURL($wikiword, array('action' => 'edit'));
401         //$link = HTML::span(HTML::a(array('href' => $url), '?'));
402         $button = $this->makeButton('?', $url);
403         $button->addTooltip(sprintf(_("Edit: %s"), $wikiword));
404         $link = HTML::span($button);
405
406
407         if (!empty($linktext)) {
408             $link->pushContent(HTML::u($linktext));
409             $link->setAttr('class', 'named-wikiunknown');
410         }
411         else {
412             $link->pushContent(HTML::u($this->maybeSplitWikiWord($wikiword)));
413             $link->setAttr('class', 'wikiunknown');
414         }
415
416         return $link;
417     }
418
419     ////////////////////////////////////////////////////////////////
420     //
421     // Images and Icons
422     //
423     ////////////////////////////////////////////////////////////////
424
425     /**
426         *
427      * (To disable an image, alias the image to <code>false</code>.
428         */
429     function addImageAlias ($alias, $image_name) {
430         $this->_imageAliases[$alias] = $image_name;
431     }
432
433     function getImageURL ($image) {
434         $aliases = &$this->_imageAliases;
435
436         if (isset($aliases[$image])) {
437             $image = $aliases[$image];
438             if (!$image)
439                 return false;
440         }
441
442         // If not extension, default to .png.
443         if (!preg_match('/\.\w+$/', $image))
444             $image .= '.png';
445
446         // FIXME: this should probably be made to fall back
447         //        automatically to .gif, .jpg.
448         //        Also try .gif before .png if browser doesn't like png.
449
450         return $this->_findData("images/$image", 'missing okay');
451     }
452
453     function setLinkIcon($proto, $image = false) {
454         if (!$image)
455             $image = $proto;
456
457         $this->_linkIcons[$proto] = $image;
458     }
459
460     function getLinkIconURL ($proto) {
461         $icons = &$this->_linkIcons;
462         if (!empty($icons[$proto]))
463             return $this->getImageURL($icons[$proto]);
464         elseif (!empty($icons['*']))
465             return $this->getImageURL($icons['*']);
466         return false;
467     }
468
469     function addButtonAlias ($text, $alias = false) {
470         $aliases = &$this->_buttonAliases;
471
472         if (is_array($text))
473             $aliases = array_merge($aliases, $text);
474         elseif ($alias === false)
475             unset($aliases[$text]);
476         else
477             $aliases[$text] = $alias;
478     }
479
480     function getButtonURL ($text) {
481         $aliases = &$this->_buttonAliases;
482         if (isset($aliases[$text]))
483             $text = $aliases[$text];
484
485         $qtext = urlencode($text);
486         $url = $this->_findButton("$qtext.png");
487         if ($url && strstr($url, '%')) {
488             $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
489         }
490         return $url;
491     }
492
493     function _findButton ($button_file) {
494         if (!isset($this->_button_path))
495             $this->_button_path = $this->_getButtonPath();
496
497         foreach ($this->_button_path as $dir) {
498             $path = "$this->_theme/$dir/$button_file";
499             if (file_exists($this->_path . $path))
500                 return defined('DATA_PATH') ? DATA_PATH . "/$path" : $path;
501         }
502         return false;
503     }
504
505     function _getButtonPath () {
506         $button_dir = $this->file("buttons");
507         if (!file_exists($button_dir) || !is_dir($button_dir))
508             return array();
509
510         $path = array('buttons');
511
512         $dir = dir($button_dir);
513         while (($subdir = $dir->read()) !== false) {
514             if ($subdir[0] == '.')
515                 continue;
516             if (is_dir("$button_dir/$subdir"))
517                 $path[] = "buttons/$subdir";
518         }
519         $dir->close();
520
521         return $path;
522     }
523
524     ////////////////////////////////////////////////////////////////
525     //
526     // Button style
527     //
528     ////////////////////////////////////////////////////////////////
529
530     function makeButton ($text, $url, $class = false) {
531         // FIXME: don't always try for image button?
532
533         // Special case: URLs like 'submit:preview' generate form
534         // submission buttons.
535         if (preg_match('/^submit:(.*)$/', $url, $m))
536             return $this->makeSubmitButton($text, $m[1], $class);
537
538         $imgurl = $this->getButtonURL($text);
539         if ($imgurl)
540             return new ImageButton($text, $url, $class, $imgurl);
541         else
542             return new Button($text, $url, $class);
543     }
544
545     function makeSubmitButton ($text, $name, $class = false) {
546         $imgurl = $this->getButtonURL($text);
547
548         if ($imgurl)
549             return new SubmitImageButton($text, $name, $class, $imgurl);
550         else
551             return new SubmitButton($text, $name, $class);
552     }
553
554     /**
555      * Make button to perform action.
556      *
557      * This constructs a button which performs an action on the
558      * currently selected version of the current page.
559      * (Or anotherpage or version, if you want...)
560      *
561      * @param $action string The action to perform (e.g. 'edit', 'lock').
562      * This can also be the name of an "action page" like 'LikePages'.
563      * Alternatively you can give a hash of query args to be applied
564      * to the page.
565      *
566      * @param $label string Textual label for the button.  If left empty,
567      * a suitable name will be guessed.
568      *
569      * @param $page_or_rev mixed  The page to link to.  This can be
570      * given as a string (the page name), a WikiDB_Page object, or as
571      * WikiDB_PageRevision object.  If given as a WikiDB_PageRevision
572      * object, the button will link to a specific version of the
573      * designated page, otherwise the button links to the most recent
574      * version of the page.
575      *
576      * @return object A Button object.
577      */
578     function makeActionButton ($action, $label = false, $page_or_rev = false) {
579         extract($this->_get_name_and_rev($page_or_rev));
580
581         if (is_array($action)) {
582             $attr = $action;
583             $action = isset($attr['action']) ? $attr['action'] : 'browse';
584         }
585         else
586             $attr['action'] = $action;
587
588         $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
589         if (!$label)
590             $label = $this->_labelForAction($action);
591
592         if ($version)
593             $attr['version'] = $version;
594
595         if ($action == 'browse')
596             unset($attr['action']);
597
598         return $this->makeButton($label, WikiURL($pagename, $attr), $class);
599     }
600
601     /**
602      * Make a "button" which links to a wiki-page.
603      *
604      * These are really just regular WikiLinks, possibly
605      * disguised (e.g. behind an image button) by the theme.
606      *
607      * This method should probably only be used for links
608      * which appear in page navigation bars, or similar places.
609      *
610      * Use linkExistingWikiWord, or LinkWikiWord for normal links.
611      *
612      * @param $page_or_rev mixed The page to link to.  This can be
613      * given as a string (the page name), a WikiDB_Page object, or as
614      * WikiDB_PageRevision object.  If given as a WikiDB_PageRevision
615      * object, the button will link to a specific version of the
616      * designated page, otherwise the button links to the most recent
617      * version of the page.
618      *
619      * @return object A Button object.
620      */
621     function makeLinkButton ($page_or_rev) {
622         extract($this->_get_name_and_rev($page_or_rev));
623
624         $args = $version ? array('version' => $version) : false;
625
626         return $this->makeButton($pagename, WikiURL($pagename, $args), 'wiki');
627     }
628
629     function _get_name_and_rev ($page_or_rev) {
630         $version = false;
631
632         if (empty($page_or_rev)) {
633             global $request;
634             $pagename = $request->getArg("pagename");
635             $version = $request->getArg("version");
636         }
637         elseif (is_object($page_or_rev)) {
638             if (isa($page_or_rev, 'WikiDB_PageRevision')) {
639                 $rev = $page_or_rev;
640                 $page = $rev->getPage();
641                 $version = $rev->getVersion();
642             }
643             else {
644                 $page = $page_or_rev;
645             }
646             $pagename = $page->getName();
647         }
648         else {
649             $pagename = (string) $page_or_rev;
650         }
651         return compact('pagename', 'version');
652     }
653
654     function _labelForAction ($action) {
655         switch ($action) {
656             case 'edit':   return _("Edit");
657             case 'diff':   return _("Diff");
658             case 'logout': return _("Sign Out");
659             case 'login':  return _("Sign In");
660             case 'lock':   return _("Lock Page");
661             case 'unlock': return _("Unlock Page");
662             case 'remove': return _("Remove Page");
663             default:
664                 // I don't think the rest of these actually get used.
665                 // 'setprefs'
666                 // 'upload' 'dumpserial' 'loadfile' 'zip'
667                 // 'save' 'browse'
668                 return ucfirst($action);
669         }
670     }
671
672     //----------------------------------------------------------------
673     var $_buttonSeparator = ' | ';
674
675     function setButtonSeparator($separator) {
676         $this->_buttonSeparator = $separator;
677     }
678
679     function getButtonSeparator() {
680         return $this->_buttonSeparator;
681     }
682
683
684     ////////////////////////////////////////////////////////////////
685     //
686     // CSS
687     //
688     ////////////////////////////////////////////////////////////////
689
690     function _CSSlink($title, $css_file, $media, $is_alt = false) {
691         $link = HTML::link(array('rel'     => $is_alt ? 'alternate stylesheet' : 'stylesheet',
692                                  'title'   => $title,
693                                  'type'    => 'text/css',
694                                  'charset' => CHARSET,
695                                  'href'    => $this->_findData($css_file)));
696         if ($media)
697             $link->setAttr('media', $media);
698         return $link;
699     }
700
701     function setDefaultCSS ($title, $css_file, $media = false) {
702         if (isset($this->_defaultCSS)) {
703             $oldtitle = $this->_defaultCSS->_attr['title'];
704             $error = sprintf("'%s' -> '%s'", $oldtitle, $title);
705             trigger_error(sprintf(_("Redefinition of %s: %s"), "'default CSS'", $error),
706                           E_USER_NOTICE);
707         }
708         if (isset($this->_alternateCSS))
709             unset($this->_alternateCSS[$title]);
710         $this->_defaultCSS = $this->_CSSlink($title, $css_file, $media);
711     }
712
713     function addAlternateCSS ($title, $css_file, $media = false) {
714         $this->_alternateCSS[$title] = $this->_CSSlink($title, $css_file, $media, true);
715     }
716
717     /**
718         * @return string HTML for CSS.
719      */
720     function getCSS () {
721         $css = HTML($this->_defaultCSS);
722         if (!empty($this->_alternateCSS))
723             $css->pushContent($this->_alternateCSS);
724         return $css;
725     }
726
727     function findTemplate ($name) {
728         return $this->_path . $this->_findFile("templates/$name.tmpl");
729     }
730 };
731
732
733 /**
734  * A class representing a clickable "button".
735  *
736  * In it's simplest (default) form, a "button" is just a link associated
737  * with some sort of wiki-action.
738  */
739 class Button extends HtmlElement {
740     /** Constructor
741      *
742      * @param $text string The text for the button.
743      * @param $url string The url (href) for the button.
744      * @param $class string The CSS class for the button.
745      */
746     function Button ($text, $url, $class = false) {
747         $this->HtmlElement('a', array('href' => $url));
748         if ($class)
749             $this->setAttr('class', $class);
750         $this->pushContent($text);
751     }
752
753 };
754
755
756 /**
757  * A clickable image button.
758  */
759 class ImageButton extends Button {
760     /** Constructor
761      *
762      * @param $text string The text for the button.
763      * @param $url string The url (href) for the button.
764      * @param $class string The CSS class for the button.
765      * @param $img_url string URL for button's image.
766      * @param $img_attr array Additional attributes for the &lt;img&gt; tag.
767      */
768     function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
769         $this->HtmlElement('a', array('href' => $url));
770         if ($class)
771             $this->setAttr('class', $class);
772
773         if (!is_array($img_attr))
774             $img_attr = array();
775         $img_attr['src'] = $img_url;
776         $img_attr['alt'] = $text;
777         $img_attr['class'] = 'wiki-button';
778         $img_attr['border'] = 0;
779         $this->pushContent(HTML::img($img_attr));
780     }
781 };
782
783 /**
784  * A class representing a form <samp>submit</samp> button.
785  */
786 class SubmitButton extends HtmlElement {
787     /** Constructor
788      *
789      * @param $text string The text for the button.
790      * @param $name string The name of the form field.
791      * @param $class string The CSS class for the button.
792      */
793     function SubmitButton ($text, $name = false, $class = false) {
794         $this->HtmlElement('input', array('type' => 'submit',
795                                           'value' => $text));
796         if ($name)
797             $this->setAttr('name', $name);
798         if ($class)
799             $this->setAttr('class', $class);
800     }
801
802 };
803
804
805 /**
806  * A class representing an image form <samp>submit</samp> button.
807  */
808 class SubmitImageButton extends SubmitButton {
809     /** Constructor
810      *
811      * @param $text string The text for the button.
812      * @param $name string The name of the form field.
813      * @param $class string The CSS class for the button.
814      * @param $img_url string URL for button's image.
815      * @param $img_attr array Additional attributes for the &lt;img&gt; tag.
816      */
817     function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
818         $this->HtmlElement('input', array('type'  => 'image',
819                                           'src'   => $img_url,
820                                           'value' => $text,
821                                           'alt'   => $text));
822         if ($name)
823             $this->setAttr('name', $name);
824         if ($class)
825             $this->setAttr('class', $class);
826     }
827
828 };
829
830
831 // (c-file-style: "gnu")
832 // Local Variables:
833 // mode: php
834 // tab-width: 8
835 // c-basic-offset: 4
836 // c-hanging-comment-ender-p: nil
837 // indent-tabs-mode: nil
838 // End:
839 ?>