Converting number of Excel column names no longer limited
[phpmyadmin/arisferyanto.git] / libraries / Config.class.php
bloba7b448bee01cc0c3a5e40ccbc48e0e6929a838af
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
11 * Load vendor configuration.
13 require_once('./libraries/vendor_config.php');
15 /**
16 * Configuration class
18 * @package phpMyAdmin
20 class PMA_Config
22 /**
23 * @var string default config source
25 var $default_source = './libraries/config.default.php';
27 /**
28 * @var array configuration settings
30 var $settings = array();
32 /**
33 * @var string config source
35 var $source = '';
37 /**
38 * @var int source modification time
40 var $source_mtime = 0;
41 var $default_source_mtime = 0;
42 var $set_mtime = 0;
44 /**
45 * @var boolean
47 var $error_config_file = false;
49 /**
50 * @var boolean
52 var $error_config_default_file = false;
54 /**
55 * @var boolean
57 var $error_pma_uri = false;
59 /**
60 * @var array
62 var $default_server = array();
64 /**
65 * @var boolean whether init is done or not
66 * set this to false to force some initial checks
67 * like checking for required functions
69 var $done = false;
71 /**
72 * constructor
74 * @param string source to read config from
76 function __construct($source = null)
78 $this->settings = array();
80 // functions need to refresh in case of config file changed goes in
81 // PMA_Config::load()
82 $this->load($source);
84 // other settings, independent from config file, comes in
85 $this->checkSystem();
87 $this->checkIsHttps();
90 /**
91 * sets system and application settings
93 function checkSystem()
95 $this->set('PMA_VERSION', '3.3.5-dev');
96 /**
97 * @deprecated
99 $this->set('PMA_THEME_VERSION', 2);
101 * @deprecated
103 $this->set('PMA_THEME_GENERATION', 2);
105 $this->checkPhpVersion();
106 $this->checkWebServerOs();
107 $this->checkWebServer();
108 $this->checkGd2();
109 $this->checkClient();
110 $this->checkUpload();
111 $this->checkUploadSize();
112 $this->checkOutputCompression();
116 * whether to use gzip output compression or not
118 function checkOutputCompression()
120 // If zlib output compression is set in the php configuration file, no
121 // output buffering should be run
122 if (@ini_get('zlib.output_compression')) {
123 $this->set('OBGzip', false);
126 // disable output-buffering (if set to 'auto') for IE6, else enable it.
127 if (strtolower($this->get('OBGzip')) == 'auto') {
128 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
129 && $this->get('PMA_USR_BROWSER_VER') >= 6
130 && $this->get('PMA_USR_BROWSER_VER') < 7) {
131 $this->set('OBGzip', false);
132 } else {
133 $this->set('OBGzip', true);
139 * Determines platform (OS), browser and version of the user
140 * Based on a phpBuilder article:
141 * @see http://www.phpbuilder.net/columns/tim20000821.php
143 function checkClient()
145 if (PMA_getenv('HTTP_USER_AGENT')) {
146 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
147 } elseif (!isset($HTTP_USER_AGENT)) {
148 $HTTP_USER_AGENT = '';
151 // 1. Platform
152 if (strstr($HTTP_USER_AGENT, 'Win')) {
153 $this->set('PMA_USR_OS', 'Win');
154 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
155 $this->set('PMA_USR_OS', 'Mac');
156 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
157 $this->set('PMA_USR_OS', 'Linux');
158 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
159 $this->set('PMA_USR_OS', 'Unix');
160 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
161 $this->set('PMA_USR_OS', 'OS/2');
162 } else {
163 $this->set('PMA_USR_OS', 'Other');
166 // 2. browser and version
167 // (must check everything else before Mozilla)
169 if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
170 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
171 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
172 } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
173 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
174 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
175 } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
176 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
177 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
178 // Konqueror 2.2.2 says Konqueror/2.2.2
179 // Konqueror 3.0.3 says Konqueror/3
180 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
181 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
182 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
183 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
184 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
185 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
186 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
187 } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
188 $this->set('PMA_USR_BROWSER_VER', '1.9');
189 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
190 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
191 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
192 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
193 } else {
194 $this->set('PMA_USR_BROWSER_VER', 0);
195 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
200 * Whether GD2 is present
202 function checkGd2()
204 if ($this->get('GD2Available') == 'yes') {
205 $this->set('PMA_IS_GD2', 1);
206 } elseif ($this->get('GD2Available') == 'no') {
207 $this->set('PMA_IS_GD2', 0);
208 } else {
209 if (!@function_exists('imagecreatetruecolor')) {
210 $this->set('PMA_IS_GD2', 0);
211 } else {
212 if (@function_exists('gd_info')) {
213 $gd_nfo = gd_info();
214 if (strstr($gd_nfo["GD Version"], '2.')) {
215 $this->set('PMA_IS_GD2', 1);
216 } else {
217 $this->set('PMA_IS_GD2', 0);
219 } else {
220 /* We must do hard way... but almost no chance to execute this */
221 ob_start();
222 phpinfo(INFO_MODULES); /* Only modules */
223 $a = strip_tags(ob_get_contents());
224 ob_end_clean();
225 /* Get GD version string from phpinfo output */
226 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
227 if (strstr($v, '2.')) {
228 $this->set('PMA_IS_GD2', 1);
229 } else {
230 $this->set('PMA_IS_GD2', 0);
232 } else {
233 $this->set('PMA_IS_GD2', 0);
241 * Whether the Web server php is running on is IIS
243 function checkWebServer()
245 if (PMA_getenv('SERVER_SOFTWARE')
246 // some versions return Microsoft-IIS, some Microsoft/IIS
247 // we could use a preg_match() but it's slower
248 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
249 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
250 $this->set('PMA_IS_IIS', 1);
251 } else {
252 $this->set('PMA_IS_IIS', 0);
257 * Whether the os php is running on is windows or not
259 function checkWebServerOs()
261 // Default to Unix or Equiv
262 $this->set('PMA_IS_WINDOWS', 0);
263 // If PHP_OS is defined then continue
264 if (defined('PHP_OS')) {
265 if (stristr(PHP_OS, 'win')) {
266 // Is it some version of Windows
267 $this->set('PMA_IS_WINDOWS', 1);
268 } elseif (stristr(PHP_OS, 'OS/2')) {
269 // Is it OS/2 (No file permissions like Windows)
270 $this->set('PMA_IS_WINDOWS', 1);
276 * detects PHP version
278 function checkPhpVersion()
280 $match = array();
281 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
282 phpversion(), $match)) {
283 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
284 phpversion(), $match);
286 if (isset($match) && ! empty($match[1])) {
287 if (! isset($match[2])) {
288 $match[2] = 0;
290 if (! isset($match[3])) {
291 $match[3] = 0;
293 $this->set('PMA_PHP_INT_VERSION',
294 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
295 } else {
296 $this->set('PMA_PHP_INT_VERSION', 0);
298 $this->set('PMA_PHP_STR_VERSION', phpversion());
302 * re-init object after loading from session file
303 * checks config file for changes and relaods if neccessary
305 function __wakeup()
307 if (SKIP_MTIME_CONFIG_CHECK
308 || ! $this->checkConfigSource()
309 || $this->source_mtime !== filemtime($this->getSource())
310 || $this->default_source_mtime !== filemtime($this->default_source)
311 || $this->error_config_file
312 || $this->error_config_default_file) {
313 $this->settings = array();
314 $this->load();
315 $this->checkSystem();
318 // check for https needs to be done everytime,
319 // as https and http uses same session so this info can not be stored
320 // in session
321 $this->checkIsHttps();
323 $this->checkCollationConnection();
324 $this->checkFontsize();
328 * loads default values from default source
330 * @uses file_exists()
331 * @uses $this->default_source
332 * @uses $this->error_config_default_file
333 * @uses $this->settings
334 * @return boolean success
336 function loadDefaults()
338 $cfg = array();
339 if (! file_exists($this->default_source)) {
340 $this->error_config_default_file = true;
341 return false;
343 include $this->default_source;
345 $this->default_source_mtime = filemtime($this->default_source);
347 $this->default_server = $cfg['Servers'][1];
348 unset($cfg['Servers']);
350 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
352 $this->error_config_default_file = false;
354 return true;
358 * loads configuration from $source, usally the config file
359 * should be called on object creation and from __wakeup if config file
360 * has changed
362 * @param string $source config file
364 function load($source = null)
366 $this->loadDefaults();
368 if (null !== $source) {
369 $this->setSource($source);
372 if (! $this->checkConfigSource()) {
373 return false;
376 $cfg = array();
379 * Parses the configuration file
381 $old_error_reporting = error_reporting(0);
382 if (function_exists('file_get_contents')) {
383 $eval_result =
384 eval('?>' . trim(file_get_contents($this->getSource())));
385 } else {
386 $eval_result =
387 eval('?>' . trim(implode("\n", file($this->getSource()))));
389 error_reporting($old_error_reporting);
391 if ($eval_result === false) {
392 $this->error_config_file = true;
393 } else {
394 $this->error_config_file = false;
395 $this->source_mtime = filemtime($this->getSource());
399 * Backward compatibility code
401 if (!empty($cfg['DefaultTabTable'])) {
402 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
404 if (!empty($cfg['DefaultTabDatabase'])) {
405 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
408 $this->checkFontsize();
409 //$this->checkPmaAbsoluteUri();
410 $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
412 $this->checkPermissions();
414 // Handling of the collation must be done after merging of $cfg
415 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
416 // can have an effect. Note that the presence of collation
417 // information in a cookie has priority over what is defined
418 // in the default or user's config files.
420 * @todo check validity of $_COOKIE['pma_collation_connection']
422 if (! empty($_COOKIE['pma_collation_connection'])) {
423 $this->set('collation_connection',
424 strip_tags($_COOKIE['pma_collation_connection']));
425 } else {
426 $this->set('collation_connection',
427 $this->get('DefaultConnectionCollation'));
429 // Now, a collation information could come from REQUEST
430 // (an example of this: the collation selector in main.php)
431 // so the following handles the setting of collation_connection
432 // and later, in common.inc.php, the cookie will be set
433 // according to this.
434 $this->checkCollationConnection();
436 return true;
440 * set source
441 * @param string $source
443 function setSource($source)
445 $this->source = trim($source);
449 * checks if the config folder still exists and terminates app if true
451 function checkConfigFolder()
453 // Refuse to work while there still might be some world writable dir:
454 if (is_dir('./config')) {
455 die('Remove "./config" directory before using phpMyAdmin!');
460 * check config source
462 * @return boolean whether source is valid or not
464 function checkConfigSource()
466 if (! $this->getSource()) {
467 // no configuration file set at all
468 return false;
471 if (! file_exists($this->getSource())) {
472 // do not trigger error here
473 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
475 trigger_error(
476 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
477 E_USER_WARNING);
479 $this->source_mtime = 0;
480 return false;
483 if (! is_readable($this->getSource())) {
484 $this->source_mtime = 0;
485 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
488 return true;
492 * verifies the permissions on config file (if asked by configuration)
493 * (must be called after config.inc.php has been merged)
495 function checkPermissions()
497 // Check for permissions (on platforms that support it):
498 if ($this->get('CheckConfigurationPermissions')) {
499 $perms = @fileperms($this->getSource());
500 if (!($perms === false) && ($perms & 2)) {
501 // This check is normally done after loading configuration
502 $this->checkWebServerOs();
503 if ($this->get('PMA_IS_WINDOWS') == 0) {
504 $this->source_mtime = 0;
505 die('Wrong permissions on configuration file, should not be world writable!');
512 * returns specific config setting
513 * @param string $setting
514 * @return mixed value
516 function get($setting)
518 if (isset($this->settings[$setting])) {
519 return $this->settings[$setting];
521 return null;
525 * sets configuration variable
527 * @uses $this->settings
528 * @param string $setting configuration option
529 * @param string $value new value for configuration option
531 function set($setting, $value)
533 if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
534 $this->settings[$setting] = $value;
535 $this->set_mtime = time();
540 * returns source for current config
541 * @return string config source
543 function getSource()
545 return $this->source;
549 * returns a unique value to force a CSS reload if either the config
550 * or the theme changes
551 * must also check the pma_fontsize cookie in case there is no
552 * config file
553 * @return int Unix timestamp
555 function getThemeUniqueValue()
557 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['tmp_user_values']['custom_color']) ? substr($_SESSION['tmp_user_values']['custom_color'],1,6) : '');
561 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
562 * set properly and, depending on browsers, inserting or updating a
563 * record might fail
565 function checkPmaAbsoluteUri()
567 // Setup a default value to let the people and lazy sysadmins work anyway,
568 // they'll get an error if the autodetect code doesn't work
569 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
570 $is_https = $this->get('is_https');
572 if (strlen($pma_absolute_uri) < 5
573 // needed to catch http/https switch
574 || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
575 || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
577 $url = array();
579 // At first we try to parse REQUEST_URI, it might contain full URL
581 * REQUEST_URI contains PATH_INFO too, this is not what we want
582 * script-php/pathinfo/
583 if (PMA_getenv('REQUEST_URI')) {
584 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
585 if ($url === false) {
586 $url = array('path' => $_SERVER['REQUEST_URI']);
591 // If we don't have scheme, we didn't have full URL so we need to
592 // dig deeper
593 if (empty($url['scheme'])) {
594 // Scheme
595 if (PMA_getenv('HTTP_SCHEME')) {
596 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
597 } else {
598 $url['scheme'] =
599 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
600 ? 'https'
601 : 'http';
604 // Host and port
605 if (PMA_getenv('HTTP_HOST')) {
606 // Prepend the scheme before using parse_url() since this is not part of the RFC2616 Host request-header
607 $parsed_url = parse_url($url['scheme'] . '://' . PMA_getenv('HTTP_HOST'));
608 if (!empty($parsed_url['host'])) {
609 $url = $parsed_url;
610 } else {
611 $url['host'] = PMA_getenv('HTTP_HOST');
613 } elseif (PMA_getenv('SERVER_NAME')) {
614 $url['host'] = PMA_getenv('SERVER_NAME');
615 } else {
616 $this->error_pma_uri = true;
617 return false;
620 // If we didn't set port yet...
621 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
622 $url['port'] = PMA_getenv('SERVER_PORT');
625 // And finally the path could be already set from REQUEST_URI
626 if (empty($url['path'])) {
628 * REQUEST_URI contains PATH_INFO too, this is not what we want
629 * script-php/pathinfo/
630 if (PMA_getenv('PATH_INFO')) {
631 $path = parse_url(PMA_getenv('PATH_INFO'));
632 } else {
633 // PHP_SELF in CGI often points to cgi executable, so use it
634 // as last choice
636 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
638 $url['path'] = $path['path'];
642 // Make url from parts we have
643 $pma_absolute_uri = $url['scheme'] . '://';
644 // Was there user information?
645 if (!empty($url['user'])) {
646 $pma_absolute_uri .= $url['user'];
647 if (!empty($url['pass'])) {
648 $pma_absolute_uri .= ':' . $url['pass'];
650 $pma_absolute_uri .= '@';
652 // Add hostname
653 $pma_absolute_uri .= $url['host'];
654 // Add port, if it not the default one
655 if (! empty($url['port'])
656 && (($url['scheme'] == 'http' && $url['port'] != 80)
657 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
658 $pma_absolute_uri .= ':' . $url['port'];
660 // And finally path, without script name, the 'a' is there not to
661 // strip our directory, when path is only /pmadir/ without filename.
662 // Backslashes returned by Windows have to be changed.
663 // Only replace backslashes by forward slashes if on Windows,
664 // as the backslash could be valid on a non-Windows system.
665 $this->checkWebServerOs();
666 if ($this->get('PMA_IS_WINDOWS') == 1) {
667 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
668 } else {
669 $path = dirname($url['path'] . 'a');
672 // To work correctly within transformations overview:
673 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
674 if ($this->get('PMA_IS_WINDOWS') == 1) {
675 $path = str_replace("\\", "/", dirname(dirname($path)));
676 } else {
677 $path = dirname(dirname($path));
681 // PHP's dirname function would have returned a dot when $path contains no slash
682 if ($path == '.') {
683 $path = '';
685 // in vhost situations, there could be already an ending slash
686 if (substr($path, -1) != '/') {
687 $path .= '/';
689 $pma_absolute_uri .= $path;
691 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
692 // the autodetect code works well enough that we don't display the
693 // warning at all. The user can still set PmaAbsoluteUri manually.
694 // See
695 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
697 } else {
698 // The URI is specified, however users do often specify this
699 // wrongly, so we try to fix this.
701 // Adds a trailing slash et the end of the phpMyAdmin uri if it
702 // does not exist.
703 if (substr($pma_absolute_uri, -1) != '/') {
704 $pma_absolute_uri .= '/';
707 // If URI doesn't start with http:// or https://, we will add
708 // this.
709 if (substr($pma_absolute_uri, 0, 7) != 'http://'
710 && substr($pma_absolute_uri, 0, 8) != 'https://') {
711 $pma_absolute_uri =
712 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
713 ? 'https'
714 : 'http')
715 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
716 . $pma_absolute_uri;
719 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
723 * check selected collation_connection
724 * @todo check validity of $_REQUEST['collation_connection']
726 function checkCollationConnection()
728 if (! empty($_REQUEST['collation_connection'])) {
729 $this->set('collation_connection',
730 strip_tags($_REQUEST['collation_connection']));
735 * checks for font size configuration, and sets font size as requested by user
737 * @uses $_GET
738 * @uses $_POST
739 * @uses $_COOKIE
740 * @uses preg_match()
741 * @uses function_exists()
742 * @uses PMA_Config::set()
743 * @uses PMA_Config::get()
744 * @uses PMA_setCookie()
746 function checkFontsize()
748 $new_fontsize = '';
750 if (isset($_GET['fontsize'])) {
751 $new_fontsize = $_GET['fontsize'];
752 } elseif (isset($_POST['fontsize'])) {
753 $new_fontsize = $_POST['fontsize'];
754 } elseif (isset($_COOKIE['pma_fontsize'])) {
755 $new_fontsize = $_COOKIE['pma_fontsize'];
758 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
759 $this->set('fontsize', $new_fontsize);
760 } elseif (! $this->get('fontsize')) {
761 // 80% would correspond to the default browser font size
762 // of 16, but use 82% to help read the monoface font
763 $this->set('fontsize', '82%');
766 if (function_exists('PMA_setCookie')) {
767 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '82%');
772 * checks if upload is enabled
776 function checkUpload()
778 if (ini_get('file_uploads')) {
779 $this->set('enable_upload', true);
780 // if set "php_admin_value file_uploads Off" in httpd.conf
781 // ini_get() also returns the string "Off" in this case:
782 if ('off' == strtolower(ini_get('file_uploads'))) {
783 $this->set('enable_upload', false);
785 } else {
786 $this->set('enable_upload', false);
791 * Maximum upload size as limited by PHP
792 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
794 * this section generates $max_upload_size in bytes
796 function checkUploadSize()
798 if (! $filesize = ini_get('upload_max_filesize')) {
799 $filesize = "5M";
802 if ($postsize = ini_get('post_max_size')) {
803 $this->set('max_upload_size',
804 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
805 } else {
806 $this->set('max_upload_size', PMA_get_real_size($filesize));
811 * check for https
813 function checkIsHttps()
815 $this->set('is_https', PMA_Config::isHttps());
819 * @static
821 static public function isHttps()
823 $is_https = false;
825 $url = array();
827 // At first we try to parse REQUEST_URI, it might contain full URL,
828 if (PMA_getenv('REQUEST_URI')) {
829 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
830 if($url === false) {
831 $url = array();
835 // If we don't have scheme, we didn't have full URL so we need to
836 // dig deeper
837 if (empty($url['scheme'])) {
838 // Scheme
839 if (PMA_getenv('HTTP_SCHEME')) {
840 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
841 } else {
842 $url['scheme'] =
843 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
844 ? 'https'
845 : 'http';
849 if (isset($url['scheme'])
850 && $url['scheme'] == 'https') {
851 $is_https = true;
852 } else {
853 $is_https = false;
856 return $is_https;
860 * detect correct cookie path
862 function checkCookiePath()
864 $this->set('cookie_path', PMA_Config::getCookiePath());
868 * @static
870 static public function getCookiePath()
872 static $cookie_path = null;
874 if (null !== $cookie_path) {
875 return $cookie_path;
878 $url = '';
881 * REQUEST_URI contains PATH_INFO too, this is not what we want
882 * script-php/pathinfo/
883 if (PMA_getenv('REQUEST_URI')) {
884 $url = PMA_getenv('REQUEST_URI');
888 // If we don't have path
889 if (empty($url)) {
890 if ($GLOBALS['PMA_PHP_SELF']) {
891 // PHP_SELF in CGI often points to cgi executable, so use it
892 // as last choice
893 $url = $GLOBALS['PMA_PHP_SELF'];
894 // on IIS with PHP-CGI:
895 } elseif (PMA_getenv('SCRIPT_NAME')) {
896 $url = PMA_getenv('SCRIPT_NAME');
901 * REQUEST_URI contains PATH_INFO too, this is not what we want
902 * script-php/pathinfo/
903 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
904 if ($parsed_url === false) {
906 $parsed_url = array('path' => $url);
909 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
911 return $cookie_path;
915 * enables backward compatibility
917 function enableBc()
919 $GLOBALS['cfg'] = $this->settings;
920 $GLOBALS['default_server'] = $this->default_server;
921 unset($this->default_server);
922 $GLOBALS['collation_connection'] = $this->get('collation_connection');
923 $GLOBALS['is_upload'] = $this->get('enable_upload');
924 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
925 $GLOBALS['cookie_path'] = $this->get('cookie_path');
926 $GLOBALS['is_https'] = $this->get('is_https');
928 $defines = array(
929 'PMA_VERSION',
930 'PMA_THEME_VERSION',
931 'PMA_THEME_GENERATION',
932 'PMA_PHP_STR_VERSION',
933 'PMA_PHP_INT_VERSION',
934 'PMA_IS_WINDOWS',
935 'PMA_IS_IIS',
936 'PMA_IS_GD2',
937 'PMA_USR_OS',
938 'PMA_USR_BROWSER_VER',
939 'PMA_USR_BROWSER_AGENT'
942 foreach ($defines as $define) {
943 if (! defined($define)) {
944 define($define, $this->get($define));
950 * @todo finish
952 function save() {}
955 * returns options for font size selection
957 * @uses preg_replace()
958 * @uses ksort()
959 * @static
960 * @param string $current_size current selected font size with unit
961 * @return array selectable font sizes
963 static protected function _getFontsizeOptions($current_size = '82%')
965 $unit = preg_replace('/[0-9.]*/', '', $current_size);
966 $value = preg_replace('/[^0-9.]*/', '', $current_size);
968 $factors = array();
969 $options = array();
970 $options["$value"] = $value . $unit;
972 if ($unit === '%') {
973 $factors[] = 1;
974 $factors[] = 5;
975 $factors[] = 10;
976 } elseif ($unit === 'em') {
977 $factors[] = 0.05;
978 $factors[] = 0.2;
979 $factors[] = 1;
980 } elseif ($unit === 'pt') {
981 $factors[] = 0.5;
982 $factors[] = 2;
983 } elseif ($unit === 'px') {
984 $factors[] = 1;
985 $factors[] = 5;
986 $factors[] = 10;
987 } else {
988 //unknown font size unit
989 $factors[] = 0.05;
990 $factors[] = 0.2;
991 $factors[] = 1;
992 $factors[] = 5;
993 $factors[] = 10;
996 foreach ($factors as $key => $factor) {
997 $option_inc = $value + $factor;
998 $option_dec = $value - $factor;
999 while (count($options) < 21) {
1000 $options["$option_inc"] = $option_inc . $unit;
1001 if ($option_dec > $factors[0]) {
1002 $options["$option_dec"] = $option_dec . $unit;
1004 $option_inc += $factor;
1005 $option_dec -= $factor;
1006 if (isset($factors[$key + 1])
1007 && $option_inc >= $value + $factors[$key + 1]) {
1008 break;
1012 ksort($options);
1013 return $options;
1017 * returns html selectbox for font sizes
1019 * @uses $_SESSION['PMA_Config']
1020 * @uses PMA_Config::get()
1021 * @uses PMA_Config::_getFontsizeOptions()
1022 * @uses $GLOBALS['strFontSize']
1023 * @static
1024 * @param string $current_size currently slected font size with unit
1025 * @return string html selectbox
1027 static protected function _getFontsizeSelection()
1029 $current_size = $_SESSION['PMA_Config']->get('fontsize');
1030 // for the case when there is no config file (this is supported)
1031 if (empty($current_size)) {
1032 if (isset($_COOKIE['pma_fontsize'])) {
1033 $current_size = $_COOKIE['pma_fontsize'];
1034 } else {
1035 $current_size = '82%';
1038 $options = PMA_Config::_getFontsizeOptions($current_size);
1040 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1041 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1042 foreach ($options as $option) {
1043 $return .= '<option value="' . $option . '"';
1044 if ($option == $current_size) {
1045 $return .= ' selected="selected"';
1047 $return .= '>' . $option . '</option>' . "\n";
1049 $return .= '</select>';
1051 return $return;
1055 * return complete font size selection form
1057 * @uses PMA_generate_common_hidden_inputs()
1058 * @uses PMA_Config::_getFontsizeSelection()
1059 * @uses $GLOBALS['strGo']
1060 * @static
1061 * @param string $current_size currently slected font size with unit
1062 * @return string html selectbox
1064 static public function getFontsizeForm()
1066 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1067 . ' method="post" action="index.php" target="_parent">' . "\n"
1068 . PMA_generate_common_hidden_inputs() . "\n"
1069 . PMA_Config::_getFontsizeSelection() . "\n"
1070 . '<noscript>' . "\n"
1071 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1072 . '</noscript>' . "\n"
1073 . '</form>';