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 object PMA_Theme
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 existance - 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 agaisnt $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
;
327 if (is_readable($this->img_path
. $file)) {
328 return $this->img_path
. $file;
330 return $GLOBALS['cfg']['ThemePath'] . '/'
331 . PMA_Theme_Manager
::FALLBACK_THEME
. '/img/' . $file;
337 * Builds a CSS rule used for html formatted SQL queries
339 * @param string $classname The class name
340 * @param string $property The property name
341 * @param string $value The property value
343 * @return string The CSS rule
347 * @see PMA_SQP_buildCssData()
349 public function buildSQPCssRule($classname, $property, $value)
351 $str = '.' . $classname . ' {';
353 $str .= $property . ': ' . $value . ';';
358 } // end of the "PMA_SQP_buildCssRule()" function
362 * Builds CSS rules used for html formatted SQL queries
364 * @return string The CSS rules set
368 * @global array The current PMA configuration
370 * @see PMA_SQP_buildCssRule()
372 public function buildSQPCssData()
377 foreach ($cfg['SQP']['fmtColor'] AS $key => $col) {
378 $css_string .= $this->buildSQPCssRule('syntax_' . $key, 'color', $col);
381 for ($i = 0; $i < 8; $i++
) {
382 $css_string .= $this->buildSQPCssRule(
383 'syntax_indent' . $i, 'margin-left',
384 ($i * $cfg['SQP']['fmtInd']) . $cfg['SQP']['fmtIndUnit']
389 } // end of the "PMA_SQP_buildCssData()" function
392 * load css (send to stdout, normally the browser)
397 public function loadCss()
401 echo $this->buildSQPCssData();
403 if ($GLOBALS['text_dir'] === 'ltr') {
411 foreach ($this->_cssFiles
as $file) {
412 $path = $this->getPath() . "/css/$file.css.php";
413 $fallback = "./themes/"
414 . PMA_Theme_Manager
::FALLBACK_THEME
. "/css/$file.css.php";
416 if (is_readable($path)) {
417 echo "\n/* FILE: $file.css.php */\n";
419 } else if (is_readable($fallback)) {
420 echo "\n/* FILE: $file.css.php */\n";
427 include './themes/sprites.css.php';
433 * Renders the preview for this theme
438 public function getPrintPreview()
440 $url_params = array('set_theme' => $this->getId());
441 $url = 'index.php'. PMA_generate_common_url($url_params);
443 $retval = '<div class="theme_preview">';
445 $retval .= htmlspecialchars($this->getName());
446 $retval .= ' (' . htmlspecialchars($this->getVersion()) . ') ';
449 $retval .= '<a class="take_theme" ';
450 $retval .= 'name="' . htmlspecialchars($this->getId()) . '" ';
451 $retval .= 'href="' . $url . '">';
452 if (@file_exists
($this->getPath() . '/screen.png')) {
453 // if screen exists then output
454 $retval .= '<img src="' . $this->getPath() . '/screen.png" border="1"';
455 $retval .= ' alt="' . htmlspecialchars($this->getName()) . '"';
456 $retval .= ' title="' . htmlspecialchars($this->getName()) . '" />';
459 $retval .= __('No preview available.');
461 $retval .= '[ <strong>' . __('take it') . '</strong> ]';
469 * Remove filter for IE.
471 * @return string CSS code.
473 function getCssIEClearFilter()
475 return PMA_USR_BROWSER_AGENT
== 'IE'
476 && PMA_USR_BROWSER_VER
>= 6
477 && PMA_USR_BROWSER_VER
<= 8
483 * Gets currently configured font size.
485 * @return String with font size.
487 function getFontSize()
489 $fs = $GLOBALS['PMA_Config']->get('fontsize');
493 if (isset($_COOKIE['pma_fontsize'])) {
494 return $_COOKIE['pma_fontsize'];
500 * Generates code for CSS gradient using various browser extensions.
502 * @param string $start_color Color of gradient start, hex value without #
503 * @param string $end_color Color of gradient end, hex value without #
505 * @return string CSS code.
507 function getCssGradient($start_color, $end_color)
511 $result[] = 'background-image: url(./themes/svg_gradient.php?from='
512 . $start_color . '&to=' . $end_color . ');';
513 $result[] = 'background-size: 100% 100%;';
514 // Safari 4-5, Chrome 1-9
515 $result[] = 'background: '
516 . '-webkit-gradient(linear, left top, left bottom, from(#'
517 . $start_color . '), to(#' . $end_color . '));';
518 // Safari 5.1, Chrome 10+
519 $result[] = 'background: -webkit-linear-gradient(top, #'
520 . $start_color . ', #' . $end_color . ');';
522 $result[] = 'background: -moz-linear-gradient(top, #'
523 . $start_color . ', #' . $end_color . ');';
525 $result[] = 'background: -ms-linear-gradient(top, #'
526 . $start_color . ', #' . $end_color . ');';
528 $result[] = 'background: -o-linear-gradient(top, #'
529 . $start_color . ', #' . $end_color . ');';
531 if (PMA_USR_BROWSER_AGENT
== 'IE'
532 && PMA_USR_BROWSER_VER
>= 6
533 && PMA_USR_BROWSER_VER
<= 8
535 $result[] = 'filter: '
536 . 'progid:DXImageTransform.Microsoft.gradient(startColorstr="#'
537 . $start_color . '", endColorstr="#' . $end_color . '");';
539 return implode("\n", $result);
543 * Returns CSS styles for CodeMirror editor based on query formatter colors.
545 * @return string CSS code.
547 function getCssCodeMirror()
549 if (! $GLOBALS['cfg']['CodemirrorEnable']) {
553 $result[] = 'span.cm-keyword, span.cm-statement-verb {';
554 $result[] = ' color: '
555 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_reservedWord'] . ';';
557 $result[] = 'span.cm-variable {';
558 $result[] = ' color: '
559 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_identifier'] . ';';
561 $result[] = 'span.cm-comment {';
562 $result[] = ' color: '
563 . $GLOBALS['cfg']['SQP']['fmtColor']['comment'] . ';';
565 $result[] = 'span.cm-mysql-string {';
566 $result[] = ' color: '
567 . $GLOBALS['cfg']['SQP']['fmtColor']['quote'] . ';';
569 $result[] = 'span.cm-operator {';
570 $result[] = ' color: '
571 . $GLOBALS['cfg']['SQP']['fmtColor']['punct'] . ';';
573 $result[] = 'span.cm-mysql-word {';
574 $result[] = ' color: '
575 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_identifier'] . ';';
577 $result[] = 'span.cm-builtin {';
578 $result[] = ' color: '
579 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_functionName'] . ';';
581 $result[] = 'span.cm-variable-2 {';
582 $result[] = ' color: '
583 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_columnType'] . ';';
585 $result[] = 'span.cm-variable-3 {';
586 $result[] = ' color: '
587 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_columnAttrib'] . ';';
589 $result[] = 'span.cm-separator {';
590 $result[] = ' color: '
591 . $GLOBALS['cfg']['SQP']['fmtColor']['punct'] . ';';
593 $result[] = 'span.cm-number {';
594 $result[] = ' color: '
595 . $GLOBALS['cfg']['SQP']['fmtColor']['digit_integer'] . ';';
598 return implode("\n", $result);