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 #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ř <michal@cihar.com>
* libraries/common.lib.php: Make cookie login form work with token

View File

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

View File

@@ -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 {
@@ -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;
}
}
?>