2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 * Load vendor configuration.
13 require_once('./libraries/vendor_config.php');
23 * @var string default config source
25 var $default_source = './libraries/config.default.php';
28 * @var array configuration settings
30 var $settings = array();
33 * @var string config source
38 * @var int source modification time
40 var $source_mtime = 0;
41 var $default_source_mtime = 0;
47 var $error_config_file = false;
52 var $error_config_default_file = false;
57 var $error_pma_uri = false;
62 var $default_server = array();
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
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
84 // other settings, independent from config file, comes in
87 $this->checkIsHttps();
91 * sets system and application settings
93 function checkSystem()
95 $this->set('PMA_VERSION', '3.4.0-dev');
99 $this->set('PMA_THEME_VERSION', 2);
103 $this->set('PMA_THEME_GENERATION', 2);
105 $this->checkPhpVersion();
106 $this->checkWebServerOs();
107 $this->checkWebServer();
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);
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 = '';
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');
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');
194 $this->set('PMA_USR_BROWSER_VER', 0);
195 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
200 * Whether GD2 is present
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);
209 if (!@function_exists
('imagecreatetruecolor')) {
210 $this->set('PMA_IS_GD2', 0);
212 if (@function_exists
('gd_info')) {
214 if (strstr($gd_nfo["GD Version"], '2.')) {
215 $this->set('PMA_IS_GD2', 1);
217 $this->set('PMA_IS_GD2', 0);
220 /* We must do hard way... but almost no chance to execute this */
222 phpinfo(INFO_MODULES
); /* Only modules */
223 $a = strip_tags(ob_get_contents());
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);
230 $this->set('PMA_IS_GD2', 0);
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);
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()
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])) {
290 if (! isset($match[3])) {
293 $this->set('PMA_PHP_INT_VERSION',
294 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
296 $this->set('PMA_PHP_INT_VERSION', 0);
298 $this->set('PMA_PHP_STR_VERSION', phpversion());
302 * loads default values from default source
304 * @uses file_exists()
305 * @uses $this->default_source
306 * @uses $this->error_config_default_file
307 * @uses $this->settings
308 * @return boolean success
310 function loadDefaults()
313 if (! file_exists($this->default_source
)) {
314 $this->error_config_default_file
= true;
317 include $this->default_source
;
319 $this->default_source_mtime
= filemtime($this->default_source
);
321 $this->default_server
= $cfg['Servers'][1];
322 unset($cfg['Servers']);
324 $this->settings
= PMA_array_merge_recursive($this->settings
, $cfg);
326 $this->error_config_default_file
= false;
332 * loads configuration from $source, usally the config file
333 * should be called on object creation
335 * @param string $source config file
337 function load($source = null)
339 $this->loadDefaults();
341 if (null !== $source) {
342 $this->setSource($source);
345 if (! $this->checkConfigSource()) {
352 * Parses the configuration file
354 $old_error_reporting = error_reporting(0);
355 if (function_exists('file_get_contents')) {
357 eval('?' . '>' . trim(file_get_contents($this->getSource())));
360 eval('?' . '>' . trim(implode("\n", file($this->getSource()))));
362 error_reporting($old_error_reporting);
364 if ($eval_result === false) {
365 $this->error_config_file
= true;
367 $this->error_config_file
= false;
368 $this->source_mtime
= filemtime($this->getSource());
372 * Backward compatibility code
374 if (!empty($cfg['DefaultTabTable'])) {
375 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
377 if (!empty($cfg['DefaultTabDatabase'])) {
378 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
381 $this->settings
= PMA_array_merge_recursive($this->settings
, $cfg);
382 $this->checkPmaAbsoluteUri();
383 $this->checkFontsize();
385 $this->checkPermissions();
387 // Handling of the collation must be done after merging of $cfg
388 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
389 // can have an effect. Note that the presence of collation
390 // information in a cookie has priority over what is defined
391 // in the default or user's config files.
393 * @todo check validity of $_COOKIE['pma_collation_connection']
395 if (! empty($_COOKIE['pma_collation_connection'])) {
396 $this->set('collation_connection',
397 strip_tags($_COOKIE['pma_collation_connection']));
399 $this->set('collation_connection',
400 $this->get('DefaultConnectionCollation'));
402 // Now, a collation information could come from REQUEST
403 // (an example of this: the collation selector in main.php)
404 // so the following handles the setting of collation_connection
405 // and later, in common.inc.php, the cookie will be set
406 // according to this.
407 $this->checkCollationConnection();
414 * @param string $source
416 function setSource($source)
418 $this->source
= trim($source);
422 * checks if the config folder still exists and terminates app if true
424 function checkConfigFolder()
426 // Refuse to work while there still might be some world writable dir:
427 if (is_dir('./config')) {
428 die('Remove "./config" directory before using phpMyAdmin!');
433 * check config source
435 * @return boolean whether source is valid or not
437 function checkConfigSource()
439 if (! $this->getSource()) {
440 // no configuration file set at all
444 if (! file_exists($this->getSource())) {
445 // do not trigger error here
446 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
449 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
452 $this->source_mtime
= 0;
456 if (! is_readable($this->getSource())) {
457 $this->source_mtime
= 0;
458 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
465 * verifies the permissions on config file (if asked by configuration)
466 * (must be called after config.inc.php has been merged)
468 function checkPermissions()
470 // Check for permissions (on platforms that support it):
471 if ($this->get('CheckConfigurationPermissions')) {
472 $perms = @fileperms
($this->getSource());
473 if (!($perms === false) && ($perms & 2)) {
474 // This check is normally done after loading configuration
475 $this->checkWebServerOs();
476 if ($this->get('PMA_IS_WINDOWS') == 0) {
477 $this->source_mtime
= 0;
478 die('Wrong permissions on configuration file, should not be world writable!');
485 * returns specific config setting
486 * @param string $setting
487 * @return mixed value
489 function get($setting)
491 if (isset($this->settings
[$setting])) {
492 return $this->settings
[$setting];
498 * sets configuration variable
500 * @uses $this->settings
501 * @param string $setting configuration option
502 * @param string $value new value for configuration option
504 function set($setting, $value)
506 if (!isset($this->settings
[$setting]) ||
$this->settings
[$setting] != $value) {
507 $this->settings
[$setting] = $value;
508 $this->set_mtime
= time();
513 * returns source for current config
514 * @return string config source
518 return $this->source
;
522 * returns a unique value to force a CSS reload if either the config
523 * or the theme changes
524 * must also check the pma_fontsize cookie in case there is no
526 * @return int Unix timestamp
528 function getThemeUniqueValue()
530 if (null !== $this->get('fontsize')) {
531 $fontsize = intval($this->get('fontsize'));
532 } elseif (isset($_COOKIE['pma_fontsize'])) {
533 $fontsize = intval($_COOKIE['pma_fontsize']);
539 $this->source_mtime +
540 $this->default_source_mtime +
541 $_SESSION['PMA_Theme']->mtime_info +
542 $_SESSION['PMA_Theme']->filesize_info
)
543 . (isset($_SESSION['tmp_user_values']['custom_color']) ?
substr($_SESSION['tmp_user_values']['custom_color'],1,6) : '');
547 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
548 * set properly and, depending on browsers, inserting or updating a
551 function checkPmaAbsoluteUri()
553 // Setup a default value to let the people and lazy sysadmins work anyway,
554 // they'll get an error if the autodetect code doesn't work
555 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
556 $is_https = $this->detectHttps();
558 if (strlen($pma_absolute_uri) < 5) {
561 // At first we try to parse REQUEST_URI, it might contain full URL
563 * REQUEST_URI contains PATH_INFO too, this is not what we want
564 * script-php/pathinfo/
565 if (PMA_getenv('REQUEST_URI')) {
566 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
567 if ($url === false) {
568 $url = array('path' => $_SERVER['REQUEST_URI']);
573 // If we don't have scheme, we didn't have full URL so we need to
575 if (empty($url['scheme'])) {
577 if (PMA_getenv('HTTP_SCHEME')) {
578 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
581 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
587 if (PMA_getenv('HTTP_HOST')) {
588 // Prepend the scheme before using parse_url() since this is not part of the RFC2616 Host request-header
589 $parsed_url = parse_url($url['scheme'] . '://' . PMA_getenv('HTTP_HOST'));
590 if (!empty($parsed_url['host'])) {
593 $url['host'] = PMA_getenv('HTTP_HOST');
595 } elseif (PMA_getenv('SERVER_NAME')) {
596 $url['host'] = PMA_getenv('SERVER_NAME');
598 $this->error_pma_uri
= true;
602 // If we didn't set port yet...
603 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
604 $url['port'] = PMA_getenv('SERVER_PORT');
607 // And finally the path could be already set from REQUEST_URI
608 if (empty($url['path'])) {
610 * REQUEST_URI contains PATH_INFO too, this is not what we want
611 * script-php/pathinfo/
612 if (PMA_getenv('PATH_INFO')) {
613 $path = parse_url(PMA_getenv('PATH_INFO'));
615 // PHP_SELF in CGI often points to cgi executable, so use it
618 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
620 $url['path'] = $path['path'];
624 // Make url from parts we have
625 $pma_absolute_uri = $url['scheme'] . '://';
626 // Was there user information?
627 if (!empty($url['user'])) {
628 $pma_absolute_uri .= $url['user'];
629 if (!empty($url['pass'])) {
630 $pma_absolute_uri .= ':' . $url['pass'];
632 $pma_absolute_uri .= '@';
635 $pma_absolute_uri .= $url['host'];
636 // Add port, if it not the default one
637 if (! empty($url['port'])
638 && (($url['scheme'] == 'http' && $url['port'] != 80)
639 ||
($url['scheme'] == 'https' && $url['port'] != 443))) {
640 $pma_absolute_uri .= ':' . $url['port'];
642 // And finally path, without script name, the 'a' is there not to
643 // strip our directory, when path is only /pmadir/ without filename.
644 // Backslashes returned by Windows have to be changed.
645 // Only replace backslashes by forward slashes if on Windows,
646 // as the backslash could be valid on a non-Windows system.
647 $this->checkWebServerOs();
648 if ($this->get('PMA_IS_WINDOWS') == 1) {
649 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
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)));
659 $path = dirname(dirname($path));
663 // PHP's dirname function would have returned a dot when $path contains no slash
667 // in vhost situations, there could be already an ending slash
668 if (substr($path, -1) != '/') {
671 $pma_absolute_uri .= $path;
673 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
674 // the autodetect code works well enough that we don't display the
675 // warning at all. The user can still set PmaAbsoluteUri manually.
677 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
680 // The URI is specified, however users do often specify this
681 // wrongly, so we try to fix this.
683 // Adds a trailing slash et the end of the phpMyAdmin uri if it
685 if (substr($pma_absolute_uri, -1) != '/') {
686 $pma_absolute_uri .= '/';
689 // If URI doesn't start with http:// or https://, we will add
691 if (substr($pma_absolute_uri, 0, 7) != 'http://'
692 && substr($pma_absolute_uri, 0, 8) != 'https://') {
694 ($is_https ?
'https' : 'http')
695 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ?
'' : '//')
699 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
703 * check selected collation_connection
704 * @todo check validity of $_REQUEST['collation_connection']
706 function checkCollationConnection()
708 if (! empty($_REQUEST['collation_connection'])) {
709 $this->set('collation_connection',
710 strip_tags($_REQUEST['collation_connection']));
715 * checks for font size configuration, and sets font size as requested by user
721 * @uses function_exists()
722 * @uses PMA_Config::set()
723 * @uses PMA_Config::get()
724 * @uses PMA_Config::setCookie()
726 function checkFontsize()
730 if (isset($_GET['fontsize'])) {
731 $new_fontsize = $_GET['fontsize'];
732 } elseif (isset($_POST['fontsize'])) {
733 $new_fontsize = $_POST['fontsize'];
734 } elseif (isset($_COOKIE['pma_fontsize'])) {
735 $new_fontsize = $_COOKIE['pma_fontsize'];
738 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
739 $this->set('fontsize', $new_fontsize);
740 } elseif (! $this->get('fontsize')) {
741 // 80% would correspond to the default browser font size
742 // of 16, but use 82% to help read the monoface font
743 $this->set('fontsize', '82%');
746 $this->setCookie('pma_fontsize', $this->get('fontsize'), '82%');
750 * checks if upload is enabled
754 function checkUpload()
756 if (ini_get('file_uploads')) {
757 $this->set('enable_upload', true);
758 // if set "php_admin_value file_uploads Off" in httpd.conf
759 // ini_get() also returns the string "Off" in this case:
760 if ('off' == strtolower(ini_get('file_uploads'))) {
761 $this->set('enable_upload', false);
764 $this->set('enable_upload', false);
769 * Maximum upload size as limited by PHP
770 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
772 * this section generates $max_upload_size in bytes
774 function checkUploadSize()
776 if (! $filesize = ini_get('upload_max_filesize')) {
780 if ($postsize = ini_get('post_max_size')) {
781 $this->set('max_upload_size',
782 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
784 $this->set('max_upload_size', PMA_get_real_size($filesize));
791 function checkIsHttps()
793 $this->set('is_https', $this->isHttps());
799 public function isHttps()
801 static $is_https = null;
803 if (null !== $is_https) {
807 $url = parse_url($this->get('PmaAbsoluteUri'));
809 if (isset($url['scheme'])
810 && $url['scheme'] == 'https') {
820 * Detects whether https appears to be used.
822 * Please note that this just detects what we see, so
823 * it completely ignores things like reverse proxies.
825 function detectHttps()
831 // At first we try to parse REQUEST_URI, it might contain full URL,
832 if (PMA_getenv('REQUEST_URI')) {
833 $url = @parse_url
(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
839 // If we don't have scheme, we didn't have full URL so we need to
841 if (empty($url['scheme'])) {
843 if (PMA_getenv('HTTP_SCHEME')) {
844 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
847 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
853 if (isset($url['scheme'])
854 && $url['scheme'] == 'https') {
864 * detect correct cookie path
866 function checkCookiePath()
868 $this->set('cookie_path', $this->getCookiePath());
874 public function getCookiePath()
876 static $cookie_path = null;
878 if (null !== $cookie_path) {
882 $parsed_url = parse_url($this->get('PmaAbsoluteUri'));
884 $cookie_path = $parsed_url['path'];
890 * enables backward compatibility
894 $GLOBALS['cfg'] = $this->settings
;
895 $GLOBALS['default_server'] = $this->default_server
;
896 unset($this->default_server
);
897 $GLOBALS['collation_connection'] = $this->get('collation_connection');
898 $GLOBALS['is_upload'] = $this->get('enable_upload');
899 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
900 $GLOBALS['cookie_path'] = $this->get('cookie_path');
901 $GLOBALS['is_https'] = $this->get('is_https');
906 'PMA_THEME_GENERATION',
907 'PMA_PHP_STR_VERSION',
908 'PMA_PHP_INT_VERSION',
913 'PMA_USR_BROWSER_VER',
914 'PMA_USR_BROWSER_AGENT'
917 foreach ($defines as $define) {
918 if (! defined($define)) {
919 define($define, $this->get($define));
930 * returns options for font size selection
932 * @uses preg_replace()
935 * @param string $current_size current selected font size with unit
936 * @return array selectable font sizes
938 static protected function _getFontsizeOptions($current_size = '82%')
940 $unit = preg_replace('/[0-9.]*/', '', $current_size);
941 $value = preg_replace('/[^0-9.]*/', '', $current_size);
945 $options["$value"] = $value . $unit;
951 } elseif ($unit === 'em') {
955 } elseif ($unit === 'pt') {
958 } elseif ($unit === 'px') {
963 //unknown font size unit
971 foreach ($factors as $key => $factor) {
972 $option_inc = $value +
$factor;
973 $option_dec = $value - $factor;
974 while (count($options) < 21) {
975 $options["$option_inc"] = $option_inc . $unit;
976 if ($option_dec > $factors[0]) {
977 $options["$option_dec"] = $option_dec . $unit;
979 $option_inc +
= $factor;
980 $option_dec -= $factor;
981 if (isset($factors[$key +
1])
982 && $option_inc >= $value +
$factors[$key +
1]) {
992 * returns html selectbox for font sizes
994 * @uses $GLOBALS['PMA_Config']
995 * @uses PMA_Config::get()
996 * @uses PMA_Config::_getFontsizeOptions()
997 * @uses $GLOBALS['strFontSize']
999 * @param string $current_size currently slected font size with unit
1000 * @return string html selectbox
1002 static protected function _getFontsizeSelection()
1004 $current_size = $GLOBALS['PMA_Config']->get('fontsize');
1005 // for the case when there is no config file (this is supported)
1006 if (empty($current_size)) {
1007 if (isset($_COOKIE['pma_fontsize'])) {
1008 $current_size = $_COOKIE['pma_fontsize'];
1010 $current_size = '82%';
1013 $options = PMA_Config
::_getFontsizeOptions($current_size);
1015 $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
1016 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1017 foreach ($options as $option) {
1018 $return .= '<option value="' . $option . '"';
1019 if ($option == $current_size) {
1020 $return .= ' selected="selected"';
1022 $return .= '>' . $option . '</option>' . "\n";
1024 $return .= '</select>';
1030 * return complete font size selection form
1032 * @uses PMA_generate_common_hidden_inputs()
1033 * @uses PMA_Config::_getFontsizeSelection()
1034 * @uses $GLOBALS['strGo']
1036 * @param string $current_size currently slected font size with unit
1037 * @return string html selectbox
1039 static public function getFontsizeForm()
1041 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1042 . ' method="post" action="index.php" target="_parent">' . "\n"
1043 . PMA_generate_common_hidden_inputs() . "\n"
1044 . PMA_Config
::_getFontsizeSelection() . "\n"
1045 . '<noscript>' . "\n"
1046 . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1047 . '</noscript>' . "\n"
1054 * @uses PMA_Config::isHttps()
1055 * @uses PMA_Config::getCookiePath()
1058 * @param string $cookie name of cookie to remove
1059 * @return boolean result of setcookie()
1061 function removeCookie($cookie)
1063 return setcookie($cookie, '', time() - 3600,
1064 $this->getCookiePath(), '', $this->isHttps());
1068 * sets cookie if value is different from current cokkie value,
1069 * or removes if value is equal to default
1071 * @uses PMA_Config::isHttps()
1072 * @uses PMA_Config::getCookiePath()
1074 * @uses PMA_Config::removeCookie()
1077 * @param string $cookie name of cookie to remove
1078 * @param mixed $value new cookie value
1079 * @param string $default default value
1080 * @param int $validity validity of cookie in seconds (default is one month)
1081 * @param bool $httponlt whether cookie is only for HTTP (and not for scripts)
1082 * @return boolean result of setcookie()
1084 function setCookie($cookie, $value, $default = null, $validity = null, $httponly = true)
1086 if ($validity == null) {
1087 $validity = 2592000;
1089 if (strlen($value) && null !== $default && $value === $default
1090 && isset($_COOKIE[$cookie])) {
1091 // remove cookie, default value is used
1092 return $this->removeCookie($cookie);
1095 if (! strlen($value) && isset($_COOKIE[$cookie])) {
1096 // remove cookie, value is empty
1097 return $this->removeCookie($cookie);
1100 if (! isset($_COOKIE[$cookie]) ||
$_COOKIE[$cookie] !== $value) {
1101 // set cookie with new value
1102 /* Calculate cookie validity */
1103 if ($validity == 0) {
1106 $v = time() +
$validity;
1108 return setcookie($cookie, $value, $v,
1109 $this->getCookiePath(), '', $this->isHttps(), $httponly);
1112 // cookie has already $value as value