home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / Config.class.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  33.5 KB  |  1,045 lines

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