1 <?php rcs_id('$Id: Theme.php,v 1.69 2003-12-05 01:32:28 carstenklapp Exp $');
3 require_once('lib/HtmlElement.php');
7 * Make a link to a wiki page (in this wiki).
9 * This is a convenience function.
11 * @param mixed $page_or_rev
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>
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 * <dt>'if_known'</dt><dd>Only linkify if page exists.</dd>
26 * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown',
27 * 'named-wiki', or 'named-wikiunknown', as appropriate.
29 * @param mixed $label (string or XmlContent object)
30 * Label for the link. If not given, defaults to the page name.
32 * @return XmlContent The link
34 function WikiLink ($page_or_rev, $type = 'known', $label = false) {
35 global $Theme, $request;
37 if ($type == 'button') {
38 return $Theme->makeLinkButton($page_or_rev, $label);
43 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
44 $version = $page_or_rev->getVersion();
45 $page = $page_or_rev->getPage();
46 $pagename = $page->getName();
47 $wikipage = $pagename;
50 elseif (isa($page_or_rev, 'WikiDB_Page')) {
52 $pagename = $page->getName();
53 $wikipage = $pagename;
55 elseif (isa($page_or_rev, 'WikiPageName')) {
56 $wikipage = $page_or_rev;
57 $pagename = $wikipage->name;
60 $wikipage = new WikiPageName($page_or_rev, $request->getPage());
61 $pagename = $wikipage->name;
64 if (!is_string($wikipage) and !$wikipage->isValid('strict'))
65 return $Theme->linkBadWikiWord($wikipage, $label);
67 if ($type == 'auto' or $type == 'if_known') {
69 $current = $page->getCurrentRevision();
70 $exists = ! $current->hasDefaultContents();
73 $dbi = $request->getDbh();
74 $exists = $dbi->isWikiPage($wikipage->name);
77 elseif ($type == 'unknown') {
84 // FIXME: this should be somewhere else, if really needed.
85 // WikiLink makes A link, not a string of fancy ones.
86 // (I think that the fancy split links are just confusing.)
87 // Todo: test external ImageLinks http://some/images/next.gif
88 if (isa($wikipage, 'WikiPageName') and !$label
89 and strchr(substr($wikipage->shortName,1), SUBPAGE_SEPARATOR)) {
90 $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName);
91 $last_part = array_pop($parts);
94 foreach ($parts as $part) {
96 $parent = join(SUBPAGE_SEPARATOR, $path);
98 $link->pushContent($Theme->linkExistingWikiWord($parent, $sep . $part));
99 $sep = SUBPAGE_SEPARATOR;
102 $link->pushContent($Theme->linkExistingWikiWord($wikipage, $sep . $last_part, $version));
104 $link->pushContent($Theme->linkUnknownWikiWord($wikipage, $last_part));
109 return $Theme->linkExistingWikiWord($wikipage, $label, $version);
111 elseif ($type == 'if_known') {
112 if (!$label && isa($wikipage, 'WikiPageName'))
113 $label = $wikipage->shortName;
114 return HTML($label ? $label : $pagename);
117 return $Theme->linkUnknownWikiWord($wikipage, $label);
126 * This is a convenience function.
128 * @param $action string
130 * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
131 * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
132 * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
133 * ([name] can be blank for a nameless submit button.)</dd>
134 * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
135 * array('action' => 'diff', 'previous' => 'author')
139 * @param $label string
140 * A label for the button. If ommited, a suitable default (based on the valued of $action)
143 * @param $page_or_rev mixed
144 * Which page (& version) to perform the action on.
146 * <dt>A string</dt><dd>The pagename.</dd>
147 * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
148 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
150 * ($Page_or_rev is ignored for submit buttons.)
152 function Button ($action, $label = false, $page_or_rev = false) {
155 if (!is_array($action) && preg_match('/submit:(.*)/A', $action, $m))
156 return $Theme->makeSubmitButton($label, $m[1], $class = $page_or_rev);
158 return $Theme->makeActionButton($action, $label, $page_or_rev);
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";
168 $this->_path = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/" : "";
169 $this->_theme = "themes/$theme_name";
171 if ($theme_name != 'default')
172 $this->_default_theme = new Theme;
174 $this->_css = array();
177 function file ($file) {
178 return $this->_path . "$this->_theme/$file";
181 function _findFile ($file, $missing_okay = false) {
182 if (file_exists($this->_path . "$this->_theme/$file"))
183 return "$this->_theme/$file";
185 // FIXME: this is a short-term hack. Delete this after all files
186 // get moved into themes/...
187 if (file_exists($this->_path . $file))
191 if (isset($this->_default_theme)) {
192 return $this->_default_theme->_findFile($file, $missing_okay);
194 else if (!$missing_okay) {
195 trigger_error("$file: not found", E_USER_NOTICE);
200 function _findData ($file, $missing_okay = false) {
201 $path = $this->_findFile($file, $missing_okay);
205 if (defined('DATA_PATH'))
206 return DATA_PATH . "/$path";
210 ////////////////////////////////////////////////////////////////
212 // Date and Time formatting
214 ////////////////////////////////////////////////////////////////
216 // Note: Windows' implemetation of strftime does not include certain
217 // format specifiers, such as %e (for date without leading zeros). In
219 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
220 // As a result, we have to use %d, and strip out leading zeros ourselves.
222 var $_dateFormat = "%B %d, %Y";
223 var $_timeFormat = "%I:%M %p";
225 var $_showModTime = true;
228 * Set format string used for dates.
230 * @param $fs string Format string for dates.
232 * @param $show_mod_time bool If true (default) then times
233 * are included in the messages generated by getLastModifiedMessage(),
234 * otherwise, only the date of last modification will be shown.
236 function setDateFormat ($fs, $show_mod_time = true) {
237 $this->_dateFormat = $fs;
238 $this->_showModTime = $show_mod_time;
242 * Set format string used for times.
244 * @param $fs string Format string for times.
246 function setTimeFormat ($fs) {
247 $this->_timeFormat = $fs;
253 * Any time zone offset specified in the users preferences is
254 * taken into account by this method.
256 * @param $time_t integer Unix-style time.
258 * @return string The date.
260 function formatDate ($time_t) {
263 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
264 // strip leading zeros from date elements (ie space followed by zero)
265 return preg_replace('/ 0/', ' ',
266 strftime($this->_dateFormat, $offset_time));
272 * Any time zone offset specified in the users preferences is
273 * taken into account by this method.
275 * @param $time_t integer Unix-style time.
277 * @return string The time.
279 function formatTime ($time_t) {
280 //FIXME: make 24-hour mode configurable?
282 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
283 return preg_replace('/^0/', ' ',
284 strtolower(strftime($this->_timeFormat, $offset_time)));
288 * Format a date and time.
290 * Any time zone offset specified in the users preferences is
291 * taken into account by this method.
293 * @param $time_t integer Unix-style time.
295 * @return string The date and time.
297 function formatDateTime ($time_t) {
298 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
302 * Format a (possibly relative) date.
304 * If enabled in the users preferences, this method might
305 * return a relative day (e.g. 'Today', 'Yesterday').
307 * Any time zone offset specified in the users preferences is
308 * taken into account by this method.
310 * @param $time_t integer Unix-style time.
312 * @return string The day.
314 function getDay ($time_t) {
317 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
318 return ucfirst($date);
320 return $this->formatDate($time_t);
324 * Format the "last modified" message for a page revision.
326 * @param $revision object A WikiDB_PageRevision object.
328 * @param $show_version bool Should the page version number
329 * be included in the message. (If this argument is omitted,
330 * then the version number will be shown only iff the revision
331 * is not the current one.
333 * @return string The "last modified" message.
335 function getLastModifiedMessage ($revision, $show_version = 'auto') {
338 // dates >= this are considered invalid.
339 if (! defined('EPOCH'))
340 define('EPOCH', 0); // seconds since ~ January 1 1970
342 $mtime = $revision->get('mtime');
344 return fmt("Never edited.");
346 if ($show_version == 'auto')
347 $show_version = !$revision->isCurrent();
349 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
350 if ($this->_showModTime)
351 $date = sprintf(_("%s at %s"),
352 $date, $this->formatTime($mtime));
355 return fmt("Version %s, saved %s.", $revision->getVersion(), $date);
357 return fmt("Last edited %s.", $date);
360 if ($this->_showModTime)
361 $date = $this->formatDateTime($mtime);
363 $date = $this->formatDate($mtime);
366 return fmt("Version %s, saved on %s.", $revision->getVersion(), $date);
368 return fmt("Last edited on %s.", $date);
371 function _relativeDay ($time_t) {
373 $offset = 3600 * $request->getPref('timeOffset');
375 $now = time() + $offset;
376 $today = localtime($now, true);
377 $time = localtime($time_t + $offset, true);
379 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
382 // Note that due to daylight savings chages (and leap seconds), $now minus
383 // 24 hours is not guaranteed to be yesterday.
384 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
385 if ($time['tm_yday'] == $yesterday['tm_yday'] && $time['tm_year'] == $yesterday['tm_year'])
386 return _("yesterday");
391 ////////////////////////////////////////////////////////////////
393 // Hooks for other formatting
395 ////////////////////////////////////////////////////////////////
397 //FIXME: PHP 4.1 Warnings
398 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
399 //use the call_user_func variety with the array(&$obj, "method") syntax instead
401 function getFormatter ($type, $format) {
402 $method = strtolower("get${type}Formatter");
403 if (method_exists($this, $method))
404 return $this->{$method}($format);
408 ////////////////////////////////////////////////////////////////
412 ////////////////////////////////////////////////////////////////
414 var $_autosplitWikiWords = false;
416 function setAutosplitWikiWords($autosplit=false) {
417 $this->_autosplitWikiWords = $autosplit ? true : false;
420 function maybeSplitWikiWord ($wikiword) {
421 if ($this->_autosplitWikiWords)
422 return split_pagename($wikiword);
427 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
430 if ($version !== false)
431 $url = WikiURL($wikiword, array('version' => $version));
433 $url = WikiURL($wikiword);
435 // Extra steps for dumping page to an html file.
436 // FIXME: shouldn't this be in WikiURL?
437 if ($this->HTML_DUMP_SUFFIX) {
438 // urlencode for pagenames with accented letters
439 $url = rawurlencode($url);
440 $url = preg_replace('/^\./', '%2e', $url);
441 $url .= $this->HTML_DUMP_SUFFIX;
444 $link = HTML::a(array('href' => $url));
446 if (isa($wikiword, 'WikiPageName'))
447 $default_text = $wikiword->shortName;
449 $default_text = $wikiword;
451 if (!empty($linktext)) {
452 $link->pushContent($linktext);
453 $link->setAttr('class', 'named-wiki');
454 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
457 $link->pushContent($this->maybeSplitWikiWord($default_text));
458 $link->setAttr('class', 'wiki');
460 if ($request->getArg('frame'))
461 $link->setAttr('target', '_top');
465 function linkUnknownWikiWord($wikiword, $linktext = '') {
468 // Get rid of anchors on unknown wikiwords
469 if (isa($wikiword, 'WikiPageName')) {
470 $default_text = $wikiword->shortName;
471 $wikiword = $wikiword->name;
474 $default_text = $wikiword;
477 $url = WikiURL($wikiword, array('action' => 'create'));
479 $button = $this->makeButton('?', $url);
480 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
481 $link = HTML::span($button);
484 if (!empty($linktext)) {
485 $link->pushContent(HTML::u($linktext));
486 $link->setAttr('class', 'named-wikiunknown');
489 $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
490 $link->setAttr('class', 'wikiunknown');
492 if ($request->getArg('frame'))
493 $link->setAttr('target', '_top');
498 function linkBadWikiWord($wikiword, $linktext = '') {
499 global $ErrorManager;
504 elseif (isa($wikiword, 'WikiPageName')) {
505 $text = $wikiword->shortName;
511 if (isa($wikiword, 'WikiPageName'))
512 $message = $wikiword->getWarnings();
514 $message = sprintf(_("'%s': Bad page name"), $wikiword);
515 $ErrorManager->warning($message);
517 return HTML::span(array('class' => 'badwikiword'), $text);
520 ////////////////////////////////////////////////////////////////
524 ////////////////////////////////////////////////////////////////
525 var $_imageAliases = array();
526 var $_imageAlt = array();
530 * (To disable an image, alias the image to <code>false</code>.
532 function addImageAlias ($alias, $image_name) {
533 // fall back to the PhpWiki-supplied image if not found
534 if ($this->_findFile("images/$image_name", true))
535 $this->_imageAliases[$alias] = $image_name;
538 function addImageAlt ($alias, $alt_text) {
539 $this->_imageAlt[$alias] = $alt_text;
541 function getImageAlt ($alias) {
542 return $this->_imageAlt[$alias];
545 function getImageURL ($image) {
546 $aliases = &$this->_imageAliases;
548 if (isset($aliases[$image])) {
549 $image = $aliases[$image];
554 // If not extension, default to .png.
555 if (!preg_match('/\.\w+$/', $image))
558 // FIXME: this should probably be made to fall back
559 // automatically to .gif, .jpg.
560 // Also try .gif before .png if browser doesn't like png.
562 $path = $this->_findData("images/$image", 'missing okay');
563 if (!$path) // search explicit images/ or button/ links also
564 return $this->_findData("$image", 'missing okay');
569 function setLinkIcon($proto, $image = false) {
573 $this->_linkIcons[$proto] = $image;
576 function getLinkIconURL ($proto) {
577 $icons = &$this->_linkIcons;
578 if (!empty($icons[$proto]))
579 return $this->getImageURL($icons[$proto]);
580 elseif (!empty($icons['*']))
581 return $this->getImageURL($icons['*']);
585 function addButtonAlias ($text, $alias = false) {
586 $aliases = &$this->_buttonAliases;
589 $aliases = array_merge($aliases, $text);
590 elseif ($alias === false)
591 unset($aliases[$text]);
593 $aliases[$text] = $alias;
596 function getButtonURL ($text) {
597 $aliases = &$this->_buttonAliases;
598 if (isset($aliases[$text]))
599 $text = $aliases[$text];
601 $qtext = urlencode($text);
602 $url = $this->_findButton("$qtext.png");
603 if ($url && strstr($url, '%')) {
604 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
606 if (!$url) {// Jeff complained about png not supported everywhere. This is not PC
607 $url = $this->_findButton("$qtext.gif");
608 if ($url && strstr($url, '%')) {
609 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
615 function _findButton ($button_file) {
616 if (!isset($this->_button_path))
617 $this->_button_path = $this->_getButtonPath();
619 foreach ($this->_button_path as $dir) {
620 $path = "$this->_theme/$dir/$button_file";
621 if (file_exists($this->_path . $path))
622 return defined('DATA_PATH') ? DATA_PATH . "/$path" : $path;
627 function _getButtonPath () {
628 $button_dir = $this->file("buttons");
629 if (!file_exists($button_dir) || !is_dir($button_dir))
632 $path = array('buttons');
634 $dir = dir($button_dir);
635 while (($subdir = $dir->read()) !== false) {
636 if ($subdir[0] == '.')
638 if (is_dir("$button_dir/$subdir"))
639 $path[] = "buttons/$subdir";
646 ////////////////////////////////////////////////////////////////
650 ////////////////////////////////////////////////////////////////
652 function makeButton ($text, $url, $class = false) {
653 // FIXME: don't always try for image button?
655 // Special case: URLs like 'submit:preview' generate form
656 // submission buttons.
657 if (preg_match('/^submit:(.*)$/', $url, $m))
658 return $this->makeSubmitButton($text, $m[1], $class);
660 $imgurl = $this->getButtonURL($text);
662 return new ImageButton($text, $url, $class, $imgurl);
664 return new Button($text, $url, $class);
667 function makeSubmitButton ($text, $name, $class = false) {
668 $imgurl = $this->getButtonURL($text);
671 return new SubmitImageButton($text, $name, $class, $imgurl);
673 return new SubmitButton($text, $name, $class);
677 * Make button to perform action.
679 * This constructs a button which performs an action on the
680 * currently selected version of the current page.
681 * (Or anotherpage or version, if you want...)
683 * @param $action string The action to perform (e.g. 'edit', 'lock').
684 * This can also be the name of an "action page" like 'LikePages'.
685 * Alternatively you can give a hash of query args to be applied
688 * @param $label string Textual label for the button. If left empty,
689 * a suitable name will be guessed.
691 * @param $page_or_rev mixed The page to link to. This can be
692 * given as a string (the page name), a WikiDB_Page object, or as
693 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
694 * object, the button will link to a specific version of the
695 * designated page, otherwise the button links to the most recent
696 * version of the page.
698 * @return object A Button object.
700 function makeActionButton ($action, $label = false, $page_or_rev = false) {
701 extract($this->_get_name_and_rev($page_or_rev));
703 if (is_array($action)) {
705 $action = isset($attr['action']) ? $attr['action'] : 'browse';
708 $attr['action'] = $action;
710 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
712 $label = $this->_labelForAction($action);
715 $attr['version'] = $version;
717 if ($action == 'browse')
718 unset($attr['action']);
720 return $this->makeButton($label, WikiURL($pagename, $attr), $class);
724 * Make a "button" which links to a wiki-page.
726 * These are really just regular WikiLinks, possibly
727 * disguised (e.g. behind an image button) by the theme.
729 * This method should probably only be used for links
730 * which appear in page navigation bars, or similar places.
732 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
734 * @param $page_or_rev mixed The page to link to. This can be
735 * given as a string (the page name), a WikiDB_Page object, or as
736 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
737 * object, the button will link to a specific version of the
738 * designated page, otherwise the button links to the most recent
739 * version of the page.
741 * @return object A Button object.
743 function makeLinkButton ($page_or_rev, $label = false) {
744 extract($this->_get_name_and_rev($page_or_rev));
746 $args = $version ? array('version' => $version) : false;
748 return $this->makeButton($label ? $label : $this->maybeSplitWikiWord($pagename),
749 WikiURL($pagename, $args), 'wiki');
752 function _get_name_and_rev ($page_or_rev) {
755 if (empty($page_or_rev)) {
757 $pagename = $request->getArg("pagename");
758 $version = $request->getArg("version");
760 elseif (is_object($page_or_rev)) {
761 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
763 $page = $rev->getPage();
764 $version = $rev->getVersion();
767 $page = $page_or_rev;
769 $pagename = $page->getName();
772 $pagename = (string) $page_or_rev;
774 return compact('pagename', 'version');
777 function _labelForAction ($action) {
779 case 'edit': return _("Edit");
780 case 'diff': return _("Diff");
781 case 'logout': return _("Sign Out");
782 case 'login': return _("Sign In");
783 case 'lock': return _("Lock Page");
784 case 'unlock': return _("Unlock Page");
785 case 'remove': return _("Remove Page");
787 // I don't think the rest of these actually get used.
789 // 'upload' 'dumpserial' 'loadfile' 'zip'
791 return gettext(ucfirst($action));
795 //----------------------------------------------------------------
796 var $_buttonSeparator = "\n | ";
798 function setButtonSeparator($separator) {
799 $this->_buttonSeparator = $separator;
802 function getButtonSeparator() {
803 return $this->_buttonSeparator;
807 ////////////////////////////////////////////////////////////////
813 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
814 // Automatic media-based style selection (via <link> tags) only
815 // seems to work for the default style, not for alternate styles.
819 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
820 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
822 // works to make it so that the printer style sheet get used
823 // automatically when printing (or print-previewing) a page
824 // (but when only when the default style is selected.)
828 // <link rel="alternate stylesheet" title="Modern"
829 // type="text/css" href="phpwiki-modern.css" />
830 // <link rel="alternate stylesheet" title="Modern"
831 // type="text/css" href="phpwiki-printer.css" media="print" />
833 // Result in two "Modern" choices when trying to select alternate style.
834 // If one selects the first of those choices, one gets phpwiki-modern
835 // both when browsing and printing. If one selects the second "Modern",
836 // one gets no CSS when browsing, and phpwiki-printer when printing.
841 // We should probably move to doing the media based style
842 // switching in the CSS files themselves using, e.g.:
844 // @import url(print.css) print;
846 ////////////////////////////////////////////////////////////////
848 function _CSSlink($title, $css_file, $media, $is_alt = false) {
849 // Don't set title on default style. This makes it clear to
850 // the user which is the default (i.e. most supported) style.
851 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
852 'type' => 'text/css',
853 'charset' => CHARSET,
854 'href' => $this->_findData($css_file)));
856 $link->setAttr('title', $title);
859 $link->setAttr('media', $media);
864 /** Set default CSS source for this theme.
866 * To set styles to be used for different media, pass a
867 * hash for the second argument, e.g.
869 * $theme->setDefaultCSS('default', array('' => 'normal.css',
870 * 'print' => 'printer.css'));
872 * If you call this more than once, the last one called takes
873 * precedence as the default style.
875 * @param string $title Name of style (currently ignored, unless
876 * you call this more than once, in which case, some of the style
877 * will become alternate (rather than default) styles, and then their
878 * titles will be used.
880 * @param mixed $css_files Name of CSS file, or hash containing a mapping
881 * between media types and CSS file names. Use a key of '' (the empty string)
882 * to set the default CSS for non-specified media. (See above for an example.)
884 function setDefaultCSS ($title, $css_files) {
885 if (!is_array($css_files))
886 $css_files = array('' => $css_files);
887 // Add to the front of $this->_css
888 unset($this->_css[$title]);
889 $this->_css = array_merge(array($title => $css_files), $this->_css);
892 /** Set alternate CSS source for this theme.
894 * @param string $title Name of style.
895 * @param string $css_files Name of CSS file.
897 function addAlternateCSS ($title, $css_files) {
898 if (!is_array($css_files))
899 $css_files = array('' => $css_files);
900 $this->_css[$title] = $css_files;
904 * @return string HTML for CSS.
909 foreach ($this->_css as $title => $css_files) {
910 ksort($css_files); // move $css_files[''] to front.
911 foreach ($css_files as $media => $css_file) {
912 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
922 function findTemplate ($name) {
923 return $this->_path . $this->_findFile("templates/$name.tmpl");
929 * A class representing a clickable "button".
931 * In it's simplest (default) form, a "button" is just a link associated
932 * with some sort of wiki-action.
934 class Button extends HtmlElement {
937 * @param $text string The text for the button.
938 * @param $url string The url (href) for the button.
939 * @param $class string The CSS class for the button.
941 function Button ($text, $url, $class = false) {
943 $this->HtmlElement('a', array('href' => $url));
945 $this->setAttr('class', $class);
946 if ($request->getArg('frame'))
947 $this->setAttr('target', '_top');
948 $this->pushContent($GLOBALS['Theme']->maybeSplitWikiWord($text));
955 * A clickable image button.
957 class ImageButton extends Button {
960 * @param $text string The text for the button.
961 * @param $url string The url (href) for the button.
962 * @param $class string The CSS class for the button.
963 * @param $img_url string URL for button's image.
964 * @param $img_attr array Additional attributes for the <img> tag.
966 function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
967 $this->HtmlElement('a', array('href' => $url));
969 $this->setAttr('class', $class);
971 if (!is_array($img_attr))
973 $img_attr['src'] = $img_url;
974 $img_attr['alt'] = $text;
975 $img_attr['class'] = 'wiki-button';
976 $img_attr['border'] = 0;
977 $this->pushContent(HTML::img($img_attr));
982 * A class representing a form <samp>submit</samp> button.
984 class SubmitButton extends HtmlElement {
987 * @param $text string The text for the button.
988 * @param $name string The name of the form field.
989 * @param $class string The CSS class for the button.
991 function SubmitButton ($text, $name = false, $class = false) {
992 $this->HtmlElement('input', array('type' => 'submit',
995 $this->setAttr('name', $name);
997 $this->setAttr('class', $class);
1004 * A class representing an image form <samp>submit</samp> button.
1006 class SubmitImageButton extends SubmitButton {
1009 * @param $text string The text for the button.
1010 * @param $name string The name of the form field.
1011 * @param $class string The CSS class for the button.
1012 * @param $img_url string URL for button's image.
1013 * @param $img_attr array Additional attributes for the <img> tag.
1015 function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
1016 $this->HtmlElement('input', array('type' => 'image',
1021 $this->setAttr('name', $name);
1023 $this->setAttr('class', $class);
1028 // $Log: not supported by cvs2svn $
1029 // Revision 1.68 2003/03/04 01:53:30 dairiki
1030 // Inconsequential decrufting.
1032 // Revision 1.67 2003/02/26 03:40:22 dairiki
1033 // New action=create. Essentially the same as action=edit, except that if the
1034 // page already exists, it falls back to action=browse.
1036 // This is for use in the "question mark" links for unknown wiki words
1037 // to avoid problems and confusion when following links from stale pages.
1038 // (If the "unknown page" has been created in the interim, the user probably
1039 // wants to view the page before editing it.)
1041 // Revision 1.66 2003/02/26 00:10:26 dairiki
1042 // More/better/different checks for bad page names.
1044 // Revision 1.65 2003/02/24 22:41:57 dairiki
1047 // Revision 1.64 2003/02/24 22:06:14 dairiki
1048 // Attempts to fix auto-selection of printer CSS when printing.
1049 // See new comments lib/Theme.php for more details.
1050 // Also see SF patch #669563.
1052 // Revision 1.63 2003/02/23 03:37:05 dairiki
1053 // Stupid typo/bug fix.
1055 // Revision 1.62 2003/02/21 04:14:52 dairiki
1056 // New WikiLink type 'if_known'. This gives linkified name if page
1057 // exists, otherwise, just plain text.
1059 // Revision 1.61 2003/02/18 21:52:05 dairiki
1060 // Fix so that one can still link to wiki pages with # in their names.
1061 // (This was made difficult by the introduction of named tags, since
1062 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
1064 // Now the ~ escape for page names should work: [Page ~#1].
1066 // Revision 1.60 2003/02/15 01:59:47 dairiki
1067 // Theme::getCSS(): Add Default-Style HTTP(-eqiv) header in attempt
1068 // to fix default stylesheet selection on some browsers.
1069 // For details on the Default-Style header, see:
1070 // http://home.dairiki.org/docs/html4/present/styles.html#h-14.3.2
1072 // Revision 1.59 2003/01/04 22:30:16 carstenklapp
1073 // New: display a "Never edited." message instead of an invalid epoch date.
1076 // (c-file-style: "gnu")
1080 // c-basic-offset: 4
1081 // c-hanging-comment-ender-p: nil
1082 // indent-tabs-mode: nil