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 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['PMA_errors']
137 * @uses $GLOBALS['strThemeNoValidImgPath']
141 function checkImgPath()
143 if (is_dir($this->getPath() . '/img/')) {
144 $this->setImgPath($this->getPath() . '/img/');
146 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
147 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
150 $GLOBALS['PMA_errors'][] =
151 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
154 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
162 * returns path to theme
165 * @uses PMA_Theme::$path as return value
166 * @return string $path path to theme
174 * returns layout file
177 * @uses PMA_Theme::getPath()
178 * @return string layout file
180 function getLayoutFile()
182 return $this->getPath() . '/layout.inc.php';
189 * @uses PMA_Theme::$path to set it
190 * @param string $path path to theme
192 function setPath($path)
194 $this->path
= trim($path);
201 * @uses PMA_Theme::$version
202 * @param string new version
204 function setVersion($version)
206 $this->version
= trim($version);
213 * @uses PMA_Theme::$version
214 * @return string version
216 function getVersion()
218 return $this->version
;
222 * checks theme version agaisnt $version
223 * returns true if theme version is equal or higher to $version
226 * @uses version_compare()
227 * @uses PMA_Theme::getVersion()
228 * @param string $version version to compare to
231 function checkVersion($version)
233 return version_compare($this->getVersion(), $version, 'lt');
240 * @uses PMA_Theme::$name to set it
242 * @param string $name new name
244 function setName($name)
246 $this->name
= trim($name);
253 * @uses PMA_Theme::$name as return value
254 * @return string name
265 * @uses PMA_Theme::$id to set it
266 * @param string $id new id
270 $this->id
= trim($id);
277 * @uses PMA_Theme::$id as return value
287 * @uses PMA_Theme::$img_path to set it
288 * @param string path to images for this theme
290 function setImgPath($path)
292 $this->img_path
= $path;
297 * @uses PMA_Theme::$img_path as retunr value
298 * @return string image path for this theme
300 function getImgPath()
302 return $this->img_path
;
306 * load css (send to stdout, normaly the browser)
309 * @uses PMA_Theme::getPath()
310 * @uses PMA_Theme::$types
311 * @uses PMA_SQP_buildCssData()
312 * @uses file_exists()
314 * @param string $type left, right or print
316 function loadCss(&$type)
318 if (empty($type) ||
! in_array($type, $this->types
)) {
322 if ($type == 'right') {
323 echo PMA_SQP_buildCssData();
326 $_css_file = $this->getPath()
327 . '/css/theme_' . $type . '.css.php';
329 if (! file_exists($_css_file)) {
333 if ($GLOBALS['text_dir'] === 'ltr') {
346 * prints out the preview for this theme
349 * @uses PMA_Theme::getName()
350 * @uses PMA_Theme::getVersion()
351 * @uses PMA_Theme::getId()
352 * @uses PMA_Theme::getPath()
353 * @uses $GLOBALS['strThemeNoPreviewAvailable']
354 * @uses $GLOBALS['strTakeIt']
355 * @uses PMA_generate_common_url()
357 * @uses file_exists()
358 * @uses htmlspecialchars()
360 function printPreview()
362 echo '<div class="theme_preview">';
363 echo '<h2>' . htmlspecialchars($this->getName())
364 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
366 .'<a target="_top" href="index.php'
367 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
368 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
370 if (@file_exists
($this->getPath() . '/screen.png')) {
371 // if screen exists then output
373 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
374 .' alt="' . htmlspecialchars($this->getName()) . '"'
375 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
377 echo $GLOBALS['strThemeNoPreviewAvailable'];
380 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'