2 /* vim: set expandtab sw=4 ts=4 sts=4: */
13 * @todo add the possibility to make a theme depend on another theme and by default on original
14 * @todo make all components optional - get missing components from 'parent' theme
15 * @todo make css optionally replacing 'parent' css or extending it (by appending at the end)
16 * @todo add an optional global css file - which will be used for both frames
22 * @var string theme version
25 var $version = '0.0.0.0';
28 * @var string theme name
34 * @var string theme id
40 * @var string theme path
46 * @var string image path
52 * @var array valid css types
55 var $types = array('left', 'right', 'print');
58 * @var integer last modification time for info file
64 * needed because sometimes, the mtime for different themes
66 * @var integer filesize for info file
69 var $filesize_info = 0;
73 * @uses PMA_Theme::getPath()
74 * @uses PMA_Theme::$mtime_info
75 * @uses PMA_Theme::setVersion()
76 * @uses PMA_Theme::setName()
80 * @return boolean whether loading them info was successful or not
84 if (! file_exists($this->getPath() . '/info.inc.php')) {
88 if ($this->mtime_info
=== filemtime($this->getPath() . '/info.inc.php')) {
92 @include
$this->getPath() . '/info.inc.php';
94 // was it set correctly?
95 if (! isset($theme_name)) {
99 $this->mtime_info
= filemtime($this->getPath() . '/info.inc.php');
100 $this->filesize_info
= filesize($this->getPath() . '/info.inc.php');
102 if (isset($theme_full_version)) {
103 $this->setVersion($theme_full_version);
104 } elseif (isset($theme_generation, $theme_version)) {
105 $this->setVersion($theme_generation . '.' . $theme_version);
107 $this->setName($theme_name);
113 * returns theme object loaded from given folder
114 * or false if theme is invalid
119 * @uses PMA_Theme::setPath()
120 * @uses PMA_Theme::loadInfo()
121 * @uses PMA_Theme::checkImgPath()
122 * @param string $folder path to theme
123 * @return object PMA_Theme
125 static public function load($folder)
127 $theme = new PMA_Theme();
129 $theme->setPath($folder);
131 if (! $theme->loadInfo()) {
135 $theme->checkImgPath();
141 * checks image path for existance - if not found use img from original theme
144 * @uses PMA_Theme::getPath()
145 * @uses PMA_Theme::setImgPath()
146 * @uses PMA_Theme::getName()
147 * @uses $GLOBALS['cfg']['ThemePath']
148 * @uses __('No valid image path for theme %s found!')
152 function checkImgPath()
154 if (is_dir($this->getPath() . '/img/')) {
155 $this->setImgPath($this->getPath() . '/img/');
157 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
158 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
162 sprintf(__('No valid image path for theme %s found!'), $this->getName()),
169 * returns path to theme
172 * @uses PMA_Theme::$path as return value
173 * @return string $path path to theme
181 * returns layout file
184 * @uses PMA_Theme::getPath()
185 * @return string layout file
187 function getLayoutFile()
189 return $this->getPath() . '/layout.inc.php';
196 * @uses PMA_Theme::$path to set it
197 * @param string $path path to theme
199 function setPath($path)
201 $this->path
= trim($path);
208 * @uses PMA_Theme::$version
209 * @param string new version
211 function setVersion($version)
213 $this->version
= trim($version);
220 * @uses PMA_Theme::$version
221 * @return string version
223 function getVersion()
225 return $this->version
;
229 * checks theme version agaisnt $version
230 * returns true if theme version is equal or higher to $version
233 * @uses version_compare()
234 * @uses PMA_Theme::getVersion()
235 * @param string $version version to compare to
238 function checkVersion($version)
240 return version_compare($this->getVersion(), $version, 'lt');
247 * @uses PMA_Theme::$name to set it
249 * @param string $name new name
251 function setName($name)
253 $this->name
= trim($name);
260 * @uses PMA_Theme::$name as return value
261 * @return string name
272 * @uses PMA_Theme::$id to set it
273 * @param string $id new id
277 $this->id
= trim($id);
284 * @uses PMA_Theme::$id as return value
294 * @uses PMA_Theme::$img_path to set it
295 * @param string path to images for this theme
297 function setImgPath($path)
299 $this->img_path
= $path;
304 * @uses PMA_Theme::$img_path as retunr value
305 * @return string image path for this theme
307 function getImgPath()
309 return $this->img_path
;
313 * load css (send to stdout, normally the browser)
316 * @uses PMA_Theme::getPath()
317 * @uses PMA_Theme::$types
318 * @uses PMA_SQP_buildCssData()
319 * @uses file_exists()
321 * @param string $type left, right or print
323 function loadCss(&$type)
325 if (empty($type) ||
! in_array($type, $this->types
)) {
329 if ($type == 'right') {
330 echo PMA_SQP_buildCssData();
333 $_css_file = $this->getPath()
334 . '/css/theme_' . $type . '.css.php';
336 if (! file_exists($_css_file)) {
340 if ($GLOBALS['text_dir'] === 'ltr') {
353 * prints out the preview for this theme
356 * @uses PMA_Theme::getName()
357 * @uses PMA_Theme::getVersion()
358 * @uses PMA_Theme::getId()
359 * @uses PMA_Theme::getPath()
360 * @uses __('No preview available.')
361 * @uses __('take it')
362 * @uses PMA_generate_common_url()
364 * @uses file_exists()
365 * @uses htmlspecialchars()
367 function printPreview()
369 echo '<div class="theme_preview">';
370 echo '<h2>' . htmlspecialchars($this->getName())
371 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
373 .'<a target="_top" href="index.php'
374 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
375 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
377 if (@file_exists
($this->getPath() . '/screen.png')) {
378 // if screen exists then output
380 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
381 .' alt="' . htmlspecialchars($this->getName()) . '"'
382 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
384 echo __('No preview available.');
387 echo '[ <strong>' . __('take it') . '</strong> ]</a>'