2.11.1.2 release
[phpmyadmin/arisferyanto.git] / libraries / Theme.class.php
bloba0a93eb9b8c4cbcf64a41600bf8fdca78ec954dd
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA_Theme class
6 * @version $Id$
7 */
9 /**
10 * handles theme
12 * @todo add the possibility to make a theme depends on another theme and by default on orignal
13 * @todo make all components optional - taking missing compnents from 'parent' theme
14 * @todo make css optionaly replacing 'parent' css or extending it (by appending at the end)
15 * @todo add an optional global css file - which will be used for both frames
18 class PMA_Theme {
19 /**
20 * @var string theme version
21 * @access protected
23 var $version = '0.0.0.0';
25 /**
26 * @var string theme name
27 * @access protected
29 var $name = '';
31 /**
32 * @var string theme id
33 * @access protected
35 var $id = '';
37 /**
38 * @var string theme path
39 * @access protected
41 var $path = '';
43 /**
44 * @var string image path
45 * @access protected
47 var $img_path = '';
49 /**
50 * @var array valid css types
51 * @access protected
53 var $types = array('left', 'right', 'print');
55 /**
56 * @var integer last modification time for info file
57 * @access protected
59 var $mtime_info = 0;
61 /**
62 * @access public
63 * @uses PMA_Theme::getPath()
64 * @uses PMA_Theme::$mtime_info
65 * @uses PMA_Theme::setVersion()
66 * @uses PMA_Theme::setName()
67 * @uses filemtime()
68 * @uses file_exists()
69 * @return boolean whether loading them info was successful or not
71 function loadInfo()
73 if (! file_exists($this->getPath() . '/info.inc.php')) {
74 return false;
77 if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
78 return true;
81 @include $this->getPath() . '/info.inc.php';
83 // did it set correctly?
84 if (! isset($theme_name)) {
85 return false;
88 $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
90 if (isset($theme_full_version)) {
91 $this->setVersion($theme_full_version);
92 } elseif (isset($theme_generation, $theme_version)) {
93 $this->setVersion($theme_generation . '.' . $theme_version);
95 $this->setName($theme_name);
97 return true;
101 * returns theme object loaded from given folder
102 * or false if theme is invalid
104 * @static
105 * @access public
106 * @uses PMA_Theme
107 * @uses PMA_Theme::setPath()
108 * @uses PMA_Theme::loadInfo()
109 * @uses PMA_Theme::checkImgPath()
110 * @param string $folder path to theme
111 * @return object PMA_Theme
113 function load($folder)
115 $theme = new PMA_Theme();
117 $theme->setPath($folder);
119 if (! $theme->loadInfo()) {
120 return false;
123 $theme->checkImgPath();
125 return $theme;
129 * checks image path for existance - if not found use img from original theme
131 * @access public
132 * @uses PMA_Theme::getPath()
133 * @uses PMA_Theme::setImgPath()
134 * @uses PMA_Theme::getName()
135 * @uses $GLOBALS['cfg']['ThemePath']
136 * @uses $GLOBALS['PMA_errors']
137 * @uses $GLOBALS['strThemeNoValidImgPath']
138 * @uses is_dir()
139 * @uses sprintf()
141 function checkImgPath()
143 if (is_dir($this->getPath() . '/img/')) {
144 $this->setImgPath($this->getPath() . '/img/');
145 return true;
146 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
147 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
148 return true;
149 } else {
150 $GLOBALS['PMA_errors'][] =
151 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
153 trigger_error(
154 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
155 E_USER_WARNING);
157 return false;
162 * returns path to theme
164 * @access public
165 * @uses PMA_Theme::$path as return value
166 * @return string $path path to theme
168 function getPath()
170 return $this->path;
174 * returns layout file
176 * @access public
177 * @uses PMA_Theme::getPath()
178 * @return string layout file
180 function getLayoutFile()
182 return $this->getPath() . '/layout.inc.php';
186 * set path to theme
188 * @access public
189 * @uses PMA_Theme::$path to set it
190 * @param string $path path to theme
192 function setPath($path)
194 $this->path = trim($path);
198 * sets version
200 * @access public
201 * @uses PMA_Theme::$version
202 * @param string new version
204 function setVersion($version)
206 $this->version = trim($version);
210 * returns version
212 * @access public
213 * @uses PMA_Theme::$version
214 * @return string version
216 function getVersion()
218 return $this->version;
222 * checks theme version agaisnt $version
223 * returns true if theme version is equal or higher to $version
225 * @access public
226 * @uses version_compare()
227 * @uses PMA_Theme::getVersion()
228 * @param string $version version to compare to
229 * @return boolean
231 function checkVersion($version)
233 return version_compare($this->getVersion(), $version, 'lt');
237 * sets name
239 * @access public
240 * @uses PMA_Theme::$name to set it
241 * @uses trim()
242 * @param string $name new name
244 function setName($name)
246 $this->name = trim($name);
250 * returns name
252 * @access public
253 * @uses PMA_Theme::$name as return value
254 * @return string name
256 function getName()
258 return $this->name;
262 * sets id
264 * @access public
265 * @uses PMA_Theme::$id to set it
266 * @param string $id new id
268 function setId($id)
270 $this->id = trim($id);
274 * returns id
276 * @access public
277 * @uses PMA_Theme::$id as return value
278 * @return string id
280 function getId()
282 return $this->id;
286 * @access public
287 * @uses PMA_Theme::$img_path to set it
288 * @param string path to images for this theme
290 function setImgPath($path)
292 $this->img_path = $path;
296 * @access public
297 * @uses PMA_Theme::$img_path as retunr value
298 * @return string image path for this theme
300 function getImgPath()
302 return $this->img_path;
306 * load css (send to stdout, normaly the browser)
308 * @access public
309 * @uses PMA_Theme::getPath()
310 * @uses PMA_Theme::$types
311 * @uses PMA_SQP_buildCssData()
312 * @uses file_exists()
313 * @uses in_array()
314 * @param string $type left, right or print
316 function loadCss(&$type)
318 if (empty($type) || ! in_array($type, $this->types)) {
319 $type = 'left';
322 if ($type == 'right') {
323 echo PMA_SQP_buildCssData();
326 $_css_file = $this->getPath()
327 . '/css/theme_' . $type . '.css.php';
329 if (! file_exists($_css_file)) {
330 return false;
333 if ($GLOBALS['text_dir'] === 'ltr') {
334 $right = 'right';
335 $left = 'left';
336 } else {
337 $right = 'left';
338 $left = 'right';
341 include $_css_file;
342 return true;
346 * prints out the preview for this theme
348 * @access public
349 * @uses PMA_Theme::getName()
350 * @uses PMA_Theme::getVersion()
351 * @uses PMA_Theme::getId()
352 * @uses PMA_Theme::getPath()
353 * @uses $GLOBALS['strThemeNoPreviewAvailable']
354 * @uses $GLOBALS['strTakeIt']
355 * @uses PMA_generate_common_url()
356 * @uses addslashes()
357 * @uses file_exists()
358 * @uses htmlspecialchars()
360 function printPreview()
362 echo '<div class="theme_preview">';
363 echo '<h2>' . htmlspecialchars($this->getName())
364 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
365 .'<p>'
366 .'<a target="_top" href="index.php'
367 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
368 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
369 .' return false;">';
370 if (@file_exists($this->getPath() . '/screen.png')) {
371 // if screen exists then output
373 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
374 .' alt="' . htmlspecialchars($this->getName()) . '"'
375 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
376 } else {
377 echo $GLOBALS['strThemeNoPreviewAvailable'];
380 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
381 .'</p>'
382 .'</div>';