Clarify FAQ 5.18; put the vim modeline higher in the file so that it works
[phpmyadmin/crack.git] / libraries / Config.class.php
blob59f7c4407a18270e03b6e998cdde228bf0821bc5
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.2.0-beta1');
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['userconf']['custom_color']) ? substr($_SESSION['userconf']['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 if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
607 list($url['host'], $url['port']) =
608 explode(':', PMA_getenv('HTTP_HOST'));
609 } else {
610 $url['host'] = PMA_getenv('HTTP_HOST');
612 } elseif (PMA_getenv('SERVER_NAME')) {
613 $url['host'] = PMA_getenv('SERVER_NAME');
614 } else {
615 $this->error_pma_uri = true;
616 return false;
619 // If we didn't set port yet...
620 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
621 $url['port'] = PMA_getenv('SERVER_PORT');
624 // And finally the path could be already set from REQUEST_URI
625 if (empty($url['path'])) {
627 * REQUEST_URI contains PATH_INFO too, this is not what we want
628 * script-php/pathinfo/
629 if (PMA_getenv('PATH_INFO')) {
630 $path = parse_url(PMA_getenv('PATH_INFO'));
631 } else {
632 // PHP_SELF in CGI often points to cgi executable, so use it
633 // as last choice
635 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
637 $url['path'] = $path['path'];
641 // Make url from parts we have
642 $pma_absolute_uri = $url['scheme'] . '://';
643 // Was there user information?
644 if (!empty($url['user'])) {
645 $pma_absolute_uri .= $url['user'];
646 if (!empty($url['pass'])) {
647 $pma_absolute_uri .= ':' . $url['pass'];
649 $pma_absolute_uri .= '@';
651 // Add hostname
652 $pma_absolute_uri .= $url['host'];
653 // Add port, if it not the default one
654 if (! empty($url['port'])
655 && (($url['scheme'] == 'http' && $url['port'] != 80)
656 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
657 $pma_absolute_uri .= ':' . $url['port'];
659 // And finally path, without script name, the 'a' is there not to
660 // strip our directory, when path is only /pmadir/ without filename.
661 // Backslashes returned by Windows have to be changed.
662 // Only replace backslashes by forward slashes if on Windows,
663 // as the backslash could be valid on a non-Windows system.
664 if ($this->get('PMA_IS_WINDOWS') == 1) {
665 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
666 } else {
667 $path = dirname($url['path'] . 'a');
670 // To work correctly within transformations overview:
671 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
672 if ($this->get('PMA_IS_WINDOWS') == 1) {
673 $path = str_replace("\\", "/", dirname(dirname($path)));
674 } else {
675 $path = dirname(dirname($path));
678 // in vhost situations, there could be already an ending slash
679 if (substr($path, -1) != '/') {
680 $path .= '/';
682 $pma_absolute_uri .= $path;
684 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
685 // the autodetect code works well enough that we don't display the
686 // warning at all. The user can still set PmaAbsoluteUri manually.
687 // See
688 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
690 } else {
691 // The URI is specified, however users do often specify this
692 // wrongly, so we try to fix this.
694 // Adds a trailing slash et the end of the phpMyAdmin uri if it
695 // does not exist.
696 if (substr($pma_absolute_uri, -1) != '/') {
697 $pma_absolute_uri .= '/';
700 // If URI doesn't start with http:// or https://, we will add
701 // this.
702 if (substr($pma_absolute_uri, 0, 7) != 'http://'
703 && substr($pma_absolute_uri, 0, 8) != 'https://') {
704 $pma_absolute_uri =
705 (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
706 ? 'https'
707 : 'http')
708 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
709 . $pma_absolute_uri;
712 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
716 * check selected collation_connection
717 * @todo check validity of $_REQUEST['collation_connection']
719 function checkCollationConnection()
721 if (! empty($_REQUEST['collation_connection'])) {
722 $this->set('collation_connection',
723 strip_tags($_REQUEST['collation_connection']));
728 * checks for font size configuration, and sets font size as requested by user
730 * @uses $_GET
731 * @uses $_POST
732 * @uses $_COOKIE
733 * @uses preg_match()
734 * @uses function_exists()
735 * @uses PMA_Config::set()
736 * @uses PMA_Config::get()
737 * @uses PMA_setCookie()
739 function checkFontsize()
741 $new_fontsize = '';
743 if (isset($_GET['fontsize'])) {
744 $new_fontsize = $_GET['fontsize'];
745 } elseif (isset($_POST['fontsize'])) {
746 $new_fontsize = $_POST['fontsize'];
747 } elseif (isset($_COOKIE['pma_fontsize'])) {
748 $new_fontsize = $_COOKIE['pma_fontsize'];
751 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
752 $this->set('fontsize', $new_fontsize);
753 } elseif (! $this->get('fontsize')) {
754 // 80% would correspond to the default browser font size
755 // of 16, but use 82% to help read the monoface font
756 $this->set('fontsize', '82%');
759 if (function_exists('PMA_setCookie')) {
760 PMA_setCookie('pma_fontsize', $this->get('fontsize'), '82%');
765 * checks if upload is enabled
769 function checkUpload()
771 if (ini_get('file_uploads')) {
772 $this->set('enable_upload', true);
773 // if set "php_admin_value file_uploads Off" in httpd.conf
774 // ini_get() also returns the string "Off" in this case:
775 if ('off' == strtolower(ini_get('file_uploads'))) {
776 $this->set('enable_upload', false);
778 } else {
779 $this->set('enable_upload', false);
784 * Maximum upload size as limited by PHP
785 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
787 * this section generates $max_upload_size in bytes
789 function checkUploadSize()
791 if (! $filesize = ini_get('upload_max_filesize')) {
792 $filesize = "5M";
795 if ($postsize = ini_get('post_max_size')) {
796 $this->set('max_upload_size',
797 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
798 } else {
799 $this->set('max_upload_size', PMA_get_real_size($filesize));
804 * check for https
806 function checkIsHttps()
808 $this->set('is_https', PMA_Config::isHttps());
812 * @static
814 static public function isHttps()
816 $is_https = false;
818 $url = array();
820 // At first we try to parse REQUEST_URI, it might contain full URL,
821 if (PMA_getenv('REQUEST_URI')) {
822 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
823 if($url === false) {
824 $url = array();
828 // If we don't have scheme, we didn't have full URL so we need to
829 // dig deeper
830 if (empty($url['scheme'])) {
831 // Scheme
832 if (PMA_getenv('HTTP_SCHEME')) {
833 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
834 } else {
835 $url['scheme'] =
836 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
837 ? 'https'
838 : 'http';
842 if (isset($url['scheme'])
843 && $url['scheme'] == 'https') {
844 $is_https = true;
845 } else {
846 $is_https = false;
849 return $is_https;
853 * detect correct cookie path
855 function checkCookiePath()
857 $this->set('cookie_path', PMA_Config::getCookiePath());
861 * @static
863 static public function getCookiePath()
865 static $cookie_path = null;
867 if (null !== $cookie_path) {
868 return $cookie_path;
871 $url = '';
874 * REQUEST_URI contains PATH_INFO too, this is not what we want
875 * script-php/pathinfo/
876 if (PMA_getenv('REQUEST_URI')) {
877 $url = PMA_getenv('REQUEST_URI');
881 // If we don't have path
882 if (empty($url)) {
883 if ($GLOBALS['PMA_PHP_SELF']) {
884 // PHP_SELF in CGI often points to cgi executable, so use it
885 // as last choice
886 $url = $GLOBALS['PMA_PHP_SELF'];
887 // on IIS with PHP-CGI:
888 } elseif (PMA_getenv('SCRIPT_NAME')) {
889 $url = PMA_getenv('SCRIPT_NAME');
894 * REQUEST_URI contains PATH_INFO too, this is not what we want
895 * script-php/pathinfo/
896 $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
897 if ($parsed_url === false) {
899 $parsed_url = array('path' => $url);
902 $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
904 return $cookie_path;
908 * enables backward compatibility
910 function enableBc()
912 $GLOBALS['cfg'] = $this->settings;
913 $GLOBALS['default_server'] = $this->default_server;
914 unset($this->default_server);
915 $GLOBALS['collation_connection'] = $this->get('collation_connection');
916 $GLOBALS['is_upload'] = $this->get('enable_upload');
917 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
918 $GLOBALS['cookie_path'] = $this->get('cookie_path');
919 $GLOBALS['is_https'] = $this->get('is_https');
921 $defines = array(
922 'PMA_VERSION',
923 'PMA_THEME_VERSION',
924 'PMA_THEME_GENERATION',
925 'PMA_PHP_STR_VERSION',
926 'PMA_PHP_INT_VERSION',
927 'PMA_IS_WINDOWS',
928 'PMA_IS_IIS',
929 'PMA_IS_GD2',
930 'PMA_USR_OS',
931 'PMA_USR_BROWSER_VER',
932 'PMA_USR_BROWSER_AGENT'
935 foreach ($defines as $define) {
936 if (! defined($define)) {
937 define($define, $this->get($define));
943 * @todo finish
945 function save() {}
948 * returns options for font size selection
950 * @uses preg_replace()
951 * @uses ksort()
952 * @static
953 * @param string $current_size current selected font size with unit
954 * @return array selectable font sizes
956 static protected function _getFontsizeOptions($current_size = '82%')
958 $unit = preg_replace('/[0-9.]*/', '', $current_size);
959 $value = preg_replace('/[^0-9.]*/', '', $current_size);
961 $factors = array();
962 $options = array();
963 $options["$value"] = $value . $unit;
965 if ($unit === '%') {
966 $factors[] = 1;
967 $factors[] = 5;
968 $factors[] = 10;
969 } elseif ($unit === 'em') {
970 $factors[] = 0.05;
971 $factors[] = 0.2;
972 $factors[] = 1;
973 } elseif ($unit === 'pt') {
974 $factors[] = 0.5;
975 $factors[] = 2;
976 } elseif ($unit === 'px') {
977 $factors[] = 1;
978 $factors[] = 5;
979 $factors[] = 10;
980 } else {
981 //unknown font size unit
982 $factors[] = 0.05;
983 $factors[] = 0.2;
984 $factors[] = 1;
985 $factors[] = 5;
986 $factors[] = 10;
989 foreach ($factors as $key => $factor) {
990 $option_inc = $value + $factor;
991 $option_dec = $value - $factor;
992 while (count($options) < 21) {
993 $options["$option_inc"] = $option_inc . $unit;
994 if ($option_dec > $factors[0]) {
995 $options["$option_dec"] = $option_dec . $unit;
997 $option_inc += $factor;
998 $option_dec -= $factor;
999 if (isset($factors[$key + 1])
1000 && $option_inc >= $value + $factors[$key + 1]) {
1001 break;
1005 ksort($options);
1006 return $options;
1010 * returns html selectbox for font sizes
1012 * @uses $_SESSION['PMA_Config']
1013 * @uses PMA_Config::get()
1014 * @uses PMA_Config::_getFontsizeOptions()
1015 * @uses $GLOBALS['strFontSize']
1016 * @static
1017 * @param string $current_size currently slected font size with unit
1018 * @return string html selectbox
1020 static protected function _getFontsizeSelection()
1022 $current_size = $_SESSION['PMA_Config']->get('fontsize');
1023 // for the case when there is no config file (this is supported)
1024 if (empty($current_size)) {
1025 if (isset($_COOKIE['pma_fontsize'])) {
1026 $current_size = $_COOKIE['pma_fontsize'];
1027 } else {
1028 $current_size = '82%';
1031 $options = PMA_Config::_getFontsizeOptions($current_size);
1033 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1034 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1035 foreach ($options as $option) {
1036 $return .= '<option value="' . $option . '"';
1037 if ($option == $current_size) {
1038 $return .= ' selected="selected"';
1040 $return .= '>' . $option . '</option>' . "\n";
1042 $return .= '</select>';
1044 return $return;
1048 * return complete font size selection form
1050 * @uses PMA_generate_common_hidden_inputs()
1051 * @uses PMA_Config::_getFontsizeSelection()
1052 * @uses $GLOBALS['strGo']
1053 * @static
1054 * @param string $current_size currently slected font size with unit
1055 * @return string html selectbox
1057 static public function getFontsizeForm()
1059 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1060 . ' method="post" action="index.php" target="_parent">' . "\n"
1061 . PMA_generate_common_hidden_inputs() . "\n"
1062 . PMA_Config::_getFontsizeSelection() . "\n"
1063 . '<noscript>' . "\n"
1064 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1065 . '</noscript>' . "\n"
1066 . '</form>';