From 8b5038befcccc29bdf8ea1f0f5745277e87e072f Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 29 Sep 2014 05:22:38 -0400
Subject: [PATCH] Fix handling of smart list inputs

---
 program/lib/Roundcube/rcube_plugin_api.php |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php
index 335348c..e0b8aea 100644
--- a/program/lib/Roundcube/rcube_plugin_api.php
+++ b/program/lib/Roundcube/rcube_plugin_api.php
@@ -46,7 +46,7 @@
     protected $actionmap = array();
     protected $objectsmap = array();
     protected $template_contents = array();
-    protected $active_hook = false;
+    protected $exec_stack = array();
 
     // Deprecated names of hooks, will be removed after 0.5-stable release
     protected $deprecated_hooks = array(
@@ -170,10 +170,11 @@
      *
      * @param string Plugin name
      * @param boolean Force loading of the plugin even if it doesn't match the filter
+     * @param boolean Require loading of the plugin, error if it doesn't exist
      *
      * @return boolean True on success, false if not loaded or failure
      */
-    public function load_plugin($plugin_name, $force = false)
+    public function load_plugin($plugin_name, $force = false, $require = true)
     {
         static $plugins_dir;
 
@@ -187,8 +188,7 @@
             return true;
         }
 
-        $fn = $plugins_dir . DIRECTORY_SEPARATOR . $plugin_name
-            . DIRECTORY_SEPARATOR . $plugin_name . '.php';
+        $fn = "$plugins_dir/$plugin_name/$plugin_name.php";
 
         if (is_readable($fn)) {
             if (!class_exists($plugin_name, false)) {
@@ -225,7 +225,7 @@
                     true, false);
             }
         }
-        else {
+        elseif ($require) {
             rcube::raise_error(array('code' => 520, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Failed to load plugin file $fn"), true, false);
@@ -278,7 +278,7 @@
       );
 
       $dir = dir($this->dir);
-      $fn = unslashify($dir->path) . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . $plugin_name . '.php';
+      $fn = unslashify($dir->path) . "/$plugin_name/$plugin_name.php";
       $info = false;
 
       if (!class_exists($plugin_name, false)) {
@@ -422,8 +422,10 @@
             $args = array('arg' => $args);
         }
 
+        // TODO: avoid recusion by checking in_array($hook, $this->exec_stack) ?
+
         $args += array('abort' => false);
-        $this->active_hook = $hook;
+        array_push($this->exec_stack, $hook);
 
         foreach ((array)$this->handlers[$hook] as $callback) {
             $ret = call_user_func($callback, $args);
@@ -436,7 +438,7 @@
             }
         }
 
-        $this->active_hook = false;
+        array_pop($this->exec_stack);
         return $args;
     }
 
@@ -572,7 +574,7 @@
      */
     public function is_processing($hook = null)
     {
-        return $this->active_hook && (!$hook || $this->active_hook == $hook);
+        return count($this->exec_stack) > 0 && (!$hook || in_array($hook, $this->exec_stack));
     }
 
     /**

--
Gitblit v1.9.1