bug #1817612 [cookies] Wrong cookie path on IIS with PHP-CGI
[phpmyadmin/crack.git] / libraries / Config.class.php
blob42284a49175ff12ae16975d2e4a1cd9f5aea4f5d
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.4-dev');
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 if (function_exists('file_get_contents')) {
376 $eval_result =
377 eval('?>' . trim(file_get_contents($this->getSource())));
378 } else {
379 $eval_result =
380 eval('?>' . trim(implode("\n", file($this->getSource()))));
382 error_reporting($old_error_reporting);
384 if ($eval_result === false) {
385 $this->error_config_file = true;
386 } else {
387 $this->error_config_file = false;
388 $this->source_mtime = filemtime($this->getSource());
392 * Backward compatibility code
394 if (!empty($cfg['DefaultTabTable'])) {
395 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
397 if (!empty($cfg['DefaultTabDatabase'])) {
398 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
401 $this->checkFontsize();
402 //$this->checkPmaAbsoluteUri();
403 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
405 // Handling of the collation must be done after merging of $cfg
406 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
407 // can have an effect. Note that the presence of collation
408 // information in a cookie has priority over what is defined
409 // in the default or user's config files.
411 * @todo check validity of $_COOKIE['pma_collation_connection']
413 if (! empty($_COOKIE['pma_collation_connection'])) {
414 $this->set('collation_connection',
415 strip_tags($_COOKIE['pma_collation_connection']));
416 } else {
417 $this->set('collation_connection',
418 $this->get('DefaultConnectionCollation'));
420 // Now, a collation information could come from REQUEST
421 // (an example of this: the collation selector in main.php)
422 // so the following handles the setting of collation_connection
423 // and later, in common.inc.php, the cookie will be set
424 // according to this.
425 $this->checkCollationConnection();
427 return true;
431 * set source
432 * @param string $source
434 function setSource($source)
436 $this->source = trim($source);
440 * checks if the config folder still exists and terminates app if true
442 function checkConfigFolder()
444 // Refuse to work while there still might be some world writable dir:
445 if (is_dir('./config')) {
446 die('Remove "./config" directory before using phpMyAdmin!');
451 * check config source
453 * @return boolean wether source is valid or not
455 function checkConfigSource()
457 if (! $this->getSource()) {
458 // no configuration file set at all
459 return false;
462 if (! file_exists($this->getSource())) {
463 // do not trigger error here
464 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
466 trigger_error(
467 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
468 E_USER_WARNING);
470 $this->source_mtime = 0;
471 return false;
474 if (! is_readable($this->getSource())) {
475 $this->source_mtime = 0;
476 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
479 // Check for permissions (on platforms that support it):
480 $perms = @fileperms($this->getSource());
481 if (!($perms === false) && ($perms & 2)) {
482 // This check is normally done after loading configuration
483 $this->checkWebServerOs();
484 if ($this->get('PMA_IS_WINDOWS') == 0) {
485 $this->source_mtime = 0;
486 die('Wrong permissions on configuration file, should not be world writable!');
490 return true;
494 * returns specific config setting
495 * @param string $setting
496 * @return mixed value
498 function get($setting)
500 if (isset($this->settings[$setting])) {
501 return $this->settings[$setting];
503 return null;
507 * sets configuration variable
509 * @uses $this->settings
510 * @param string $setting configuration option
511 * @param string $value new value for configuration option
513 function set($setting, $value)
515 if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
516 $this->settings[$setting] = $value;
517 $this->set_mtime = time();
522 * returns source for current config
523 * @return string config source
525 function getSource()
527 return $this->source;
531 * old PHP 4 style constructor
533 * @deprecated
535 function PMA_Config($source = null)
537 $this->__construct($source);
541 * returns a unique value to force a CSS reload if either the config
542 * or the theme changes
543 * @return int Unix timestamp
545 function getMtime()
547 return intval($_SESSION['PMA_Config']->get('fontsize')) + ($this->source_mtime + $this->default_source_mtime + $_SESSION['PMA_Theme']->mtime_info);
551 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
552 * set properly and, depending on browsers, inserting or updating a
553 * record might fail
555 function checkPmaAbsoluteUri()
557 // Setup a default value to let the people and lazy syadmins work anyway,
558 // they'll get an error if the autodetect code doesn't work
559 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
560 $is_https = $this->get('is_https');
562 if (strlen($pma_absolute_uri) < 5
563 // needed to catch http/https switch
564 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
565 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
567 $url = array();
569 // At first we try to parse REQUEST_URI, it might contain full URL
570 if (PMA_getenv('REQUEST_URI')) {
571 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
572 if ($url === false) {
573 $url = array('path' => $_SERVER['REQUEST_URI']);
577 // If we don't have scheme, we didn't have full URL so we need to
578 // dig deeper
579 if (empty($url['scheme'])) {
580 // Scheme
581 if (PMA_getenv('HTTP_SCHEME')) {
582 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
583 } else {
584 $url['scheme'] =
585 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
586 ? 'https'
587 : 'http';
590 // Host and port
591 if (PMA_getenv('HTTP_HOST')) {
592 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
593 list($url['host'], $url['port']) =
594 explode(':', PMA_getenv('HTTP_HOST'));
595 } else {
596 $url['host'] = PMA_getenv('HTTP_HOST');
598 } elseif (PMA_getenv('SERVER_NAME')) {
599 $url['host'] = PMA_getenv('SERVER_NAME');
600 } else {
601 $this->error_pma_uri = true;
602 return false;
605 // If we didn't set port yet...
606 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
607 $url['port'] = PMA_getenv('SERVER_PORT');
610 // And finally the path could be already set from REQUEST_URI
611 if (empty($url['path'])) {
612 if (PMA_getenv('PATH_INFO')) {
613 $path = parse_url(PMA_getenv('PATH_INFO'));
614 } else {
615 // PHP_SELF in CGI often points to cgi executable, so use it
616 // as last choice
617 $path = parse_url(PMA_getenv('PHP_SELF'));
619 $url['path'] = $path['path'];
623 // Make url from parts we have
624 $pma_absolute_uri = $url['scheme'] . '://';
625 // Was there user information?
626 if (!empty($url['user'])) {
627 $pma_absolute_uri .= $url['user'];
628 if (!empty($url['pass'])) {
629 $pma_absolute_uri .= ':' . $url['pass'];
631 $pma_absolute_uri .= '@';
633 // Add hostname
634 $pma_absolute_uri .= $url['host'];
635 // Add port, if it not the default one
636 if (! empty($url['port'])
637 && (($url['scheme'] == 'http' && $url['port'] != 80)
638 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
639 $pma_absolute_uri .= ':' . $url['port'];
641 // And finally path, without script name, the 'a' is there not to
642 // strip our directory, when path is only /pmadir/ without filename.
643 // Backslashes returned by Windows have to be changed.
644 // Only replace backslashes by forward slashes if on Windows,
645 // as the backslash could be valid on a non-Windows system.
646 if ($this->get('PMA_IS_WINDOWS') == 1) {
647 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
648 } else {
649 $path = dirname($url['path'] . 'a');
652 // To work correctly within transformations overview:
653 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
654 if ($this->get('PMA_IS_WINDOWS') == 1) {
655 $path = str_replace("\\", "/", dirname(dirname($path)));
656 } else {
657 $path = dirname(dirname($path));
660 // in vhost situations, there could be already an ending slash
661 if (substr($path, -1) != '/') {
662 $path .= '/';
664 $pma_absolute_uri .= $path;
666 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
667 // the autodetect code works well enough that we don't display the
668 // warning at all. The user can still set PmaAbsoluteUri manually.
669 // See
670 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
672 } else {
673 // The URI is specified, however users do often specify this
674 // wrongly, so we try to fix this.
676 // Adds a trailing slash et the end of the phpMyAdmin uri if it
677 // does not exist.
678 if (substr($pma_absolute_uri, -1) != '/') {
679 $pma_absolute_uri .= '/';
682 // If URI doesn't start with http:// or https://, we will add
683 // this.
684 if (substr($pma_absolute_uri, 0, 7) != 'http://'
685 && substr($pma_absolute_uri, 0, 8) != 'https://') {
686 $pma_absolute_uri =
687 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
688 ? 'https'
689 : 'http')
690 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
691 . $pma_absolute_uri;
694 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
698 * check selected collation_connection
699 * @todo check validity of $_REQUEST['collation_connection']
701 function checkCollationConnection()
703 // (could be improved by executing it after the MySQL connection only if
704 // PMA_MYSQL_INT_VERSION >= 40100)
705 if (! empty($_REQUEST['collation_connection'])) {
706 $this->set('collation_connection',
707 strip_tags($_REQUEST['collation_connection']));
712 * checks for font size configuration, and sets font size as requested by user
714 * @uses $_GET
715 * @uses $_POST
716 * @uses $_COOKIE
717 * @uses preg_match()
718 * @uses function_exists()
719 * @uses PMA_Config::set()
720 * @uses PMA_Config::get()
721 * @uses PMA_setCookie()
723 function checkFontsize()
725 $new_fontsize = '';
727 if (isset($_GET['fontsize'])) {
728 $new_fontsize = $_GET['fontsize'];
729 } elseif (isset($_POST['fontsize'])) {
730 $new_fontsize = $_POST['fontsize'];
731 } elseif (isset($_COOKIE['pma_fontsize'])) {
732 $new_fontsize = $_COOKIE['pma_fontsize'];
735 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
736 $this->set('fontsize', $new_fontsize);
737 } elseif (! $this->get('fontsize')) {
738 // 80% would correspond to the default browser font size
739 // of 16, but use 82% to help read the monoface font
740 $this->set('fontsize', '82%');
743 if (function_exists('PMA_setCookie')) {
744 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '82%');
749 * checks if upload is enabled
752 function checkUpload()
754 if (ini_get('file_uploads')) {
755 $this->set('enable_upload', true);
756 // if set "php_admin_value file_uploads Off" in httpd.conf
757 // ini_get() also returns the string "Off" in this case:
758 if ('off' == strtolower(ini_get('file_uploads'))) {
759 $this->set('enable_upload', false);
761 } else {
762 $this->set('enable_upload', false);
767 * Maximum upload size as limited by PHP
768 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
770 * this section generates $max_upload_size in bytes
772 function checkUploadSize()
774 if (! $filesize = ini_get('upload_max_filesize')) {
775 $filesize = "5M";
778 if ($postsize = ini_get('post_max_size')) {
779 $this->set('max_upload_size',
780 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
781 } else {
782 $this->set('max_upload_size', PMA_get_real_size($filesize));
787 * check for https
789 function checkIsHttps()
791 $this->set('is_https', PMA_Config::isHttps());
795 * @static
797 function isHttps()
799 $is_https = false;
801 $url = array();
803 // At first we try to parse REQUEST_URI, it might contain full URL,
804 if (PMA_getenv('REQUEST_URI')) {
805 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
806 if($url === false) {
807 $url = array();
811 // If we don't have scheme, we didn't have full URL so we need to
812 // dig deeper
813 if (empty($url['scheme'])) {
814 // Scheme
815 if (PMA_getenv('HTTP_SCHEME')) {
816 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
817 } else {
818 $url['scheme'] =
819 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
820 ? 'https'
821 : 'http';
825 if (isset($url['scheme'])
826 && $url['scheme'] == 'https') {
827 $is_https = true;
828 } else {
829 $is_https = false;
832 return $is_https;
836 * detect correct cookie path
838 function checkCookiePath()
840 $this->set('cookie_path', PMA_Config::getCookiePath());
844 * @static
846 function getCookiePath()
848 static $cookie_path = null;
850 if (null !== $cookie_path) {
851 return $cookie_path;
854 $url = '';
856 if (PMA_getenv('REQUEST_URI')) {
857 $url = PMA_getenv('REQUEST_URI');
860 // If we don't have path
861 if (empty($url)) {
862 if (PMA_getenv('PATH_INFO')) {
863 $url = PMA_getenv('PATH_INFO');
864 // on IIS with PHP-CGI:
865 } elseif (PMA_getenv('SCRIPT_NAME')) {
866 $url = PMA_getenv('SCRIPT_NAME');
867 } elseif (PMA_getenv('PHP_SELF')) {
868 // PHP_SELF in CGI often points to cgi executable, so use it
869 // as last choice
870 $url = PMA_getenv('PHP_SELF');
874 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
875 if ($parsed_url === false || empty($parsed_url['path'])) {
876 $parsed_url = array('path' => $url);
879 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
881 return $cookie_path;
885 * enables backward compatibility
887 function enableBc()
889 $GLOBALS['cfg'] =& $this->settings;
890 $GLOBALS['default_server'] =& $this->default_server;
891 $GLOBALS['collation_connection'] = $this->get('collation_connection');
892 $GLOBALS['is_upload'] = $this->get('enable_upload');
893 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
894 $GLOBALS['cookie_path'] = $this->get('cookie_path');
895 $GLOBALS['is_https'] = $this->get('is_https');
897 $defines = array(
898 'PMA_VERSION',
899 'PMA_THEME_VERSION',
900 'PMA_THEME_GENERATION',
901 'PMA_PHP_STR_VERSION',
902 'PMA_PHP_INT_VERSION',
903 'PMA_IS_WINDOWS',
904 'PMA_IS_IIS',
905 'PMA_IS_GD2',
906 'PMA_USR_OS',
907 'PMA_USR_BROWSER_VER',
908 'PMA_USR_BROWSER_AGENT'
911 foreach ($defines as $define) {
912 if (! defined($define)) {
913 define($define, $this->get($define));
919 * @todo finish
921 function save() {}
924 * returns options for font size selection
926 * @uses preg_replace()
927 * @uses ksort()
928 * @static
929 * @param string $current_size current selected font size with unit
930 * @return array selectable font sizes
932 function getFontsizeOptions($current_size = '82%')
934 $unit = preg_replace('/[0-9.]*/', '', $current_size);
935 $value = preg_replace('/[^0-9.]*/', '', $current_size);
937 $factors = array();
938 $options = array();
939 $options["$value"] = $value . $unit;
941 if ($unit === '%') {
942 $factors[] = 1;
943 $factors[] = 5;
944 $factors[] = 10;
945 } elseif ($unit === 'em') {
946 $factors[] = 0.05;
947 $factors[] = 0.2;
948 $factors[] = 1;
949 } elseif ($unit === 'pt') {
950 $factors[] = 0.5;
951 $factors[] = 2;
952 } elseif ($unit === 'px') {
953 $factors[] = 1;
954 $factors[] = 5;
955 $factors[] = 10;
956 } else {
957 //unknown font size unit
958 $factors[] = 0.05;
959 $factors[] = 0.2;
960 $factors[] = 1;
961 $factors[] = 5;
962 $factors[] = 10;
965 foreach ($factors as $key => $factor) {
966 $option_inc = $value + $factor;
967 $option_dec = $value - $factor;
968 while (count($options) < 21) {
969 $options["$option_inc"] = $option_inc . $unit;
970 if ($option_dec > $factors[0]) {
971 $options["$option_dec"] = $option_dec . $unit;
973 $option_inc += $factor;
974 $option_dec -= $factor;
975 if (isset($factors[$key + 1])
976 && $option_inc >= $value + $factors[$key + 1]) {
977 break;
981 ksort($options);
982 return $options;
986 * returns html selectbox for font sizes
988 * @uses $_SESSION['PMA_Config']
989 * @uses PMA_Config::get()
990 * @uses PMA_Config::getFontsizeOptions()
991 * @uses $GLOBALS['strFontSize']
992 * @static
993 * @param string $current_size currently slected font size with unit
994 * @return string html selectbox
996 function getFontsizeSelection()
998 $current_size = $_SESSION['PMA_Config']->get('fontsize');
999 $options = PMA_Config::getFontsizeOptions($current_size);
1001 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1002 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1003 foreach ($options as $option) {
1004 $return .= '<option value="' . $option . '"';
1005 if ($option == $current_size) {
1006 $return .= ' selected="selected"';
1008 $return .= '>' . $option . '</option>' . "\n";
1010 $return .= '</select>';
1012 return $return;
1016 * return complete font size selection form
1018 * @uses PMA_generate_common_hidden_inputs()
1019 * @uses PMA_Config::getFontsizeSelection()
1020 * @uses $GLOBALS['strGo']
1021 * @static
1022 * @param string $current_size currently slected font size with unit
1023 * @return string html selectbox
1025 function getFontsizeForm()
1027 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1028 . ' method="post" action="index.php" target="_parent">' . "\n"
1029 . PMA_generate_common_hidden_inputs() . "\n"
1030 . PMA_Config::getFontsizeSelection() . "\n"
1031 . '<noscript>' . "\n"
1032 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1033 . '</noscript>' . "\n"
1034 . '</form>';