Update edih_x12file_class.php (#295)
[openemr.git] / phpmyadmin / libraries / Config.class.php
blob262791f1179b3257ee6adbd50f450832eaf73e7d
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 * Indication for error handler (see end of this file).
21 $GLOBALS['pma_config_loading'] = false;
23 /**
24 * Configuration class
26 * @package PhpMyAdmin
28 class PMA_Config
30 /**
31 * @var string default config source
33 var $default_source = './libraries/config.default.php';
35 /**
36 * @var array default configuration settings
38 var $default = array();
40 /**
41 * @var array configuration settings, without user preferences applied
43 var $base_settings = array();
45 /**
46 * @var array configuration settings
48 var $settings = array();
50 /**
51 * @var string config source
53 var $source = '';
55 /**
56 * @var int source modification time
58 var $source_mtime = 0;
59 var $default_source_mtime = 0;
60 var $set_mtime = 0;
62 /**
63 * @var boolean
65 var $error_config_file = false;
67 /**
68 * @var boolean
70 var $error_config_default_file = false;
72 /**
73 * @var boolean
75 var $error_pma_uri = false;
77 /**
78 * @var array
80 var $default_server = array();
82 /**
83 * @var boolean whether init is done or not
84 * set this to false to force some initial checks
85 * like checking for required functions
87 var $done = false;
89 /**
90 * constructor
92 * @param string $source source to read config from
94 public function __construct($source = null)
96 $this->settings = array();
98 // functions need to refresh in case of config file changed goes in
99 // PMA_Config::load()
100 $this->load($source);
102 // other settings, independent from config file, comes in
103 $this->checkSystem();
105 $this->isHttps();
107 $this->base_settings = $this->settings;
111 * sets system and application settings
113 * @return void
115 public function checkSystem()
117 $this->set('PMA_VERSION', '4.5.4.1');
119 * @deprecated
121 $this->set('PMA_THEME_VERSION', 2);
123 * @deprecated
125 $this->set('PMA_THEME_GENERATION', 2);
127 $this->checkPhpVersion();
128 $this->checkWebServerOs();
129 $this->checkWebServer();
130 $this->checkGd2();
131 $this->checkClient();
132 $this->checkUpload();
133 $this->checkUploadSize();
134 $this->checkOutputCompression();
138 * whether to use gzip output compression or not
140 * @return void
142 public function checkOutputCompression()
144 // If zlib output compression is set in the php configuration file, no
145 // output buffering should be run
146 if (@ini_get('zlib.output_compression')) {
147 $this->set('OBGzip', false);
150 // disable output-buffering (if set to 'auto') for IE6, else enable it.
151 if (strtolower($this->get('OBGzip')) == 'auto') {
152 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
153 && $this->get('PMA_USR_BROWSER_VER') >= 6
154 && $this->get('PMA_USR_BROWSER_VER') < 7
156 $this->set('OBGzip', false);
157 } else {
158 $this->set('OBGzip', true);
164 * Sets the client platform based on user agent
166 * @param string $user_agent the user agent
168 * @return void
170 private function _setClientPlatform($user_agent)
172 if (/*overload*/mb_strstr($user_agent, 'Win')) {
173 $this->set('PMA_USR_OS', 'Win');
174 } elseif (/*overload*/mb_strstr($user_agent, 'Mac')) {
175 $this->set('PMA_USR_OS', 'Mac');
176 } elseif (/*overload*/mb_strstr($user_agent, 'Linux')) {
177 $this->set('PMA_USR_OS', 'Linux');
178 } elseif (/*overload*/mb_strstr($user_agent, 'Unix')) {
179 $this->set('PMA_USR_OS', 'Unix');
180 } elseif (/*overload*/mb_strstr($user_agent, 'OS/2')) {
181 $this->set('PMA_USR_OS', 'OS/2');
182 } else {
183 $this->set('PMA_USR_OS', 'Other');
188 * Determines platform (OS), browser and version of the user
189 * Based on a phpBuilder article:
191 * @see http://www.phpbuilder.net/columns/tim20000821.php
193 * @return void
195 public function checkClient()
197 if (PMA_getenv('HTTP_USER_AGENT')) {
198 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
199 } else {
200 $HTTP_USER_AGENT = '';
203 // 1. Platform
204 $this->_setClientPlatform($HTTP_USER_AGENT);
206 // 2. browser and version
207 // (must check everything else before Mozilla)
209 $is_mozilla = preg_match(
210 '@Mozilla/([0-9].[0-9]{1,2})@',
211 $HTTP_USER_AGENT,
212 $mozilla_version
215 if (preg_match(
216 '@Opera(/| )([0-9].[0-9]{1,2})@',
217 $HTTP_USER_AGENT,
218 $log_version
219 )) {
220 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
221 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
222 } elseif (preg_match(
223 '@(MS)?IE ([0-9]{1,2}.[0-9]{1,2})@',
224 $HTTP_USER_AGENT,
225 $log_version
226 )) {
227 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
228 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
229 } elseif (preg_match(
230 '@Trident/(7)\.0@',
231 $HTTP_USER_AGENT,
232 $log_version
233 )) {
234 $this->set('PMA_USR_BROWSER_VER', intval($log_version[1]) + 4);
235 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
236 } elseif (preg_match(
237 '@OmniWeb/([0-9].[0-9]{1,2})@',
238 $HTTP_USER_AGENT,
239 $log_version
240 )) {
241 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
242 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
243 // Konqueror 2.2.2 says Konqueror/2.2.2
244 // Konqueror 3.0.3 says Konqueror/3
245 } elseif (preg_match(
246 '@(Konqueror/)(.*)(;)@',
247 $HTTP_USER_AGENT,
248 $log_version
249 )) {
250 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
251 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
252 // must check Chrome before Safari
253 } elseif ($is_mozilla
254 && preg_match('@Chrome/([0-9.]*)@', $HTTP_USER_AGENT, $log_version)
256 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
257 $this->set('PMA_USR_BROWSER_AGENT', 'CHROME');
258 // newer Safari
259 } elseif ($is_mozilla
260 && preg_match('@Version/(.*) Safari@', $HTTP_USER_AGENT, $log_version)
262 $this->set(
263 'PMA_USR_BROWSER_VER', $log_version[1]
265 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
266 // older Safari
267 } elseif ($is_mozilla
268 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version)
270 $this->set(
271 'PMA_USR_BROWSER_VER', $mozilla_version[1] . '.' . $log_version[1]
273 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
274 // Firefox
275 } elseif (! /*overload*/mb_strstr($HTTP_USER_AGENT, 'compatible')
276 && preg_match('@Firefox/([\w.]+)@', $HTTP_USER_AGENT, $log_version)
278 $this->set(
279 'PMA_USR_BROWSER_VER', $log_version[1]
281 $this->set('PMA_USR_BROWSER_AGENT', 'FIREFOX');
282 } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
283 $this->set('PMA_USR_BROWSER_VER', '1.9');
284 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
285 } elseif ($is_mozilla) {
286 $this->set('PMA_USR_BROWSER_VER', $mozilla_version[1]);
287 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
288 } else {
289 $this->set('PMA_USR_BROWSER_VER', 0);
290 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
295 * Whether GD2 is present
297 * @return void
299 public function checkGd2()
301 if ($this->get('GD2Available') == 'yes') {
302 $this->set('PMA_IS_GD2', 1);
303 return;
306 if ($this->get('GD2Available') == 'no') {
307 $this->set('PMA_IS_GD2', 0);
308 return;
311 if (!@function_exists('imagecreatetruecolor')) {
312 $this->set('PMA_IS_GD2', 0);
313 return;
316 if (@function_exists('gd_info')) {
317 $gd_nfo = gd_info();
318 if (/*overload*/mb_strstr($gd_nfo["GD Version"], '2.')) {
319 $this->set('PMA_IS_GD2', 1);
320 } else {
321 $this->set('PMA_IS_GD2', 0);
323 } else {
324 $this->set('PMA_IS_GD2', 0);
329 * Whether the Web server php is running on is IIS
331 * @return void
333 public function checkWebServer()
335 // some versions return Microsoft-IIS, some Microsoft/IIS
336 // we could use a preg_match() but it's slower
337 if (PMA_getenv('SERVER_SOFTWARE')
338 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
339 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')
341 $this->set('PMA_IS_IIS', 1);
342 } else {
343 $this->set('PMA_IS_IIS', 0);
348 * Whether the os php is running on is windows or not
350 * @return void
352 public function checkWebServerOs()
354 // Default to Unix or Equiv
355 $this->set('PMA_IS_WINDOWS', 0);
356 // If PHP_OS is defined then continue
357 if (defined('PHP_OS')) {
358 if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
359 // Is it some version of Windows
360 $this->set('PMA_IS_WINDOWS', 1);
361 } elseif (stristr(PHP_OS, 'OS/2')) {
362 // Is it OS/2 (No file permissions like Windows)
363 $this->set('PMA_IS_WINDOWS', 1);
369 * detects PHP version
371 * @return void
373 public function checkPhpVersion()
375 $match = array();
376 if (! preg_match(
377 '@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
378 phpversion(),
379 $match
380 )) {
381 preg_match(
382 '@([0-9]{1,2}).([0-9]{1,2})@',
383 phpversion(),
384 $match
387 if (isset($match) && ! empty($match[1])) {
388 if (! isset($match[2])) {
389 $match[2] = 0;
391 if (! isset($match[3])) {
392 $match[3] = 0;
394 $this->set(
395 'PMA_PHP_INT_VERSION',
396 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3])
398 } else {
399 $this->set('PMA_PHP_INT_VERSION', 0);
401 $this->set('PMA_PHP_STR_VERSION', phpversion());
405 * detects if Git revision
407 * @return boolean
409 public function isGitRevision()
411 if (!$this->get('ShowGitRevision')) {
412 return false;
415 // caching
416 if (isset($_SESSION['is_git_revision'])) {
417 if ($_SESSION['is_git_revision']) {
418 $this->set('PMA_VERSION_GIT', 1);
420 return $_SESSION['is_git_revision'];
422 // find out if there is a .git folder
423 $git_folder = '.git';
424 if (! @file_exists($git_folder)
425 || ! @file_exists($git_folder . '/config')
427 $_SESSION['is_git_revision'] = false;
428 return false;
430 $_SESSION['is_git_revision'] = true;
431 return true;
435 * detects Git revision, if running inside repo
437 * @return void
439 public function checkGitRevision()
441 // find out if there is a .git folder
442 $git_folder = '.git';
443 if (! $this->isGitRevision()) {
444 return;
447 if (! $ref_head = @file_get_contents($git_folder . '/HEAD')) {
448 return;
451 $branch = false;
452 // are we on any branch?
453 if (/*overload*/mb_strstr($ref_head, '/')) {
454 $ref_head = /*overload*/mb_substr(trim($ref_head), 5);
455 if (substr($ref_head, 0, 11) === 'refs/heads/') {
456 $branch = /*overload*/mb_substr($ref_head, 11);
457 } else {
458 $branch = basename($ref_head);
461 $ref_file = $git_folder . '/' . $ref_head;
462 if (@file_exists($ref_file)) {
463 $hash = @file_get_contents($ref_file);
464 if (! $hash) {
465 return;
467 $hash = trim($hash);
468 } else {
469 // deal with packed refs
470 $packed_refs = @file_get_contents($git_folder . '/packed-refs');
471 if (! $packed_refs) {
472 return;
474 // split file to lines
475 $ref_lines = explode("\n", $packed_refs);
476 foreach ($ref_lines as $line) {
477 // skip comments
478 if ($line[0] == '#') {
479 continue;
481 // parse line
482 $parts = explode(' ', $line);
483 // care only about named refs
484 if (count($parts) != 2) {
485 continue;
487 // have found our ref?
488 if ($parts[1] == $ref_head) {
489 $hash = $parts[0];
490 break;
493 if (! isset($hash)) {
494 // Could not find ref
495 return;
498 } else {
499 $hash = trim($ref_head);
502 $commit = false;
503 if (isset($_SESSION['PMA_VERSION_COMMITDATA_' . $hash])) {
504 $commit = $_SESSION['PMA_VERSION_COMMITDATA_' . $hash];
505 } elseif (function_exists('gzuncompress')) {
506 $git_file_name = $git_folder . '/objects/'
507 . substr($hash, 0, 2) . '/' . substr($hash, 2);
508 if (file_exists($git_file_name) ) {
509 if (! $commit = @file_get_contents($git_file_name)) {
510 return;
512 $commit = explode("\0", gzuncompress($commit), 2);
513 $commit = explode("\n", $commit[1]);
514 $_SESSION['PMA_VERSION_COMMITDATA_' . $hash] = $commit;
515 } else {
516 $pack_names = array();
517 // work with packed data
518 $packs_file = $git_folder . '/objects/info/packs';
519 if (file_exists($packs_file)
520 && $packs = @file_get_contents($packs_file)
522 // File exists. Read it, parse the file to get the names of the
523 // packs. (to look for them in .git/object/pack directory later)
524 foreach (explode("\n", $packs) as $line) {
525 // skip blank lines
526 if (strlen(trim($line)) == 0) {
527 continue;
529 // skip non pack lines
530 if ($line[0] != 'P') {
531 continue;
533 // parse names
534 $pack_names[] = substr($line, 2);
536 } else {
537 // '.git/objects/info/packs' file can be missing
538 // (atlease in mysGit)
539 // File missing. May be we can look in the .git/object/pack
540 // directory for all the .pack files and use that list of
541 // files instead
542 $dirIterator = new DirectoryIterator(
543 $git_folder . '/objects/pack'
545 foreach ($dirIterator as $file_info) {
546 $file_name = $file_info->getFilename();
547 // if this is a .pack file
548 if ($file_info->isFile() && substr($file_name, -5) == '.pack'
550 $pack_names[] = $file_name;
554 $hash = strtolower($hash);
555 foreach ($pack_names as $pack_name) {
556 $index_name = str_replace('.pack', '.idx', $pack_name);
558 // load index
559 $index_data = @file_get_contents(
560 $git_folder . '/objects/pack/' . $index_name
562 if (! $index_data) {
563 continue;
565 // check format
566 if (substr($index_data, 0, 4) != "\377tOc") {
567 continue;
569 // check version
570 $version = unpack('N', substr($index_data, 4, 4));
571 if ($version[1] != 2) {
572 continue;
574 // parse fanout table
575 $fanout = unpack(
576 "N*",
577 substr($index_data, 8, 256 * 4)
580 // find where we should search
581 $firstbyte = intval(substr($hash, 0, 2), 16);
582 // array is indexed from 1 and we need to get
583 // previous entry for start
584 if ($firstbyte == 0) {
585 $start = 0;
586 } else {
587 $start = $fanout[$firstbyte];
589 $end = $fanout[$firstbyte + 1];
591 // stupid linear search for our sha
592 $found = false;
593 $offset = 8 + (256 * 4);
594 for ($position = $start; $position < $end; $position++) {
595 $sha = strtolower(
596 bin2hex(
597 substr($index_data, $offset + ($position * 20), 20)
600 if ($sha == $hash) {
601 $found = true;
602 break;
605 if (! $found) {
606 continue;
608 // read pack offset
609 $offset = 8 + (256 * 4) + (24 * $fanout[256]);
610 $pack_offset = unpack(
611 'N',
612 substr($index_data, $offset + ($position * 4), 4)
614 $pack_offset = $pack_offset[1];
616 // open pack file
617 $pack_file = fopen(
618 $git_folder . '/objects/pack/' . $pack_name, 'rb'
620 if ($pack_file === false) {
621 continue;
623 // seek to start
624 fseek($pack_file, $pack_offset);
626 // parse header
627 $header = ord(fread($pack_file, 1));
628 $type = ($header >> 4) & 7;
629 $hasnext = ($header & 128) >> 7;
630 $size = $header & 0xf;
631 $offset = 4;
633 while ($hasnext) {
634 $byte = ord(fread($pack_file, 1));
635 $size |= ($byte & 0x7f) << $offset;
636 $hasnext = ($byte & 128) >> 7;
637 $offset += 7;
640 // we care only about commit objects
641 if ($type != 1) {
642 continue;
645 // read data
646 $commit = fread($pack_file, $size);
647 $commit = gzuncompress($commit);
648 $commit = explode("\n", $commit);
649 $_SESSION['PMA_VERSION_COMMITDATA_' . $hash] = $commit;
650 fclose($pack_file);
655 // check if commit exists in Github
656 if ($commit !== false
657 && isset($_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash])
659 $is_remote_commit = $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash];
660 } else {
661 $link = 'https://api.github.com/repos/phpmyadmin/phpmyadmin/git/commits/'
662 . $hash;
663 $is_found = $this->checkHTTP($link, ! $commit);
664 switch($is_found) {
665 case false:
666 $is_remote_commit = false;
667 $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash] = false;
668 break;
669 case null:
670 // no remote link for now, but don't cache this as Github is down
671 $is_remote_commit = false;
672 break;
673 default:
674 $is_remote_commit = true;
675 $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash] = true;
676 if ($commit === false) {
677 // if no local commit data, try loading from Github
678 $commit_json = json_decode($is_found);
680 break;
684 $is_remote_branch = false;
685 if ($is_remote_commit && $branch !== false) {
686 // check if branch exists in Github
687 if (isset($_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash])) {
688 $is_remote_branch = $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash];
689 } else {
690 $link = 'https://api.github.com/repos/phpmyadmin/phpmyadmin'
691 . '/git/trees/' . $branch;
692 $is_found = $this->checkHTTP($link);
693 switch($is_found) {
694 case true:
695 $is_remote_branch = true;
696 $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash] = true;
697 break;
698 case false:
699 $is_remote_branch = false;
700 $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash] = false;
701 break;
702 case null:
703 // no remote link for now, but don't cache this as Github is down
704 $is_remote_branch = false;
705 break;
710 if ($commit !== false) {
711 $author = array('name' => '', 'email' => '', 'date' => '');
712 $committer = array('name' => '', 'email' => '', 'date' => '');
714 do {
715 $dataline = array_shift($commit);
716 $datalinearr = explode(' ', $dataline, 2);
717 $linetype = $datalinearr[0];
718 if (in_array($linetype, array('author', 'committer'))) {
719 $user = $datalinearr[1];
720 preg_match('/([^<]+)<([^>]+)> ([0-9]+)( [^ ]+)?/', $user, $user);
721 $user2 = array(
722 'name' => trim($user[1]),
723 'email' => trim($user[2]),
724 'date' => date('Y-m-d H:i:s', $user[3]));
725 if (isset($user[4])) {
726 $user2['date'] .= $user[4];
728 $$linetype = $user2;
730 } while ($dataline != '');
731 $message = trim(implode(' ', $commit));
733 } elseif (isset($commit_json)) {
734 $author = array(
735 'name' => $commit_json->author->name,
736 'email' => $commit_json->author->email,
737 'date' => $commit_json->author->date);
738 $committer = array(
739 'name' => $commit_json->committer->name,
740 'email' => $commit_json->committer->email,
741 'date' => $commit_json->committer->date);
742 $message = trim($commit_json->message);
743 } else {
744 return;
747 $this->set('PMA_VERSION_GIT', 1);
748 $this->set('PMA_VERSION_GIT_COMMITHASH', $hash);
749 $this->set('PMA_VERSION_GIT_BRANCH', $branch);
750 $this->set('PMA_VERSION_GIT_MESSAGE', $message);
751 $this->set('PMA_VERSION_GIT_AUTHOR', $author);
752 $this->set('PMA_VERSION_GIT_COMMITTER', $committer);
753 $this->set('PMA_VERSION_GIT_ISREMOTECOMMIT', $is_remote_commit);
754 $this->set('PMA_VERSION_GIT_ISREMOTEBRANCH', $is_remote_branch);
758 * Checks if given URL is 200 or 404, optionally returns data
760 * @param string $link the URL to check
761 * @param boolean $get_body whether to retrieve body of document
763 * @return string|boolean test result or data
765 public function checkHTTP($link, $get_body = false)
767 if (! function_exists('curl_init')) {
768 return null;
770 $handle = curl_init($link);
771 if ($handle === false) {
772 return null;
774 PMA_Util::configureCurl($handle);
775 curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 0);
776 curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
777 curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);
778 curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0);
779 curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
780 curl_setopt($handle, CURLOPT_TIMEOUT, 5);
781 curl_setopt($handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
782 if (! defined('TESTSUITE')) {
783 session_write_close();
785 $data = @curl_exec($handle);
786 if (! defined('TESTSUITE')) {
787 ini_set('session.use_only_cookies', '0');
788 ini_set('session.use_cookies', '0');
789 ini_set('session.use_trans_sid', '0');
790 ini_set('session.cache_limiter', 'nocache');
791 session_start();
793 if ($data === false) {
794 return null;
796 $http_status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
798 if ($http_status == 200) {
799 return $get_body ? $data : true;
802 if ($http_status == 404) {
803 return false;
805 return null;
809 * loads default values from default source
811 * @return boolean success
813 public function loadDefaults()
815 $cfg = array();
816 if (! file_exists($this->default_source)) {
817 $this->error_config_default_file = true;
818 return false;
820 include $this->default_source;
822 $this->default_source_mtime = filemtime($this->default_source);
824 $this->default_server = $cfg['Servers'][1];
825 unset($cfg['Servers']);
827 $this->default = $cfg;
828 $this->settings = PMA_arrayMergeRecursive($this->settings, $cfg);
830 $this->error_config_default_file = false;
832 return true;
836 * loads configuration from $source, usually the config file
837 * should be called on object creation
839 * @param string $source config file
841 * @return bool
843 public function load($source = null)
845 $this->loadDefaults();
847 if (null !== $source) {
848 $this->setSource($source);
852 * We check and set the font size at this point, to make the font size
853 * selector work also for users without a config.inc.php
855 $this->checkFontsize();
857 if (! $this->checkConfigSource()) {
858 // even if no config file, set collation_connection
859 $this->checkCollationConnection();
860 return false;
863 $cfg = array();
866 * Parses the configuration file, we throw away any errors or
867 * output.
869 $old_error_reporting = error_reporting(0);
870 ob_start();
871 $GLOBALS['pma_config_loading'] = true;
872 $eval_result = include $this->getSource();
873 $GLOBALS['pma_config_loading'] = false;
874 ob_end_clean();
875 error_reporting($old_error_reporting);
877 if ($eval_result === false) {
878 $this->error_config_file = true;
879 } else {
880 $this->error_config_file = false;
881 $this->source_mtime = filemtime($this->getSource());
885 * Backward compatibility code
887 if (!empty($cfg['DefaultTabTable'])) {
888 $cfg['DefaultTabTable'] = str_replace(
889 '_properties',
891 str_replace(
892 'tbl_properties.php',
893 'tbl_sql.php',
894 $cfg['DefaultTabTable']
898 if (!empty($cfg['DefaultTabDatabase'])) {
899 $cfg['DefaultTabDatabase'] = str_replace(
900 '_details',
902 str_replace(
903 'db_details.php',
904 'db_sql.php',
905 $cfg['DefaultTabDatabase']
910 $this->settings = PMA_arrayMergeRecursive($this->settings, $cfg);
911 $this->checkPmaAbsoluteUri();
913 // Handling of the collation must be done after merging of $cfg
914 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
915 // can have an effect.
916 $this->checkCollationConnection();
918 return true;
922 * Saves the connection collation
924 * @param array $config_data configuration data from user preferences
926 * @return void
928 private function _saveConnectionCollation($config_data)
930 if (!PMA_DRIZZLE) {
931 // just to shorten the lines
932 $collation = 'collation_connection';
933 if (isset($GLOBALS[$collation])
934 && (isset($_COOKIE['pma_collation_connection'])
935 || isset($_POST[$collation]))
937 if ((! isset($config_data[$collation])
938 && $GLOBALS[$collation] != 'utf8_general_ci')
939 || isset($config_data[$collation])
940 && $GLOBALS[$collation] != $config_data[$collation]
942 $this->setUserValue(
943 null,
944 $collation,
945 $GLOBALS[$collation],
946 'utf8_general_ci'
949 } else {
950 // read collation from settings
951 if (isset($config_data[$collation])) {
952 $GLOBALS[$collation]
953 = $config_data[$collation];
954 $this->setCookie(
955 'pma_collation_connection',
956 $GLOBALS[$collation]
964 * Loads user preferences and merges them with current config
965 * must be called after control connection has been established
967 * @return void
969 public function loadUserPreferences()
971 // index.php should load these settings, so that phpmyadmin.css.php
972 // will have everything available in session cache
973 $server = isset($GLOBALS['server'])
974 ? $GLOBALS['server']
975 : (!empty($GLOBALS['cfg']['ServerDefault'])
976 ? $GLOBALS['cfg']['ServerDefault']
977 : 0);
978 $cache_key = 'server_' . $server;
979 if ($server > 0 && !defined('PMA_MINIMUM_COMMON')) {
980 $config_mtime = max($this->default_source_mtime, $this->source_mtime);
981 // cache user preferences, use database only when needed
982 if (! isset($_SESSION['cache'][$cache_key]['userprefs'])
983 || $_SESSION['cache'][$cache_key]['config_mtime'] < $config_mtime
985 // load required libraries
986 include_once './libraries/user_preferences.lib.php';
987 $prefs = PMA_loadUserprefs();
988 $_SESSION['cache'][$cache_key]['userprefs']
989 = PMA_applyUserprefs($prefs['config_data']);
990 $_SESSION['cache'][$cache_key]['userprefs_mtime'] = $prefs['mtime'];
991 $_SESSION['cache'][$cache_key]['userprefs_type'] = $prefs['type'];
992 $_SESSION['cache'][$cache_key]['config_mtime'] = $config_mtime;
994 } elseif ($server == 0
995 || ! isset($_SESSION['cache'][$cache_key]['userprefs'])
997 $this->set('user_preferences', false);
998 return;
1000 $config_data = $_SESSION['cache'][$cache_key]['userprefs'];
1001 // type is 'db' or 'session'
1002 $this->set(
1003 'user_preferences',
1004 $_SESSION['cache'][$cache_key]['userprefs_type']
1006 $this->set(
1007 'user_preferences_mtime',
1008 $_SESSION['cache'][$cache_key]['userprefs_mtime']
1011 // backup some settings
1012 $org_fontsize = '';
1013 if (isset($this->settings['fontsize'])) {
1014 $org_fontsize = $this->settings['fontsize'];
1016 // load config array
1017 $this->settings = PMA_arrayMergeRecursive($this->settings, $config_data);
1018 $GLOBALS['cfg'] = PMA_arrayMergeRecursive($GLOBALS['cfg'], $config_data);
1019 if (defined('PMA_MINIMUM_COMMON')) {
1020 return;
1023 // settings below start really working on next page load, but
1024 // changes are made only in index.php so everything is set when
1025 // in frames
1027 // save theme
1028 /** @var PMA_Theme_Manager $tmanager */
1029 $tmanager = $_SESSION['PMA_Theme_Manager'];
1030 if ($tmanager->getThemeCookie() || isset($_REQUEST['set_theme'])) {
1031 if ((! isset($config_data['ThemeDefault'])
1032 && $tmanager->theme->getId() != 'original')
1033 || isset($config_data['ThemeDefault'])
1034 && $config_data['ThemeDefault'] != $tmanager->theme->getId()
1036 // new theme was set in common.inc.php
1037 $this->setUserValue(
1038 null,
1039 'ThemeDefault',
1040 $tmanager->theme->getId(),
1041 'original'
1044 } else {
1045 // no cookie - read default from settings
1046 if ($this->settings['ThemeDefault'] != $tmanager->theme->getId()
1047 && $tmanager->checkTheme($this->settings['ThemeDefault'])
1049 $tmanager->setActiveTheme($this->settings['ThemeDefault']);
1050 $tmanager->setThemeCookie();
1054 // save font size
1055 if ((! isset($config_data['fontsize'])
1056 && $org_fontsize != '82%')
1057 || isset($config_data['fontsize'])
1058 && $org_fontsize != $config_data['fontsize']
1060 $this->setUserValue(null, 'fontsize', $org_fontsize, '82%');
1063 // save language
1064 if (isset($_COOKIE['pma_lang']) || isset($_POST['lang'])) {
1065 if ((! isset($config_data['lang'])
1066 && $GLOBALS['lang'] != 'en')
1067 || isset($config_data['lang'])
1068 && $GLOBALS['lang'] != $config_data['lang']
1070 $this->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
1072 } else {
1073 // read language from settings
1074 if (isset($config_data['lang']) && PMA_langSet($config_data['lang'])) {
1075 $this->setCookie('pma_lang', $GLOBALS['lang']);
1079 // save connection collation
1080 $this->_saveConnectionCollation($config_data);
1084 * Sets config value which is stored in user preferences (if available)
1085 * or in a cookie.
1087 * If user preferences are not yet initialized, option is applied to
1088 * global config and added to a update queue, which is processed
1089 * by {@link loadUserPreferences()}
1091 * @param string $cookie_name can be null
1092 * @param string $cfg_path configuration path
1093 * @param mixed $new_cfg_value new value
1094 * @param mixed $default_value default value
1096 * @return void
1098 public function setUserValue($cookie_name, $cfg_path, $new_cfg_value,
1099 $default_value = null
1101 // use permanent user preferences if possible
1102 $prefs_type = $this->get('user_preferences');
1103 if ($prefs_type) {
1104 include_once './libraries/user_preferences.lib.php';
1105 if ($default_value === null) {
1106 $default_value = PMA_arrayRead($cfg_path, $this->default);
1108 PMA_persistOption($cfg_path, $new_cfg_value, $default_value);
1110 if ($prefs_type != 'db' && $cookie_name) {
1111 // fall back to cookies
1112 if ($default_value === null) {
1113 $default_value = PMA_arrayRead($cfg_path, $this->settings);
1115 $this->setCookie($cookie_name, $new_cfg_value, $default_value);
1117 PMA_arrayWrite($cfg_path, $GLOBALS['cfg'], $new_cfg_value);
1118 PMA_arrayWrite($cfg_path, $this->settings, $new_cfg_value);
1122 * Reads value stored by {@link setUserValue()}
1124 * @param string $cookie_name cookie name
1125 * @param mixed $cfg_value config value
1127 * @return mixed
1129 public function getUserValue($cookie_name, $cfg_value)
1131 $cookie_exists = isset($_COOKIE) && !empty($_COOKIE[$cookie_name]);
1132 $prefs_type = $this->get('user_preferences');
1133 if ($prefs_type == 'db') {
1134 // permanent user preferences value exists, remove cookie
1135 if ($cookie_exists) {
1136 $this->removeCookie($cookie_name);
1138 } else if ($cookie_exists) {
1139 return $_COOKIE[$cookie_name];
1141 // return value from $cfg array
1142 return $cfg_value;
1146 * set source
1148 * @param string $source source
1150 * @return void
1152 public function setSource($source)
1154 $this->source = trim($source);
1158 * check config source
1160 * @return boolean whether source is valid or not
1162 public function checkConfigSource()
1164 if (! $this->getSource()) {
1165 // no configuration file set at all
1166 return false;
1169 if (! file_exists($this->getSource())) {
1170 $this->source_mtime = 0;
1171 return false;
1174 if (! is_readable($this->getSource())) {
1175 // manually check if file is readable
1176 // might be bug #3059806 Supporting running from CIFS/Samba shares
1178 $contents = false;
1179 $handle = @fopen($this->getSource(), 'r');
1180 if ($handle !== false) {
1181 $contents = @fread($handle, 1); // reading 1 byte is enough to test
1182 @fclose($handle);
1184 if ($contents === false) {
1185 $this->source_mtime = 0;
1186 PMA_fatalError(
1187 sprintf(
1188 function_exists('__')
1189 ? __('Existing configuration file (%s) is not readable.')
1190 : 'Existing configuration file (%s) is not readable.',
1191 $this->getSource()
1194 return false;
1198 return true;
1202 * verifies the permissions on config file (if asked by configuration)
1203 * (must be called after config.inc.php has been merged)
1205 * @return void
1207 public function checkPermissions()
1209 // Check for permissions (on platforms that support it):
1210 if ($this->get('CheckConfigurationPermissions')) {
1211 $perms = @fileperms($this->getSource());
1212 if (!($perms === false) && ($perms & 2)) {
1213 // This check is normally done after loading configuration
1214 $this->checkWebServerOs();
1215 if ($this->get('PMA_IS_WINDOWS') == 0) {
1216 $this->source_mtime = 0;
1217 PMA_fatalError(
1219 'Wrong permissions on configuration file, '
1220 . 'should not be world writable!'
1229 * returns specific config setting
1231 * @param string $setting config setting
1233 * @return mixed value
1235 public function get($setting)
1237 if (isset($this->settings[$setting])) {
1238 return $this->settings[$setting];
1240 return null;
1244 * sets configuration variable
1246 * @param string $setting configuration option
1247 * @param mixed $value new value for configuration option
1249 * @return void
1251 public function set($setting, $value)
1253 if (! isset($this->settings[$setting])
1254 || $this->settings[$setting] !== $value
1256 $this->settings[$setting] = $value;
1257 $this->set_mtime = time();
1262 * returns source for current config
1264 * @return string config source
1266 public function getSource()
1268 return $this->source;
1272 * returns a unique value to force a CSS reload if either the config
1273 * or the theme changes
1274 * must also check the pma_fontsize cookie in case there is no
1275 * config file
1277 * @return int Summary of unix timestamps and fontsize,
1278 * to be unique on theme parameters change
1280 public function getThemeUniqueValue()
1282 if (null !== $this->get('fontsize')) {
1283 $fontsize = intval($this->get('fontsize'));
1284 } elseif (isset($_COOKIE['pma_fontsize'])) {
1285 $fontsize = intval($_COOKIE['pma_fontsize']);
1286 } else {
1287 $fontsize = 0;
1289 return (
1290 $fontsize +
1291 $this->source_mtime +
1292 $this->default_source_mtime +
1293 $this->get('user_preferences_mtime') +
1294 $_SESSION['PMA_Theme']->mtime_info +
1295 $_SESSION['PMA_Theme']->filesize_info);
1299 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
1300 * set properly and, depending on browsers, inserting or updating a
1301 * record might fail
1303 * @return void
1305 public function checkPmaAbsoluteUri()
1307 // Setup a default value to let the people and lazy sysadmins work anyway,
1308 // they'll get an error if the autodetect code doesn't work
1309 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
1310 $is_https = $this->detectHttps();
1312 if (/*overload*/mb_strlen($pma_absolute_uri) < 5) {
1313 $url = array();
1315 // If we don't have scheme, we didn't have full URL so we need to
1316 // dig deeper
1317 if (empty($url['scheme'])) {
1318 // Scheme
1319 if ($is_https) {
1320 $url['scheme'] = 'https';
1321 } else {
1322 $url['scheme'] = 'http';
1325 // Host and port
1326 if (PMA_getenv('HTTP_HOST')) {
1327 // Prepend the scheme before using parse_url() since this
1328 // is not part of the RFC2616 Host request-header
1329 $parsed_url = parse_url(
1330 $url['scheme'] . '://' . PMA_getenv('HTTP_HOST')
1332 if (!empty($parsed_url['host'])) {
1333 $url = $parsed_url;
1334 } else {
1335 $url['host'] = PMA_getenv('HTTP_HOST');
1337 } elseif (PMA_getenv('SERVER_NAME')) {
1338 $url['host'] = PMA_getenv('SERVER_NAME');
1339 } else {
1340 $this->error_pma_uri = true;
1341 return;
1344 // If we didn't set port yet...
1345 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
1346 $url['port'] = PMA_getenv('SERVER_PORT');
1349 // And finally the path could be already set from REQUEST_URI
1350 if (empty($url['path'])) {
1351 // we got a case with nginx + php-fpm where PHP_SELF
1352 // was not set, so PMA_PHP_SELF was not set as well
1353 if (isset($GLOBALS['PMA_PHP_SELF'])) {
1354 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
1355 } else {
1356 $path = parse_url(PMA_getenv('REQUEST_URI'));
1358 $url['path'] = $path['path'];
1362 // Make url from parts we have
1363 $pma_absolute_uri = $url['scheme'] . '://';
1364 // Was there user information?
1365 if (!empty($url['user'])) {
1366 $pma_absolute_uri .= $url['user'];
1367 if (!empty($url['pass'])) {
1368 $pma_absolute_uri .= ':' . $url['pass'];
1370 $pma_absolute_uri .= '@';
1372 // Add hostname
1373 $pma_absolute_uri .= $url['host'];
1374 // Add port, if it not the default one
1375 // (or 80 for https which is most likely a bug)
1376 if (! empty($url['port'])
1377 && (($url['scheme'] == 'http' && $url['port'] != 80)
1378 || ($url['scheme'] == 'https' && $url['port'] != 80)
1379 || ($url['scheme'] == 'https' && $url['port'] != 443))
1381 $pma_absolute_uri .= ':' . $url['port'];
1383 // And finally path, without script name, the 'a' is there not to
1384 // strip our directory, when path is only /pmadir/ without filename.
1385 // Backslashes returned by Windows have to be changed.
1386 // Only replace backslashes by forward slashes if on Windows,
1387 // as the backslash could be valid on a non-Windows system.
1388 $this->checkWebServerOs();
1389 if ($this->get('PMA_IS_WINDOWS') == 1) {
1390 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
1391 } else {
1392 $path = dirname($url['path'] . 'a');
1395 // To work correctly within javascript
1396 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../') {
1397 if ($this->get('PMA_IS_WINDOWS') == 1) {
1398 $path = str_replace("\\", "/", dirname($path));
1399 } else {
1400 $path = dirname($path);
1404 // PHP's dirname function would have returned a dot
1405 // when $path contains no slash
1406 if ($path == '.') {
1407 $path = '';
1409 // in vhost situations, there could be already an ending slash
1410 if (/*overload*/mb_substr($path, -1) != '/') {
1411 $path .= '/';
1413 $pma_absolute_uri .= $path;
1415 // This is to handle the case of a reverse proxy
1416 if ($this->get('ForceSSL')) {
1417 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
1418 $pma_absolute_uri = $this->getSSLUri();
1419 $this->isHttps();
1422 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
1423 // the autodetect code works well enough that we don't display the
1424 // warning at all. The user can still set PmaAbsoluteUri manually.
1426 } else {
1427 // The URI is specified, however users do often specify this
1428 // wrongly, so we try to fix this.
1430 // Adds a trailing slash et the end of the phpMyAdmin uri if it
1431 // does not exist.
1432 if (/*overload*/mb_substr($pma_absolute_uri, -1) != '/') {
1433 $pma_absolute_uri .= '/';
1436 // If URI doesn't start with http:// or https://, we will add
1437 // this.
1438 if (/*overload*/mb_substr($pma_absolute_uri, 0, 7) != 'http://'
1439 && /*overload*/mb_substr($pma_absolute_uri, 0, 8) != 'https://'
1441 $pma_absolute_uri
1442 = ($is_https ? 'https' : 'http')
1443 . ':'
1445 /*overload*/mb_substr($pma_absolute_uri, 0, 2) == '//'
1446 ? ''
1447 : '//'
1449 . $pma_absolute_uri;
1452 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
1456 * Converts currently used PmaAbsoluteUri to SSL based variant.
1458 * @return String witch adjusted URI
1460 public function getSSLUri()
1462 // grab current URL
1463 $url = $this->get('PmaAbsoluteUri');
1464 // Parse current URL
1465 $parsed = parse_url($url);
1466 // In case parsing has failed do stupid string replacement
1467 if ($parsed === false) {
1468 // Replace http protocol
1469 return preg_replace('@^http:@', 'https:', $url);
1472 // Reconstruct URL using parsed parts
1473 return 'https://' . $parsed['host'] . ':443' . $parsed['path'];
1477 * Sets collation_connection based on user preference. First is checked
1478 * value from request, then cookies with fallback to default.
1480 * After setting it here, cookie is set in common.inc.php to persist
1481 * the selection.
1483 * @todo check validity of collation string
1485 * @return void
1487 public function checkCollationConnection()
1489 if (! empty($_REQUEST['collation_connection'])) {
1490 $collation = strip_tags($_REQUEST['collation_connection']);
1491 } elseif (! empty($_COOKIE['pma_collation_connection'])) {
1492 $collation = strip_tags($_COOKIE['pma_collation_connection']);
1493 } else {
1494 $collation = $this->get('DefaultConnectionCollation');
1496 $this->set('collation_connection', $collation);
1500 * checks for font size configuration, and sets font size as requested by user
1502 * @return void
1504 public function checkFontsize()
1506 $new_fontsize = '';
1508 if (isset($_GET['set_fontsize'])) {
1509 $new_fontsize = $_GET['set_fontsize'];
1510 } elseif (isset($_POST['set_fontsize'])) {
1511 $new_fontsize = $_POST['set_fontsize'];
1512 } elseif (isset($_COOKIE['pma_fontsize'])) {
1513 $new_fontsize = $_COOKIE['pma_fontsize'];
1516 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
1517 $this->set('fontsize', $new_fontsize);
1518 } elseif (! $this->get('fontsize')) {
1519 // 80% would correspond to the default browser font size
1520 // of 16, but use 82% to help read the monoface font
1521 $this->set('fontsize', '82%');
1524 $this->setCookie('pma_fontsize', $this->get('fontsize'), '82%');
1528 * checks if upload is enabled
1530 * @return void
1532 public function checkUpload()
1534 if (!ini_get('file_uploads')) {
1535 $this->set('enable_upload', false);
1536 return;
1539 $this->set('enable_upload', true);
1540 // if set "php_admin_value file_uploads Off" in httpd.conf
1541 // ini_get() also returns the string "Off" in this case:
1542 if ('off' == strtolower(ini_get('file_uploads'))) {
1543 $this->set('enable_upload', false);
1548 * Maximum upload size as limited by PHP
1549 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
1551 * this section generates $max_upload_size in bytes
1553 * @return void
1555 public function checkUploadSize()
1557 if (! $filesize = ini_get('upload_max_filesize')) {
1558 $filesize = "5M";
1561 if ($postsize = ini_get('post_max_size')) {
1562 $this->set(
1563 'max_upload_size',
1564 min(PMA_getRealSize($filesize), PMA_getRealSize($postsize))
1566 } else {
1567 $this->set('max_upload_size', PMA_getRealSize($filesize));
1572 * Checks if protocol is https
1574 * This function checks if the https protocol is used in the PmaAbsoluteUri
1575 * configuration setting, as opposed to detectHttps() which checks if the
1576 * https protocol is used on the active connection.
1578 * @return bool
1580 public function isHttps()
1583 if (null !== $this->get('is_https')) {
1584 return $this->get('is_https');
1587 $url = parse_url($this->get('PmaAbsoluteUri'));
1589 $is_https = (isset($url['scheme']) && $url['scheme'] == 'https');
1591 $this->set('is_https', $is_https);
1593 return $is_https;
1597 * Detects whether https appears to be used.
1599 * This function checks if the https protocol is used in the current connection
1600 * with the webserver, based on environment variables.
1601 * Please note that this just detects what we see, so
1602 * it completely ignores things like reverse proxies.
1604 * @return bool
1606 public function detectHttps()
1608 $url = array();
1610 // At first we try to parse REQUEST_URI, it might contain full URL,
1611 if (PMA_getenv('REQUEST_URI')) {
1612 // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
1613 $url = @parse_url(PMA_getenv('REQUEST_URI'));
1614 if ($url === false) {
1615 $url = array();
1619 // If we don't have scheme, we didn't have full URL so we need to
1620 // dig deeper
1621 if (empty($url['scheme'])) {
1622 // Scheme
1623 if (PMA_getenv('HTTP_SCHEME')) {
1624 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
1625 } elseif (PMA_getenv('HTTPS')
1626 && strtolower(PMA_getenv('HTTPS')) == 'on'
1628 $url['scheme'] = 'https';
1629 // A10 Networks load balancer:
1630 } elseif (PMA_getenv('HTTP_HTTPS_FROM_LB')
1631 && strtolower(PMA_getenv('HTTP_HTTPS_FROM_LB')) == 'on'
1633 $url['scheme'] = 'https';
1634 } elseif (PMA_getenv('HTTP_X_FORWARDED_PROTO')) {
1635 $url['scheme'] = /*overload*/mb_strtolower(
1636 PMA_getenv('HTTP_X_FORWARDED_PROTO')
1638 } elseif (PMA_getenv('HTTP_FRONT_END_HTTPS')
1639 && strtolower(PMA_getenv('HTTP_FRONT_END_HTTPS')) == 'on'
1641 $url['scheme'] = 'https';
1642 } else {
1643 $url['scheme'] = 'http';
1647 if (isset($url['scheme']) && $url['scheme'] == 'https') {
1648 $is_https = true;
1649 } else {
1650 $is_https = false;
1653 return $is_https;
1657 * detect correct cookie path
1659 * @return void
1661 public function checkCookiePath()
1663 $this->set('cookie_path', $this->getCookiePath());
1667 * Get cookie path
1669 * @return string
1671 public function getCookiePath()
1673 static $cookie_path = null;
1675 if (null !== $cookie_path && !defined('TESTSUITE')) {
1676 return $cookie_path;
1679 $parsed_url = parse_url($this->get('PmaAbsoluteUri'));
1681 $cookie_path = $parsed_url['path'];
1683 return $cookie_path;
1687 * enables backward compatibility
1689 * @return void
1691 public function enableBc()
1693 $GLOBALS['cfg'] = $this->settings;
1694 $GLOBALS['default_server'] = $this->default_server;
1695 unset($this->default_server);
1696 $GLOBALS['collation_connection'] = $this->get('collation_connection');
1697 $GLOBALS['is_upload'] = $this->get('enable_upload');
1698 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
1699 $GLOBALS['cookie_path'] = $this->get('cookie_path');
1700 $GLOBALS['is_https'] = $this->get('is_https');
1702 $defines = array(
1703 'PMA_VERSION',
1704 'PMA_THEME_VERSION',
1705 'PMA_THEME_GENERATION',
1706 'PMA_PHP_STR_VERSION',
1707 'PMA_PHP_INT_VERSION',
1708 'PMA_IS_WINDOWS',
1709 'PMA_IS_IIS',
1710 'PMA_IS_GD2',
1711 'PMA_USR_OS',
1712 'PMA_USR_BROWSER_VER',
1713 'PMA_USR_BROWSER_AGENT'
1716 foreach ($defines as $define) {
1717 if (! defined($define)) {
1718 define($define, $this->get($define));
1724 * returns options for font size selection
1726 * @param string $current_size current selected font size with unit
1728 * @return array selectable font sizes
1730 protected static function getFontsizeOptions($current_size = '82%')
1732 $unit = preg_replace('/[0-9.]*/', '', $current_size);
1733 $value = preg_replace('/[^0-9.]*/', '', $current_size);
1735 $factors = array();
1736 $options = array();
1737 $options["$value"] = $value . $unit;
1739 if ($unit === '%') {
1740 $factors[] = 1;
1741 $factors[] = 5;
1742 $factors[] = 10;
1743 } elseif ($unit === 'em') {
1744 $factors[] = 0.05;
1745 $factors[] = 0.2;
1746 $factors[] = 1;
1747 } elseif ($unit === 'pt') {
1748 $factors[] = 0.5;
1749 $factors[] = 2;
1750 } elseif ($unit === 'px') {
1751 $factors[] = 1;
1752 $factors[] = 5;
1753 $factors[] = 10;
1754 } else {
1755 //unknown font size unit
1756 $factors[] = 0.05;
1757 $factors[] = 0.2;
1758 $factors[] = 1;
1759 $factors[] = 5;
1760 $factors[] = 10;
1763 foreach ($factors as $key => $factor) {
1764 $option_inc = $value + $factor;
1765 $option_dec = $value - $factor;
1766 while (count($options) < 21) {
1767 $options["$option_inc"] = $option_inc . $unit;
1768 if ($option_dec > $factors[0]) {
1769 $options["$option_dec"] = $option_dec . $unit;
1771 $option_inc += $factor;
1772 $option_dec -= $factor;
1773 if (isset($factors[$key + 1])
1774 && $option_inc >= $value + $factors[$key + 1]
1776 break;
1780 ksort($options);
1781 return $options;
1785 * returns html selectbox for font sizes
1787 * @return string html selectbox
1789 protected static function getFontsizeSelection()
1791 $current_size = $GLOBALS['PMA_Config']->get('fontsize');
1792 // for the case when there is no config file (this is supported)
1793 if (empty($current_size)) {
1794 if (isset($_COOKIE['pma_fontsize'])) {
1795 $current_size = htmlspecialchars($_COOKIE['pma_fontsize']);
1796 } else {
1797 $current_size = '82%';
1800 $options = PMA_Config::getFontsizeOptions($current_size);
1802 $return = '<label for="select_fontsize">' . __('Font size')
1803 . ':</label>' . "\n"
1804 . '<select name="set_fontsize" id="select_fontsize"'
1805 . ' class="autosubmit">' . "\n";
1806 foreach ($options as $option) {
1807 $return .= '<option value="' . $option . '"';
1808 if ($option == $current_size) {
1809 $return .= ' selected="selected"';
1811 $return .= '>' . $option . '</option>' . "\n";
1813 $return .= '</select>';
1815 return $return;
1819 * return complete font size selection form
1821 * @return string html selectbox
1823 public static function getFontsizeForm()
1825 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1826 . ' method="get" action="index.php" class="disableAjax">' . "\n"
1827 . PMA_URL_getHiddenInputs() . "\n"
1828 . PMA_Config::getFontsizeSelection() . "\n"
1829 . '</form>';
1833 * removes cookie
1835 * @param string $cookie name of cookie to remove
1837 * @return boolean result of setcookie()
1839 public function removeCookie($cookie)
1841 if (defined('TESTSUITE')) {
1842 if (isset($_COOKIE[$cookie])) {
1843 unset($_COOKIE[$cookie]);
1845 return true;
1847 return setcookie(
1848 $cookie,
1850 time() - 3600,
1851 $this->getCookiePath(),
1853 $this->isHttps()
1858 * sets cookie if value is different from current cookie value,
1859 * or removes if value is equal to default
1861 * @param string $cookie name of cookie to remove
1862 * @param mixed $value new cookie value
1863 * @param string $default default value
1864 * @param int $validity validity of cookie in seconds (default is one month)
1865 * @param bool $httponly whether cookie is only for HTTP (and not for scripts)
1867 * @return boolean result of setcookie()
1869 public function setCookie($cookie, $value, $default = null,
1870 $validity = null, $httponly = true
1872 if (/*overload*/mb_strlen($value) && null !== $default && $value === $default
1874 // default value is used
1875 if (isset($_COOKIE[$cookie])) {
1876 // remove cookie
1877 return $this->removeCookie($cookie);
1879 return false;
1882 if (!/*overload*/mb_strlen($value) && isset($_COOKIE[$cookie])) {
1883 // remove cookie, value is empty
1884 return $this->removeCookie($cookie);
1887 if (! isset($_COOKIE[$cookie]) || $_COOKIE[$cookie] !== $value) {
1888 // set cookie with new value
1889 /* Calculate cookie validity */
1890 if ($validity === null) {
1891 $validity = time() + 2592000;
1892 } elseif ($validity == 0) {
1893 $validity = 0;
1894 } else {
1895 $validity = time() + $validity;
1897 if (defined('TESTSUITE')) {
1898 $_COOKIE[$cookie] = $value;
1899 return true;
1901 return setcookie(
1902 $cookie,
1903 $value,
1904 $validity,
1905 $this->getCookiePath(),
1907 $this->isHttps(),
1908 $httponly
1912 // cookie has already $value as value
1913 return true;
1919 * Error handler to catch fatal errors when loading configuration
1920 * file
1922 * @return void
1924 function PMA_Config_fatalErrorHandler()
1926 if (isset($GLOBALS['pma_config_loading']) && $GLOBALS['pma_config_loading']) {
1927 $error = error_get_last();
1928 if ($error !== null) {
1929 PMA_fatalError(
1930 sprintf(
1931 'Failed to load phpMyAdmin configuration (%s:%s): %s',
1932 PMA_Error::relPath($error['file']),
1933 $error['line'],
1934 $error['message']
1941 if (!defined('TESTSUITE')) {
1942 register_shutdown_function('PMA_Config_fatalErrorHandler');