2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 namespace PMA\libraries
;
10 use PMA\libraries\URL
;
15 * @todo add the possibility to make a theme depend on another theme
16 * and by default on original
17 * @todo make all components optional - get missing components from 'parent' theme
24 * @var string theme version
27 var $version = '0.0.0.0';
30 * @var string theme name
36 * @var string theme id
42 * @var string theme path
48 * @var string image path
54 * @var integer last modification time for info file
60 * needed because sometimes, the mtime for different themes
62 * @var integer filesize for info file
65 var $filesize_info = 0;
68 * @var array List of css files to load
71 private $_cssFiles = array(
84 * Loads theme information
86 * @return boolean whether loading them info was successful or not
91 if (! file_exists($this->getPath() . '/info.inc.php')) {
95 if ($this->mtime_info
=== filemtime($this->getPath() . '/info.inc.php')) {
99 @include
$this->getPath() . '/info.inc.php';
101 // was it set correctly?
102 if (! isset($theme_name)) {
106 $this->mtime_info
= filemtime($this->getPath() . '/info.inc.php');
107 $this->filesize_info
= filesize($this->getPath() . '/info.inc.php');
109 if (isset($theme_full_version)) {
110 $this->setVersion($theme_full_version);
111 } elseif (isset($theme_generation, $theme_version)) {
112 $this->setVersion($theme_generation . '.' . $theme_version);
114 $this->setName($theme_name);
120 * returns theme object loaded from given folder
121 * or false if theme is invalid
123 * @param string $folder path to theme
125 * @return Theme|false
129 static public function load($folder)
131 $theme = new Theme();
133 $theme->setPath($folder);
135 if (! $theme->loadInfo()) {
139 $theme->checkImgPath();
145 * checks image path for existence - if not found use img from fallback theme
150 public function checkImgPath()
152 // try current theme first
153 if (is_dir($this->getPath() . '/img/')) {
154 $this->setImgPath($this->getPath() . '/img/');
158 // try fallback theme
159 $fallback = './themes/' . ThemeManager
::FALLBACK_THEME
. '/img/';
160 if (is_dir($fallback)) {
161 $this->setImgPath($fallback);
168 __('No valid image path for theme %s found!'),
177 * returns path to theme
180 * @return string path to theme
182 public function getPath()
188 * returns layout file
191 * @return string layout file
193 public function getLayoutFile()
195 return $this->getPath() . '/layout.inc.php';
201 * @param string $path path to theme
206 public function setPath($path)
208 $this->path
= trim($path);
214 * @param string $version version to set
219 public function setVersion($version)
221 $this->version
= trim($version);
227 * @return string version
230 public function getVersion()
232 return $this->version
;
236 * checks theme version against $version
237 * returns true if theme version is equal or higher to $version
239 * @param string $version version to compare to
241 * @return boolean true if theme version is equal or higher to $version
244 public function checkVersion($version)
246 return version_compare($this->getVersion(), $version, 'lt');
252 * @param string $name name to set
257 public function setName($name)
259 $this->name
= trim($name);
266 * @return string name
268 public function getName()
276 * @param string $id new id
281 public function setId($id)
283 $this->id
= trim($id);
292 public function getId()
298 * Sets path to images for the theme
300 * @param string $path path to images for this theme
305 public function setImgPath($path)
307 $this->img_path
= $path;
311 * Returns the path to image for the theme.
312 * If filename is given, it possibly fallbacks to fallback
313 * theme for it if image does not exist.
315 * @param string $file file name for image
318 * @return string image path for this theme
320 public function getImgPath($file = null)
322 if (is_null($file)) {
323 return $this->img_path
;
326 if (is_readable($this->img_path
. $file)) {
327 return $this->img_path
. $file;
330 return './themes/' . ThemeManager
::FALLBACK_THEME
. '/img/' . $file;
334 * load css (send to stdout, normally the browser)
339 public function loadCss()
343 if ($GLOBALS['text_dir'] === 'ltr') {
351 foreach ($this->_cssFiles
as $file) {
352 $path = $this->getPath() . "/css/$file.css.php";
353 $fallback = "./themes/"
354 . ThemeManager
::FALLBACK_THEME
. "/css/$file.css.php";
356 if (is_readable($path)) {
357 echo "\n/* FILE: " , $file , ".css.php */\n";
359 } else if (is_readable($fallback)) {
360 echo "\n/* FILE: " , $file , ".css.php */\n";
367 $sprites = $this->getSpriteData();
368 /* Check if there is a valid data file for sprites */
369 if (count($sprites) > 0) {
371 $bg = $this->getImgPath() . 'sprites.png?v=' . urlencode(PMA_VERSION
);
376 margin
-<?php
echo $left; ?
>: .3em
;
377 padding
: 0 !important
;
380 background
-image
: url('<?php echo $bg; ?>') !important
;
381 background
-repeat
: no
-repeat
!important
;
382 background
-position
: top left
!important
;
386 $template = ".ic_%s { background-position: 0 -%upx !important;%s%s }\n";
387 foreach ($sprites as $name => $data) {
388 // generate the CSS code for each icon
391 // if either the height or width of an icon is 16px,
392 // then it's pointless to set this as a parameter,
393 //since it will be inherited from the "icon" class
394 if ($data['width'] != 16) {
395 $width = " width: " . $data['width'] . "px;";
397 if ($data['height'] != 16) {
398 $height = " height: " . $data['height'] . "px;";
403 ($data['position'] * 16),
416 * @return array with sprites
418 public function getSpriteData()
421 $filename = $this->getPath() . '/sprites.lib.php';
422 if (is_readable($filename)) {
424 // This defines sprites array
427 // Backwards compatibility for themes from 4.6 and older
428 if (function_exists('PMA_sprites')) {
429 $sprites = PMA_sprites();
436 * Renders the preview for this theme
441 public function getPrintPreview()
443 $url_params = array('set_theme' => $this->getId());
444 $url = 'index.php' . URL
::getCommon($url_params);
446 $retval = '<div class="theme_preview">';
448 $retval .= htmlspecialchars($this->getName());
449 $retval .= ' (' . htmlspecialchars($this->getVersion()) . ') ';
452 $retval .= '<a class="take_theme" ';
453 $retval .= 'name="' . htmlspecialchars($this->getId()) . '" ';
454 $retval .= 'href="' . $url . '">';
455 if (@file_exists
($this->getPath() . '/screen.png')) {
456 // if screen exists then output
457 $retval .= '<img src="' . $this->getPath() . '/screen.png" border="1"';
458 $retval .= ' alt="' . htmlspecialchars($this->getName()) . '"';
459 $retval .= ' title="' . htmlspecialchars($this->getName()) . '" />';
462 $retval .= __('No preview available.');
464 $retval .= '[ <strong>' . __('take it') . '</strong> ]';
472 * Gets currently configured font size.
474 * @return String with font size.
476 function getFontSize()
478 $fs = $GLOBALS['PMA_Config']->get('fontsize');
482 if (isset($_COOKIE['pma_fontsize'])) {
483 return htmlspecialchars($_COOKIE['pma_fontsize']);
489 * Generates code for CSS gradient using various browser extensions.
491 * @param string $start_color Color of gradient start, hex value without #
492 * @param string $end_color Color of gradient end, hex value without #
494 * @return string CSS code.
496 function getCssGradient($start_color, $end_color)
500 $result[] = 'background-image: url(./themes/svg_gradient.php?from='
501 . $start_color . '&to=' . $end_color . ');';
502 $result[] = 'background-size: 100% 100%;';
503 // Safari 4-5, Chrome 1-9
504 $result[] = 'background: '
505 . '-webkit-gradient(linear, left top, left bottom, from(#'
506 . $start_color . '), to(#' . $end_color . '));';
507 // Safari 5.1, Chrome 10+
508 $result[] = 'background: -webkit-linear-gradient(top, #'
509 . $start_color . ', #' . $end_color . ');';
511 $result[] = 'background: -moz-linear-gradient(top, #'
512 . $start_color . ', #' . $end_color . ');';
514 $result[] = 'background: -ms-linear-gradient(top, #'
515 . $start_color . ', #' . $end_color . ');';
517 $result[] = 'background: -o-linear-gradient(top, #'
518 . $start_color . ', #' . $end_color . ');';
519 return implode("\n", $result);