Improve docs.
[phpmyadmin/crack.git] / libraries / Theme.class.php
blob196a249ebc5e977d87e6ae22ffa98eede619c035
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 class PMA_Theme {
6 /**
7 * @var string version
8 */
9 var $version = '0.0.0.0';
11 /**
12 * @var string name
14 var $name = '';
16 /**
17 * @var string id
19 var $id = '';
21 /**
22 * @var string
24 var $path = '';
26 /**
27 * @var string
29 var $img_path = '';
31 /**
32 * @var array valid css types
34 var $types = array('left', 'right', 'print');
36 /**
37 * @var integer last modification time for info file
39 var $mtime_info = 0;
41 function __wakeup()
43 $this->loadInfo();
44 $this->checkImgPath();
47 function loadInfo()
49 if (! file_exists($this->getPath() . '/info.inc.php')) {
50 return false;
53 if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
54 return true;
57 @include $this->getPath() . '/info.inc.php';
59 // did it set correctly?
60 if (! isset($theme_name)) {
61 return false;
64 $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
66 if (isset($theme_full_version)) {
67 $this->setVersion($theme_full_version);
68 } elseif (isset($theme_generation, $theme_version)) {
69 $this->setVersion($theme_generation . '.' . $theme_version);
71 $this->setName($theme_name);
73 return true;
76 /**
77 * returns theme object loaded from given folder
78 * or false if theme is invalid
80 * @static
81 * @param string path to theme
82 * @return object PMA_Theme
84 function load($folder)
87 $theme = new PMA_Theme();
89 $theme->setPath($folder);
91 if (! $theme->loadInfo()) {
92 return false;
95 $theme->checkImgPath();
97 return $theme;
100 function checkImgPath()
102 if (is_dir($this->getPath() . '/img/')) {
103 $this->setImgPath($this->getPath() . '/img/');
104 return true;
105 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
106 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
107 return true;
108 } else {
109 $GLOBALS['PMA_errors'][] =
110 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
111 trigger_error(
112 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
113 E_USER_WARNING);
114 return false;
119 * returns path to theme
120 * @uses $this->$path as return value
121 * @return string $path path to theme
123 function getPath()
125 return $this->path;
129 * returns layout file
131 * @return string layout file
133 function getLayoutFile()
135 return $this->getPath() . '/layout.inc.php';
139 * set path to theme
140 * @uses $this->$path to set it
141 * @param string $path path to theme
143 function setPath($path)
145 $this->path = trim($path);
149 * sets version
150 * @uses $this->version
151 * @param string new version
153 function setVersion($version)
155 $this->version = trim($version);
159 * returns version
160 * @uses $this->version
161 * @return string version
163 function getVersion()
165 return $this->version;
169 * checks theme version agaisnt $version
170 * returns true if theme version is equal or higher to $version
172 * @uses version_compare()
173 * @uses $this->getVersion()
174 * @param string $version version to compare to
175 * @return boolean
177 function checkVersion($version)
179 return version_compare($this->getVersion(), $version, 'lt');
183 * sets name
184 * @param string $name new name
186 function setName($name)
188 $this->name = trim($name);
192 * returns name
193 * @return string name
195 function getName()
197 return $this->name;
201 * sets id
202 * @param string $id new id
204 function setId($id)
206 $this->id = trim($id);
210 * returns id
211 * @return string id
213 function getId()
215 return $this->id;
218 function setImgPath($path)
220 $this->img_path = $path;
223 function getImgPath()
225 return $this->img_path;
229 * load css (send to stdout, normaly the browser)
231 * @uses $this->getPath()
232 * @uses $this->types
233 * @uses PMA_SQP_buildCssData()
234 * @uses file_exists()
235 * @uses in_array()
236 * @param string $type left, right or print
238 function loadCss(&$type)
240 if (empty($type) || ! in_array($type, $this->types)) {
241 $type = 'left';
244 if ($type == 'right') {
245 echo PMA_SQP_buildCssData();
248 $_css_file = $this->getPath()
249 . '/css/theme_' . $type . '.css.php';
251 if (! file_exists($_css_file)) {
252 return false;
255 if ($GLOBALS['text_dir'] === 'ltr') {
256 $right = 'right';
257 $left = 'left';
258 } else {
259 $right = 'left';
260 $left = 'right';
263 include $_css_file;
264 return true;
268 * prints out the preview for this theme
270 * @uses $this->getName()
271 * @uses $this->getVersion()
272 * @uses $this->getId()
273 * @uses $this->getPath()
274 * @uses $GLOBALS['strThemeNoPreviewAvailable']
275 * @uses $GLOBALS['strTakeIt']
276 * @uses PMA_generate_common_url()
277 * @uses addslashes()
278 * @uses file_exists()
279 * @uses htmlspecialchars()
281 function printPreview()
283 echo '<div class="theme_preview">';
284 echo '<h2>' . htmlspecialchars($this->getName())
285 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
286 .'<p>'
287 .'<a target="_top" href="index.php'
288 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
289 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
290 .' return false;">';
291 if (@file_exists($this->getPath() . '/screen.png')) {
292 // if screen exists then output
294 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
295 .' alt="' . htmlspecialchars($this->getName()) . '"'
296 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
297 } else {
298 echo $GLOBALS['strThemeNoPreviewAvailable'];
301 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
302 .'</p>'
303 .'</div>';