2.9.2-rc1
[phpmyadmin/arisferyanto.git] / libraries / Config.class.php
blob5f9051ec3709aa77baf6bd5c100a3a8d8b077053
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Configuration class
8 */
9 class PMA_Config
11 /**
12 * @var string default config source
14 var $default_source = './libraries/config.default.php';
16 /**
17 * @var array configuration settings
19 var $settings = array();
21 /**
22 * @var string config source
24 var $source = '';
26 /**
27 * @var int source modification time
29 var $source_mtime = 0;
30 var $default_source_mtime = 0;
32 /**
33 * @var boolean
35 var $error_config_file = false;
37 /**
38 * @var boolean
40 var $error_config_default_file = false;
42 /**
43 * @var boolean
45 var $error_pma_uri = false;
47 /**
48 * @var array
50 var $default_server = array();
52 /**
53 * @var boolean wether init is done or mot
54 * set this to false to force some initial checks
55 * like checking for required functions
57 var $done = false;
59 /**
60 * constructor
62 * @param string source to read config from
64 function __construct($source = null)
66 $this->settings = array();
68 // functions need to refresh in case of config file changed goes in
69 // PMA_Config::load()
70 $this->load($source);
72 // other settings, independant from config file, comes in
73 $this->checkSystem();
75 $this->checkIsHttps();
78 /**
79 * sets system and application settings
81 function checkSystem()
83 $this->set('PMA_VERSION', '2.9.2-rc1');
84 /**
85 * @deprecated
87 $this->set('PMA_THEME_VERSION', 2);
88 /**
89 * @deprecated
91 $this->set('PMA_THEME_GENERATION', 2);
93 $this->checkPhpVersion();
94 $this->checkWebServerOs();
95 $this->checkWebServer();
96 $this->checkGd2();
97 $this->checkClient();
98 $this->checkUpload();
99 $this->checkUploadSize();
100 $this->checkOutputCompression();
104 * wether to use gzip output compression or not
106 function checkOutputCompression()
108 // If zlib output compression is set in the php configuration file, no
109 // output buffering should be run
110 if (@ini_get('zlib.output_compression')) {
111 $this->set('OBGzip', false);
114 // disable output-buffering (if set to 'auto') for IE6, else enable it.
115 if (strtolower($this->get('OBGzip')) == 'auto') {
116 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
117 && $this->get('PMA_USR_BROWSER_VER') >= 6
118 && $this->get('PMA_USR_BROWSER_VER') < 7) {
119 $this->set('OBGzip', false);
120 } else {
121 $this->set('OBGzip', true);
127 * Determines platform (OS), browser and version of the user
128 * Based on a phpBuilder article:
129 * @see http://www.phpbuilder.net/columns/tim20000821.php
131 function checkClient()
133 if (PMA_getenv('HTTP_USER_AGENT')) {
134 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
135 } elseif (!isset($HTTP_USER_AGENT)) {
136 $HTTP_USER_AGENT = '';
139 // 1. Platform
140 if (strstr($HTTP_USER_AGENT, 'Win')) {
141 $this->set('PMA_USR_OS', 'Win');
142 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
143 $this->set('PMA_USR_OS', 'Mac');
144 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
145 $this->set('PMA_USR_OS', 'Linux');
146 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
147 $this->set('PMA_USR_OS', 'Unix');
148 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
149 $this->set('PMA_USR_OS', 'OS/2');
150 } else {
151 $this->set('PMA_USR_OS', 'Other');
154 // 2. browser and version
155 // (must check everything else before Mozilla)
157 if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
158 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
159 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
160 } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
161 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
162 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
163 } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
164 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
165 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
166 //} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
167 // Konqueror 2.2.2 says Konqueror/2.2.2
168 // Konqueror 3.0.3 says Konqueror/3
169 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
170 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
171 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
172 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
173 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
174 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
175 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
176 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
177 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
178 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
179 } else {
180 $this->set('PMA_USR_BROWSER_VER', 0);
181 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
186 * Whether GD2 is present
188 function checkGd2()
190 if ($this->get('GD2Available') == 'yes') {
191 $this->set('PMA_IS_GD2', 1);
192 } elseif ($this->get('GD2Available') == 'no') {
193 $this->set('PMA_IS_GD2', 0);
194 } else {
195 if (!@extension_loaded('gd')) {
196 PMA_dl('gd');
198 if (!@function_exists('imagecreatetruecolor')) {
199 $this->set('PMA_IS_GD2', 0);
200 } else {
201 if (@function_exists('gd_info')) {
202 $gd_nfo = gd_info();
203 if (strstr($gd_nfo["GD Version"], '2.')) {
204 $this->set('PMA_IS_GD2', 1);
205 } else {
206 $this->set('PMA_IS_GD2', 0);
208 } else {
209 /* We must do hard way... */
210 ob_start();
211 phpinfo(INFO_MODULES); /* Only modules */
212 $a = strip_tags(ob_get_contents());
213 ob_end_clean();
214 /* Get GD version string from phpinfo output */
215 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
216 if (strstr($v, '2.')) {
217 $this->set('PMA_IS_GD2', 1);
218 } else {
219 $this->set('PMA_IS_GD2', 0);
221 } else {
222 $this->set('PMA_IS_GD2', 0);
230 * Whether the Web server php is running on is IIS
232 function checkWebServer()
234 if (PMA_getenv('SERVER_SOFTWARE')
235 // some versions return Microsoft-IIS, some Microsoft/IIS
236 // we could use a preg_match() but it's slower
237 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
238 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
239 $this->set('PMA_IS_IIS', 1);
240 } else {
241 $this->set('PMA_IS_IIS', 0);
246 * Whether the os php is running on is windows or not
248 function checkWebServerOs()
250 // Default to Unix or Equiv
251 $this->set('PMA_IS_WINDOWS', 0);
252 // If PHP_OS is defined then continue
253 if (defined('PHP_OS')) {
254 if (stristr(PHP_OS, 'win') ) {
255 // Is it some version of Windows
256 $this->set('PMA_IS_WINDOWS', 1);
257 } elseif (stristr(PHP_OS, 'OS/2')) {
258 // Is it OS/2 (No file permissions like Windows)
259 $this->set('PMA_IS_WINDOWS', 1);
265 * detects PHP version
267 function checkPhpVersion()
269 $match = array();
270 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
271 phpversion(), $match)) {
272 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
273 phpversion(), $match);
275 if (isset($match) && ! empty($match[1])) {
276 if (! isset($match[2])) {
277 $match[2] = 0;
279 if (! isset($match[3])) {
280 $match[3] = 0;
282 $this->set('PMA_PHP_INT_VERSION',
283 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
284 } else {
285 $this->set('PMA_PHP_INT_VERSION', 0);
287 $this->set('PMA_PHP_STR_VERSION', phpversion());
291 * re-init object after loading from session file
292 * checks config file for changes and relaods if neccessary
294 function __wakeup()
296 if (! $this->checkConfigSource()
297 || $this->source_mtime !== filemtime($this->getSource())
298 || $this->default_source_mtime !== filemtime($this->default_source)
299 || $this->error_config_file
300 || $this->error_config_default_file) {
301 $this->settings = array();
302 $this->load();
303 $this->checkSystem();
306 // check for https needs to be done everytime,
307 // as https and http uses same session so this info can not be stored
308 // in session
309 $this->checkIsHttps();
311 $this->checkCollationConnection();
312 $this->checkFontsize();
316 * loads default values from default source
318 * @uses file_exists()
319 * @uses $this->default_source
320 * @uses $this->error_config_default_file
321 * @uses $this->settings
322 * @return boolean success
324 function loadDefaults()
326 $cfg = array();
327 if (! file_exists($this->default_source)) {
328 $this->error_config_default_file = true;
329 return false;
331 include $this->default_source;
333 $this->default_source_mtime = filemtime($this->default_source);
335 $this->default_server = $cfg['Servers'][1];
336 unset($cfg['Servers']);
338 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
340 $this->error_config_default_file = false;
342 return true;
346 * loads configuration from $source, usally the config file
347 * should be called on object creation and from __wakeup if config file
348 * has changed
350 * @param string $source config file
352 function load($source = null)
354 $this->loadDefaults();
356 if (null !== $source) {
357 $this->setSource($source);
360 if (! $this->checkConfigSource()) {
361 return false;
364 $cfg = array();
367 * Parses the configuration file
369 $old_error_reporting = error_reporting(0);
370 if (function_exists('file_get_contents')) {
371 $eval_result =
372 eval('?>' . trim(file_get_contents($this->getSource())));
373 } else {
374 $eval_result =
375 eval('?>' . trim(implode("\n", file($this->getSource()))));
377 error_reporting($old_error_reporting);
379 if ($eval_result === false) {
380 $this->error_config_file = true;
381 } else {
382 $this->error_config_file = false;
383 $this->source_mtime = filemtime($this->getSource());
387 * @TODO check validity of $_COOKIE['pma_collation_connection']
389 if (! empty($_COOKIE['pma_collation_connection'])) {
390 $this->set('collation_connection',
391 strip_tags($_COOKIE['pma_collation_connection']));
392 } else {
393 $this->set('collation_connection',
394 $this->get('DefaultConnectionCollation'));
397 $this->checkCollationConnection();
398 $this->checkFontsize();
399 //$this->checkPmaAbsoluteUri();
400 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
401 return true;
405 * set source
406 * @param string $source
408 function setSource($source)
410 $this->source = trim($source);
414 * checks if the config folder still exists and terminates app if true
416 function checkConfigFolder()
418 // Refuse to work while there still might be some world writable dir:
419 if (is_dir('./config')) {
420 die('Remove "./config" directory before using phpMyAdmin!');
425 * check config source
427 * @return boolean wether source is valid or not
429 function checkConfigSource()
431 if (! $this->getSource()) {
432 // no configuration file set at all
433 return false;
436 if (! file_exists($this->getSource())) {
437 // do not trigger error here
438 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
440 trigger_error(
441 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
442 E_USER_WARNING);
444 $this->source_mtime = 0;
445 return false;
448 if (! is_readable($this->getSource())) {
449 $this->source_mtime = 0;
450 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
453 // Check for permissions (on platforms that support it):
454 $perms = @fileperms($this->getSource());
455 if (!($perms === false) && ($perms & 2)) {
456 // This check is normally done after loading configuration
457 $this->checkWebServerOs();
458 if ($this->get('PMA_IS_WINDOWS') == 0) {
459 $this->source_mtime = 0;
460 die('Wrong permissions on configuration file, should not be world writable!');
464 return true;
468 * returns specific config setting
469 * @param string $setting
470 * @return mixed value
472 function get($setting)
474 if (isset($this->settings[$setting])) {
475 return $this->settings[$setting];
477 return null;
481 * sets configuration variable
483 * @uses $this->settings
484 * @param string $setting configuration option
485 * @param string $value new value for configuration option
487 function set($setting, $value)
489 $this->settings[$setting] = $value;
493 * returns source for current config
494 * @return string config source
496 function getSource()
498 return $this->source;
502 * old PHP 4 style constructor
504 * @deprecated
506 function PMA_Config($source = null)
508 $this->__construct($source);
512 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
513 * set properly and, depending on browsers, inserting or updating a
514 * record might fail
516 function checkPmaAbsoluteUri()
518 // Setup a default value to let the people and lazy syadmins work anyway,
519 // they'll get an error if the autodetect code doesn't work
520 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
521 $is_https = $this->get('is_https');
522 if (strlen($pma_absolute_uri) < 5
523 // needed to catch http/https switch
524 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
525 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
527 $url = array();
529 // At first we try to parse REQUEST_URI, it might contain full URL
530 if (PMA_getenv('REQUEST_URI')) {
531 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
532 if ($url === false) {
533 $url = array( 'path' => $_SERVER['REQUEST_URI'] );
537 // If we don't have scheme, we didn't have full URL so we need to
538 // dig deeper
539 if (empty($url['scheme'])) {
540 // Scheme
541 if (PMA_getenv('HTTP_SCHEME')) {
542 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
543 } else {
544 $url['scheme'] =
545 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
546 ? 'https'
547 : 'http';
550 // Host and port
551 if (PMA_getenv('HTTP_HOST')) {
552 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
553 list($url['host'], $url['port']) =
554 explode(':', PMA_getenv('HTTP_HOST'));
555 } else {
556 $url['host'] = PMA_getenv('HTTP_HOST');
558 } elseif (PMA_getenv('SERVER_NAME')) {
559 $url['host'] = PMA_getenv('SERVER_NAME');
560 } else {
561 $this->error_pma_uri = true;
562 return false;
565 // If we didn't set port yet...
566 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
567 $url['port'] = PMA_getenv('SERVER_PORT');
570 // And finally the path could be already set from REQUEST_URI
571 if (empty($url['path'])) {
572 if (PMA_getenv('PATH_INFO')) {
573 $path = parse_url(PMA_getenv('PATH_INFO'));
574 } else {
575 // PHP_SELF in CGI often points to cgi executable, so use it
576 // as last choice
577 $path = parse_url(PMA_getenv('PHP_SELF'));
579 $url['path'] = $path['path'];
583 // Make url from parts we have
584 $pma_absolute_uri = $url['scheme'] . '://';
585 // Was there user information?
586 if (!empty($url['user'])) {
587 $pma_absolute_uri .= $url['user'];
588 if (!empty($url['pass'])) {
589 $pma_absolute_uri .= ':' . $url['pass'];
591 $pma_absolute_uri .= '@';
593 // Add hostname
594 $pma_absolute_uri .= $url['host'];
595 // Add port, if it not the default one
596 if (! empty($url['port'])
597 && (($url['scheme'] == 'http' && $url['port'] != 80)
598 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
599 $pma_absolute_uri .= ':' . $url['port'];
601 // And finally path, without script name, the 'a' is there not to
602 // strip our directory, when path is only /pmadir/ without filename.
603 // Backslashes returned by Windows have to be changed.
604 // Only replace backslashes by forward slashes if on Windows,
605 // as the backslash could be valid on a non-Windows system.
606 if ($this->get('PMA_IS_WINDOWS') == 1) {
607 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
608 } else {
609 $path = dirname($url['path'] . 'a');
612 // To work correctly within transformations overview:
613 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
614 if ($this->get('PMA_IS_WINDOWS') == 1) {
615 $path = str_replace("\\", "/", dirname(dirname($path)));
616 } else {
617 $path = dirname(dirname($path));
620 // in vhost situations, there could be already an ending slash
621 if (substr($path, -1) != '/') {
622 $path .= '/';
624 $pma_absolute_uri .= $path;
626 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
627 // the autodetect code works well enough that we don't display the
628 // warning at all. The user can still set PmaAbsoluteUri manually.
629 // See
630 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
632 } else {
633 // The URI is specified, however users do often specify this
634 // wrongly, so we try to fix this.
636 // Adds a trailing slash et the end of the phpMyAdmin uri if it
637 // does not exist.
638 if (substr($pma_absolute_uri, -1) != '/') {
639 $pma_absolute_uri .= '/';
642 // If URI doesn't start with http:// or https://, we will add
643 // this.
644 if (substr($pma_absolute_uri, 0, 7) != 'http://'
645 && substr($pma_absolute_uri, 0, 8) != 'https://') {
646 $pma_absolute_uri =
647 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
648 ? 'https'
649 : 'http')
650 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
651 . $pma_absolute_uri;
655 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
659 * check selected collation_connection
660 * @TODO check validity of $_REQUEST['collation_connection']
662 function checkCollationConnection()
664 // (could be improved by executing it after the MySQL connection only if
665 // PMA_MYSQL_INT_VERSION >= 40100)
666 if (! empty($_REQUEST['collation_connection'])) {
667 $this->set('collation_connection',
668 strip_tags($_REQUEST['collation_connection']));
673 * checks for font size configuration, and sets font size as requested by user
675 * @uses $_GET
676 * @uses $_POST
677 * @uses $_COOKIE
678 * @uses preg_match()
679 * @uses function_exists()
680 * @uses PMA_Config::set()
681 * @uses PMA_Config::get()
682 * @uses PMA_setCookie()
684 function checkFontsize()
686 $new_fontsize = '';
688 if (isset($_GET['fontsize'])) {
689 $new_fontsize = $_GET['fontsize'];
690 } elseif (isset($_POST['fontsize'])) {
691 $new_fontsize = $_POST['fontsize'];
692 } elseif (isset($_COOKIE['pma_fontsize'])) {
693 $new_fontsize = $_COOKIE['pma_fontsize'];
696 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
697 $this->set('fontsize', $new_fontsize);
698 } elseif (! $this->get('fontsize')) {
699 $this->set('fontsize', '100%');
702 if (function_exists('PMA_setCookie')) {
703 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '100%');
708 * checks if upload is enabled
711 function checkUpload()
713 $this->set('enable_upload', true);
714 if (strtolower(@ini_get('file_uploads')) == 'off'
715 || @ini_get('file_uploads') == 0) {
716 $this->set('enable_upload', false);
721 * Maximum upload size as limited by PHP
722 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
724 * this section generates $max_upload_size in bytes
726 function checkUploadSize()
728 if (! $filesize = ini_get('upload_max_filesize')) {
729 $filesize = "5M";
732 if ($postsize = ini_get('post_max_size')) {
733 $this->set('max_upload_size',
734 min(get_real_size($filesize), get_real_size($postsize)));
735 } else {
736 $this->set('max_upload_size', get_real_size($filesize));
741 * check for https
743 function checkIsHttps()
745 $this->set('is_https', PMA_Config::isHttps());
749 * @static
751 function isHttps()
753 $is_https = false;
755 $url = array();
757 // At first we try to parse REQUEST_URI, it might contain full URL,
758 if (PMA_getenv('REQUEST_URI')) {
759 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
760 if($url === false) {
761 $url = array();
765 // If we don't have scheme, we didn't have full URL so we need to
766 // dig deeper
767 if (empty($url['scheme'])) {
768 // Scheme
769 if (PMA_getenv('HTTP_SCHEME')) {
770 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
771 } else {
772 $url['scheme'] =
773 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
774 ? 'https'
775 : 'http';
779 if (isset($url['scheme'])
780 && $url['scheme'] == 'https') {
781 $is_https = true;
782 } else {
783 $is_https = false;
786 return $is_https;
790 * detect correct cookie path
792 function checkCookiePath()
794 $this->set('cookie_path', PMA_Config::getCookiePath());
798 * @static
800 function getCookiePath()
802 static $cookie_path = null;
804 if (null !== $cookie_path) {
805 return $cookie_path;
808 $url = '';
810 if (PMA_getenv('REQUEST_URI')) {
811 $url = PMA_getenv('REQUEST_URI');
814 // If we don't have path
815 if (empty($url)) {
816 if (PMA_getenv('PATH_INFO')) {
817 $url = PMA_getenv('PATH_INFO');
818 } elseif (PMA_getenv('PHP_SELF')) {
819 // PHP_SELF in CGI often points to cgi executable, so use it
820 // as last choice
821 $url = PMA_getenv('PHP_SELF');
822 } elseif (PMA_getenv('SCRIPT_NAME')) {
823 $url = PMA_getenv('PHP_SELF');
827 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
828 if ($parsed_url === false) {
829 $parsed_url = array('path' => $url);
832 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
834 return $cookie_path;
838 * enables backward compatibility
840 function enableBc()
842 $GLOBALS['cfg'] =& $this->settings;
843 $GLOBALS['default_server'] =& $this->default_server;
844 $GLOBALS['collation_connection'] = $this->get('collation_connection');
845 $GLOBALS['is_upload'] = $this->get('enable_upload');
846 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
847 $GLOBALS['cookie_path'] = $this->get('cookie_path');
848 $GLOBALS['is_https'] = $this->get('is_https');
850 $defines = array(
851 'PMA_VERSION',
852 'PMA_THEME_VERSION',
853 'PMA_THEME_GENERATION',
854 'PMA_PHP_STR_VERSION',
855 'PMA_PHP_INT_VERSION',
856 'PMA_IS_WINDOWS',
857 'PMA_IS_IIS',
858 'PMA_IS_GD2',
859 'PMA_USR_OS',
860 'PMA_USR_BROWSER_VER',
861 'PMA_USR_BROWSER_AGENT',
864 foreach ($defines as $define) {
865 if (! defined($define)) {
866 define($define, $this->get($define));
872 * @todo finish
874 function save() {}
877 * returns options for font size selection
879 * @uses preg_replace()
880 * @uses ksort()
881 * @static
882 * @param string $current_size current selected font size with unit
883 * @return array selectable font sizes
885 function getFontsizeOptions($current_size = '100%')
887 $unit = preg_replace('/[0-9.]*/', '', $current_size);
888 $value = preg_replace('/[^0-9.]*/', '', $current_size);
890 $factors = array();
891 $options = array();
892 $options["$value"] = $value . $unit;
894 if ($unit === '%') {
895 $factors[] = 1;
896 $factors[] = 5;
897 $factors[] = 10;
898 } elseif ($unit === 'em') {
899 $factors[] = 0.05;
900 $factors[] = 0.2;
901 $factors[] = 1;
902 } elseif ($unit === 'pt') {
903 $factors[] = 0.5;
904 $factors[] = 2;
905 } elseif ($unit === 'px') {
906 $factors[] = 1;
907 $factors[] = 5;
908 $factors[] = 10;
909 } else {
910 //unknown font size unit
911 $factors[] = 0.05;
912 $factors[] = 0.2;
913 $factors[] = 1;
914 $factors[] = 5;
915 $factors[] = 10;
918 foreach ($factors as $key => $factor) {
919 $option_inc = $value + $factor;
920 $option_dec = $value - $factor;
921 while (count($options) < 21) {
922 $options["$option_inc"] = $option_inc . $unit;
923 if ($option_dec > $factors[0]) {
924 $options["$option_dec"] = $option_dec . $unit;
926 $option_inc += $factor;
927 $option_dec -= $factor;
928 if (isset($factors[$key + 1])
929 && $option_inc >= $value + $factors[$key + 1]) {
930 break;
934 ksort($options);
935 return $options;
939 * returns html selectbox for font sizes
941 * @uses $_SESSION['PMA_Config']
942 * @uses PMA_Config::get()
943 * @uses PMA_Config::getFontsizeOptions()
944 * @uses $GLOBALS['strFontSize']
945 * @static
946 * @param string $current_size currently slected font size with unit
947 * @return string html selectbox
949 function getFontsizeSelection()
951 $current_size = $_SESSION['PMA_Config']->get('fontsize');
952 $options = PMA_Config::getFontsizeOptions($current_size);
954 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
955 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
956 foreach ($options as $option) {
957 $return .= '<option value="' . $option . '"';
958 if ($option == $current_size) {
959 $return .= ' selected="selected"';
961 $return .= '>' . $option . '</option>' . "\n";
963 $return .= '</select>';
965 return $return;
969 * return complete font size selection form
971 * @uses PMA_generate_common_hidden_inputs()
972 * @uses PMA_Config::getFontsizeSelection()
973 * @uses $GLOBALS['strGo']
974 * @static
975 * @param string $current_size currently slected font size with unit
976 * @return string html selectbox
978 function getFontsizeForm()
980 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
981 . ' method="post" action="index.php" target="_parent">' . "\n"
982 . PMA_generate_common_hidden_inputs() . "\n"
983 . PMA_Config::getFontsizeSelection() . "\n"
984 . '<noscript>' . "\n"
985 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
986 . '</noscript>' . "\n"
987 . '</form>';