From deb2b8d0804d1d25a3f28266747ce9041495b372 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Fri, 12 Jul 2013 04:17:32 -0400
Subject: [PATCH] Allow to load config files for different environments (#1487311); keep (non-default) filename in URLs throughout the webmail app

---
 program/include/rcmail.php |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index fd625ba..800edda 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -51,6 +51,7 @@
    */
   public $action = '';
   public $comm_path = './';
+  public $filename = '';
 
   private $address_books = array();
   private $action_map = array();
@@ -65,12 +66,13 @@
   /**
    * This implements the 'singleton' design pattern
    *
+   * @param string Environment name to run (e.g. live, dev, test)
    * @return rcmail The one and only instance
    */
-  static function get_instance()
+  static function get_instance($env = '')
   {
     if (!self::$instance || !is_a(self::$instance, 'rcmail')) {
-      self::$instance = new rcmail();
+      self::$instance = new rcmail($env);
       self::$instance->startup();  // init AFTER object was linked with self::$instance
     }
 
@@ -85,6 +87,10 @@
   protected function startup()
   {
     $this->init(self::INIT_WITH_DB | self::INIT_WITH_PLUGINS);
+
+    // set filename if not index.php
+    if (($basename = basename($_SERVER['SCRIPT_FILENAME'])) && $basename != 'index.php')
+      $this->filename = $basename;
 
     // start session
     $this->session_init();
@@ -162,7 +168,7 @@
     setlocale(LC_ALL, $lang . '.utf8', $lang . '.UTF-8', 'en_US.utf8', 'en_US.UTF-8');
 
     // workaround for http://bugs.php.net/bug.php?id=18556
-    if (in_array($lang, array('tr_TR', 'ku', 'az_AZ'))) {
+    if (version_compare(PHP_VERSION, '5.5.0', '<') && in_array($lang, array('tr_TR', 'ku', 'az_AZ'))) {
       setlocale(LC_CTYPE, 'en_US.utf8', 'en_US.UTF-8');
     }
   }
@@ -294,7 +300,7 @@
         $list[$id] = array(
           'id'       => $id,
           'name'     => html::quote($prop['name']),
-          'groups'   => is_array($prop['groups']),
+          'groups'   => !empty($prop['groups']) || !empty($prop['group_filters']),
           'readonly' => !$prop['writable'],
           'hidden'   => $prop['hidden'],
           'autocomplete' => in_array($id, $autocomplete)
@@ -724,7 +730,7 @@
     $p['_task'] = $task;
     unset($p['task']);
 
-    $url = './';
+    $url = './' . $this->filename;
     $delm = '?';
     foreach (array_reverse($p) as $key => $val) {
       if ($val !== '' && $val !== null) {
@@ -747,11 +753,6 @@
     foreach ($this->address_books as $book) {
       if (is_object($book) && is_a($book, 'rcube_addressbook'))
         $book->close();
-    }
-
-    // before closing the database connection, write session data
-    if ($_SERVER['REMOTE_ADDR'] && is_object($this->session)) {
-      $this->session->write_close();
     }
 
     // write performance stats to logs/console
@@ -1765,7 +1766,8 @@
     public function upload_init()
     {
         // Enable upload progress bar
-        if (($seconds = $this->config->get('upload_progress')) && ini_get('apc.rfc1867')) {
+        $rfc1867 = filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN);
+        if ($rfc1867 && ($seconds = $this->config->get('upload_progress'))) {
             if ($field_name = ini_get('apc.rfc1867_name')) {
                 $this->output->set_env('upload_progress_name', $field_name);
                 $this->output->set_env('upload_progress_time', (int) $seconds);

--
Gitblit v1.9.1