From c73b195e5d02a09d56430dd6e666313b86fee2f9 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Thu, 21 May 2009 16:34:28 -0400
Subject: [PATCH] Add function for plugins to load a local config file
---
program/include/rcube_plugin.php | 38 +++++++++++++++++++++++++++++++++++---
1 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/program/include/rcube_plugin.php b/program/include/rcube_plugin.php
index 62f65a9..63acaf8 100644
--- a/program/include/rcube_plugin.php
+++ b/program/include/rcube_plugin.php
@@ -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
@@ -101,11 +115,29 @@
* @return string Localized text
* @see rcmail::gettext()
*/
- function gettext($p)
+ public function gettext($p)
{
return rcmail::get_instance()->gettext($p, $this->ID);
}
-
+
+ /**
+ * Register this plugin to be responsible for a specific task
+ *
+ * @param string Task name (only characters [a-z0-9_.-] are allowed)
+ */
+ public function register_task($task)
+ {
+ if ($task != asciiwords($task)) {
+ raise_error(array('code' => 526, 'type' => 'php', 'message' => "Invalid task name: $task. Only characters [a-z0-9_.-] are allowed"), true, false);
+ }
+ else if (in_array(rcmail::$main_tasks, $task)) {
+ raise_error(array('code' => 526, 'type' => 'php', 'message' => "Cannot register taks $task; already taken by another plugin or the application itself"), true, false);
+ }
+ else {
+ rcmail::$main_tasks[] = $task;
+ }
+ }
+
/**
* Register a handler for a specific client-request action
*
@@ -177,7 +209,7 @@
*/
private function ressource_url($fn)
{
- if ($fn[0] != '/' && !eregi('^https?://', $fn))
+ if ($fn[0] != '/' && !preg_match('|^https?://|i', $fn))
return $this->ID . '/' . $fn;
else
return $fn;
--
Gitblit v1.9.1