diff --git a/ChangeLog b/ChangeLog index 7a63a2ba6..6e7b0d694 100755 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,9 @@ $Source$ fixed bug #1452131 Fonts too large; fixed bug #1446211 Colors hardcoded in theme css files; * libraries/Theme_Manager.class.php: search themes on every script start + * libraries/Theme_Manager.class.php, libraries/Theme.class.php: + use fallback (original) css file if not found in current theme + (no need to include unchanged files into theme, f. e. print.css) 2006-04-25 Michal Čihař * libraries/common.lib.php: Make cookie login form work with token diff --git a/libraries/Theme.class.php b/libraries/Theme.class.php index 7ab049348..196a249eb 100644 --- a/libraries/Theme.class.php +++ b/libraries/Theme.class.php @@ -31,42 +31,44 @@ class PMA_Theme { /** * @var array valid css types */ - var $types = array( 'left', 'right', 'print' ); + var $types = array('left', 'right', 'print'); /** * @var integer last modification time for info file */ var $mtime_info = 0; - function __wakeup() { + function __wakeup() + { $this->loadInfo(); $this->checkImgPath(); } - function loadInfo() { - if ( ! file_exists( $this->getPath() . '/info.inc.php' ) ) { + function loadInfo() + { + if (! file_exists($this->getPath() . '/info.inc.php')) { return false; } - if ( $this->mtime_info === filemtime( $this->getPath() . '/info.inc.php' ) ) { + if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) { return true; } - @include( $this->getPath() . '/info.inc.php' ); + @include $this->getPath() . '/info.inc.php'; // did it set correctly? - if ( ! isset( $theme_name ) ) { + if (! isset($theme_name)) { return false; } - $this->mtime_info = filemtime( $this->getPath() . '/info.inc.php' ); + $this->mtime_info = filemtime($this->getPath() . '/info.inc.php'); - if ( isset( $theme_full_version ) ) { - $this->setVersion( $theme_full_version ); - } elseif ( isset( $theme_generation, $theme_version ) ) { - $this->setVersion( $theme_generation . '.' . $theme_version ); + if (isset($theme_full_version)) { + $this->setVersion($theme_full_version); + } elseif (isset($theme_generation, $theme_version)) { + $this->setVersion($theme_generation . '.' . $theme_version); } - $this->setName( $theme_name ); + $this->setName($theme_name); return true; } @@ -79,13 +81,14 @@ class PMA_Theme { * @param string path to theme * @return object PMA_Theme */ - function load( $folder ) { + function load($folder) + { $theme = new PMA_Theme(); - $theme->setPath( $folder ); + $theme->setPath($folder); - if ( ! $theme->loadInfo() ) { + if (! $theme->loadInfo()) { return false; } @@ -94,19 +97,20 @@ class PMA_Theme { return $theme; } - function checkImgPath() { - if ( is_dir( $this->getPath() . '/img/' ) ) { - $this->setImgPath( $this->getPath() . '/img/' ); + function checkImgPath() + { + if (is_dir($this->getPath() . '/img/')) { + $this->setImgPath($this->getPath() . '/img/'); return true; - } elseif ( is_dir( $GLOBALS['cfg']['ThemePath'] . '/original/img/' ) ) { - $this->setImgPath( $GLOBALS['cfg']['ThemePath'] . '/original/img/' ); + } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) { + $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/'); return true; } else { $GLOBALS['PMA_errors'][] = - sprintf( $GLOBALS['strThemeNoValidImgPath'], $this->getName() ); + sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()); trigger_error( - sprintf( $GLOBALS['strThemeNoValidImgPath'], $this->getName() ), - E_USER_WARNING ); + sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()), + E_USER_WARNING); return false; } } @@ -116,7 +120,8 @@ class PMA_Theme { * @uses $this->$path as return value * @return string $path path to theme */ - function getPath() { + function getPath() + { return $this->path; } @@ -125,7 +130,8 @@ class PMA_Theme { * * @return string layout file */ - function getLayoutFile() { + function getLayoutFile() + { return $this->getPath() . '/layout.inc.php'; } @@ -134,8 +140,9 @@ class PMA_Theme { * @uses $this->$path to set it * @param string $path path to theme */ - function setPath( $path ) { - $this->path = trim( $path ); + function setPath($path) + { + $this->path = trim($path); } /** @@ -143,8 +150,9 @@ class PMA_Theme { * @uses $this->version * @param string new version */ - function setVersion( $version ) { - $this->version = trim( $version ); + function setVersion($version) + { + $this->version = trim($version); } /** @@ -152,7 +160,8 @@ class PMA_Theme { * @uses $this->version * @return string version */ - function getVersion() { + function getVersion() + { return $this->version; } @@ -165,23 +174,26 @@ class PMA_Theme { * @param string $version version to compare to * @return boolean */ - function checkVersion( $version ) { - return version_compare( $this->getVersion(), $version, 'lt' ); + function checkVersion($version) + { + return version_compare($this->getVersion(), $version, 'lt'); } /** * sets name * @param string $name new name */ - function setName( $name ) { - $this->name = trim( $name ); + function setName($name) + { + $this->name = trim($name); } /** * returns name * @return string name */ - function getName() { + function getName() + { return $this->name; } @@ -189,23 +201,27 @@ class PMA_Theme { * sets id * @param string $id new id */ - function setId( $id ) { - $this->id = trim( $id ); + function setId($id) + { + $this->id = trim($id); } /** * returns id * @return string id */ - function getId() { + function getId() + { return $this->id; } - function setImgPath( $path ) { + function setImgPath($path) + { $this->img_path = $path; } - function getImgPath() { + function getImgPath() + { return $this->img_path; } @@ -219,29 +235,33 @@ class PMA_Theme { * @uses in_array() * @param string $type left, right or print */ - function loadCss( &$type ) { - if ( empty( $type ) || ! in_array( $type, $this->types ) ) { + function loadCss(&$type) + { + if (empty($type) || ! in_array($type, $this->types)) { $type = 'left'; } - if ( $type == 'right' ) { + if ($type == 'right') { echo PMA_SQP_buildCssData(); } $_css_file = $this->getPath() . '/css/theme_' . $type . '.css.php'; - if ( file_exists( $_css_file ) ) { - if ( $GLOBALS['text_dir'] === 'ltr' ) { - $right = 'right'; - $left = 'left'; - } else { - $right = 'left'; - $left = 'right'; - } - - include( $_css_file ); + if (! file_exists($_css_file)) { + return false; } + + if ($GLOBALS['text_dir'] === 'ltr') { + $right = 'right'; + $left = 'left'; + } else { + $right = 'left'; + $left = 'right'; + } + + include $_css_file; + return true; } /** @@ -258,21 +278,22 @@ class PMA_Theme { * @uses file_exists() * @uses htmlspecialchars() */ - function printPreview() { + function printPreview() + { echo '
'; - echo '

' . htmlspecialchars( $this->getName() ) - .' (' . htmlspecialchars( $this->getVersion() ) . ')

' + echo '

' . htmlspecialchars($this->getName()) + .' (' . htmlspecialchars($this->getVersion()) . ')

' .'

' .''; - if ( @file_exists( $this->getPath() . '/screen.png' ) ) { + if (@file_exists($this->getPath() . '/screen.png')) { // if screen exists then output echo '' . htmlspecialchars( $this->getName() ) . '
'; + .' alt="' . htmlspecialchars($this->getName()) . '"' + .' title="' . htmlspecialchars($this->getName()) . '" />
'; } else { echo $GLOBALS['strThemeNoPreviewAvailable']; } diff --git a/libraries/Theme_Manager.class.php b/libraries/Theme_Manager.class.php index caa228e96..94adfac01 100644 --- a/libraries/Theme_Manager.class.php +++ b/libraries/Theme_Manager.class.php @@ -2,7 +2,7 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: -require_once('./libraries/Theme.class.php'); +require_once './libraries/Theme.class.php'; class PMA_Theme_Manager { @@ -251,7 +251,7 @@ class PMA_Theme_Manager { closedir($handleThemes); } else { trigger_error( - 'phpMyAdmin-ERROR: can not open themes folder: ' . $this->getThemesPath(), + 'phpMyAdmin-ERROR: cannot open themes folder: ' . $this->getThemesPath(), E_USER_WARNING); return false; } // end check for themes directory @@ -346,5 +346,36 @@ class PMA_Theme_Manager { $each_theme->printPreview(); } // end 'open themes' } + + /** + * returns PMA_Theme object for fall back theme + * @return object PMA_Theme + */ + function getFallBackTheme() + { + if (isset($this->themes['Original'])) { + return $this->themes['Original']; + } + + return false; + } + + /** + * prints css data + */ + function printCss($type) + { + if ($this->theme->loadCss($type)) { + return true; + } + + // load css for this them failed, try default theme css + $fallback_theme = $this->getFallBackTheme(); + if ($fallback_theme && $fallback_theme->loadCss($type)) { + return true; + } + + return false; + } } ?>