bug #2363919 [display] Incorrect size for view
[phpmyadmin/crack.git] / libraries / Theme.class.php
blob7f8f222103c37b6dd6d05f63938f931fcea8a896
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 depend on another theme and by default on original
13 * @todo make all components optional - get missing components from 'parent' theme
14 * @todo make css optionally 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 * needed because sometimes, the mtime for different themes
63 * is identical
64 * @var integer filesize for info file
65 * @access protected
67 var $filesize_info = 0;
69 /**
70 * @access public
71 * @uses PMA_Theme::getPath()
72 * @uses PMA_Theme::$mtime_info
73 * @uses PMA_Theme::setVersion()
74 * @uses PMA_Theme::setName()
75 * @uses filemtime()
76 * @uses filesize()
77 * @uses file_exists()
78 * @return boolean whether loading them info was successful or not
80 function loadInfo()
82 if (! file_exists($this->getPath() . '/info.inc.php')) {
83 return false;
86 if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
87 return true;
90 @include $this->getPath() . '/info.inc.php';
92 // was it set correctly?
93 if (! isset($theme_name)) {
94 return false;
97 $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
98 $this->filesize_info = filesize($this->getPath() . '/info.inc.php');
100 if (isset($theme_full_version)) {
101 $this->setVersion($theme_full_version);
102 } elseif (isset($theme_generation, $theme_version)) {
103 $this->setVersion($theme_generation . '.' . $theme_version);
105 $this->setName($theme_name);
107 return true;
111 * returns theme object loaded from given folder
112 * or false if theme is invalid
114 * @static
115 * @access public
116 * @uses PMA_Theme
117 * @uses PMA_Theme::setPath()
118 * @uses PMA_Theme::loadInfo()
119 * @uses PMA_Theme::checkImgPath()
120 * @param string $folder path to theme
121 * @return object PMA_Theme
123 static public function load($folder)
125 $theme = new PMA_Theme();
127 $theme->setPath($folder);
129 if (! $theme->loadInfo()) {
130 return false;
133 $theme->checkImgPath();
135 return $theme;
139 * checks image path for existance - if not found use img from original theme
141 * @access public
142 * @uses PMA_Theme::getPath()
143 * @uses PMA_Theme::setImgPath()
144 * @uses PMA_Theme::getName()
145 * @uses $GLOBALS['cfg']['ThemePath']
146 * @uses $GLOBALS['strThemeNoValidImgPath']
147 * @uses is_dir()
148 * @uses sprintf()
150 function checkImgPath()
152 if (is_dir($this->getPath() . '/img/')) {
153 $this->setImgPath($this->getPath() . '/img/');
154 return true;
155 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
156 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
157 return true;
158 } else {
159 trigger_error(
160 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
161 E_USER_ERROR);
162 return false;
167 * returns path to theme
169 * @access public
170 * @uses PMA_Theme::$path as return value
171 * @return string $path path to theme
173 function getPath()
175 return $this->path;
179 * returns layout file
181 * @access public
182 * @uses PMA_Theme::getPath()
183 * @return string layout file
185 function getLayoutFile()
187 return $this->getPath() . '/layout.inc.php';
191 * set path to theme
193 * @access public
194 * @uses PMA_Theme::$path to set it
195 * @param string $path path to theme
197 function setPath($path)
199 $this->path = trim($path);
203 * sets version
205 * @access public
206 * @uses PMA_Theme::$version
207 * @param string new version
209 function setVersion($version)
211 $this->version = trim($version);
215 * returns version
217 * @access public
218 * @uses PMA_Theme::$version
219 * @return string version
221 function getVersion()
223 return $this->version;
227 * checks theme version agaisnt $version
228 * returns true if theme version is equal or higher to $version
230 * @access public
231 * @uses version_compare()
232 * @uses PMA_Theme::getVersion()
233 * @param string $version version to compare to
234 * @return boolean
236 function checkVersion($version)
238 return version_compare($this->getVersion(), $version, 'lt');
242 * sets name
244 * @access public
245 * @uses PMA_Theme::$name to set it
246 * @uses trim()
247 * @param string $name new name
249 function setName($name)
251 $this->name = trim($name);
255 * returns name
257 * @access public
258 * @uses PMA_Theme::$name as return value
259 * @return string name
261 function getName()
263 return $this->name;
267 * sets id
269 * @access public
270 * @uses PMA_Theme::$id to set it
271 * @param string $id new id
273 function setId($id)
275 $this->id = trim($id);
279 * returns id
281 * @access public
282 * @uses PMA_Theme::$id as return value
283 * @return string id
285 function getId()
287 return $this->id;
291 * @access public
292 * @uses PMA_Theme::$img_path to set it
293 * @param string path to images for this theme
295 function setImgPath($path)
297 $this->img_path = $path;
301 * @access public
302 * @uses PMA_Theme::$img_path as retunr value
303 * @return string image path for this theme
305 function getImgPath()
307 return $this->img_path;
311 * load css (send to stdout, normally the browser)
313 * @access public
314 * @uses PMA_Theme::getPath()
315 * @uses PMA_Theme::$types
316 * @uses PMA_SQP_buildCssData()
317 * @uses file_exists()
318 * @uses in_array()
319 * @param string $type left, right or print
321 function loadCss(&$type)
323 if (empty($type) || ! in_array($type, $this->types)) {
324 $type = 'left';
327 if ($type == 'right') {
328 echo PMA_SQP_buildCssData();
331 $_css_file = $this->getPath()
332 . '/css/theme_' . $type . '.css.php';
334 if (! file_exists($_css_file)) {
335 return false;
338 if ($GLOBALS['text_dir'] === 'ltr') {
339 $right = 'right';
340 $left = 'left';
341 } else {
342 $right = 'left';
343 $left = 'right';
346 include $_css_file;
347 return true;
351 * prints out the preview for this theme
353 * @access public
354 * @uses PMA_Theme::getName()
355 * @uses PMA_Theme::getVersion()
356 * @uses PMA_Theme::getId()
357 * @uses PMA_Theme::getPath()
358 * @uses $GLOBALS['strThemeNoPreviewAvailable']
359 * @uses $GLOBALS['strTakeIt']
360 * @uses PMA_generate_common_url()
361 * @uses addslashes()
362 * @uses file_exists()
363 * @uses htmlspecialchars()
365 function printPreview()
367 echo '<div class="theme_preview">';
368 echo '<h2>' . htmlspecialchars($this->getName())
369 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
370 .'<p>'
371 .'<a target="_top" href="index.php'
372 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
373 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
374 .' return false;">';
375 if (@file_exists($this->getPath() . '/screen.png')) {
376 // if screen exists then output
378 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
379 .' alt="' . htmlspecialchars($this->getName()) . '"'
380 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
381 } else {
382 echo $GLOBALS['strThemeNoPreviewAvailable'];
385 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
386 .'</p>'
387 .'</div>';