3.1.4-rc2
[phpmyadmin/crack.git] / libraries / Config.class.php
blobac760e0cbd407885c2767215a22377769fea9764
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.4-rc2');
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 $this->checkPermissions();
406 // Handling of the collation must be done after merging of $cfg
407 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
408 // can have an effect. Note that the presence of collation
409 // information in a cookie has priority over what is defined
410 // in the default or user's config files.
412 * @todo check validity of $_COOKIE['pma_collation_connection']
414 if (! empty($_COOKIE['pma_collation_connection'])) {
415 $this->set('collation_connection',
416 strip_tags($_COOKIE['pma_collation_connection']));
417 } else {
418 $this->set('collation_connection',
419 $this->get('DefaultConnectionCollation'));
421 // Now, a collation information could come from REQUEST
422 // (an example of this: the collation selector in main.php)
423 // so the following handles the setting of collation_connection
424 // and later, in common.inc.php, the cookie will be set
425 // according to this.
426 $this->checkCollationConnection();
428 return true;
432 * set source
433 * @param string $source
435 function setSource($source)
437 $this->source = trim($source);
441 * checks if the config folder still exists and terminates app if true
443 function checkConfigFolder()
445 // Refuse to work while there still might be some world writable dir:
446 if (is_dir('./config')) {
447 die('Remove "./config" directory before using phpMyAdmin!');
452 * check config source
454 * @return boolean whether source is valid or not
456 function checkConfigSource()
458 if (! $this->getSource()) {
459 // no configuration file set at all
460 return false;
463 if (! file_exists($this->getSource())) {
464 // do not trigger error here
465 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
467 trigger_error(
468 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
469 E_USER_WARNING);
471 $this->source_mtime = 0;
472 return false;
475 if (! is_readable($this->getSource())) {
476 $this->source_mtime = 0;
477 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
480 return true;
484 * verifies the permissions on config file (if asked by configuration)
485 * (must be called after config.inc.php has been merged)
487 function checkPermissions()
489 // Check for permissions (on platforms that support it):
490 if ($this->get('CheckConfigurationPermissions')) {
491 $perms = @fileperms($this->getSource());
492 if (!($perms === false) && ($perms & 2)) {
493 // This check is normally done after loading configuration
494 $this->checkWebServerOs();
495 if ($this->get('PMA_IS_WINDOWS') == 0) {
496 $this->source_mtime = 0;
497 die('Wrong permissions on configuration file, should not be world writable!');
504 * returns specific config setting
505 * @param string $setting
506 * @return mixed value
508 function get($setting)
510 if (isset($this->settings[$setting])) {
511 return $this->settings[$setting];
513 return null;
517 * sets configuration variable
519 * @uses $this->settings
520 * @param string $setting configuration option
521 * @param string $value new value for configuration option
523 function set($setting, $value)
525 if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
526 $this->settings[$setting] = $value;
527 $this->set_mtime = time();
532 * returns source for current config
533 * @return string config source
535 function getSource()
537 return $this->source;
541 * returns a unique value to force a CSS reload if either the config
542 * or the theme changes
543 * must also check the pma_fontsize cookie in case there is no
544 * config file
545 * @return int Unix timestamp
547 function getThemeUniqueValue()
549 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) : '');
553 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
554 * set properly and, depending on browsers, inserting or updating a
555 * record might fail
557 function checkPmaAbsoluteUri()
559 // Setup a default value to let the people and lazy sysadmins work anyway,
560 // they'll get an error if the autodetect code doesn't work
561 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
562 $is_https = $this->get('is_https');
564 if (strlen($pma_absolute_uri) < 5
565 // needed to catch http/https switch
566 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
567 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
569 $url = array();
571 // At first we try to parse REQUEST_URI, it might contain full URL
573 * REQUEST_URI contains PATH_INFO too, this is not what we want
574 * script-php/pathinfo/
575 if (PMA_getenv('REQUEST_URI')) {
576 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
577 if ($url === false) {
578 $url = array('path' => $_SERVER['REQUEST_URI']);
583 // If we don't have scheme, we didn't have full URL so we need to
584 // dig deeper
585 if (empty($url['scheme'])) {
586 // Scheme
587 if (PMA_getenv('HTTP_SCHEME')) {
588 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
589 } else {
590 $url['scheme'] =
591 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
592 ? 'https'
593 : 'http';
596 // Host and port
597 if (PMA_getenv('HTTP_HOST')) {
598 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
599 list($url['host'], $url['port']) =
600 explode(':', PMA_getenv('HTTP_HOST'));
601 } else {
602 $url['host'] = PMA_getenv('HTTP_HOST');
604 } elseif (PMA_getenv('SERVER_NAME')) {
605 $url['host'] = PMA_getenv('SERVER_NAME');
606 } else {
607 $this->error_pma_uri = true;
608 return false;
611 // If we didn't set port yet...
612 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
613 $url['port'] = PMA_getenv('SERVER_PORT');
616 // And finally the path could be already set from REQUEST_URI
617 if (empty($url['path'])) {
619 * REQUEST_URI contains PATH_INFO too, this is not what we want
620 * script-php/pathinfo/
621 if (PMA_getenv('PATH_INFO')) {
622 $path = parse_url(PMA_getenv('PATH_INFO'));
623 } else {
624 // PHP_SELF in CGI often points to cgi executable, so use it
625 // as last choice
627 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
629 $url['path'] = $path['path'];
633 // Make url from parts we have
634 $pma_absolute_uri = $url['scheme'] . '://';
635 // Was there user information?
636 if (!empty($url['user'])) {
637 $pma_absolute_uri .= $url['user'];
638 if (!empty($url['pass'])) {
639 $pma_absolute_uri .= ':' . $url['pass'];
641 $pma_absolute_uri .= '@';
643 // Add hostname
644 $pma_absolute_uri .= $url['host'];
645 // Add port, if it not the default one
646 if (! empty($url['port'])
647 && (($url['scheme'] == 'http' && $url['port'] != 80)
648 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
649 $pma_absolute_uri .= ':' . $url['port'];
651 // And finally path, without script name, the 'a' is there not to
652 // strip our directory, when path is only /pmadir/ without filename.
653 // Backslashes returned by Windows have to be changed.
654 // Only replace backslashes by forward slashes if on Windows,
655 // as the backslash could be valid on a non-Windows system.
656 if ($this->get('PMA_IS_WINDOWS') == 1) {
657 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
658 } else {
659 $path = dirname($url['path'] . 'a');
662 // To work correctly within transformations overview:
663 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
664 if ($this->get('PMA_IS_WINDOWS') == 1) {
665 $path = str_replace("\\", "/", dirname(dirname($path)));
666 } else {
667 $path = dirname(dirname($path));
670 // in vhost situations, there could be already an ending slash
671 if (substr($path, -1) != '/') {
672 $path .= '/';
674 $pma_absolute_uri .= $path;
676 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
677 // the autodetect code works well enough that we don't display the
678 // warning at all. The user can still set PmaAbsoluteUri manually.
679 // See
680 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
682 } else {
683 // The URI is specified, however users do often specify this
684 // wrongly, so we try to fix this.
686 // Adds a trailing slash et the end of the phpMyAdmin uri if it
687 // does not exist.
688 if (substr($pma_absolute_uri, -1) != '/') {
689 $pma_absolute_uri .= '/';
692 // If URI doesn't start with http:// or https://, we will add
693 // this.
694 if (substr($pma_absolute_uri, 0, 7) != 'http://'
695 && substr($pma_absolute_uri, 0, 8) != 'https://') {
696 $pma_absolute_uri =
697 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
698 ? 'https'
699 : 'http')
700 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
701 . $pma_absolute_uri;
704 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
708 * check selected collation_connection
709 * @todo check validity of $_REQUEST['collation_connection']
711 function checkCollationConnection()
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
761 function checkUpload()
763 if (ini_get('file_uploads')) {
764 $this->set('enable_upload', true);
765 // if set "php_admin_value file_uploads Off" in httpd.conf
766 // ini_get() also returns the string "Off" in this case:
767 if ('off' == strtolower(ini_get('file_uploads'))) {
768 $this->set('enable_upload', false);
770 } else {
771 $this->set('enable_upload', false);
776 * Maximum upload size as limited by PHP
777 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
779 * this section generates $max_upload_size in bytes
781 function checkUploadSize()
783 if (! $filesize = ini_get('upload_max_filesize')) {
784 $filesize = "5M";
787 if ($postsize = ini_get('post_max_size')) {
788 $this->set('max_upload_size',
789 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
790 } else {
791 $this->set('max_upload_size', PMA_get_real_size($filesize));
796 * check for https
798 function checkIsHttps()
800 $this->set('is_https', PMA_Config::isHttps());
804 * @static
806 static public function isHttps()
808 $is_https = false;
810 $url = array();
812 // At first we try to parse REQUEST_URI, it might contain full URL,
813 if (PMA_getenv('REQUEST_URI')) {
814 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
815 if($url === false) {
816 $url = array();
820 // If we don't have scheme, we didn't have full URL so we need to
821 // dig deeper
822 if (empty($url['scheme'])) {
823 // Scheme
824 if (PMA_getenv('HTTP_SCHEME')) {
825 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
826 } else {
827 $url['scheme'] =
828 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
829 ? 'https'
830 : 'http';
834 if (isset($url['scheme'])
835 && $url['scheme'] == 'https') {
836 $is_https = true;
837 } else {
838 $is_https = false;
841 return $is_https;
845 * detect correct cookie path
847 function checkCookiePath()
849 $this->set('cookie_path', PMA_Config::getCookiePath());
853 * @static
855 static public function getCookiePath()
857 static $cookie_path = null;
859 if (null !== $cookie_path) {
860 return $cookie_path;
863 $url = '';
866 * REQUEST_URI contains PATH_INFO too, this is not what we want
867 * script-php/pathinfo/
868 if (PMA_getenv('REQUEST_URI')) {
869 $url = PMA_getenv('REQUEST_URI');
873 // If we don't have path
874 if (empty($url)) {
875 if ($GLOBALS['PMA_PHP_SELF']) {
876 // PHP_SELF in CGI often points to cgi executable, so use it
877 // as last choice
878 $url = $GLOBALS['PMA_PHP_SELF'];
879 // on IIS with PHP-CGI:
880 } elseif (PMA_getenv('SCRIPT_NAME')) {
881 $url = PMA_getenv('SCRIPT_NAME');
886 * REQUEST_URI contains PATH_INFO too, this is not what we want
887 * script-php/pathinfo/
888 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
889 if ($parsed_url === false) {
891 $parsed_url = array('path' => $url);
894 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
896 return $cookie_path;
900 * enables backward compatibility
902 function enableBc()
904 $GLOBALS['cfg'] = $this->settings;
905 $GLOBALS['default_server'] = $this->default_server;
906 unset($this->default_server);
907 $GLOBALS['collation_connection'] = $this->get('collation_connection');
908 $GLOBALS['is_upload'] = $this->get('enable_upload');
909 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
910 $GLOBALS['cookie_path'] = $this->get('cookie_path');
911 $GLOBALS['is_https'] = $this->get('is_https');
913 $defines = array(
914 'PMA_VERSION',
915 'PMA_THEME_VERSION',
916 'PMA_THEME_GENERATION',
917 'PMA_PHP_STR_VERSION',
918 'PMA_PHP_INT_VERSION',
919 'PMA_IS_WINDOWS',
920 'PMA_IS_IIS',
921 'PMA_IS_GD2',
922 'PMA_USR_OS',
923 'PMA_USR_BROWSER_VER',
924 'PMA_USR_BROWSER_AGENT'
927 foreach ($defines as $define) {
928 if (! defined($define)) {
929 define($define, $this->get($define));
935 * @todo finish
937 function save() {}
940 * returns options for font size selection
942 * @uses preg_replace()
943 * @uses ksort()
944 * @static
945 * @param string $current_size current selected font size with unit
946 * @return array selectable font sizes
948 static protected function _getFontsizeOptions($current_size = '82%')
950 $unit = preg_replace('/[0-9.]*/', '', $current_size);
951 $value = preg_replace('/[^0-9.]*/', '', $current_size);
953 $factors = array();
954 $options = array();
955 $options["$value"] = $value . $unit;
957 if ($unit === '%') {
958 $factors[] = 1;
959 $factors[] = 5;
960 $factors[] = 10;
961 } elseif ($unit === 'em') {
962 $factors[] = 0.05;
963 $factors[] = 0.2;
964 $factors[] = 1;
965 } elseif ($unit === 'pt') {
966 $factors[] = 0.5;
967 $factors[] = 2;
968 } elseif ($unit === 'px') {
969 $factors[] = 1;
970 $factors[] = 5;
971 $factors[] = 10;
972 } else {
973 //unknown font size unit
974 $factors[] = 0.05;
975 $factors[] = 0.2;
976 $factors[] = 1;
977 $factors[] = 5;
978 $factors[] = 10;
981 foreach ($factors as $key => $factor) {
982 $option_inc = $value + $factor;
983 $option_dec = $value - $factor;
984 while (count($options) < 21) {
985 $options["$option_inc"] = $option_inc . $unit;
986 if ($option_dec > $factors[0]) {
987 $options["$option_dec"] = $option_dec . $unit;
989 $option_inc += $factor;
990 $option_dec -= $factor;
991 if (isset($factors[$key + 1])
992 && $option_inc >= $value + $factors[$key + 1]) {
993 break;
997 ksort($options);
998 return $options;
1002 * returns html selectbox for font sizes
1004 * @uses $_SESSION['PMA_Config']
1005 * @uses PMA_Config::get()
1006 * @uses PMA_Config::_getFontsizeOptions()
1007 * @uses $GLOBALS['strFontSize']
1008 * @static
1009 * @param string $current_size currently slected font size with unit
1010 * @return string html selectbox
1012 static protected function _getFontsizeSelection()
1014 $current_size = $_SESSION['PMA_Config']->get('fontsize');
1015 // for the case when there is no config file (this is supported)
1016 if (empty($current_size)) {
1017 if (isset($_COOKIE['pma_fontsize'])) {
1018 $current_size = $_COOKIE['pma_fontsize'];
1019 } else {
1020 $current_size = '82%';
1023 $options = PMA_Config::_getFontsizeOptions($current_size);
1025 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1026 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1027 foreach ($options as $option) {
1028 $return .= '<option value="' . $option . '"';
1029 if ($option == $current_size) {
1030 $return .= ' selected="selected"';
1032 $return .= '>' . $option . '</option>' . "\n";
1034 $return .= '</select>';
1036 return $return;
1040 * return complete font size selection form
1042 * @uses PMA_generate_common_hidden_inputs()
1043 * @uses PMA_Config::_getFontsizeSelection()
1044 * @uses $GLOBALS['strGo']
1045 * @static
1046 * @param string $current_size currently slected font size with unit
1047 * @return string html selectbox
1049 static public function getFontsizeForm()
1051 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1052 . ' method="post" action="index.php" target="_parent">' . "\n"
1053 . PMA_generate_common_hidden_inputs() . "\n"
1054 . PMA_Config::_getFontsizeSelection() . "\n"
1055 . '<noscript>' . "\n"
1056 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1057 . '</noscript>' . "\n"
1058 . '</form>';