summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2012-03-07 10:07:57 +0000
committeralecpl <alec@alec.pl>2012-03-07 10:07:57 +0000
commit479af90579e7898ded7ed5de966ab03a3be9300a (patch)
tree925806bbcc1e6967952dabe6bb8015604c293ba8
parent2f88b17d341980bfb025cdb002f41f12331bfd16 (diff)
- Hook unregister methods (#1488184)
-rw-r--r--program/include/rcube_plugin.php31
-rw-r--r--program/include/rcube_plugin_api.php14
2 files changed, 34 insertions, 11 deletions
diff --git a/program/include/rcube_plugin.php b/program/include/rcube_plugin.php
index 9864749d7..aeb05afa1 100644
--- a/program/include/rcube_plugin.php
+++ b/program/include/rcube_plugin.php
@@ -81,7 +81,7 @@ abstract class rcube_plugin
$this->home = $api->dir . $this->ID;
$this->urlbase = $api->url . $this->ID . '/';
}
-
+
/**
* Initialization method, needs to be implemented by the plugin itself
*/
@@ -117,7 +117,7 @@ abstract class rcube_plugin
'message' => "Failed to load config from $fpath"), true, false);
return false;
}
-
+
return true;
}
@@ -131,7 +131,18 @@ abstract class rcube_plugin
{
$this->api->register_hook($hook, $callback);
}
-
+
+ /**
+ * Unregister a callback function for a specific (server-side) hook.
+ *
+ * @param string $hook Hook name
+ * @param mixed $callback Callback function as string or array with object reference and method name
+ */
+ public function remove_hook($hook, $callback)
+ {
+ $this->api->unregister_hook($hook, $callback);
+ }
+
/**
* Load localized texts from the plugins dir
*
@@ -141,7 +152,7 @@ abstract class rcube_plugin
public function add_texts($dir, $add2client = false)
{
$domain = $this->ID;
-
+
$lang = $_SESSION['language'];
$locdir = slashify(realpath(slashify($this->home) . $dir));
$texts = array();
@@ -167,7 +178,7 @@ abstract class rcube_plugin
$rcmail = rcmail::get_instance();
$rcmail->load_language($lang, $add);
-
+
// add labels to client
if ($add2client) {
$js_labels = is_array($add2client) ? array_map(array($this, 'label_map_callback'), $add2client) : array_keys($add);
@@ -175,7 +186,7 @@ abstract class rcube_plugin
}
}
}
-
+
/**
* Wrapper for rcmail::gettext() adding the plugin ID as domain
*
@@ -245,7 +256,7 @@ abstract class rcube_plugin
{
$this->api->include_stylesheet($this->resource_url($fn));
}
-
+
/**
* Append a button to a certain container
*
@@ -260,11 +271,11 @@ abstract class rcube_plugin
foreach (array('imagepas', 'imageact', 'imagesel') as $key)
if ($p[$key])
$p[$key] = $this->api->url . $this->resource_url($p[$key]);
-
+
$this->api->add_content($this->api->output->button($p), $container);
}
}
-
+
/**
* Generate an absolute URL to the given resource within the current
* plugin directory
@@ -315,6 +326,4 @@ abstract class rcube_plugin
return $this->ID.'.'.$key;
}
-
}
-
diff --git a/program/include/rcube_plugin_api.php b/program/include/rcube_plugin_api.php
index fbf3584e3..be12f11b5 100644
--- a/program/include/rcube_plugin_api.php
+++ b/program/include/rcube_plugin_api.php
@@ -230,6 +230,20 @@ class rcube_plugin_api
'message' => "Invalid callback function for $hook"), true, false);
}
+ /**
+ * Allow a plugin object to unregister a callback.
+ *
+ * @param string $hook Hook name
+ * @param mixed $callback String with global function name or array($obj, 'methodname')
+ */
+ public function unregister_hook($hook, $callback)
+ {
+ $callback_id = array_search($callback, $this->handlers[$hook]);
+ if ($callback_id !== false) {
+ unset($this->handlers[$hook][$callback_id]);
+ }
+ }
+
/**
* Triggers a plugin hook.