summaryrefslogtreecommitdiff
path: root/roundcubemail/program/include
diff options
context:
space:
mode:
authorthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2009-05-21 20:34:28 +0000
committerthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2009-05-21 20:34:28 +0000
commit9b0aa170e0313acb11ed02d06aea49ab3248e9b6 (patch)
tree06851d0f1ada8eded5db0ad5052b0574dc465e45 /roundcubemail/program/include
parent2c1da0d681334a1322d6cbf21ce36079131a3041 (diff)
Add function for plugins to load a local config file
git-svn-id: https://svn.roundcube.net/trunk@2516 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include')
-rw-r--r--roundcubemail/program/include/rcube_config.php34
-rw-r--r--roundcubemail/program/include/rcube_plugin.php14
2 files changed, 39 insertions, 9 deletions
diff --git a/roundcubemail/program/include/rcube_config.php b/roundcubemail/program/include/rcube_config.php
index 56f577bda..d4adb7bd1 100644
--- a/roundcubemail/program/include/rcube_config.php
+++ b/roundcubemail/program/include/rcube_config.php
@@ -51,15 +51,11 @@ class rcube_config
ob_start();
// load main config file
- if (include(RCMAIL_CONFIG_DIR . '/main.inc.php'))
- $this->prop = (array)$rcmail_config;
- else
+ if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/main.inc.php'))
$this->errors[] = 'main.inc.php was not found.';
// load database config
- if (include(RCMAIL_CONFIG_DIR . '/db.inc.php'))
- $this->prop += (array)$rcmail_config;
- else
+ if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/db.inc.php'))
$this->errors[] = 'db.inc.php was not found.';
// load host-specific configuration
@@ -124,10 +120,30 @@ class rcube_config
$fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php';
}
- if ($fname && is_file(RCMAIL_CONFIG_DIR . '/' . $fname)) {
- include(RCMAIL_CONFIG_DIR . '/' . $fname);
- $this->prop = array_merge($this->prop, (array)$rcmail_config);
+ if ($fname) {
+ $this->load_from_file(RCMAIL_CONFIG_DIR . '/' . $fname);
+ }
+ }
+
+
+ /**
+ * Read configuration from a file
+ * and merge with the already stored config values
+ *
+ * @param string Full path to the config file to be loaded
+ * @return booelan True on success, false on failure
+ */
+ public function load_from_file($fpath)
+ {
+ if (is_file($fpath)) {
+ @include($fpath);
+ if (is_array($rcmail_config)) {
+ $this->prop = array_merge($this->prop, $rcmail_config);
+ return true;
+ }
}
+
+ return false;
}
diff --git a/roundcubemail/program/include/rcube_plugin.php b/roundcubemail/program/include/rcube_plugin.php
index 365ef2898..63acaf84e 100644
--- a/roundcubemail/program/include/rcube_plugin.php
+++ b/roundcubemail/program/include/rcube_plugin.php
@@ -47,6 +47,20 @@ abstract class rcube_plugin
* Initialization method, needs to be implemented by the plugin itself
*/
abstract function init();
+
+ /**
+ * Load local config file from plugins directory.
+ * The loaded values are patched over the global configuration.
+ *
+ * @param string Config file name relative to the plugin's folder
+ */
+ public function load_config($fname = 'config.inc.php')
+ {
+ $fpath = $this->home.'/'.$fname;
+ $rcmail = rcmail::get_instance();
+ if (!$rcmail->config->load_from_file($fpath))
+ raise_error(array('code' => 527, 'type' => 'php', 'message' => "Failed to load config from $fpath"), true, false);
+ }
/**
* Register a callback function for a specific (server-side) hook