+
+
+ /**
+ * Load the specified plugin
+ *
+ * @param string Plugin name
+ * @return boolean True on success, false if not loaded or failure
+ */
+ public function load_plugin($plugin_name)
+ {
+ static $plugins_dir;
+
+ $rcmail = rcmail::get_instance();
+
+ if (!$plugins_dir) {
+ $dir = dir($this->dir);
+ $plugins_dir = unslashify($dir->path);
+ }
+
+ // plugin already loaded
+ if ($this->plugins[$plugin_name] || class_exists($plugin_name, false))
+ return true;
+
+ $fn = $plugins_dir . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . $plugin_name . '.php';
+
+ if (file_exists($fn)) {
+ include($fn);
+
+ // instantiate class if exists
+ if (class_exists($plugin_name, false)) {
+ $plugin = new $plugin_name($this);
+ // check inheritance...
+ if (is_subclass_of($plugin, 'rcube_plugin')) {
+ // ... task, request type and framed mode
+ if ((!$plugin->task || preg_match('/^('.$plugin->task.')$/i', $rcmail->task))
+ && (!$plugin->noajax || (is_object($rcmail->output) && is_a($rcmail->output, 'rcube_template')))
+ && (!$plugin->noframe || empty($_REQUEST['_framed']))
+ ) {
+ $plugin->init();
+ $this->plugins[$plugin_name] = $plugin;
+ }
+ return true;
+ }
+ }
+ else {
+ raise_error(array('code' => 520, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "No plugin class $plugin_name found in $fn"), true, false);
+ }
+ }
+ else {
+ raise_error(array('code' => 520, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Failed to load plugin file $fn"), true, false);
+ }
+
+ return false;
+ }
+
+