1 <?php rcs_id('$Id: Theme.php,v 1.11 2002-01-20 03:36:17 carstenklapp Exp $');
4 function Theme ($theme_name) {
5 $this->_name = $theme_name;
6 $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes";
7 $this->_theme_dir = "$themes_dir/$theme_name";
8 $this->_path = array($this->_theme_dir,
9 "$themes_dir/default");
12 function _findFile ($file, $missing_okay = false) {
13 foreach ($this->_path as $dir) {
14 if (file_exists("$dir/$file"))
17 // FIXME: this is a short-term hack. Delete this after all files
18 // get moved into themes/...
19 if (file_exists($file))
23 trigger_error("$file: not found", E_USER_ERROR);
28 function _findData ($file, $missing_okay = false) {
29 $path = $this->_findFile($file, $missing_okay);
33 if (defined('DATA_PATH'))
34 return DATA_PATH . "/$path";
38 function file ($file) {
39 return "$this->_theme_dir/$file";
42 ////////////////////////////////////////////////////////////////
44 // Date and Time formatting
46 ////////////////////////////////////////////////////////////////
48 var $_dateTimeFormat = "%B %e, %Y";
49 var $_dateFormat = "%B %e, %Y";
51 function setDateFormat ($fs) {
52 $this->_dateFormat = $fs;
55 function formatDate ($time_t) {
56 return strftime($this->_dateFormat, $time_t);
59 function setDateTimeFormat ($fs) {
60 $this->_dateTimeFormat = $fs;
63 function formatDateTime ($time_t) {
64 return strftime($this->_dateTimeFormat, $time_t);
68 function formatTime ($time_t) {
69 //FIXME: make 24-hour mode configurable?
70 return preg_replace('/^0/', ' ',
71 strtolower(strftime("%I:%M %p", $time_t)));
75 ////////////////////////////////////////////////////////////////
77 // Hooks for other formatting
79 ////////////////////////////////////////////////////////////////
81 //FIXME: PHP 4.1 Warnings
82 //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
83 //use the call_user_func variety with the array(&$obj, "method") syntax instead
85 function getFormatter ($type, $format) {
86 $method = strtolower("get${type}Formatter");
87 if (method_exists($this, $method))
88 return @call_user_method($method, $this, $format);
93 ////////////////////////////////////////////////////////////////
97 ////////////////////////////////////////////////////////////////
99 function setAutosplitWikiWords($autosplit=false) {
100 $this->_autosplitWikiWords = $autosplit ? true : false;
103 function getAutoSplitWikiWords() {
104 if (! @$this->_autosplitWikiWords)
105 $this->setAutosplitWikiWords();
107 return $this->_autosplitWikiWords;
110 function LinkExistingWikiWord($wikiword, $linktext = '', $version = false) {
111 if (empty($linktext)) {
112 $linktext = $wikiword;
113 if ($this->getAutoSplitWikiWords())
114 $linktext = split_pagename($linktext);
118 $class = 'named-wiki';
121 if ($version !== false)
122 $attr['version'] = $version;
124 return QElement('a', array('href' => WikiURL($wikiword, $attr),
129 function LinkUnknownWikiWord($wikiword, $linktext = '') {
130 if (empty($linktext)) {
131 $linktext = $wikiword;
132 if ($this->getAutoSplitWikiWords())
133 $linktext=split_pagename($linktext);
134 $class = 'wikiunknown';
136 $class = 'named-wikiunknown';
138 return Element('span', array('class' => $class),
140 array('href' => WikiURL($wikiword,
141 array('action' => 'edit'))),
142 '?') . Element('u', $linktext));
146 ////////////////////////////////////////////////////////////////
150 ////////////////////////////////////////////////////////////////
152 function addImageAlias ($alias, $image_name) {
153 $this->_imageAliases[$alias] = $image_name;
156 function getImageURL ($image) {
157 $aliases = &$this->_imageAliases;
159 if (isset($aliases[$image]))
160 $image = $aliases[$image];
162 // If not extension, default to .png.
163 if (!preg_match('/\.\w+$/', $image))
166 // FIXME: this should probably be made to fall back
167 // automatically to .gif, .jpg.
168 // Also try .gif before .png if browser doesn't like png.
170 return $this->_findData("images/$image", 'missing okay');
173 function setLinkIcon($proto, $image = false) {
177 $this->_linkIcons[$proto] = $image;
180 function getLinkIconURL ($proto) {
181 $icons = &$this->_linkIcons;
182 if (!empty($icons[$proto]))
183 return $this->getImageURL($icons[$proto]);
184 elseif (!empty($icons['*']))
185 return $this->getImageURL($icons['*']);
189 function addButtonAlias ($text, $alias) {
190 $this->_buttonAliases[$text] = $alias;
193 function getButtonURL ($text) {
194 $aliases = &$this->_buttonAliases;
195 if (isset($aliases[$text]))
196 $text = $aliases[$text];
198 $qtext = urlencode($text);
199 // FIXME: search other languages too.
200 foreach (array("buttons/en/$qtext.png",
201 "buttons/$qtext.png") as $file) {
202 $path = $this->_findData($file, 'missing okay');
209 ////////////////////////////////////////////////////////////////
213 ////////////////////////////////////////////////////////////////
215 function makeButton ($text, $url, $class = false) {
216 // FIXME: don't always try for image button?
218 $imgurl = $this->getButtonURL($text);
220 return new ImageButton($text, $url, $class, $imgurl);
222 return new Button($text, $url, $class);
225 function setButtonSeparator($separator=false) {
226 $this->_buttonSeparator = $separator ? $separator : " | ";
229 function getButtonSeparator() {
230 if (! @$this->_buttonSeparator)
231 $this->setButtonSeparator();
233 return $this->_buttonSeparator;
237 ////////////////////////////////////////////////////////////////
241 ////////////////////////////////////////////////////////////////
243 function _CSSlink($title, $css_file, $media, $is_alt = false) {
244 $attr = array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
246 'type' => 'text/css',
247 'charset' => CHARSET);
248 $attr['href'] = $this->_findData($css_file);
250 $attr['media'] = $media;
251 return Element('link', $attr);
254 function setDefaultCSS ($title, $css_file, $media = false) {
255 if (isset($this->_alternateCSS))
256 unset($this->_alternateCSS[$title]);
257 $this->_defaultCSS = $this->_CSSlink($title, $css_file, $media);
260 function addAlternateCSS ($title, $css_file, $media = false) {
261 $this->_alternateCSS[$title] = $this->_CSSlink($title, $css_file, $media, true);
265 * @return string HTML for CSS.
268 $css = "$this->_defaultCSS\n";
269 if (!empty($this->_alternateCSS))
270 $css .= join("\n", $this->_alternateCSS) . "\n";
274 function findTemplate ($name) {
275 return $this->_findFile("templates/$name.tmpl");
280 // (c-file-style: "gnu")
285 // c-hanging-comment-ender-p: nil
286 // indent-tabs-mode: nil