1 <?php rcs_id('$Id: Theme.php,v 1.13 2002-01-22 03:12:59 carstenklapp Exp $');
3 require_once('lib/HtmlElement.php');
6 function Theme ($theme_name) {
7 $this->_name = $theme_name;
8 $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes";
9 $this->_theme_dir = "$themes_dir/$theme_name";
10 $this->_path = array($this->_theme_dir,
11 "$themes_dir/default");
14 function _findFile ($file, $missing_okay = false) {
15 foreach ($this->_path as $dir) {
16 if (file_exists("$dir/$file"))
19 // FIXME: this is a short-term hack. Delete this after all files
20 // get moved into themes/...
21 if (file_exists($file))
25 trigger_error("$file: not found", E_USER_ERROR);
30 function _findData ($file, $missing_okay = false) {
31 $path = $this->_findFile($file, $missing_okay);
35 if (defined('DATA_PATH'))
36 return DATA_PATH . "/$path";
40 function file ($file) {
41 return "$this->_theme_dir/$file";
44 ////////////////////////////////////////////////////////////////
46 // Date and Time formatting
48 ////////////////////////////////////////////////////////////////
50 var $_dateTimeFormat = "%B %e, %Y";
51 var $_dateFormat = "%B %e, %Y";
53 function setDateFormat ($fs) {
54 $this->_dateFormat = $fs;
57 function formatDate ($time_t) {
58 return strftime($this->_dateFormat, $time_t);
61 function setDateTimeFormat ($fs) {
62 $this->_dateTimeFormat = $fs;
65 function formatDateTime ($time_t) {
66 return strftime($this->_dateTimeFormat, $time_t);
70 function formatTime ($time_t) {
71 //FIXME: make 24-hour mode configurable?
72 return preg_replace('/^0/', ' ',
73 strtolower(strftime("%I:%M %p", $time_t)));
77 ////////////////////////////////////////////////////////////////
79 // Hooks for other formatting
81 ////////////////////////////////////////////////////////////////
83 //FIXME: PHP 4.1 Warnings
84 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
85 //use the call_user_func variety with the array(&$obj, "method") syntax instead
87 function getFormatter ($type, $format) {
88 $method = strtolower("get${type}Formatter");
89 if (method_exists($this, $method))
90 return @call_user_method($method, $this, $format);
95 ////////////////////////////////////////////////////////////////
99 ////////////////////////////////////////////////////////////////
101 var $_autosplitWikiWords = false;
103 function setAutosplitWikiWords($autosplit=false) {
104 $this->_autosplitWikiWords = $autosplit ? true : false;
107 function maybeSplitWikiWord ($wikiword) {
108 if ($this->_autosplitWikiWords)
109 return split_pagename($wikiword);
114 function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
115 if ($version !== false)
116 $url = WikiURL($wikiword, array('version' => $version));
118 $url = WikiURL($wikiword);
120 $link = HTML::a(array('href' => $url));
122 if (!empty($linktext)) {
123 $link->pushContent($linktext);
124 $link->setAttr('class', 'named-wiki');
127 $link->pushContent($this->maybeSplitWikiWord($wikiword));
128 $link->setAttr('class', 'wiki');
133 function linkUnknownWikiWord($wikiword, $linktext = '') {
134 $url = WikiURL($wikiword, array('action' => 'edit'));
135 $link = HTML::span(HTML::a(array('href' => $url), '?'));
137 if (!empty($linktext)) {
138 $link->pushContent(HTML::u($linktext));
139 $link->setAttr('class', 'named-wikiunknown');
142 $link->pushContent(HTML::u($this->maybeSplitWikiWord($wikiword)));
143 $link->setAttr('class', 'wikiunknown');
149 ////////////////////////////////////////////////////////////////
153 ////////////////////////////////////////////////////////////////
155 function addImageAlias ($alias, $image_name) {
156 $this->_imageAliases[$alias] = $image_name;
159 function getImageURL ($image) {
160 $aliases = &$this->_imageAliases;
162 if (isset($aliases[$image]))
163 $image = $aliases[$image];
165 // If not extension, default to .png.
166 if (!preg_match('/\.\w+$/', $image))
169 // FIXME: this should probably be made to fall back
170 // automatically to .gif, .jpg.
171 // Also try .gif before .png if browser doesn't like png.
173 return $this->_findData("images/$image", 'missing okay');
176 function setLinkIcon($proto, $image = false) {
180 $this->_linkIcons[$proto] = $image;
183 function getLinkIconURL ($proto) {
184 $icons = &$this->_linkIcons;
185 if (!empty($icons[$proto]))
186 return $this->getImageURL($icons[$proto]);
187 elseif (!empty($icons['*']))
188 return $this->getImageURL($icons['*']);
192 function addButtonAlias ($text, $alias) {
193 $this->_buttonAliases[$text] = $alias;
196 function getButtonURL ($text) {
197 $aliases = &$this->_buttonAliases;
198 if (isset($aliases[$text]))
199 $text = $aliases[$text];
201 $qtext = urlencode($text);
203 // search no-label buttons in ./buttons
204 // FIXME: this probably needs the untranslated button label to work correctly
205 $path = $this->_findData("buttons/$qtext.png", 'missing okay');
209 // search languages ./buttons/??
210 $path = FindLocalizedButtonFile("$qtext.png", 'missing okay');
214 // search english ./buttons/en in case word is spelled the same
215 $path = $this->_findData("buttons/en/$qtext.png", 'missing okay');
223 ////////////////////////////////////////////////////////////////
227 ////////////////////////////////////////////////////////////////
229 function makeButton ($text, $url, $class = false) {
230 // FIXME: don't always try for image button?
232 $imgurl = $this->getButtonURL($text);
234 return new ImageButton($text, $url, $class, $imgurl);
236 return new Button($text, $url, $class);
239 function setButtonSeparator($separator=false) {
240 $this->_buttonSeparator = $separator ? $separator : " | ";
243 function getButtonSeparator() {
244 if (! @$this->_buttonSeparator)
245 $this->setButtonSeparator();
247 return $this->_buttonSeparator;
251 ////////////////////////////////////////////////////////////////
255 ////////////////////////////////////////////////////////////////
257 function _CSSlink($title, $css_file, $media, $is_alt = false) {
258 $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
260 'type' => 'text/css',
262 'href' => $this->_findData($css_file)));
264 $link->setAttr('media', $media);
268 function setDefaultCSS ($title, $css_file, $media = false) {
269 if (isset($this->_alternateCSS))
270 unset($this->_alternateCSS[$title]);
271 $this->_defaultCSS = $this->_CSSlink($title, $css_file, $media);
274 function addAlternateCSS ($title, $css_file, $media = false) {
275 $this->_alternateCSS[$title] = $this->_CSSlink($title, $css_file, $media, true);
279 * @return string HTML for CSS.
282 $css[] = $this->_defaultCSS;
283 if (!empty($this->_alternateCSS))
284 foreach ($this->_alternateCSS as $link)
289 function findTemplate ($name) {
290 return $this->_findFile("templates/$name.tmpl");
295 // (c-file-style: "gnu")
300 // c-hanging-comment-ender-p: nil
301 // indent-tabs-mode: nil