diff --git a/index.php b/index.php index 5d5257142..2d220dede 100644 --- a/index.php +++ b/index.php @@ -39,7 +39,7 @@ require_once 'program/include/iniset.php'; // init application, start session, init output class, etc. -$RCMAIL = rcmail::get_instance(); +$RCMAIL = rcmail::get_instance($GLOBALS['env']); // Make the whole PHP output non-cacheable (#1487797) $RCMAIL->output->nocacheing_headers(); diff --git a/program/include/rcmail.php b/program/include/rcmail.php index d430cd350..800eddac6 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -51,6 +51,7 @@ class rcmail extends rcube */ public $action = ''; public $comm_path = './'; + public $filename = ''; private $address_books = array(); private $action_map = array(); @@ -65,12 +66,13 @@ class rcmail extends rcube /** * 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 } @@ -86,6 +88,10 @@ class rcmail extends rcube { $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(); @@ -724,7 +730,7 @@ class rcmail extends rcube $p['_task'] = $task; unset($p['task']); - $url = './'; + $url = './' . $this->filename; $delm = '?'; foreach (array_reverse($p) as $key => $val) { if ($val !== '' && $val !== null) { diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php index c96a40ab9..998779509 100644 --- a/program/include/rcmail_output_html.php +++ b/program/include/rcmail_output_html.php @@ -1004,7 +1004,9 @@ class rcmail_output_html extends rcmail_output } return html::quote($value); - break; + + case 'form': + return $this->form_tag($attrib); } return ''; } @@ -1432,7 +1434,7 @@ class rcmail_output_html extends rcmail_output $attrib['noclose'] = true; return html::tag('form', - $attrib + array('action' => "./", 'method' => "get"), + $attrib + array('action' => $this->app->comm_path, 'method' => "get"), $hidden . $content, array('id','class','style','name','method','action','enctype','onsubmit')); } diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 05a94f3be..ce97cd0a5 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -105,13 +105,14 @@ class rcube * This implements the 'singleton' design pattern * * @param integer Options to initialize with this instance. See rcube::INIT_WITH_* constants + * @param string Environment name to run (e.g. live, dev, test) * * @return rcube The one and only instance */ - static function get_instance($mode = 0) + static function get_instance($mode = 0, $env = '') { if (!self::$instance) { - self::$instance = new rcube(); + self::$instance = new rcube($env); self::$instance->init($mode); } @@ -122,10 +123,10 @@ class rcube /** * Private constructor */ - protected function __construct() + protected function __construct($env = '') { // load configuration - $this->config = new rcube_config; + $this->config = new rcube_config($env); $this->plugins = new rcube_dummy_plugin_api; register_shutdown_function(array($this, 'shutdown')); diff --git a/program/lib/Roundcube/rcube_config.php b/program/lib/Roundcube/rcube_config.php index 90bb85348..62567a0e0 100644 --- a/program/lib/Roundcube/rcube_config.php +++ b/program/lib/Roundcube/rcube_config.php @@ -26,6 +26,8 @@ class rcube_config { const DEFAULT_SKIN = 'larry'; + private $env = ''; + private $basedir = 'config/'; private $prop = array(); private $errors = array(); private $userprefs = array(); @@ -50,9 +52,14 @@ class rcube_config /** * 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,15 +77,15 @@ class rcube_config private function load() { // Load default settings - if (!$this->load_from_file(RCUBE_CONFIG_DIR . 'defaults.inc.php')) { + if (!$this->load_from_file('defaults.inc.php')) { $this->errors[] = 'defaults.inc.php was not found.'; } // load main config file - if (!$this->load_from_file(RCUBE_CONFIG_DIR . 'config.inc.php')) { + if (!$this->load_from_file('config.inc.php')) { // Old configuration files - if (!$this->load_from_file(RCUBE_CONFIG_DIR . 'main.inc.php') || - !$this->load_from_file(RCUBE_CONFIG_DIR . 'db.inc.php')) { + 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) @@ -87,7 +94,8 @@ class rcube_config } // 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'])) { @@ -164,7 +172,7 @@ class rcube_config } if ($fname) { - $this->load_from_file(RCUBE_CONFIG_DIR . $fname); + $this->load_from_file($fname); } } @@ -173,12 +181,13 @@ class rcube_config * 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); @@ -198,6 +207,26 @@ class rcube_config 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 -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; + } + /** * Getter for a specific config parameter diff --git a/skins/classic/templates/compose.html b/skins/classic/templates/compose.html index 660f354cd..5e259e11c 100644 --- a/skins/classic/templates/compose.html +++ b/skins/classic/templates/compose.html @@ -44,7 +44,7 @@ -
+
diff --git a/skins/classic/templates/contactadd.html b/skins/classic/templates/contactadd.html index 86bca46ea..bad6daf28 100644 --- a/skins/classic/templates/contactadd.html +++ b/skins/classic/templates/contactadd.html @@ -9,7 +9,7 @@
- +
:
diff --git a/skins/classic/templates/contactedit.html b/skins/classic/templates/contactedit.html index 8ab801d05..c51cbf296 100644 --- a/skins/classic/templates/contactedit.html +++ b/skins/classic/templates/contactedit.html @@ -9,7 +9,7 @@
- +
:
diff --git a/skins/classic/templates/login.html b/skins/classic/templates/login.html index cca2bd934..2dacd48ff 100644 --- a/skins/classic/templates/login.html +++ b/skins/classic/templates/login.html @@ -15,7 +15,7 @@
- +

diff --git a/skins/larry/templates/compose.html b/skins/larry/templates/compose.html index 9cfe7fe4c..09eafe73b 100644 --- a/skins/larry/templates/compose.html +++ b/skins/larry/templates/compose.html @@ -65,7 +65,7 @@
- +
diff --git a/skins/larry/templates/contactedit.html b/skins/larry/templates/contactedit.html index f84936635..3467ebe8e 100644 --- a/skins/larry/templates/contactedit.html +++ b/skins/larry/templates/contactedit.html @@ -11,7 +11,7 @@ - +
:
diff --git a/skins/larry/templates/login.html b/skins/larry/templates/login.html index a605eb7fe..6e56ee2fd 100644 --- a/skins/larry/templates/login.html +++ b/skins/larry/templates/login.html @@ -11,7 +11,7 @@