2.11.6
[phpmyadmin.git] / libraries / Config.class.php
blobf4c461f224b5be9500a87fb815bcfd1df8080480
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
6 * @version $Id$
7 */
9 /**
10 * Configuration class
13 class PMA_Config
15 /**
16 * @var string default config source
18 var $default_source = './libraries/config.default.php';
20 /**
21 * @var array configuration settings
23 var $settings = array();
25 /**
26 * @var string config source
28 var $source = '';
30 /**
31 * @var int source modification time
33 var $source_mtime = 0;
34 var $default_source_mtime = 0;
35 var $set_mtime = 0;
37 /**
38 * @var boolean
40 var $error_config_file = false;
42 /**
43 * @var boolean
45 var $error_config_default_file = false;
47 /**
48 * @var boolean
50 var $error_pma_uri = false;
52 /**
53 * @var array
55 var $default_server = array();
57 /**
58 * @var boolean wether init is done or mot
59 * set this to false to force some initial checks
60 * like checking for required functions
62 var $done = false;
64 /**
65 * constructor
67 * @param string source to read config from
69 function __construct($source = null)
71 $this->settings = array();
73 // functions need to refresh in case of config file changed goes in
74 // PMA_Config::load()
75 $this->load($source);
77 // other settings, independant from config file, comes in
78 $this->checkSystem();
80 $this->checkIsHttps();
83 /**
84 * sets system and application settings
86 function checkSystem()
88 $this->set('PMA_VERSION', '2.11.6');
89 /**
90 * @deprecated
92 $this->set('PMA_THEME_VERSION', 2);
93 /**
94 * @deprecated
96 $this->set('PMA_THEME_GENERATION', 2);
98 $this->checkPhpVersion();
99 $this->checkWebServerOs();
100 $this->checkWebServer();
101 $this->checkGd2();
102 $this->checkClient();
103 $this->checkUpload();
104 $this->checkUploadSize();
105 $this->checkOutputCompression();
109 * wether to use gzip output compression or not
111 function checkOutputCompression()
113 // If zlib output compression is set in the php configuration file, no
114 // output buffering should be run
115 if (@ini_get('zlib.output_compression')) {
116 $this->set('OBGzip', false);
119 // disable output-buffering (if set to 'auto') for IE6, else enable it.
120 if (strtolower($this->get('OBGzip')) == 'auto') {
121 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
122 && $this->get('PMA_USR_BROWSER_VER') >= 6
123 && $this->get('PMA_USR_BROWSER_VER') < 7) {
124 $this->set('OBGzip', false);
125 } else {
126 $this->set('OBGzip', true);
132 * Determines platform (OS), browser and version of the user
133 * Based on a phpBuilder article:
134 * @see http://www.phpbuilder.net/columns/tim20000821.php
136 function checkClient()
138 if (PMA_getenv('HTTP_USER_AGENT')) {
139 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
140 } elseif (!isset($HTTP_USER_AGENT)) {
141 $HTTP_USER_AGENT = '';
144 // 1. Platform
145 if (strstr($HTTP_USER_AGENT, 'Win')) {
146 $this->set('PMA_USR_OS', 'Win');
147 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
148 $this->set('PMA_USR_OS', 'Mac');
149 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
150 $this->set('PMA_USR_OS', 'Linux');
151 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
152 $this->set('PMA_USR_OS', 'Unix');
153 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
154 $this->set('PMA_USR_OS', 'OS/2');
155 } else {
156 $this->set('PMA_USR_OS', 'Other');
159 // 2. browser and version
160 // (must check everything else before Mozilla)
162 if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
163 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
164 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
165 } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
166 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
167 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
168 } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
169 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
170 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
171 //} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
172 // Konqueror 2.2.2 says Konqueror/2.2.2
173 // Konqueror 3.0.3 says Konqueror/3
174 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
175 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
176 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
177 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
178 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
179 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
180 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
181 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
182 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
183 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
184 } else {
185 $this->set('PMA_USR_BROWSER_VER', 0);
186 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
191 * Whether GD2 is present
193 function checkGd2()
195 if ($this->get('GD2Available') == 'yes') {
196 $this->set('PMA_IS_GD2', 1);
197 } elseif ($this->get('GD2Available') == 'no') {
198 $this->set('PMA_IS_GD2', 0);
199 } else {
200 if (!@extension_loaded('gd')) {
201 PMA_dl('gd');
203 if (!@function_exists('imagecreatetruecolor')) {
204 $this->set('PMA_IS_GD2', 0);
205 } else {
206 if (@function_exists('gd_info')) {
207 $gd_nfo = gd_info();
208 if (strstr($gd_nfo["GD Version"], '2.')) {
209 $this->set('PMA_IS_GD2', 1);
210 } else {
211 $this->set('PMA_IS_GD2', 0);
213 } else {
214 /* We must do hard way... */
215 ob_start();
216 phpinfo(INFO_MODULES); /* Only modules */
217 $a = strip_tags(ob_get_contents());
218 ob_end_clean();
219 /* Get GD version string from phpinfo output */
220 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
221 if (strstr($v, '2.')) {
222 $this->set('PMA_IS_GD2', 1);
223 } else {
224 $this->set('PMA_IS_GD2', 0);
226 } else {
227 $this->set('PMA_IS_GD2', 0);
235 * Whether the Web server php is running on is IIS
237 function checkWebServer()
239 if (PMA_getenv('SERVER_SOFTWARE')
240 // some versions return Microsoft-IIS, some Microsoft/IIS
241 // we could use a preg_match() but it's slower
242 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
243 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
244 $this->set('PMA_IS_IIS', 1);
245 } else {
246 $this->set('PMA_IS_IIS', 0);
251 * Whether the os php is running on is windows or not
253 function checkWebServerOs()
255 // Default to Unix or Equiv
256 $this->set('PMA_IS_WINDOWS', 0);
257 // If PHP_OS is defined then continue
258 if (defined('PHP_OS')) {
259 if (stristr(PHP_OS, 'win')) {
260 // Is it some version of Windows
261 $this->set('PMA_IS_WINDOWS', 1);
262 } elseif (stristr(PHP_OS, 'OS/2')) {
263 // Is it OS/2 (No file permissions like Windows)
264 $this->set('PMA_IS_WINDOWS', 1);
270 * detects PHP version
272 function checkPhpVersion()
274 $match = array();
275 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
276 phpversion(), $match)) {
277 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
278 phpversion(), $match);
280 if (isset($match) && ! empty($match[1])) {
281 if (! isset($match[2])) {
282 $match[2] = 0;
284 if (! isset($match[3])) {
285 $match[3] = 0;
287 $this->set('PMA_PHP_INT_VERSION',
288 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
289 } else {
290 $this->set('PMA_PHP_INT_VERSION', 0);
292 $this->set('PMA_PHP_STR_VERSION', phpversion());
296 * re-init object after loading from session file
297 * checks config file for changes and relaods if neccessary
299 function __wakeup()
301 if (! $this->checkConfigSource()
302 || $this->source_mtime !== filemtime($this->getSource())
303 || $this->default_source_mtime !== filemtime($this->default_source)
304 || $this->error_config_file
305 || $this->error_config_default_file) {
306 $this->settings = array();
307 $this->load();
308 $this->checkSystem();
311 // check for https needs to be done everytime,
312 // as https and http uses same session so this info can not be stored
313 // in session
314 $this->checkIsHttps();
316 $this->checkCollationConnection();
317 $this->checkFontsize();
321 * loads default values from default source
323 * @uses file_exists()
324 * @uses $this->default_source
325 * @uses $this->error_config_default_file
326 * @uses $this->settings
327 * @return boolean success
329 function loadDefaults()
331 $cfg = array();
332 if (! file_exists($this->default_source)) {
333 $this->error_config_default_file = true;
334 return false;
336 include $this->default_source;
338 $this->default_source_mtime = filemtime($this->default_source);
340 $this->default_server = $cfg['Servers'][1];
341 unset($cfg['Servers']);
343 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
345 $this->error_config_default_file = false;
347 return true;
351 * loads configuration from $source, usally the config file
352 * should be called on object creation and from __wakeup if config file
353 * has changed
355 * @param string $source config file
357 function load($source = null)
359 $this->loadDefaults();
361 if (null !== $source) {
362 $this->setSource($source);
365 if (! $this->checkConfigSource()) {
366 return false;
369 $cfg = array();
372 * Parses the configuration file
374 $old_error_reporting = error_reporting(0);
375 // avoid "headers already sent" error when file contains a BOM
376 ob_start();
377 if (function_exists('file_get_contents')) {
378 $eval_result =
379 eval('?>' . trim(file_get_contents($this->getSource())));
380 } else {
381 $eval_result =
382 eval('?>' . trim(implode("\n", file($this->getSource()))));
384 ob_end_clean();
385 error_reporting($old_error_reporting);
387 if ($eval_result === false) {
388 $this->error_config_file = true;
389 } else {
390 $this->error_config_file = false;
391 $this->source_mtime = filemtime($this->getSource());
395 * Backward compatibility code
397 if (!empty($cfg['DefaultTabTable'])) {
398 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
400 if (!empty($cfg['DefaultTabDatabase'])) {
401 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
404 $this->checkFontsize();
405 //$this->checkPmaAbsoluteUri();
406 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
408 // Handling of the collation must be done after merging of $cfg
409 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
410 // can have an effect. Note that the presence of collation
411 // information in a cookie has priority over what is defined
412 // in the default or user's config files.
414 * @todo check validity of $_COOKIE['pma_collation_connection']
416 if (! empty($_COOKIE['pma_collation_connection'])) {
417 $this->set('collation_connection',
418 strip_tags($_COOKIE['pma_collation_connection']));
419 } else {
420 $this->set('collation_connection',
421 $this->get('DefaultConnectionCollation'));
423 // Now, a collation information could come from REQUEST
424 // (an example of this: the collation selector in main.php)
425 // so the following handles the setting of collation_connection
426 // and later, in common.inc.php, the cookie will be set
427 // according to this.
428 $this->checkCollationConnection();
430 return true;
434 * set source
435 * @param string $source
437 function setSource($source)
439 $this->source = trim($source);
443 * checks if the config folder still exists and terminates app if true
445 function checkConfigFolder()
447 // Refuse to work while there still might be some world writable dir:
448 if (is_dir('./config')) {
449 die('Remove "./config" directory before using phpMyAdmin!');
454 * check config source
456 * @return boolean wether source is valid or not
458 function checkConfigSource()
460 if (! $this->getSource()) {
461 // no configuration file set at all
462 return false;
465 if (! file_exists($this->getSource())) {
466 // do not trigger error here
467 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
469 trigger_error(
470 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
471 E_USER_WARNING);
473 $this->source_mtime = 0;
474 return false;
477 if (! is_readable($this->getSource())) {
478 $this->source_mtime = 0;
479 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
482 // Check for permissions (on platforms that support it):
483 $perms = @fileperms($this->getSource());
484 if (!($perms === false) && ($perms & 2)) {
485 // This check is normally done after loading configuration
486 $this->checkWebServerOs();
487 if ($this->get('PMA_IS_WINDOWS') == 0) {
488 $this->source_mtime = 0;
489 die('Wrong permissions on configuration file, should not be world writable!');
493 return true;
497 * returns specific config setting
498 * @param string $setting
499 * @return mixed value
501 function get($setting)
503 if (isset($this->settings[$setting])) {
504 return $this->settings[$setting];
506 return null;
510 * sets configuration variable
512 * @uses $this->settings
513 * @param string $setting configuration option
514 * @param string $value new value for configuration option
516 function set($setting, $value)
518 if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
519 $this->settings[$setting] = $value;
520 $this->set_mtime = time();
525 * returns source for current config
526 * @return string config source
528 function getSource()
530 return $this->source;
534 * old PHP 4 style constructor
536 * @deprecated
538 function PMA_Config($source = null)
540 $this->__construct($source);
544 * returns a unique value to force a CSS reload if either the config
545 * or the theme changes
546 * @return int Unix timestamp
548 function getThemeUniqueValue()
550 return intval($_SESSION['PMA_Config']->get('fontsize')) + ($this->source_mtime + $this->default_source_mtime + $_SESSION['PMA_Theme']->mtime_info + $_SESSION['PMA_Theme']->filesize_info);
554 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
555 * set properly and, depending on browsers, inserting or updating a
556 * record might fail
558 function checkPmaAbsoluteUri()
560 // Setup a default value to let the people and lazy syadmins work anyway,
561 // they'll get an error if the autodetect code doesn't work
562 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
563 $is_https = $this->get('is_https');
565 if (strlen($pma_absolute_uri) < 5
566 // needed to catch http/https switch
567 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
568 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
570 $url = array();
572 // At first we try to parse REQUEST_URI, it might contain full URL
573 if (PMA_getenv('REQUEST_URI')) {
574 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
575 if ($url === false) {
576 $url = array('path' => $_SERVER['REQUEST_URI']);
580 // If we don't have scheme, we didn't have full URL so we need to
581 // dig deeper
582 if (empty($url['scheme'])) {
583 // Scheme
584 if (PMA_getenv('HTTP_SCHEME')) {
585 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
586 } else {
587 $url['scheme'] =
588 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
589 ? 'https'
590 : 'http';
593 // Host and port
594 if (PMA_getenv('HTTP_HOST')) {
595 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
596 list($url['host'], $url['port']) =
597 explode(':', PMA_getenv('HTTP_HOST'));
598 } else {
599 $url['host'] = PMA_getenv('HTTP_HOST');
601 } elseif (PMA_getenv('SERVER_NAME')) {
602 $url['host'] = PMA_getenv('SERVER_NAME');
603 } else {
604 $this->error_pma_uri = true;
605 return false;
608 // If we didn't set port yet...
609 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
610 $url['port'] = PMA_getenv('SERVER_PORT');
613 // And finally the path could be already set from REQUEST_URI
614 if (empty($url['path'])) {
615 if (PMA_getenv('PATH_INFO')) {
616 $path = parse_url(PMA_getenv('PATH_INFO'));
617 } else {
618 // PHP_SELF in CGI often points to cgi executable, so use it
619 // as last choice
620 $path = parse_url(PMA_getenv('PHP_SELF'));
622 $url['path'] = $path['path'];
626 // Make url from parts we have
627 $pma_absolute_uri = $url['scheme'] . '://';
628 // Was there user information?
629 if (!empty($url['user'])) {
630 $pma_absolute_uri .= $url['user'];
631 if (!empty($url['pass'])) {
632 $pma_absolute_uri .= ':' . $url['pass'];
634 $pma_absolute_uri .= '@';
636 // Add hostname
637 $pma_absolute_uri .= $url['host'];
638 // Add port, if it not the default one
639 if (! empty($url['port'])
640 && (($url['scheme'] == 'http' && $url['port'] != 80)
641 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
642 $pma_absolute_uri .= ':' . $url['port'];
644 // And finally path, without script name, the 'a' is there not to
645 // strip our directory, when path is only /pmadir/ without filename.
646 // Backslashes returned by Windows have to be changed.
647 // Only replace backslashes by forward slashes if on Windows,
648 // as the backslash could be valid on a non-Windows system.
649 if ($this->get('PMA_IS_WINDOWS') == 1) {
650 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
651 } else {
652 $path = dirname($url['path'] . 'a');
655 // To work correctly within transformations overview:
656 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
657 if ($this->get('PMA_IS_WINDOWS') == 1) {
658 $path = str_replace("\\", "/", dirname(dirname($path)));
659 } else {
660 $path = dirname(dirname($path));
663 // in vhost situations, there could be already an ending slash
664 if (substr($path, -1) != '/') {
665 $path .= '/';
667 $pma_absolute_uri .= $path;
669 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
670 // the autodetect code works well enough that we don't display the
671 // warning at all. The user can still set PmaAbsoluteUri manually.
672 // See
673 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
675 } else {
676 // The URI is specified, however users do often specify this
677 // wrongly, so we try to fix this.
679 // Adds a trailing slash et the end of the phpMyAdmin uri if it
680 // does not exist.
681 if (substr($pma_absolute_uri, -1) != '/') {
682 $pma_absolute_uri .= '/';
685 // If URI doesn't start with http:// or https://, we will add
686 // this.
687 if (substr($pma_absolute_uri, 0, 7) != 'http://'
688 && substr($pma_absolute_uri, 0, 8) != 'https://') {
689 $pma_absolute_uri =
690 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
691 ? 'https'
692 : 'http')
693 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
694 . $pma_absolute_uri;
697 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
701 * check selected collation_connection
702 * @todo check validity of $_REQUEST['collation_connection']
704 function checkCollationConnection()
706 // (could be improved by executing it after the MySQL connection only if
707 // PMA_MYSQL_INT_VERSION >= 40100)
708 if (! empty($_REQUEST['collation_connection'])) {
709 $this->set('collation_connection',
710 strip_tags($_REQUEST['collation_connection']));
715 * checks for font size configuration, and sets font size as requested by user
717 * @uses $_GET
718 * @uses $_POST
719 * @uses $_COOKIE
720 * @uses preg_match()
721 * @uses function_exists()
722 * @uses PMA_Config::set()
723 * @uses PMA_Config::get()
724 * @uses PMA_setCookie()
726 function checkFontsize()
728 $new_fontsize = '';
730 if (isset($_GET['fontsize'])) {
731 $new_fontsize = $_GET['fontsize'];
732 } elseif (isset($_POST['fontsize'])) {
733 $new_fontsize = $_POST['fontsize'];
734 } elseif (isset($_COOKIE['pma_fontsize'])) {
735 $new_fontsize = $_COOKIE['pma_fontsize'];
738 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
739 $this->set('fontsize', $new_fontsize);
740 } elseif (! $this->get('fontsize')) {
741 // 80% would correspond to the default browser font size
742 // of 16, but use 82% to help read the monoface font
743 $this->set('fontsize', '82%');
746 if (function_exists('PMA_setCookie')) {
747 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '82%');
752 * checks if upload is enabled
755 function checkUpload()
757 if (ini_get('file_uploads')) {
758 $this->set('enable_upload', true);
759 // if set "php_admin_value file_uploads Off" in httpd.conf
760 // ini_get() also returns the string "Off" in this case:
761 if ('off' == strtolower(ini_get('file_uploads'))) {
762 $this->set('enable_upload', false);
764 } else {
765 $this->set('enable_upload', false);
770 * Maximum upload size as limited by PHP
771 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
773 * this section generates $max_upload_size in bytes
775 function checkUploadSize()
777 if (! $filesize = ini_get('upload_max_filesize')) {
778 $filesize = "5M";
781 if ($postsize = ini_get('post_max_size')) {
782 $this->set('max_upload_size',
783 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
784 } else {
785 $this->set('max_upload_size', PMA_get_real_size($filesize));
790 * check for https
792 function checkIsHttps()
794 $this->set('is_https', PMA_Config::isHttps());
798 * @static
800 function isHttps()
802 $is_https = false;
804 $url = array();
806 // At first we try to parse REQUEST_URI, it might contain full URL,
807 if (PMA_getenv('REQUEST_URI')) {
808 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
809 if($url === false) {
810 $url = array();
814 // If we don't have scheme, we didn't have full URL so we need to
815 // dig deeper
816 if (empty($url['scheme'])) {
817 // Scheme
818 if (PMA_getenv('HTTP_SCHEME')) {
819 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
820 } else {
821 $url['scheme'] =
822 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
823 ? 'https'
824 : 'http';
828 if (isset($url['scheme'])
829 && $url['scheme'] == 'https') {
830 $is_https = true;
831 } else {
832 $is_https = false;
835 return $is_https;
839 * detect correct cookie path
841 function checkCookiePath()
843 $this->set('cookie_path', PMA_Config::getCookiePath());
847 * @static
849 function getCookiePath()
851 static $cookie_path = null;
853 if (null !== $cookie_path) {
854 return $cookie_path;
857 $url = '';
859 if (PMA_getenv('REQUEST_URI')) {
860 $url = PMA_getenv('REQUEST_URI');
863 // If we don't have path
864 if (empty($url)) {
865 if (PMA_getenv('PATH_INFO')) {
866 $url = PMA_getenv('PATH_INFO');
867 // on IIS with PHP-CGI:
868 } elseif (PMA_getenv('SCRIPT_NAME')) {
869 $url = PMA_getenv('SCRIPT_NAME');
870 } elseif (PMA_getenv('PHP_SELF')) {
871 // PHP_SELF in CGI often points to cgi executable, so use it
872 // as last choice
873 $url = PMA_getenv('PHP_SELF');
877 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
878 if ($parsed_url === false || empty($parsed_url['path'])) {
879 $parsed_url = array('path' => $url);
882 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
884 return $cookie_path;
888 * enables backward compatibility
890 function enableBc()
892 $GLOBALS['cfg'] = $this->settings;
893 $GLOBALS['default_server'] = $this->default_server;
894 unset($this->default_server);
895 $GLOBALS['collation_connection'] = $this->get('collation_connection');
896 $GLOBALS['is_upload'] = $this->get('enable_upload');
897 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
898 $GLOBALS['cookie_path'] = $this->get('cookie_path');
899 $GLOBALS['is_https'] = $this->get('is_https');
901 $defines = array(
902 'PMA_VERSION',
903 'PMA_THEME_VERSION',
904 'PMA_THEME_GENERATION',
905 'PMA_PHP_STR_VERSION',
906 'PMA_PHP_INT_VERSION',
907 'PMA_IS_WINDOWS',
908 'PMA_IS_IIS',
909 'PMA_IS_GD2',
910 'PMA_USR_OS',
911 'PMA_USR_BROWSER_VER',
912 'PMA_USR_BROWSER_AGENT'
915 foreach ($defines as $define) {
916 if (! defined($define)) {
917 define($define, $this->get($define));
923 * @todo finish
925 function save() {}
928 * returns options for font size selection
930 * @uses preg_replace()
931 * @uses ksort()
932 * @static
933 * @param string $current_size current selected font size with unit
934 * @return array selectable font sizes
936 function getFontsizeOptions($current_size = '82%')
938 $unit = preg_replace('/[0-9.]*/', '', $current_size);
939 $value = preg_replace('/[^0-9.]*/', '', $current_size);
941 $factors = array();
942 $options = array();
943 $options["$value"] = $value . $unit;
945 if ($unit === '%') {
946 $factors[] = 1;
947 $factors[] = 5;
948 $factors[] = 10;
949 } elseif ($unit === 'em') {
950 $factors[] = 0.05;
951 $factors[] = 0.2;
952 $factors[] = 1;
953 } elseif ($unit === 'pt') {
954 $factors[] = 0.5;
955 $factors[] = 2;
956 } elseif ($unit === 'px') {
957 $factors[] = 1;
958 $factors[] = 5;
959 $factors[] = 10;
960 } else {
961 //unknown font size unit
962 $factors[] = 0.05;
963 $factors[] = 0.2;
964 $factors[] = 1;
965 $factors[] = 5;
966 $factors[] = 10;
969 foreach ($factors as $key => $factor) {
970 $option_inc = $value + $factor;
971 $option_dec = $value - $factor;
972 while (count($options) < 21) {
973 $options["$option_inc"] = $option_inc . $unit;
974 if ($option_dec > $factors[0]) {
975 $options["$option_dec"] = $option_dec . $unit;
977 $option_inc += $factor;
978 $option_dec -= $factor;
979 if (isset($factors[$key + 1])
980 && $option_inc >= $value + $factors[$key + 1]) {
981 break;
985 ksort($options);
986 return $options;
990 * returns html selectbox for font sizes
992 * @uses $_SESSION['PMA_Config']
993 * @uses PMA_Config::get()
994 * @uses PMA_Config::getFontsizeOptions()
995 * @uses $GLOBALS['strFontSize']
996 * @static
997 * @param string $current_size currently slected font size with unit
998 * @return string html selectbox
1000 function getFontsizeSelection()
1002 $current_size = $_SESSION['PMA_Config']->get('fontsize');
1003 $options = PMA_Config::getFontsizeOptions($current_size);
1005 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1006 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1007 foreach ($options as $option) {
1008 $return .= '<option value="' . $option . '"';
1009 if ($option == $current_size) {
1010 $return .= ' selected="selected"';
1012 $return .= '>' . $option . '</option>' . "\n";
1014 $return .= '</select>';
1016 return $return;
1020 * return complete font size selection form
1022 * @uses PMA_generate_common_hidden_inputs()
1023 * @uses PMA_Config::getFontsizeSelection()
1024 * @uses $GLOBALS['strGo']
1025 * @static
1026 * @param string $current_size currently slected font size with unit
1027 * @return string html selectbox
1029 function getFontsizeForm()
1031 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1032 . ' method="post" action="index.php" target="_parent">' . "\n"
1033 . PMA_generate_common_hidden_inputs() . "\n"
1034 . PMA_Config::getFontsizeSelection() . "\n"
1035 . '<noscript>' . "\n"
1036 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1037 . '</noscript>' . "\n"
1038 . '</form>';