summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube
diff options
context:
space:
mode:
authorcorbosman <cor@xs4all.net>2015-01-06 21:48:39 +0100
committercorbosman <cor@xs4all.net>2015-02-04 13:17:51 +0100
commitde89d46be24f6b3454a0c0e62973af947b22ff29 (patch)
treeba1faa661c200a91c281b80614b2745fc79f8b83 /program/lib/Roundcube
parentfe653e312206f57b0937193d8f7be46518a619d2 (diff)
Load plugins before sessions have started
Move the plugin loading phase to before sessions have started allowing plugins to add session drivers. Plugins that want to use this should define an "onload" method in their plugins. This method does not have access to variables like $task as they are not yet initialised at that time.
Diffstat (limited to 'program/lib/Roundcube')
-rw-r--r--program/lib/Roundcube/rcube_plugin_api.php45
1 files changed, 38 insertions, 7 deletions
diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php
index c74162619..ba5dffefd 100644
--- a/program/lib/Roundcube/rcube_plugin_api.php
+++ b/program/lib/Roundcube/rcube_plugin_api.php
@@ -34,6 +34,8 @@ class rcube_plugin_api
public $dir;
public $url = 'plugins/';
public $task = '';
+ public $initialized = false;
+
public $output;
public $handlers = array();
public $allowed_prefs = array();
@@ -117,12 +119,20 @@ class rcube_plugin_api
{
$this->task = $task;
$this->output = $app->output;
-
// register an internal hook
$this->register_hook('template_container', array($this, 'template_container_hook'));
-
// maybe also register a shudown function which triggers
// shutdown functions of all plugin objects
+
+ foreach ($this->plugins as $plugin) {
+ // ... task, request type and framed mode
+ if (!$this->filter($plugin)) {
+ $plugin->init();
+ }
+ }
+
+ // we have finished initializing all plugins
+ $this->initialized = true;
}
/**
@@ -203,14 +213,22 @@ class rcube_plugin_api
// check inheritance...
if (is_subclass_of($plugin, 'rcube_plugin')) {
// ... task, request type and framed mode
- if (($force || !$plugin->task || preg_match('/^('.$plugin->task.')$/i', $this->task))
- && (!$plugin->noajax || (is_object($this->output) && $this->output->type == 'html'))
- && (!$plugin->noframe || empty($_REQUEST['_framed']))
- ) {
+
+ // call onload method on plugin if it exists.
+ // this is useful if you want to be called early in the boot process
+ if (method_exists($plugin, 'onload')) {
+ $plugin->onload();
+ }
+
+ // init a plugin only if $force is set or if we're called after initialization
+ if (($force || $this->initialized)
+ && !$this->filter($plugin))
+ {
$plugin->init();
- $this->plugins[$plugin_name] = $plugin;
}
+ $this->plugins[$plugin_name] = $plugin;
+
if (!empty($plugin->allowed_prefs)) {
$this->allowed_prefs = array_merge($this->allowed_prefs, $plugin->allowed_prefs);
}
@@ -235,6 +253,19 @@ class rcube_plugin_api
}
/**
+ * check if we should prevent this plugin from initialising
+ *
+ * @param $plugin
+ * @return bool
+ */
+ private function filter($plugin)
+ {
+ return (($plugin->noajax && !(is_object($this->output) && $this->output->type == 'html') )
+ || ($plugin->task && !preg_match('/^('.$plugin->task.')$/i', $this->task))
+ || ($plugin->noframe && !empty($_REQUEST['_framed']))) ? true : false;
+ }
+
+ /**
* Get information about a specific plugin.
* This is either provided my a plugin's info() method or extracted from a package.xml or a composer.json file
*