use fallback (original) css file if not found in current theme (no need to include unchanged files into theme, f. e. print.css)

This commit is contained in:
Sebastian Mendel
2006-04-26 17:09:45 +00:00
parent 04e666ff7c
commit 5c82bf4b29
3 changed files with 119 additions and 64 deletions

View File

@@ -29,6 +29,9 @@ $Source$
fixed bug #1452131 Fonts too large; fixed bug #1452131 Fonts too large;
fixed bug #1446211 Colors hardcoded in theme css files; 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: 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ř <michal@cihar.com> 2006-04-25 Michal Čihař <michal@cihar.com>
* libraries/common.lib.php: Make cookie login form work with token * libraries/common.lib.php: Make cookie login form work with token

View File

@@ -38,12 +38,14 @@ class PMA_Theme {
*/ */
var $mtime_info = 0; var $mtime_info = 0;
function __wakeup() { function __wakeup()
{
$this->loadInfo(); $this->loadInfo();
$this->checkImgPath(); $this->checkImgPath();
} }
function loadInfo() { function loadInfo()
{
if (! file_exists($this->getPath() . '/info.inc.php')) { if (! file_exists($this->getPath() . '/info.inc.php')) {
return false; return false;
} }
@@ -52,7 +54,7 @@ class PMA_Theme {
return true; return true;
} }
@include( $this->getPath() . '/info.inc.php' ); @include $this->getPath() . '/info.inc.php';
// did it set correctly? // did it set correctly?
if (! isset($theme_name)) { if (! isset($theme_name)) {
@@ -79,7 +81,8 @@ class PMA_Theme {
* @param string path to theme * @param string path to theme
* @return object PMA_Theme * @return object PMA_Theme
*/ */
function load( $folder ) { function load($folder)
{
$theme = new PMA_Theme(); $theme = new PMA_Theme();
@@ -94,7 +97,8 @@ class PMA_Theme {
return $theme; return $theme;
} }
function checkImgPath() { function checkImgPath()
{
if (is_dir($this->getPath() . '/img/')) { if (is_dir($this->getPath() . '/img/')) {
$this->setImgPath($this->getPath() . '/img/'); $this->setImgPath($this->getPath() . '/img/');
return true; return true;
@@ -116,7 +120,8 @@ class PMA_Theme {
* @uses $this->$path as return value * @uses $this->$path as return value
* @return string $path path to theme * @return string $path path to theme
*/ */
function getPath() { function getPath()
{
return $this->path; return $this->path;
} }
@@ -125,7 +130,8 @@ class PMA_Theme {
* *
* @return string layout file * @return string layout file
*/ */
function getLayoutFile() { function getLayoutFile()
{
return $this->getPath() . '/layout.inc.php'; return $this->getPath() . '/layout.inc.php';
} }
@@ -134,7 +140,8 @@ class PMA_Theme {
* @uses $this->$path to set it * @uses $this->$path to set it
* @param string $path path to theme * @param string $path path to theme
*/ */
function setPath( $path ) { function setPath($path)
{
$this->path = trim($path); $this->path = trim($path);
} }
@@ -143,7 +150,8 @@ class PMA_Theme {
* @uses $this->version * @uses $this->version
* @param string new version * @param string new version
*/ */
function setVersion( $version ) { function setVersion($version)
{
$this->version = trim($version); $this->version = trim($version);
} }
@@ -152,7 +160,8 @@ class PMA_Theme {
* @uses $this->version * @uses $this->version
* @return string version * @return string version
*/ */
function getVersion() { function getVersion()
{
return $this->version; return $this->version;
} }
@@ -165,7 +174,8 @@ class PMA_Theme {
* @param string $version version to compare to * @param string $version version to compare to
* @return boolean * @return boolean
*/ */
function checkVersion( $version ) { function checkVersion($version)
{
return version_compare($this->getVersion(), $version, 'lt'); return version_compare($this->getVersion(), $version, 'lt');
} }
@@ -173,7 +183,8 @@ class PMA_Theme {
* sets name * sets name
* @param string $name new name * @param string $name new name
*/ */
function setName( $name ) { function setName($name)
{
$this->name = trim($name); $this->name = trim($name);
} }
@@ -181,7 +192,8 @@ class PMA_Theme {
* returns name * returns name
* @return string name * @return string name
*/ */
function getName() { function getName()
{
return $this->name; return $this->name;
} }
@@ -189,7 +201,8 @@ class PMA_Theme {
* sets id * sets id
* @param string $id new id * @param string $id new id
*/ */
function setId( $id ) { function setId($id)
{
$this->id = trim($id); $this->id = trim($id);
} }
@@ -197,15 +210,18 @@ class PMA_Theme {
* returns id * returns id
* @return string id * @return string id
*/ */
function getId() { function getId()
{
return $this->id; return $this->id;
} }
function setImgPath( $path ) { function setImgPath($path)
{
$this->img_path = $path; $this->img_path = $path;
} }
function getImgPath() { function getImgPath()
{
return $this->img_path; return $this->img_path;
} }
@@ -219,7 +235,8 @@ class PMA_Theme {
* @uses in_array() * @uses in_array()
* @param string $type left, right or print * @param string $type left, right or print
*/ */
function loadCss( &$type ) { function loadCss(&$type)
{
if (empty($type) || ! in_array($type, $this->types)) { if (empty($type) || ! in_array($type, $this->types)) {
$type = 'left'; $type = 'left';
} }
@@ -231,7 +248,10 @@ class PMA_Theme {
$_css_file = $this->getPath() $_css_file = $this->getPath()
. '/css/theme_' . $type . '.css.php'; . '/css/theme_' . $type . '.css.php';
if ( file_exists( $_css_file ) ) { if (! file_exists($_css_file)) {
return false;
}
if ($GLOBALS['text_dir'] === 'ltr') { if ($GLOBALS['text_dir'] === 'ltr') {
$right = 'right'; $right = 'right';
$left = 'left'; $left = 'left';
@@ -240,8 +260,8 @@ class PMA_Theme {
$left = 'right'; $left = 'right';
} }
include( $_css_file ); include $_css_file;
} return true;
} }
/** /**
@@ -258,7 +278,8 @@ class PMA_Theme {
* @uses file_exists() * @uses file_exists()
* @uses htmlspecialchars() * @uses htmlspecialchars()
*/ */
function printPreview() { function printPreview()
{
echo '<div class="theme_preview">'; echo '<div class="theme_preview">';
echo '<h2>' . htmlspecialchars($this->getName()) echo '<h2>' . htmlspecialchars($this->getName())
.' (' . htmlspecialchars($this->getVersion()) . ')</h2>' .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'

View File

@@ -2,7 +2,7 @@
/* $Id$ */ /* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4: // vim: expandtab sw=4 ts=4 sts=4:
require_once('./libraries/Theme.class.php'); require_once './libraries/Theme.class.php';
class PMA_Theme_Manager { class PMA_Theme_Manager {
@@ -346,5 +346,36 @@ class PMA_Theme_Manager {
$each_theme->printPreview(); $each_theme->printPreview();
} // end 'open themes' } // 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;
}
} }
?> ?>