Fix XSS on table comment.
[phpmyadmin/crack.git] / libraries / Config.class.php
blob36ffa251b6cde900f821cf31ff8f7240423536bf
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Configuration class
8 */
9 class PMA_Config
11 /**
12 * @var string default config source
14 var $default_source = './libraries/config.default.php';
16 /**
17 * @var array configuration settings
19 var $settings = array();
21 /**
22 * @var string config source
24 var $source = '';
26 /**
27 * @var int source modification time
29 var $source_mtime = 0;
30 var $default_source_mtime = 0;
32 /**
33 * @var boolean
35 var $error_config_file = false;
37 /**
38 * @var boolean
40 var $error_config_default_file = false;
42 /**
43 * @var boolean
45 var $error_pma_uri = false;
47 /**
48 * @var array
50 var $default_server = array();
52 /**
53 * @var boolean wether init is done or mot
54 * set this to false to force some initial checks
55 * like checking for required functions
57 var $done = false;
59 /**
60 * constructor
62 * @param string source to read config from
64 function __construct($source = null)
66 $this->settings = array();
68 // functions need to refresh in case of config file changed goes in
69 // PMA_Config::load()
70 $this->load($source);
72 // other settings, independant from config file, comes in
73 $this->checkSystem();
75 $this->checkIsHttps();
78 /**
79 * sets system and application settings
81 function checkSystem()
83 $this->set('PMA_VERSION', '2.10.0-dev');
84 /**
85 * @deprecated
87 $this->set('PMA_THEME_VERSION', 2);
88 /**
89 * @deprecated
91 $this->set('PMA_THEME_GENERATION', 2);
93 $this->checkPhpVersion();
94 $this->checkWebServerOs();
95 $this->checkWebServer();
96 $this->checkGd2();
97 $this->checkClient();
98 $this->checkUpload();
99 $this->checkUploadSize();
100 $this->checkOutputCompression();
104 * wether to use gzip output compression or not
106 function checkOutputCompression()
108 // If zlib output compression is set in the php configuration file, no
109 // output buffering should be run
110 if (@ini_get('zlib.output_compression')) {
111 $this->set('OBGzip', false);
114 // disable output-buffering (if set to 'auto') for IE6, else enable it.
115 if (strtolower($this->get('OBGzip')) == 'auto') {
116 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
117 && $this->get('PMA_USR_BROWSER_VER') >= 6
118 && $this->get('PMA_USR_BROWSER_VER') < 7) {
119 $this->set('OBGzip', false);
120 } else {
121 $this->set('OBGzip', true);
127 * Determines platform (OS), browser and version of the user
128 * Based on a phpBuilder article:
129 * @see http://www.phpbuilder.net/columns/tim20000821.php
131 function checkClient()
133 if (PMA_getenv('HTTP_USER_AGENT')) {
134 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
135 } elseif (!isset($HTTP_USER_AGENT)) {
136 $HTTP_USER_AGENT = '';
139 // 1. Platform
140 if (strstr($HTTP_USER_AGENT, 'Win')) {
141 $this->set('PMA_USR_OS', 'Win');
142 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
143 $this->set('PMA_USR_OS', 'Mac');
144 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
145 $this->set('PMA_USR_OS', 'Linux');
146 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
147 $this->set('PMA_USR_OS', 'Unix');
148 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
149 $this->set('PMA_USR_OS', 'OS/2');
150 } else {
151 $this->set('PMA_USR_OS', 'Other');
154 // 2. browser and version
155 // (must check everything else before Mozilla)
157 if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
158 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
159 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
160 } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
161 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
162 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
163 } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
164 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
165 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
166 //} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
167 // Konqueror 2.2.2 says Konqueror/2.2.2
168 // Konqueror 3.0.3 says Konqueror/3
169 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
170 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
171 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
172 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
173 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
174 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
175 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
176 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
177 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
178 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
179 } else {
180 $this->set('PMA_USR_BROWSER_VER', 0);
181 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
186 * Whether GD2 is present
188 function checkGd2()
190 if ($this->get('GD2Available') == 'yes') {
191 $this->set('PMA_IS_GD2', 1);
192 } elseif ($this->get('GD2Available') == 'no') {
193 $this->set('PMA_IS_GD2', 0);
194 } else {
195 if (!@extension_loaded('gd')) {
196 PMA_dl('gd');
198 if (!@function_exists('imagecreatetruecolor')) {
199 $this->set('PMA_IS_GD2', 0);
200 } else {
201 if (@function_exists('gd_info')) {
202 $gd_nfo = gd_info();
203 if (strstr($gd_nfo["GD Version"], '2.')) {
204 $this->set('PMA_IS_GD2', 1);
205 } else {
206 $this->set('PMA_IS_GD2', 0);
208 } else {
209 /* We must do hard way... */
210 ob_start();
211 phpinfo(INFO_MODULES); /* Only modules */
212 $a = strip_tags(ob_get_contents());
213 ob_end_clean();
214 /* Get GD version string from phpinfo output */
215 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
216 if (strstr($v, '2.')) {
217 $this->set('PMA_IS_GD2', 1);
218 } else {
219 $this->set('PMA_IS_GD2', 0);
221 } else {
222 $this->set('PMA_IS_GD2', 0);
230 * Whether the Web server php is running on is IIS
232 function checkWebServer()
234 if (PMA_getenv('SERVER_SOFTWARE')
235 // some versions return Microsoft-IIS, some Microsoft/IIS
236 // we could use a preg_match() but it's slower
237 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
238 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
239 $this->set('PMA_IS_IIS', 1);
240 } else {
241 $this->set('PMA_IS_IIS', 0);
246 * Whether the os php is running on is windows or not
248 function checkWebServerOs()
250 // Default to Unix or Equiv
251 $this->set('PMA_IS_WINDOWS', 0);
252 // If PHP_OS is defined then continue
253 if (defined('PHP_OS')) {
254 if (stristr(PHP_OS, 'win') ) {
255 // Is it some version of Windows
256 $this->set('PMA_IS_WINDOWS', 1);
257 } elseif (stristr(PHP_OS, 'OS/2')) {
258 // Is it OS/2 (No file permissions like Windows)
259 $this->set('PMA_IS_WINDOWS', 1);
265 * detects PHP version
267 function checkPhpVersion()
269 $match = array();
270 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
271 phpversion(), $match)) {
272 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
273 phpversion(), $match);
275 if (isset($match) && ! empty($match[1])) {
276 if (! isset($match[2])) {
277 $match[2] = 0;
279 if (! isset($match[3])) {
280 $match[3] = 0;
282 $this->set('PMA_PHP_INT_VERSION',
283 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
284 } else {
285 $this->set('PMA_PHP_INT_VERSION', 0);
287 $this->set('PMA_PHP_STR_VERSION', phpversion());
291 * re-init object after loading from session file
292 * checks config file for changes and relaods if neccessary
294 function __wakeup()
296 if (! $this->checkConfigSource()
297 || $this->source_mtime !== filemtime($this->getSource())
298 || $this->default_source_mtime !== filemtime($this->default_source)
299 || $this->error_config_file
300 || $this->error_config_default_file) {
301 $this->settings = array();
302 $this->load();
303 $this->checkSystem();
306 // check for https needs to be done everytime,
307 // as https and http uses same session so this info can not be stored
308 // in session
309 $this->checkIsHttps();
311 $this->checkCollationConnection();
312 $this->checkFontsize();
316 * loads default values from default source
318 * @uses file_exists()
319 * @uses $this->default_source
320 * @uses $this->error_config_default_file
321 * @uses $this->settings
322 * @return boolean success
324 function loadDefaults()
326 $cfg = array();
327 if (! file_exists($this->default_source)) {
328 $this->error_config_default_file = true;
329 return false;
331 include $this->default_source;
333 $this->default_source_mtime = filemtime($this->default_source);
335 $this->default_server = $cfg['Servers'][1];
336 unset($cfg['Servers']);
338 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
340 $this->error_config_default_file = false;
342 return true;
346 * loads configuration from $source, usally the config file
347 * should be called on object creation and from __wakeup if config file
348 * has changed
350 * @param string $source config file
352 function load($source = null)
354 $this->loadDefaults();
356 if (null !== $source) {
357 $this->setSource($source);
360 if (! $this->checkConfigSource()) {
361 return false;
364 $cfg = array();
367 * Parses the configuration file
369 $old_error_reporting = error_reporting(0);
370 if (function_exists('file_get_contents')) {
371 $eval_result =
372 eval('?>' . trim(file_get_contents($this->getSource())));
373 } else {
374 $eval_result =
375 eval('?>' . trim(implode("\n", file($this->getSource()))));
377 error_reporting($old_error_reporting);
379 if ($eval_result === false) {
380 $this->error_config_file = true;
381 } else {
382 $this->error_config_file = false;
383 $this->source_mtime = filemtime($this->getSource());
387 * Backward compatibility code
389 if (!empty($cfg['DefaultTabTable'])) {
390 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
392 if (!empty($cfg['DefaultTabDatabase'])) {
393 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
397 * @todo check validity of $_COOKIE['pma_collation_connection']
399 if (! empty($_COOKIE['pma_collation_connection'])) {
400 $this->set('collation_connection',
401 strip_tags($_COOKIE['pma_collation_connection']));
402 } else {
403 $this->set('collation_connection',
404 $this->get('DefaultConnectionCollation'));
407 $this->checkCollationConnection();
408 $this->checkFontsize();
409 //$this->checkPmaAbsoluteUri();
410 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
411 return true;
415 * set source
416 * @param string $source
418 function setSource($source)
420 $this->source = trim($source);
424 * checks if the config folder still exists and terminates app if true
426 function checkConfigFolder()
428 // Refuse to work while there still might be some world writable dir:
429 if (is_dir('./config')) {
430 die('Remove "./config" directory before using phpMyAdmin!');
435 * check config source
437 * @return boolean wether source is valid or not
439 function checkConfigSource()
441 if (! $this->getSource()) {
442 // no configuration file set at all
443 return false;
446 if (! file_exists($this->getSource())) {
447 // do not trigger error here
448 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
450 trigger_error(
451 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
452 E_USER_WARNING);
454 $this->source_mtime = 0;
455 return false;
458 if (! is_readable($this->getSource())) {
459 $this->source_mtime = 0;
460 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
463 // Check for permissions (on platforms that support it):
464 $perms = @fileperms($this->getSource());
465 if (!($perms === false) && ($perms & 2)) {
466 // This check is normally done after loading configuration
467 $this->checkWebServerOs();
468 if ($this->get('PMA_IS_WINDOWS') == 0) {
469 $this->source_mtime = 0;
470 die('Wrong permissions on configuration file, should not be world writable!');
474 return true;
478 * returns specific config setting
479 * @param string $setting
480 * @return mixed value
482 function get($setting)
484 if (isset($this->settings[$setting])) {
485 return $this->settings[$setting];
487 return null;
491 * sets configuration variable
493 * @uses $this->settings
494 * @param string $setting configuration option
495 * @param string $value new value for configuration option
497 function set($setting, $value)
499 $this->settings[$setting] = $value;
503 * returns source for current config
504 * @return string config source
506 function getSource()
508 return $this->source;
512 * old PHP 4 style constructor
514 * @deprecated
516 function PMA_Config($source = null)
518 $this->__construct($source);
522 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
523 * set properly and, depending on browsers, inserting or updating a
524 * record might fail
526 function checkPmaAbsoluteUri()
528 // Setup a default value to let the people and lazy syadmins work anyway,
529 // they'll get an error if the autodetect code doesn't work
530 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
531 $is_https = $this->get('is_https');
532 if (strlen($pma_absolute_uri) < 5
533 // needed to catch http/https switch
534 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
535 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
537 $url = array();
539 // At first we try to parse REQUEST_URI, it might contain full URL
540 if (PMA_getenv('REQUEST_URI')) {
541 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
542 if ($url === false) {
543 $url = array( 'path' => $_SERVER['REQUEST_URI'] );
547 // If we don't have scheme, we didn't have full URL so we need to
548 // dig deeper
549 if (empty($url['scheme'])) {
550 // Scheme
551 if (PMA_getenv('HTTP_SCHEME')) {
552 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
553 } else {
554 $url['scheme'] =
555 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
556 ? 'https'
557 : 'http';
560 // Host and port
561 if (PMA_getenv('HTTP_HOST')) {
562 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
563 list($url['host'], $url['port']) =
564 explode(':', PMA_getenv('HTTP_HOST'));
565 } else {
566 $url['host'] = PMA_getenv('HTTP_HOST');
568 } elseif (PMA_getenv('SERVER_NAME')) {
569 $url['host'] = PMA_getenv('SERVER_NAME');
570 } else {
571 $this->error_pma_uri = true;
572 return false;
575 // If we didn't set port yet...
576 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
577 $url['port'] = PMA_getenv('SERVER_PORT');
580 // And finally the path could be already set from REQUEST_URI
581 if (empty($url['path'])) {
582 if (PMA_getenv('PATH_INFO')) {
583 $path = parse_url(PMA_getenv('PATH_INFO'));
584 } else {
585 // PHP_SELF in CGI often points to cgi executable, so use it
586 // as last choice
587 $path = parse_url(PMA_getenv('PHP_SELF'));
589 $url['path'] = $path['path'];
593 // Make url from parts we have
594 $pma_absolute_uri = $url['scheme'] . '://';
595 // Was there user information?
596 if (!empty($url['user'])) {
597 $pma_absolute_uri .= $url['user'];
598 if (!empty($url['pass'])) {
599 $pma_absolute_uri .= ':' . $url['pass'];
601 $pma_absolute_uri .= '@';
603 // Add hostname
604 $pma_absolute_uri .= $url['host'];
605 // Add port, if it not the default one
606 if (! empty($url['port'])
607 && (($url['scheme'] == 'http' && $url['port'] != 80)
608 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
609 $pma_absolute_uri .= ':' . $url['port'];
611 // And finally path, without script name, the 'a' is there not to
612 // strip our directory, when path is only /pmadir/ without filename.
613 // Backslashes returned by Windows have to be changed.
614 // Only replace backslashes by forward slashes if on Windows,
615 // as the backslash could be valid on a non-Windows system.
616 if ($this->get('PMA_IS_WINDOWS') == 1) {
617 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
618 } else {
619 $path = dirname($url['path'] . 'a');
622 // To work correctly within transformations overview:
623 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
624 if ($this->get('PMA_IS_WINDOWS') == 1) {
625 $path = str_replace("\\", "/", dirname(dirname($path)));
626 } else {
627 $path = dirname(dirname($path));
630 // in vhost situations, there could be already an ending slash
631 if (substr($path, -1) != '/') {
632 $path .= '/';
634 $pma_absolute_uri .= $path;
636 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
637 // the autodetect code works well enough that we don't display the
638 // warning at all. The user can still set PmaAbsoluteUri manually.
639 // See
640 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
642 } else {
643 // The URI is specified, however users do often specify this
644 // wrongly, so we try to fix this.
646 // Adds a trailing slash et the end of the phpMyAdmin uri if it
647 // does not exist.
648 if (substr($pma_absolute_uri, -1) != '/') {
649 $pma_absolute_uri .= '/';
652 // If URI doesn't start with http:// or https://, we will add
653 // this.
654 if (substr($pma_absolute_uri, 0, 7) != 'http://'
655 && substr($pma_absolute_uri, 0, 8) != 'https://') {
656 $pma_absolute_uri =
657 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
658 ? 'https'
659 : 'http')
660 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
661 . $pma_absolute_uri;
665 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
669 * check selected collation_connection
670 * @todo check validity of $_REQUEST['collation_connection']
672 function checkCollationConnection()
674 // (could be improved by executing it after the MySQL connection only if
675 // PMA_MYSQL_INT_VERSION >= 40100)
676 if (! empty($_REQUEST['collation_connection'])) {
677 $this->set('collation_connection',
678 strip_tags($_REQUEST['collation_connection']));
683 * checks for font size configuration, and sets font size as requested by user
685 * @uses $_GET
686 * @uses $_POST
687 * @uses $_COOKIE
688 * @uses preg_match()
689 * @uses function_exists()
690 * @uses PMA_Config::set()
691 * @uses PMA_Config::get()
692 * @uses PMA_setCookie()
694 function checkFontsize()
696 $new_fontsize = '';
698 if (isset($_GET['fontsize'])) {
699 $new_fontsize = $_GET['fontsize'];
700 } elseif (isset($_POST['fontsize'])) {
701 $new_fontsize = $_POST['fontsize'];
702 } elseif (isset($_COOKIE['pma_fontsize'])) {
703 $new_fontsize = $_COOKIE['pma_fontsize'];
706 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
707 $this->set('fontsize', $new_fontsize);
708 } elseif (! $this->get('fontsize')) {
709 $this->set('fontsize', '100%');
712 if (function_exists('PMA_setCookie')) {
713 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '100%');
718 * checks if upload is enabled
721 function checkUpload()
723 $this->set('enable_upload', true);
724 if (strtolower(@ini_get('file_uploads')) == 'off'
725 || @ini_get('file_uploads') == 0) {
726 $this->set('enable_upload', false);
731 * Maximum upload size as limited by PHP
732 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
734 * this section generates $max_upload_size in bytes
736 function checkUploadSize()
738 if (! $filesize = ini_get('upload_max_filesize')) {
739 $filesize = "5M";
742 if ($postsize = ini_get('post_max_size')) {
743 $this->set('max_upload_size',
744 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
745 } else {
746 $this->set('max_upload_size', PMA_get_real_size($filesize));
751 * check for https
753 function checkIsHttps()
755 $this->set('is_https', PMA_Config::isHttps());
759 * @static
761 function isHttps()
763 $is_https = false;
765 $url = array();
767 // At first we try to parse REQUEST_URI, it might contain full URL,
768 if (PMA_getenv('REQUEST_URI')) {
769 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
770 if($url === false) {
771 $url = array();
775 // If we don't have scheme, we didn't have full URL so we need to
776 // dig deeper
777 if (empty($url['scheme'])) {
778 // Scheme
779 if (PMA_getenv('HTTP_SCHEME')) {
780 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
781 } else {
782 $url['scheme'] =
783 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
784 ? 'https'
785 : 'http';
789 if (isset($url['scheme'])
790 && $url['scheme'] == 'https') {
791 $is_https = true;
792 } else {
793 $is_https = false;
796 return $is_https;
800 * detect correct cookie path
802 function checkCookiePath()
804 $this->set('cookie_path', PMA_Config::getCookiePath());
808 * @static
810 function getCookiePath()
812 static $cookie_path = null;
814 if (null !== $cookie_path) {
815 return $cookie_path;
818 $url = '';
820 if (PMA_getenv('REQUEST_URI')) {
821 $url = PMA_getenv('REQUEST_URI');
824 // If we don't have path
825 if (empty($url)) {
826 if (PMA_getenv('PATH_INFO')) {
827 $url = PMA_getenv('PATH_INFO');
828 } elseif (PMA_getenv('PHP_SELF')) {
829 // PHP_SELF in CGI often points to cgi executable, so use it
830 // as last choice
831 $url = PMA_getenv('PHP_SELF');
832 } elseif (PMA_getenv('SCRIPT_NAME')) {
833 $url = PMA_getenv('PHP_SELF');
837 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
838 if ($parsed_url === false) {
839 $parsed_url = array('path' => $url);
842 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
844 return $cookie_path;
848 * enables backward compatibility
850 function enableBc()
852 $GLOBALS['cfg'] =& $this->settings;
853 $GLOBALS['default_server'] =& $this->default_server;
854 $GLOBALS['collation_connection'] = $this->get('collation_connection');
855 $GLOBALS['is_upload'] = $this->get('enable_upload');
856 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
857 $GLOBALS['cookie_path'] = $this->get('cookie_path');
858 $GLOBALS['is_https'] = $this->get('is_https');
860 $defines = array(
861 'PMA_VERSION',
862 'PMA_THEME_VERSION',
863 'PMA_THEME_GENERATION',
864 'PMA_PHP_STR_VERSION',
865 'PMA_PHP_INT_VERSION',
866 'PMA_IS_WINDOWS',
867 'PMA_IS_IIS',
868 'PMA_IS_GD2',
869 'PMA_USR_OS',
870 'PMA_USR_BROWSER_VER',
871 'PMA_USR_BROWSER_AGENT',
874 foreach ($defines as $define) {
875 if (! defined($define)) {
876 define($define, $this->get($define));
882 * @todo finish
884 function save() {}
887 * returns options for font size selection
889 * @uses preg_replace()
890 * @uses ksort()
891 * @static
892 * @param string $current_size current selected font size with unit
893 * @return array selectable font sizes
895 function getFontsizeOptions($current_size = '100%')
897 $unit = preg_replace('/[0-9.]*/', '', $current_size);
898 $value = preg_replace('/[^0-9.]*/', '', $current_size);
900 $factors = array();
901 $options = array();
902 $options["$value"] = $value . $unit;
904 if ($unit === '%') {
905 $factors[] = 1;
906 $factors[] = 5;
907 $factors[] = 10;
908 } elseif ($unit === 'em') {
909 $factors[] = 0.05;
910 $factors[] = 0.2;
911 $factors[] = 1;
912 } elseif ($unit === 'pt') {
913 $factors[] = 0.5;
914 $factors[] = 2;
915 } elseif ($unit === 'px') {
916 $factors[] = 1;
917 $factors[] = 5;
918 $factors[] = 10;
919 } else {
920 //unknown font size unit
921 $factors[] = 0.05;
922 $factors[] = 0.2;
923 $factors[] = 1;
924 $factors[] = 5;
925 $factors[] = 10;
928 foreach ($factors as $key => $factor) {
929 $option_inc = $value + $factor;
930 $option_dec = $value - $factor;
931 while (count($options) < 21) {
932 $options["$option_inc"] = $option_inc . $unit;
933 if ($option_dec > $factors[0]) {
934 $options["$option_dec"] = $option_dec . $unit;
936 $option_inc += $factor;
937 $option_dec -= $factor;
938 if (isset($factors[$key + 1])
939 && $option_inc >= $value + $factors[$key + 1]) {
940 break;
944 ksort($options);
945 return $options;
949 * returns html selectbox for font sizes
951 * @uses $_SESSION['PMA_Config']
952 * @uses PMA_Config::get()
953 * @uses PMA_Config::getFontsizeOptions()
954 * @uses $GLOBALS['strFontSize']
955 * @static
956 * @param string $current_size currently slected font size with unit
957 * @return string html selectbox
959 function getFontsizeSelection()
961 $current_size = $_SESSION['PMA_Config']->get('fontsize');
962 $options = PMA_Config::getFontsizeOptions($current_size);
964 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
965 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
966 foreach ($options as $option) {
967 $return .= '<option value="' . $option . '"';
968 if ($option == $current_size) {
969 $return .= ' selected="selected"';
971 $return .= '>' . $option . '</option>' . "\n";
973 $return .= '</select>';
975 return $return;
979 * return complete font size selection form
981 * @uses PMA_generate_common_hidden_inputs()
982 * @uses PMA_Config::getFontsizeSelection()
983 * @uses $GLOBALS['strGo']
984 * @static
985 * @param string $current_size currently slected font size with unit
986 * @return string html selectbox
988 function getFontsizeForm()
990 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
991 . ' method="post" action="index.php" target="_parent">' . "\n"
992 . PMA_generate_common_hidden_inputs() . "\n"
993 . PMA_Config::getFontsizeSelection() . "\n"
994 . '<noscript>' . "\n"
995 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
996 . '</noscript>' . "\n"
997 . '</form>';