1 <?php rcs_id('$Id: Theme.php,v 1.8 2002-01-19 19:29:49 carstenklapp Exp $');
4 function Theme ($theme_name) {
5 $this->_name = $theme_name;
6 $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes";
7 $this->_path = array("$themes_dir/$theme_name",
8 "$themes_dir/default");
11 function _findFile ($file, $missing_okay = false) {
12 foreach ($this->_path as $dir) {
13 if (file_exists("$dir/$file"))
16 // FIXME: this is a short-term hack. Delete this after all files
17 // get moved into themes/...
18 if (file_exists($file))
22 trigger_error("$file: not found", E_USER_ERROR);
27 function _findData ($file, $missing_okay = false) {
28 $path = $this->_findFile($file, $missing_okay);
32 if (defined('DATA_PATH'))
33 return DATA_PATH . "/$path";
37 function requireFile ($file) {
38 $path = $this->_findFile($file);
41 return require_once($path);
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 function getFormatter ($type, $format) {
84 $method = strtolower("get${type}Formatter");
85 if (method_exists($this, $method))
86 return call_user_method($method, $this, $format);
90 function LinkUnknownWikiWord($wikiword, $linktext = '') {
91 if (empty($linktext)) {
92 $linktext = $wikiword;
93 if (defined("autosplit_wikiwords"))
94 $linktext=split_pagename($linktext);
95 $class = 'wikiunknown';
97 $class = 'named-wikiunknown';
99 return Element('span', array('class' => $class),
101 array('href' => WikiURL($wikiword,
102 array('action' => 'edit'))),
103 '?') . Element('u', $linktext));
107 ////////////////////////////////////////////////////////////////
111 ////////////////////////////////////////////////////////////////
113 function addImageAlias ($alias, $image_name) {
114 $this->_imageAliases[$alias] = $image_name;
117 function getImageURL ($image) {
118 $aliases = &$this->_imageAliases;
120 if (isset($aliases[$image]))
121 $image = $aliases[$image];
123 // If not extension, default to .png.
124 if (!preg_match('/\.\w+$/', $image))
127 // FIXME: this should probably be made to fall back
128 // automatically to .gif, .jpg.
129 // Also try .gif before .png if browser doesn't like png.
131 return $this->_findData("images/$image", 'missing okay');
134 function setLinkIcon($proto, $image = false) {
138 $this->_linkIcons[$proto] = $image;
141 function getLinkIconURL ($proto) {
142 $icons = &$this->_linkIcons;
143 if (!empty($icons[$proto]))
144 return $this->getImageURL($icons[$proto]);
145 elseif (!empty($icons['*']))
146 return $this->getImageURL($icons['*']);
150 // FIXME: need buttonAlias map?
151 function getButtonURL ($text) {
152 $qtext = urlencode($text);
153 // FIXME: search other languages too.
154 foreach (array("buttons/en/$qtext.png",
155 "buttons/$qtext.png") as $file) {
156 $path = $this->_findData($file, 'missing okay');
163 ////////////////////////////////////////////////////////////////
167 ////////////////////////////////////////////////////////////////
169 function makeButton ($text, $url, $class) {
170 // FIXME: don't always try for image button?
172 $imgurl = $this->getButtonURL($text);
174 return new ImageButton($text, $url, $class, $imgurl);
176 return new Button($text, $url, $class);
179 function setButtonSeparator($separator=false) {
180 $this->_buttonSeparator = $separator ? $separator : " ";
183 function getButtonSeparator() {
184 if (! @$this->_buttonSeparator)
185 $this->setButtonSeparator(" | ");
187 return $this->_buttonSeparator;
191 ////////////////////////////////////////////////////////////////
195 ////////////////////////////////////////////////////////////////
197 function _CSSlink($title, $css_file, $media, $is_alt = false) {
198 $attr = array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
200 'type' => 'text/css',
201 'charset' => CHARSET);
202 $attr['href'] = $this->_findData($css_file);
204 $attr['media'] = $media;
205 return Element('link', $attr);
208 function setDefaultCSS ($title, $css_file, $media = false) {
209 if (isset($this->_alternateCSS))
210 unset($this->_alternateCSS[$title]);
211 $this->_defaultCSS = $this->_CSSlink($title, $css_file, $media);
214 function addAlternateCSS ($title, $css_file, $media = false) {
215 $this->_alternateCSS[$title] = $this->_CSSlink($title, $css_file, $media, true);
219 * @return string HTML for CSS.
222 $css = "$this->_defaultCSS\n";
223 if (!empty($this->_alternateCSS))
224 $css .= join("\n", $this->_alternateCSS) . "\n";
228 function findTemplate ($name) {
229 return $this->_findFile("templates/$name.tmpl");
234 // (c-file-style: "gnu")
239 // c-hanging-comment-ender-p: nil
240 // indent-tabs-mode: nil