[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libraries/ -> Config.class.php (source)

   1  <?php
   2  /* $Id: Config.class.php 10510 2007-07-20 13:03:09Z lem9 $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  /**
   6   * Configuration class
   7   *
   8   */
   9  class PMA_Config
  10  {
  11      /**
  12       * @var string  default config source
  13       */
  14      var $default_source = './libraries/config.default.php';
  15  
  16      /**
  17       * @var array   configuration settings
  18       */
  19      var $settings = array();
  20  
  21      /**
  22       * @var string  config source
  23       */
  24      var $source = '';
  25  
  26      /**
  27       * @var int     source modification time
  28       */
  29      var $source_mtime = 0;
  30      var $default_source_mtime = 0;
  31      var $set_mtime = 0;
  32  
  33      /**
  34       * @var boolean
  35       */
  36      var $error_config_file = false;
  37  
  38      /**
  39       * @var boolean
  40       */
  41      var $error_config_default_file = false;
  42  
  43      /**
  44       * @var boolean
  45       */
  46      var $error_pma_uri = false;
  47  
  48      /**
  49       * @var array
  50       */
  51      var $default_server = array();
  52  
  53      /**
  54       * @var boolean wether init is done or mot
  55       * set this to false to force some initial checks
  56       * like checking for required functions
  57       */
  58      var $done = false;
  59  
  60      /**
  61       * constructor
  62       *
  63       * @param   string  source to read config from
  64       */
  65      function __construct($source = null)
  66      {
  67          $this->settings = array();
  68  
  69          // functions need to refresh in case of config file changed goes in
  70          // PMA_Config::load()
  71          $this->load($source);
  72  
  73          // other settings, independant from config file, comes in
  74          $this->checkSystem();
  75  
  76          $this->checkIsHttps();
  77      }
  78  
  79      /**
  80       * sets system and application settings
  81       */
  82      function checkSystem()
  83      {
  84          $this->set('PMA_VERSION', '2.10.3deb1');
  85          /**
  86           * @deprecated
  87           */
  88          $this->set('PMA_THEME_VERSION', 2);
  89          /**
  90           * @deprecated
  91           */
  92          $this->set('PMA_THEME_GENERATION', 2);
  93  
  94          $this->checkPhpVersion();
  95          $this->checkWebServerOs();
  96          $this->checkWebServer();
  97          $this->checkGd2();
  98          $this->checkClient();
  99          $this->checkUpload();
 100          $this->checkUploadSize();
 101          $this->checkOutputCompression();
 102      }
 103  
 104      /**
 105       * wether to use gzip output compression or not
 106       */
 107      function checkOutputCompression()
 108      {
 109          // If zlib output compression is set in the php configuration file, no
 110          // output buffering should be run
 111          if (@ini_get('zlib.output_compression')) {
 112              $this->set('OBGzip', false);
 113          }
 114  
 115          // disable output-buffering (if set to 'auto') for IE6, else enable it.
 116          if (strtolower($this->get('OBGzip')) == 'auto') {
 117              if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
 118                && $this->get('PMA_USR_BROWSER_VER') >= 6
 119                && $this->get('PMA_USR_BROWSER_VER') < 7) {
 120                  $this->set('OBGzip', false);
 121              } else {
 122                  $this->set('OBGzip', true);
 123              }
 124          }
 125      }
 126  
 127      /**
 128       * Determines platform (OS), browser and version of the user
 129       * Based on a phpBuilder article:
 130       * @see http://www.phpbuilder.net/columns/tim20000821.php
 131       */
 132      function checkClient()
 133      {
 134          if (PMA_getenv('HTTP_USER_AGENT')) {
 135              $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
 136          } elseif (!isset($HTTP_USER_AGENT)) {
 137              $HTTP_USER_AGENT = '';
 138          }
 139  
 140          // 1. Platform
 141          if (strstr($HTTP_USER_AGENT, 'Win')) {
 142              $this->set('PMA_USR_OS', 'Win');
 143          } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
 144              $this->set('PMA_USR_OS', 'Mac');
 145          } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
 146              $this->set('PMA_USR_OS', 'Linux');
 147          } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
 148              $this->set('PMA_USR_OS', 'Unix');
 149          } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
 150              $this->set('PMA_USR_OS', 'OS/2');
 151          } else {
 152              $this->set('PMA_USR_OS', 'Other');
 153          }
 154  
 155          // 2. browser and version
 156          // (must check everything else before Mozilla)
 157  
 158          if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
 159              $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
 160              $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
 161          } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
 162              $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
 163              $this->set('PMA_USR_BROWSER_AGENT', 'IE');
 164          } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
 165              $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
 166              $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
 167          //} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
 168          // Konqueror 2.2.2 says Konqueror/2.2.2
 169          // Konqueror 3.0.3 says Konqueror/3
 170          } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
 171              $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
 172              $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
 173          } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
 174                     && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
 175              $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
 176              $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
 177          } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
 178              $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
 179              $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
 180          } else {
 181              $this->set('PMA_USR_BROWSER_VER', 0);
 182              $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
 183          }
 184      }
 185  
 186      /**
 187       * Whether GD2 is present
 188       */
 189      function checkGd2()
 190      {
 191          if ($this->get('GD2Available') == 'yes') {
 192              $this->set('PMA_IS_GD2', 1);
 193          } elseif ($this->get('GD2Available') == 'no') {
 194              $this->set('PMA_IS_GD2', 0);
 195          } else {
 196              if (!@extension_loaded('gd')) {
 197                  PMA_dl('gd');
 198              }
 199              if (!@function_exists('imagecreatetruecolor')) {
 200                  $this->set('PMA_IS_GD2', 0);
 201              } else {
 202                  if (@function_exists('gd_info')) {
 203                      $gd_nfo = gd_info();
 204                      if (strstr($gd_nfo["GD Version"], '2.')) {
 205                          $this->set('PMA_IS_GD2', 1);
 206                      } else {
 207                          $this->set('PMA_IS_GD2', 0);
 208                      }
 209                  } else {
 210                      /* We must do hard way... */
 211                      ob_start();
 212                      phpinfo(INFO_MODULES); /* Only modules */
 213                      $a = strip_tags(ob_get_contents());
 214                      ob_end_clean();
 215                      /* Get GD version string from phpinfo output */
 216                      if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
 217                          if (strstr($v, '2.')) {
 218                              $this->set('PMA_IS_GD2', 1);
 219                          } else {
 220                              $this->set('PMA_IS_GD2', 0);
 221                          }
 222                      } else {
 223                          $this->set('PMA_IS_GD2', 0);
 224                      }
 225                  }
 226              }
 227          }
 228      }
 229  
 230      /**
 231       * Whether the Web server php is running on is IIS
 232       */
 233      function checkWebServer()
 234      {
 235          if (PMA_getenv('SERVER_SOFTWARE')
 236            // some versions return Microsoft-IIS, some Microsoft/IIS
 237            // we could use a preg_match() but it's slower
 238            && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
 239            && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
 240              $this->set('PMA_IS_IIS', 1);
 241          } else {
 242              $this->set('PMA_IS_IIS', 0);
 243          }
 244      }
 245  
 246      /**
 247       * Whether the os php is running on is windows or not
 248       */
 249      function checkWebServerOs()
 250      {
 251          // Default to Unix or Equiv
 252          $this->set('PMA_IS_WINDOWS', 0);
 253          // If PHP_OS is defined then continue
 254          if (defined('PHP_OS')) {
 255              if (stristr(PHP_OS, 'win') ) {
 256                  // Is it some version of Windows
 257                  $this->set('PMA_IS_WINDOWS', 1);
 258              } elseif (stristr(PHP_OS, 'OS/2')) {
 259                  // Is it OS/2 (No file permissions like Windows)
 260                  $this->set('PMA_IS_WINDOWS', 1);
 261              }
 262          }
 263      }
 264  
 265      /**
 266       * detects PHP version
 267       */
 268      function checkPhpVersion()
 269      {
 270          $match = array();
 271          if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
 272                  phpversion(), $match)) {
 273              $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
 274                  phpversion(), $match);
 275          }
 276          if (isset($match) && ! empty($match[1])) {
 277              if (! isset($match[2])) {
 278                  $match[2] = 0;
 279              }
 280              if (! isset($match[3])) {
 281                  $match[3] = 0;
 282              }
 283              $this->set('PMA_PHP_INT_VERSION',
 284                  (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
 285          } else {
 286              $this->set('PMA_PHP_INT_VERSION', 0);
 287          }
 288          $this->set('PMA_PHP_STR_VERSION', phpversion());
 289      }
 290  
 291      /**
 292       * re-init object after loading from session file
 293       * checks config file for changes and relaods if neccessary
 294       */
 295      function __wakeup()
 296      {
 297          /* Disable in Debian: we're including a couple of other files
 298           * in config.inc.php, and their changes will never be picked up
 299           * if we leave this check in.
 300          if (! $this->checkConfigSource()
 301            || $this->source_mtime !== filemtime($this->getSource())
 302            || $this->default_source_mtime !== filemtime($this->default_source)
 303            || $this->error_config_file
 304            || $this->error_config_default_file) {
 305           */
 306              $this->settings = array();
 307              $this->load();
 308              $this->checkSystem();
 309           /*
 310          } */
 311  
 312          // check for https needs to be done everytime,
 313          // as https and http uses same session so this info can not be stored
 314          // in session
 315          $this->checkIsHttps();
 316  
 317          $this->checkCollationConnection();
 318          $this->checkFontsize();
 319      }
 320  
 321      /**
 322       * loads default values from default source
 323       *
 324       * @uses    file_exists()
 325       * @uses    $this->default_source
 326       * @uses    $this->error_config_default_file
 327       * @uses    $this->settings
 328       * @return  boolean     success
 329       */
 330      function loadDefaults()
 331      {
 332          $cfg = array();
 333          if (! file_exists($this->default_source)) {
 334              $this->error_config_default_file = true;
 335              return false;
 336          }
 337          include $this->default_source;
 338  
 339          $this->default_source_mtime = filemtime($this->default_source);
 340  
 341          $this->default_server = $cfg['Servers'][1];
 342          unset($cfg['Servers']);
 343  
 344          $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
 345  
 346          $this->error_config_default_file = false;
 347  
 348          return true;
 349      }
 350  
 351      /**
 352       * loads configuration from $source, usally the config file
 353       * should be called on object creation and from __wakeup if config file
 354       * has changed
 355       *
 356       * @param   string $source  config file
 357       */
 358      function load($source = null)
 359      {
 360          $this->loadDefaults();
 361  
 362          if (null !== $source) {
 363              $this->setSource($source);
 364          }
 365  
 366          if (! $this->checkConfigSource()) {
 367              return false;
 368          }
 369  
 370          $cfg = array();
 371  
 372          /**
 373           * Parses the configuration file
 374           */
 375          $old_error_reporting = error_reporting(0);
 376          if (function_exists('file_get_contents')) {
 377              $eval_result =
 378                  eval('?>' . trim(file_get_contents($this->getSource())));
 379          } else {
 380              $eval_result =
 381                  eval('?>' . trim(implode("\n", file($this->getSource()))));
 382          }
 383          error_reporting($old_error_reporting);
 384  
 385          if ($eval_result === false) {
 386              $this->error_config_file = true;
 387          } else  {
 388              $this->error_config_file = false;
 389              $this->source_mtime = filemtime($this->getSource());
 390          }
 391  
 392          /**
 393           * Backward compatibility code
 394           */
 395          if (!empty($cfg['DefaultTabTable'])) {
 396              $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
 397          }
 398          if (!empty($cfg['DefaultTabDatabase'])) {
 399              $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
 400          }
 401  
 402          $this->checkFontsize();
 403          //$this->checkPmaAbsoluteUri();
 404          $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
 405  
 406          // Handling of the collation must be done after merging of $cfg
 407          // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
 408          // can have an effect. Note that the presence of collation
 409          // information in a cookie has priority over what is defined
 410          // in the default or user's config files. 
 411          /**
 412           * @todo check validity of $_COOKIE['pma_collation_connection']
 413           */
 414          if (! empty($_COOKIE['pma_collation_connection'])) {
 415              $this->set('collation_connection',
 416                  strip_tags($_COOKIE['pma_collation_connection']));
 417          } else {
 418              $this->set('collation_connection',
 419                  $this->get('DefaultConnectionCollation'));
 420          }
 421          // Now, a collation information could come from REQUEST
 422          // (an example of this: the collation selector in main.php)
 423          // so the following handles the setting of collation_connection
 424          // and later, in common.lib.php, the cookie will be set
 425          // according to this.
 426          $this->checkCollationConnection();
 427  
 428          return true;
 429      }
 430  
 431      /**
 432       * set source
 433       * @param   string  $source
 434       */
 435      function setSource($source)
 436      {
 437          $this->source = trim($source);
 438      }
 439  
 440      /**
 441       * checks if the config folder still exists and terminates app if true
 442       */
 443      function checkConfigFolder()
 444      {
 445          // Refuse to work while there still might be some world writable dir:
 446          if (is_dir('./config')) {
 447              die('Remove "./config" directory before using phpMyAdmin!');
 448          }
 449      }
 450  
 451      /**
 452       * check config source
 453       *
 454       * @return  boolean wether source is valid or not
 455       */
 456      function checkConfigSource()
 457      {
 458          if (! $this->getSource()) {
 459              // no configuration file set at all
 460              return false;
 461          }
 462  
 463          if (! file_exists($this->getSource())) {
 464              // do not trigger error here
 465              // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
 466              /*
 467              trigger_error(
 468                  'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
 469                  E_USER_WARNING);
 470              */
 471              $this->source_mtime = 0;
 472              return false;
 473          }
 474  
 475          if (! is_readable($this->getSource())) {
 476              $this->source_mtime = 0;
 477              die('Existing configuration file (' . $this->getSource() . ') is not readable.');
 478          }
 479  
 480          // Check for permissions (on platforms that support it):
 481          $perms = @fileperms($this->getSource());
 482          if (!($perms === false) && ($perms & 2)) {
 483              // This check is normally done after loading configuration
 484              $this->checkWebServerOs();
 485              if ($this->get('PMA_IS_WINDOWS') == 0) {
 486                  $this->source_mtime = 0;
 487                  die('Wrong permissions on configuration file, should not be world writable!');
 488              }
 489          }
 490  
 491          return true;
 492      }
 493  
 494      /**
 495       * returns specific config setting
 496       * @param   string  $setting
 497       * @return  mixed   value
 498       */
 499      function get($setting)
 500      {
 501          if (isset($this->settings[$setting])) {
 502              return $this->settings[$setting];
 503          }
 504          return null;
 505      }
 506  
 507      /**
 508       * sets configuration variable
 509       *
 510       * @uses    $this->settings
 511       * @param   string  $setting    configuration option
 512       * @param   string  $value      new value for configuration option
 513       */
 514      function set($setting, $value)
 515      {
 516          if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
 517              $this->settings[$setting] = $value;
 518              $this->set_mtime = time();
 519          }
 520      }
 521  
 522      /**
 523       * returns source for current config
 524       * @return  string  config source
 525       */
 526      function getSource()
 527      {
 528          return $this->source;
 529      }
 530  
 531      /**
 532       * old PHP 4 style constructor
 533       *
 534       * @deprecated
 535       */
 536      function PMA_Config($source = null)
 537      {
 538          $this->__construct($source);
 539      }
 540  
 541      /**
 542       * returns time of last config change.
 543       * @return  int  Unix timestamp
 544       */
 545      function getMtime()
 546      {
 547          return max($this->source_mtime, $this->default_source_mtime, $this->set_mtime);
 548      }
 549  
 550      /**
 551       * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
 552       * set properly and, depending on browsers, inserting or updating a
 553       * record might fail
 554       */
 555      function checkPmaAbsoluteUri()
 556      {
 557          // Setup a default value to let the people and lazy syadmins work anyway,
 558          // they'll get an error if the autodetect code doesn't work
 559          $pma_absolute_uri = $this->get('PmaAbsoluteUri');
 560          $is_https = $this->get('is_https');
 561          if (strlen($pma_absolute_uri) < 5
 562              // needed to catch http/https switch
 563              || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
 564              || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
 565          ) {
 566              $url = array();
 567  
 568              // At first we try to parse REQUEST_URI, it might contain full URL
 569              if (PMA_getenv('REQUEST_URI')) {
 570                  $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
 571                  if ($url === false) {
 572                      $url = array( 'path' => $_SERVER['REQUEST_URI'] );
 573                  }
 574              }
 575  
 576              // If we don't have scheme, we didn't have full URL so we need to
 577              // dig deeper
 578              if (empty($url['scheme'])) {
 579                  // Scheme
 580                  if (PMA_getenv('HTTP_SCHEME')) {
 581                      $url['scheme'] = PMA_getenv('HTTP_SCHEME');
 582                  } else {
 583                      $url['scheme'] =
 584                          PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
 585                              ? 'https'
 586                              : 'http';
 587                  }
 588  
 589                  // Host and port
 590                  if (PMA_getenv('HTTP_HOST')) {
 591                      if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
 592                          list($url['host'], $url['port']) =
 593                              explode(':', PMA_getenv('HTTP_HOST'));
 594                      } else {
 595                          $url['host'] = PMA_getenv('HTTP_HOST');
 596                      }
 597                  } elseif (PMA_getenv('SERVER_NAME')) {
 598                      $url['host'] = PMA_getenv('SERVER_NAME');
 599                  } else {
 600                      $this->error_pma_uri = true;
 601                      return false;
 602                  }
 603  
 604                  // If we didn't set port yet...
 605                  if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
 606                      $url['port'] = PMA_getenv('SERVER_PORT');
 607                  }
 608  
 609                  // And finally the path could be already set from REQUEST_URI
 610                  if (empty($url['path'])) {
 611                      if (PMA_getenv('PATH_INFO')) {
 612                          $path = parse_url(PMA_getenv('PATH_INFO'));
 613                      } else {
 614                          // PHP_SELF in CGI often points to cgi executable, so use it
 615                          // as last choice
 616                          $path = parse_url(PMA_getenv('PHP_SELF'));
 617                      }
 618                      $url['path'] = $path['path'];
 619                  }
 620              }
 621  
 622              // Make url from parts we have
 623              $pma_absolute_uri = $url['scheme'] . '://';
 624              // Was there user information?
 625              if (!empty($url['user'])) {
 626                  $pma_absolute_uri .= $url['user'];
 627                  if (!empty($url['pass'])) {
 628                      $pma_absolute_uri .= ':' . $url['pass'];
 629                  }
 630                  $pma_absolute_uri .= '@';
 631              }
 632              // Add hostname
 633              $pma_absolute_uri .= $url['host'];
 634              // Add port, if it not the default one
 635              if (! empty($url['port'])
 636                && (($url['scheme'] == 'http' && $url['port'] != 80)
 637                  || ($url['scheme'] == 'https' && $url['port'] != 443))) {
 638                  $pma_absolute_uri .= ':' . $url['port'];
 639              }
 640              // And finally path, without script name, the 'a' is there not to
 641              // strip our directory, when path is only /pmadir/ without filename.
 642              // Backslashes returned by Windows have to be changed.
 643              // Only replace backslashes by forward slashes if on Windows,
 644              // as the backslash could be valid on a non-Windows system.
 645              if ($this->get('PMA_IS_WINDOWS') == 1) {
 646                  $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
 647              } else {
 648                  $path = dirname($url['path'] . 'a');
 649              }
 650  
 651              // To work correctly within transformations overview:
 652              if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
 653                  if ($this->get('PMA_IS_WINDOWS') == 1) {
 654                      $path = str_replace("\\", "/", dirname(dirname($path)));
 655                  } else {
 656                      $path = dirname(dirname($path));
 657                  }
 658              }
 659              // in vhost situations, there could be already an ending slash
 660              if (substr($path, -1) != '/') {
 661                  $path .= '/';
 662              }
 663              $pma_absolute_uri .= $path;
 664  
 665              // We used to display a warning if PmaAbsoluteUri wasn't set, but now
 666              // the autodetect code works well enough that we don't display the
 667              // warning at all. The user can still set PmaAbsoluteUri manually.
 668              // See
 669              // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
 670  
 671          } else {
 672              // The URI is specified, however users do often specify this
 673              // wrongly, so we try to fix this.
 674  
 675              // Adds a trailing slash et the end of the phpMyAdmin uri if it
 676              // does not exist.
 677              if (substr($pma_absolute_uri, -1) != '/') {
 678                  $pma_absolute_uri .= '/';
 679              }
 680  
 681              // If URI doesn't start with http:// or https://, we will add
 682              // this.
 683              if (substr($pma_absolute_uri, 0, 7) != 'http://'
 684                && substr($pma_absolute_uri, 0, 8) != 'https://') {
 685                  $pma_absolute_uri =
 686                      (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
 687                          ? 'https'
 688                          : 'http')
 689                      . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
 690                      . $pma_absolute_uri;
 691              }
 692          }
 693  
 694          $this->set('PmaAbsoluteUri', $pma_absolute_uri);
 695      }
 696  
 697      /**
 698       * check selected collation_connection
 699       * @todo check validity of $_REQUEST['collation_connection']
 700       */
 701      function checkCollationConnection()
 702      {
 703          // (could be improved by executing it after the MySQL connection only if
 704          //  PMA_MYSQL_INT_VERSION >= 40100)
 705          if (! empty($_REQUEST['collation_connection'])) {
 706              $this->set('collation_connection',
 707                  strip_tags($_REQUEST['collation_connection']));
 708          }
 709      }
 710  
 711      /**
 712       * checks for font size configuration, and sets font size as requested by user
 713       *
 714       * @uses    $_GET
 715       * @uses    $_POST
 716       * @uses    $_COOKIE
 717       * @uses    preg_match()
 718       * @uses    function_exists()
 719       * @uses    PMA_Config::set()
 720       * @uses    PMA_Config::get()
 721       * @uses    PMA_setCookie()
 722       */
 723      function checkFontsize()
 724      {
 725          $new_fontsize = '';
 726  
 727          if (isset($_GET['fontsize'])) {
 728              $new_fontsize = $_GET['fontsize'];
 729          } elseif (isset($_POST['fontsize'])) {
 730              $new_fontsize = $_POST['fontsize'];
 731          } elseif (isset($_COOKIE['pma_fontsize'])) {
 732              $new_fontsize = $_COOKIE['pma_fontsize'];
 733          }
 734  
 735          if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
 736              $this->set('fontsize', $new_fontsize);
 737          } elseif (! $this->get('fontsize')) {
 738              $this->set('fontsize', '100%');
 739          }
 740  
 741          if (function_exists('PMA_setCookie')) {
 742              PMA_setCookie('pma_fontsize', $this->get('fontsize'), '100%');
 743          }
 744      }
 745  
 746      /**
 747       * checks if upload is enabled
 748       *
 749       */
 750      function checkUpload()
 751      {
 752          $this->set('enable_upload', true);
 753          if (strtolower(@ini_get('file_uploads')) == 'off'
 754            || @ini_get('file_uploads') == 0) {
 755              $this->set('enable_upload', false);
 756          }
 757      }
 758  
 759      /**
 760       * Maximum upload size as limited by PHP
 761       * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
 762       *
 763       * this section generates $max_upload_size in bytes
 764       */
 765      function checkUploadSize()
 766      {
 767          if (! $filesize = ini_get('upload_max_filesize')) {
 768              $filesize = "5M";
 769          }
 770  
 771          if ($postsize = ini_get('post_max_size')) {
 772              $this->set('max_upload_size',
 773                  min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
 774          } else {
 775              $this->set('max_upload_size', PMA_get_real_size($filesize));
 776          }
 777      }
 778  
 779      /**
 780       * check for https
 781       */
 782      function checkIsHttps()
 783      {
 784          $this->set('is_https', PMA_Config::isHttps());
 785      }
 786  
 787      /**
 788       * @static
 789       */
 790      function isHttps()
 791      {
 792          $is_https = false;
 793  
 794          $url = array();
 795  
 796          // At first we try to parse REQUEST_URI, it might contain full URL,
 797          if (PMA_getenv('REQUEST_URI')) {
 798              $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
 799              if($url === false) {
 800                  $url = array();
 801              }
 802          }
 803  
 804          // If we don't have scheme, we didn't have full URL so we need to
 805          // dig deeper
 806          if (empty($url['scheme'])) {
 807              // Scheme
 808              if (PMA_getenv('HTTP_SCHEME')) {
 809                  $url['scheme'] = PMA_getenv('HTTP_SCHEME');
 810              } else {
 811                  $url['scheme'] =
 812                      PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
 813                          ? 'https'
 814                          : 'http';
 815              }
 816          }
 817  
 818          if (isset($url['scheme'])
 819            && $url['scheme'] == 'https') {
 820              $is_https = true;
 821          } else {
 822              $is_https = false;
 823          }
 824  
 825          return $is_https;
 826      }
 827  
 828      /**
 829       * detect correct cookie path
 830       */
 831      function checkCookiePath()
 832      {
 833          $this->set('cookie_path', PMA_Config::getCookiePath());
 834      }
 835  
 836      /**
 837       * @static
 838       */
 839      function getCookiePath()
 840      {
 841          static $cookie_path = null;
 842  
 843          if (null !== $cookie_path) {
 844              return $cookie_path;
 845          }
 846  
 847          $url = '';
 848  
 849          if (PMA_getenv('REQUEST_URI')) {
 850              $url = PMA_getenv('REQUEST_URI');
 851          }
 852  
 853          // If we don't have path
 854          if (empty($url)) {
 855              if (PMA_getenv('PATH_INFO')) {
 856                  $url = PMA_getenv('PATH_INFO');
 857              } elseif (PMA_getenv('PHP_SELF')) {
 858                  // PHP_SELF in CGI often points to cgi executable, so use it
 859                  // as last choice
 860                  $url = PMA_getenv('PHP_SELF');
 861              } elseif (PMA_getenv('SCRIPT_NAME')) {
 862                  $url = PMA_getenv('PHP_SELF');
 863              }
 864          }
 865  
 866          $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
 867          if ($parsed_url === false) {
 868              $parsed_url = array('path' => $url);
 869          }
 870  
 871          $cookie_path   = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/'))  . '/';
 872  
 873          return $cookie_path;
 874      }
 875  
 876      /**
 877       * enables backward compatibility
 878       */
 879      function enableBc()
 880      {
 881          $GLOBALS['cfg']             =& $this->settings;
 882          $GLOBALS['default_server']  =& $this->default_server;
 883          $GLOBALS['collation_connection'] = $this->get('collation_connection');
 884          $GLOBALS['is_upload']       = $this->get('enable_upload');
 885          $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
 886          $GLOBALS['cookie_path']     = $this->get('cookie_path');
 887          $GLOBALS['is_https']        = $this->get('is_https');
 888  
 889          $defines = array(
 890              'PMA_VERSION',
 891              'PMA_THEME_VERSION',
 892              'PMA_THEME_GENERATION',
 893              'PMA_PHP_STR_VERSION',
 894              'PMA_PHP_INT_VERSION',
 895              'PMA_IS_WINDOWS',
 896              'PMA_IS_IIS',
 897              'PMA_IS_GD2',
 898              'PMA_USR_OS',
 899              'PMA_USR_BROWSER_VER',
 900              'PMA_USR_BROWSER_AGENT',
 901              );
 902  
 903          foreach ($defines as $define) {
 904              if (! defined($define)) {
 905                  define($define, $this->get($define));
 906              }
 907          }
 908      }
 909  
 910      /**
 911       * @todo finish
 912       */
 913      function save() {}
 914  
 915      /**
 916       * returns options for font size selection
 917       *
 918       * @uses    preg_replace()
 919       * @uses    ksort()
 920       * @static
 921       * @param   string  $current_size   current selected font size with unit
 922       * @return  array   selectable font sizes
 923       */
 924      function getFontsizeOptions($current_size = '100%')
 925      {
 926          $unit = preg_replace('/[0-9.]*/', '', $current_size);
 927          $value = preg_replace('/[^0-9.]*/', '', $current_size);
 928  
 929          $factors = array();
 930          $options = array();
 931          $options["$value"] = $value . $unit;
 932  
 933          if ($unit === '%') {
 934              $factors[] = 1;
 935              $factors[] = 5;
 936              $factors[] = 10;
 937          } elseif ($unit === 'em') {
 938              $factors[] = 0.05;
 939              $factors[] = 0.2;
 940              $factors[] = 1;
 941          } elseif ($unit === 'pt') {
 942              $factors[] = 0.5;
 943              $factors[] = 2;
 944          } elseif ($unit === 'px') {
 945              $factors[] = 1;
 946              $factors[] = 5;
 947              $factors[] = 10;
 948          } else {
 949              //unknown font size unit
 950              $factors[] = 0.05;
 951              $factors[] = 0.2;
 952              $factors[] = 1;
 953              $factors[] = 5;
 954              $factors[] = 10;
 955          }
 956  
 957          foreach ($factors as $key => $factor) {
 958              $option_inc = $value + $factor;
 959              $option_dec = $value - $factor;
 960              while (count($options) < 21) {
 961                  $options["$option_inc"] = $option_inc . $unit;
 962                  if ($option_dec > $factors[0]) {
 963                      $options["$option_dec"] = $option_dec . $unit;
 964                  }
 965                  $option_inc += $factor;
 966                  $option_dec -= $factor;
 967                  if (isset($factors[$key + 1])
 968                   && $option_inc >= $value + $factors[$key + 1]) {
 969                      break;
 970                  }
 971              }
 972          }
 973          ksort($options);
 974          return $options;
 975      }
 976  
 977      /**
 978       * returns html selectbox for font sizes
 979       *
 980       * @uses    $_SESSION['PMA_Config']
 981       * @uses    PMA_Config::get()
 982       * @uses    PMA_Config::getFontsizeOptions()
 983       * @uses    $GLOBALS['strFontSize']
 984       * @static
 985       * @param   string  $current_size   currently slected font size with unit
 986       * @return  string  html selectbox
 987       */
 988      function getFontsizeSelection()
 989      {
 990          $current_size = $_SESSION['PMA_Config']->get('fontsize');
 991          $options = PMA_Config::getFontsizeOptions($current_size);
 992  
 993          $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
 994          $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
 995          foreach ($options as $option) {
 996              $return .= '<option value="' . $option . '"';
 997              if ($option == $current_size) {
 998                  $return .= ' selected="selected"';
 999              }
1000              $return .= '>' . $option . '</option>' . "\n";
1001          }
1002          $return .= '</select>';
1003  
1004          return $return;
1005      }
1006  
1007      /**
1008       * return complete font size selection form
1009       *
1010       * @uses    PMA_generate_common_hidden_inputs()
1011       * @uses    PMA_Config::getFontsizeSelection()
1012       * @uses    $GLOBALS['strGo']
1013       * @static
1014       * @param   string  $current_size   currently slected font size with unit
1015       * @return  string  html selectbox
1016       */
1017      function getFontsizeForm()
1018      {
1019          return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1020              . ' method="post" action="index.php" target="_parent">' . "\n"
1021              . PMA_generate_common_hidden_inputs() . "\n"
1022              . PMA_Config::getFontsizeSelection() . "\n"
1023              . '<noscript>' . "\n"
1024              . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1025              . '</noscript>' . "\n"
1026              . '</form>';
1027      }
1028  }
1029  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics