Add function for plugins to load a local config file

release-0.6
thomascube 15 years ago
parent 66f68e9623
commit c73b195e5d

@ -51,15 +51,11 @@ class rcube_config
ob_start(); ob_start();
// load main config file // load main config file
if (include(RCMAIL_CONFIG_DIR . '/main.inc.php')) if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/main.inc.php'))
$this->prop = (array)$rcmail_config;
else
$this->errors[] = 'main.inc.php was not found.'; $this->errors[] = 'main.inc.php was not found.';
// load database config // load database config
if (include(RCMAIL_CONFIG_DIR . '/db.inc.php')) if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/db.inc.php'))
$this->prop += (array)$rcmail_config;
else
$this->errors[] = 'db.inc.php was not found.'; $this->errors[] = 'db.inc.php was not found.';
// load host-specific configuration // load host-specific configuration
@ -124,10 +120,30 @@ class rcube_config
$fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php'; $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php';
} }
if ($fname && is_file(RCMAIL_CONFIG_DIR . '/' . $fname)) { if ($fname) {
include(RCMAIL_CONFIG_DIR . '/' . $fname); $this->load_from_file(RCMAIL_CONFIG_DIR . '/' . $fname);
$this->prop = array_merge($this->prop, (array)$rcmail_config); }
}
/**
* 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;
} }

@ -47,6 +47,20 @@ abstract class rcube_plugin
* Initialization method, needs to be implemented by the plugin itself * Initialization method, needs to be implemented by the plugin itself
*/ */
abstract function init(); 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 * Register a callback function for a specific (server-side) hook

@ -81,7 +81,7 @@ else {
if (($CONFIG['debug_level'] & 4) && $ERROR_MESSAGE) if (($CONFIG['debug_level'] & 4) && $ERROR_MESSAGE)
$__error_text = $ERROR_MESSAGE; $__error_text = $ERROR_MESSAGE;
else else
$__error_text = sprintf('Error No. [0x%04X]', $ERROR_CODE); $__error_text = sprintf('Error No. [%s]', $ERROR_CODE);
} }

Loading…
Cancel
Save