1 <?php rcs_id('$Id: Theme.php,v 1.7 2002-01-19 03:23:45 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 setWikiMark($wikimark=false) {
91 //FIXME: Check for %s in wikimark
92 $this->_wikiMark = $wikimark ? $wikimark : "?%s";
95 function getWikiMark() {
96 if (! @$this->_wikiMark)
99 return $this->_wikiMark;
103 ////////////////////////////////////////////////////////////////
107 ////////////////////////////////////////////////////////////////
109 function addImageAlias ($alias, $image_name) {
110 $this->_imageAliases[$alias] = $image_name;
113 function getImageURL ($image) {
114 $aliases = &$this->_imageAliases;
116 if (isset($aliases[$image]))
117 $image = $aliases[$image];
119 // If not extension, default to .png.
120 if (!preg_match('/\.\w+$/', $image))
123 // FIXME: this should probably be made to fall back
124 // automatically to .gif, .jpg.
125 // Also try .gif before .png if browser doesn't like png.
127 return $this->_findData("images/$image", 'missing okay');
130 function setLinkIcon($proto, $image = false) {
134 $this->_linkIcons[$proto] = $image;
137 function getLinkIconURL ($proto) {
138 $icons = &$this->_linkIcons;
139 if (!empty($icons[$proto]))
140 return $this->getImageURL($icons[$proto]);
141 elseif (!empty($icons['*']))
142 return $this->getImageURL($icons['*']);
146 // FIXME: need buttonAlias map?
147 function getButtonURL ($text) {
148 $qtext = urlencode($text);
149 // FIXME: search other languages too.
150 foreach (array("buttons/en/$qtext.png",
151 "buttons/$qtext.png") as $file) {
152 $path = $this->_findData($file, 'missing okay');
159 ////////////////////////////////////////////////////////////////
163 ////////////////////////////////////////////////////////////////
165 function makeButton ($text, $url, $class) {
166 // FIXME: don't always try for image button?
168 $imgurl = $this->getButtonURL($text);
170 return new ImageButton($text, $url, $class, $imgurl);
172 return new Button($text, $url, $class);
175 function setButtonSeparator($separator=false) {
176 $this->_buttonSeparator = $separator ? $separator : " ";
179 function getButtonSeparator() {
180 if (! @$this->_buttonSeparator)
181 $this->setButtonSeparator(" | ");
183 return $this->_buttonSeparator;
187 ////////////////////////////////////////////////////////////////
191 ////////////////////////////////////////////////////////////////
193 function _CSSlink($title, $css_file, $media, $is_alt = false) {
194 $attr = array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
196 'type' => 'text/css',
197 'charset' => CHARSET);
198 $attr['href'] = $this->_findData($css_file);
200 $attr['media'] = $media;
201 return Element('link', $attr);
204 function setDefaultCSS ($title, $css_file, $media = false) {
205 if (isset($this->_alternateCSS))
206 unset($this->_alternateCSS[$title]);
207 $this->_defaultCSS = $this->_CSSlink($title, $css_file, $media);
210 function addAlternateCSS ($title, $css_file, $media = false) {
211 $this->_alternateCSS[$title] = $this->_CSSlink($title, $css_file, $media, true);
215 * @return string HTML for CSS.
218 $css = "$this->_defaultCSS\n";
219 if (!empty($this->_alternateCSS))
220 $css .= join("\n", $this->_alternateCSS) . "\n";
224 function findTemplate ($name) {
225 return $this->_findFile("templates/$name.tmpl");
230 // (c-file-style: "gnu")
235 // c-hanging-comment-ender-p: nil
236 // indent-tabs-mode: nil