2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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
21 * @var string theme version
24 var $version = '0.0.0.0';
27 * @var string theme name
33 * @var string theme id
39 * @var string theme path
45 * @var string image path
51 * @var array valid css types
54 var $types = array('left', 'right', 'print');
57 * @var integer last modification time for info file
63 * needed because sometimes, the mtime for different themes
65 * @var integer filesize for info file
68 var $filesize_info = 0;
72 * @uses PMA_Theme::getPath()
73 * @uses PMA_Theme::$mtime_info
74 * @uses PMA_Theme::setVersion()
75 * @uses PMA_Theme::setName()
79 * @return boolean whether loading them info was successful or not
83 if (! file_exists($this->getPath() . '/info.inc.php')) {
87 if ($this->mtime_info
=== filemtime($this->getPath() . '/info.inc.php')) {
91 @include
$this->getPath() . '/info.inc.php';
93 // was it set correctly?
94 if (! isset($theme_name)) {
98 $this->mtime_info
= filemtime($this->getPath() . '/info.inc.php');
99 $this->filesize_info
= filesize($this->getPath() . '/info.inc.php');
101 if (isset($theme_full_version)) {
102 $this->setVersion($theme_full_version);
103 } elseif (isset($theme_generation, $theme_version)) {
104 $this->setVersion($theme_generation . '.' . $theme_version);
106 $this->setName($theme_name);
112 * returns theme object loaded from given folder
113 * or false if theme is invalid
118 * @uses PMA_Theme::setPath()
119 * @uses PMA_Theme::loadInfo()
120 * @uses PMA_Theme::checkImgPath()
121 * @param string $folder path to theme
122 * @return object PMA_Theme
124 static public function load($folder)
126 $theme = new PMA_Theme();
128 $theme->setPath($folder);
130 if (! $theme->loadInfo()) {
134 $theme->checkImgPath();
140 * checks image path for existance - if not found use img from original theme
143 * @uses PMA_Theme::getPath()
144 * @uses PMA_Theme::setImgPath()
145 * @uses PMA_Theme::getName()
146 * @uses $GLOBALS['cfg']['ThemePath']
150 function checkImgPath()
152 if (is_dir($this->getPath() . '/img/')) {
153 $this->setImgPath($this->getPath() . '/img/');
155 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
156 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
160 sprintf(__('No valid image path for theme %s found!'), $this->getName()),
167 * returns path to theme
170 * @uses PMA_Theme::$path as return value
171 * @return string $path path to theme
179 * returns layout file
182 * @uses PMA_Theme::getPath()
183 * @return string layout file
185 function getLayoutFile()
187 return $this->getPath() . '/layout.inc.php';
194 * @uses PMA_Theme::$path to set it
195 * @param string $path path to theme
197 function setPath($path)
199 $this->path
= trim($path);
206 * @uses PMA_Theme::$version
207 * @param string new version
209 function setVersion($version)
211 $this->version
= trim($version);
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
231 * @uses version_compare()
232 * @uses PMA_Theme::getVersion()
233 * @param string $version version to compare to
236 function checkVersion($version)
238 return version_compare($this->getVersion(), $version, 'lt');
245 * @uses PMA_Theme::$name to set it
247 * @param string $name new name
249 function setName($name)
251 $this->name
= trim($name);
258 * @uses PMA_Theme::$name as return value
259 * @return string name
270 * @uses PMA_Theme::$id to set it
271 * @param string $id new id
275 $this->id
= trim($id);
282 * @uses PMA_Theme::$id as return value
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;
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)
314 * @uses PMA_Theme::getPath()
315 * @uses PMA_Theme::$types
316 * @uses PMA_SQP_buildCssData()
317 * @uses file_exists()
319 * @param string $type left, right or print
321 function loadCss(&$type)
323 if (empty($type) ||
! in_array($type, $this->types
)) {
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)) {
338 if ($GLOBALS['text_dir'] === 'ltr') {
351 * prints out the preview for this theme
354 * @uses PMA_Theme::getName()
355 * @uses PMA_Theme::getVersion()
356 * @uses PMA_Theme::getId()
357 * @uses PMA_Theme::getPath()
358 * @uses PMA_generate_common_url()
360 * @uses file_exists()
361 * @uses htmlspecialchars()
363 function printPreview()
365 echo '<div class="theme_preview">';
366 echo '<h2>' . htmlspecialchars($this->getName())
367 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
369 .'<a target="_top" href="index.php'
370 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
371 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
373 if (@file_exists
($this->getPath() . '/screen.png')) {
374 // if screen exists then output
376 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
377 .' alt="' . htmlspecialchars($this->getName()) . '"'
378 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
380 echo __('No preview available.');
383 echo '[ <strong>' . __('take it') . '</strong> ]</a>'