]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/Theme.php
For submit buttons, pass the third argument as the css class instead of always 'butto...
[SourceForge/phpwiki.git] / lib / Theme.php
1 <?php rcs_id('$Id: Theme.php,v 1.41 2002-02-14 03:39:15 carstenklapp 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     var $_dateFormat = "%B %e, %Y";
175     var $_timeFormat = "%l:%M %p";
176     var $_showModTime = true;
177
178     /**
179      * Set format string used for dates.
180      *
181      * @param $fs string Format string for dates.
182      *
183      * @param $show_mod_time bool If true (default) then times
184      * are included in the messages generated by getLastModifiedMessage(),
185      * otherwise, only the date of last modification will be shown.
186      */
187     function setDateFormat ($fs, $show_mod_time = true) {
188         $this->_dateFormat = $fs;
189         $this->_showModTime = $show_mod_time;
190     }
191
192     /**
193      * Set format string used for times.
194      *
195      * @param $fs string Format string for times.
196      */
197     function setTimeFormat ($fs) {
198         $this->_timeFormat = $fs;
199     }
200
201     /**
202      * Format a date.
203      *
204      * Any time zone offset specified in the users preferences is
205      * taken into account by this method.
206      *
207      * @param $time_t integer Unix-style time.
208      *
209      * @return string The date.
210      */
211     function formatDate ($time_t) {
212         global $request;
213         
214         $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
215         return strftime($this->_dateFormat, $offset_time);
216     }
217
218     /**
219      * Format a date.
220      *
221      * Any time zone offset specified in the users preferences is
222      * taken into account by this method.
223      *
224      * @param $time_t integer Unix-style time.
225      *
226      * @return string The time.
227      */
228     function formatTime ($time_t) {
229         //FIXME: make 24-hour mode configurable?
230         global $request;
231         $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
232         return preg_replace('/^0/', ' ',
233                             strtolower(strftime($this->_timeFormat, $offset_time)));
234     }
235
236     /**
237      * Format a date and time.
238      *
239      * Any time zone offset specified in the users preferences is
240      * taken into account by this method.
241      *
242      * @param $time_t integer Unix-style time.
243      *
244      * @return string The date and time.
245      */
246     function formatDateTime ($time_t) {
247         return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
248     }
249
250     /**
251      * Format a (possibly relative) date.
252      *
253      * If enabled in the users preferences, this method might
254      * return a relative day (e.g. 'Today', 'Yesterday').
255      *
256      * Any time zone offset specified in the users preferences is
257      * taken into account by this method.
258      *
259      * @param $time_t integer Unix-style time.
260      *
261      * @return string The day.
262      */
263     function getDay ($time_t) {
264         global $request;
265         
266         if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
267             return ucfirst($date);
268         }
269         return $this->formatDate($time_t);
270     }
271     
272     /**
273      * Format the "last modified" message for a page revision.
274      *
275      * @param $revision object A WikiDB_PageRevision object.
276      *
277      * @param $show_version bool Should the page version number
278      * be included in the message.  (If this argument is omitted,
279      * then the version number will be shown only iff the revision
280      * is not the current one.
281      *
282      * @return string The "last modified" message.
283      */
284     function getLastModifiedMessage ($revision, $show_version = 'auto') {
285         global $request;
286
287         $mtime = $revision->get('mtime');
288         
289         if ($show_version == 'auto')
290             $show_version = !$revision->isCurrent();
291             
292         if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
293             if ($this->_showModTime)
294                 $date =  sprintf(_("%s at %s"),
295                                  $date, $this->formatTime($mtime));
296             
297             if ($show_version)
298                 return fmt("Version %s, saved %s.", $revision->getVersion(), $date);
299             else
300                 return fmt("Last edited %s.", $date);
301         }
302
303         if ($this->_showModTime)
304             $date = $this->formatDateTime($mtime);
305         else
306             $date = $this->formatDate($mtime);
307         
308         if ($show_version)
309             return fmt("Version %s, saved on %s.", $revision->getVersion(), $date);
310         else
311             return fmt("Last edited on %s.", $date);
312     }
313     
314     function _relativeDay ($time_t) {
315         global $request;
316         $offset = 3600 * $request->getPref('timeOffset');
317
318         $now = time() + $offset;
319         $today = localtime($now, true);
320         $time = localtime($time_t + $offset, true);
321
322         if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
323             return _("today");
324         
325         // Note that due to daylight savings chages (and leap seconds), $now minus
326         // 24 hours is not guaranteed to be yesterday.
327         $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
328         if ($time['tm_yday'] == $yesterday['tm_yday'] && $time['tm_year'] == $yesterday['tm_year'])
329             return _("yesterday");
330
331         return false;
332     }
333
334     ////////////////////////////////////////////////////////////////
335     //
336     // Hooks for other formatting
337     //
338     ////////////////////////////////////////////////////////////////
339
340     //FIXME: PHP 4.1 Warnings
341     //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
342     //use the call_user_func variety with the array(&$obj, "method") syntax instead
343
344     function getFormatter ($type, $format) {
345         $method = strtolower("get${type}Formatter");
346         if (method_exists($this, $method))
347             return $this->{$method}($format);
348         return false;
349     }
350
351     ////////////////////////////////////////////////////////////////
352     //
353     // Links
354     //
355     ////////////////////////////////////////////////////////////////
356
357     var $_autosplitWikiWords = false;
358
359     function setAutosplitWikiWords($autosplit=false) {
360         $this->_autosplitWikiWords = $autosplit ? true : false;
361     }
362
363     function maybeSplitWikiWord ($wikiword) {
364         if ($this->_autosplitWikiWords)
365             return split_pagename($wikiword);
366         else
367             return $wikiword;
368     }
369
370     function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
371         if ($version !== false)
372             $url = WikiURL($wikiword, array('version' => $version));
373         else
374             $url = WikiURL($wikiword);
375
376         $link = HTML::a(array('href' => $url));
377
378         if (!empty($linktext)) {
379             $link->pushContent($linktext);
380             $link->setAttr('class', 'named-wiki');
381             $link->setAttr('title', $this->maybeSplitWikiWord($wikiword));
382         }
383         else {
384             $link->pushContent($this->maybeSplitWikiWord($wikiword));
385             $link->setAttr('class', 'wiki');
386         }
387         return $link;
388     }
389
390     function linkUnknownWikiWord($wikiword, $linktext = '') {
391         $url = WikiURL($wikiword, array('action' => 'edit'));
392         //$link = HTML::span(HTML::a(array('href' => $url), '?'));
393         $button = $this->makeButton('?', $url);
394         $button->addTooltip(sprintf(_("Edit: %s"), $wikiword));
395         $link = HTML::span($button);
396
397
398         if (!empty($linktext)) {
399             $link->pushContent(HTML::u($linktext));
400             $link->setAttr('class', 'named-wikiunknown');
401         }
402         else {
403             $link->pushContent(HTML::u($this->maybeSplitWikiWord($wikiword)));
404             $link->setAttr('class', 'wikiunknown');
405         }
406
407         return $link;
408     }
409
410     ////////////////////////////////////////////////////////////////
411     //
412     // Images and Icons
413     //
414     ////////////////////////////////////////////////////////////////
415
416     /**
417         *
418      * (To disable an image, alias the image to <code>false</code>.
419         */
420     function addImageAlias ($alias, $image_name) {
421         $this->_imageAliases[$alias] = $image_name;
422     }
423
424     function getImageURL ($image) {
425         $aliases = &$this->_imageAliases;
426
427         if (isset($aliases[$image])) {
428             $image = $aliases[$image];
429             if (!$image)
430                 return false;
431         }
432
433         // If not extension, default to .png.
434         if (!preg_match('/\.\w+$/', $image))
435             $image .= '.png';
436
437         // FIXME: this should probably be made to fall back
438         //        automatically to .gif, .jpg.
439         //        Also try .gif before .png if browser doesn't like png.
440
441         return $this->_findData("images/$image", 'missing okay');
442     }
443
444     function setLinkIcon($proto, $image = false) {
445         if (!$image)
446             $image = $proto;
447
448         $this->_linkIcons[$proto] = $image;
449     }
450
451     function getLinkIconURL ($proto) {
452         $icons = &$this->_linkIcons;
453         if (!empty($icons[$proto]))
454             return $this->getImageURL($icons[$proto]);
455         elseif (!empty($icons['*']))
456             return $this->getImageURL($icons['*']);
457         return false;
458     }
459
460     function addButtonAlias ($text, $alias = false) {
461         $aliases = &$this->_buttonAliases;
462
463         if (is_array($text))
464             $aliases = array_merge($aliases, $text);
465         elseif ($alias === false)
466             unset($aliases[$text]);
467         else
468             $aliases[$text] = $alias;
469     }
470
471     function getButtonURL ($text) {
472         $aliases = &$this->_buttonAliases;
473         if (isset($aliases[$text]))
474             $text = $aliases[$text];
475
476         $qtext = urlencode($text);
477         $url = $this->_findButton("$qtext.png");
478         if ($url && strstr($url, '%')) {
479             $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
480         }
481         return $url;
482     }
483
484     function _findButton ($button_file) {
485         if (!isset($this->_button_path))
486             $this->_button_path = $this->_getButtonPath();
487
488         foreach ($this->_button_path as $dir) {
489             $path = "$this->_theme/$dir/$button_file";
490             if (file_exists($this->_path . $path))
491                 return defined('DATA_PATH') ? DATA_PATH . "/$path" : $path;
492         }
493         return false;
494     }
495
496     function _getButtonPath () {
497         $button_dir = $this->file("buttons");
498         if (!file_exists($button_dir) || !is_dir($button_dir))
499             return array();
500
501         $path = array('buttons');
502
503         $dir = dir($button_dir);
504         while (($subdir = $dir->read()) !== false) {
505             if ($subdir[0] == '.')
506                 continue;
507             if (is_dir("$button_dir/$subdir"))
508                 $path[] = "buttons/$subdir";
509         }
510         $dir->close();
511
512         return $path;
513     }
514
515     ////////////////////////////////////////////////////////////////
516     //
517     // Button style
518     //
519     ////////////////////////////////////////////////////////////////
520
521     function makeButton ($text, $url, $class = false) {
522         // FIXME: don't always try for image button?
523
524         // Special case: URLs like 'submit:preview' generate form
525         // submission buttons.
526         if (preg_match('/^submit:(.*)$/', $url, $m))
527             return $this->makeSubmitButton($text, $m[1], $class);
528
529         $imgurl = $this->getButtonURL($text);
530         if ($imgurl)
531             return new ImageButton($text, $url, $class, $imgurl);
532         else
533             return new Button($text, $url, $class);
534     }
535
536     function makeSubmitButton ($text, $name, $class = false) {
537         $imgurl = $this->getButtonURL($text);
538
539         if ($imgurl)
540             return new SubmitImageButton($text, $name, $class, $imgurl);
541         else
542             return new SubmitButton($text, $name, $class);
543     }
544
545     /**
546      * Make button to perform action.
547      *
548      * This constructs a button which performs an action on the
549      * currently selected version of the current page.
550      * (Or anotherpage or version, if you want...)
551      *
552      * @param $action string The action to perform (e.g. 'edit', 'lock').
553      * This can also be the name of an "action page" like 'LikePages'.
554      * Alternatively you can give a hash of query args to be applied
555      * to the page.
556      *
557      * @param $label string Textual label for the button.  If left empty,
558      * a suitable name will be guessed.
559      *
560      * @param $page_or_rev mixed  The page to link to.  This can be
561      * given as a string (the page name), a WikiDB_Page object, or as
562      * WikiDB_PageRevision object.  If given as a WikiDB_PageRevision
563      * object, the button will link to a specific version of the
564      * designated page, otherwise the button links to the most recent
565      * version of the page.
566      *
567      * @return object A Button object.
568      */
569     function makeActionButton ($action, $label = false, $page_or_rev = false) {
570         extract($this->_get_name_and_rev($page_or_rev));
571
572         if (is_array($action)) {
573             $attr = $action;
574             $action = isset($attr['action']) ? $attr['action'] : 'browse';
575         }
576         else
577             $attr['action'] = $action;
578
579         $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
580         if (!$label)
581             $label = $this->_labelForAction($action);
582
583         if ($version)
584             $attr['version'] = $version;
585
586         if ($action == 'browse')
587             unset($attr['action']);
588
589         return $this->makeButton($label, WikiURL($pagename, $attr), $class);
590     }
591
592     /**
593      * Make a "button" which links to a wiki-page.
594      *
595      * These are really just regular WikiLinks, possibly
596      * disguised (e.g. behind an image button) by the theme.
597      *
598      * This method should probably only be used for links
599      * which appear in page navigation bars, or similar places.
600      *
601      * Use linkExistingWikiWord, or LinkWikiWord for normal links.
602      *
603      * @param $page_or_rev mixed The page to link to.  This can be
604      * given as a string (the page name), a WikiDB_Page object, or as
605      * WikiDB_PageRevision object.  If given as a WikiDB_PageRevision
606      * object, the button will link to a specific version of the
607      * designated page, otherwise the button links to the most recent
608      * version of the page.
609      *
610      * @return object A Button object.
611      */
612     function makeLinkButton ($page_or_rev) {
613         extract($this->_get_name_and_rev($page_or_rev));
614
615         $args = $version ? array('version' => $version) : false;
616
617         return $this->makeButton($pagename, WikiURL($pagename, $args), 'wiki');
618     }
619
620     function _get_name_and_rev ($page_or_rev) {
621         $version = false;
622
623         if (empty($page_or_rev)) {
624             global $request;
625             $pagename = $request->getArg("pagename");
626             $version = $request->getArg("version");
627         }
628         elseif (is_object($page_or_rev)) {
629             if (isa($page_or_rev, 'WikiDB_PageRevision')) {
630                 $rev = $page_or_rev;
631                 $page = $rev->getPage();
632                 $version = $rev->getVersion();
633             }
634             else {
635                 $page = $page_or_rev;
636             }
637             $pagename = $page->getName();
638         }
639         else {
640             $pagename = (string) $page_or_rev;
641         }
642         return compact('pagename', 'version');
643     }
644
645     function _labelForAction ($action) {
646         switch ($action) {
647             case 'edit':   return _("Edit");
648             case 'diff':   return _("Diff");
649             case 'logout': return _("Sign Out");
650             case 'login':  return _("Sign In");
651             case 'lock':   return _("Lock Page");
652             case 'unlock': return _("Unlock Page");
653             case 'remove': return _("Remove Page");
654             default:
655                 // I don't think the rest of these actually get used.
656                 // 'setprefs'
657                 // 'upload' 'dumpserial' 'loadfile' 'zip'
658                 // 'save' 'browse'
659                 return ucfirst($action);
660         }
661     }
662
663     //----------------------------------------------------------------
664     var $_buttonSeparator = ' | ';
665
666     function setButtonSeparator($separator) {
667         $this->_buttonSeparator = $separator;
668     }
669
670     function getButtonSeparator() {
671         return $this->_buttonSeparator;
672     }
673
674
675     ////////////////////////////////////////////////////////////////
676     //
677     // CSS
678     //
679     ////////////////////////////////////////////////////////////////
680
681     function _CSSlink($title, $css_file, $media, $is_alt = false) {
682         $link = HTML::link(array('rel'     => $is_alt ? 'alternate stylesheet' : 'stylesheet',
683                                  'title'   => $title,
684                                  'type'    => 'text/css',
685                                  'charset' => CHARSET,
686                                  'href'    => $this->_findData($css_file)));
687         if ($media)
688             $link->setAttr('media', $media);
689         return $link;
690     }
691
692     function setDefaultCSS ($title, $css_file, $media = false) {
693         if (isset($this->_defaultCSS)) {
694             $oldtitle = $this->_defaultCSS->_attr['title'];
695             $error = sprintf("'%s' -> '%s'", $oldtitle, $title);
696             trigger_error(sprintf(_("Redefinition of default CSS: %s"), $error),
697                           E_USER_NOTICE);
698         }
699         if (isset($this->_alternateCSS))
700             unset($this->_alternateCSS[$title]);
701         $this->_defaultCSS = $this->_CSSlink($title, $css_file, $media);
702     }
703
704     function addAlternateCSS ($title, $css_file, $media = false) {
705         $this->_alternateCSS[$title] = $this->_CSSlink($title, $css_file, $media, true);
706     }
707
708     /**
709         * @return string HTML for CSS.
710      */
711     function getCSS () {
712         $css = HTML($this->_defaultCSS);
713         if (!empty($this->_alternateCSS))
714             $css->pushContent($this->_alternateCSS);
715         return $css;
716     }
717
718     function findTemplate ($name) {
719         return $this->_path . $this->_findFile("templates/$name.tmpl");
720     }
721 };
722
723
724 /**
725  * A class representing a clickable "button".
726  *
727  * In it's simplest (default) form, a "button" is just a link associated
728  * with some sort of wiki-action.
729  */
730 class Button extends HtmlElement {
731     /** Constructor
732      *
733      * @param $text string The text for the button.
734      * @param $url string The url (href) for the button.
735      * @param $class string The CSS class for the button.
736      */
737     function Button ($text, $url, $class = false) {
738         $this->HtmlElement('a', array('href' => $url));
739         if ($class)
740             $this->setAttr('class', $class);
741         $this->pushContent($text);
742     }
743
744 };
745
746
747 /**
748  * A clickable image button.
749  */
750 class ImageButton extends Button {
751     /** Constructor
752      *
753      * @param $text string The text for the button.
754      * @param $url string The url (href) for the button.
755      * @param $class string The CSS class for the button.
756      * @param $img_url string URL for button's image.
757      * @param $img_attr array Additional attributes for the &lt;img&gt; tag.
758      */
759     function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
760         $this->HtmlElement('a', array('href' => $url));
761         if ($class)
762             $this->setAttr('class', $class);
763
764         if (!is_array($img_attr))
765             $img_attr = array();
766         $img_attr['src'] = $img_url;
767         $img_attr['alt'] = $text;
768         $img_attr['class'] = 'wiki-button';
769         $img_attr['border'] = 0;
770         $this->pushContent(HTML::img($img_attr));
771     }
772 };
773
774 /**
775  * A class representing a form <samp>submit</samp> button.
776  */
777 class SubmitButton extends HtmlElement {
778     /** Constructor
779      *
780      * @param $text string The text for the button.
781      * @param $name string The name of the form field.
782      * @param $class string The CSS class for the button.
783      */
784     function SubmitButton ($text, $name = false, $class = false) {
785         $this->HtmlElement('input', array('type' => 'submit',
786                                           'value' => $text));
787         if ($name)
788             $this->setAttr('name', $name);
789         if ($class)
790             $this->setAttr('class', $class);
791     }
792
793 };
794
795
796 /**
797  * A class representing an image form <samp>submit</samp> button.
798  */
799 class SubmitImageButton extends SubmitButton {
800     /** Constructor
801      *
802      * @param $text string The text for the button.
803      * @param $name string The name of the form field.
804      * @param $class string The CSS class for the button.
805      * @param $img_url string URL for button's image.
806      * @param $img_attr array Additional attributes for the &lt;img&gt; tag.
807      */
808     function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
809         $this->HtmlElement('input', array('type'  => 'image',
810                                           'src'   => $img_url,
811                                           'value' => $text,
812                                           'alt'   => $text));
813         if ($name)
814             $this->setAttr('name', $name);
815         if ($class)
816             $this->setAttr('class', $class);
817     }
818
819 };
820
821
822 // (c-file-style: "gnu")
823 // Local Variables:
824 // mode: php
825 // tab-width: 8
826 // c-basic-offset: 4
827 // c-hanging-comment-ender-p: nil
828 // indent-tabs-mode: nil
829 // End:
830 ?>