Russian update
[phpmyadmin/tyronm.git] / libraries / Theme.class.php
blob30cfff224d39bec1d0c12c2406b852904a0b87db
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA_Theme class
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
11 * handles theme
13 * @todo add the possibility to make a theme depend on another theme and by default on original
14 * @todo make all components optional - get missing components from 'parent' theme
15 * @todo make css optionally replacing 'parent' css or extending it (by appending at the end)
16 * @todo add an optional global css file - which will be used for both frames
18 * @package phpMyAdmin
20 class PMA_Theme {
21 /**
22 * @var string theme version
23 * @access protected
25 var $version = '0.0.0.0';
27 /**
28 * @var string theme name
29 * @access protected
31 var $name = '';
33 /**
34 * @var string theme id
35 * @access protected
37 var $id = '';
39 /**
40 * @var string theme path
41 * @access protected
43 var $path = '';
45 /**
46 * @var string image path
47 * @access protected
49 var $img_path = '';
51 /**
52 * @var array valid css types
53 * @access protected
55 var $types = array('left', 'right', 'print');
57 /**
58 * @var integer last modification time for info file
59 * @access protected
61 var $mtime_info = 0;
63 /**
64 * needed because sometimes, the mtime for different themes
65 * is identical
66 * @var integer filesize for info file
67 * @access protected
69 var $filesize_info = 0;
71 /**
72 * @access public
73 * @uses PMA_Theme::getPath()
74 * @uses PMA_Theme::$mtime_info
75 * @uses PMA_Theme::setVersion()
76 * @uses PMA_Theme::setName()
77 * @uses filemtime()
78 * @uses filesize()
79 * @uses file_exists()
80 * @return boolean whether loading them info was successful or not
82 function loadInfo()
84 if (! file_exists($this->getPath() . '/info.inc.php')) {
85 return false;
88 if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
89 return true;
92 @include $this->getPath() . '/info.inc.php';
94 // was it set correctly?
95 if (! isset($theme_name)) {
96 return false;
99 $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
100 $this->filesize_info = filesize($this->getPath() . '/info.inc.php');
102 if (isset($theme_full_version)) {
103 $this->setVersion($theme_full_version);
104 } elseif (isset($theme_generation, $theme_version)) {
105 $this->setVersion($theme_generation . '.' . $theme_version);
107 $this->setName($theme_name);
109 return true;
113 * returns theme object loaded from given folder
114 * or false if theme is invalid
116 * @static
117 * @access public
118 * @uses PMA_Theme
119 * @uses PMA_Theme::setPath()
120 * @uses PMA_Theme::loadInfo()
121 * @uses PMA_Theme::checkImgPath()
122 * @param string $folder path to theme
123 * @return object PMA_Theme
125 static public function load($folder)
127 $theme = new PMA_Theme();
129 $theme->setPath($folder);
131 if (! $theme->loadInfo()) {
132 return false;
135 $theme->checkImgPath();
137 return $theme;
141 * checks image path for existance - if not found use img from original theme
143 * @access public
144 * @uses PMA_Theme::getPath()
145 * @uses PMA_Theme::setImgPath()
146 * @uses PMA_Theme::getName()
147 * @uses $GLOBALS['cfg']['ThemePath']
148 * @uses $GLOBALS['strThemeNoValidImgPath']
149 * @uses is_dir()
150 * @uses sprintf()
152 function checkImgPath()
154 if (is_dir($this->getPath() . '/img/')) {
155 $this->setImgPath($this->getPath() . '/img/');
156 return true;
157 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
158 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
159 return true;
160 } else {
161 trigger_error(
162 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
163 E_USER_ERROR);
164 return false;
169 * returns path to theme
171 * @access public
172 * @uses PMA_Theme::$path as return value
173 * @return string $path path to theme
175 function getPath()
177 return $this->path;
181 * returns layout file
183 * @access public
184 * @uses PMA_Theme::getPath()
185 * @return string layout file
187 function getLayoutFile()
189 return $this->getPath() . '/layout.inc.php';
193 * set path to theme
195 * @access public
196 * @uses PMA_Theme::$path to set it
197 * @param string $path path to theme
199 function setPath($path)
201 $this->path = trim($path);
205 * sets version
207 * @access public
208 * @uses PMA_Theme::$version
209 * @param string new version
211 function setVersion($version)
213 $this->version = trim($version);
217 * returns version
219 * @access public
220 * @uses PMA_Theme::$version
221 * @return string version
223 function getVersion()
225 return $this->version;
229 * checks theme version agaisnt $version
230 * returns true if theme version is equal or higher to $version
232 * @access public
233 * @uses version_compare()
234 * @uses PMA_Theme::getVersion()
235 * @param string $version version to compare to
236 * @return boolean
238 function checkVersion($version)
240 return version_compare($this->getVersion(), $version, 'lt');
244 * sets name
246 * @access public
247 * @uses PMA_Theme::$name to set it
248 * @uses trim()
249 * @param string $name new name
251 function setName($name)
253 $this->name = trim($name);
257 * returns name
259 * @access public
260 * @uses PMA_Theme::$name as return value
261 * @return string name
263 function getName()
265 return $this->name;
269 * sets id
271 * @access public
272 * @uses PMA_Theme::$id to set it
273 * @param string $id new id
275 function setId($id)
277 $this->id = trim($id);
281 * returns id
283 * @access public
284 * @uses PMA_Theme::$id as return value
285 * @return string id
287 function getId()
289 return $this->id;
293 * @access public
294 * @uses PMA_Theme::$img_path to set it
295 * @param string path to images for this theme
297 function setImgPath($path)
299 $this->img_path = $path;
303 * @access public
304 * @uses PMA_Theme::$img_path as retunr value
305 * @return string image path for this theme
307 function getImgPath()
309 return $this->img_path;
313 * load css (send to stdout, normally the browser)
315 * @access public
316 * @uses PMA_Theme::getPath()
317 * @uses PMA_Theme::$types
318 * @uses PMA_SQP_buildCssData()
319 * @uses file_exists()
320 * @uses in_array()
321 * @param string $type left, right or print
323 function loadCss(&$type)
325 if (empty($type) || ! in_array($type, $this->types)) {
326 $type = 'left';
329 if ($type == 'right') {
330 echo PMA_SQP_buildCssData();
333 $_css_file = $this->getPath()
334 . '/css/theme_' . $type . '.css.php';
336 if (! file_exists($_css_file)) {
337 return false;
340 if ($GLOBALS['text_dir'] === 'ltr') {
341 $right = 'right';
342 $left = 'left';
343 } else {
344 $right = 'left';
345 $left = 'right';
348 include $_css_file;
349 return true;
353 * prints out the preview for this theme
355 * @access public
356 * @uses PMA_Theme::getName()
357 * @uses PMA_Theme::getVersion()
358 * @uses PMA_Theme::getId()
359 * @uses PMA_Theme::getPath()
360 * @uses $GLOBALS['strThemeNoPreviewAvailable']
361 * @uses $GLOBALS['strTakeIt']
362 * @uses PMA_generate_common_url()
363 * @uses addslashes()
364 * @uses file_exists()
365 * @uses htmlspecialchars()
367 function printPreview()
369 echo '<div class="theme_preview">';
370 echo '<h2>' . htmlspecialchars($this->getName())
371 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
372 .'<p>'
373 .'<a target="_top" href="index.php'
374 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
375 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
376 .' return false;">';
377 if (@file_exists($this->getPath() . '/screen.png')) {
378 // if screen exists then output
380 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
381 .' alt="' . htmlspecialchars($this->getName()) . '"'
382 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
383 } else {
384 echo $GLOBALS['strThemeNoPreviewAvailable'];
387 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
388 .'</p>'
389 .'</div>';