3.1.3.1
[phpmyadmin/crack.git] / libraries / Config.class.php
blob6045fad78bfbc5e3adcf1173dd824fba351afe81
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 whether init is done or not
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, independent 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', '3.1.3.1');
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 * whether 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 // Konqueror 2.2.2 says Konqueror/2.2.2
172 // Konqueror 3.0.3 says Konqueror/3
173 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
174 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
175 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
176 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
177 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
178 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
179 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
180 } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
181 $this->set('PMA_USR_BROWSER_VER', '1.9');
182 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
183 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
184 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
185 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
186 } else {
187 $this->set('PMA_USR_BROWSER_VER', 0);
188 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
193 * Whether GD2 is present
195 function checkGd2()
197 if ($this->get('GD2Available') == 'yes') {
198 $this->set('PMA_IS_GD2', 1);
199 } elseif ($this->get('GD2Available') == 'no') {
200 $this->set('PMA_IS_GD2', 0);
201 } else {
202 if (!@function_exists('imagecreatetruecolor')) {
203 $this->set('PMA_IS_GD2', 0);
204 } else {
205 if (@function_exists('gd_info')) {
206 $gd_nfo = gd_info();
207 if (strstr($gd_nfo["GD Version"], '2.')) {
208 $this->set('PMA_IS_GD2', 1);
209 } else {
210 $this->set('PMA_IS_GD2', 0);
212 } else {
213 /* We must do hard way... but almost no chance to execute this */
214 ob_start();
215 phpinfo(INFO_MODULES); /* Only modules */
216 $a = strip_tags(ob_get_contents());
217 ob_end_clean();
218 /* Get GD version string from phpinfo output */
219 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
220 if (strstr($v, '2.')) {
221 $this->set('PMA_IS_GD2', 1);
222 } else {
223 $this->set('PMA_IS_GD2', 0);
225 } else {
226 $this->set('PMA_IS_GD2', 0);
234 * Whether the Web server php is running on is IIS
236 function checkWebServer()
238 if (PMA_getenv('SERVER_SOFTWARE')
239 // some versions return Microsoft-IIS, some Microsoft/IIS
240 // we could use a preg_match() but it's slower
241 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
242 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
243 $this->set('PMA_IS_IIS', 1);
244 } else {
245 $this->set('PMA_IS_IIS', 0);
250 * Whether the os php is running on is windows or not
252 function checkWebServerOs()
254 // Default to Unix or Equiv
255 $this->set('PMA_IS_WINDOWS', 0);
256 // If PHP_OS is defined then continue
257 if (defined('PHP_OS')) {
258 if (stristr(PHP_OS, 'win')) {
259 // Is it some version of Windows
260 $this->set('PMA_IS_WINDOWS', 1);
261 } elseif (stristr(PHP_OS, 'OS/2')) {
262 // Is it OS/2 (No file permissions like Windows)
263 $this->set('PMA_IS_WINDOWS', 1);
269 * detects PHP version
271 function checkPhpVersion()
273 $match = array();
274 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
275 phpversion(), $match)) {
276 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
277 phpversion(), $match);
279 if (isset($match) && ! empty($match[1])) {
280 if (! isset($match[2])) {
281 $match[2] = 0;
283 if (! isset($match[3])) {
284 $match[3] = 0;
286 $this->set('PMA_PHP_INT_VERSION',
287 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
288 } else {
289 $this->set('PMA_PHP_INT_VERSION', 0);
291 $this->set('PMA_PHP_STR_VERSION', phpversion());
295 * re-init object after loading from session file
296 * checks config file for changes and relaods if neccessary
298 function __wakeup()
300 if (! $this->checkConfigSource()
301 || $this->source_mtime !== filemtime($this->getSource())
302 || $this->default_source_mtime !== filemtime($this->default_source)
303 || $this->error_config_file
304 || $this->error_config_default_file) {
305 $this->settings = array();
306 $this->load();
307 $this->checkSystem();
310 // check for https needs to be done everytime,
311 // as https and http uses same session so this info can not be stored
312 // in session
313 $this->checkIsHttps();
315 $this->checkCollationConnection();
316 $this->checkFontsize();
320 * loads default values from default source
322 * @uses file_exists()
323 * @uses $this->default_source
324 * @uses $this->error_config_default_file
325 * @uses $this->settings
326 * @return boolean success
328 function loadDefaults()
330 $cfg = array();
331 if (! file_exists($this->default_source)) {
332 $this->error_config_default_file = true;
333 return false;
335 include $this->default_source;
337 $this->default_source_mtime = filemtime($this->default_source);
339 $this->default_server = $cfg['Servers'][1];
340 unset($cfg['Servers']);
342 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
344 $this->error_config_default_file = false;
346 return true;
350 * loads configuration from $source, usally the config file
351 * should be called on object creation and from __wakeup if config file
352 * has changed
354 * @param string $source config file
356 function load($source = null)
358 $this->loadDefaults();
360 if (null !== $source) {
361 $this->setSource($source);
364 if (! $this->checkConfigSource()) {
365 return false;
368 $cfg = array();
371 * Parses the configuration file
373 $old_error_reporting = error_reporting(0);
374 if (function_exists('file_get_contents')) {
375 $eval_result =
376 eval('?>' . trim(file_get_contents($this->getSource())));
377 } else {
378 $eval_result =
379 eval('?>' . trim(implode("\n", file($this->getSource()))));
381 error_reporting($old_error_reporting);
383 if ($eval_result === false) {
384 $this->error_config_file = true;
385 } else {
386 $this->error_config_file = false;
387 $this->source_mtime = filemtime($this->getSource());
391 * Backward compatibility code
393 if (!empty($cfg['DefaultTabTable'])) {
394 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
396 if (!empty($cfg['DefaultTabDatabase'])) {
397 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
400 $this->checkFontsize();
401 //$this->checkPmaAbsoluteUri();
402 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
404 // Handling of the collation must be done after merging of $cfg
405 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
406 // can have an effect. Note that the presence of collation
407 // information in a cookie has priority over what is defined
408 // in the default or user's config files.
410 * @todo check validity of $_COOKIE['pma_collation_connection']
412 if (! empty($_COOKIE['pma_collation_connection'])) {
413 $this->set('collation_connection',
414 strip_tags($_COOKIE['pma_collation_connection']));
415 } else {
416 $this->set('collation_connection',
417 $this->get('DefaultConnectionCollation'));
419 // Now, a collation information could come from REQUEST
420 // (an example of this: the collation selector in main.php)
421 // so the following handles the setting of collation_connection
422 // and later, in common.inc.php, the cookie will be set
423 // according to this.
424 $this->checkCollationConnection();
426 return true;
430 * set source
431 * @param string $source
433 function setSource($source)
435 $this->source = trim($source);
439 * checks if the config folder still exists and terminates app if true
441 function checkConfigFolder()
443 // Refuse to work while there still might be some world writable dir:
444 if (is_dir('./config')) {
445 die('Remove "./config" directory before using phpMyAdmin!');
450 * check config source
452 * @return boolean whether source is valid or not
454 function checkConfigSource()
456 if (! $this->getSource()) {
457 // no configuration file set at all
458 return false;
461 if (! file_exists($this->getSource())) {
462 // do not trigger error here
463 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
465 trigger_error(
466 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
467 E_USER_WARNING);
469 $this->source_mtime = 0;
470 return false;
473 if (! is_readable($this->getSource())) {
474 $this->source_mtime = 0;
475 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
478 // Check for permissions (on platforms that support it):
479 if ($this->get('CheckConfigurationPermissions')) {
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!');
491 return true;
495 * returns specific config setting
496 * @param string $setting
497 * @return mixed value
499 function get($setting)
501 if (isset($this->settings[$setting])) {
502 return $this->settings[$setting];
504 return null;
508 * sets configuration variable
510 * @uses $this->settings
511 * @param string $setting configuration option
512 * @param string $value new value for configuration option
514 function set($setting, $value)
516 if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
517 $this->settings[$setting] = $value;
518 $this->set_mtime = time();
523 * returns source for current config
524 * @return string config source
526 function getSource()
528 return $this->source;
532 * returns a unique value to force a CSS reload if either the config
533 * or the theme changes
534 * must also check the pma_fontsize cookie in case there is no
535 * config file
536 * @return int Unix timestamp
538 function getThemeUniqueValue()
540 return intval((null !== $_SESSION['PMA_Config']->get('fontsize') ? $_SESSION['PMA_Config']->get('fontsize') : (isset($_COOKIE['pma_fontsize']) ? $_COOKIE['pma_fontsize'] : 0))) + ($this->source_mtime + $this->default_source_mtime + $_SESSION['PMA_Theme']->mtime_info + $_SESSION['PMA_Theme']->filesize_info) . (isset($_SESSION['userconf']['custom_color']) ? substr($_SESSION['userconf']['custom_color'],1,6) : '');
544 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
545 * set properly and, depending on browsers, inserting or updating a
546 * record might fail
548 function checkPmaAbsoluteUri()
550 // Setup a default value to let the people and lazy sysadmins work anyway,
551 // they'll get an error if the autodetect code doesn't work
552 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
553 $is_https = $this->get('is_https');
555 if (strlen($pma_absolute_uri) < 5
556 // needed to catch http/https switch
557 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
558 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
560 $url = array();
562 // At first we try to parse REQUEST_URI, it might contain full URL
564 * REQUEST_URI contains PATH_INFO too, this is not what we want
565 * script-php/pathinfo/
566 if (PMA_getenv('REQUEST_URI')) {
567 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
568 if ($url === false) {
569 $url = array('path' => $_SERVER['REQUEST_URI']);
574 // If we don't have scheme, we didn't have full URL so we need to
575 // dig deeper
576 if (empty($url['scheme'])) {
577 // Scheme
578 if (PMA_getenv('HTTP_SCHEME')) {
579 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
580 } else {
581 $url['scheme'] =
582 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
583 ? 'https'
584 : 'http';
587 // Host and port
588 if (PMA_getenv('HTTP_HOST')) {
589 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
590 list($url['host'], $url['port']) =
591 explode(':', PMA_getenv('HTTP_HOST'));
592 } else {
593 $url['host'] = PMA_getenv('HTTP_HOST');
595 } elseif (PMA_getenv('SERVER_NAME')) {
596 $url['host'] = PMA_getenv('SERVER_NAME');
597 } else {
598 $this->error_pma_uri = true;
599 return false;
602 // If we didn't set port yet...
603 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
604 $url['port'] = PMA_getenv('SERVER_PORT');
607 // And finally the path could be already set from REQUEST_URI
608 if (empty($url['path'])) {
610 * REQUEST_URI contains PATH_INFO too, this is not what we want
611 * script-php/pathinfo/
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
618 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
620 $url['path'] = $path['path'];
624 // Make url from parts we have
625 $pma_absolute_uri = $url['scheme'] . '://';
626 // Was there user information?
627 if (!empty($url['user'])) {
628 $pma_absolute_uri .= $url['user'];
629 if (!empty($url['pass'])) {
630 $pma_absolute_uri .= ':' . $url['pass'];
632 $pma_absolute_uri .= '@';
634 // Add hostname
635 $pma_absolute_uri .= $url['host'];
636 // Add port, if it not the default one
637 if (! empty($url['port'])
638 && (($url['scheme'] == 'http' && $url['port'] != 80)
639 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
640 $pma_absolute_uri .= ':' . $url['port'];
642 // And finally path, without script name, the 'a' is there not to
643 // strip our directory, when path is only /pmadir/ without filename.
644 // Backslashes returned by Windows have to be changed.
645 // Only replace backslashes by forward slashes if on Windows,
646 // as the backslash could be valid on a non-Windows system.
647 if ($this->get('PMA_IS_WINDOWS') == 1) {
648 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
649 } else {
650 $path = dirname($url['path'] . 'a');
653 // To work correctly within transformations overview:
654 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
655 if ($this->get('PMA_IS_WINDOWS') == 1) {
656 $path = str_replace("\\", "/", dirname(dirname($path)));
657 } else {
658 $path = dirname(dirname($path));
661 // in vhost situations, there could be already an ending slash
662 if (substr($path, -1) != '/') {
663 $path .= '/';
665 $pma_absolute_uri .= $path;
667 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
668 // the autodetect code works well enough that we don't display the
669 // warning at all. The user can still set PmaAbsoluteUri manually.
670 // See
671 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
673 } else {
674 // The URI is specified, however users do often specify this
675 // wrongly, so we try to fix this.
677 // Adds a trailing slash et the end of the phpMyAdmin uri if it
678 // does not exist.
679 if (substr($pma_absolute_uri, -1) != '/') {
680 $pma_absolute_uri .= '/';
683 // If URI doesn't start with http:// or https://, we will add
684 // this.
685 if (substr($pma_absolute_uri, 0, 7) != 'http://'
686 && substr($pma_absolute_uri, 0, 8) != 'https://') {
687 $pma_absolute_uri =
688 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
689 ? 'https'
690 : 'http')
691 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
692 . $pma_absolute_uri;
695 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
699 * check selected collation_connection
700 * @todo check validity of $_REQUEST['collation_connection']
702 function checkCollationConnection()
704 if (! empty($_REQUEST['collation_connection'])) {
705 $this->set('collation_connection',
706 strip_tags($_REQUEST['collation_connection']));
711 * checks for font size configuration, and sets font size as requested by user
713 * @uses $_GET
714 * @uses $_POST
715 * @uses $_COOKIE
716 * @uses preg_match()
717 * @uses function_exists()
718 * @uses PMA_Config::set()
719 * @uses PMA_Config::get()
720 * @uses PMA_setCookie()
722 function checkFontsize()
724 $new_fontsize = '';
726 if (isset($_GET['fontsize'])) {
727 $new_fontsize = $_GET['fontsize'];
728 } elseif (isset($_POST['fontsize'])) {
729 $new_fontsize = $_POST['fontsize'];
730 } elseif (isset($_COOKIE['pma_fontsize'])) {
731 $new_fontsize = $_COOKIE['pma_fontsize'];
734 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
735 $this->set('fontsize', $new_fontsize);
736 } elseif (! $this->get('fontsize')) {
737 // 80% would correspond to the default browser font size
738 // of 16, but use 82% to help read the monoface font
739 $this->set('fontsize', '82%');
742 if (function_exists('PMA_setCookie')) {
743 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '82%');
748 * 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 static public 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 static public function getCookiePath()
848 static $cookie_path = null;
850 if (null !== $cookie_path) {
851 return $cookie_path;
854 $url = '';
857 * REQUEST_URI contains PATH_INFO too, this is not what we want
858 * script-php/pathinfo/
859 if (PMA_getenv('REQUEST_URI')) {
860 $url = PMA_getenv('REQUEST_URI');
864 // If we don't have path
865 if (empty($url)) {
866 if ($GLOBALS['PMA_PHP_SELF']) {
867 // PHP_SELF in CGI often points to cgi executable, so use it
868 // as last choice
869 $url = $GLOBALS['PMA_PHP_SELF'];
870 // on IIS with PHP-CGI:
871 } elseif (PMA_getenv('SCRIPT_NAME')) {
872 $url = PMA_getenv('SCRIPT_NAME');
877 * REQUEST_URI contains PATH_INFO too, this is not what we want
878 * script-php/pathinfo/
879 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
880 if ($parsed_url === false) {
882 $parsed_url = array('path' => $url);
885 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
887 return $cookie_path;
891 * enables backward compatibility
893 function enableBc()
895 $GLOBALS['cfg'] = $this->settings;
896 $GLOBALS['default_server'] = $this->default_server;
897 unset($this->default_server);
898 $GLOBALS['collation_connection'] = $this->get('collation_connection');
899 $GLOBALS['is_upload'] = $this->get('enable_upload');
900 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
901 $GLOBALS['cookie_path'] = $this->get('cookie_path');
902 $GLOBALS['is_https'] = $this->get('is_https');
904 $defines = array(
905 'PMA_VERSION',
906 'PMA_THEME_VERSION',
907 'PMA_THEME_GENERATION',
908 'PMA_PHP_STR_VERSION',
909 'PMA_PHP_INT_VERSION',
910 'PMA_IS_WINDOWS',
911 'PMA_IS_IIS',
912 'PMA_IS_GD2',
913 'PMA_USR_OS',
914 'PMA_USR_BROWSER_VER',
915 'PMA_USR_BROWSER_AGENT'
918 foreach ($defines as $define) {
919 if (! defined($define)) {
920 define($define, $this->get($define));
926 * @todo finish
928 function save() {}
931 * returns options for font size selection
933 * @uses preg_replace()
934 * @uses ksort()
935 * @static
936 * @param string $current_size current selected font size with unit
937 * @return array selectable font sizes
939 static protected function _getFontsizeOptions($current_size = '82%')
941 $unit = preg_replace('/[0-9.]*/', '', $current_size);
942 $value = preg_replace('/[^0-9.]*/', '', $current_size);
944 $factors = array();
945 $options = array();
946 $options["$value"] = $value . $unit;
948 if ($unit === '%') {
949 $factors[] = 1;
950 $factors[] = 5;
951 $factors[] = 10;
952 } elseif ($unit === 'em') {
953 $factors[] = 0.05;
954 $factors[] = 0.2;
955 $factors[] = 1;
956 } elseif ($unit === 'pt') {
957 $factors[] = 0.5;
958 $factors[] = 2;
959 } elseif ($unit === 'px') {
960 $factors[] = 1;
961 $factors[] = 5;
962 $factors[] = 10;
963 } else {
964 //unknown font size unit
965 $factors[] = 0.05;
966 $factors[] = 0.2;
967 $factors[] = 1;
968 $factors[] = 5;
969 $factors[] = 10;
972 foreach ($factors as $key => $factor) {
973 $option_inc = $value + $factor;
974 $option_dec = $value - $factor;
975 while (count($options) < 21) {
976 $options["$option_inc"] = $option_inc . $unit;
977 if ($option_dec > $factors[0]) {
978 $options["$option_dec"] = $option_dec . $unit;
980 $option_inc += $factor;
981 $option_dec -= $factor;
982 if (isset($factors[$key + 1])
983 && $option_inc >= $value + $factors[$key + 1]) {
984 break;
988 ksort($options);
989 return $options;
993 * returns html selectbox for font sizes
995 * @uses $_SESSION['PMA_Config']
996 * @uses PMA_Config::get()
997 * @uses PMA_Config::_getFontsizeOptions()
998 * @uses $GLOBALS['strFontSize']
999 * @static
1000 * @param string $current_size currently slected font size with unit
1001 * @return string html selectbox
1003 static protected function _getFontsizeSelection()
1005 $current_size = $_SESSION['PMA_Config']->get('fontsize');
1006 // for the case when there is no config file (this is supported)
1007 if (empty($current_size)) {
1008 if (isset($_COOKIE['pma_fontsize'])) {
1009 $current_size = $_COOKIE['pma_fontsize'];
1010 } else {
1011 $current_size = '82%';
1014 $options = PMA_Config::_getFontsizeOptions($current_size);
1016 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1017 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1018 foreach ($options as $option) {
1019 $return .= '<option value="' . $option . '"';
1020 if ($option == $current_size) {
1021 $return .= ' selected="selected"';
1023 $return .= '>' . $option . '</option>' . "\n";
1025 $return .= '</select>';
1027 return $return;
1031 * return complete font size selection form
1033 * @uses PMA_generate_common_hidden_inputs()
1034 * @uses PMA_Config::_getFontsizeSelection()
1035 * @uses $GLOBALS['strGo']
1036 * @static
1037 * @param string $current_size currently slected font size with unit
1038 * @return string html selectbox
1040 static public function getFontsizeForm()
1042 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1043 . ' method="post" action="index.php" target="_parent">' . "\n"
1044 . PMA_generate_common_hidden_inputs() . "\n"
1045 . PMA_Config::_getFontsizeSelection() . "\n"
1046 . '<noscript>' . "\n"
1047 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1048 . '</noscript>' . "\n"
1049 . '</form>';