1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
<?php
/* $Id: Theme.class.php 8960 2006-04-26 17:09:45Z cybot_tm $ */
// vim: expandtab sw=4 ts=4 sts=4:
class PMA_Theme {
/**
* @var string version
*/
var $version = '0.0.0.0';
/**
* @var string name
*/
var $name = '';
/**
* @var string id
*/
var $id = '';
/**
* @var string
*/
var $path = '';
/**
* @var string
*/
var $img_path = '';
/**
* @var array valid css types
*/
var $types = array('left', 'right', 'print');
/**
* @var integer last modification time for info file
*/
var $mtime_info = 0;
function __wakeup()
{
$this->loadInfo();
$this->checkImgPath();
}
function loadInfo()
{
if (! file_exists($this->getPath() . '/info.inc.php')) {
return false;
}
if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
return true;
}
@include $this->getPath() . '/info.inc.php';
// did it set correctly?
if (! isset($theme_name)) {
return false;
}
$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);
}
$this->setName($theme_name);
return true;
}
/**
* returns theme object loaded from given folder
* or false if theme is invalid
*
* @static
* @param string path to theme
* @return object PMA_Theme
*/
function load($folder)
{
$theme = new PMA_Theme();
$theme->setPath($folder);
if (! $theme->loadInfo()) {
return false;
}
$theme->checkImgPath();
return $theme;
}
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/');
return true;
} else {
$GLOBALS['PMA_errors'][] =
sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
trigger_error(
sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
E_USER_WARNING);
return false;
}
}
/**
* returns path to theme
* @uses $this->$path as return value
* @return string $path path to theme
*/
function getPath()
{
return $this->path;
}
/**
* returns layout file
*
* @return string layout file
*/
function getLayoutFile()
{
return $this->getPath() . '/layout.inc.php';
}
/**
* set path to theme
* @uses $this->$path to set it
* @param string $path path to theme
*/
function setPath($path)
{
$this->path = trim($path);
}
/**
* sets version
* @uses $this->version
* @param string new version
*/
function setVersion($version)
{
$this->version = trim($version);
}
/**
* returns version
* @uses $this->version
* @return string version
*/
function getVersion()
{
return $this->version;
}
/**
* checks theme version agaisnt $version
* returns true if theme version is equal or higher to $version
*
* @uses version_compare()
* @uses $this->getVersion()
* @param string $version version to compare to
* @return boolean
*/
function checkVersion($version)
{
return version_compare($this->getVersion(), $version, 'lt');
}
/**
* sets name
* @param string $name new name
*/
function setName($name)
{
$this->name = trim($name);
}
/**
* returns name
* @return string name
*/
function getName()
{
return $this->name;
}
/**
* sets id
* @param string $id new id
*/
function setId($id)
{
$this->id = trim($id);
}
/**
* returns id
* @return string id
*/
function getId()
{
return $this->id;
}
function setImgPath($path)
{
$this->img_path = $path;
}
function getImgPath()
{
return $this->img_path;
}
/**
* load css (send to stdout, normaly the browser)
*
* @uses $this->getPath()
* @uses $this->types
* @uses PMA_SQP_buildCssData()
* @uses file_exists()
* @uses in_array()
* @param string $type left, right or print
*/
function loadCss(&$type)
{
if (empty($type) || ! in_array($type, $this->types)) {
$type = 'left';
}
if ($type == 'right') {
echo PMA_SQP_buildCssData();
}
$_css_file = $this->getPath()
. '/css/theme_' . $type . '.css.php';
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;
}
/**
* prints out the preview for this theme
*
* @uses $this->getName()
* @uses $this->getVersion()
* @uses $this->getId()
* @uses $this->getPath()
* @uses $GLOBALS['strThemeNoPreviewAvailable']
* @uses $GLOBALS['strTakeIt']
* @uses PMA_generate_common_url()
* @uses addslashes()
* @uses file_exists()
* @uses htmlspecialchars()
*/
function printPreview()
{
echo '<div class="theme_preview">';
echo '<h2>' . htmlspecialchars($this->getName())
.' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
.'<p>'
.'<a target="_top" href="index.php'
.PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
.' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
.' return false;">';
if (@file_exists($this->getPath() . '/screen.png')) {
// if screen exists then output
echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
.' alt="' . htmlspecialchars($this->getName()) . '"'
.' title="' . htmlspecialchars($this->getName()) . '" /><br />';
} else {
echo $GLOBALS['strThemeNoPreviewAvailable'];
}
echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
.'</p>'
.'</div>';
}
}
?>
|