2.10.0.2 release
[phpmyadmin/crack.git] / libraries / Config.class.php
blob4da17f0038dc6903fd709c37c4b428aca393973f
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;
31 var $set_mtime = 0;
33 /**
34 * @var boolean
36 var $error_config_file = false;
38 /**
39 * @var boolean
41 var $error_config_default_file = false;
43 /**
44 * @var boolean
46 var $error_pma_uri = false;
48 /**
49 * @var array
51 var $default_server = array();
53 /**
54 * @var boolean wether init is done or mot
55 * set this to false to force some initial checks
56 * like checking for required functions
58 var $done = false;
60 /**
61 * constructor
63 * @param string source to read config from
65 function __construct($source = null)
67 $this->settings = array();
69 // functions need to refresh in case of config file changed goes in
70 // PMA_Config::load()
71 $this->load($source);
73 // other settings, independant from config file, comes in
74 $this->checkSystem();
76 $this->checkIsHttps();
79 /**
80 * sets system and application settings
82 function checkSystem()
84 $this->set('PMA_VERSION', '2.10.0.2');
85 /**
86 * @deprecated
88 $this->set('PMA_THEME_VERSION', 2);
89 /**
90 * @deprecated
92 $this->set('PMA_THEME_GENERATION', 2);
94 $this->checkPhpVersion();
95 $this->checkWebServerOs();
96 $this->checkWebServer();
97 $this->checkGd2();
98 $this->checkClient();
99 $this->checkUpload();
100 $this->checkUploadSize();
101 $this->checkOutputCompression();
105 * wether to use gzip output compression or not
107 function checkOutputCompression()
109 // If zlib output compression is set in the php configuration file, no
110 // output buffering should be run
111 if (@ini_get('zlib.output_compression')) {
112 $this->set('OBGzip', false);
115 // disable output-buffering (if set to 'auto') for IE6, else enable it.
116 if (strtolower($this->get('OBGzip')) == 'auto') {
117 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
118 && $this->get('PMA_USR_BROWSER_VER') >= 6
119 && $this->get('PMA_USR_BROWSER_VER') < 7) {
120 $this->set('OBGzip', false);
121 } else {
122 $this->set('OBGzip', true);
128 * Determines platform (OS), browser and version of the user
129 * Based on a phpBuilder article:
130 * @see http://www.phpbuilder.net/columns/tim20000821.php
132 function checkClient()
134 if (PMA_getenv('HTTP_USER_AGENT')) {
135 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
136 } elseif (!isset($HTTP_USER_AGENT)) {
137 $HTTP_USER_AGENT = '';
140 // 1. Platform
141 if (strstr($HTTP_USER_AGENT, 'Win')) {
142 $this->set('PMA_USR_OS', 'Win');
143 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
144 $this->set('PMA_USR_OS', 'Mac');
145 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
146 $this->set('PMA_USR_OS', 'Linux');
147 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
148 $this->set('PMA_USR_OS', 'Unix');
149 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
150 $this->set('PMA_USR_OS', 'OS/2');
151 } else {
152 $this->set('PMA_USR_OS', 'Other');
155 // 2. browser and version
156 // (must check everything else before Mozilla)
158 if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
159 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
160 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
161 } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
162 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
163 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
164 } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
165 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
166 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
167 //} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
168 // Konqueror 2.2.2 says Konqueror/2.2.2
169 // Konqueror 3.0.3 says Konqueror/3
170 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
171 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
172 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
173 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
174 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
175 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
176 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
177 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
178 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
179 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
180 } else {
181 $this->set('PMA_USR_BROWSER_VER', 0);
182 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
187 * Whether GD2 is present
189 function checkGd2()
191 if ($this->get('GD2Available') == 'yes') {
192 $this->set('PMA_IS_GD2', 1);
193 } elseif ($this->get('GD2Available') == 'no') {
194 $this->set('PMA_IS_GD2', 0);
195 } else {
196 if (!@extension_loaded('gd')) {
197 PMA_dl('gd');
199 if (!@function_exists('imagecreatetruecolor')) {
200 $this->set('PMA_IS_GD2', 0);
201 } else {
202 if (@function_exists('gd_info')) {
203 $gd_nfo = gd_info();
204 if (strstr($gd_nfo["GD Version"], '2.')) {
205 $this->set('PMA_IS_GD2', 1);
206 } else {
207 $this->set('PMA_IS_GD2', 0);
209 } else {
210 /* We must do hard way... */
211 ob_start();
212 phpinfo(INFO_MODULES); /* Only modules */
213 $a = strip_tags(ob_get_contents());
214 ob_end_clean();
215 /* Get GD version string from phpinfo output */
216 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
217 if (strstr($v, '2.')) {
218 $this->set('PMA_IS_GD2', 1);
219 } else {
220 $this->set('PMA_IS_GD2', 0);
222 } else {
223 $this->set('PMA_IS_GD2', 0);
231 * Whether the Web server php is running on is IIS
233 function checkWebServer()
235 if (PMA_getenv('SERVER_SOFTWARE')
236 // some versions return Microsoft-IIS, some Microsoft/IIS
237 // we could use a preg_match() but it's slower
238 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
239 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
240 $this->set('PMA_IS_IIS', 1);
241 } else {
242 $this->set('PMA_IS_IIS', 0);
247 * Whether the os php is running on is windows or not
249 function checkWebServerOs()
251 // Default to Unix or Equiv
252 $this->set('PMA_IS_WINDOWS', 0);
253 // If PHP_OS is defined then continue
254 if (defined('PHP_OS')) {
255 if (stristr(PHP_OS, 'win') ) {
256 // Is it some version of Windows
257 $this->set('PMA_IS_WINDOWS', 1);
258 } elseif (stristr(PHP_OS, 'OS/2')) {
259 // Is it OS/2 (No file permissions like Windows)
260 $this->set('PMA_IS_WINDOWS', 1);
266 * detects PHP version
268 function checkPhpVersion()
270 $match = array();
271 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
272 phpversion(), $match)) {
273 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
274 phpversion(), $match);
276 if (isset($match) && ! empty($match[1])) {
277 if (! isset($match[2])) {
278 $match[2] = 0;
280 if (! isset($match[3])) {
281 $match[3] = 0;
283 $this->set('PMA_PHP_INT_VERSION',
284 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
285 } else {
286 $this->set('PMA_PHP_INT_VERSION', 0);
288 $this->set('PMA_PHP_STR_VERSION', phpversion());
292 * re-init object after loading from session file
293 * checks config file for changes and relaods if neccessary
295 function __wakeup()
297 if (! $this->checkConfigSource()
298 || $this->source_mtime !== filemtime($this->getSource())
299 || $this->default_source_mtime !== filemtime($this->default_source)
300 || $this->error_config_file
301 || $this->error_config_default_file) {
302 $this->settings = array();
303 $this->load();
304 $this->checkSystem();
307 // check for https needs to be done everytime,
308 // as https and http uses same session so this info can not be stored
309 // in session
310 $this->checkIsHttps();
312 $this->checkCollationConnection();
313 $this->checkFontsize();
317 * loads default values from default source
319 * @uses file_exists()
320 * @uses $this->default_source
321 * @uses $this->error_config_default_file
322 * @uses $this->settings
323 * @return boolean success
325 function loadDefaults()
327 $cfg = array();
328 if (! file_exists($this->default_source)) {
329 $this->error_config_default_file = true;
330 return false;
332 include $this->default_source;
334 $this->default_source_mtime = filemtime($this->default_source);
336 $this->default_server = $cfg['Servers'][1];
337 unset($cfg['Servers']);
339 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
341 $this->error_config_default_file = false;
343 return true;
347 * loads configuration from $source, usally the config file
348 * should be called on object creation and from __wakeup if config file
349 * has changed
351 * @param string $source config file
353 function load($source = null)
355 $this->loadDefaults();
357 if (null !== $source) {
358 $this->setSource($source);
361 if (! $this->checkConfigSource()) {
362 return false;
365 $cfg = array();
368 * Parses the configuration file
370 $old_error_reporting = error_reporting(0);
371 if (function_exists('file_get_contents')) {
372 $eval_result =
373 eval('?>' . trim(file_get_contents($this->getSource())));
374 } else {
375 $eval_result =
376 eval('?>' . trim(implode("\n", file($this->getSource()))));
378 error_reporting($old_error_reporting);
380 if ($eval_result === false) {
381 $this->error_config_file = true;
382 } else {
383 $this->error_config_file = false;
384 $this->source_mtime = filemtime($this->getSource());
388 * Backward compatibility code
390 if (!empty($cfg['DefaultTabTable'])) {
391 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
393 if (!empty($cfg['DefaultTabDatabase'])) {
394 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
397 $this->checkFontsize();
398 //$this->checkPmaAbsoluteUri();
399 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
401 // Handling of the collation must be done after merging of $cfg
402 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
403 // can have an effect. Note that the presence of collation
404 // information in a cookie has priority over what is defined
405 // in the default or user's config files.
407 * @todo check validity of $_COOKIE['pma_collation_connection']
409 if (! empty($_COOKIE['pma_collation_connection'])) {
410 $this->set('collation_connection',
411 strip_tags($_COOKIE['pma_collation_connection']));
412 } else {
413 $this->set('collation_connection',
414 $this->get('DefaultConnectionCollation'));
416 // Now, a collation information could come from REQUEST
417 // (an example of this: the collation selector in main.php)
418 // so the following handles the setting of collation_connection
419 // and later, in common.lib.php, the cookie will be set
420 // according to this.
421 $this->checkCollationConnection();
423 return true;
427 * set source
428 * @param string $source
430 function setSource($source)
432 $this->source = trim($source);
436 * checks if the config folder still exists and terminates app if true
438 function checkConfigFolder()
440 // Refuse to work while there still might be some world writable dir:
441 if (is_dir('./config')) {
442 die('Remove "./config" directory before using phpMyAdmin!');
447 * check config source
449 * @return boolean wether source is valid or not
451 function checkConfigSource()
453 if (! $this->getSource()) {
454 // no configuration file set at all
455 return false;
458 if (! file_exists($this->getSource())) {
459 // do not trigger error here
460 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
462 trigger_error(
463 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
464 E_USER_WARNING);
466 $this->source_mtime = 0;
467 return false;
470 if (! is_readable($this->getSource())) {
471 $this->source_mtime = 0;
472 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
475 // Check for permissions (on platforms that support it):
476 $perms = @fileperms($this->getSource());
477 if (!($perms === false) && ($perms & 2)) {
478 // This check is normally done after loading configuration
479 $this->checkWebServerOs();
480 if ($this->get('PMA_IS_WINDOWS') == 0) {
481 $this->source_mtime = 0;
482 die('Wrong permissions on configuration file, should not be world writable!');
486 return true;
490 * returns specific config setting
491 * @param string $setting
492 * @return mixed value
494 function get($setting)
496 if (isset($this->settings[$setting])) {
497 return $this->settings[$setting];
499 return null;
503 * sets configuration variable
505 * @uses $this->settings
506 * @param string $setting configuration option
507 * @param string $value new value for configuration option
509 function set($setting, $value)
511 if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
512 $this->settings[$setting] = $value;
513 $this->set_mtime = time();
518 * returns source for current config
519 * @return string config source
521 function getSource()
523 return $this->source;
527 * old PHP 4 style constructor
529 * @deprecated
531 function PMA_Config($source = null)
533 $this->__construct($source);
537 * returns time of last config change.
538 * @return int Unix timestamp
540 function getMtime()
542 return max($this->source_mtime, $this->default_source_mtime, $this->set_mtime);
546 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
547 * set properly and, depending on browsers, inserting or updating a
548 * record might fail
550 function checkPmaAbsoluteUri()
552 // Setup a default value to let the people and lazy syadmins work anyway,
553 // they'll get an error if the autodetect code doesn't work
554 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
555 $is_https = $this->get('is_https');
556 if (strlen($pma_absolute_uri) < 5
557 // needed to catch http/https switch
558 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
559 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
561 $url = array();
563 // At first we try to parse REQUEST_URI, it might contain full URL
564 if (PMA_getenv('REQUEST_URI')) {
565 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
566 if ($url === false) {
567 $url = array( 'path' => $_SERVER['REQUEST_URI'] );
571 // If we don't have scheme, we didn't have full URL so we need to
572 // dig deeper
573 if (empty($url['scheme'])) {
574 // Scheme
575 if (PMA_getenv('HTTP_SCHEME')) {
576 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
577 } else {
578 $url['scheme'] =
579 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
580 ? 'https'
581 : 'http';
584 // Host and port
585 if (PMA_getenv('HTTP_HOST')) {
586 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
587 list($url['host'], $url['port']) =
588 explode(':', PMA_getenv('HTTP_HOST'));
589 } else {
590 $url['host'] = PMA_getenv('HTTP_HOST');
592 } elseif (PMA_getenv('SERVER_NAME')) {
593 $url['host'] = PMA_getenv('SERVER_NAME');
594 } else {
595 $this->error_pma_uri = true;
596 return false;
599 // If we didn't set port yet...
600 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
601 $url['port'] = PMA_getenv('SERVER_PORT');
604 // And finally the path could be already set from REQUEST_URI
605 if (empty($url['path'])) {
606 if (PMA_getenv('PATH_INFO')) {
607 $path = parse_url(PMA_getenv('PATH_INFO'));
608 } else {
609 // PHP_SELF in CGI often points to cgi executable, so use it
610 // as last choice
611 $path = parse_url(PMA_getenv('PHP_SELF'));
613 $url['path'] = $path['path'];
617 // Make url from parts we have
618 $pma_absolute_uri = $url['scheme'] . '://';
619 // Was there user information?
620 if (!empty($url['user'])) {
621 $pma_absolute_uri .= $url['user'];
622 if (!empty($url['pass'])) {
623 $pma_absolute_uri .= ':' . $url['pass'];
625 $pma_absolute_uri .= '@';
627 // Add hostname
628 $pma_absolute_uri .= $url['host'];
629 // Add port, if it not the default one
630 if (! empty($url['port'])
631 && (($url['scheme'] == 'http' && $url['port'] != 80)
632 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
633 $pma_absolute_uri .= ':' . $url['port'];
635 // And finally path, without script name, the 'a' is there not to
636 // strip our directory, when path is only /pmadir/ without filename.
637 // Backslashes returned by Windows have to be changed.
638 // Only replace backslashes by forward slashes if on Windows,
639 // as the backslash could be valid on a non-Windows system.
640 if ($this->get('PMA_IS_WINDOWS') == 1) {
641 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
642 } else {
643 $path = dirname($url['path'] . 'a');
646 // To work correctly within transformations overview:
647 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
648 if ($this->get('PMA_IS_WINDOWS') == 1) {
649 $path = str_replace("\\", "/", dirname(dirname($path)));
650 } else {
651 $path = dirname(dirname($path));
654 // in vhost situations, there could be already an ending slash
655 if (substr($path, -1) != '/') {
656 $path .= '/';
658 $pma_absolute_uri .= $path;
660 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
661 // the autodetect code works well enough that we don't display the
662 // warning at all. The user can still set PmaAbsoluteUri manually.
663 // See
664 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
666 } else {
667 // The URI is specified, however users do often specify this
668 // wrongly, so we try to fix this.
670 // Adds a trailing slash et the end of the phpMyAdmin uri if it
671 // does not exist.
672 if (substr($pma_absolute_uri, -1) != '/') {
673 $pma_absolute_uri .= '/';
676 // If URI doesn't start with http:// or https://, we will add
677 // this.
678 if (substr($pma_absolute_uri, 0, 7) != 'http://'
679 && substr($pma_absolute_uri, 0, 8) != 'https://') {
680 $pma_absolute_uri =
681 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
682 ? 'https'
683 : 'http')
684 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
685 . $pma_absolute_uri;
689 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
693 * check selected collation_connection
694 * @todo check validity of $_REQUEST['collation_connection']
696 function checkCollationConnection()
698 // (could be improved by executing it after the MySQL connection only if
699 // PMA_MYSQL_INT_VERSION >= 40100)
700 if (! empty($_REQUEST['collation_connection'])) {
701 $this->set('collation_connection',
702 strip_tags($_REQUEST['collation_connection']));
707 * checks for font size configuration, and sets font size as requested by user
709 * @uses $_GET
710 * @uses $_POST
711 * @uses $_COOKIE
712 * @uses preg_match()
713 * @uses function_exists()
714 * @uses PMA_Config::set()
715 * @uses PMA_Config::get()
716 * @uses PMA_setCookie()
718 function checkFontsize()
720 $new_fontsize = '';
722 if (isset($_GET['fontsize'])) {
723 $new_fontsize = $_GET['fontsize'];
724 } elseif (isset($_POST['fontsize'])) {
725 $new_fontsize = $_POST['fontsize'];
726 } elseif (isset($_COOKIE['pma_fontsize'])) {
727 $new_fontsize = $_COOKIE['pma_fontsize'];
730 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
731 $this->set('fontsize', $new_fontsize);
732 } elseif (! $this->get('fontsize')) {
733 $this->set('fontsize', '100%');
736 if (function_exists('PMA_setCookie')) {
737 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '100%');
742 * checks if upload is enabled
745 function checkUpload()
747 $this->set('enable_upload', true);
748 if (strtolower(@ini_get('file_uploads')) == 'off'
749 || @ini_get('file_uploads') == 0) {
750 $this->set('enable_upload', false);
755 * Maximum upload size as limited by PHP
756 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
758 * this section generates $max_upload_size in bytes
760 function checkUploadSize()
762 if (! $filesize = ini_get('upload_max_filesize')) {
763 $filesize = "5M";
766 if ($postsize = ini_get('post_max_size')) {
767 $this->set('max_upload_size',
768 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
769 } else {
770 $this->set('max_upload_size', PMA_get_real_size($filesize));
775 * check for https
777 function checkIsHttps()
779 $this->set('is_https', PMA_Config::isHttps());
783 * @static
785 function isHttps()
787 $is_https = false;
789 $url = array();
791 // At first we try to parse REQUEST_URI, it might contain full URL,
792 if (PMA_getenv('REQUEST_URI')) {
793 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
794 if($url === false) {
795 $url = array();
799 // If we don't have scheme, we didn't have full URL so we need to
800 // dig deeper
801 if (empty($url['scheme'])) {
802 // Scheme
803 if (PMA_getenv('HTTP_SCHEME')) {
804 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
805 } else {
806 $url['scheme'] =
807 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
808 ? 'https'
809 : 'http';
813 if (isset($url['scheme'])
814 && $url['scheme'] == 'https') {
815 $is_https = true;
816 } else {
817 $is_https = false;
820 return $is_https;
824 * detect correct cookie path
826 function checkCookiePath()
828 $this->set('cookie_path', PMA_Config::getCookiePath());
832 * @static
834 function getCookiePath()
836 static $cookie_path = null;
838 if (null !== $cookie_path) {
839 return $cookie_path;
842 $url = '';
844 if (PMA_getenv('REQUEST_URI')) {
845 $url = PMA_getenv('REQUEST_URI');
848 // If we don't have path
849 if (empty($url)) {
850 if (PMA_getenv('PATH_INFO')) {
851 $url = PMA_getenv('PATH_INFO');
852 } elseif (PMA_getenv('PHP_SELF')) {
853 // PHP_SELF in CGI often points to cgi executable, so use it
854 // as last choice
855 $url = PMA_getenv('PHP_SELF');
856 } elseif (PMA_getenv('SCRIPT_NAME')) {
857 $url = PMA_getenv('PHP_SELF');
861 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
862 if ($parsed_url === false) {
863 $parsed_url = array('path' => $url);
866 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
868 return $cookie_path;
872 * enables backward compatibility
874 function enableBc()
876 $GLOBALS['cfg'] =& $this->settings;
877 $GLOBALS['default_server'] =& $this->default_server;
878 $GLOBALS['collation_connection'] = $this->get('collation_connection');
879 $GLOBALS['is_upload'] = $this->get('enable_upload');
880 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
881 $GLOBALS['cookie_path'] = $this->get('cookie_path');
882 $GLOBALS['is_https'] = $this->get('is_https');
884 $defines = array(
885 'PMA_VERSION',
886 'PMA_THEME_VERSION',
887 'PMA_THEME_GENERATION',
888 'PMA_PHP_STR_VERSION',
889 'PMA_PHP_INT_VERSION',
890 'PMA_IS_WINDOWS',
891 'PMA_IS_IIS',
892 'PMA_IS_GD2',
893 'PMA_USR_OS',
894 'PMA_USR_BROWSER_VER',
895 'PMA_USR_BROWSER_AGENT',
898 foreach ($defines as $define) {
899 if (! defined($define)) {
900 define($define, $this->get($define));
906 * @todo finish
908 function save() {}
911 * returns options for font size selection
913 * @uses preg_replace()
914 * @uses ksort()
915 * @static
916 * @param string $current_size current selected font size with unit
917 * @return array selectable font sizes
919 function getFontsizeOptions($current_size = '100%')
921 $unit = preg_replace('/[0-9.]*/', '', $current_size);
922 $value = preg_replace('/[^0-9.]*/', '', $current_size);
924 $factors = array();
925 $options = array();
926 $options["$value"] = $value . $unit;
928 if ($unit === '%') {
929 $factors[] = 1;
930 $factors[] = 5;
931 $factors[] = 10;
932 } elseif ($unit === 'em') {
933 $factors[] = 0.05;
934 $factors[] = 0.2;
935 $factors[] = 1;
936 } elseif ($unit === 'pt') {
937 $factors[] = 0.5;
938 $factors[] = 2;
939 } elseif ($unit === 'px') {
940 $factors[] = 1;
941 $factors[] = 5;
942 $factors[] = 10;
943 } else {
944 //unknown font size unit
945 $factors[] = 0.05;
946 $factors[] = 0.2;
947 $factors[] = 1;
948 $factors[] = 5;
949 $factors[] = 10;
952 foreach ($factors as $key => $factor) {
953 $option_inc = $value + $factor;
954 $option_dec = $value - $factor;
955 while (count($options) < 21) {
956 $options["$option_inc"] = $option_inc . $unit;
957 if ($option_dec > $factors[0]) {
958 $options["$option_dec"] = $option_dec . $unit;
960 $option_inc += $factor;
961 $option_dec -= $factor;
962 if (isset($factors[$key + 1])
963 && $option_inc >= $value + $factors[$key + 1]) {
964 break;
968 ksort($options);
969 return $options;
973 * returns html selectbox for font sizes
975 * @uses $_SESSION['PMA_Config']
976 * @uses PMA_Config::get()
977 * @uses PMA_Config::getFontsizeOptions()
978 * @uses $GLOBALS['strFontSize']
979 * @static
980 * @param string $current_size currently slected font size with unit
981 * @return string html selectbox
983 function getFontsizeSelection()
985 $current_size = $_SESSION['PMA_Config']->get('fontsize');
986 $options = PMA_Config::getFontsizeOptions($current_size);
988 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
989 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
990 foreach ($options as $option) {
991 $return .= '<option value="' . $option . '"';
992 if ($option == $current_size) {
993 $return .= ' selected="selected"';
995 $return .= '>' . $option . '</option>' . "\n";
997 $return .= '</select>';
999 return $return;
1003 * return complete font size selection form
1005 * @uses PMA_generate_common_hidden_inputs()
1006 * @uses PMA_Config::getFontsizeSelection()
1007 * @uses $GLOBALS['strGo']
1008 * @static
1009 * @param string $current_size currently slected font size with unit
1010 * @return string html selectbox
1012 function getFontsizeForm()
1014 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1015 . ' method="post" action="index.php" target="_parent">' . "\n"
1016 . PMA_generate_common_hidden_inputs() . "\n"
1017 . PMA_Config::getFontsizeSelection() . "\n"
1018 . '<noscript>' . "\n"
1019 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1020 . '</noscript>' . "\n"
1021 . '</form>';