Dead code.
[phpmyadmin/last10db.git] / libraries / Theme_Manager.class.php
blob194cab24f8f58c6c8aebcd1899e04de8097885da
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
11 require_once './libraries/Theme.class.php';
13 /**
16 class PMA_Theme_Manager
18 /**
19 * @var string path to theme folder
20 * @protected
22 var $_themes_path;
24 /**
25 * @var array available themes
27 var $themes = array();
29 /**
30 * @var string cookie name
32 var $cookie_name = 'pma_theme';
34 /**
35 * @var boolean
37 var $per_server = false;
39 /**
40 * @var string name of active theme
42 var $active_theme = '';
44 /**
45 * @var object PMA_Theme active theme
47 var $theme = null;
49 /**
50 * @var string
52 var $theme_default = 'original';
54 function __construct()
56 $this->init();
59 /**
60 * sets path to folder containing the themes
62 * @param string $path path to themes folder
63 * @return boolean success
65 function setThemesPath($path)
67 if (! $this->_checkThemeFolder($path)) {
68 return false;
71 $this->_themes_path = trim($path);
72 return true;
75 /**
76 * @public
77 * @return string
79 function getThemesPath()
81 return $this->_themes_path;
84 /**
85 * sets if there are different themes per server
87 * @param boolean $per_server
89 function setThemePerServer($per_server)
91 $this->per_server = (bool) $per_server;
94 function init()
96 $this->themes = array();
97 $this->theme_default = 'original';
98 $this->active_theme = '';
100 if (! $this->setThemesPath($GLOBALS['cfg']['ThemePath'])) {
101 return false;
104 $this->setThemePerServer($GLOBALS['cfg']['ThemePerServer']);
106 $this->loadThemes();
108 $this->theme = new PMA_Theme;
111 if (! $this->checkTheme($GLOBALS['cfg']['ThemeDefault'])) {
112 trigger_error(
113 sprintf($GLOBALS['strThemeDefaultNotFound'],
114 htmlspecialchars($GLOBALS['cfg']['ThemeDefault'])),
115 E_USER_ERROR);
116 $GLOBALS['cfg']['ThemeDefault'] = false;
119 $this->theme_default = $GLOBALS['cfg']['ThemeDefault'];
121 // check if user have a theme cookie
122 if (! $this->getThemeCookie()
123 || ! $this->setActiveTheme($this->getThemeCookie())) {
124 // otherwise use default theme
125 if ($GLOBALS['cfg']['ThemeDefault']) {
126 $this->setActiveTheme($GLOBALS['cfg']['ThemeDefault']);
127 } else {
128 // or original theme
129 $this->setActiveTheme('original');
134 function checkConfig()
136 if ($this->_themes_path != trim($GLOBALS['cfg']['ThemePath'])
137 || $this->theme_default != $GLOBALS['cfg']['ThemeDefault']) {
138 $this->init();
139 } else {
140 // at least the theme path needs to be checked every time for new
141 // themes, as there is no other way at the moment to keep track of
142 // new or removed themes
143 $this->loadThemes();
147 function setActiveTheme($theme = null)
149 if (! $this->checkTheme($theme)) {
150 trigger_error(
151 sprintf($GLOBALS['strThemeNotFound'], htmlspecialchars($theme)),
152 E_USER_ERROR);
153 return false;
156 $this->active_theme = $theme;
157 $this->theme = $this->themes[$theme];
159 // need to set later
160 //$this->setThemeCookie();
162 return true;
166 * @return string cookie name
168 function getThemeCookieName()
170 // Allow different theme per server
171 if (isset($GLOBALS['server']) && $this->per_server) {
172 return $this->cookie_name . '-' . $GLOBALS['server'];
173 } else {
174 return $this->cookie_name;
179 * returns name of theme stored in the cookie
180 * @return string theme name from cookie
182 function getThemeCookie()
184 if (isset($_COOKIE[$this->getThemeCookieName()])) {
185 return $_COOKIE[$this->getThemeCookieName()];
188 return false;
192 * save theme in cookie
194 * @uses PMA_setCookie();
195 * @uses PMA_Theme_Manager::getThemeCookieName()
196 * @uses PMA_Theme_Manager::$theme
197 * @uses PMA_Theme_Manager::$theme_default
198 * @uses PMA_Theme::getId()
200 function setThemeCookie()
202 PMA_setCookie($this->getThemeCookieName(), $this->theme->id,
203 $this->theme_default);
204 // force a change of a dummy session variable to avoid problems
205 // with the caching of phpmyadmin.css.php
206 $_SESSION['PMA_Config']->set('theme-update', $this->theme->id);
207 return true;
211 * @private
212 * @param string $folder
213 * @return boolean
215 /*private*/ function _checkThemeFolder($folder)
217 if (! is_dir($folder)) {
218 trigger_error(
219 sprintf($GLOBALS['strThemePathNotFound'],
220 htmlspecialchars($folder)),
221 E_USER_ERROR);
222 return false;
225 return true;
229 * read all themes
231 function loadThemes()
233 $this->themes = array();
235 if ($handleThemes = opendir($this->getThemesPath())) {
236 // check for themes directory
237 while (false !== ($PMA_Theme = readdir($handleThemes))) {
238 if (array_key_exists($PMA_Theme, $this->themes)) {
239 // this does nothing!
240 //$this->themes[$PMA_Theme] = $this->themes[$PMA_Theme];
241 continue;
243 $new_theme = PMA_Theme::load($this->getThemesPath() . '/' . $PMA_Theme);
244 if ($new_theme) {
245 $new_theme->setId($PMA_Theme);
246 $this->themes[$PMA_Theme] = $new_theme;
248 } // end get themes
249 closedir($handleThemes);
250 } else {
251 trigger_error(
252 'phpMyAdmin-ERROR: cannot open themes folder: ' . $this->getThemesPath(),
253 E_USER_WARNING);
254 return false;
255 } // end check for themes directory
257 ksort($this->themes);
258 return true;
262 * checks if given theme name is a known theme
264 * @param string $theme name fo theme to check for
266 function checkTheme($theme)
268 if (! array_key_exists($theme, $this->themes)) {
269 return false;
272 return true;
276 * returns HTML selectbox, with or without form enclosed
278 * @param boolean $form whether enclosed by from tags or not
280 function getHtmlSelectBox($form = true)
282 $select_box = '';
284 if ($form) {
285 $select_box .= '<form name="setTheme" method="post" action="index.php"'
286 .' target="_parent">';
287 $select_box .= PMA_generate_common_hidden_inputs();
290 $theme_selected = FALSE;
291 $theme_preview_path= './themes.php';
292 $theme_preview_href = '<a href="' . $theme_preview_path . '" target="themes" onclick="'
293 . "window.open('" . $theme_preview_path . "','themes','left=10,top=20,width=510,height=350,scrollbars=yes,status=yes,resizable=yes');"
294 . '">';
295 $select_box .= $theme_preview_href . $GLOBALS['strTheme'] . '</a>:' . "\n";
297 $select_box .= '<select name="set_theme" xml:lang="en" dir="ltr"'
298 .' onchange="this.form.submit();" >';
299 foreach ($this->themes as $each_theme_id => $each_theme) {
300 $select_box .= '<option value="' . $each_theme_id . '"';
301 if ($this->active_theme === $each_theme_id) {
302 $select_box .= ' selected="selected"';
304 $select_box .= '>' . htmlspecialchars($each_theme->getName()) . '</option>';
306 $select_box .= '</select>';
308 if ($form) {
309 $select_box .= '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
310 $select_box .= '</form>';
313 return $select_box;
317 * enables backward compatibility
319 function makeBc()
321 $GLOBALS['theme'] = $this->theme->getId();
322 $GLOBALS['pmaThemePath'] = $this->theme->getPath();
323 $GLOBALS['pmaThemeImage'] = $this->theme->getImgPath();
326 * load layout file if exists
328 if (@file_exists($GLOBALS['pmaThemePath'] . 'layout.inc.php')) {
329 include $GLOBALS['pmaThemePath'] . 'layout.inc.php';
336 * prints out preview for every theme
338 * @uses $this->themes
339 * @uses PMA_Theme::printPreview()
341 function printPreviews()
343 foreach ($this->themes as $each_theme) {
344 $each_theme->printPreview();
345 } // end 'open themes'
349 * returns PMA_Theme object for fall back theme
350 * @return object PMA_Theme
352 function getFallBackTheme()
354 if (isset($this->themes['original'])) {
355 return $this->themes['original'];
358 return false;
362 * prints css data
364 function printCss($type)
366 if ($this->theme->loadCss($type)) {
367 return true;
370 // if loading css for this theme failed, try default theme css
371 $fallback_theme = $this->getFallBackTheme();
372 if ($fallback_theme && $fallback_theme->loadCss($type)) {
373 return true;
376 return false;