Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / Theme.class.php
blobbf1ee8f6f8e438564e01c415d5f5bb84b5bd0bd9
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA_Theme class
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * handles theme
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
19 * @package PhpMyAdmin
21 class PMA_Theme
23 /**
24 * @var string theme version
25 * @access protected
27 var $version = '0.0.0.0';
29 /**
30 * @var string theme name
31 * @access protected
33 var $name = '';
35 /**
36 * @var string theme id
37 * @access protected
39 var $id = '';
41 /**
42 * @var string theme path
43 * @access protected
45 var $path = '';
47 /**
48 * @var string image path
49 * @access protected
51 var $img_path = '';
53 /**
54 * @var integer last modification time for info file
55 * @access protected
57 var $mtime_info = 0;
59 /**
60 * needed because sometimes, the mtime for different themes
61 * is identical
62 * @var integer filesize for info file
63 * @access protected
65 var $filesize_info = 0;
67 /**
68 * @var array List of css files to load
69 * @access private
71 private $_cssFiles = array(
72 'common',
73 'enum_editor',
74 'gis',
75 'navigation',
76 'pmd',
77 'rte',
78 'codemirror',
79 'jqplot',
80 'resizable-menu'
83 /**
84 * Loads theme information
86 * @return boolean whether loading them info was successful or not
87 * @access public
89 function loadInfo()
91 if (! file_exists($this->getPath() . '/info.inc.php')) {
92 return false;
95 if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
96 return true;
99 @include $this->getPath() . '/info.inc.php';
101 // was it set correctly?
102 if (! isset($theme_name)) {
103 return false;
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);
116 return true;
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
126 * @static
127 * @access public
129 static public function load($folder)
131 $theme = new PMA_Theme();
133 $theme->setPath($folder);
135 if (! $theme->loadInfo()) {
136 return false;
139 $theme->checkImgPath();
141 return $theme;
145 * checks image path for existance - if not found use img from fallback theme
147 * @access public
148 * @return bool
150 public function checkImgPath()
152 // try current theme first
153 if (is_dir($this->getPath() . '/img/')) {
154 $this->setImgPath($this->getPath() . '/img/');
155 return true;
158 // try fallback theme
159 $fallback = $GLOBALS['cfg']['ThemePath'] . '/'
160 . PMA_Theme_Manager::FALLBACK_THEME
161 . '/img/';
162 if (is_dir($fallback)) {
163 $this->setImgPath($fallback);
164 return true;
167 // we failed
168 trigger_error(
169 sprintf(
170 __('No valid image path for theme %s found!'),
171 $this->getName()
173 E_USER_ERROR
175 return false;
179 * returns path to theme
181 * @access public
182 * @return string path to theme
184 public function getPath()
186 return $this->path;
190 * returns layout file
192 * @access public
193 * @return string layout file
195 public function getLayoutFile()
197 return $this->getPath() . '/layout.inc.php';
201 * set path to theme
203 * @param string $path path to theme
205 * @return void
206 * @access public
208 public function setPath($path)
210 $this->path = trim($path);
214 * sets version
216 * @param string $version version to set
218 * @return void
219 * @access public
221 public function setVersion($version)
223 $this->version = trim($version);
227 * returns version
229 * @return string version
230 * @access public
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
244 * @access public
246 public function checkVersion($version)
248 return version_compare($this->getVersion(), $version, 'lt');
252 * sets name
254 * @param string $name name to set
256 * @return void
257 * @access public
259 public function setName($name)
261 $this->name = trim($name);
265 * returns name
267 * @access public
268 * @return string name
270 public function getName()
272 return $this->name;
276 * sets id
278 * @param string $id new id
280 * @return void
281 * @access public
283 public function setId($id)
285 $this->id = trim($id);
289 * returns id
291 * @return string id
292 * @access public
294 public function getId()
296 return $this->id;
300 * Sets path to images for the theme
302 * @param string $path path to images for this theme
304 * @return void
305 * @access public
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
319 * @access public
320 * @return string image path for this theme
322 public function getImgPath($file = null)
324 if (is_null($file)) {
325 return $this->img_path;
326 } else {
327 if (is_readable($this->img_path . $file)) {
328 return $this->img_path . $file;
329 } else {
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
345 * @access public
347 * @see PMA_SQP_buildCssData()
349 public function buildSQPCssRule($classname, $property, $value)
351 $str = '.' . $classname . ' {';
352 if ($value != '') {
353 $str .= $property . ': ' . $value . ';';
355 $str .= '}' . "\n";
357 return $str;
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
366 * @access public
368 * @global array The current PMA configuration
370 * @see PMA_SQP_buildCssRule()
372 public function buildSQPCssData()
374 global $cfg;
376 $css_string = '';
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']
388 return $css_string;
389 } // end of the "PMA_SQP_buildCssData()" function
392 * load css (send to stdout, normally the browser)
394 * @return bool
395 * @access public
397 public function loadCss()
399 $success = true;
401 echo $this->buildSQPCssData();
403 if ($GLOBALS['text_dir'] === 'ltr') {
404 $right = 'right';
405 $left = 'left';
406 } else {
407 $right = 'left';
408 $left = 'right';
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";
418 include $path;
419 } else if (is_readable($fallback)) {
420 echo "\n/* FILE: $file.css.php */\n";
421 include $fallback;
422 } else {
423 $success = false;
427 include './themes/sprites.css.php';
429 return $success;
433 * Renders the preview for this theme
435 * @return string
436 * @access public
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">';
444 $retval .= '<h2>';
445 $retval .= htmlspecialchars($this->getName());
446 $retval .= ' (' . htmlspecialchars($this->getVersion()) . ') ';
447 $retval .= '</h2>';
448 $retval .= '<p>';
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()) . '" />';
457 $retval .= '<br />';
458 } else {
459 $retval .= __('No preview available.');
461 $retval .= '[ <strong>' . __('take it') . '</strong> ]';
462 $retval .= '</a>';
463 $retval .= '</p>';
464 $retval .= '</div>';
465 return $retval;
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
478 ? 'filter: none'
479 : '';
483 * Gets currently configured font size.
485 * @return String with font size.
487 function getFontSize()
489 $fs = $GLOBALS['PMA_Config']->get('fontsize');
490 if (!is_null($fs)) {
491 return $fs;
493 if (isset($_COOKIE['pma_fontsize'])) {
494 return $_COOKIE['pma_fontsize'];
496 return '82%';
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)
509 $result = array();
510 // Opera 9.5+, IE 9
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 . ');';
521 // Firefox 3.6+
522 $result[] = 'background: -moz-linear-gradient(top, #'
523 . $start_color . ', #' . $end_color . ');';
524 // IE 10
525 $result[] = 'background: -ms-linear-gradient(top, #'
526 . $start_color . ', #' . $end_color . ');';
527 // Opera 11.10
528 $result[] = 'background: -o-linear-gradient(top, #'
529 . $start_color . ', #' . $end_color . ');';
530 // IE 6-8
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']) {
550 return '';
553 $result[] = 'span.cm-keyword, span.cm-statement-verb {';
554 $result[] = ' color: '
555 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_reservedWord'] . ';';
556 $result[] = '}';
557 $result[] = 'span.cm-variable {';
558 $result[] = ' color: '
559 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_identifier'] . ';';
560 $result[] = '}';
561 $result[] = 'span.cm-comment {';
562 $result[] = ' color: '
563 . $GLOBALS['cfg']['SQP']['fmtColor']['comment'] . ';';
564 $result[] = '}';
565 $result[] = 'span.cm-mysql-string {';
566 $result[] = ' color: '
567 . $GLOBALS['cfg']['SQP']['fmtColor']['quote'] . ';';
568 $result[] = '}';
569 $result[] = 'span.cm-operator {';
570 $result[] = ' color: '
571 . $GLOBALS['cfg']['SQP']['fmtColor']['punct'] . ';';
572 $result[] = '}';
573 $result[] = 'span.cm-mysql-word {';
574 $result[] = ' color: '
575 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_identifier'] . ';';
576 $result[] = '}';
577 $result[] = 'span.cm-builtin {';
578 $result[] = ' color: '
579 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_functionName'] . ';';
580 $result[] = '}';
581 $result[] = 'span.cm-variable-2 {';
582 $result[] = ' color: '
583 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_columnType'] . ';';
584 $result[] = '}';
585 $result[] = 'span.cm-variable-3 {';
586 $result[] = ' color: '
587 . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_columnAttrib'] . ';';
588 $result[] = '}';
589 $result[] = 'span.cm-separator {';
590 $result[] = ' color: '
591 . $GLOBALS['cfg']['SQP']['fmtColor']['punct'] . ';';
592 $result[] = '}';
593 $result[] = 'span.cm-number {';
594 $result[] = ' color: '
595 . $GLOBALS['cfg']['SQP']['fmtColor']['digit_integer'] . ';';
596 $result[] = '}';
598 return implode("\n", $result);