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