Translated using Weblate (Estonian)
[phpmyadmin.git] / libraries / Config.class.php
blobec2545b052d815e3e14fe4b5102d4e8ecba62686
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Configuration handling.
6 * @package PhpMyAdmin
7 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * Load vendor configuration.
16 require_once './libraries/vendor_config.php';
18 /**
19 * Configuration class
21 * @package PhpMyAdmin
23 class PMA_Config
25 /**
26 * @var string default config source
28 var $default_source = './libraries/config.default.php';
30 /**
31 * @var array default configuration settings
33 var $default = array();
35 /**
36 * @var array configuration settings
38 var $settings = array();
40 /**
41 * @var string config source
43 var $source = '';
45 /**
46 * @var int source modification time
48 var $source_mtime = 0;
49 var $default_source_mtime = 0;
50 var $set_mtime = 0;
52 /**
53 * @var boolean
55 var $error_config_file = false;
57 /**
58 * @var boolean
60 var $error_config_default_file = false;
62 /**
63 * @var boolean
65 var $error_pma_uri = false;
67 /**
68 * @var array
70 var $default_server = array();
72 /**
73 * @var boolean whether init is done or not
74 * set this to false to force some initial checks
75 * like checking for required functions
77 var $done = false;
79 /**
80 * constructor
82 * @param string $source source to read config from
84 function __construct($source = null)
86 $this->settings = array();
88 // functions need to refresh in case of config file changed goes in
89 // PMA_Config::load()
90 $this->load($source);
92 // other settings, independent from config file, comes in
93 $this->checkSystem();
95 $this->isHttps();
98 /**
99 * sets system and application settings
101 * @return void
103 function checkSystem()
105 $this->set('PMA_VERSION', '4.1-dev');
107 * @deprecated
109 $this->set('PMA_THEME_VERSION', 2);
111 * @deprecated
113 $this->set('PMA_THEME_GENERATION', 2);
115 $this->checkPhpVersion();
116 $this->checkWebServerOs();
117 $this->checkWebServer();
118 $this->checkGd2();
119 $this->checkClient();
120 $this->checkUpload();
121 $this->checkUploadSize();
122 $this->checkOutputCompression();
126 * whether to use gzip output compression or not
128 * @return void
130 function checkOutputCompression()
132 // If zlib output compression is set in the php configuration file, no
133 // output buffering should be run
134 if (@ini_get('zlib.output_compression')) {
135 $this->set('OBGzip', false);
138 // disable output-buffering (if set to 'auto') for IE6, else enable it.
139 if (strtolower($this->get('OBGzip')) == 'auto') {
140 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
141 && $this->get('PMA_USR_BROWSER_VER') >= 6
142 && $this->get('PMA_USR_BROWSER_VER') < 7
144 $this->set('OBGzip', false);
145 } else {
146 $this->set('OBGzip', true);
152 * Determines platform (OS), browser and version of the user
153 * Based on a phpBuilder article:
155 * @see http://www.phpbuilder.net/columns/tim20000821.php
157 * @return void
159 function checkClient()
161 if (PMA_getenv('HTTP_USER_AGENT')) {
162 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
163 } else {
164 $HTTP_USER_AGENT = '';
167 // 1. Platform
168 if (strstr($HTTP_USER_AGENT, 'Win')) {
169 $this->set('PMA_USR_OS', 'Win');
170 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
171 $this->set('PMA_USR_OS', 'Mac');
172 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
173 $this->set('PMA_USR_OS', 'Linux');
174 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
175 $this->set('PMA_USR_OS', 'Unix');
176 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
177 $this->set('PMA_USR_OS', 'OS/2');
178 } else {
179 $this->set('PMA_USR_OS', 'Other');
182 // 2. browser and version
183 // (must check everything else before Mozilla)
185 $is_mozilla = preg_match(
186 '@Mozilla/([0-9].[0-9]{1,2})@',
187 $HTTP_USER_AGENT,
188 $mozilla_version
191 if (preg_match(
192 '@Opera(/| )([0-9].[0-9]{1,2})@',
193 $HTTP_USER_AGENT,
194 $log_version
195 )) {
196 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
197 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
198 } elseif (preg_match(
199 '@(MS)?IE ([0-9]{1,2}.[0-9]{1,2})@',
200 $HTTP_USER_AGENT,
201 $log_version
202 )) {
203 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
204 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
205 } elseif (preg_match(
206 '@OmniWeb/([0-9].[0-9]{1,2})@',
207 $HTTP_USER_AGENT,
208 $log_version
209 )) {
210 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
211 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
212 // Konqueror 2.2.2 says Konqueror/2.2.2
213 // Konqueror 3.0.3 says Konqueror/3
214 } elseif (preg_match(
215 '@(Konqueror/)(.*)(;)@',
216 $HTTP_USER_AGENT,
217 $log_version
218 )) {
219 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
220 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
221 // must check Chrome before Safari
222 } elseif ($is_mozilla
223 && preg_match('@Chrome/([0-9.]*)@', $HTTP_USER_AGENT, $log_version)
225 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
226 $this->set('PMA_USR_BROWSER_AGENT', 'CHROME');
227 // newer Safari
228 } elseif ($is_mozilla
229 && preg_match('@Version/(.*) Safari@', $HTTP_USER_AGENT, $log_version)
231 $this->set(
232 'PMA_USR_BROWSER_VER', $log_version[1]
234 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
235 // older Safari
236 } elseif ($is_mozilla
237 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version)
239 $this->set(
240 'PMA_USR_BROWSER_VER', $mozilla_version[1] . '.' . $log_version[1]
242 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
243 // Firefox
244 } elseif (! strstr($HTTP_USER_AGENT, 'compatible')
245 && preg_match('@Firefox/([\w.]+)@', $HTTP_USER_AGENT, $log_version)
247 $this->set(
248 'PMA_USR_BROWSER_VER', $log_version[1]
250 $this->set('PMA_USR_BROWSER_AGENT', 'FIREFOX');
251 } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
252 $this->set('PMA_USR_BROWSER_VER', '1.9');
253 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
254 } elseif ($is_mozilla) {
255 $this->set('PMA_USR_BROWSER_VER', $mozilla_version[1]);
256 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
257 } else {
258 $this->set('PMA_USR_BROWSER_VER', 0);
259 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
264 * Whether GD2 is present
266 * @return void
268 function checkGd2()
270 if ($this->get('GD2Available') == 'yes') {
271 $this->set('PMA_IS_GD2', 1);
272 } elseif ($this->get('GD2Available') == 'no') {
273 $this->set('PMA_IS_GD2', 0);
274 } else {
275 if (!@function_exists('imagecreatetruecolor')) {
276 $this->set('PMA_IS_GD2', 0);
277 } else {
278 if (@function_exists('gd_info')) {
279 $gd_nfo = gd_info();
280 if (strstr($gd_nfo["GD Version"], '2.')) {
281 $this->set('PMA_IS_GD2', 1);
282 } else {
283 $this->set('PMA_IS_GD2', 0);
285 } else {
286 $this->set('PMA_IS_GD2', 0);
293 * Whether the Web server php is running on is IIS
295 * @return void
297 function checkWebServer()
299 // some versions return Microsoft-IIS, some Microsoft/IIS
300 // we could use a preg_match() but it's slower
301 if (PMA_getenv('SERVER_SOFTWARE')
302 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
303 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')
305 $this->set('PMA_IS_IIS', 1);
306 } else {
307 $this->set('PMA_IS_IIS', 0);
312 * Whether the os php is running on is windows or not
314 * @return void
316 function checkWebServerOs()
318 // Default to Unix or Equiv
319 $this->set('PMA_IS_WINDOWS', 0);
320 // If PHP_OS is defined then continue
321 if (defined('PHP_OS')) {
322 if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
323 // Is it some version of Windows
324 $this->set('PMA_IS_WINDOWS', 1);
325 } elseif (stristr(PHP_OS, 'OS/2')) {
326 // Is it OS/2 (No file permissions like Windows)
327 $this->set('PMA_IS_WINDOWS', 1);
333 * detects PHP version
335 * @return void
337 function checkPhpVersion()
339 $match = array();
340 if (! preg_match(
341 '@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
342 phpversion(),
343 $match
344 )) {
345 preg_match(
346 '@([0-9]{1,2}).([0-9]{1,2})@',
347 phpversion(),
348 $match
351 if (isset($match) && ! empty($match[1])) {
352 if (! isset($match[2])) {
353 $match[2] = 0;
355 if (! isset($match[3])) {
356 $match[3] = 0;
358 $this->set(
359 'PMA_PHP_INT_VERSION',
360 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3])
362 } else {
363 $this->set('PMA_PHP_INT_VERSION', 0);
365 $this->set('PMA_PHP_STR_VERSION', phpversion());
369 * detects if Git revision
371 * @return boolean
373 function isGitRevision()
375 // caching
376 if (isset($_SESSION['is_git_revision'])) {
377 if ($_SESSION['is_git_revision']) {
378 $this->set('PMA_VERSION_GIT', 1);
380 return $_SESSION['is_git_revision'];
382 // find out if there is a .git folder
383 $git_folder = '.git';
384 if (! @file_exists($git_folder)
385 || ! @file_exists($git_folder . '/config')
387 $_SESSION['is_git_revision'] = false;
388 return false;
390 $_SESSION['is_git_revision'] = true;
391 return true;
395 * detects Git revision, if running inside repo
397 * @return void
399 function checkGitRevision()
401 // find out if there is a .git folder
402 $git_folder = '.git';
403 if (! $this->isGitRevision()) {
404 return;
407 if (! $ref_head = @file_get_contents($git_folder . '/HEAD')) {
408 return;
410 $branch = false;
411 // are we on any branch?
412 if (strstr($ref_head, '/')) {
413 $ref_head = substr(trim($ref_head), 5);
414 if (substr($ref_head, 0, 11) === 'refs/heads/') {
415 $branch = substr($ref_head, 11);
416 } else {
417 $branch = basename($ref_head);
420 $ref_file = $git_folder . '/' . $ref_head;
421 if (@file_exists($ref_file)) {
422 $hash = @file_get_contents($ref_file);
423 if (! $hash) {
424 return;
426 $hash = trim($hash);
427 } else {
428 // deal with packed refs
429 $packed_refs = @file_get_contents($git_folder . '/packed-refs');
430 if (! $packed_refs) {
431 return;
433 // split file to lines
434 $ref_lines = explode("\n", $packed_refs);
435 foreach ($ref_lines as $line) {
436 // skip comments
437 if ($line[0] == '#') {
438 continue;
440 // parse line
441 $parts = explode(' ', $line);
442 // care only about named refs
443 if (count($parts) != 2) {
444 continue;
446 // have found our ref?
447 if ($parts[1] == $ref_head) {
448 $hash = $parts[0];
449 break;
452 if (! isset($hash)) {
453 // Could not find ref
454 return;
457 } else {
458 $hash = trim($ref_head);
461 $commit = false;
462 if (! isset($_SESSION['PMA_VERSION_COMMITDATA_' . $hash])) {
463 $git_file_name = $git_folder . '/objects/' . substr($hash, 0, 2)
464 . '/' . substr($hash, 2);
465 if (file_exists($git_file_name) ) {
466 if (! $commit = @file_get_contents($git_file_name)) {
467 return;
469 $commit = explode("\0", gzuncompress($commit), 2);
470 $commit = explode("\n", $commit[1]);
471 $_SESSION['PMA_VERSION_COMMITDATA_' . $hash] = $commit;
472 } else {
473 $pack_names = array();
474 // work with packed data
475 $packs_file = $git_folder . '/objects/info/packs';
476 if (file_exists($packs_file)
477 && $packs = @file_get_contents($packs_file)
479 // File exists. Read it, parse the file to get the names of the
480 // packs. (to look for them in .git/object/pack directory later)
481 foreach (explode("\n", $packs) as $line) {
482 // skip blank lines
483 if (strlen(trim($line)) == 0) {
484 continue;
486 // skip non pack lines
487 if ($line[0] != 'P') {
488 continue;
490 // parse names
491 $pack_names[] = substr($line, 2);
493 } else {
494 // '.git/objects/info/packs' file can be missing
495 // (atlease in mysGit)
496 // File missing. May be we can look in the .git/object/pack
497 // directory for all the .pack files and use that list of
498 // files instead
499 $it = new DirectoryIterator($git_folder . '/objects/pack');
500 foreach ($it as $file_info) {
501 $file_name = $file_info->getFilename();
502 // if this is a .pack file
503 if ($file_info->isFile()
504 && substr($file_name, -5) == '.pack'
506 $pack_names[] = $file_name;
510 $hash = strtolower($hash);
511 foreach ($pack_names as $pack_name) {
512 $index_name = str_replace('.pack', '.idx', $pack_name);
514 // load index
515 $index_data = @file_get_contents(
516 $git_folder . '/objects/pack/' . $index_name
518 if (! $index_data) {
519 continue;
521 // check format
522 if (substr($index_data, 0, 4) != "\377tOc") {
523 continue;
525 // check version
526 $version = unpack('N', substr($index_data, 4, 4));
527 if ($version[1] != 2) {
528 continue;
530 // parse fanout table
531 $fanout = unpack("N*", substr($index_data, 8, 256 * 4));
533 // find where we should search
534 $firstbyte = intval(substr($hash, 0, 2), 16);
535 // array is indexed from 1 and we need to get
536 // previous entry for start
537 if ($firstbyte == 0) {
538 $start = 0;
539 } else {
540 $start = $fanout[$firstbyte];
542 $end = $fanout[$firstbyte + 1];
544 // stupid linear search for our sha
545 $position = $start;
546 $found = false;
547 $offset = 8 + (256 * 4);
548 for ($position = $start; $position < $end; $position++) {
549 $sha = strtolower(
550 bin2hex(
551 substr(
552 $index_data, $offset + ($position * 20), 20
556 if ($sha == $hash) {
557 $found = true;
558 break;
561 if (! $found) {
562 continue;
564 // read pack offset
565 $offset = 8 + (256 * 4) + (24 * $fanout[256]);
566 $pack_offset = unpack(
567 'N', substr($index_data, $offset + ($position * 4), 4)
569 $pack_offset = $pack_offset[1];
571 // open pack file
572 $pack_file = fopen(
573 $git_folder . '/objects/pack/' . $pack_name, 'rb'
575 if ($pack_file === false) {
576 continue;
578 // seek to start
579 fseek($pack_file, $pack_offset);
581 // parse header
582 $header = ord(fread($pack_file, 1));
583 $type = ($header >> 4) & 7;
584 $hasnext = ($header & 128) >> 7;
585 $size = $header & 0xf;
586 $offset = 4;
588 while ($hasnext) {
589 $byte = ord(fread($pack_file, 1));
590 $size |= ($byte & 0x7f) << $offset;
591 $hasnext = ($byte & 128) >> 7;
592 $offset += 7;
595 // we care only about commit objects
596 if ($type != 1) {
597 continue;
600 // read data
601 $commit = fread($pack_file, $size);
602 $commit = gzuncompress($commit);
603 $commit = explode("\n", $commit);
604 $_SESSION['PMA_VERSION_COMMITDATA_' . $hash] = $commit;
605 fclose($pack_file);
608 } else {
609 $commit = $_SESSION['PMA_VERSION_COMMITDATA_' . $hash];
612 // check if commit exists in Github
613 $is_remote_commit = false;
614 if ($commit !== false
615 && isset($_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash])
617 $is_remote_commit = $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash];
618 } else {
619 $link = 'https://api.github.com/repos/phpmyadmin/phpmyadmin/git/commits/'
620 . $hash;
621 $is_found = $this->checkHTTP($link, ! $commit);
622 switch($is_found) {
623 case false:
624 $is_remote_commit = false;
625 $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash] = false;
626 break;
627 case null:
628 // no remote link for now, but don't cache this as Github is down
629 $is_remote_commit = false;
630 break;
631 default:
632 $is_remote_commit = true;
633 $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash] = true;
634 if ($commit === false) {
635 // if no local commit data, try loading from Github
636 $commit_json = json_decode($is_found);
638 break;
642 $is_remote_branch = false;
643 if ($is_remote_commit && $branch !== false) {
644 // check if branch exists in Github
645 if (isset($_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash])) {
646 $is_remote_branch = $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash];
647 } else {
648 $link = 'https://api.github.com/repos/phpmyadmin/phpmyadmin'
649 . '/git/trees/' . $branch;
650 $is_found = $this->checkHTTP($link);
651 switch($is_found) {
652 case true:
653 $is_remote_branch = true;
654 $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash] = true;
655 break;
656 case false:
657 $is_remote_branch = false;
658 $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash] = false;
659 break;
660 case null:
661 // no remote link for now, but don't cache this as Github is down
662 $is_remote_branch = false;
663 break;
668 if ($commit !== false) {
669 $author = array('name' => '', 'email' => '', 'date' => '');
670 $committer = array('name' => '', 'email' => '', 'date' => '');
672 do {
673 $dataline = array_shift($commit);
674 $datalinearr = explode(' ', $dataline, 2);
675 $linetype = $datalinearr[0];
676 if (in_array($linetype, array('author', 'committer'))) {
677 $user = $datalinearr[1];
678 preg_match('/([^<]+)<([^>]+)> ([0-9]+)( [^ ]+)?/', $user, $user);
679 $user2 = array(
680 'name' => trim($user[1]),
681 'email' => trim($user[2]),
682 'date' => date('Y-m-d H:i:s', $user[3]));
683 if (isset($user[4])) {
684 $user2['date'] .= $user[4];
686 $$linetype = $user2;
688 } while ($dataline != '');
689 $message = trim(implode(' ', $commit));
691 } elseif (isset($commit_json)) {
692 $author = array(
693 'name' => $commit_json->author->name,
694 'email' => $commit_json->author->email,
695 'date' => $commit_json->author->date);
696 $committer = array(
697 'name' => $commit_json->committer->name,
698 'email' => $commit_json->committer->email,
699 'date' => $commit_json->committer->date);
700 $message = trim($commit_json->message);
701 } else {
702 return;
705 $this->set('PMA_VERSION_GIT', 1);
706 $this->set('PMA_VERSION_GIT_COMMITHASH', $hash);
707 $this->set('PMA_VERSION_GIT_BRANCH', $branch);
708 $this->set('PMA_VERSION_GIT_MESSAGE', $message);
709 $this->set('PMA_VERSION_GIT_AUTHOR', $author);
710 $this->set('PMA_VERSION_GIT_COMMITTER', $committer);
711 $this->set('PMA_VERSION_GIT_ISREMOTECOMMIT', $is_remote_commit);
712 $this->set('PMA_VERSION_GIT_ISREMOTEBRANCH', $is_remote_branch);
716 * Checks if given URL is 200 or 404, optionally returns data
718 * @param mixed $link curl link
719 * @param boolean $get_body whether to retrieve body of document
721 * @return test result or data
723 function checkHTTP($link, $get_body = false)
725 if (! function_exists('curl_init')) {
726 return null;
728 $ch = curl_init($link);
729 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
730 curl_setopt($ch, CURLOPT_HEADER, 1);
731 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
732 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
733 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
734 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
735 curl_setopt($ch, CURLOPT_USERAGENT, 'phpMyAdmin/' . PMA_VERSION);
736 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
737 $data = @curl_exec($ch);
738 if ($data === false) {
739 return null;
741 $ok = 'HTTP/1.1 200 OK';
742 $notfound = 'HTTP/1.1 404 Not Found';
743 if (substr($data, 0, strlen($ok)) === $ok) {
744 return $get_body ? substr($data, strpos($data, "\r\n\r\n") + 4) : true;
745 } elseif (substr($data, 0, strlen($notfound)) === $notfound) {
746 return false;
748 return null;
752 * loads default values from default source
754 * @return boolean success
756 function loadDefaults()
758 $cfg = array();
759 if (! file_exists($this->default_source)) {
760 $this->error_config_default_file = true;
761 return false;
763 include $this->default_source;
765 $this->default_source_mtime = filemtime($this->default_source);
767 $this->default_server = $cfg['Servers'][1];
768 unset($cfg['Servers']);
770 $this->default = $cfg;
771 $this->settings = PMA_arrayMergeRecursive($this->settings, $cfg);
773 $this->error_config_default_file = false;
775 return true;
779 * loads configuration from $source, usally the config file
780 * should be called on object creation
782 * @param string $source config file
784 * @return bool
786 function load($source = null)
788 $this->loadDefaults();
790 if (null !== $source) {
791 $this->setSource($source);
794 if (! $this->checkConfigSource()) {
795 return false;
798 $cfg = array();
801 * Parses the configuration file, we throw away any errors or
802 * output.
804 $old_error_reporting = error_reporting(0);
805 ob_start();
806 $GLOBALS['pma_config_loading'] = true;
807 $eval_result = include $this->getSource();
808 $GLOBALS['pma_config_loading'] = false;
809 ob_end_clean();
810 error_reporting($old_error_reporting);
812 if ($eval_result === false) {
813 $this->error_config_file = true;
814 } else {
815 $this->error_config_file = false;
816 $this->source_mtime = filemtime($this->getSource());
820 * Backward compatibility code
822 if (!empty($cfg['DefaultTabTable'])) {
823 $cfg['DefaultTabTable'] = str_replace(
824 '_properties',
826 str_replace(
827 'tbl_properties.php',
828 'tbl_sql.php',
829 $cfg['DefaultTabTable']
833 if (!empty($cfg['DefaultTabDatabase'])) {
834 $cfg['DefaultTabDatabase'] = str_replace(
835 '_details',
837 str_replace(
838 'db_details.php',
839 'db_sql.php',
840 $cfg['DefaultTabDatabase']
845 $this->settings = PMA_arrayMergeRecursive($this->settings, $cfg);
846 $this->checkPmaAbsoluteUri();
847 $this->checkFontsize();
849 // Handling of the collation must be done after merging of $cfg
850 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
851 // can have an effect. Note that the presence of collation
852 // information in a cookie has priority over what is defined
853 // in the default or user's config files.
855 * @todo check validity of $_COOKIE['pma_collation_connection']
857 if (! empty($_COOKIE['pma_collation_connection'])) {
858 $this->set(
859 'collation_connection',
860 strip_tags($_COOKIE['pma_collation_connection'])
862 } else {
863 $this->set(
864 'collation_connection',
865 $this->get('DefaultConnectionCollation')
868 // Now, a collation information could come from REQUEST
869 // (an example of this: the collation selector in index.php)
870 // so the following handles the setting of collation_connection
871 // and later, in common.inc.php, the cookie will be set
872 // according to this.
873 $this->checkCollationConnection();
875 return true;
879 * Loads user preferences and merges them with current config
880 * must be called after control connection has been estabilished
882 * @return boolean
884 function loadUserPreferences()
886 // index.php should load these settings, so that phpmyadmin.css.php
887 // will have everything avaiable in session cache
888 $server = isset($GLOBALS['server'])
889 ? $GLOBALS['server']
890 : (!empty($GLOBALS['cfg']['ServerDefault'])
891 ? $GLOBALS['cfg']['ServerDefault']
892 : 0);
893 $cache_key = 'server_' . $server;
894 if ($server > 0 && !defined('PMA_MINIMUM_COMMON')) {
895 $config_mtime = max($this->default_source_mtime, $this->source_mtime);
896 // cache user preferences, use database only when needed
897 if (! isset($_SESSION['cache'][$cache_key]['userprefs'])
898 || $_SESSION['cache'][$cache_key]['config_mtime'] < $config_mtime
900 // load required libraries
901 include_once './libraries/user_preferences.lib.php';
902 $prefs = PMA_loadUserprefs();
903 $_SESSION['cache'][$cache_key]['userprefs']
904 = PMA_applyUserprefs($prefs['config_data']);
905 $_SESSION['cache'][$cache_key]['userprefs_mtime'] = $prefs['mtime'];
906 $_SESSION['cache'][$cache_key]['userprefs_type'] = $prefs['type'];
907 $_SESSION['cache'][$cache_key]['config_mtime'] = $config_mtime;
909 } elseif ($server == 0
910 || ! isset($_SESSION['cache'][$cache_key]['userprefs'])
912 $this->set('user_preferences', false);
913 return;
915 $config_data = $_SESSION['cache'][$cache_key]['userprefs'];
916 // type is 'db' or 'session'
917 $this->set(
918 'user_preferences',
919 $_SESSION['cache'][$cache_key]['userprefs_type']
921 $this->set(
922 'user_preferences_mtime',
923 $_SESSION['cache'][$cache_key]['userprefs_mtime']
926 // backup some settings
927 $org_fontsize = '';
928 if (isset($this->settings['fontsize'])) {
929 $org_fontsize = $this->settings['fontsize'];
931 // load config array
932 $this->settings = PMA_arrayMergeRecursive($this->settings, $config_data);
933 $GLOBALS['cfg'] = PMA_arrayMergeRecursive($GLOBALS['cfg'], $config_data);
934 if (defined('PMA_MINIMUM_COMMON')) {
935 return;
938 // settings below start really working on next page load, but
939 // changes are made only in index.php so everything is set when
940 // in frames
942 // save theme
943 $tmanager = $_SESSION['PMA_Theme_Manager'];
944 if ($tmanager->getThemeCookie() || isset($_REQUEST['set_theme'])) {
945 if ((! isset($config_data['ThemeDefault'])
946 && $tmanager->theme->getId() != 'original')
947 || isset($config_data['ThemeDefault'])
948 && $config_data['ThemeDefault'] != $tmanager->theme->getId()
950 // new theme was set in common.inc.php
951 $this->setUserValue(
952 null,
953 'ThemeDefault',
954 $tmanager->theme->getId(),
955 'original'
958 } else {
959 // no cookie - read default from settings
960 if ($this->settings['ThemeDefault'] != $tmanager->theme->getId()
961 && $tmanager->checkTheme($this->settings['ThemeDefault'])
963 $tmanager->setActiveTheme($this->settings['ThemeDefault']);
964 $tmanager->setThemeCookie();
968 // save font size
969 if ((! isset($config_data['fontsize'])
970 && $org_fontsize != '82%')
971 || isset($config_data['fontsize'])
972 && $org_fontsize != $config_data['fontsize']
974 $this->setUserValue(null, 'fontsize', $org_fontsize, '82%');
977 // save language
978 if (isset($_COOKIE['pma_lang']) || isset($_POST['lang'])) {
979 if ((! isset($config_data['lang'])
980 && $GLOBALS['lang'] != 'en')
981 || isset($config_data['lang'])
982 && $GLOBALS['lang'] != $config_data['lang']
984 $this->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
986 } else {
987 // read language from settings
988 if (isset($config_data['lang']) && PMA_langSet($config_data['lang'])) {
989 $this->setCookie('pma_lang', $GLOBALS['lang']);
993 // save connection collation
994 if (isset($_COOKIE['pma_collation_connection'])
995 || isset($_POST['collation_connection'])
997 if ((! isset($config_data['collation_connection'])
998 && $GLOBALS['collation_connection'] != 'utf8_general_ci')
999 || isset($config_data['collation_connection'])
1000 && $GLOBALS['collation_connection'] != $config_data['collation_connection']
1002 $this->setUserValue(
1003 null,
1004 'collation_connection',
1005 $GLOBALS['collation_connection'],
1006 'utf8_general_ci'
1009 } else {
1010 // read collation from settings
1011 if (isset($config_data['collation_connection'])) {
1012 $GLOBALS['collation_connection']
1013 = $config_data['collation_connection'];
1014 $this->setCookie(
1015 'pma_collation_connection',
1016 $GLOBALS['collation_connection']
1023 * Sets config value which is stored in user preferences (if available)
1024 * or in a cookie.
1026 * If user preferences are not yet initialized, option is applied to
1027 * global config and added to a update queue, which is processed
1028 * by {@link loadUserPreferences()}
1030 * @param string $cookie_name can be null
1031 * @param string $cfg_path configuration path
1032 * @param mixed $new_cfg_value new value
1033 * @param mixed $default_value default value
1035 * @return void
1037 function setUserValue($cookie_name, $cfg_path, $new_cfg_value,
1038 $default_value = null
1040 // use permanent user preferences if possible
1041 $prefs_type = $this->get('user_preferences');
1042 if ($prefs_type) {
1043 include_once './libraries/user_preferences.lib.php';
1044 if ($default_value === null) {
1045 $default_value = PMA_arrayRead($cfg_path, $this->default);
1047 PMA_persistOption($cfg_path, $new_cfg_value, $default_value);
1049 if ($prefs_type != 'db' && $cookie_name) {
1050 // fall back to cookies
1051 if ($default_value === null) {
1052 $default_value = PMA_arrayRead($cfg_path, $this->settings);
1054 $this->setCookie($cookie_name, $new_cfg_value, $default_value);
1056 PMA_arrayWrite($cfg_path, $GLOBALS['cfg'], $new_cfg_value);
1057 PMA_arrayWrite($cfg_path, $this->settings, $new_cfg_value);
1061 * Reads value stored by {@link setUserValue()}
1063 * @param string $cookie_name cookie name
1064 * @param mixed $cfg_value config value
1066 * @return mixed
1068 function getUserValue($cookie_name, $cfg_value)
1070 $cookie_exists = isset($_COOKIE) && !empty($_COOKIE[$cookie_name]);
1071 $prefs_type = $this->get('user_preferences');
1072 if ($prefs_type == 'db') {
1073 // permanent user preferences value exists, remove cookie
1074 if ($cookie_exists) {
1075 $this->removeCookie($cookie_name);
1077 } else if ($cookie_exists) {
1078 return $_COOKIE[$cookie_name];
1080 // return value from $cfg array
1081 return $cfg_value;
1085 * set source
1087 * @param string $source source
1089 * @return void
1091 function setSource($source)
1093 $this->source = trim($source);
1097 * check config source
1099 * @return boolean whether source is valid or not
1101 function checkConfigSource()
1103 if (! $this->getSource()) {
1104 // no configuration file set at all
1105 return false;
1108 if (! file_exists($this->getSource())) {
1109 $this->source_mtime = 0;
1110 return false;
1113 if (! is_readable($this->getSource())) {
1114 // manually check if file is readable
1115 // might be bug #3059806 Supporting running from CIFS/Samba shares
1117 $contents = false;
1118 $handle = @fopen($this->getSource(), 'r');
1119 if ($handle !== false) {
1120 $contents = @fread($handle, 1); // reading 1 byte is enough to test
1121 @fclose($handle);
1123 if ($contents === false) {
1124 $this->source_mtime = 0;
1125 PMA_fatalError(
1126 sprintf(
1127 function_exists('__')
1128 ? __('Existing configuration file (%s) is not readable.')
1129 : 'Existing configuration file (%s) is not readable.',
1130 $this->getSource()
1133 return false;
1137 return true;
1141 * verifies the permissions on config file (if asked by configuration)
1142 * (must be called after config.inc.php has been merged)
1144 * @return void
1146 function checkPermissions()
1148 // Check for permissions (on platforms that support it):
1149 if ($this->get('CheckConfigurationPermissions')) {
1150 $perms = @fileperms($this->getSource());
1151 if (!($perms === false) && ($perms & 2)) {
1152 // This check is normally done after loading configuration
1153 $this->checkWebServerOs();
1154 if ($this->get('PMA_IS_WINDOWS') == 0) {
1155 $this->source_mtime = 0;
1156 PMA_fatalError(
1158 'Wrong permissions on configuration file, '
1159 . 'should not be world writable!'
1168 * returns specific config setting
1170 * @param string $setting config setting
1172 * @return mixed value
1174 function get($setting)
1176 if (isset($this->settings[$setting])) {
1177 return $this->settings[$setting];
1179 return null;
1183 * sets configuration variable
1185 * @param string $setting configuration option
1186 * @param mixed $value new value for configuration option
1188 * @return void
1190 function set($setting, $value)
1192 if (! isset($this->settings[$setting])
1193 || $this->settings[$setting] !== $value
1195 $this->settings[$setting] = $value;
1196 $this->set_mtime = time();
1201 * returns source for current config
1203 * @return string config source
1205 function getSource()
1207 return $this->source;
1211 * returns a unique value to force a CSS reload if either the config
1212 * or the theme changes
1213 * must also check the pma_fontsize cookie in case there is no
1214 * config file
1216 * @return int Summary of unix timestamps and fontsize,
1217 * to be unique on theme parameters change
1219 function getThemeUniqueValue()
1221 if (null !== $this->get('fontsize')) {
1222 $fontsize = intval($this->get('fontsize'));
1223 } elseif (isset($_COOKIE['pma_fontsize'])) {
1224 $fontsize = intval($_COOKIE['pma_fontsize']);
1225 } else {
1226 $fontsize = 0;
1228 return (
1229 $fontsize +
1230 $this->source_mtime +
1231 $this->default_source_mtime +
1232 $this->get('user_preferences_mtime') +
1233 $_SESSION['PMA_Theme']->mtime_info +
1234 $_SESSION['PMA_Theme']->filesize_info);
1238 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
1239 * set properly and, depending on browsers, inserting or updating a
1240 * record might fail
1242 * @return bool
1244 function checkPmaAbsoluteUri()
1246 // Setup a default value to let the people and lazy sysadmins work anyway,
1247 // they'll get an error if the autodetect code doesn't work
1248 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
1249 $is_https = $this->detectHttps();
1251 if (strlen($pma_absolute_uri) < 5) {
1252 $url = array();
1254 // If we don't have scheme, we didn't have full URL so we need to
1255 // dig deeper
1256 if (empty($url['scheme'])) {
1257 // Scheme
1258 if ($is_https) {
1259 $url['scheme'] = 'https';
1260 } else {
1261 $url['scheme'] = 'http';
1264 // Host and port
1265 if (PMA_getenv('HTTP_HOST')) {
1266 // Prepend the scheme before using parse_url() since this
1267 // is not part of the RFC2616 Host request-header
1268 $parsed_url = parse_url(
1269 $url['scheme'] . '://' . PMA_getenv('HTTP_HOST')
1271 if (!empty($parsed_url['host'])) {
1272 $url = $parsed_url;
1273 } else {
1274 $url['host'] = PMA_getenv('HTTP_HOST');
1276 } elseif (PMA_getenv('SERVER_NAME')) {
1277 $url['host'] = PMA_getenv('SERVER_NAME');
1278 } else {
1279 $this->error_pma_uri = true;
1280 return false;
1283 // If we didn't set port yet...
1284 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
1285 $url['port'] = PMA_getenv('SERVER_PORT');
1288 // And finally the path could be already set from REQUEST_URI
1289 if (empty($url['path'])) {
1290 // we got a case with nginx + php-fpm where PHP_SELF
1291 // was not set, so PMA_PHP_SELF was not set as well
1292 if (isset($GLOBALS['PMA_PHP_SELF'])) {
1293 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
1294 } else {
1295 $path = parse_url(PMA_getenv('REQUEST_URI'));
1297 $url['path'] = $path['path'];
1301 // Make url from parts we have
1302 $pma_absolute_uri = $url['scheme'] . '://';
1303 // Was there user information?
1304 if (!empty($url['user'])) {
1305 $pma_absolute_uri .= $url['user'];
1306 if (!empty($url['pass'])) {
1307 $pma_absolute_uri .= ':' . $url['pass'];
1309 $pma_absolute_uri .= '@';
1311 // Add hostname
1312 $pma_absolute_uri .= $url['host'];
1313 // Add port, if it not the default one
1314 if (! empty($url['port'])
1315 && (($url['scheme'] == 'http' && $url['port'] != 80)
1316 || ($url['scheme'] == 'https' && $url['port'] != 443))
1318 $pma_absolute_uri .= ':' . $url['port'];
1320 // And finally path, without script name, the 'a' is there not to
1321 // strip our directory, when path is only /pmadir/ without filename.
1322 // Backslashes returned by Windows have to be changed.
1323 // Only replace backslashes by forward slashes if on Windows,
1324 // as the backslash could be valid on a non-Windows system.
1325 $this->checkWebServerOs();
1326 if ($this->get('PMA_IS_WINDOWS') == 1) {
1327 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
1328 } else {
1329 $path = dirname($url['path'] . 'a');
1332 // To work correctly within javascript
1333 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../') {
1334 if ($this->get('PMA_IS_WINDOWS') == 1) {
1335 $path = str_replace("\\", "/", dirname($path));
1336 } else {
1337 $path = dirname($path);
1341 // PHP's dirname function would have returned a dot
1342 // when $path contains no slash
1343 if ($path == '.') {
1344 $path = '';
1346 // in vhost situations, there could be already an ending slash
1347 if (substr($path, -1) != '/') {
1348 $path .= '/';
1350 $pma_absolute_uri .= $path;
1352 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
1353 // the autodetect code works well enough that we don't display the
1354 // warning at all. The user can still set PmaAbsoluteUri manually.
1356 } else {
1357 // The URI is specified, however users do often specify this
1358 // wrongly, so we try to fix this.
1360 // Adds a trailing slash et the end of the phpMyAdmin uri if it
1361 // does not exist.
1362 if (substr($pma_absolute_uri, -1) != '/') {
1363 $pma_absolute_uri .= '/';
1366 // If URI doesn't start with http:// or https://, we will add
1367 // this.
1368 if (substr($pma_absolute_uri, 0, 7) != 'http://'
1369 && substr($pma_absolute_uri, 0, 8) != 'https://'
1371 $pma_absolute_uri
1372 = ($is_https ? 'https' : 'http')
1373 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
1374 . $pma_absolute_uri;
1377 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
1381 * Converts currently used PmaAbsoluteUri to SSL based variant.
1383 * @return String witch adjusted URI
1385 function getSSLUri()
1387 // grab current URL
1388 $url = $this->get('PmaAbsoluteUri');
1389 // Parse current URL
1390 $parsed = parse_url($url);
1391 // In case parsing has failed do stupid string replacement
1392 if ($parsed === false) {
1393 // Replace http protocol
1394 return preg_replace('@^http:@', 'https:', $url);
1397 // Reconstruct URL using parsed parts
1398 if ($this->get('SSLPort')) {
1399 $port_number = $this->get('SSLPort');
1400 } else {
1401 $port_number = 443;
1403 return 'https://' . $parsed['host'] . ':' . $port_number . $parsed['path'];
1407 * check selected collation_connection
1409 * @todo check validity of $_REQUEST['collation_connection']
1411 * @return void
1413 function checkCollationConnection()
1415 if (! empty($_REQUEST['collation_connection'])) {
1416 $this->set(
1417 'collation_connection',
1418 strip_tags($_REQUEST['collation_connection'])
1424 * checks for font size configuration, and sets font size as requested by user
1426 * @return void
1428 function checkFontsize()
1430 $new_fontsize = '';
1432 if (isset($_GET['set_fontsize'])) {
1433 $new_fontsize = $_GET['set_fontsize'];
1434 } elseif (isset($_POST['set_fontsize'])) {
1435 $new_fontsize = $_POST['set_fontsize'];
1436 } elseif (isset($_COOKIE['pma_fontsize'])) {
1437 $new_fontsize = $_COOKIE['pma_fontsize'];
1440 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
1441 $this->set('fontsize', $new_fontsize);
1442 } elseif (! $this->get('fontsize')) {
1443 // 80% would correspond to the default browser font size
1444 // of 16, but use 82% to help read the monoface font
1445 $this->set('fontsize', '82%');
1448 $this->setCookie('pma_fontsize', $this->get('fontsize'), '82%');
1452 * checks if upload is enabled
1454 * @return void
1456 function checkUpload()
1458 if (ini_get('file_uploads')) {
1459 $this->set('enable_upload', true);
1460 // if set "php_admin_value file_uploads Off" in httpd.conf
1461 // ini_get() also returns the string "Off" in this case:
1462 if ('off' == strtolower(ini_get('file_uploads'))) {
1463 $this->set('enable_upload', false);
1465 } else {
1466 $this->set('enable_upload', false);
1471 * Maximum upload size as limited by PHP
1472 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
1474 * this section generates $max_upload_size in bytes
1476 * @return void
1478 function checkUploadSize()
1480 if (! $filesize = ini_get('upload_max_filesize')) {
1481 $filesize = "5M";
1484 if ($postsize = ini_get('post_max_size')) {
1485 $this->set(
1486 'max_upload_size',
1487 min(PMA_getRealSize($filesize), PMA_getRealSize($postsize))
1489 } else {
1490 $this->set('max_upload_size', PMA_getRealSize($filesize));
1495 * Checks if protocol is https
1497 * This function checks if the https protocol is used in the PmaAbsoluteUri
1498 * configuration setting, as opposed to detectHttps() which checks if the
1499 * https protocol is used on the active connection.
1501 * @return bool
1503 public function isHttps()
1506 if (null !== $this->get('is_https')) {
1507 return $this->get('is_https');
1510 $url = parse_url($this->get('PmaAbsoluteUri'));
1511 $is_https = null;
1513 if (isset($url['scheme']) && $url['scheme'] == 'https') {
1514 $is_https = true;
1515 } else {
1516 $is_https = false;
1519 $this->set('is_https', $is_https);
1521 return $is_https;
1525 * Detects whether https appears to be used.
1527 * This function checks if the https protocol is used in the current connection
1528 * with the webserver, based on environment variables.
1529 * Please note that this just detects what we see, so
1530 * it completely ignores things like reverse proxies.
1532 * @return bool
1534 function detectHttps()
1536 $is_https = false;
1538 $url = array();
1540 // At first we try to parse REQUEST_URI, it might contain full URL,
1541 if (PMA_getenv('REQUEST_URI')) {
1542 // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
1543 $url = @parse_url(PMA_getenv('REQUEST_URI'));
1544 if ($url === false) {
1545 $url = array();
1549 // If we don't have scheme, we didn't have full URL so we need to
1550 // dig deeper
1551 if (empty($url['scheme'])) {
1552 // Scheme
1553 if (PMA_getenv('HTTP_SCHEME')) {
1554 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
1555 } elseif (PMA_getenv('HTTPS')
1556 && strtolower(PMA_getenv('HTTPS')) == 'on'
1558 $url['scheme'] = 'https';
1559 } elseif (PMA_getenv('HTTP_X_FORWARDED_PROTO')) {
1560 $url['scheme'] = strtolower(PMA_getenv('HTTP_X_FORWARDED_PROTO'));
1561 } elseif (PMA_getenv('HTTP_FRONT_END_HTTPS')
1562 && strtolower(PMA_getenv('HTTP_FRONT_END_HTTPS')) == 'on'
1564 $url['scheme'] = 'https';
1565 } else {
1566 $url['scheme'] = 'http';
1570 if (isset($url['scheme']) && $url['scheme'] == 'https') {
1571 $is_https = true;
1572 } else {
1573 $is_https = false;
1576 return $is_https;
1580 * detect correct cookie path
1582 * @return void
1584 function checkCookiePath()
1586 $this->set('cookie_path', $this->getCookiePath());
1590 * Get cookie path
1592 * @return string
1594 public function getCookiePath()
1596 static $cookie_path = null;
1598 if (null !== $cookie_path && !defined('TESTSUITE')) {
1599 return $cookie_path;
1602 $parsed_url = parse_url($this->get('PmaAbsoluteUri'));
1604 $cookie_path = $parsed_url['path'];
1606 return $cookie_path;
1610 * enables backward compatibility
1612 * @return void
1614 function enableBc()
1616 $GLOBALS['cfg'] = $this->settings;
1617 $GLOBALS['default_server'] = $this->default_server;
1618 unset($this->default_server);
1619 $GLOBALS['collation_connection'] = $this->get('collation_connection');
1620 $GLOBALS['is_upload'] = $this->get('enable_upload');
1621 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
1622 $GLOBALS['cookie_path'] = $this->get('cookie_path');
1623 $GLOBALS['is_https'] = $this->get('is_https');
1625 $defines = array(
1626 'PMA_VERSION',
1627 'PMA_THEME_VERSION',
1628 'PMA_THEME_GENERATION',
1629 'PMA_PHP_STR_VERSION',
1630 'PMA_PHP_INT_VERSION',
1631 'PMA_IS_WINDOWS',
1632 'PMA_IS_IIS',
1633 'PMA_IS_GD2',
1634 'PMA_USR_OS',
1635 'PMA_USR_BROWSER_VER',
1636 'PMA_USR_BROWSER_AGENT'
1639 foreach ($defines as $define) {
1640 if (! defined($define)) {
1641 define($define, $this->get($define));
1647 * returns options for font size selection
1649 * @param string $current_size current selected font size with unit
1651 * @return array selectable font sizes
1653 * @static
1655 static protected function getFontsizeOptions($current_size = '82%')
1657 $unit = preg_replace('/[0-9.]*/', '', $current_size);
1658 $value = preg_replace('/[^0-9.]*/', '', $current_size);
1660 $factors = array();
1661 $options = array();
1662 $options["$value"] = $value . $unit;
1664 if ($unit === '%') {
1665 $factors[] = 1;
1666 $factors[] = 5;
1667 $factors[] = 10;
1668 } elseif ($unit === 'em') {
1669 $factors[] = 0.05;
1670 $factors[] = 0.2;
1671 $factors[] = 1;
1672 } elseif ($unit === 'pt') {
1673 $factors[] = 0.5;
1674 $factors[] = 2;
1675 } elseif ($unit === 'px') {
1676 $factors[] = 1;
1677 $factors[] = 5;
1678 $factors[] = 10;
1679 } else {
1680 //unknown font size unit
1681 $factors[] = 0.05;
1682 $factors[] = 0.2;
1683 $factors[] = 1;
1684 $factors[] = 5;
1685 $factors[] = 10;
1688 foreach ($factors as $key => $factor) {
1689 $option_inc = $value + $factor;
1690 $option_dec = $value - $factor;
1691 while (count($options) < 21) {
1692 $options["$option_inc"] = $option_inc . $unit;
1693 if ($option_dec > $factors[0]) {
1694 $options["$option_dec"] = $option_dec . $unit;
1696 $option_inc += $factor;
1697 $option_dec -= $factor;
1698 if (isset($factors[$key + 1])
1699 && $option_inc >= $value + $factors[$key + 1]
1701 break;
1705 ksort($options);
1706 return $options;
1710 * returns html selectbox for font sizes
1712 * @static
1714 * @return string html selectbox
1716 static protected function getFontsizeSelection()
1718 $current_size = $GLOBALS['PMA_Config']->get('fontsize');
1719 // for the case when there is no config file (this is supported)
1720 if (empty($current_size)) {
1721 if (isset($_COOKIE['pma_fontsize'])) {
1722 $current_size = $_COOKIE['pma_fontsize'];
1723 } else {
1724 $current_size = '82%';
1727 $options = PMA_Config::getFontsizeOptions($current_size);
1729 $return = '<label for="select_fontsize">' . __('Font size')
1730 . ':</label>' . "\n"
1731 . '<select name="set_fontsize" id="select_fontsize"'
1732 . ' class="autosubmit">' . "\n";
1733 foreach ($options as $option) {
1734 $return .= '<option value="' . $option . '"';
1735 if ($option == $current_size) {
1736 $return .= ' selected="selected"';
1738 $return .= '>' . $option . '</option>' . "\n";
1740 $return .= '</select>';
1742 return $return;
1746 * return complete font size selection form
1748 * @static
1750 * @return string html selectbox
1752 static public function getFontsizeForm()
1754 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1755 . ' method="get" action="index.php" class="disableAjax">' . "\n"
1756 . PMA_URL_getHiddenInputs() . "\n"
1757 . PMA_Config::getFontsizeSelection() . "\n"
1758 . '</form>';
1762 * removes cookie
1764 * @param string $cookie name of cookie to remove
1766 * @return boolean result of setcookie()
1768 function removeCookie($cookie)
1770 if (defined('TESTSUITE')) {
1771 if (isset($_COOKIE[$cookie])) {
1772 unset($_COOKIE[$cookie]);
1774 return true;
1776 return setcookie(
1777 $cookie,
1779 time() - 3600,
1780 $this->getCookiePath(),
1782 $this->isHttps()
1787 * sets cookie if value is different from current cookie value,
1788 * or removes if value is equal to default
1790 * @param string $cookie name of cookie to remove
1791 * @param mixed $value new cookie value
1792 * @param string $default default value
1793 * @param int $validity validity of cookie in seconds (default is one month)
1794 * @param bool $httponly whether cookie is only for HTTP (and not for scripts)
1796 * @return boolean result of setcookie()
1798 function setCookie($cookie, $value, $default = null, $validity = null,
1799 $httponly = true
1801 if (strlen($value) && null !== $default && $value === $default) {
1802 // default value is used
1803 if (isset($_COOKIE[$cookie])) {
1804 // remove cookie
1805 return $this->removeCookie($cookie);
1807 return false;
1810 if (! strlen($value) && isset($_COOKIE[$cookie])) {
1811 // remove cookie, value is empty
1812 return $this->removeCookie($cookie);
1815 if (! isset($_COOKIE[$cookie]) || $_COOKIE[$cookie] !== $value) {
1816 // set cookie with new value
1817 /* Calculate cookie validity */
1818 if ($validity === null) {
1819 $validity = time() + 2592000;
1820 } elseif ($validity == 0) {
1821 $validity = 0;
1822 } else {
1823 $validity = time() + $validity;
1825 if (defined('TESTSUITE')) {
1826 $_COOKIE[$cookie] = $value;
1827 return true;
1829 return setcookie(
1830 $cookie,
1831 $value,
1832 $validity,
1833 $this->getCookiePath(),
1835 $this->isHttps(),
1836 $httponly
1840 // cookie has already $value as value
1841 return true;
1847 * Error handler to catch fatal errors when loading configuration
1848 * file
1850 * @return void
1852 function PMA_Config_fatalErrorHandler()
1854 if ($GLOBALS['pma_config_loading']) {
1855 $error = error_get_last();
1856 if ($error !== null) {
1857 PMA_fatalError(
1858 sprintf(
1859 'Failed to load phpMyAdmin configuration (%s:%s): %s',
1860 PMA_Error::relPath($error['file']),
1861 $error['line'],
1862 $error['message']
1869 if (!defined('TESTSUITE')) {
1870 $GLOBALS['pma_config_loading'] = false;
1871 register_shutdown_function('PMA_Config_fatalErrorHandler');