1 <?php rcs_id('$Id: Theme.php,v 1.82 2004-04-06 20:00:10 rurban Exp $');
2 /* Copyright (C) 2002, Geoffrey T. Dairiki <dairiki@dairiki.org>
4 * This file is part of PhpWiki.
6 * PhpWiki is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * PhpWiki is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with PhpWiki; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Customize output by themes: templates, css, special links functions,
23 * and more formatting.
26 require_once('lib/HtmlElement.php');
29 * Make a link to a wiki page (in this wiki).
31 * This is a convenience function.
33 * @param mixed $page_or_rev
35 * <dt>A string</dt><dd>The page to link to.</dd>
36 * <dt>A WikiDB_Page object</dt><dd>The page to link to.</dd>
37 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page to link to.</dd>
42 * <dt>'unknown'</dt><dd>Make link appropriate for a non-existant page.</dd>
43 * <dt>'known'</dt><dd>Make link appropriate for an existing page.</dd>
44 * <dt>'auto'</dt><dd>Either 'unknown' or 'known' as appropriate.</dd>
45 * <dt>'button'</dt><dd>Make a button-style link.</dd>
46 * <dt>'if_known'</dt><dd>Only linkify if page exists.</dd>
48 * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown',
49 * 'named-wiki', or 'named-wikiunknown', as appropriate.
51 * @param mixed $label (string or XmlContent object)
52 * Label for the link. If not given, defaults to the page name.
54 * @return XmlContent The link
56 function WikiLink ($page_or_rev, $type = 'known', $label = false) {
57 global $Theme, $request;
59 if ($type == 'button') {
60 return $Theme->makeLinkButton($page_or_rev, $label);
65 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
66 $version = $page_or_rev->getVersion();
67 $page = $page_or_rev->getPage();
68 $pagename = $page->getName();
69 $wikipage = $pagename;
72 elseif (isa($page_or_rev, 'WikiDB_Page')) {
74 $pagename = $page->getName();
75 $wikipage = $pagename;
77 elseif (isa($page_or_rev, 'WikiPageName')) {
78 $wikipage = $page_or_rev;
79 $pagename = $wikipage->name;
82 $wikipage = new WikiPageName($page_or_rev, $request->getPage());
83 $pagename = $wikipage->name;
86 if (!is_string($wikipage) and !$wikipage->isValid('strict'))
87 return $Theme->linkBadWikiWord($wikipage, $label);
89 if ($type == 'auto' or $type == 'if_known') {
91 $current = $page->getCurrentRevision();
92 $exists = ! $current->hasDefaultContents();
95 $dbi = $request->getDbh();
96 $exists = $dbi->isWikiPage($wikipage->name);
99 elseif ($type == 'unknown') {
106 // FIXME: this should be somewhere else, if really needed.
107 // WikiLink makes A link, not a string of fancy ones.
108 // (I think that the fancy split links are just confusing.)
109 // Todo: test external ImageLinks http://some/images/next.gif
110 if (isa($wikipage, 'WikiPageName') and !$label
111 and strchr(substr($wikipage->shortName,1), SUBPAGE_SEPARATOR)) {
112 $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName);
113 $last_part = array_pop($parts);
115 $link = HTML::span();
116 foreach ($parts as $part) {
118 $parent = join(SUBPAGE_SEPARATOR, $path);
120 $link->pushContent($Theme->linkExistingWikiWord($parent, $sep . $part));
121 $sep = SUBPAGE_SEPARATOR;
124 $link->pushContent($Theme->linkExistingWikiWord($wikipage, $sep . $last_part, $version));
126 $link->pushContent($Theme->linkUnknownWikiWord($wikipage, $last_part));
131 return $Theme->linkExistingWikiWord($wikipage, $label, $version);
133 elseif ($type == 'if_known') {
134 if (!$label && isa($wikipage, 'WikiPageName'))
135 $label = $wikipage->shortName;
136 return HTML($label ? $label : $pagename);
139 return $Theme->linkUnknownWikiWord($wikipage, $label);
148 * This is a convenience function.
150 * @param $action string
152 * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
153 * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
154 * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
155 * ([name] can be blank for a nameless submit button.)</dd>
156 * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
157 * array('action' => 'diff', 'previous' => 'author')
161 * @param $label string
162 * A label for the button. If ommited, a suitable default (based on the valued of $action)
165 * @param $page_or_rev mixed
166 * Which page (& version) to perform the action on.
168 * <dt>A string</dt><dd>The pagename.</dd>
169 * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
170 * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
172 * ($Page_or_rev is ignored for submit buttons.)
174 function Button ($action, $label = false, $page_or_rev = false) {
177 if (!is_array($action) && preg_match('/submit:(.*)/A', $action, $m))
178 return $Theme->makeSubmitButton($label, $m[1], $class = $page_or_rev);
180 return $Theme->makeActionButton($action, $label, $page_or_rev);
185 var $HTML_DUMP_SUFFIX = '';
186 var $DUMP_MODE = false, $dumped_images, $dumped_css;
188 function Theme ($theme_name = 'default') {
189 $this->_name = $theme_name;
190 $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes";
192 $this->_path = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/" : "";
193 $this->_theme = "themes/$theme_name";
195 if ($theme_name != 'default')
196 $this->_default_theme = new Theme;
198 $this->_css = array();
201 function file ($file) {
202 return $this->_path . "$this->_theme/$file";
205 function _findFile ($file, $missing_okay = false) {
206 if (file_exists($this->_path . "$this->_theme/$file"))
207 return "$this->_theme/$file";
209 // FIXME: this is a short-term hack. Delete this after all files
210 // get moved into themes/...
211 if (file_exists($this->_path . $file))
215 if (isset($this->_default_theme)) {
216 return $this->_default_theme->_findFile($file, $missing_okay);
218 else if (!$missing_okay) {
219 trigger_error("$file: not found", E_USER_NOTICE);
224 function _findData ($file, $missing_okay = false) {
225 $path = $this->_findFile($file, $missing_okay);
229 if (defined('DATA_PATH'))
230 return DATA_PATH . "/$path";
234 ////////////////////////////////////////////////////////////////
236 // Date and Time formatting
238 ////////////////////////////////////////////////////////////////
240 // Note: Windows' implemetation of strftime does not include certain
241 // format specifiers, such as %e (for date without leading zeros). In
243 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
244 // As a result, we have to use %d, and strip out leading zeros ourselves.
246 var $_dateFormat = "%B %d, %Y";
247 var $_timeFormat = "%I:%M %p";
249 var $_showModTime = true;
252 * Set format string used for dates.
254 * @param $fs string Format string for dates.
256 * @param $show_mod_time bool If true (default) then times
257 * are included in the messages generated by getLastModifiedMessage(),
258 * otherwise, only the date of last modification will be shown.
260 function setDateFormat ($fs, $show_mod_time = true) {
261 $this->_dateFormat = $fs;
262 $this->_showModTime = $show_mod_time;
266 * Set format string used for times.
268 * @param $fs string Format string for times.
270 function setTimeFormat ($fs) {
271 $this->_timeFormat = $fs;
277 * Any time zone offset specified in the users preferences is
278 * taken into account by this method.
280 * @param $time_t integer Unix-style time.
282 * @return string The date.
284 function formatDate ($time_t) {
287 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
288 // strip leading zeros from date elements (ie space followed by zero)
289 return preg_replace('/ 0/', ' ',
290 strftime($this->_dateFormat, $offset_time));
296 * Any time zone offset specified in the users preferences is
297 * taken into account by this method.
299 * @param $time_t integer Unix-style time.
301 * @return string The time.
303 function formatTime ($time_t) {
304 //FIXME: make 24-hour mode configurable?
306 $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
307 return preg_replace('/^0/', ' ',
308 strtolower(strftime($this->_timeFormat, $offset_time)));
312 * Format a date and time.
314 * Any time zone offset specified in the users preferences is
315 * taken into account by this method.
317 * @param $time_t integer Unix-style time.
319 * @return string The date and time.
321 function formatDateTime ($time_t) {
322 return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
326 * Format a (possibly relative) date.
328 * If enabled in the users preferences, this method might
329 * return a relative day (e.g. 'Today', 'Yesterday').
331 * Any time zone offset specified in the users preferences is
332 * taken into account by this method.
334 * @param $time_t integer Unix-style time.
336 * @return string The day.
338 function getDay ($time_t) {
341 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
342 return ucfirst($date);
344 return $this->formatDate($time_t);
348 * Format the "last modified" message for a page revision.
350 * @param $revision object A WikiDB_PageRevision object.
352 * @param $show_version bool Should the page version number
353 * be included in the message. (If this argument is omitted,
354 * then the version number will be shown only iff the revision
355 * is not the current one.
357 * @return string The "last modified" message.
359 function getLastModifiedMessage ($revision, $show_version = 'auto') {
362 // dates >= this are considered invalid.
363 if (! defined('EPOCH'))
364 define('EPOCH', 0); // seconds since ~ January 1 1970
366 $mtime = $revision->get('mtime');
368 return fmt("Never edited.");
370 if ($show_version == 'auto')
371 $show_version = !$revision->isCurrent();
373 if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
374 if ($this->_showModTime)
375 $date = sprintf(_("%s at %s"),
376 $date, $this->formatTime($mtime));
379 return fmt("Version %s, saved %s.", $revision->getVersion(), $date);
381 return fmt("Last edited %s.", $date);
384 if ($this->_showModTime)
385 $date = $this->formatDateTime($mtime);
387 $date = $this->formatDate($mtime);
390 return fmt("Version %s, saved on %s.", $revision->getVersion(), $date);
392 return fmt("Last edited on %s.", $date);
395 function _relativeDay ($time_t) {
398 if (is_numeric($request->getPref('timeOffset')))
399 $offset = 3600 * $request->getPref('timeOffset');
403 $now = time() + $offset;
404 $today = localtime($now, true);
405 $time = localtime($time_t + $offset, true);
407 if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
410 // Note that due to daylight savings chages (and leap seconds), $now minus
411 // 24 hours is not guaranteed to be yesterday.
412 $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
413 if ($time['tm_yday'] == $yesterday['tm_yday'] && $time['tm_year'] == $yesterday['tm_year'])
414 return _("yesterday");
419 ////////////////////////////////////////////////////////////////
421 // Hooks for other formatting
423 ////////////////////////////////////////////////////////////////
425 //FIXME: PHP 4.1 Warnings
426 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
427 //use the call_user_func variety with the array(&$obj, "method") syntax instead
429 function getFormatter ($type, $format) {
430 $method = strtolower("get${type}Formatter");
431 if (method_exists($this, $method))
432 return $this->{$method}($format);
436 ////////////////////////////////////////////////////////////////
440 ////////////////////////////////////////////////////////////////
442 var $_autosplitWikiWords = false;
444 function setAutosplitWikiWords($autosplit=false) {
445 $this->_autosplitWikiWords = $autosplit ? true : false;
448 function maybeSplitWikiWord ($wikiword) {
449 if ($this->_autosplitWikiWords)
450 return split_pagename($wikiword);
455 var $_anonEditUnknownLinks = true;
456 function setAnonEditUnknownLinks($anonedit=true) {
457 $this->_anonEditUnknownLinks = $anonedit ? true : false;
460 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
463 if ($version !== false)
464 $url = WikiURL($wikiword, array('version' => $version));
466 $url = WikiURL($wikiword);
468 // Extra steps for dumping page to an html file.
469 // FIXME: shouldn't this be in WikiURL?
470 if ($this->HTML_DUMP_SUFFIX) {
471 // no action or sortby links
472 $url = preg_replace("/\?.*$/","",$url);
473 // urlencode for pagenames with accented letters
474 $url = rawurlencode($url);
475 $url = preg_replace('/^\./', '%2e', $url);
476 // fix url#anchor links (looks awful)
477 if (strstr($url,'%23'))
478 $url = preg_replace("/%23/",$this->HTML_DUMP_SUFFIX."#",$url);
480 $url .= $this->HTML_DUMP_SUFFIX;
483 $link = HTML::a(array('href' => $url));
485 if (isa($wikiword, 'WikiPageName'))
486 $default_text = $wikiword->shortName;
488 $default_text = $wikiword;
490 if (!empty($linktext)) {
491 $link->pushContent($linktext);
492 $link->setAttr('class', 'named-wiki');
493 $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
496 $link->pushContent($this->maybeSplitWikiWord($default_text));
497 $link->setAttr('class', 'wiki');
499 if ($request->getArg('frame'))
500 $link->setAttr('target', '_top');
504 function linkUnknownWikiWord($wikiword, $linktext = '') {
507 // Get rid of anchors on unknown wikiwords
508 if (isa($wikiword, 'WikiPageName')) {
509 $default_text = $wikiword->shortName;
510 $wikiword = $wikiword->name;
513 $default_text = $wikiword;
516 if ($this->DUMP_MODE) { // HTML, PDF or XML
517 $link = HTML::u( empty($linktext) ? $wikiword : $linktext);
518 $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
519 $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
522 // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
523 if (! $this->_anonEditUnknownLinks and ! mayAccessPage('edit',$request->getArg('pagename'))) {
524 $text = HTML::span( empty($linktext) ? $wikiword : $linktext);
525 $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
528 $url = WikiURL($wikiword, array('action' => 'create'));
529 $button = $this->makeButton('?', $url);
530 $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
532 $link = HTML::span($button);
536 if (!empty($linktext)) {
537 $link->pushContent(HTML::u($linktext));
538 $link->setAttr('class', 'named-wikiunknown');
541 $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
542 $link->setAttr('class', 'wikiunknown');
544 if ($request->getArg('frame'))
545 $link->setAttr('target', '_top');
550 function linkBadWikiWord($wikiword, $linktext = '') {
551 global $ErrorManager;
556 elseif (isa($wikiword, 'WikiPageName')) {
557 $text = $wikiword->shortName;
563 if (isa($wikiword, 'WikiPageName'))
564 $message = $wikiword->getWarnings();
566 $message = sprintf(_("'%s': Bad page name"), $wikiword);
567 $ErrorManager->warning($message);
569 return HTML::span(array('class' => 'badwikiword'), $text);
572 ////////////////////////////////////////////////////////////////
576 ////////////////////////////////////////////////////////////////
577 var $_imageAliases = array();
578 var $_imageAlt = array();
582 * (To disable an image, alias the image to <code>false</code>.
584 function addImageAlias ($alias, $image_name) {
585 // fall back to the PhpWiki-supplied image if not found
586 if ($this->_findFile("images/$image_name", true))
587 $this->_imageAliases[$alias] = $image_name;
590 function addImageAlt ($alias, $alt_text) {
591 $this->_imageAlt[$alias] = $alt_text;
593 function getImageAlt ($alias) {
594 return $this->_imageAlt[$alias];
597 function getImageURL ($image) {
598 $aliases = &$this->_imageAliases;
600 if (isset($aliases[$image])) {
601 $image = $aliases[$image];
606 // If not extension, default to .png.
607 if (!preg_match('/\.\w+$/', $image))
610 // FIXME: this should probably be made to fall back
611 // automatically to .gif, .jpg.
612 // Also try .gif before .png if browser doesn't like png.
614 $path = $this->_findData("images/$image", 'missing okay');
615 if (!$path) // search explicit images/ or button/ links also
616 $path = $this->_findData("$image", 'missing okay');
618 if ($this->DUMP_MODE) {
619 if (empty($this->dumped_images)) $this->dumped_images = array();
620 $path = "images/". basename($path);
621 if (!in_array($path,$this->dumped_images)) $this->dumped_images[] = $path;
626 function setLinkIcon($proto, $image = false) {
630 $this->_linkIcons[$proto] = $image;
633 function getLinkIconURL ($proto) {
634 $icons = &$this->_linkIcons;
635 if (!empty($icons[$proto]))
636 return $this->getImageURL($icons[$proto]);
637 elseif (!empty($icons['*']))
638 return $this->getImageURL($icons['*']);
642 function addButtonAlias ($text, $alias = false) {
643 $aliases = &$this->_buttonAliases;
646 $aliases = array_merge($aliases, $text);
647 elseif ($alias === false)
648 unset($aliases[$text]);
650 $aliases[$text] = $alias;
653 function getButtonURL ($text) {
654 $aliases = &$this->_buttonAliases;
655 if (isset($aliases[$text]))
656 $text = $aliases[$text];
658 $qtext = urlencode($text);
659 $url = $this->_findButton("$qtext.png");
660 if ($url && strstr($url, '%')) {
661 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
663 if (!$url) {// Jeff complained about png not supported everywhere. This is not PC
664 $url = $this->_findButton("$qtext.gif");
665 if ($url && strstr($url, '%')) {
666 $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
672 function _findButton ($button_file) {
673 if (empty($this->_button_path))
674 $this->_button_path = $this->_getButtonPath();
676 foreach ($this->_button_path as $dir) {
677 $path = "$dir/$button_file";
678 if (file_exists($this->_path . $path))
679 return defined('DATA_PATH') ? DATA_PATH . "/$path" : $path;
684 function _getButtonPath () {
685 $button_dir = $this->_findFile("buttons");
686 $path_dir = $this->_path . $button_dir;
687 if (!file_exists($path_dir) || !is_dir($path_dir))
689 $path = array($button_dir);
690 $dir = dir($path_dir);
691 while (($subdir = $dir->read()) !== false) {
692 if ($subdir[0] == '.')
694 if ($subdir == 'CVS')
696 if (is_dir("$path_dir/$subdir"))
697 $path[] = "$button_dir/$subdir";
704 ////////////////////////////////////////////////////////////////
708 ////////////////////////////////////////////////////////////////
710 function makeButton ($text, $url, $class = false) {
711 // FIXME: don't always try for image button?
713 // Special case: URLs like 'submit:preview' generate form
714 // submission buttons.
715 if (preg_match('/^submit:(.*)$/', $url, $m))
716 return $this->makeSubmitButton($text, $m[1], $class);
718 $imgurl = $this->getButtonURL($text);
720 return new ImageButton($text, $url, $class, $imgurl);
722 return new Button($text, $url, $class);
725 function makeSubmitButton ($text, $name, $class = false) {
726 $imgurl = $this->getButtonURL($text);
729 return new SubmitImageButton($text, $name, $class, $imgurl);
731 return new SubmitButton($text, $name, $class);
735 * Make button to perform action.
737 * This constructs a button which performs an action on the
738 * currently selected version of the current page.
739 * (Or anotherpage or version, if you want...)
741 * @param $action string The action to perform (e.g. 'edit', 'lock').
742 * This can also be the name of an "action page" like 'LikePages'.
743 * Alternatively you can give a hash of query args to be applied
746 * @param $label string Textual label for the button. If left empty,
747 * a suitable name will be guessed.
749 * @param $page_or_rev mixed The page to link to. This can be
750 * given as a string (the page name), a WikiDB_Page object, or as
751 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
752 * object, the button will link to a specific version of the
753 * designated page, otherwise the button links to the most recent
754 * version of the page.
756 * @return object A Button object.
758 function makeActionButton ($action, $label = false, $page_or_rev = false) {
759 extract($this->_get_name_and_rev($page_or_rev));
761 if (is_array($action)) {
763 $action = isset($attr['action']) ? $attr['action'] : 'browse';
766 $attr['action'] = $action;
768 $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
770 $label = $this->_labelForAction($action);
773 $attr['version'] = $version;
775 if ($action == 'browse')
776 unset($attr['action']);
778 return $this->makeButton($label, WikiURL($pagename, $attr), $class);
782 * Make a "button" which links to a wiki-page.
784 * These are really just regular WikiLinks, possibly
785 * disguised (e.g. behind an image button) by the theme.
787 * This method should probably only be used for links
788 * which appear in page navigation bars, or similar places.
790 * Use linkExistingWikiWord, or LinkWikiWord for normal links.
792 * @param $page_or_rev mixed The page to link to. This can be
793 * given as a string (the page name), a WikiDB_Page object, or as
794 * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
795 * object, the button will link to a specific version of the
796 * designated page, otherwise the button links to the most recent
797 * version of the page.
799 * @return object A Button object.
801 function makeLinkButton ($page_or_rev, $label = false) {
802 extract($this->_get_name_and_rev($page_or_rev));
804 $args = $version ? array('version' => $version) : false;
806 return $this->makeButton($label ? $label : $this->maybeSplitWikiWord($pagename),
807 WikiURL($pagename, $args), 'wiki');
810 function _get_name_and_rev ($page_or_rev) {
813 if (empty($page_or_rev)) {
815 $pagename = $request->getArg("pagename");
816 $version = $request->getArg("version");
818 elseif (is_object($page_or_rev)) {
819 if (isa($page_or_rev, 'WikiDB_PageRevision')) {
821 $page = $rev->getPage();
822 $version = $rev->getVersion();
825 $page = $page_or_rev;
827 $pagename = $page->getName();
830 $pagename = (string) $page_or_rev;
832 return compact('pagename', 'version');
835 function _labelForAction ($action) {
837 case 'edit': return _("Edit");
838 case 'diff': return _("Diff");
839 case 'logout': return _("Sign Out");
840 case 'login': return _("Sign In");
841 case 'lock': return _("Lock Page");
842 case 'unlock': return _("Unlock Page");
843 case 'remove': return _("Remove Page");
845 // I don't think the rest of these actually get used.
847 // 'upload' 'dumpserial' 'loadfile' 'zip'
849 return gettext(ucfirst($action));
853 //----------------------------------------------------------------
854 var $_buttonSeparator = "\n | ";
856 function setButtonSeparator($separator) {
857 $this->_buttonSeparator = $separator;
860 function getButtonSeparator() {
861 return $this->_buttonSeparator;
865 ////////////////////////////////////////////////////////////////
871 // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
872 // Automatic media-based style selection (via <link> tags) only
873 // seems to work for the default style, not for alternate styles.
877 // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
878 // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
880 // works to make it so that the printer style sheet get used
881 // automatically when printing (or print-previewing) a page
882 // (but when only when the default style is selected.)
886 // <link rel="alternate stylesheet" title="Modern"
887 // type="text/css" href="phpwiki-modern.css" />
888 // <link rel="alternate stylesheet" title="Modern"
889 // type="text/css" href="phpwiki-printer.css" media="print" />
891 // Result in two "Modern" choices when trying to select alternate style.
892 // If one selects the first of those choices, one gets phpwiki-modern
893 // both when browsing and printing. If one selects the second "Modern",
894 // one gets no CSS when browsing, and phpwiki-printer when printing.
899 // We should probably move to doing the media based style
900 // switching in the CSS files themselves using, e.g.:
902 // @import url(print.css) print;
904 ////////////////////////////////////////////////////////////////
906 function _CSSlink($title, $css_file, $media, $is_alt = false) {
907 // Don't set title on default style. This makes it clear to
908 // the user which is the default (i.e. most supported) style.
909 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
910 'type' => 'text/css',
911 'charset' => CHARSET,
912 'href' => $this->_findData($css_file)));
914 $link->setAttr('title', $title);
917 $link->setAttr('media', $media);
918 if ($this->DUMP_MODE) {
919 if (empty($this->dumped_css)) $this->dumped_css = array();
920 if (!in_array($css_file,$this->dumped_css)) $this->dumped_css[] = $css_file;
921 $link->setAttr('href', basename($link->getAttr('href')));
927 /** Set default CSS source for this theme.
929 * To set styles to be used for different media, pass a
930 * hash for the second argument, e.g.
932 * $theme->setDefaultCSS('default', array('' => 'normal.css',
933 * 'print' => 'printer.css'));
935 * If you call this more than once, the last one called takes
936 * precedence as the default style.
938 * @param string $title Name of style (currently ignored, unless
939 * you call this more than once, in which case, some of the style
940 * will become alternate (rather than default) styles, and then their
941 * titles will be used.
943 * @param mixed $css_files Name of CSS file, or hash containing a mapping
944 * between media types and CSS file names. Use a key of '' (the empty string)
945 * to set the default CSS for non-specified media. (See above for an example.)
947 function setDefaultCSS ($title, $css_files) {
948 if (!is_array($css_files))
949 $css_files = array('' => $css_files);
950 // Add to the front of $this->_css
951 unset($this->_css[$title]);
952 $this->_css = array_merge(array($title => $css_files), $this->_css);
955 /** Set alternate CSS source for this theme.
957 * @param string $title Name of style.
958 * @param string $css_files Name of CSS file.
960 function addAlternateCSS ($title, $css_files) {
961 if (!is_array($css_files))
962 $css_files = array('' => $css_files);
963 $this->_css[$title] = $css_files;
967 * @return string HTML for CSS.
972 foreach ($this->_css as $title => $css_files) {
973 ksort($css_files); // move $css_files[''] to front.
974 foreach ($css_files as $media => $css_file) {
975 $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
985 function findTemplate ($name) {
986 return $this->_path . $this->_findFile("templates/$name.tmpl");
989 var $_MoreHeaders = array();
990 function addMoreHeaders ($element) {
991 array_push($this->_MoreHeaders,$element);
993 function getMoreHeaders () {
994 if (empty($this->_MoreHeaders))
997 //$out = "<!-- More Headers -->\n";
998 foreach ($this->_MoreHeaders as $h) {
1000 $out .= printXML($h);
1007 var $_MoreAttr = array();
1008 function addMoreAttr ($id,$element) {
1009 if (empty($this->_MoreAttr) or !is_array($this->_MoreAttr[$id]))
1010 $this->_MoreAttr[$id] = array($element);
1012 array_push($this->_MoreAttr[$id],$element);
1014 function getMoreAttr ($id) {
1015 if (empty($this->_MoreAttr[$id]))
1018 foreach ($this->_MoreAttr[$id] as $h) {
1020 $out .= printXML($h);
1028 * Custom UserPreferences:
1029 * A list of name => _UserPreference class pairs.
1030 * Rationale: Certain themes should be able to extend the predefined list
1031 * of preferences. Display/editing is done in the theme specific userprefs.tmpl
1032 * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
1033 * These values are just ignored if another theme is used.
1035 function customUserPreferences($array) {
1036 global $customUserPreferenceColumns; // FIXME: really a global?
1037 if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
1038 //array('wikilens' => new _UserPreference_wikilens());
1039 foreach ($array as $field => $prefobj) {
1040 $customUserPreferenceColumns[$field] = $prefobj;
1044 /** addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
1045 * Register custom PageList types for special themes, like
1046 * 'rating' for wikilens
1048 function addPageListColumn ($array) {
1049 global $customPageListColumns;
1050 if (empty($customPageListColumns)) $customPageListColumns = array();
1051 foreach ($array as $column => $obj) {
1052 $customPageListColumns[$column] = $obj;
1060 * A class representing a clickable "button".
1062 * In it's simplest (default) form, a "button" is just a link associated
1063 * with some sort of wiki-action.
1065 class Button extends HtmlElement {
1068 * @param $text string The text for the button.
1069 * @param $url string The url (href) for the button.
1070 * @param $class string The CSS class for the button.
1072 function Button ($text, $url, $class = false) {
1075 if (check_php_version(5)) {
1076 $this->_init('a', array('href' => $url));
1078 $this->HtmlElement('a', array('href' => $url));
1081 $this->setAttr('class', $class);
1082 if ($request->getArg('frame'))
1083 $this->setAttr('target', '_top');
1084 $this->pushContent($GLOBALS['Theme']->maybeSplitWikiWord($text));
1091 * A clickable image button.
1093 class ImageButton extends Button {
1096 * @param $text string The text for the button.
1097 * @param $url string The url (href) for the button.
1098 * @param $class string The CSS class for the button.
1099 * @param $img_url string URL for button's image.
1100 * @param $img_attr array Additional attributes for the <img> tag.
1102 function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
1103 $this->HtmlElement('a', array('href' => $url));
1105 $this->setAttr('class', $class);
1107 if (!is_array($img_attr))
1108 $img_attr = array();
1109 $img_attr['src'] = $img_url;
1110 $img_attr['alt'] = $text;
1111 $img_attr['class'] = 'wiki-button';
1112 $img_attr['border'] = 0;
1113 $this->pushContent(HTML::img($img_attr));
1118 * A class representing a form <samp>submit</samp> button.
1120 class SubmitButton extends HtmlElement {
1123 * @param $text string The text for the button.
1124 * @param $name string The name of the form field.
1125 * @param $class string The CSS class for the button.
1127 function SubmitButton ($text, $name = false, $class = false) {
1128 $this->HtmlElement('input', array('type' => 'submit',
1131 $this->setAttr('name', $name);
1133 $this->setAttr('class', $class);
1140 * A class representing an image form <samp>submit</samp> button.
1142 class SubmitImageButton extends SubmitButton {
1145 * @param $text string The text for the button.
1146 * @param $name string The name of the form field.
1147 * @param $class string The CSS class for the button.
1148 * @param $img_url string URL for button's image.
1149 * @param $img_attr array Additional attributes for the <img> tag.
1151 function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
1152 $this->HtmlElement('input', array('type' => 'image',
1157 $this->setAttr('name', $name);
1159 $this->setAttr('class', $class);
1165 * A sidebar box with title and body, narrow fixed-width.
1166 * To represent abbrevated content of plugins, links or forms,
1167 * like "Getting Started", "Search", "Sarch Pagename",
1168 * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
1170 * ... See http://tikiwiki.org/
1174 * $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
1175 * $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
1179 function SidebarBox($title, $body) {
1180 $this->title = $title;
1181 $this->body = $body;
1184 return WikiPlugin::makeBox($this->title, $this->body);
1189 * A sidebar box for plugins.
1190 * Any plugin may provide a box($args=false, $request=false, $basepage=false)
1191 * method, with the help of WikiPlugin::makeBox()
1193 class PluginSidebarBox extends SidebarBox {
1195 var $_plugin, $_args = false, $_basepage = false;
1197 function PluginSidebarBox($name, $args = false, $basepage = false) {
1198 $loader = new WikiPluginLoader();
1199 $plugin = $loader->getPlugin($name);
1200 if (!method_exists($plugin,'box')) {
1201 return $loader->error(sprintf(_("%s: has no box method"),
1202 get_class($plugin)));
1204 $this->_plugin =& $plugin;
1205 $this->_args = $args ? $args : array();
1206 $this->_basepage = $basepage;
1209 function format($args = false) {
1210 return $this->_plugin->box($args ? array_merge($this->_args,$args) : $this->_args,
1211 $GLOBALS['request'],
1216 // Various boxes which are no plugins
1217 class RelatedLinksBox extends SidebarBox {
1218 function RelatedLinksBox($title = false, $body = '', $limit = 20) {
1220 $this->title = $title ? $title : _("Related Links");
1221 $this->body = HTML($body);
1222 $page = $request->getPage($request->getArg('pagename'));
1223 $revision = $page->getCurrentRevision();
1224 $page_content = $revision->getTransformedContent();
1225 //$cache = &$page->_wikidb->_cache;
1227 $sp = HTML::Raw('· ');
1228 foreach ($page_content->getWikiPageLinks() as $link) {
1229 if (!$request->_dbi->isWikiPage($link)) continue;
1230 $this->body->pushContent($sp,WikiLink($link), HTML::br());
1232 if ($limit and $counter > $limit) continue;
1237 class RelatedExternalLinksBox extends SidebarBox {
1238 function RelatedExternalLinksBox($title = false, $body = '', $limit = 20) {
1240 $this->title = $title ? $title : _("External Links");
1241 $this->body = HTML($body);
1242 $page = $request->getPage($request->getArg('pagename'));
1243 $cache = &$page->_wikidb->_cache;
1245 $sp = HTML::Raw('· ');
1246 foreach ($cache->getWikiPageLinks() as $link) {
1248 $this->body->pushContent($sp, WikiLink($link), HTML::br());
1250 if ($limit and $counter > $limit) continue;
1258 // $Log: not supported by cvs2svn $
1259 // Revision 1.81 2004/04/01 15:57:10 rurban
1260 // simplified Sidebar theme: table, not absolute css positioning
1261 // added the new box methods.
1262 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1264 // Revision 1.80 2004/03/30 02:14:03 rurban
1265 // fixed yet another Prefs bug
1266 // added generic PearDb_iter
1267 // $request->appendValidators no so strict as before
1268 // added some box plugin methods
1269 // PageList commalist for condensed output
1271 // Revision 1.79 2004/03/24 19:39:02 rurban
1272 // php5 workaround code (plus some interim debugging code in XmlElement)
1273 // php5 doesn't work yet with the current XmlElement class constructors,
1274 // WikiUserNew does work better than php4.
1275 // rewrote WikiUserNew user upgrading to ease php5 update
1276 // fixed pref handling in WikiUserNew
1277 // added Email Notification
1278 // added simple Email verification
1279 // removed emailVerify userpref subclass: just a email property
1280 // changed pref binary storage layout: numarray => hash of non default values
1281 // print optimize message only if really done.
1282 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1283 // prefs should be stored in db or homepage, besides the current session.
1285 // Revision 1.78 2004/03/18 22:32:33 rurban
1286 // work to make it php5 compatible
1288 // Revision 1.77 2004/03/08 19:30:01 rurban
1289 // fixed Theme->getButtonURL
1290 // AllUsers uses now WikiGroup (also DB User and DB Pref users)
1291 // PageList fix for empty pagenames
1293 // Revision 1.76 2004/03/08 18:17:09 rurban
1294 // added more WikiGroup::getMembersOf methods, esp. for special groups
1295 // fixed $LDAP_SET_OPTIONS
1296 // fixed _AuthInfo group methods
1298 // Revision 1.75 2004/03/01 09:34:37 rurban
1299 // fixed button path logic: now fallback to default also
1301 // Revision 1.74 2004/02/28 21:14:08 rurban
1302 // generally more PHPDOC docs
1303 // see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
1304 // fxied WikiUserNew pref handling: empty theme not stored, save only
1305 // changed prefs, sql prefs improved, fixed password update,
1306 // removed REPLACE sql (dangerous)
1307 // moved gettext init after the locale was guessed
1308 // + some minor changes
1310 // Revision 1.73 2004/02/26 03:22:05 rurban
1311 // also copy css and images with XHTML Dump
1313 // Revision 1.72 2004/02/26 02:25:53 rurban
1314 // fix empty and #-anchored links in XHTML Dumps
1316 // Revision 1.71 2004/02/15 21:34:37 rurban
1317 // PageList enhanced and improved.
1318 // fixed new WikiAdmin... plugins
1319 // editpage, Theme with exp. htmlarea framework
1320 // (htmlarea yet committed, this is really questionable)
1321 // WikiUser... code with better session handling for prefs
1322 // enhanced UserPreferences (again)
1323 // RecentChanges for show_deleted: how should pages be deleted then?
1325 // Revision 1.70 2004/01/26 09:17:48 rurban
1326 // * changed stored pref representation as before.
1327 // the array of objects is 1) bigger and 2)
1328 // less portable. If we would import packed pref
1329 // objects and the object definition was changed, PHP would fail.
1330 // This doesn't happen with an simple array of non-default values.
1331 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1332 // understands the interim format of array of objects also.
1333 // * simplified $prefs->get() and fixed $prefs->set()
1334 // * added $user->_userid and class '_WikiUser' portability functions
1335 // * fixed $user object ->_level upgrading, mostly using sessions.
1336 // this fixes yesterdays problems with loosing authorization level.
1337 // * fixed WikiUserNew::checkPass to return the _level
1338 // * fixed WikiUserNew::isSignedIn
1339 // * added explodePageList to class PageList, support sortby arg
1340 // * fixed UserPreferences for WikiUserNew
1341 // * fixed WikiPlugin for empty defaults array
1342 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1343 // removed sort arg, support sortby arg
1345 // Revision 1.69 2003/12/05 01:32:28 carstenklapp
1346 // New feature: Easier to run multiple wiks off of one set of code. Name
1347 // your logo and signature image files "YourWikiNameLogo.png" and
1348 // "YourWikiNameSignature.png" and put them all into
1349 // themes/default/images. YourWikiName should match what is defined as
1350 // WIKI_NAME in index.php. In case the image is not found, the default
1351 // shipped with PhpWiki will be used.
1353 // Revision 1.68 2003/03/04 01:53:30 dairiki
1354 // Inconsequential decrufting.
1356 // Revision 1.67 2003/02/26 03:40:22 dairiki
1357 // New action=create. Essentially the same as action=edit, except that if the
1358 // page already exists, it falls back to action=browse.
1360 // This is for use in the "question mark" links for unknown wiki words
1361 // to avoid problems and confusion when following links from stale pages.
1362 // (If the "unknown page" has been created in the interim, the user probably
1363 // wants to view the page before editing it.)
1365 // Revision 1.66 2003/02/26 00:10:26 dairiki
1366 // More/better/different checks for bad page names.
1368 // Revision 1.65 2003/02/24 22:41:57 dairiki
1371 // Revision 1.64 2003/02/24 22:06:14 dairiki
1372 // Attempts to fix auto-selection of printer CSS when printing.
1373 // See new comments lib/Theme.php for more details.
1374 // Also see SF patch #669563.
1376 // Revision 1.63 2003/02/23 03:37:05 dairiki
1377 // Stupid typo/bug fix.
1379 // Revision 1.62 2003/02/21 04:14:52 dairiki
1380 // New WikiLink type 'if_known'. This gives linkified name if page
1381 // exists, otherwise, just plain text.
1383 // Revision 1.61 2003/02/18 21:52:05 dairiki
1384 // Fix so that one can still link to wiki pages with # in their names.
1385 // (This was made difficult by the introduction of named tags, since
1386 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
1388 // Now the ~ escape for page names should work: [Page ~#1].
1390 // Revision 1.60 2003/02/15 01:59:47 dairiki
1391 // Theme::getCSS(): Add Default-Style HTTP(-eqiv) header in attempt
1392 // to fix default stylesheet selection on some browsers.
1393 // For details on the Default-Style header, see:
1394 // http://home.dairiki.org/docs/html4/present/styles.html#h-14.3.2
1396 // Revision 1.59 2003/01/04 22:30:16 carstenklapp
1397 // New: display a "Never edited." message instead of an invalid epoch date.
1400 // (c-file-style: "gnu")
1404 // c-basic-offset: 4
1405 // c-hanging-comment-ender-p: nil
1406 // indent-tabs-mode: nil