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
21 * @var string theme version
24 var $version = '0.0.0.0';
27 * @var string theme name
33 * @var string theme id
39 * @var string theme path
45 * @var string image path
51 * @var array valid css types
54 var $types = array('left', 'right', 'print');
57 * @var integer last modification time for info file
63 * needed because sometimes, the mtime for different themes
65 * @var integer filesize for info file
68 var $filesize_info = 0;
72 * @return boolean whether loading them info was successful or not
76 if (! file_exists($this->getPath() . '/info.inc.php')) {
80 if ($this->mtime_info
=== filemtime($this->getPath() . '/info.inc.php')) {
84 @include
$this->getPath() . '/info.inc.php';
86 // was it set correctly?
87 if (! isset($theme_name)) {
91 $this->mtime_info
= filemtime($this->getPath() . '/info.inc.php');
92 $this->filesize_info
= filesize($this->getPath() . '/info.inc.php');
94 if (isset($theme_full_version)) {
95 $this->setVersion($theme_full_version);
96 } elseif (isset($theme_generation, $theme_version)) {
97 $this->setVersion($theme_generation . '.' . $theme_version);
99 $this->setName($theme_name);
105 * returns theme object loaded from given folder
106 * or false if theme is invalid
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
133 function checkImgPath()
135 if (is_dir($this->getPath() . '/img/')) {
136 $this->setImgPath($this->getPath() . '/img/');
138 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
139 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
143 sprintf(__('No valid image path for theme %s found!'), $this->getName()),
150 * returns path to theme
153 * @return string $path path to theme
161 * returns layout file
164 * @return string layout file
166 function getLayoutFile()
168 return $this->getPath() . '/layout.inc.php';
175 * @param string $path path to theme
177 function setPath($path)
179 $this->path
= trim($path);
186 * @param string new version
188 function setVersion($version)
190 $this->version
= trim($version);
197 * @return string version
199 function getVersion()
201 return $this->version
;
205 * checks theme version agaisnt $version
206 * returns true if theme version is equal or higher to $version
209 * @param string $version version to compare to
212 function checkVersion($version)
214 return version_compare($this->getVersion(), $version, 'lt');
221 * @param string $name new name
223 function setName($name)
225 $this->name
= trim($name);
232 * @return string name
243 * @param string $id new id
247 $this->id
= trim($id);
263 * @param string path to images for this theme
265 function setImgPath($path)
267 $this->img_path
= $path;
272 * @return string image path for this theme
274 function getImgPath()
276 return $this->img_path
;
280 * load css (send to stdout, normally the browser)
283 * @param string $type left, right or print
285 function loadCss(&$type)
287 if (empty($type) ||
! in_array($type, $this->types
)) {
291 if ($type == 'right') {
292 echo PMA_SQP_buildCssData();
295 $_css_file = $this->getPath()
296 . '/css/theme_' . $type . '.css.php';
298 if (! file_exists($_css_file)) {
302 if ($GLOBALS['text_dir'] === 'ltr') {
315 * prints out the preview for this theme
319 function printPreview()
321 echo '<div class="theme_preview">';
322 echo '<h2>' . htmlspecialchars($this->getName())
323 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
325 .'<a target="_top" href="index.php'
326 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
327 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
329 if (@file_exists
($this->getPath() . '/screen.png')) {
330 // if screen exists then output
332 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
333 .' alt="' . htmlspecialchars($this->getName()) . '"'
334 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
336 echo __('No preview available.');
339 echo '[ <strong>' . __('take it') . '</strong> ]</a>'