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 original
13 * @todo make all components optional - taking 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
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
62 * needed because sometimes, the mtime for different themes
64 * @var integer filesize for info file
67 var $filesize_info = 0;
71 * @uses PMA_Theme::getPath()
72 * @uses PMA_Theme::$mtime_info
73 * @uses PMA_Theme::setVersion()
74 * @uses PMA_Theme::setName()
78 * @return boolean whether loading them info was successful or not
82 if (! file_exists($this->getPath() . '/info.inc.php')) {
86 if ($this->mtime_info
=== filemtime($this->getPath() . '/info.inc.php')) {
90 @include
$this->getPath() . '/info.inc.php';
92 // did it set correctly?
93 if (! isset($theme_name)) {
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);
111 * returns theme object loaded from given folder
112 * or false if theme is invalid
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 function load($folder)
125 $theme = new PMA_Theme();
127 $theme->setPath($folder);
129 if (! $theme->loadInfo()) {
133 $theme->checkImgPath();
139 * checks image path for existance - if not found use img from original theme
142 * @uses PMA_Theme::getPath()
143 * @uses PMA_Theme::setImgPath()
144 * @uses PMA_Theme::getName()
145 * @uses $GLOBALS['cfg']['ThemePath']
146 * @uses $GLOBALS['PMA_errors']
147 * @uses $GLOBALS['strThemeNoValidImgPath']
151 function checkImgPath()
153 if (is_dir($this->getPath() . '/img/')) {
154 $this->setImgPath($this->getPath() . '/img/');
156 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
157 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
160 $GLOBALS['PMA_errors'][] =
161 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
164 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
172 * returns path to theme
175 * @uses PMA_Theme::$path as return value
176 * @return string $path path to theme
184 * returns layout file
187 * @uses PMA_Theme::getPath()
188 * @return string layout file
190 function getLayoutFile()
192 return $this->getPath() . '/layout.inc.php';
199 * @uses PMA_Theme::$path to set it
200 * @param string $path path to theme
202 function setPath($path)
204 $this->path
= trim($path);
211 * @uses PMA_Theme::$version
212 * @param string new version
214 function setVersion($version)
216 $this->version
= trim($version);
223 * @uses PMA_Theme::$version
224 * @return string version
226 function getVersion()
228 return $this->version
;
232 * checks theme version agaisnt $version
233 * returns true if theme version is equal or higher to $version
236 * @uses version_compare()
237 * @uses PMA_Theme::getVersion()
238 * @param string $version version to compare to
241 function checkVersion($version)
243 return version_compare($this->getVersion(), $version, 'lt');
250 * @uses PMA_Theme::$name to set it
252 * @param string $name new name
254 function setName($name)
256 $this->name
= trim($name);
263 * @uses PMA_Theme::$name as return value
264 * @return string name
275 * @uses PMA_Theme::$id to set it
276 * @param string $id new id
280 $this->id
= trim($id);
287 * @uses PMA_Theme::$id as return value
297 * @uses PMA_Theme::$img_path to set it
298 * @param string path to images for this theme
300 function setImgPath($path)
302 $this->img_path
= $path;
307 * @uses PMA_Theme::$img_path as retunr value
308 * @return string image path for this theme
310 function getImgPath()
312 return $this->img_path
;
316 * load css (send to stdout, normaly the browser)
319 * @uses PMA_Theme::getPath()
320 * @uses PMA_Theme::$types
321 * @uses PMA_SQP_buildCssData()
322 * @uses file_exists()
324 * @param string $type left, right or print
326 function loadCss(&$type)
328 if (empty($type) ||
! in_array($type, $this->types
)) {
332 if ($type == 'right') {
333 echo PMA_SQP_buildCssData();
336 $_css_file = $this->getPath()
337 . '/css/theme_' . $type . '.css.php';
339 if (! file_exists($_css_file)) {
343 if ($GLOBALS['text_dir'] === 'ltr') {
356 * prints out the preview for this theme
359 * @uses PMA_Theme::getName()
360 * @uses PMA_Theme::getVersion()
361 * @uses PMA_Theme::getId()
362 * @uses PMA_Theme::getPath()
363 * @uses $GLOBALS['strThemeNoPreviewAvailable']
364 * @uses $GLOBALS['strTakeIt']
365 * @uses PMA_generate_common_url()
367 * @uses file_exists()
368 * @uses htmlspecialchars()
370 function printPreview()
372 echo '<div class="theme_preview">';
373 echo '<h2>' . htmlspecialchars($this->getName())
374 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
376 .'<a target="_top" href="index.php'
377 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
378 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
380 if (@file_exists
($this->getPath() . '/screen.png')) {
381 // if screen exists then output
383 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
384 .' alt="' . htmlspecialchars($this->getName()) . '"'
385 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
387 echo $GLOBALS['strThemeNoPreviewAvailable'];
390 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'