2.11.9-dev
[phpmyadmin/crack.git] / libraries / Config.class.php
blobb8c3bd8afa0f4b47f7ede9e56e0e14a0fa5418c7
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.9-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('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
182 $this->set('PMA_USR_BROWSER_VER', '1.9');
183 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
184 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
185 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
186 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
187 } else {
188 $this->set('PMA_USR_BROWSER_VER', 0);
189 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
194 * Whether GD2 is present
196 function checkGd2()
198 if ($this->get('GD2Available') == 'yes') {
199 $this->set('PMA_IS_GD2', 1);
200 } elseif ($this->get('GD2Available') == 'no') {
201 $this->set('PMA_IS_GD2', 0);
202 } else {
203 if (!@extension_loaded('gd')) {
204 PMA_dl('gd');
206 if (!@function_exists('imagecreatetruecolor')) {
207 $this->set('PMA_IS_GD2', 0);
208 } else {
209 if (@function_exists('gd_info')) {
210 $gd_nfo = gd_info();
211 if (strstr($gd_nfo["GD Version"], '2.')) {
212 $this->set('PMA_IS_GD2', 1);
213 } else {
214 $this->set('PMA_IS_GD2', 0);
216 } else {
217 /* We must do hard way... */
218 ob_start();
219 phpinfo(INFO_MODULES); /* Only modules */
220 $a = strip_tags(ob_get_contents());
221 ob_end_clean();
222 /* Get GD version string from phpinfo output */
223 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
224 if (strstr($v, '2.')) {
225 $this->set('PMA_IS_GD2', 1);
226 } else {
227 $this->set('PMA_IS_GD2', 0);
229 } else {
230 $this->set('PMA_IS_GD2', 0);
238 * Whether the Web server php is running on is IIS
240 function checkWebServer()
242 if (PMA_getenv('SERVER_SOFTWARE')
243 // some versions return Microsoft-IIS, some Microsoft/IIS
244 // we could use a preg_match() but it's slower
245 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
246 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
247 $this->set('PMA_IS_IIS', 1);
248 } else {
249 $this->set('PMA_IS_IIS', 0);
254 * Whether the os php is running on is windows or not
256 function checkWebServerOs()
258 // Default to Unix or Equiv
259 $this->set('PMA_IS_WINDOWS', 0);
260 // If PHP_OS is defined then continue
261 if (defined('PHP_OS')) {
262 if (stristr(PHP_OS, 'win')) {
263 // Is it some version of Windows
264 $this->set('PMA_IS_WINDOWS', 1);
265 } elseif (stristr(PHP_OS, 'OS/2')) {
266 // Is it OS/2 (No file permissions like Windows)
267 $this->set('PMA_IS_WINDOWS', 1);
273 * detects PHP version
275 function checkPhpVersion()
277 $match = array();
278 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
279 phpversion(), $match)) {
280 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
281 phpversion(), $match);
283 if (isset($match) && ! empty($match[1])) {
284 if (! isset($match[2])) {
285 $match[2] = 0;
287 if (! isset($match[3])) {
288 $match[3] = 0;
290 $this->set('PMA_PHP_INT_VERSION',
291 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
292 } else {
293 $this->set('PMA_PHP_INT_VERSION', 0);
295 $this->set('PMA_PHP_STR_VERSION', phpversion());
299 * re-init object after loading from session file
300 * checks config file for changes and relaods if neccessary
302 function __wakeup()
304 if (! $this->checkConfigSource()
305 || $this->source_mtime !== filemtime($this->getSource())
306 || $this->default_source_mtime !== filemtime($this->default_source)
307 || $this->error_config_file
308 || $this->error_config_default_file) {
309 $this->settings = array();
310 $this->load();
311 $this->checkSystem();
314 // check for https needs to be done everytime,
315 // as https and http uses same session so this info can not be stored
316 // in session
317 $this->checkIsHttps();
319 $this->checkCollationConnection();
320 $this->checkFontsize();
324 * loads default values from default source
326 * @uses file_exists()
327 * @uses $this->default_source
328 * @uses $this->error_config_default_file
329 * @uses $this->settings
330 * @return boolean success
332 function loadDefaults()
334 $cfg = array();
335 if (! file_exists($this->default_source)) {
336 $this->error_config_default_file = true;
337 return false;
339 include $this->default_source;
341 $this->default_source_mtime = filemtime($this->default_source);
343 $this->default_server = $cfg['Servers'][1];
344 unset($cfg['Servers']);
346 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
348 $this->error_config_default_file = false;
350 return true;
354 * loads configuration from $source, usally the config file
355 * should be called on object creation and from __wakeup if config file
356 * has changed
358 * @param string $source config file
360 function load($source = null)
362 $this->loadDefaults();
364 if (null !== $source) {
365 $this->setSource($source);
368 if (! $this->checkConfigSource()) {
369 return false;
372 $cfg = array();
375 * Parses the configuration file
377 $old_error_reporting = error_reporting(0);
378 // avoid "headers already sent" error when file contains a BOM
379 ob_start();
380 if (function_exists('file_get_contents')) {
381 $eval_result =
382 eval('?>' . trim(file_get_contents($this->getSource())));
383 } else {
384 $eval_result =
385 eval('?>' . trim(implode("\n", file($this->getSource()))));
387 ob_end_clean();
388 error_reporting($old_error_reporting);
390 if ($eval_result === false) {
391 $this->error_config_file = true;
392 } else {
393 $this->error_config_file = false;
394 $this->source_mtime = filemtime($this->getSource());
398 * Backward compatibility code
400 if (!empty($cfg['DefaultTabTable'])) {
401 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
403 if (!empty($cfg['DefaultTabDatabase'])) {
404 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
407 $this->checkFontsize();
408 //$this->checkPmaAbsoluteUri();
409 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
411 // Handling of the collation must be done after merging of $cfg
412 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
413 // can have an effect. Note that the presence of collation
414 // information in a cookie has priority over what is defined
415 // in the default or user's config files.
417 * @todo check validity of $_COOKIE['pma_collation_connection']
419 if (! empty($_COOKIE['pma_collation_connection'])) {
420 $this->set('collation_connection',
421 strip_tags($_COOKIE['pma_collation_connection']));
422 } else {
423 $this->set('collation_connection',
424 $this->get('DefaultConnectionCollation'));
426 // Now, a collation information could come from REQUEST
427 // (an example of this: the collation selector in main.php)
428 // so the following handles the setting of collation_connection
429 // and later, in common.inc.php, the cookie will be set
430 // according to this.
431 $this->checkCollationConnection();
433 return true;
437 * set source
438 * @param string $source
440 function setSource($source)
442 $this->source = trim($source);
446 * checks if the config folder still exists and terminates app if true
448 function checkConfigFolder()
450 // Refuse to work while there still might be some world writable dir:
451 if (is_dir('./config')) {
452 die('Remove "./config" directory before using phpMyAdmin!');
457 * check config source
459 * @return boolean wether source is valid or not
461 function checkConfigSource()
463 if (! $this->getSource()) {
464 // no configuration file set at all
465 return false;
468 if (! file_exists($this->getSource())) {
469 // do not trigger error here
470 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
472 trigger_error(
473 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
474 E_USER_WARNING);
476 $this->source_mtime = 0;
477 return false;
480 if (! is_readable($this->getSource())) {
481 $this->source_mtime = 0;
482 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
485 // Check for permissions (on platforms that support it):
486 $perms = @fileperms($this->getSource());
487 if (!($perms === false) && ($perms & 2)) {
488 // This check is normally done after loading configuration
489 $this->checkWebServerOs();
490 if ($this->get('PMA_IS_WINDOWS') == 0) {
491 $this->source_mtime = 0;
492 die('Wrong permissions on configuration file, should not be world writable!');
496 return true;
500 * returns specific config setting
501 * @param string $setting
502 * @return mixed value
504 function get($setting)
506 if (isset($this->settings[$setting])) {
507 return $this->settings[$setting];
509 return null;
513 * sets configuration variable
515 * @uses $this->settings
516 * @param string $setting configuration option
517 * @param string $value new value for configuration option
519 function set($setting, $value)
521 if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
522 $this->settings[$setting] = $value;
523 $this->set_mtime = time();
528 * returns source for current config
529 * @return string config source
531 function getSource()
533 return $this->source;
537 * old PHP 4 style constructor
539 * @deprecated
541 function PMA_Config($source = null)
543 $this->__construct($source);
547 * returns a unique value to force a CSS reload if either the config
548 * or the theme changes;
549 * must also check the pma_fontsize cookie in case there is no
550 * config file
551 * @return int Unix timestamp
553 function getThemeUniqueValue()
555 return intval((null !== $_SESSION['PMA_Config']->get('fontsize') ? $_SESSION['PMA_Config']->get('fontsize') : $_COOKIE['pma_fontsize'])) + ($this->source_mtime + $this->default_source_mtime + $_SESSION['PMA_Theme']->mtime_info + $_SESSION['PMA_Theme']->filesize_info);
559 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
560 * set properly and, depending on browsers, inserting or updating a
561 * record might fail
563 function checkPmaAbsoluteUri()
565 // Setup a default value to let the people and lazy syadmins work anyway,
566 // they'll get an error if the autodetect code doesn't work
567 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
568 $is_https = $this->get('is_https');
570 if (strlen($pma_absolute_uri) < 5
571 // needed to catch http/https switch
572 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
573 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
575 $url = array();
577 // At first we try to parse REQUEST_URI, it might contain full URL
578 if (PMA_getenv('REQUEST_URI')) {
579 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
580 if ($url === false) {
581 $url = array('path' => $_SERVER['REQUEST_URI']);
585 // If we don't have scheme, we didn't have full URL so we need to
586 // dig deeper
587 if (empty($url['scheme'])) {
588 // Scheme
589 if (PMA_getenv('HTTP_SCHEME')) {
590 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
591 } else {
592 $url['scheme'] =
593 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
594 ? 'https'
595 : 'http';
598 // Host and port
599 if (PMA_getenv('HTTP_HOST')) {
600 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
601 list($url['host'], $url['port']) =
602 explode(':', PMA_getenv('HTTP_HOST'));
603 } else {
604 $url['host'] = PMA_getenv('HTTP_HOST');
606 } elseif (PMA_getenv('SERVER_NAME')) {
607 $url['host'] = PMA_getenv('SERVER_NAME');
608 } else {
609 $this->error_pma_uri = true;
610 return false;
613 // If we didn't set port yet...
614 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
615 $url['port'] = PMA_getenv('SERVER_PORT');
618 // And finally the path could be already set from REQUEST_URI
619 if (empty($url['path'])) {
620 if (PMA_getenv('PATH_INFO')) {
621 $path = parse_url(PMA_getenv('PATH_INFO'));
622 } else {
623 // PHP_SELF in CGI often points to cgi executable, so use it
624 // as last choice
625 $path = parse_url(PMA_getenv('PHP_SELF'));
627 $url['path'] = $path['path'];
631 // Make url from parts we have
632 $pma_absolute_uri = $url['scheme'] . '://';
633 // Was there user information?
634 if (!empty($url['user'])) {
635 $pma_absolute_uri .= $url['user'];
636 if (!empty($url['pass'])) {
637 $pma_absolute_uri .= ':' . $url['pass'];
639 $pma_absolute_uri .= '@';
641 // Add hostname
642 $pma_absolute_uri .= $url['host'];
643 // Add port, if it not the default one
644 if (! empty($url['port'])
645 && (($url['scheme'] == 'http' && $url['port'] != 80)
646 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
647 $pma_absolute_uri .= ':' . $url['port'];
649 // And finally path, without script name, the 'a' is there not to
650 // strip our directory, when path is only /pmadir/ without filename.
651 // Backslashes returned by Windows have to be changed.
652 // Only replace backslashes by forward slashes if on Windows,
653 // as the backslash could be valid on a non-Windows system.
654 if ($this->get('PMA_IS_WINDOWS') == 1) {
655 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
656 } else {
657 $path = dirname($url['path'] . 'a');
660 // To work correctly within transformations overview:
661 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
662 if ($this->get('PMA_IS_WINDOWS') == 1) {
663 $path = str_replace("\\", "/", dirname(dirname($path)));
664 } else {
665 $path = dirname(dirname($path));
668 // in vhost situations, there could be already an ending slash
669 if (substr($path, -1) != '/') {
670 $path .= '/';
672 $pma_absolute_uri .= $path;
674 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
675 // the autodetect code works well enough that we don't display the
676 // warning at all. The user can still set PmaAbsoluteUri manually.
677 // See
678 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
680 } else {
681 // The URI is specified, however users do often specify this
682 // wrongly, so we try to fix this.
684 // Adds a trailing slash et the end of the phpMyAdmin uri if it
685 // does not exist.
686 if (substr($pma_absolute_uri, -1) != '/') {
687 $pma_absolute_uri .= '/';
690 // If URI doesn't start with http:// or https://, we will add
691 // this.
692 if (substr($pma_absolute_uri, 0, 7) != 'http://'
693 && substr($pma_absolute_uri, 0, 8) != 'https://') {
694 $pma_absolute_uri =
695 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
696 ? 'https'
697 : 'http')
698 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
699 . $pma_absolute_uri;
702 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
706 * check selected collation_connection
707 * @todo check validity of $_REQUEST['collation_connection']
709 function checkCollationConnection()
711 // (could be improved by executing it after the MySQL connection only if
712 // PMA_MYSQL_INT_VERSION >= 40100)
713 if (! empty($_REQUEST['collation_connection'])) {
714 $this->set('collation_connection',
715 strip_tags($_REQUEST['collation_connection']));
720 * checks for font size configuration, and sets font size as requested by user
722 * @uses $_GET
723 * @uses $_POST
724 * @uses $_COOKIE
725 * @uses preg_match()
726 * @uses function_exists()
727 * @uses PMA_Config::set()
728 * @uses PMA_Config::get()
729 * @uses PMA_setCookie()
731 function checkFontsize()
733 $new_fontsize = '';
735 if (isset($_GET['fontsize'])) {
736 $new_fontsize = $_GET['fontsize'];
737 } elseif (isset($_POST['fontsize'])) {
738 $new_fontsize = $_POST['fontsize'];
739 } elseif (isset($_COOKIE['pma_fontsize'])) {
740 $new_fontsize = $_COOKIE['pma_fontsize'];
743 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
744 $this->set('fontsize', $new_fontsize);
745 } elseif (! $this->get('fontsize')) {
746 // 80% would correspond to the default browser font size
747 // of 16, but use 82% to help read the monoface font
748 $this->set('fontsize', '82%');
751 if (function_exists('PMA_setCookie')) {
752 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '82%');
757 * checks if upload is enabled
760 function checkUpload()
762 if (ini_get('file_uploads')) {
763 $this->set('enable_upload', true);
764 // if set "php_admin_value file_uploads Off" in httpd.conf
765 // ini_get() also returns the string "Off" in this case:
766 if ('off' == strtolower(ini_get('file_uploads'))) {
767 $this->set('enable_upload', false);
769 } else {
770 $this->set('enable_upload', false);
775 * Maximum upload size as limited by PHP
776 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
778 * this section generates $max_upload_size in bytes
780 function checkUploadSize()
782 if (! $filesize = ini_get('upload_max_filesize')) {
783 $filesize = "5M";
786 if ($postsize = ini_get('post_max_size')) {
787 $this->set('max_upload_size',
788 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
789 } else {
790 $this->set('max_upload_size', PMA_get_real_size($filesize));
795 * check for https
797 function checkIsHttps()
799 $this->set('is_https', PMA_Config::isHttps());
803 * @static
805 function isHttps()
807 $is_https = false;
809 $url = array();
811 // At first we try to parse REQUEST_URI, it might contain full URL,
812 if (PMA_getenv('REQUEST_URI')) {
813 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
814 if($url === false) {
815 $url = array();
819 // If we don't have scheme, we didn't have full URL so we need to
820 // dig deeper
821 if (empty($url['scheme'])) {
822 // Scheme
823 if (PMA_getenv('HTTP_SCHEME')) {
824 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
825 } else {
826 $url['scheme'] =
827 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
828 ? 'https'
829 : 'http';
833 if (isset($url['scheme'])
834 && $url['scheme'] == 'https') {
835 $is_https = true;
836 } else {
837 $is_https = false;
840 return $is_https;
844 * detect correct cookie path
846 function checkCookiePath()
848 $this->set('cookie_path', PMA_Config::getCookiePath());
852 * @static
854 function getCookiePath()
856 static $cookie_path = null;
858 if (null !== $cookie_path) {
859 return $cookie_path;
862 $url = '';
864 if (PMA_getenv('REQUEST_URI')) {
865 $url = PMA_getenv('REQUEST_URI');
868 // If we don't have path
869 if (empty($url)) {
870 if (PMA_getenv('PATH_INFO')) {
871 $url = PMA_getenv('PATH_INFO');
872 // on IIS with PHP-CGI:
873 } elseif (PMA_getenv('SCRIPT_NAME')) {
874 $url = PMA_getenv('SCRIPT_NAME');
875 } elseif (PMA_getenv('PHP_SELF')) {
876 // PHP_SELF in CGI often points to cgi executable, so use it
877 // as last choice
878 $url = PMA_getenv('PHP_SELF');
882 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
883 if ($parsed_url === false || empty($parsed_url['path'])) {
884 $parsed_url = array('path' => $url);
887 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
889 return $cookie_path;
893 * enables backward compatibility
895 function enableBc()
897 $GLOBALS['cfg'] = $this->settings;
898 $GLOBALS['default_server'] = $this->default_server;
899 unset($this->default_server);
900 $GLOBALS['collation_connection'] = $this->get('collation_connection');
901 $GLOBALS['is_upload'] = $this->get('enable_upload');
902 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
903 $GLOBALS['cookie_path'] = $this->get('cookie_path');
904 $GLOBALS['is_https'] = $this->get('is_https');
906 $defines = array(
907 'PMA_VERSION',
908 'PMA_THEME_VERSION',
909 'PMA_THEME_GENERATION',
910 'PMA_PHP_STR_VERSION',
911 'PMA_PHP_INT_VERSION',
912 'PMA_IS_WINDOWS',
913 'PMA_IS_IIS',
914 'PMA_IS_GD2',
915 'PMA_USR_OS',
916 'PMA_USR_BROWSER_VER',
917 'PMA_USR_BROWSER_AGENT'
920 foreach ($defines as $define) {
921 if (! defined($define)) {
922 define($define, $this->get($define));
928 * @todo finish
930 function save() {}
933 * returns options for font size selection
935 * @uses preg_replace()
936 * @uses ksort()
937 * @static
938 * @param string $current_size current selected font size with unit
939 * @return array selectable font sizes
941 function getFontsizeOptions($current_size = '82%')
943 $unit = preg_replace('/[0-9.]*/', '', $current_size);
944 $value = preg_replace('/[^0-9.]*/', '', $current_size);
946 $factors = array();
947 $options = array();
948 $options["$value"] = $value . $unit;
950 if ($unit === '%') {
951 $factors[] = 1;
952 $factors[] = 5;
953 $factors[] = 10;
954 } elseif ($unit === 'em') {
955 $factors[] = 0.05;
956 $factors[] = 0.2;
957 $factors[] = 1;
958 } elseif ($unit === 'pt') {
959 $factors[] = 0.5;
960 $factors[] = 2;
961 } elseif ($unit === 'px') {
962 $factors[] = 1;
963 $factors[] = 5;
964 $factors[] = 10;
965 } else {
966 //unknown font size unit
967 $factors[] = 0.05;
968 $factors[] = 0.2;
969 $factors[] = 1;
970 $factors[] = 5;
971 $factors[] = 10;
974 foreach ($factors as $key => $factor) {
975 $option_inc = $value + $factor;
976 $option_dec = $value - $factor;
977 while (count($options) < 21) {
978 $options["$option_inc"] = $option_inc . $unit;
979 if ($option_dec > $factors[0]) {
980 $options["$option_dec"] = $option_dec . $unit;
982 $option_inc += $factor;
983 $option_dec -= $factor;
984 if (isset($factors[$key + 1])
985 && $option_inc >= $value + $factors[$key + 1]) {
986 break;
990 ksort($options);
991 return $options;
995 * returns html selectbox for font sizes
997 * @uses $_SESSION['PMA_Config']
998 * @uses PMA_Config::get()
999 * @uses PMA_Config::getFontsizeOptions()
1000 * @uses $GLOBALS['strFontSize']
1001 * @static
1002 * @param string $current_size currently slected font size with unit
1003 * @return string html selectbox
1005 function getFontsizeSelection()
1007 $current_size = $_SESSION['PMA_Config']->get('fontsize');
1008 // for the case when there is no config file (this is supported)
1009 if (empty($current_size)) {
1010 if (isset($_COOKIE['pma_fontsize'])) {
1011 $current_size = $_COOKIE['pma_fontsize'];
1012 } else {
1013 $current_size = '82%';
1016 $options = PMA_Config::getFontsizeOptions($current_size);
1018 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1019 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1020 foreach ($options as $option) {
1021 $return .= '<option value="' . $option . '"';
1022 if ($option == $current_size) {
1023 $return .= ' selected="selected"';
1025 $return .= '>' . $option . '</option>' . "\n";
1027 $return .= '</select>';
1029 return $return;
1033 * return complete font size selection form
1035 * @uses PMA_generate_common_hidden_inputs()
1036 * @uses PMA_Config::getFontsizeSelection()
1037 * @uses $GLOBALS['strGo']
1038 * @static
1039 * @param string $current_size currently slected font size with unit
1040 * @return string html selectbox
1042 function getFontsizeForm()
1044 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1045 . ' method="post" action="index.php" target="_parent">' . "\n"
1046 . PMA_generate_common_hidden_inputs() . "\n"
1047 . PMA_Config::getFontsizeSelection() . "\n"
1048 . '<noscript>' . "\n"
1049 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1050 . '</noscript>' . "\n"
1051 . '</form>';