Improve translation.
[phpmyadmin/crack.git] / libraries / Theme.class.php
blob45399303478f0866baab71ed305fbe0387dbce9d
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 static public 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['strThemeNoValidImgPath']
137 * @uses is_dir()
138 * @uses sprintf()
140 function checkImgPath()
142 if (is_dir($this->getPath() . '/img/')) {
143 $this->setImgPath($this->getPath() . '/img/');
144 return true;
145 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
146 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
147 return true;
148 } else {
149 trigger_error(
150 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
151 E_USER_ERROR);
152 return false;
157 * returns path to theme
159 * @access public
160 * @uses PMA_Theme::$path as return value
161 * @return string $path path to theme
163 function getPath()
165 return $this->path;
169 * returns layout file
171 * @access public
172 * @uses PMA_Theme::getPath()
173 * @return string layout file
175 function getLayoutFile()
177 return $this->getPath() . '/layout.inc.php';
181 * set path to theme
183 * @access public
184 * @uses PMA_Theme::$path to set it
185 * @param string $path path to theme
187 function setPath($path)
189 $this->path = trim($path);
193 * sets version
195 * @access public
196 * @uses PMA_Theme::$version
197 * @param string new version
199 function setVersion($version)
201 $this->version = trim($version);
205 * returns version
207 * @access public
208 * @uses PMA_Theme::$version
209 * @return string version
211 function getVersion()
213 return $this->version;
217 * checks theme version agaisnt $version
218 * returns true if theme version is equal or higher to $version
220 * @access public
221 * @uses version_compare()
222 * @uses PMA_Theme::getVersion()
223 * @param string $version version to compare to
224 * @return boolean
226 function checkVersion($version)
228 return version_compare($this->getVersion(), $version, 'lt');
232 * sets name
234 * @access public
235 * @uses PMA_Theme::$name to set it
236 * @uses trim()
237 * @param string $name new name
239 function setName($name)
241 $this->name = trim($name);
245 * returns name
247 * @access public
248 * @uses PMA_Theme::$name as return value
249 * @return string name
251 function getName()
253 return $this->name;
257 * sets id
259 * @access public
260 * @uses PMA_Theme::$id to set it
261 * @param string $id new id
263 function setId($id)
265 $this->id = trim($id);
269 * returns id
271 * @access public
272 * @uses PMA_Theme::$id as return value
273 * @return string id
275 function getId()
277 return $this->id;
281 * @access public
282 * @uses PMA_Theme::$img_path to set it
283 * @param string path to images for this theme
285 function setImgPath($path)
287 $this->img_path = $path;
291 * @access public
292 * @uses PMA_Theme::$img_path as retunr value
293 * @return string image path for this theme
295 function getImgPath()
297 return $this->img_path;
301 * load css (send to stdout, normaly the browser)
303 * @access public
304 * @uses PMA_Theme::getPath()
305 * @uses PMA_Theme::$types
306 * @uses PMA_SQP_buildCssData()
307 * @uses file_exists()
308 * @uses in_array()
309 * @param string $type left, right or print
311 function loadCss(&$type)
313 if (empty($type) || ! in_array($type, $this->types)) {
314 $type = 'left';
317 if ($type == 'right') {
318 echo PMA_SQP_buildCssData();
321 $_css_file = $this->getPath()
322 . '/css/theme_' . $type . '.css.php';
324 if (! file_exists($_css_file)) {
325 return false;
328 if ($GLOBALS['text_dir'] === 'ltr') {
329 $right = 'right';
330 $left = 'left';
331 } else {
332 $right = 'left';
333 $left = 'right';
336 include $_css_file;
337 return true;
341 * prints out the preview for this theme
343 * @access public
344 * @uses PMA_Theme::getName()
345 * @uses PMA_Theme::getVersion()
346 * @uses PMA_Theme::getId()
347 * @uses PMA_Theme::getPath()
348 * @uses $GLOBALS['strThemeNoPreviewAvailable']
349 * @uses $GLOBALS['strTakeIt']
350 * @uses PMA_generate_common_url()
351 * @uses addslashes()
352 * @uses file_exists()
353 * @uses htmlspecialchars()
355 function printPreview()
357 echo '<div class="theme_preview">';
358 echo '<h2>' . htmlspecialchars($this->getName())
359 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
360 .'<p>'
361 .'<a target="_top" href="index.php'
362 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
363 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
364 .' return false;">';
365 if (@file_exists($this->getPath() . '/screen.png')) {
366 // if screen exists then output
368 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
369 .' alt="' . htmlspecialchars($this->getName()) . '"'
370 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
371 } else {
372 echo $GLOBALS['strThemeNoPreviewAvailable'];
375 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
376 .'</p>'
377 .'</div>';