bug #2363919 [display] Incorrect size for view
[phpmyadmin/crack.git] / libraries / Config.class.php
blob086474c0d9a75f9e7d97d87ccea5911d514ddeac
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.1-dev');
89 /**
90 * @deprecated
92 $this->set('PMA_THEME_VERSION', 2);
93 /**
94 * @deprecated
96 $this->set('PMA_THEME_GENERATION', 2);
98 $this->checkPhpVersion();
99 $this->checkWebServerOs();
100 $this->checkWebServer();
101 $this->checkGd2();
102 $this->checkClient();
103 $this->checkUpload();
104 $this->checkUploadSize();
105 $this->checkOutputCompression();
109 * 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 //} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
172 // Konqueror 2.2.2 says Konqueror/2.2.2
173 // Konqueror 3.0.3 says Konqueror/3
174 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
175 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
176 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
177 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
178 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
179 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
180 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
181 } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
182 $this->set('PMA_USR_BROWSER_VER', '1.9');
183 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
184 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
185 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
186 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
187 } else {
188 $this->set('PMA_USR_BROWSER_VER', 0);
189 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
194 * Whether GD2 is present
196 function checkGd2()
198 if ($this->get('GD2Available') == 'yes') {
199 $this->set('PMA_IS_GD2', 1);
200 } elseif ($this->get('GD2Available') == 'no') {
201 $this->set('PMA_IS_GD2', 0);
202 } else {
203 if (!@function_exists('imagecreatetruecolor')) {
204 $this->set('PMA_IS_GD2', 0);
205 } else {
206 if (@function_exists('gd_info')) {
207 $gd_nfo = gd_info();
208 if (strstr($gd_nfo["GD Version"], '2.')) {
209 $this->set('PMA_IS_GD2', 1);
210 } else {
211 $this->set('PMA_IS_GD2', 0);
213 } else {
214 /* We must do hard way... but almost no chance to execute this */
215 ob_start();
216 phpinfo(INFO_MODULES); /* Only modules */
217 $a = strip_tags(ob_get_contents());
218 ob_end_clean();
219 /* Get GD version string from phpinfo output */
220 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
221 if (strstr($v, '2.')) {
222 $this->set('PMA_IS_GD2', 1);
223 } else {
224 $this->set('PMA_IS_GD2', 0);
226 } else {
227 $this->set('PMA_IS_GD2', 0);
235 * Whether the Web server php is running on is IIS
237 function checkWebServer()
239 if (PMA_getenv('SERVER_SOFTWARE')
240 // some versions return Microsoft-IIS, some Microsoft/IIS
241 // we could use a preg_match() but it's slower
242 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
243 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
244 $this->set('PMA_IS_IIS', 1);
245 } else {
246 $this->set('PMA_IS_IIS', 0);
251 * Whether the os php is running on is windows or not
253 function checkWebServerOs()
255 // Default to Unix or Equiv
256 $this->set('PMA_IS_WINDOWS', 0);
257 // If PHP_OS is defined then continue
258 if (defined('PHP_OS')) {
259 if (stristr(PHP_OS, 'win')) {
260 // Is it some version of Windows
261 $this->set('PMA_IS_WINDOWS', 1);
262 } elseif (stristr(PHP_OS, 'OS/2')) {
263 // Is it OS/2 (No file permissions like Windows)
264 $this->set('PMA_IS_WINDOWS', 1);
270 * detects PHP version
272 function checkPhpVersion()
274 $match = array();
275 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
276 phpversion(), $match)) {
277 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
278 phpversion(), $match);
280 if (isset($match) && ! empty($match[1])) {
281 if (! isset($match[2])) {
282 $match[2] = 0;
284 if (! isset($match[3])) {
285 $match[3] = 0;
287 $this->set('PMA_PHP_INT_VERSION',
288 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
289 } else {
290 $this->set('PMA_PHP_INT_VERSION', 0);
292 $this->set('PMA_PHP_STR_VERSION', phpversion());
296 * re-init object after loading from session file
297 * checks config file for changes and relaods if neccessary
299 function __wakeup()
301 if (! $this->checkConfigSource()
302 || $this->source_mtime !== filemtime($this->getSource())
303 || $this->default_source_mtime !== filemtime($this->default_source)
304 || $this->error_config_file
305 || $this->error_config_default_file) {
306 $this->settings = array();
307 $this->load();
308 $this->checkSystem();
311 // check for https needs to be done everytime,
312 // as https and http uses same session so this info can not be stored
313 // in session
314 $this->checkIsHttps();
316 $this->checkCollationConnection();
317 $this->checkFontsize();
321 * loads default values from default source
323 * @uses file_exists()
324 * @uses $this->default_source
325 * @uses $this->error_config_default_file
326 * @uses $this->settings
327 * @return boolean success
329 function loadDefaults()
331 $cfg = array();
332 if (! file_exists($this->default_source)) {
333 $this->error_config_default_file = true;
334 return false;
336 include $this->default_source;
338 $this->default_source_mtime = filemtime($this->default_source);
340 $this->default_server = $cfg['Servers'][1];
341 unset($cfg['Servers']);
343 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
345 $this->error_config_default_file = false;
347 return true;
351 * loads configuration from $source, usally the config file
352 * should be called on object creation and from __wakeup if config file
353 * has changed
355 * @param string $source config file
357 function load($source = null)
359 $this->loadDefaults();
361 if (null !== $source) {
362 $this->setSource($source);
365 if (! $this->checkConfigSource()) {
366 return false;
369 $cfg = array();
372 * Parses the configuration file
374 $old_error_reporting = error_reporting(0);
375 if (function_exists('file_get_contents')) {
376 $eval_result =
377 eval('?>' . trim(file_get_contents($this->getSource())));
378 } else {
379 $eval_result =
380 eval('?>' . trim(implode("\n", file($this->getSource()))));
382 error_reporting($old_error_reporting);
384 if ($eval_result === false) {
385 $this->error_config_file = true;
386 } else {
387 $this->error_config_file = false;
388 $this->source_mtime = filemtime($this->getSource());
392 * Backward compatibility code
394 if (!empty($cfg['DefaultTabTable'])) {
395 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
397 if (!empty($cfg['DefaultTabDatabase'])) {
398 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
401 $this->checkFontsize();
402 //$this->checkPmaAbsoluteUri();
403 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
405 // Handling of the collation must be done after merging of $cfg
406 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
407 // can have an effect. Note that the presence of collation
408 // information in a cookie has priority over what is defined
409 // in the default or user's config files.
411 * @todo check validity of $_COOKIE['pma_collation_connection']
413 if (! empty($_COOKIE['pma_collation_connection'])) {
414 $this->set('collation_connection',
415 strip_tags($_COOKIE['pma_collation_connection']));
416 } else {
417 $this->set('collation_connection',
418 $this->get('DefaultConnectionCollation'));
420 // Now, a collation information could come from REQUEST
421 // (an example of this: the collation selector in main.php)
422 // so the following handles the setting of collation_connection
423 // and later, in common.inc.php, the cookie will be set
424 // according to this.
425 $this->checkCollationConnection();
427 return true;
431 * set source
432 * @param string $source
434 function setSource($source)
436 $this->source = trim($source);
440 * checks if the config folder still exists and terminates app if true
442 function checkConfigFolder()
444 // Refuse to work while there still might be some world writable dir:
445 if (is_dir('./config')) {
446 die('Remove "./config" directory before using phpMyAdmin!');
451 * check config source
453 * @return boolean whether source is valid or not
455 function checkConfigSource()
457 if (! $this->getSource()) {
458 // no configuration file set at all
459 return false;
462 if (! file_exists($this->getSource())) {
463 // do not trigger error here
464 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
466 trigger_error(
467 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
468 E_USER_WARNING);
470 $this->source_mtime = 0;
471 return false;
474 if (! is_readable($this->getSource())) {
475 $this->source_mtime = 0;
476 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
479 // Check for permissions (on platforms that support it):
480 if ($this->get('CheckConfigurationPermissions')) {
481 $perms = @fileperms($this->getSource());
482 if (!($perms === false) && ($perms & 2)) {
483 // This check is normally done after loading configuration
484 $this->checkWebServerOs();
485 if ($this->get('PMA_IS_WINDOWS') == 0) {
486 $this->source_mtime = 0;
487 die('Wrong permissions on configuration file, should not be world writable!');
492 return true;
496 * returns specific config setting
497 * @param string $setting
498 * @return mixed value
500 function get($setting)
502 if (isset($this->settings[$setting])) {
503 return $this->settings[$setting];
505 return null;
509 * sets configuration variable
511 * @uses $this->settings
512 * @param string $setting configuration option
513 * @param string $value new value for configuration option
515 function set($setting, $value)
517 if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
518 $this->settings[$setting] = $value;
519 $this->set_mtime = time();
524 * returns source for current config
525 * @return string config source
527 function getSource()
529 return $this->source;
533 * returns a unique value to force a CSS reload if either the config
534 * or the theme changes
535 * must also check the pma_fontsize cookie in case there is no
536 * config file
537 * @return int Unix timestamp
539 function getThemeUniqueValue()
541 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) : '');
545 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
546 * set properly and, depending on browsers, inserting or updating a
547 * record might fail
549 function checkPmaAbsoluteUri()
551 // Setup a default value to let the people and lazy sysadmins work anyway,
552 // they'll get an error if the autodetect code doesn't work
553 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
554 $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
565 * REQUEST_URI contains PATH_INFO too, this is not what we want
566 * script-php/pathinfo/
567 if (PMA_getenv('REQUEST_URI')) {
568 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
569 if ($url === false) {
570 $url = array('path' => $_SERVER['REQUEST_URI']);
575 // If we don't have scheme, we didn't have full URL so we need to
576 // dig deeper
577 if (empty($url['scheme'])) {
578 // Scheme
579 if (PMA_getenv('HTTP_SCHEME')) {
580 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
581 } else {
582 $url['scheme'] =
583 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
584 ? 'https'
585 : 'http';
588 // Host and port
589 if (PMA_getenv('HTTP_HOST')) {
590 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
591 list($url['host'], $url['port']) =
592 explode(':', PMA_getenv('HTTP_HOST'));
593 } else {
594 $url['host'] = PMA_getenv('HTTP_HOST');
596 } elseif (PMA_getenv('SERVER_NAME')) {
597 $url['host'] = PMA_getenv('SERVER_NAME');
598 } else {
599 $this->error_pma_uri = true;
600 return false;
603 // If we didn't set port yet...
604 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
605 $url['port'] = PMA_getenv('SERVER_PORT');
608 // And finally the path could be already set from REQUEST_URI
609 if (empty($url['path'])) {
611 * REQUEST_URI contains PATH_INFO too, this is not what we want
612 * script-php/pathinfo/
613 if (PMA_getenv('PATH_INFO')) {
614 $path = parse_url(PMA_getenv('PATH_INFO'));
615 } else {
616 // PHP_SELF in CGI often points to cgi executable, so use it
617 // as last choice
619 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
621 $url['path'] = $path['path'];
625 // Make url from parts we have
626 $pma_absolute_uri = $url['scheme'] . '://';
627 // Was there user information?
628 if (!empty($url['user'])) {
629 $pma_absolute_uri .= $url['user'];
630 if (!empty($url['pass'])) {
631 $pma_absolute_uri .= ':' . $url['pass'];
633 $pma_absolute_uri .= '@';
635 // Add hostname
636 $pma_absolute_uri .= $url['host'];
637 // Add port, if it not the default one
638 if (! empty($url['port'])
639 && (($url['scheme'] == 'http' && $url['port'] != 80)
640 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
641 $pma_absolute_uri .= ':' . $url['port'];
643 // And finally path, without script name, the 'a' is there not to
644 // strip our directory, when path is only /pmadir/ without filename.
645 // Backslashes returned by Windows have to be changed.
646 // Only replace backslashes by forward slashes if on Windows,
647 // as the backslash could be valid on a non-Windows system.
648 if ($this->get('PMA_IS_WINDOWS') == 1) {
649 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
650 } else {
651 $path = dirname($url['path'] . 'a');
654 // To work correctly within transformations overview:
655 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
656 if ($this->get('PMA_IS_WINDOWS') == 1) {
657 $path = str_replace("\\", "/", dirname(dirname($path)));
658 } else {
659 $path = dirname(dirname($path));
662 // in vhost situations, there could be already an ending slash
663 if (substr($path, -1) != '/') {
664 $path .= '/';
666 $pma_absolute_uri .= $path;
668 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
669 // the autodetect code works well enough that we don't display the
670 // warning at all. The user can still set PmaAbsoluteUri manually.
671 // See
672 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
674 } else {
675 // The URI is specified, however users do often specify this
676 // wrongly, so we try to fix this.
678 // Adds a trailing slash et the end of the phpMyAdmin uri if it
679 // does not exist.
680 if (substr($pma_absolute_uri, -1) != '/') {
681 $pma_absolute_uri .= '/';
684 // If URI doesn't start with http:// or https://, we will add
685 // this.
686 if (substr($pma_absolute_uri, 0, 7) != 'http://'
687 && substr($pma_absolute_uri, 0, 8) != 'https://') {
688 $pma_absolute_uri =
689 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
690 ? 'https'
691 : 'http')
692 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
693 . $pma_absolute_uri;
696 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
700 * check selected collation_connection
701 * @todo check validity of $_REQUEST['collation_connection']
703 function checkCollationConnection()
705 if (! empty($_REQUEST['collation_connection'])) {
706 $this->set('collation_connection',
707 strip_tags($_REQUEST['collation_connection']));
712 * checks for font size configuration, and sets font size as requested by user
714 * @uses $_GET
715 * @uses $_POST
716 * @uses $_COOKIE
717 * @uses preg_match()
718 * @uses function_exists()
719 * @uses PMA_Config::set()
720 * @uses PMA_Config::get()
721 * @uses PMA_setCookie()
723 function checkFontsize()
725 $new_fontsize = '';
727 if (isset($_GET['fontsize'])) {
728 $new_fontsize = $_GET['fontsize'];
729 } elseif (isset($_POST['fontsize'])) {
730 $new_fontsize = $_POST['fontsize'];
731 } elseif (isset($_COOKIE['pma_fontsize'])) {
732 $new_fontsize = $_COOKIE['pma_fontsize'];
735 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
736 $this->set('fontsize', $new_fontsize);
737 } elseif (! $this->get('fontsize')) {
738 // 80% would correspond to the default browser font size
739 // of 16, but use 82% to help read the monoface font
740 $this->set('fontsize', '82%');
743 if (function_exists('PMA_setCookie')) {
744 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '82%');
749 * checks if upload is enabled
753 function checkUpload()
755 if (ini_get('file_uploads')) {
756 $this->set('enable_upload', true);
757 // if set "php_admin_value file_uploads Off" in httpd.conf
758 // ini_get() also returns the string "Off" in this case:
759 if ('off' == strtolower(ini_get('file_uploads'))) {
760 $this->set('enable_upload', false);
762 } else {
763 $this->set('enable_upload', false);
768 * Maximum upload size as limited by PHP
769 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
771 * this section generates $max_upload_size in bytes
773 function checkUploadSize()
775 if (! $filesize = ini_get('upload_max_filesize')) {
776 $filesize = "5M";
779 if ($postsize = ini_get('post_max_size')) {
780 $this->set('max_upload_size',
781 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
782 } else {
783 $this->set('max_upload_size', PMA_get_real_size($filesize));
788 * check for https
790 function checkIsHttps()
792 $this->set('is_https', PMA_Config::isHttps());
796 * @static
798 static public function isHttps()
800 $is_https = false;
802 $url = array();
804 // At first we try to parse REQUEST_URI, it might contain full URL,
805 if (PMA_getenv('REQUEST_URI')) {
806 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
807 if($url === false) {
808 $url = array();
812 // If we don't have scheme, we didn't have full URL so we need to
813 // dig deeper
814 if (empty($url['scheme'])) {
815 // Scheme
816 if (PMA_getenv('HTTP_SCHEME')) {
817 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
818 } else {
819 $url['scheme'] =
820 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
821 ? 'https'
822 : 'http';
826 if (isset($url['scheme'])
827 && $url['scheme'] == 'https') {
828 $is_https = true;
829 } else {
830 $is_https = false;
833 return $is_https;
837 * detect correct cookie path
839 function checkCookiePath()
841 $this->set('cookie_path', PMA_Config::getCookiePath());
845 * @static
847 static public function getCookiePath()
849 static $cookie_path = null;
851 if (null !== $cookie_path) {
852 return $cookie_path;
855 $url = '';
858 * REQUEST_URI contains PATH_INFO too, this is not what we want
859 * script-php/pathinfo/
860 if (PMA_getenv('REQUEST_URI')) {
861 $url = PMA_getenv('REQUEST_URI');
865 // If we don't have path
866 if (empty($url)) {
867 if ($GLOBALS['PMA_PHP_SELF']) {
868 // PHP_SELF in CGI often points to cgi executable, so use it
869 // as last choice
870 $url = $GLOBALS['PMA_PHP_SELF'];
871 // on IIS with PHP-CGI:
872 } elseif (PMA_getenv('SCRIPT_NAME')) {
873 $url = PMA_getenv('SCRIPT_NAME');
878 * REQUEST_URI contains PATH_INFO too, this is not what we want
879 * script-php/pathinfo/
880 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
881 if ($parsed_url === false) {
883 $parsed_url = array('path' => $url);
886 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
888 return $cookie_path;
892 * enables backward compatibility
894 function enableBc()
896 $GLOBALS['cfg'] = $this->settings;
897 $GLOBALS['default_server'] = $this->default_server;
898 unset($this->default_server);
899 $GLOBALS['collation_connection'] = $this->get('collation_connection');
900 $GLOBALS['is_upload'] = $this->get('enable_upload');
901 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
902 $GLOBALS['cookie_path'] = $this->get('cookie_path');
903 $GLOBALS['is_https'] = $this->get('is_https');
905 $defines = array(
906 'PMA_VERSION',
907 'PMA_THEME_VERSION',
908 'PMA_THEME_GENERATION',
909 'PMA_PHP_STR_VERSION',
910 'PMA_PHP_INT_VERSION',
911 'PMA_IS_WINDOWS',
912 'PMA_IS_IIS',
913 'PMA_IS_GD2',
914 'PMA_USR_OS',
915 'PMA_USR_BROWSER_VER',
916 'PMA_USR_BROWSER_AGENT'
919 foreach ($defines as $define) {
920 if (! defined($define)) {
921 define($define, $this->get($define));
927 * @todo finish
929 function save() {}
932 * returns options for font size selection
934 * @uses preg_replace()
935 * @uses ksort()
936 * @static
937 * @param string $current_size current selected font size with unit
938 * @return array selectable font sizes
940 static protected function _getFontsizeOptions($current_size = '82%')
942 $unit = preg_replace('/[0-9.]*/', '', $current_size);
943 $value = preg_replace('/[^0-9.]*/', '', $current_size);
945 $factors = array();
946 $options = array();
947 $options["$value"] = $value . $unit;
949 if ($unit === '%') {
950 $factors[] = 1;
951 $factors[] = 5;
952 $factors[] = 10;
953 } elseif ($unit === 'em') {
954 $factors[] = 0.05;
955 $factors[] = 0.2;
956 $factors[] = 1;
957 } elseif ($unit === 'pt') {
958 $factors[] = 0.5;
959 $factors[] = 2;
960 } elseif ($unit === 'px') {
961 $factors[] = 1;
962 $factors[] = 5;
963 $factors[] = 10;
964 } else {
965 //unknown font size unit
966 $factors[] = 0.05;
967 $factors[] = 0.2;
968 $factors[] = 1;
969 $factors[] = 5;
970 $factors[] = 10;
973 foreach ($factors as $key => $factor) {
974 $option_inc = $value + $factor;
975 $option_dec = $value - $factor;
976 while (count($options) < 21) {
977 $options["$option_inc"] = $option_inc . $unit;
978 if ($option_dec > $factors[0]) {
979 $options["$option_dec"] = $option_dec . $unit;
981 $option_inc += $factor;
982 $option_dec -= $factor;
983 if (isset($factors[$key + 1])
984 && $option_inc >= $value + $factors[$key + 1]) {
985 break;
989 ksort($options);
990 return $options;
994 * returns html selectbox for font sizes
996 * @uses $_SESSION['PMA_Config']
997 * @uses PMA_Config::get()
998 * @uses PMA_Config::_getFontsizeOptions()
999 * @uses $GLOBALS['strFontSize']
1000 * @static
1001 * @param string $current_size currently slected font size with unit
1002 * @return string html selectbox
1004 static protected function _getFontsizeSelection()
1006 $current_size = $_SESSION['PMA_Config']->get('fontsize');
1007 // for the case when there is no config file (this is supported)
1008 if (empty($current_size)) {
1009 if (isset($_COOKIE['pma_fontsize'])) {
1010 $current_size = $_COOKIE['pma_fontsize'];
1011 } else {
1012 $current_size = '82%';
1015 $options = PMA_Config::_getFontsizeOptions($current_size);
1017 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1018 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1019 foreach ($options as $option) {
1020 $return .= '<option value="' . $option . '"';
1021 if ($option == $current_size) {
1022 $return .= ' selected="selected"';
1024 $return .= '>' . $option . '</option>' . "\n";
1026 $return .= '</select>';
1028 return $return;
1032 * return complete font size selection form
1034 * @uses PMA_generate_common_hidden_inputs()
1035 * @uses PMA_Config::_getFontsizeSelection()
1036 * @uses $GLOBALS['strGo']
1037 * @static
1038 * @param string $current_size currently slected font size with unit
1039 * @return string html selectbox
1041 static public function getFontsizeForm()
1043 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1044 . ' method="post" action="index.php" target="_parent">' . "\n"
1045 . PMA_generate_common_hidden_inputs() . "\n"
1046 . PMA_Config::_getFontsizeSelection() . "\n"
1047 . '<noscript>' . "\n"
1048 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1049 . '</noscript>' . "\n"
1050 . '</form>';