1 <?php rcs_id('$Id: Theme.php,v 1.10 2002-01-19 22:32:01 dairiki 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 function getFormatter ($type, $format) {
82 $method = strtolower("get${type}Formatter");
83 if (method_exists($this, $method))
84 return call_user_method($method, $this, $format);
89 ////////////////////////////////////////////////////////////////
93 ////////////////////////////////////////////////////////////////
95 function setAutosplitWikiWords($autosplit=false) {
96 $this->_autosplitWikiWords = $autosplit ? true : false;
99 function getAutoSplitWikiWords() {
100 if (! @$this->_autosplitWikiWords)
101 $this->setAutosplitWikiWords();
103 return $this->_autosplitWikiWords;
106 function LinkExistingWikiWord($wikiword, $linktext = '', $version = false) {
107 if (empty($linktext)) {
108 $linktext = $wikiword;
109 if ($this->getAutoSplitWikiWords())
110 $linktext = split_pagename($linktext);
114 $class = 'named-wiki';
117 if ($version !== false)
118 $attr['version'] = $version;
120 return QElement('a', array('href' => WikiURL($wikiword, $attr),
125 function LinkUnknownWikiWord($wikiword, $linktext = '') {
126 if (empty($linktext)) {
127 $linktext = $wikiword;
128 if ($this->getAutoSplitWikiWords())
129 $linktext=split_pagename($linktext);
130 $class = 'wikiunknown';
132 $class = 'named-wikiunknown';
134 return Element('span', array('class' => $class),
136 array('href' => WikiURL($wikiword,
137 array('action' => 'edit'))),
138 '?') . Element('u', $linktext));
142 ////////////////////////////////////////////////////////////////
146 ////////////////////////////////////////////////////////////////
148 function addImageAlias ($alias, $image_name) {
149 $this->_imageAliases[$alias] = $image_name;
152 function getImageURL ($image) {
153 $aliases = &$this->_imageAliases;
155 if (isset($aliases[$image]))
156 $image = $aliases[$image];
158 // If not extension, default to .png.
159 if (!preg_match('/\.\w+$/', $image))
162 // FIXME: this should probably be made to fall back
163 // automatically to .gif, .jpg.
164 // Also try .gif before .png if browser doesn't like png.
166 return $this->_findData("images/$image", 'missing okay');
169 function setLinkIcon($proto, $image = false) {
173 $this->_linkIcons[$proto] = $image;
176 function getLinkIconURL ($proto) {
177 $icons = &$this->_linkIcons;
178 if (!empty($icons[$proto]))
179 return $this->getImageURL($icons[$proto]);
180 elseif (!empty($icons['*']))
181 return $this->getImageURL($icons['*']);
185 function addButtonAlias ($text, $alias) {
186 $this->_buttonAliases[$text] = $alias;
189 function getButtonURL ($text) {
190 $aliases = &$this->_buttonAliases;
191 if (isset($aliases[$text]))
192 $text = $aliases[$text];
194 $qtext = urlencode($text);
195 // FIXME: search other languages too.
196 foreach (array("buttons/en/$qtext.png",
197 "buttons/$qtext.png") as $file) {
198 $path = $this->_findData($file, 'missing okay');
205 ////////////////////////////////////////////////////////////////
209 ////////////////////////////////////////////////////////////////
211 function makeButton ($text, $url, $class = false) {
212 // FIXME: don't always try for image button?
214 $imgurl = $this->getButtonURL($text);
216 return new ImageButton($text, $url, $class, $imgurl);
218 return new Button($text, $url, $class);
221 function setButtonSeparator($separator=false) {
222 $this->_buttonSeparator = $separator ? $separator : " | ";
225 function getButtonSeparator() {
226 if (! @$this->_buttonSeparator)
227 $this->setButtonSeparator();
229 return $this->_buttonSeparator;
233 ////////////////////////////////////////////////////////////////
237 ////////////////////////////////////////////////////////////////
239 function _CSSlink($title, $css_file, $media, $is_alt = false) {
240 $attr = array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
242 'type' => 'text/css',
243 'charset' => CHARSET);
244 $attr['href'] = $this->_findData($css_file);
246 $attr['media'] = $media;
247 return Element('link', $attr);
250 function setDefaultCSS ($title, $css_file, $media = false) {
251 if (isset($this->_alternateCSS))
252 unset($this->_alternateCSS[$title]);
253 $this->_defaultCSS = $this->_CSSlink($title, $css_file, $media);
256 function addAlternateCSS ($title, $css_file, $media = false) {
257 $this->_alternateCSS[$title] = $this->_CSSlink($title, $css_file, $media, true);
261 * @return string HTML for CSS.
264 $css = "$this->_defaultCSS\n";
265 if (!empty($this->_alternateCSS))
266 $css .= join("\n", $this->_alternateCSS) . "\n";
270 function findTemplate ($name) {
271 return $this->_findFile("templates/$name.tmpl");
276 // (c-file-style: "gnu")
281 // c-hanging-comment-ender-p: nil
282 // indent-tabs-mode: nil