Refresh .po files
[phpmyadmin.git] / libraries / Theme.class.php
blob11ebb0d33313a9d258fa3e95e4799cbf2b5cdfef
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA_Theme class
6 * @package PhpMyAdmin
7 */
9 /**
10 * handles theme
12 * @todo add the possibility to make a theme depend on another theme and by default on original
13 * @todo make all components optional - get missing components from 'parent' theme
14 * @todo make css optionally replacing 'parent' css or extending it (by appending at the end)
15 * @todo add an optional global css file - which will be used for both frames
17 * @package PhpMyAdmin
19 class PMA_Theme
21 /**
22 * @var string theme version
23 * @access protected
25 var $version = '0.0.0.0';
27 /**
28 * @var string theme name
29 * @access protected
31 var $name = '';
33 /**
34 * @var string theme id
35 * @access protected
37 var $id = '';
39 /**
40 * @var string theme path
41 * @access protected
43 var $path = '';
45 /**
46 * @var string image path
47 * @access protected
49 var $img_path = '';
51 /**
52 * @var array valid css types
53 * @access protected
55 var $types = array('left', 'right', 'print');
57 /**
58 * @var integer last modification time for info file
59 * @access protected
61 var $mtime_info = 0;
63 /**
64 * needed because sometimes, the mtime for different themes
65 * is identical
66 * @var integer filesize for info file
67 * @access protected
69 var $filesize_info = 0;
71 /**
72 * @access public
73 * @return boolean whether loading them info was successful or not
75 function loadInfo()
77 if (! file_exists($this->getPath() . '/info.inc.php')) {
78 return false;
81 if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
82 return true;
85 @include $this->getPath() . '/info.inc.php';
87 // was it set correctly?
88 if (! isset($theme_name)) {
89 return false;
92 $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
93 $this->filesize_info = filesize($this->getPath() . '/info.inc.php');
95 if (isset($theme_full_version)) {
96 $this->setVersion($theme_full_version);
97 } elseif (isset($theme_generation, $theme_version)) {
98 $this->setVersion($theme_generation . '.' . $theme_version);
100 $this->setName($theme_name);
102 return true;
106 * returns theme object loaded from given folder
107 * or false if theme is invalid
109 * @static
110 * @access public
111 * @param string $folder path to theme
112 * @return object PMA_Theme
114 static public function load($folder)
116 $theme = new PMA_Theme();
118 $theme->setPath($folder);
120 if (! $theme->loadInfo()) {
121 return false;
124 $theme->checkImgPath();
126 return $theme;
130 * checks image path for existance - if not found use img from original theme
132 * @access public
133 * @return bool
135 function checkImgPath()
137 if (is_dir($this->getPath() . '/img/')) {
138 $this->setImgPath($this->getPath() . '/img/');
139 return true;
140 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
141 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
142 return true;
143 } else {
144 trigger_error(
145 sprintf(__('No valid image path for theme %s found!'), $this->getName()),
146 E_USER_ERROR);
147 return false;
152 * returns path to theme
154 * @access public
155 * @return string $path path to theme
157 function getPath()
159 return $this->path;
163 * returns layout file
165 * @access public
166 * @return string layout file
168 function getLayoutFile()
170 return $this->getPath() . '/layout.inc.php';
174 * set path to theme
176 * @access public
177 * @param string $path path to theme
179 function setPath($path)
181 $this->path = trim($path);
185 * sets version
187 * @access public
188 * @param string new version
190 function setVersion($version)
192 $this->version = trim($version);
196 * returns version
198 * @access public
199 * @return string version
201 function getVersion()
203 return $this->version;
207 * checks theme version agaisnt $version
208 * returns true if theme version is equal or higher to $version
210 * @access public
211 * @param string $version version to compare to
212 * @return boolean
214 function checkVersion($version)
216 return version_compare($this->getVersion(), $version, 'lt');
220 * sets name
222 * @access public
223 * @param string $name new name
225 function setName($name)
227 $this->name = trim($name);
231 * returns name
233 * @access public
234 * @return string name
236 function getName()
238 return $this->name;
242 * sets id
244 * @access public
245 * @param string $id new id
247 function setId($id)
249 $this->id = trim($id);
253 * returns id
255 * @access public
256 * @return string id
258 function getId()
260 return $this->id;
264 * @access public
265 * @param string path to images for this theme
267 function setImgPath($path)
269 $this->img_path = $path;
273 * @access public
274 * @return string image path for this theme
276 function getImgPath()
278 return $this->img_path;
282 * load css (send to stdout, normally the browser)
284 * @access public
285 * @param string $type left, right or print
286 * @return bool
288 function loadCss(&$type)
290 if (empty($type) || ! in_array($type, $this->types)) {
291 $type = 'left';
294 if ($type == 'right') {
295 echo PMA_SQP_buildCssData();
298 $_css_file = $this->getPath()
299 . '/css/theme_' . $type . '.css.php';
301 if (! file_exists($_css_file)) {
302 return false;
305 if ($GLOBALS['text_dir'] === 'ltr') {
306 $right = 'right';
307 $left = 'left';
308 } else {
309 $right = 'left';
310 $left = 'right';
313 include $_css_file;
315 if ($type != 'print') {
316 $_sprites_data_file = $this->getPath() . '/sprites.lib.php';
317 $_sprites_css_file = './themes/sprites.css.php';
318 if ( (file_exists($_sprites_data_file) && is_readable($_sprites_data_file))
319 && (file_exists($_sprites_css_file) && is_readable($_sprites_css_file))
321 include $_sprites_data_file;
322 include $_sprites_css_file;
326 return true;
330 * prints out the preview for this theme
332 * @access public
334 function printPreview()
336 echo '<div class="theme_preview">';
337 echo '<h2>' . htmlspecialchars($this->getName())
338 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>';
339 echo '<p>';
340 echo '<a target="_top" class="take_theme" '
341 .'name="' . htmlspecialchars($this->getId()) . '" '
342 . 'href="index.php'.PMA_generate_common_url(array(
343 'set_theme' => $this->getId()
344 )) . '">';
345 if (@file_exists($this->getPath() . '/screen.png')) {
346 // if screen exists then output
348 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
349 .' alt="' . htmlspecialchars($this->getName()) . '"'
350 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
351 } else {
352 echo __('No preview available.');
355 echo '[ <strong>' . __('take it') . '</strong> ]</a>'
356 .'</p>'
357 .'</div>';
361 * Remove filter for IE.
363 * @return string CSS code.
365 function getCssIEClearFilter() {
366 return PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 6 && PMA_USR_BROWSER_VER <= 8
367 ? 'filter: none'
368 : '';
372 * Generates code for CSS gradient using various browser extensions.
374 * @param string $start_color Color of gradient start, hex value without #
375 * @param string $end_color Color of gradient end, hex value without #
377 * @return string CSS code.
379 function getCssGradient($start_color, $end_color)
381 $result = array();
382 // Opera 9.5+, IE 9
383 $result[] = 'background-image: url(./themes/svg_gradient.php?from=' . $start_color . '&to=' . $end_color . ');';
384 $result[] = 'background-size: 100% 100%;';
385 // Safari 4-5, Chrome 1-9
386 $result[] = 'background: -webkit-gradient(linear, left top, left bottom, from(#' . $start_color . '), to(#' . $end_color . '));';
387 // Safari 5.1, Chrome 10+
388 $result[] = 'background: -webkit-linear-gradient(top, #' . $start_color . ', #' . $end_color . ');';
389 // Firefox 3.6+
390 $result[] = 'background: -moz-linear-gradient(top, #' . $start_color . ', #' . $end_color . ');';
391 // IE 10
392 $result[] = 'background: -ms-linear-gradient(top, #' . $start_color . ', #' . $end_color . ');';
393 // Opera 11.10
394 $result[] = 'background: -o-linear-gradient(top, #' . $start_color . ', #' . $end_color . ');';
395 // IE 6-8
396 if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 6 && PMA_USR_BROWSER_VER <= 8) {
397 $result[] = 'filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#' . $start_color . '", endColorstr="#' . $end_color . '");';
399 return implode("\n", $result);
403 * Returns CSS styles for CodeMirror editor based on query formatter colors.
405 * @return string CSS code.
407 function getCssCodeMirror()
409 $result[] = 'span.cm-keyword, span.cm-statement-verb {';
410 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_reservedWord'] . ';';
411 $result[] = '}';
412 $result[] = 'span.cm-variable {';
413 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_identifier'] . ';';
414 $result[] = '}';
415 $result[] = 'span.cm-comment {';
416 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['comment'] . ';';
417 $result[] = '}';
418 $result[] = 'span.cm-mysql-string {';
419 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['quote'] . ';';
420 $result[] = '}';
421 $result[] = 'span.cm-operator {';
422 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['punct'] . ';';
423 $result[] = '}';
424 $result[] = 'span.cm-mysql-word {';
425 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_identifier'] . ';';
426 $result[] = '}';
427 $result[] = 'span.cm-builtin {';
428 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_functionName'] . ';';
429 $result[] = '}';
430 $result[] = 'span.cm-variable-2 {';
431 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_columnType'] . ';';
432 $result[] = '}';
433 $result[] = 'span.cm-variable-3 {';
434 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_columnAttrib'] . ';';
435 $result[] = '}';
436 $result[] = 'span.cm-separator {';
437 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['punct'] . ';';
438 $result[] = '}';
439 $result[] = 'span.cm-number {';
440 $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['digit_integer'] . ';';
441 $result[] = '}';
442 return implode("\n", $result);