From eef9eb1146cf9903e58743291ca27c68340aea2c Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 21 Aug 2013 03:44:27 -0400
Subject: [PATCH] Synchronized localization files from Transifex

---
 program/lib/Roundcube/rcube_config.php |  104 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 80 insertions(+), 24 deletions(-)

diff --git a/program/lib/Roundcube/rcube_config.php b/program/lib/Roundcube/rcube_config.php
index 7d206ff..62567a0 100644
--- a/program/lib/Roundcube/rcube_config.php
+++ b/program/lib/Roundcube/rcube_config.php
@@ -2,8 +2,6 @@
 
 /*
  +-----------------------------------------------------------------------+
- | program/include/rcube_config.php                                      |
- |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
  | Copyright (C) 2008-2012, The Roundcube Dev Team                       |
  |                                                                       |
@@ -13,7 +11,6 @@
  |                                                                       |
  | PURPOSE:                                                              |
  |   Class to read configuration settings                                |
- |                                                                       |
  +-----------------------------------------------------------------------+
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
@@ -29,6 +26,8 @@
 {
     const DEFAULT_SKIN = 'larry';
 
+    private $env = '';
+    private $basedir = 'config/';
     private $prop = array();
     private $errors = array();
     private $userprefs = array();
@@ -46,14 +45,21 @@
         'reply_mode'           => 'top_posting',
         'refresh_interval'     => 'keep_alive',
         'min_refresh_interval' => 'min_keep_alive',
+        'messages_cache_ttl'   => 'message_cache_lifetime',
+        'redundant_attachments_cache_ttl' => 'redundant_attachments_memcache_ttl',
     );
 
 
     /**
      * Object constructor
+     *
+     * @param string Environment suffix for config files to load
      */
-    public function __construct()
+    public function __construct($env = '')
     {
+        $this->env = $env;
+        $this->basedir = RCUBE_CONFIG_DIR;
+
         $this->load();
 
         // Defaults, that we do not require you to configure,
@@ -70,16 +76,26 @@
      */
     private function load()
     {
-        // load main config file
-        if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/main.inc.php'))
-            $this->errors[] = 'main.inc.php was not found.';
+        // Load default settings
+        if (!$this->load_from_file('defaults.inc.php')) {
+            $this->errors[] = 'defaults.inc.php was not found.';
+        }
 
-        // load database config
-        if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/db.inc.php'))
-            $this->errors[] = 'db.inc.php was not found.';
+        // load main config file
+        if (!$this->load_from_file('config.inc.php')) {
+            // Old configuration files
+            if (!$this->load_from_file('main.inc.php') ||
+                !$this->load_from_file('db.inc.php')) {
+                $this->errors[] = 'config.inc.php was not found.';
+            }
+            else if (rand(1,100) == 10) {  // log warning on every 100th request (average)
+                trigger_error("config.inc.php was not found. Please migrate your config by running bin/update.sh", E_USER_WARNING);
+            }
+        }
 
         // load host-specific configuration
-        $this->load_host_config();
+        if (!empty($_SERVER['HTTP_HOST']))
+            $this->load_host_config();
 
         // set skin (with fallback to old 'skin_path' property)
         if (empty($this->prop['skin'])) {
@@ -96,16 +112,16 @@
             $this->prop['skin'] = self::DEFAULT_SKIN;
 
         // fix paths
-        $this->prop['log_dir'] = $this->prop['log_dir'] ? realpath(unslashify($this->prop['log_dir'])) : INSTALL_PATH . 'logs';
-        $this->prop['temp_dir'] = $this->prop['temp_dir'] ? realpath(unslashify($this->prop['temp_dir'])) : INSTALL_PATH . 'temp';
+        $this->prop['log_dir'] = $this->prop['log_dir'] ? realpath(unslashify($this->prop['log_dir'])) : RCUBE_INSTALL_PATH . 'logs';
+        $this->prop['temp_dir'] = $this->prop['temp_dir'] ? realpath(unslashify($this->prop['temp_dir'])) : RCUBE_INSTALL_PATH . 'temp';
 
         // fix default imap folders encoding
         foreach (array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox') as $folder)
-            $this->prop[$folder] = rcube_charset::convert($this->prop[$folder], RCMAIL_CHARSET, 'UTF7-IMAP');
+            $this->prop[$folder] = rcube_charset::convert($this->prop[$folder], RCUBE_CHARSET, 'UTF7-IMAP');
 
         if (!empty($this->prop['default_folders']))
             foreach ($this->prop['default_folders'] as $n => $folder)
-                $this->prop['default_folders'][$n] = rcube_charset::convert($folder, RCMAIL_CHARSET, 'UTF7-IMAP');
+                $this->prop['default_folders'][$n] = rcube_charset::convert($folder, RCUBE_CHARSET, 'UTF7-IMAP');
 
         // set PHP error logging according to config
         if ($this->prop['debug_level'] & 1) {
@@ -156,7 +172,7 @@
         }
 
         if ($fname) {
-            $this->load_from_file(RCMAIL_CONFIG_DIR . '/' . $fname);
+            $this->load_from_file($fname);
         }
     }
 
@@ -165,24 +181,50 @@
      * Read configuration from a file
      * and merge with the already stored config values
      *
-     * @param string $fpath Full path to the config file to be loaded
+     * @param string $file Name of the config file to be loaded
      * @return booelan True on success, false on failure
      */
-    public function load_from_file($fpath)
+    public function load_from_file($file)
     {
-        if (is_file($fpath) && is_readable($fpath)) {
+        $fpath = $this->resolve_path($file);
+        if ($fpath && is_file($fpath) && is_readable($fpath)) {
             // use output buffering, we don't need any output here 
             ob_start();
             include($fpath);
             ob_end_clean();
 
-            if (is_array($rcmail_config)) {
-                $this->prop = array_merge($this->prop, $rcmail_config, $this->userprefs);
+            if (is_array($config)) {
+                $this->merge($config);
+                return true;
+            }
+            // deprecated name of config variable
+            else if (is_array($rcmail_config)) {
+                $this->merge($rcmail_config);
                 return true;
             }
         }
 
         return false;
+    }
+
+    /**
+     * Helper method to resolve the absolute path to the given config file.
+     * This also takes the 'env' property into account.
+     */
+    public function resolve_path($file, $use_env = true)
+    {
+        if (strpos($file, '/') === false) {
+            $file = realpath($this->basedir . '/' . $file);
+        }
+
+        // check if <file>-env.ini exists
+        if ($file && $use_env && !empty($this->env)) {
+            $envfile = preg_replace('/\.(inc.php)$/', '-' . $this->env . '.\\1', $file);
+            if (is_file($envfile))
+                return $envfile;
+        }
+
+        return $file;
     }
 
 
@@ -197,9 +239,6 @@
     {
         if (isset($this->prop[$name])) {
             $result = $this->prop[$name];
-        }
-        else if (isset($this->legacy_props[$name])) {
-            return $this->get($this->legacy_props[$name], $def);
         }
         else {
             $result = $def;
@@ -244,6 +283,7 @@
     public function merge($prefs)
     {
         $this->prop = array_merge($this->prop, $prefs, $this->userprefs);
+        $this->fix_legacy_props();
     }
 
 
@@ -275,6 +315,8 @@
 
         $this->userprefs = $prefs;
         $this->prop      = array_merge($this->prop, $prefs);
+
+        $this->fix_legacy_props();
 
         // override timezone settings with client values
         if ($this->prop['timezone'] == 'auto') {
@@ -438,4 +480,18 @@
         return date_default_timezone_get();
     }
 
+    /**
+     * Convert legacy options into new ones
+     */
+    private function fix_legacy_props()
+    {
+        foreach ($this->legacy_props as $new => $old) {
+            if (isset($this->prop[$old])) {
+                if (!isset($this->prop[$new])) {
+                    $this->prop[$new] = $this->prop[$old];
+                }
+                unset($this->prop[$old]);
+            }
+        }
+    }
 }

--
Gitblit v1.9.1