2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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
20 * @var string theme version
23 var $version = '0.0.0.0';
26 * @var string theme name
32 * @var string theme id
38 * @var string theme path
44 * @var string image path
50 * @var array valid css types
53 var $types = array('left', 'right', 'print');
56 * @var integer last modification time for info file
63 * @uses PMA_Theme::getPath()
64 * @uses PMA_Theme::$mtime_info
65 * @uses PMA_Theme::setVersion()
66 * @uses PMA_Theme::setName()
69 * @return boolean whether loading them info was successful or not
73 if (! file_exists($this->getPath() . '/info.inc.php')) {
77 if ($this->mtime_info
=== filemtime($this->getPath() . '/info.inc.php')) {
81 @include
$this->getPath() . '/info.inc.php';
83 // did it set correctly?
84 if (! isset($theme_name)) {
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);
101 * returns theme object loaded from given folder
102 * or false if theme is invalid
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()) {
123 $theme->checkImgPath();
129 * checks image path for existance - if not found use img from original theme
132 * @uses PMA_Theme::getPath()
133 * @uses PMA_Theme::setImgPath()
134 * @uses PMA_Theme::getName()
135 * @uses $GLOBALS['cfg']['ThemePath']
136 * @uses $GLOBALS['strThemeNoValidImgPath']
140 function checkImgPath()
142 if (is_dir($this->getPath() . '/img/')) {
143 $this->setImgPath($this->getPath() . '/img/');
145 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
146 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
150 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
157 * returns path to theme
160 * @uses PMA_Theme::$path as return value
161 * @return string $path path to theme
169 * returns layout file
172 * @uses PMA_Theme::getPath()
173 * @return string layout file
175 function getLayoutFile()
177 return $this->getPath() . '/layout.inc.php';
184 * @uses PMA_Theme::$path to set it
185 * @param string $path path to theme
187 function setPath($path)
189 $this->path
= trim($path);
196 * @uses PMA_Theme::$version
197 * @param string new version
199 function setVersion($version)
201 $this->version
= trim($version);
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
221 * @uses version_compare()
222 * @uses PMA_Theme::getVersion()
223 * @param string $version version to compare to
226 function checkVersion($version)
228 return version_compare($this->getVersion(), $version, 'lt');
235 * @uses PMA_Theme::$name to set it
237 * @param string $name new name
239 function setName($name)
241 $this->name
= trim($name);
248 * @uses PMA_Theme::$name as return value
249 * @return string name
260 * @uses PMA_Theme::$id to set it
261 * @param string $id new id
265 $this->id
= trim($id);
272 * @uses PMA_Theme::$id as return value
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;
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)
304 * @uses PMA_Theme::getPath()
305 * @uses PMA_Theme::$types
306 * @uses PMA_SQP_buildCssData()
307 * @uses file_exists()
309 * @param string $type left, right or print
311 function loadCss(&$type)
313 if (empty($type) ||
! in_array($type, $this->types
)) {
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)) {
328 if ($GLOBALS['text_dir'] === 'ltr') {
341 * prints out the preview for this theme
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()
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>'
361 .'<a target="_top" href="index.php'
362 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
363 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
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 />';
372 echo $GLOBALS['strThemeNoPreviewAvailable'];
375 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'