1 <?php rcs_id('$Id: Theme.php,v 1.71 2004-02-15 21:34:37 rurban 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) {
374 if (is_numeric($request->getPref('timeOffset')))
375 $offset = 3600 * $request->getPref('timeOffset');
379 $now = time() + $offset;
380 $today = localtime($now, true);
381 $time = localtime($time_t + $offset, true);
383 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
386 // Note that due to daylight savings chages (and leap seconds), $now minus
387 // 24 hours is not guaranteed to be yesterday.
388 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
389 if ($time['tm_yday'] == $yesterday['tm_yday'] && $time['tm_year'] == $yesterday['tm_year'])
390 return _("yesterday");
395 ////////////////////////////////////////////////////////////////
397 // Hooks for other formatting
399 ////////////////////////////////////////////////////////////////
401 //FIXME: PHP 4.1 Warnings
402 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
403 //use the call_user_func variety with the array(&$obj, "method") syntax instead
405 function getFormatter ($type, $format) {
406 $method = strtolower("get${type}Formatter");
407 if (method_exists($this, $method))
408 return $this->{$method}($format);
412 ////////////////////////////////////////////////////////////////
416 ////////////////////////////////////////////////////////////////
418 var $_autosplitWikiWords = false;
420 function setAutosplitWikiWords($autosplit=false) {
421 $this->_autosplitWikiWords = $autosplit ? true : false;
424 function maybeSplitWikiWord ($wikiword) {
425 if ($this->_autosplitWikiWords)
426 return split_pagename($wikiword);
431 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
434 if ($version !== false)
435 $url = WikiURL($wikiword, array('version' => $version));
437 $url = WikiURL($wikiword);
439 // Extra steps for dumping page to an html file.
440 // FIXME: shouldn't this be in WikiURL?
441 if ($this->HTML_DUMP_SUFFIX) {
442 // urlencode for pagenames with accented letters
443 $url = rawurlencode($url);
444 $url = preg_replace('/^\./', '%2e', $url);
445 $url .= $this->HTML_DUMP_SUFFIX;
448 $link = HTML::a(array('href' => $url));
450 if (isa($wikiword, 'WikiPageName'))
451 $default_text = $wikiword->shortName;
453 $default_text = $wikiword;
455 if (!empty($linktext)) {
456 $link->pushContent($linktext);
457 $link->setAttr('class', 'named-wiki');
458 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
461 $link->pushContent($this->maybeSplitWikiWord($default_text));
462 $link->setAttr('class', 'wiki');
464 if ($request->getArg('frame'))
465 $link->setAttr('target', '_top');
469 function linkUnknownWikiWord($wikiword, $linktext = '') {
472 // Get rid of anchors on unknown wikiwords
473 if (isa($wikiword, 'WikiPageName')) {
474 $default_text = $wikiword->shortName;
475 $wikiword = $wikiword->name;
478 $default_text = $wikiword;
481 $url = WikiURL($wikiword, array('action' => 'create'));
483 $button = $this->makeButton('?', $url);
484 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
485 $link = HTML::span($button);
488 if (!empty($linktext)) {
489 $link->pushContent(HTML::u($linktext));
490 $link->setAttr('class', 'named-wikiunknown');
493 $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
494 $link->setAttr('class', 'wikiunknown');
496 if ($request->getArg('frame'))
497 $link->setAttr('target', '_top');
502 function linkBadWikiWord($wikiword, $linktext = '') {
503 global $ErrorManager;
508 elseif (isa($wikiword, 'WikiPageName')) {
509 $text = $wikiword->shortName;
515 if (isa($wikiword, 'WikiPageName'))
516 $message = $wikiword->getWarnings();
518 $message = sprintf(_("'%s': Bad page name"), $wikiword);
519 $ErrorManager->warning($message);
521 return HTML::span(array('class' => 'badwikiword'), $text);
524 ////////////////////////////////////////////////////////////////
528 ////////////////////////////////////////////////////////////////
529 var $_imageAliases = array();
530 var $_imageAlt = array();
534 * (To disable an image, alias the image to <code>false</code>.
536 function addImageAlias ($alias, $image_name) {
537 // fall back to the PhpWiki-supplied image if not found
538 if ($this->_findFile("images/$image_name", true))
539 $this->_imageAliases[$alias] = $image_name;
542 function addImageAlt ($alias, $alt_text) {
543 $this->_imageAlt[$alias] = $alt_text;
545 function getImageAlt ($alias) {
546 return $this->_imageAlt[$alias];
549 function getImageURL ($image) {
550 $aliases = &$this->_imageAliases;
552 if (isset($aliases[$image])) {
553 $image = $aliases[$image];
558 // If not extension, default to .png.
559 if (!preg_match('/\.\w+$/', $image))
562 // FIXME: this should probably be made to fall back
563 // automatically to .gif, .jpg.
564 // Also try .gif before .png if browser doesn't like png.
566 $path = $this->_findData("images/$image", 'missing okay');
567 if (!$path) // search explicit images/ or button/ links also
568 return $this->_findData("$image", 'missing okay');
573 function setLinkIcon($proto, $image = false) {
577 $this->_linkIcons[$proto] = $image;
580 function getLinkIconURL ($proto) {
581 $icons = &$this->_linkIcons;
582 if (!empty($icons[$proto]))
583 return $this->getImageURL($icons[$proto]);
584 elseif (!empty($icons['*']))
585 return $this->getImageURL($icons['*']);
589 function addButtonAlias ($text, $alias = false) {
590 $aliases = &$this->_buttonAliases;
593 $aliases = array_merge($aliases, $text);
594 elseif ($alias === false)
595 unset($aliases[$text]);
597 $aliases[$text] = $alias;
600 function getButtonURL ($text) {
601 $aliases = &$this->_buttonAliases;
602 if (isset($aliases[$text]))
603 $text = $aliases[$text];
605 $qtext = urlencode($text);
606 $url = $this->_findButton("$qtext.png");
607 if ($url && strstr($url, '%')) {
608 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
610 if (!$url) {// Jeff complained about png not supported everywhere. This is not PC
611 $url = $this->_findButton("$qtext.gif");
612 if ($url && strstr($url, '%')) {
613 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
619 function _findButton ($button_file) {
620 if (!isset($this->_button_path))
621 $this->_button_path = $this->_getButtonPath();
623 foreach ($this->_button_path as $dir) {
624 $path = "$this->_theme/$dir/$button_file";
625 if (file_exists($this->_path . $path))
626 return defined('DATA_PATH') ? DATA_PATH . "/$path" : $path;
631 function _getButtonPath () {
632 $button_dir = $this->file("buttons");
633 if (!file_exists($button_dir) || !is_dir($button_dir))
636 $path = array('buttons');
638 $dir = dir($button_dir);
639 while (($subdir = $dir->read()) !== false) {
640 if ($subdir[0] == '.')
642 if (is_dir("$button_dir/$subdir"))
643 $path[] = "buttons/$subdir";
650 ////////////////////////////////////////////////////////////////
654 ////////////////////////////////////////////////////////////////
656 function makeButton ($text, $url, $class = false) {
657 // FIXME: don't always try for image button?
659 // Special case: URLs like 'submit:preview' generate form
660 // submission buttons.
661 if (preg_match('/^submit:(.*)$/', $url, $m))
662 return $this->makeSubmitButton($text, $m[1], $class);
664 $imgurl = $this->getButtonURL($text);
666 return new ImageButton($text, $url, $class, $imgurl);
668 return new Button($text, $url, $class);
671 function makeSubmitButton ($text, $name, $class = false) {
672 $imgurl = $this->getButtonURL($text);
675 return new SubmitImageButton($text, $name, $class, $imgurl);
677 return new SubmitButton($text, $name, $class);
681 * Make button to perform action.
683 * This constructs a button which performs an action on the
684 * currently selected version of the current page.
685 * (Or anotherpage or version, if you want...)
687 * @param $action string The action to perform (e.g. 'edit', 'lock').
688 * This can also be the name of an "action page" like 'LikePages'.
689 * Alternatively you can give a hash of query args to be applied
692 * @param $label string Textual label for the button. If left empty,
693 * a suitable name will be guessed.
695 * @param $page_or_rev mixed The page to link to. This can be
696 * given as a string (the page name), a WikiDB_Page object, or as
697 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
698 * object, the button will link to a specific version of the
699 * designated page, otherwise the button links to the most recent
700 * version of the page.
702 * @return object A Button object.
704 function makeActionButton ($action, $label = false, $page_or_rev = false) {
705 extract($this->_get_name_and_rev($page_or_rev));
707 if (is_array($action)) {
709 $action = isset($attr['action']) ? $attr['action'] : 'browse';
712 $attr['action'] = $action;
714 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
716 $label = $this->_labelForAction($action);
719 $attr['version'] = $version;
721 if ($action == 'browse')
722 unset($attr['action']);
724 return $this->makeButton($label, WikiURL($pagename, $attr), $class);
728 * Make a "button" which links to a wiki-page.
730 * These are really just regular WikiLinks, possibly
731 * disguised (e.g. behind an image button) by the theme.
733 * This method should probably only be used for links
734 * which appear in page navigation bars, or similar places.
736 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
738 * @param $page_or_rev mixed The page to link to. This can be
739 * given as a string (the page name), a WikiDB_Page object, or as
740 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
741 * object, the button will link to a specific version of the
742 * designated page, otherwise the button links to the most recent
743 * version of the page.
745 * @return object A Button object.
747 function makeLinkButton ($page_or_rev, $label = false) {
748 extract($this->_get_name_and_rev($page_or_rev));
750 $args = $version ? array('version' => $version) : false;
752 return $this->makeButton($label ? $label : $this->maybeSplitWikiWord($pagename),
753 WikiURL($pagename, $args), 'wiki');
756 function _get_name_and_rev ($page_or_rev) {
759 if (empty($page_or_rev)) {
761 $pagename = $request->getArg("pagename");
762 $version = $request->getArg("version");
764 elseif (is_object($page_or_rev)) {
765 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
767 $page = $rev->getPage();
768 $version = $rev->getVersion();
771 $page = $page_or_rev;
773 $pagename = $page->getName();
776 $pagename = (string) $page_or_rev;
778 return compact('pagename', 'version');
781 function _labelForAction ($action) {
783 case 'edit': return _("Edit");
784 case 'diff': return _("Diff");
785 case 'logout': return _("Sign Out");
786 case 'login': return _("Sign In");
787 case 'lock': return _("Lock Page");
788 case 'unlock': return _("Unlock Page");
789 case 'remove': return _("Remove Page");
791 // I don't think the rest of these actually get used.
793 // 'upload' 'dumpserial' 'loadfile' 'zip'
795 return gettext(ucfirst($action));
799 //----------------------------------------------------------------
800 var $_buttonSeparator = "\n | ";
802 function setButtonSeparator($separator) {
803 $this->_buttonSeparator = $separator;
806 function getButtonSeparator() {
807 return $this->_buttonSeparator;
811 ////////////////////////////////////////////////////////////////
817 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
818 // Automatic media-based style selection (via <link> tags) only
819 // seems to work for the default style, not for alternate styles.
823 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
824 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
826 // works to make it so that the printer style sheet get used
827 // automatically when printing (or print-previewing) a page
828 // (but when only when the default style is selected.)
832 // <link rel="alternate stylesheet" title="Modern"
833 // type="text/css" href="phpwiki-modern.css" />
834 // <link rel="alternate stylesheet" title="Modern"
835 // type="text/css" href="phpwiki-printer.css" media="print" />
837 // Result in two "Modern" choices when trying to select alternate style.
838 // If one selects the first of those choices, one gets phpwiki-modern
839 // both when browsing and printing. If one selects the second "Modern",
840 // one gets no CSS when browsing, and phpwiki-printer when printing.
845 // We should probably move to doing the media based style
846 // switching in the CSS files themselves using, e.g.:
848 // @import url(print.css) print;
850 ////////////////////////////////////////////////////////////////
852 function _CSSlink($title, $css_file, $media, $is_alt = false) {
853 // Don't set title on default style. This makes it clear to
854 // the user which is the default (i.e. most supported) style.
855 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
856 'type' => 'text/css',
857 'charset' => CHARSET,
858 'href' => $this->_findData($css_file)));
860 $link->setAttr('title', $title);
863 $link->setAttr('media', $media);
868 /** Set default CSS source for this theme.
870 * To set styles to be used for different media, pass a
871 * hash for the second argument, e.g.
873 * $theme->setDefaultCSS('default', array('' => 'normal.css',
874 * 'print' => 'printer.css'));
876 * If you call this more than once, the last one called takes
877 * precedence as the default style.
879 * @param string $title Name of style (currently ignored, unless
880 * you call this more than once, in which case, some of the style
881 * will become alternate (rather than default) styles, and then their
882 * titles will be used.
884 * @param mixed $css_files Name of CSS file, or hash containing a mapping
885 * between media types and CSS file names. Use a key of '' (the empty string)
886 * to set the default CSS for non-specified media. (See above for an example.)
888 function setDefaultCSS ($title, $css_files) {
889 if (!is_array($css_files))
890 $css_files = array('' => $css_files);
891 // Add to the front of $this->_css
892 unset($this->_css[$title]);
893 $this->_css = array_merge(array($title => $css_files), $this->_css);
896 /** Set alternate CSS source for this theme.
898 * @param string $title Name of style.
899 * @param string $css_files Name of CSS file.
901 function addAlternateCSS ($title, $css_files) {
902 if (!is_array($css_files))
903 $css_files = array('' => $css_files);
904 $this->_css[$title] = $css_files;
908 * @return string HTML for CSS.
913 foreach ($this->_css as $title => $css_files) {
914 ksort($css_files); // move $css_files[''] to front.
915 foreach ($css_files as $media => $css_file) {
916 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
926 function findTemplate ($name) {
927 return $this->_path . $this->_findFile("templates/$name.tmpl");
930 var $_MoreHeaders = array();
931 function addMoreHeaders ($element) {
932 array_push($this->_MoreHeaders,$element);
934 function getMoreHeaders () {
935 if (empty($this->_MoreHeaders))
938 //$out = "<!-- More Headers -->\n";
939 foreach ($this->_MoreHeaders as $h) {
941 $out .= printXML($h);
948 var $_MoreAttr = array();
949 function addMoreAttr ($id,$element) {
950 if (empty($this->_MoreAttr) or !is_array($this->_MoreAttr[$id]))
951 $this->_MoreAttr[$id] = array($element);
953 array_push($this->_MoreAttr[$id],$element);
955 function getMoreAttr ($id) {
956 if (empty($this->_MoreAttr[$id]))
959 foreach ($this->_MoreAttr[$id] as $h) {
961 $out .= printXML($h);
971 * A class representing a clickable "button".
973 * In it's simplest (default) form, a "button" is just a link associated
974 * with some sort of wiki-action.
976 class Button extends HtmlElement {
979 * @param $text string The text for the button.
980 * @param $url string The url (href) for the button.
981 * @param $class string The CSS class for the button.
983 function Button ($text, $url, $class = false) {
985 $this->HtmlElement('a', array('href' => $url));
987 $this->setAttr('class', $class);
988 if ($request->getArg('frame'))
989 $this->setAttr('target', '_top');
990 $this->pushContent($GLOBALS['Theme']->maybeSplitWikiWord($text));
997 * A clickable image button.
999 class ImageButton extends Button {
1002 * @param $text string The text for the button.
1003 * @param $url string The url (href) for the button.
1004 * @param $class string The CSS class for the button.
1005 * @param $img_url string URL for button's image.
1006 * @param $img_attr array Additional attributes for the <img> tag.
1008 function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
1009 $this->HtmlElement('a', array('href' => $url));
1011 $this->setAttr('class', $class);
1013 if (!is_array($img_attr))
1014 $img_attr = array();
1015 $img_attr['src'] = $img_url;
1016 $img_attr['alt'] = $text;
1017 $img_attr['class'] = 'wiki-button';
1018 $img_attr['border'] = 0;
1019 $this->pushContent(HTML::img($img_attr));
1024 * A class representing a form <samp>submit</samp> button.
1026 class SubmitButton extends HtmlElement {
1029 * @param $text string The text for the button.
1030 * @param $name string The name of the form field.
1031 * @param $class string The CSS class for the button.
1033 function SubmitButton ($text, $name = false, $class = false) {
1034 $this->HtmlElement('input', array('type' => 'submit',
1037 $this->setAttr('name', $name);
1039 $this->setAttr('class', $class);
1046 * A class representing an image form <samp>submit</samp> button.
1048 class SubmitImageButton extends SubmitButton {
1051 * @param $text string The text for the button.
1052 * @param $name string The name of the form field.
1053 * @param $class string The CSS class for the button.
1054 * @param $img_url string URL for button's image.
1055 * @param $img_attr array Additional attributes for the <img> tag.
1057 function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
1058 $this->HtmlElement('input', array('type' => 'image',
1063 $this->setAttr('name', $name);
1065 $this->setAttr('class', $class);
1070 // $Log: not supported by cvs2svn $
1071 // Revision 1.70 2004/01/26 09:17:48 rurban
1072 // * changed stored pref representation as before.
1073 // the array of objects is 1) bigger and 2)
1074 // less portable. If we would import packed pref
1075 // objects and the object definition was changed, PHP would fail.
1076 // This doesn't happen with an simple array of non-default values.
1077 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1078 // understands the interim format of array of objects also.
1079 // * simplified $prefs->get() and fixed $prefs->set()
1080 // * added $user->_userid and class '_WikiUser' portability functions
1081 // * fixed $user object ->_level upgrading, mostly using sessions.
1082 // this fixes yesterdays problems with loosing authorization level.
1083 // * fixed WikiUserNew::checkPass to return the _level
1084 // * fixed WikiUserNew::isSignedIn
1085 // * added explodePageList to class PageList, support sortby arg
1086 // * fixed UserPreferences for WikiUserNew
1087 // * fixed WikiPlugin for empty defaults array
1088 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1089 // removed sort arg, support sortby arg
1091 // Revision 1.69 2003/12/05 01:32:28 carstenklapp
1092 // New feature: Easier to run multiple wiks off of one set of code. Name
1093 // your logo and signature image files "YourWikiNameLogo.png" and
1094 // "YourWikiNameSignature.png" and put them all into
1095 // themes/default/images. YourWikiName should match what is defined as
1096 // WIKI_NAME in index.php. In case the image is not found, the default
1097 // shipped with PhpWiki will be used.
1099 // Revision 1.68 2003/03/04 01:53:30 dairiki
1100 // Inconsequential decrufting.
1102 // Revision 1.67 2003/02/26 03:40:22 dairiki
1103 // New action=create. Essentially the same as action=edit, except that if the
1104 // page already exists, it falls back to action=browse.
1106 // This is for use in the "question mark" links for unknown wiki words
1107 // to avoid problems and confusion when following links from stale pages.
1108 // (If the "unknown page" has been created in the interim, the user probably
1109 // wants to view the page before editing it.)
1111 // Revision 1.66 2003/02/26 00:10:26 dairiki
1112 // More/better/different checks for bad page names.
1114 // Revision 1.65 2003/02/24 22:41:57 dairiki
1117 // Revision 1.64 2003/02/24 22:06:14 dairiki
1118 // Attempts to fix auto-selection of printer CSS when printing.
1119 // See new comments lib/Theme.php for more details.
1120 // Also see SF patch #669563.
1122 // Revision 1.63 2003/02/23 03:37:05 dairiki
1123 // Stupid typo/bug fix.
1125 // Revision 1.62 2003/02/21 04:14:52 dairiki
1126 // New WikiLink type 'if_known'. This gives linkified name if page
1127 // exists, otherwise, just plain text.
1129 // Revision 1.61 2003/02/18 21:52:05 dairiki
1130 // Fix so that one can still link to wiki pages with # in their names.
1131 // (This was made difficult by the introduction of named tags, since
1132 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
1134 // Now the ~ escape for page names should work: [Page ~#1].
1136 // Revision 1.60 2003/02/15 01:59:47 dairiki
1137 // Theme::getCSS(): Add Default-Style HTTP(-eqiv) header in attempt
1138 // to fix default stylesheet selection on some browsers.
1139 // For details on the Default-Style header, see:
1140 // http://home.dairiki.org/docs/html4/present/styles.html#h-14.3.2
1142 // Revision 1.59 2003/01/04 22:30:16 carstenklapp
1143 // New: display a "Never edited." message instead of an invalid epoch date.
1146 // (c-file-style: "gnu")
1150 // c-basic-offset: 4
1151 // c-hanging-comment-ender-p: nil
1152 // indent-tabs-mode: nil