2 /* vim: set expandtab sw=4 ts=4 sts=4: */
10 * Load vendor configuration.
12 require('./libraries/vendor_config.php');
22 * @var string default config source
24 var $default_source = './libraries/config.default.php';
27 * @var array configuration settings
29 var $settings = array();
32 * @var string config source
37 * @var int source modification time
39 var $source_mtime = 0;
40 var $default_source_mtime = 0;
46 var $error_config_file = false;
51 var $error_config_default_file = false;
56 var $error_pma_uri = false;
61 var $default_server = array();
64 * @var boolean whether init is done or not
65 * set this to false to force some initial checks
66 * like checking for required functions
73 * @param string source to read config from
75 function __construct($source = null)
77 $this->settings
= array();
79 // functions need to refresh in case of config file changed goes in
83 // other settings, independent from config file, comes in
86 $this->checkIsHttps();
90 * sets system and application settings
92 function checkSystem()
94 $this->set('PMA_VERSION', '3.4.0-dev');
98 $this->set('PMA_THEME_VERSION', 2);
102 $this->set('PMA_THEME_GENERATION', 2);
104 $this->checkPhpVersion();
105 $this->checkWebServerOs();
106 $this->checkWebServer();
108 $this->checkClient();
109 $this->checkUpload();
110 $this->checkUploadSize();
111 $this->checkOutputCompression();
115 * whether to use gzip output compression or not
117 function checkOutputCompression()
119 // If zlib output compression is set in the php configuration file, no
120 // output buffering should be run
121 if (@ini_get
('zlib.output_compression')) {
122 $this->set('OBGzip', false);
125 // disable output-buffering (if set to 'auto') for IE6, else enable it.
126 if (strtolower($this->get('OBGzip')) == 'auto') {
127 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
128 && $this->get('PMA_USR_BROWSER_VER') >= 6
129 && $this->get('PMA_USR_BROWSER_VER') < 7) {
130 $this->set('OBGzip', false);
132 $this->set('OBGzip', true);
138 * Determines platform (OS), browser and version of the user
139 * Based on a phpBuilder article:
140 * @see http://www.phpbuilder.net/columns/tim20000821.php
142 function checkClient()
144 if (PMA_getenv('HTTP_USER_AGENT')) {
145 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
146 } elseif (!isset($HTTP_USER_AGENT)) {
147 $HTTP_USER_AGENT = '';
151 if (strstr($HTTP_USER_AGENT, 'Win')) {
152 $this->set('PMA_USR_OS', 'Win');
153 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
154 $this->set('PMA_USR_OS', 'Mac');
155 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
156 $this->set('PMA_USR_OS', 'Linux');
157 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
158 $this->set('PMA_USR_OS', 'Unix');
159 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
160 $this->set('PMA_USR_OS', 'OS/2');
162 $this->set('PMA_USR_OS', 'Other');
165 // 2. browser and version
166 // (must check everything else before Mozilla)
168 if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
169 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
170 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
171 } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
172 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
173 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
174 } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
175 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
176 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
177 // Konqueror 2.2.2 says Konqueror/2.2.2
178 // Konqueror 3.0.3 says Konqueror/3
179 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
180 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
181 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
182 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
183 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
184 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
185 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
186 } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
187 $this->set('PMA_USR_BROWSER_VER', '1.9');
188 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
189 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
190 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
191 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
193 $this->set('PMA_USR_BROWSER_VER', 0);
194 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
199 * Whether GD2 is present
203 if ($this->get('GD2Available') == 'yes') {
204 $this->set('PMA_IS_GD2', 1);
205 } elseif ($this->get('GD2Available') == 'no') {
206 $this->set('PMA_IS_GD2', 0);
208 if (!@function_exists
('imagecreatetruecolor')) {
209 $this->set('PMA_IS_GD2', 0);
211 if (@function_exists
('gd_info')) {
213 if (strstr($gd_nfo["GD Version"], '2.')) {
214 $this->set('PMA_IS_GD2', 1);
216 $this->set('PMA_IS_GD2', 0);
219 /* We must do hard way... but almost no chance to execute this */
221 phpinfo(INFO_MODULES
); /* Only modules */
222 $a = strip_tags(ob_get_contents());
224 /* Get GD version string from phpinfo output */
225 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
226 if (strstr($v, '2.')) {
227 $this->set('PMA_IS_GD2', 1);
229 $this->set('PMA_IS_GD2', 0);
232 $this->set('PMA_IS_GD2', 0);
240 * Whether the Web server php is running on is IIS
242 function checkWebServer()
244 if (PMA_getenv('SERVER_SOFTWARE')
245 // some versions return Microsoft-IIS, some Microsoft/IIS
246 // we could use a preg_match() but it's slower
247 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
248 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
249 $this->set('PMA_IS_IIS', 1);
251 $this->set('PMA_IS_IIS', 0);
256 * Whether the os php is running on is windows or not
258 function checkWebServerOs()
260 // Default to Unix or Equiv
261 $this->set('PMA_IS_WINDOWS', 0);
262 // If PHP_OS is defined then continue
263 if (defined('PHP_OS')) {
264 if (stristr(PHP_OS
, 'win')) {
265 // Is it some version of Windows
266 $this->set('PMA_IS_WINDOWS', 1);
267 } elseif (stristr(PHP_OS
, 'OS/2')) {
268 // Is it OS/2 (No file permissions like Windows)
269 $this->set('PMA_IS_WINDOWS', 1);
275 * detects PHP version
277 function checkPhpVersion()
280 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
281 phpversion(), $match)) {
282 $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
283 phpversion(), $match);
285 if (isset($match) && ! empty($match[1])) {
286 if (! isset($match[2])) {
289 if (! isset($match[3])) {
292 $this->set('PMA_PHP_INT_VERSION',
293 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
295 $this->set('PMA_PHP_INT_VERSION', 0);
297 $this->set('PMA_PHP_STR_VERSION', phpversion());
301 * loads default values from default source
303 * @uses file_exists()
304 * @uses $this->default_source
305 * @uses $this->error_config_default_file
306 * @uses $this->settings
307 * @return boolean success
309 function loadDefaults()
312 if (! file_exists($this->default_source
)) {
313 $this->error_config_default_file
= true;
316 include $this->default_source
;
318 $this->default_source_mtime
= filemtime($this->default_source
);
320 $this->default_server
= $cfg['Servers'][1];
321 unset($cfg['Servers']);
323 $this->settings
= PMA_array_merge_recursive($this->settings
, $cfg);
325 $this->error_config_default_file
= false;
331 * loads configuration from $source, usally the config file
332 * should be called on object creation
334 * @param string $source config file
336 function load($source = null)
338 $this->loadDefaults();
340 if (null !== $source) {
341 $this->setSource($source);
344 if (! $this->checkConfigSource()) {
351 * Parses the configuration file
353 $old_error_reporting = error_reporting(0);
354 if (function_exists('file_get_contents')) {
356 eval('?' . '>' . trim(file_get_contents($this->getSource())));
359 eval('?' . '>' . trim(implode("\n", file($this->getSource()))));
361 error_reporting($old_error_reporting);
363 if ($eval_result === false) {
364 $this->error_config_file
= true;
366 $this->error_config_file
= false;
367 $this->source_mtime
= filemtime($this->getSource());
371 * Backward compatibility code
373 if (!empty($cfg['DefaultTabTable'])) {
374 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
376 if (!empty($cfg['DefaultTabDatabase'])) {
377 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
380 $this->settings
= PMA_array_merge_recursive($this->settings
, $cfg);
381 $this->checkPmaAbsoluteUri();
382 $this->checkFontsize();
384 $this->checkPermissions();
386 // Handling of the collation must be done after merging of $cfg
387 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
388 // can have an effect. Note that the presence of collation
389 // information in a cookie has priority over what is defined
390 // in the default or user's config files.
392 * @todo check validity of $_COOKIE['pma_collation_connection']
394 if (! empty($_COOKIE['pma_collation_connection'])) {
395 $this->set('collation_connection',
396 strip_tags($_COOKIE['pma_collation_connection']));
398 $this->set('collation_connection',
399 $this->get('DefaultConnectionCollation'));
401 // Now, a collation information could come from REQUEST
402 // (an example of this: the collation selector in main.php)
403 // so the following handles the setting of collation_connection
404 // and later, in common.inc.php, the cookie will be set
405 // according to this.
406 $this->checkCollationConnection();
413 * @param string $source
415 function setSource($source)
417 $this->source
= trim($source);
421 * checks if the config folder still exists and terminates app if true
423 function checkConfigFolder()
425 // Refuse to work while there still might be some world writable dir:
426 if (is_dir('./config')) {
427 die('Remove "./config" directory before using phpMyAdmin!');
432 * check config source
434 * @return boolean whether source is valid or not
436 function checkConfigSource()
438 if (! $this->getSource()) {
439 // no configuration file set at all
443 if (! file_exists($this->getSource())) {
444 // do not trigger error here
445 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
448 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
451 $this->source_mtime
= 0;
455 if (! is_readable($this->getSource())) {
456 $this->source_mtime
= 0;
457 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
464 * verifies the permissions on config file (if asked by configuration)
465 * (must be called after config.inc.php has been merged)
467 function checkPermissions()
469 // Check for permissions (on platforms that support it):
470 if ($this->get('CheckConfigurationPermissions')) {
471 $perms = @fileperms
($this->getSource());
472 if (!($perms === false) && ($perms & 2)) {
473 // This check is normally done after loading configuration
474 $this->checkWebServerOs();
475 if ($this->get('PMA_IS_WINDOWS') == 0) {
476 $this->source_mtime
= 0;
477 die('Wrong permissions on configuration file, should not be world writable!');
484 * returns specific config setting
485 * @param string $setting
486 * @return mixed value
488 function get($setting)
490 if (isset($this->settings
[$setting])) {
491 return $this->settings
[$setting];
497 * sets configuration variable
499 * @uses $this->settings
500 * @param string $setting configuration option
501 * @param string $value new value for configuration option
503 function set($setting, $value)
505 if (!isset($this->settings
[$setting]) ||
$this->settings
[$setting] != $value) {
506 $this->settings
[$setting] = $value;
507 $this->set_mtime
= time();
512 * returns source for current config
513 * @return string config source
517 return $this->source
;
521 * returns a unique value to force a CSS reload if either the config
522 * or the theme changes
523 * must also check the pma_fontsize cookie in case there is no
525 * @return int Unix timestamp
527 function getThemeUniqueValue()
529 if (null !== $this->get('fontsize')) {
530 $fontsize = intval($this->get('fontsize'));
531 } elseif (isset($_COOKIE['pma_fontsize'])) {
532 $fontsize = intval($_COOKIE['pma_fontsize']);
538 $this->source_mtime +
539 $this->default_source_mtime +
540 $_SESSION['PMA_Theme']->mtime_info +
541 $_SESSION['PMA_Theme']->filesize_info
)
542 . (isset($_SESSION['tmp_user_values']['custom_color']) ?
substr($_SESSION['tmp_user_values']['custom_color'],1,6) : '');
546 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
547 * set properly and, depending on browsers, inserting or updating a
550 function checkPmaAbsoluteUri()
552 // Setup a default value to let the people and lazy sysadmins work anyway,
553 // they'll get an error if the autodetect code doesn't work
554 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
555 $is_https = $this->detectHttps();
557 if (strlen($pma_absolute_uri) < 5) {
560 // At first we try to parse REQUEST_URI, it might contain full URL
562 * REQUEST_URI contains PATH_INFO too, this is not what we want
563 * script-php/pathinfo/
564 if (PMA_getenv('REQUEST_URI')) {
565 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
566 if ($url === false) {
567 $url = array('path' => $_SERVER['REQUEST_URI']);
572 // If we don't have scheme, we didn't have full URL so we need to
574 if (empty($url['scheme'])) {
576 if (PMA_getenv('HTTP_SCHEME')) {
577 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
580 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
586 if (PMA_getenv('HTTP_HOST')) {
587 // Prepend the scheme before using parse_url() since this is not part of the RFC2616 Host request-header
588 $parsed_url = parse_url($url['scheme'] . '://' . PMA_getenv('HTTP_HOST'));
589 if (!empty($parsed_url['host'])) {
592 $url['host'] = PMA_getenv('HTTP_HOST');
594 } elseif (PMA_getenv('SERVER_NAME')) {
595 $url['host'] = PMA_getenv('SERVER_NAME');
597 $this->error_pma_uri
= true;
601 // If we didn't set port yet...
602 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
603 $url['port'] = PMA_getenv('SERVER_PORT');
606 // And finally the path could be already set from REQUEST_URI
607 if (empty($url['path'])) {
609 * REQUEST_URI contains PATH_INFO too, this is not what we want
610 * script-php/pathinfo/
611 if (PMA_getenv('PATH_INFO')) {
612 $path = parse_url(PMA_getenv('PATH_INFO'));
614 // PHP_SELF in CGI often points to cgi executable, so use it
617 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
619 $url['path'] = $path['path'];
623 // Make url from parts we have
624 $pma_absolute_uri = $url['scheme'] . '://';
625 // Was there user information?
626 if (!empty($url['user'])) {
627 $pma_absolute_uri .= $url['user'];
628 if (!empty($url['pass'])) {
629 $pma_absolute_uri .= ':' . $url['pass'];
631 $pma_absolute_uri .= '@';
634 $pma_absolute_uri .= $url['host'];
635 // Add port, if it not the default one
636 if (! empty($url['port'])
637 && (($url['scheme'] == 'http' && $url['port'] != 80)
638 ||
($url['scheme'] == 'https' && $url['port'] != 443))) {
639 $pma_absolute_uri .= ':' . $url['port'];
641 // And finally path, without script name, the 'a' is there not to
642 // strip our directory, when path is only /pmadir/ without filename.
643 // Backslashes returned by Windows have to be changed.
644 // Only replace backslashes by forward slashes if on Windows,
645 // as the backslash could be valid on a non-Windows system.
646 $this->checkWebServerOs();
647 if ($this->get('PMA_IS_WINDOWS') == 1) {
648 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
650 $path = dirname($url['path'] . 'a');
653 // To work correctly within transformations overview:
654 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR
== '../../') {
655 if ($this->get('PMA_IS_WINDOWS') == 1) {
656 $path = str_replace("\\", "/", dirname(dirname($path)));
658 $path = dirname(dirname($path));
662 // PHP's dirname function would have returned a dot when $path contains no slash
666 // in vhost situations, there could be already an ending slash
667 if (substr($path, -1) != '/') {
670 $pma_absolute_uri .= $path;
672 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
673 // the autodetect code works well enough that we don't display the
674 // warning at all. The user can still set PmaAbsoluteUri manually.
676 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
679 // The URI is specified, however users do often specify this
680 // wrongly, so we try to fix this.
682 // Adds a trailing slash et the end of the phpMyAdmin uri if it
684 if (substr($pma_absolute_uri, -1) != '/') {
685 $pma_absolute_uri .= '/';
688 // If URI doesn't start with http:// or https://, we will add
690 if (substr($pma_absolute_uri, 0, 7) != 'http://'
691 && substr($pma_absolute_uri, 0, 8) != 'https://') {
693 ($is_https ?
'https' : 'http')
694 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ?
'' : '//')
698 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
702 * check selected collation_connection
703 * @todo check validity of $_REQUEST['collation_connection']
705 function checkCollationConnection()
707 if (! empty($_REQUEST['collation_connection'])) {
708 $this->set('collation_connection',
709 strip_tags($_REQUEST['collation_connection']));
714 * checks for font size configuration, and sets font size as requested by user
720 * @uses function_exists()
721 * @uses PMA_Config::set()
722 * @uses PMA_Config::get()
723 * @uses PMA_Config::setCookie()
725 function checkFontsize()
729 if (isset($_GET['fontsize'])) {
730 $new_fontsize = $_GET['fontsize'];
731 } elseif (isset($_POST['fontsize'])) {
732 $new_fontsize = $_POST['fontsize'];
733 } elseif (isset($_COOKIE['pma_fontsize'])) {
734 $new_fontsize = $_COOKIE['pma_fontsize'];
737 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
738 $this->set('fontsize', $new_fontsize);
739 } elseif (! $this->get('fontsize')) {
740 // 80% would correspond to the default browser font size
741 // of 16, but use 82% to help read the monoface font
742 $this->set('fontsize', '82%');
745 $this->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);
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')) {
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)));
783 $this->set('max_upload_size', PMA_get_real_size($filesize));
790 function checkIsHttps()
792 $this->set('is_https', $this->isHttps());
798 public function isHttps()
800 static $is_https = null;
802 if (null !== $is_https) {
806 $url = parse_url($this->get('PmaAbsoluteUri'));
808 if (isset($url['scheme'])
809 && $url['scheme'] == 'https') {
819 * Detects whether https appears to be used.
821 * Please note that this just detects what we see, so
822 * it completely ignores things like reverse proxies.
824 function detectHttps()
830 // At first we try to parse REQUEST_URI, it might contain full URL,
831 if (PMA_getenv('REQUEST_URI')) {
832 $url = @parse_url
(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
838 // If we don't have scheme, we didn't have full URL so we need to
840 if (empty($url['scheme'])) {
842 if (PMA_getenv('HTTP_SCHEME')) {
843 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
846 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
852 if (isset($url['scheme'])
853 && $url['scheme'] == 'https') {
863 * detect correct cookie path
865 function checkCookiePath()
867 $this->set('cookie_path', $this->getCookiePath());
873 public function getCookiePath()
875 static $cookie_path = null;
877 if (null !== $cookie_path) {
881 $parsed_url = parse_url($this->get('PmaAbsoluteUri'));
883 $cookie_path = $parsed_url['path'];
889 * enables backward compatibility
893 $GLOBALS['cfg'] = $this->settings
;
894 $GLOBALS['default_server'] = $this->default_server
;
895 unset($this->default_server
);
896 $GLOBALS['collation_connection'] = $this->get('collation_connection');
897 $GLOBALS['is_upload'] = $this->get('enable_upload');
898 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
899 $GLOBALS['cookie_path'] = $this->get('cookie_path');
900 $GLOBALS['is_https'] = $this->get('is_https');
905 'PMA_THEME_GENERATION',
906 'PMA_PHP_STR_VERSION',
907 'PMA_PHP_INT_VERSION',
912 'PMA_USR_BROWSER_VER',
913 'PMA_USR_BROWSER_AGENT'
916 foreach ($defines as $define) {
917 if (! defined($define)) {
918 define($define, $this->get($define));
929 * returns options for font size selection
931 * @uses preg_replace()
934 * @param string $current_size current selected font size with unit
935 * @return array selectable font sizes
937 static protected function _getFontsizeOptions($current_size = '82%')
939 $unit = preg_replace('/[0-9.]*/', '', $current_size);
940 $value = preg_replace('/[^0-9.]*/', '', $current_size);
944 $options["$value"] = $value . $unit;
950 } elseif ($unit === 'em') {
954 } elseif ($unit === 'pt') {
957 } elseif ($unit === 'px') {
962 //unknown font size unit
970 foreach ($factors as $key => $factor) {
971 $option_inc = $value +
$factor;
972 $option_dec = $value - $factor;
973 while (count($options) < 21) {
974 $options["$option_inc"] = $option_inc . $unit;
975 if ($option_dec > $factors[0]) {
976 $options["$option_dec"] = $option_dec . $unit;
978 $option_inc +
= $factor;
979 $option_dec -= $factor;
980 if (isset($factors[$key +
1])
981 && $option_inc >= $value +
$factors[$key +
1]) {
991 * returns html selectbox for font sizes
993 * @uses $GLOBALS['PMA_Config']
994 * @uses PMA_Config::get()
995 * @uses PMA_Config::_getFontsizeOptions()
997 * @param string $current_size currently slected font size with unit
998 * @return string html selectbox
1000 static protected function _getFontsizeSelection()
1002 $current_size = $GLOBALS['PMA_Config']->get('fontsize');
1003 // for the case when there is no config file (this is supported)
1004 if (empty($current_size)) {
1005 if (isset($_COOKIE['pma_fontsize'])) {
1006 $current_size = $_COOKIE['pma_fontsize'];
1008 $current_size = '82%';
1011 $options = PMA_Config
::_getFontsizeOptions($current_size);
1013 $return = '<label for="select_fontsize">' . __('Font size') . ':</label>' . "\n";
1014 $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
1015 foreach ($options as $option) {
1016 $return .= '<option value="' . $option . '"';
1017 if ($option == $current_size) {
1018 $return .= ' selected="selected"';
1020 $return .= '>' . $option . '</option>' . "\n";
1022 $return .= '</select>';
1028 * return complete font size selection form
1030 * @uses PMA_generate_common_hidden_inputs()
1031 * @uses PMA_Config::_getFontsizeSelection()
1033 * @param string $current_size currently slected font size with unit
1034 * @return string html selectbox
1036 static public function getFontsizeForm()
1038 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1039 . ' method="post" action="index.php" target="_parent">' . "\n"
1040 . PMA_generate_common_hidden_inputs() . "\n"
1041 . PMA_Config
::_getFontsizeSelection() . "\n"
1042 . '<noscript>' . "\n"
1043 . '<input type="submit" value="' . __('Go') . '" />' . "\n"
1044 . '</noscript>' . "\n"
1051 * @uses PMA_Config::isHttps()
1052 * @uses PMA_Config::getCookiePath()
1055 * @param string $cookie name of cookie to remove
1056 * @return boolean result of setcookie()
1058 function removeCookie($cookie)
1060 return setcookie($cookie, '', time() - 3600,
1061 $this->getCookiePath(), '', $this->isHttps());
1065 * sets cookie if value is different from current cokkie value,
1066 * or removes if value is equal to default
1068 * @uses PMA_Config::isHttps()
1069 * @uses PMA_Config::getCookiePath()
1071 * @uses PMA_Config::removeCookie()
1074 * @param string $cookie name of cookie to remove
1075 * @param mixed $value new cookie value
1076 * @param string $default default value
1077 * @param int $validity validity of cookie in seconds (default is one month)
1078 * @param bool $httponlt whether cookie is only for HTTP (and not for scripts)
1079 * @return boolean result of setcookie()
1081 function setCookie($cookie, $value, $default = null, $validity = null, $httponly = true)
1083 if ($validity == null) {
1084 $validity = 2592000;
1086 if (strlen($value) && null !== $default && $value === $default) {
1087 // default value is used
1088 if (isset($_COOKIE[$cookie])) {
1090 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