[Svn] r2516 - in trunk/roundcubemail/program: include steps

trac at roundcube.net trac at roundcube.net
Thu May 21 22:34:28 CEST 2009


Author: thomasb
Date: 2009-05-21 15:34:28 -0500 (Thu, 21 May 2009)
New Revision: 2516

Modified:
   trunk/roundcubemail/program/include/rcube_config.php
   trunk/roundcubemail/program/include/rcube_plugin.php
   trunk/roundcubemail/program/steps/error.inc
Log:
Add function for plugins to load a local config file

Modified: trunk/roundcubemail/program/include/rcube_config.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_config.php	2009-05-21 20:02:43 UTC (rev 2515)
+++ trunk/roundcubemail/program/include/rcube_config.php	2009-05-21 20:34:28 UTC (rev 2516)
@@ -51,15 +51,11 @@
     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,14 +120,34 @@
       $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;
+  }
+  
+  
+  /**
    * Getter for a specific config parameter
    *
    * @param  string Parameter name

Modified: trunk/roundcubemail/program/include/rcube_plugin.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_plugin.php	2009-05-21 20:02:43 UTC (rev 2515)
+++ trunk/roundcubemail/program/include/rcube_plugin.php	2009-05-21 20:34:28 UTC (rev 2516)
@@ -47,6 +47,20 @@
    * 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

Modified: trunk/roundcubemail/program/steps/error.inc
===================================================================
--- trunk/roundcubemail/program/steps/error.inc	2009-05-21 20:02:43 UTC (rev 2515)
+++ trunk/roundcubemail/program/steps/error.inc	2009-05-21 20:34:28 UTC (rev 2516)
@@ -81,7 +81,7 @@
   if (($CONFIG['debug_level'] & 4) && $ERROR_MESSAGE)
     $__error_text = $ERROR_MESSAGE;
   else
-    $__error_text = sprintf('Error No. [0x%04X]', $ERROR_CODE);
+    $__error_text = sprintf('Error No. [%s]', $ERROR_CODE);
 }
 
 

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list