Пример #1
0
 /**
  * Loads user preferences and merges them with current config
  * must be called after control connection has been estabilished
  *
  * @uses $GLOBALS['cfg']
  * @uses $GLOBALS['collation_connection']
  * @uses $GLOBALS['lang']
  * @uses $_SESSION['cache']['server_$server']['config_mtime']
  * @uses $_SESSION['cache']['server_$server']['userprefs']
  * @uses $_SESSION['cache']['server_$server']['userprefs_mtime']
  * @uses $_SESSION['PMA_Theme_Manager']
  * @uses PMA_apply_userprefs()
  * @uses PMA_array_merge_recursive()
  * @uses PMA_load_userprefs()
  * @return boolean
  */
 function loadUserPreferences()
 {
     // index.php should load these settings, so that phpmyadmin.css.php
     // will have everything avaiable in session cache
     $server = isset($GLOBALS['server']) ? $GLOBALS['server'] : (!empty($GLOBALS['cfg']['ServerDefault']) ? $GLOBALS['cfg']['ServerDefault'] : 0);
     $cache_key = 'server_' . $server;
     if ($server > 0 && !defined('PMA_MINIMUM_COMMON')) {
         $config_mtime = max($this->default_source_mtime, $this->source_mtime);
         // cache user preferences, use database only when needed
         if (!isset($_SESSION['cache'][$cache_key]['userprefs']) || $_SESSION['cache'][$cache_key]['config_mtime'] < $config_mtime) {
             // load required libraries
             require_once './libraries/user_preferences.lib.php';
             $prefs = PMA_load_userprefs();
             $_SESSION['cache'][$cache_key]['userprefs'] = PMA_apply_userprefs($prefs['config_data']);
             $_SESSION['cache'][$cache_key]['userprefs_mtime'] = $prefs['mtime'];
             $_SESSION['cache'][$cache_key]['userprefs_type'] = $prefs['type'];
             $_SESSION['cache'][$cache_key]['config_mtime'] = $config_mtime;
         }
     } else {
         if ($server == 0 || !isset($_SESSION['cache'][$cache_key]['userprefs'])) {
             $this->set('user_preferences', false);
             return;
         }
     }
     $config_data = $_SESSION['cache'][$cache_key]['userprefs'];
     // type is 'db' or 'session'
     $this->set('user_preferences', $_SESSION['cache'][$cache_key]['userprefs_type']);
     $this->set('user_preferences_mtime', $_SESSION['cache'][$cache_key]['userprefs_mtime']);
     // backup some settings
     $org_fontsize = $this->settings['fontsize'];
     // load config array
     $this->settings = PMA_array_merge_recursive($this->settings, $config_data);
     $GLOBALS['cfg'] = PMA_array_merge_recursive($GLOBALS['cfg'], $config_data);
     if (defined('PMA_MINIMUM_COMMON')) {
         return;
     }
     // settings below start really working on next page load, but
     // changes are made only in index.php so everything is set when
     // in frames
     // save theme
     $tmanager = $_SESSION['PMA_Theme_Manager'];
     if ($tmanager->getThemeCookie() || isset($_REQUEST['set_theme'])) {
         if (!isset($config_data['ThemeDefault']) && $tmanager->theme->getId() != 'original' || isset($config_data['ThemeDefault']) && $config_data['ThemeDefault'] != $tmanager->theme->getId()) {
             // new theme was set in common.inc.php
             $this->setUserValue(null, 'ThemeDefault', $tmanager->theme->getId(), 'original');
         }
     } else {
         // no cookie - read default from settings
         if ($this->settings['ThemeDefault'] != $tmanager->theme->getId() && $tmanager->checkTheme($this->settings['ThemeDefault'])) {
             $tmanager->setActiveTheme($this->settings['ThemeDefault']);
             $tmanager->setThemeCookie();
         }
     }
     // save font size
     if (!isset($config_data['fontsize']) && $org_fontsize != '82%' || isset($config_data['fontsize']) && $org_fontsize != $config_data['fontsize']) {
         $this->setUserValue(null, 'fontsize', $org_fontsize, '82%');
     }
     // save language
     if (isset($_COOKIE['pma_lang']) || isset($_POST['lang'])) {
         if (!isset($config_data['lang']) && $GLOBALS['lang'] != 'en' || isset($config_data['lang']) && $GLOBALS['lang'] != $config_data['lang']) {
             $this->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
         }
     } else {
         // read language from settings
         if (isset($config_data['lang']) && PMA_langSet($config_data['lang'])) {
             $this->setCookie('pma_lang', $GLOBALS['lang']);
         }
     }
     // save connection collation
     if (isset($_COOKIE['pma_collation_connection']) || isset($_POST['collation_connection'])) {
         if (!isset($config_data['collation_connection']) && $GLOBALS['collation_connection'] != 'utf8_general_ci' || isset($config_data['collation_connection']) && $GLOBALS['collation_connection'] != $config_data['collation_connection']) {
             $this->setUserValue(null, 'collation_connection', $GLOBALS['collation_connection'], 'utf8_general_ci');
         }
     } else {
         // read collation from settings
         if (isset($config_data['collation_connection'])) {
             $GLOBALS['collation_connection'] = $config_data['collation_connection'];
             $this->setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
         }
     }
 }
Пример #2
0
/**
 * merges array recursive like array_merge_recursive() but keyed-values are
 * always overwritten.
 *
 * array PMA_array_merge_recursive(array $array1[, array $array2[, array ...]])
 *
 * @see     http://php.net/array_merge
 * @see     http://php.net/array_merge_recursive
 * @uses    func_num_args()
 * @uses    func_get_arg()
 * @uses    is_array()
 * @uses    call_user_func_array()
 * @param   array   array to merge
 * @param   array   array to merge
 * @param   array   ...
 * @return  array   merged array
 */
function PMA_array_merge_recursive()
{
    switch (func_num_args()) {
        case 0:
            return false;
            break;
        case 1:
            // when does that happen?
            return func_get_arg(0);
            break;
        case 2:
            $args = func_get_args();
            if (!is_array($args[0]) || !is_array($args[1])) {
                return $args[1];
            }
            foreach ($args[1] as $key2 => $value2) {
                if (isset($args[0][$key2]) && !is_int($key2)) {
                    $args[0][$key2] = PMA_array_merge_recursive($args[0][$key2], $value2);
                } else {
                    // we erase the parent array, otherwise we cannot override a directive that
                    // contains array elements, like this:
                    // (in config.default.php) $cfg['ForeignKeyDropdownOrder'] = array('id-content','content-id');
                    // (in config.inc.php) $cfg['ForeignKeyDropdownOrder'] = array('content-id');
                    if (is_int($key2) && $key2 == 0) {
                        unset($args[0]);
                    }
                    $args[0][$key2] = $value2;
                }
            }
            return $args[0];
            break;
        default:
            $args = func_get_args();
            $args[1] = PMA_array_merge_recursive($args[0], $args[1]);
            array_shift($args);
            return call_user_func_array('PMA_array_merge_recursive', $args);
            break;
    }
}
Пример #3
0
 /**
  * Tests loading of default values
  *
  * @group large
  */
 public function testLoadDefaults()
 {
     $prevDefaultSource = $this->object->default_source;
     $this->object->default_source = 'unexisted.file.php';
     $this->assertFalse($this->object->loadDefaults());
     $this->object->default_source = $prevDefaultSource;
     include $this->object->default_source;
     $loadedConf = $cfg;
     unset($cfg);
     $this->assertTrue($this->object->loadDefaults());
     $this->assertEquals($this->object->default_source_mtime, filemtime($prevDefaultSource));
     $this->assertEquals($loadedConf['Servers'][1], $this->object->default_server);
     unset($loadedConf['Servers']);
     $this->assertEquals($loadedConf, $this->object->default);
     $expectedSettings = PMA_array_merge_recursive($this->object->settings, $loadedConf);
     $this->assertEquals($expectedSettings, $this->object->settings, 'Settings loaded wrong');
     $this->assertFalse($this->object->error_config_default_file);
 }
 /**
  * loads configuration from $source, usally the config file
  * should be called on object creation and from __wakeup if config file
  * has changed
  *
  * @param   string $source  config file
  */
 function load($source = null)
 {
     $this->loadDefaults();
     if (null !== $source) {
         $this->setSource($source);
     }
     if (!$this->checkConfigSource()) {
         return false;
     }
     $cfg = array();
     /**
      * Parses the configuration file
      */
     $old_error_reporting = error_reporting(0);
     if (function_exists('file_get_contents')) {
         $eval_result = eval('?>' . trim(file_get_contents($this->getSource())));
     } else {
         $eval_result = eval('?>' . trim(implode("\n", file($this->getSource()))));
     }
     error_reporting($old_error_reporting);
     if ($eval_result === false) {
         $this->error_config_file = true;
     } else {
         $this->error_config_file = false;
         $this->source_mtime = filemtime($this->getSource());
     }
     /**
      * Backward compatibility code
      */
     if (!empty($cfg['DefaultTabTable'])) {
         $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
     }
     if (!empty($cfg['DefaultTabDatabase'])) {
         $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
     }
     $this->checkFontsize();
     //$this->checkPmaAbsoluteUri();
     $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
     // Handling of the collation must be done after merging of $cfg
     // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
     // can have an effect. Note that the presence of collation
     // information in a cookie has priority over what is defined
     // in the default or user's config files.
     /**
      * @todo check validity of $_COOKIE['pma_collation_connection']
      */
     if (!empty($_COOKIE['pma_collation_connection'])) {
         $this->set('collation_connection', strip_tags($_COOKIE['pma_collation_connection']));
     } else {
         $this->set('collation_connection', $this->get('DefaultConnectionCollation'));
     }
     // Now, a collation information could come from REQUEST
     // (an example of this: the collation selector in main.php)
     // so the following handles the setting of collation_connection
     // and later, in common.inc.php, the cookie will be set
     // according to this.
     $this->checkCollationConnection();
     return true;
 }
Пример #5
0
 /**
  * loads configuration from $source, usally the config file
  * should be called on object creation and from __wakeup if config file
  * has changed
  *
  * @param   string $source  config file
  */
 function load($source = null)
 {
     $this->loadDefaults();
     if (null !== $source) {
         $this->setSource($source);
     }
     if (!$this->checkConfigSource()) {
         return false;
     }
     $cfg = array();
     /**
      * Parses the configuration file
      */
     $old_error_reporting = error_reporting(0);
     if (function_exists('file_get_contents')) {
         $eval_result = eval('?>' . trim(file_get_contents($this->getSource())));
     } else {
         $eval_result = eval('?>' . trim(implode("\n", file($this->getSource()))));
     }
     error_reporting($old_error_reporting);
     if ($eval_result === false) {
         $this->error_config_file = true;
     } else {
         $this->error_config_file = false;
         $this->source_mtime = filemtime($this->getSource());
     }
     /**
      * @TODO check validity of $_COOKIE['pma_collation_connection']
      */
     if (!empty($_COOKIE['pma_collation_connection'])) {
         $this->set('collation_connection', strip_tags($_COOKIE['pma_collation_connection']));
     } else {
         $this->set('collation_connection', $this->get('DefaultConnectionCollation'));
     }
     $this->checkCollationConnection();
     $this->checkFontsize();
     //$this->checkPmaAbsoluteUri();
     $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
     return true;
 }
Пример #6
0
 function testPMA_array_merge_recursive()
 {
     $arr1 = array('key1' => 1, 'key2' => 2.3, 'key3' => 'str3');
     $arr2 = array('key1' => 4, 'key2' => 5, 'key3' => 6);
     $arr3 = array('key4' => 7, 'key5' => 'str8', 'key6' => 9);
     $arr4 = array(1, 2, 3);
     $this->assertFalse(PMA_array_merge_recursive());
     $this->assertEquals(PMA_array_merge_recursive($arr1), $arr1);
     $this->assertEquals(PMA_array_merge_recursive($arr1, 'str'), 'str');
     $this->assertEquals(PMA_array_merge_recursive('str1', $arr2), $arr2);
     $this->assertEquals(PMA_array_merge_recursive($arr1, $arr2), array('key1' => 4, 'key2' => 5, 'key3' => 6));
     $this->assertEquals(PMA_array_merge_recursive($arr1, $arr3), array('key1' => 1, 'key2' => 2.3, 'key3' => 'str3', 'key4' => 7, 'key5' => 'str8', 'key6' => 9));
     $this->assertEquals(PMA_array_merge_recursive($arr2, $arr4), array(1, 2, 3));
     $this->assertEquals(PMA_array_merge_recursive($arr1, $arr2, $arr3), array('key1' => 4, 'key2' => 5, 'key3' => 6, 'key4' => 7, 'key5' => 'str8', 'key6' => 9));
 }