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
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 * @return boolean whether loading them info was successful or not
77 if (! file_exists($this->getPath() . '/info.inc.php')) {
81 if ($this->mtime_info
=== filemtime($this->getPath() . '/info.inc.php')) {
85 @include
$this->getPath() . '/info.inc.php';
87 // was it set correctly?
88 if (! isset($theme_name)) {
92 $this->mtime_info
= filemtime($this->getPath() . '/info.inc.php');
93 $this->filesize_info
= filesize($this->getPath() . '/info.inc.php');
95 if (isset($theme_full_version)) {
96 $this->setVersion($theme_full_version);
97 } elseif (isset($theme_generation, $theme_version)) {
98 $this->setVersion($theme_generation . '.' . $theme_version);
100 $this->setName($theme_name);
106 * returns theme object loaded from given folder
107 * or false if theme is invalid
111 * @param string $folder path to theme
112 * @return object PMA_Theme
114 static public function load($folder)
116 $theme = new PMA_Theme();
118 $theme->setPath($folder);
120 if (! $theme->loadInfo()) {
124 $theme->checkImgPath();
130 * checks image path for existance - if not found use img from original theme
135 function checkImgPath()
137 if (is_dir($this->getPath() . '/img/')) {
138 $this->setImgPath($this->getPath() . '/img/');
140 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
141 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
145 sprintf(__('No valid image path for theme %s found!'), $this->getName()),
152 * returns path to theme
155 * @return string $path path to theme
163 * returns layout file
166 * @return string layout file
168 function getLayoutFile()
170 return $this->getPath() . '/layout.inc.php';
177 * @param string $path path to theme
179 function setPath($path)
181 $this->path
= trim($path);
188 * @param string new version
190 function setVersion($version)
192 $this->version
= trim($version);
199 * @return string version
201 function getVersion()
203 return $this->version
;
207 * checks theme version agaisnt $version
208 * returns true if theme version is equal or higher to $version
211 * @param string $version version to compare to
214 function checkVersion($version)
216 return version_compare($this->getVersion(), $version, 'lt');
223 * @param string $name new name
225 function setName($name)
227 $this->name
= trim($name);
234 * @return string name
245 * @param string $id new id
249 $this->id
= trim($id);
265 * @param string path to images for this theme
267 function setImgPath($path)
269 $this->img_path
= $path;
274 * @return string image path for this theme
276 function getImgPath()
278 return $this->img_path
;
282 * load css (send to stdout, normally the browser)
285 * @param string $type left, right or print
288 function loadCss(&$type)
290 if (empty($type) ||
! in_array($type, $this->types
)) {
294 if ($type == 'right') {
295 echo PMA_SQP_buildCssData();
298 $_css_file = $this->getPath()
299 . '/css/theme_' . $type . '.css.php';
301 if (! file_exists($_css_file)) {
305 if ($GLOBALS['text_dir'] === 'ltr') {
318 * prints out the preview for this theme
322 function printPreview()
324 echo '<div class="theme_preview">';
325 echo '<h2>' . htmlspecialchars($this->getName())
326 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>';
328 echo '<a target="_top" class="take_theme" '
329 .'name="' . htmlspecialchars($this->getId()) . '" '
330 . 'href="index.php'.PMA_generate_common_url(array(
331 'set_theme' => $this->getId()
333 if (@file_exists
($this->getPath() . '/screen.png')) {
334 // if screen exists then output
336 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
337 .' alt="' . htmlspecialchars($this->getName()) . '"'
338 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
340 echo __('No preview available.');
343 echo '[ <strong>' . __('take it') . '</strong> ]</a>'