2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 if (! defined('PHPMYADMIN')) {
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 PMA_Theme|false
129 static public function load($folder)
131 $theme = new PMA_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 = $GLOBALS['cfg']['ThemePath'] . '/'
160 . PMA_Theme_Manager
::FALLBACK_THEME
162 if (is_dir($fallback)) {
163 $this->setImgPath($fallback);
170 __('No valid image path for theme %s found!'),
179 * returns path to theme
182 * @return string path to theme
184 public function getPath()
190 * returns layout file
193 * @return string layout file
195 public function getLayoutFile()
197 return $this->getPath() . '/layout.inc.php';
203 * @param string $path path to theme
208 public function setPath($path)
210 $this->path
= trim($path);
216 * @param string $version version to set
221 public function setVersion($version)
223 $this->version
= trim($version);
229 * @return string version
232 public function getVersion()
234 return $this->version
;
238 * checks theme version against $version
239 * returns true if theme version is equal or higher to $version
241 * @param string $version version to compare to
243 * @return boolean true if theme version is equal or higher to $version
246 public function checkVersion($version)
248 return version_compare($this->getVersion(), $version, 'lt');
254 * @param string $name name to set
259 public function setName($name)
261 $this->name
= trim($name);
268 * @return string name
270 public function getName()
278 * @param string $id new id
283 public function setId($id)
285 $this->id
= trim($id);
294 public function getId()
300 * Sets path to images for the theme
302 * @param string $path path to images for this theme
307 public function setImgPath($path)
309 $this->img_path
= $path;
313 * Returns the path to image for the theme.
314 * If filename is given, it possibly fallbacks to fallback
315 * theme for it if image does not exist.
317 * @param string $file file name for image
320 * @return string image path for this theme
322 public function getImgPath($file = null)
324 if (is_null($file)) {
325 return $this->img_path
;
328 if (is_readable($this->img_path
. $file)) {
329 return $this->img_path
. $file;
332 return $GLOBALS['cfg']['ThemePath'] . '/'
333 . PMA_Theme_Manager
::FALLBACK_THEME
. '/img/' . $file;
337 * load css (send to stdout, normally the browser)
342 public function loadCss()
346 if ($GLOBALS['text_dir'] === 'ltr') {
354 foreach ($this->_cssFiles
as $file) {
355 $path = $this->getPath() . "/css/$file.css.php";
356 $fallback = "./themes/"
357 . PMA_Theme_Manager
::FALLBACK_THEME
. "/css/$file.css.php";
359 if (is_readable($path)) {
360 echo "\n/* FILE: $file.css.php */\n";
362 } else if (is_readable($fallback)) {
363 echo "\n/* FILE: $file.css.php */\n";
370 include './themes/sprites.css.php';
376 * Renders the preview for this theme
381 public function getPrintPreview()
383 $url_params = array('set_theme' => $this->getId());
384 $url = 'index.php' . PMA_URL_getCommon($url_params);
386 $retval = '<div class="theme_preview">';
388 $retval .= htmlspecialchars($this->getName());
389 $retval .= ' (' . htmlspecialchars($this->getVersion()) . ') ';
392 $retval .= '<a class="take_theme" ';
393 $retval .= 'name="' . htmlspecialchars($this->getId()) . '" ';
394 $retval .= 'href="' . $url . '">';
395 if (@file_exists
($this->getPath() . '/screen.png')) {
396 // if screen exists then output
397 $retval .= '<img src="' . $this->getPath() . '/screen.png" border="1"';
398 $retval .= ' alt="' . htmlspecialchars($this->getName()) . '"';
399 $retval .= ' title="' . htmlspecialchars($this->getName()) . '" />';
402 $retval .= __('No preview available.');
404 $retval .= '[ <strong>' . __('take it') . '</strong> ]';
412 * Remove filter for IE.
414 * @return string CSS code.
416 function getCssIEClearFilter()
418 return PMA_USR_BROWSER_AGENT
== 'IE'
419 && PMA_USR_BROWSER_VER
>= 6
420 && PMA_USR_BROWSER_VER
<= 8
426 * Gets currently configured font size.
428 * @return String with font size.
430 function getFontSize()
432 $fs = $GLOBALS['PMA_Config']->get('fontsize');
436 if (isset($_COOKIE['pma_fontsize'])) {
437 return htmlspecialchars($_COOKIE['pma_fontsize']);
443 * Generates code for CSS gradient using various browser extensions.
445 * @param string $start_color Color of gradient start, hex value without #
446 * @param string $end_color Color of gradient end, hex value without #
448 * @return string CSS code.
450 function getCssGradient($start_color, $end_color)
454 $result[] = 'background-image: url(./themes/svg_gradient.php?from='
455 . $start_color . '&to=' . $end_color . ');';
456 $result[] = 'background-size: 100% 100%;';
457 // Safari 4-5, Chrome 1-9
458 $result[] = 'background: '
459 . '-webkit-gradient(linear, left top, left bottom, from(#'
460 . $start_color . '), to(#' . $end_color . '));';
461 // Safari 5.1, Chrome 10+
462 $result[] = 'background: -webkit-linear-gradient(top, #'
463 . $start_color . ', #' . $end_color . ');';
465 $result[] = 'background: -moz-linear-gradient(top, #'
466 . $start_color . ', #' . $end_color . ');';
468 $result[] = 'background: -ms-linear-gradient(top, #'
469 . $start_color . ', #' . $end_color . ');';
471 $result[] = 'background: -o-linear-gradient(top, #'
472 . $start_color . ', #' . $end_color . ');';
474 if (PMA_USR_BROWSER_AGENT
== 'IE'
475 && PMA_USR_BROWSER_VER
>= 6
476 && PMA_USR_BROWSER_VER
<= 8
478 $result[] = 'filter: '
479 . 'progid:DXImageTransform.Microsoft.gradient(startColorstr="#'
480 . $start_color . '", endColorstr="#' . $end_color . '");';
482 return implode("\n", $result);