Add hook to allow for easy definition of additional AJAX actions
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 21 Jan 2010 18:20:27 +0000 (11:20 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 21 Jan 2010 18:20:27 +0000 (11:20 -0700)
framework/Ajax/lib/Horde/Ajax/Application/Base.php
horde/config/hooks.php.dist
imp/config/hooks.php.dist
kronolith/config/hooks.php.dist [new file with mode: 0644]
shout/config/hooks.php.dist [new file with mode: 0644]

index 6ed882d..86b9265 100644 (file)
@@ -65,10 +65,18 @@ abstract class Horde_Ajax_Application_Base
             return false;
         }
 
+        $vars = Horde_Variables::getDefaultVariables();
+
         if (method_exists($this, $this->_action)) {
-            return call_user_func(array($this, $this->_action), Horde_Variables::getDefaultVariables());
+            return call_user_func(array($this, $this->_action), $vars);
         }
 
+        /* Look for hook in application. */
+        try {
+            return Horde::callHook('ajaxaction', array($this->_action, $vars), $this->_app);
+        } catch (Horde_Exception_HookNotSet $e) {
+        } catch (Horde_Ajax_Exception $e) {}
+
         throw new Horde_Ajax_Exception('Handler for action "' . $this->_action . '" does not exist.');
     }
 
index c4f2eab..7034bdf 100644 (file)
  * This hook is used to do any local processing necessary to initialize an
  * application. It is passed no parameters and expects no return value.
  *
+ *
+ * AJAX Hooks
+ * ==========
+ * These are hookos that are available in any application that has an AJAX
+ * interface configured.
+ *
+ * ajaxaction
+ * ----------
+ * This hook is used to add user-defined AJAX action handlers to an
+ * application.
+ *
+ * Parameters in:
+ *   $action (string): The AJAX action.
+ *   $vars (Horde_Variables): The URL parameters.
+ *
+ * The return value from this hook is as follows:
+ *   [throw Horde_Ajax_Exception] - Fatal error.
+ *   [mixed] - The data to send to the browser (will be JSON encoded).
+ *
+ *
  * TODO: groupldap, share_add, share_modify, share_remove
  *
  * $Id$
index d0db740..fb9e90c 100644 (file)
@@ -106,6 +106,25 @@ class IMP_Hooks
 //    }
 
     /**
+     * AJAX HOOK: Add user-defined AJAX action handlers.
+     *
+     * @param string $action         The AJAX action.
+     * @param Horde_Variables $vars  The URL parameters.
+     *
+     * @return mixed  The data to send to the browser (will be JSON encoded).
+     * @throws Horde_Ajax_Exception
+     */
+//     function ajaxaction($action, $vars)
+//     {
+//        switch ($action) {
+//        case 'Foo':
+//            return 'bar';
+//        }
+//
+//        throw new Horde_Ajax_Exception('Unknown action');
+//     }
+
+    /**
      * Perform an action after a message has been sent successfully.
      *
      * @param Horde_Mime_Part $message  The message content object.
diff --git a/kronolith/config/hooks.php.dist b/kronolith/config/hooks.php.dist
new file mode 100644 (file)
index 0000000..d1eed43
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Kronolith Hooks configuration file.
+ *
+ * THE HOOKS PROVIDED IN THIS FILE ARE EXAMPLES ONLY.  DO NOT ENABLE THEM
+ * BLINDLY IF YOU DO NOT KNOW WHAT YOU ARE DOING.  YOU HAVE TO CUSTOMIZE THEM
+ * TO MATCH YOUR SPECIFIC NEEDS AND SYSTEM ENVIRONMENT.
+ *
+ * For more information please see the horde/config/hooks.php.dist file.
+ *
+ * $Id$
+ */
+
+class Kronolith_Hooks
+{
+    /**
+     * AJAX HOOK: Add user-defined AJAX action handlers.
+     *
+     * @param string $action         The AJAX action.
+     * @param Horde_Variables $vars  The URL parameters.
+     *
+     * @return mixed  The data to send to the browser (will be JSON encoded).
+     * @throws Horde_Ajax_Exception
+     */
+//     function ajaxaction($action, $vars)
+//     {
+//        switch ($action) {
+//        case 'Foo':
+//            return 'bar';
+//        }
+//
+//        throw new Horde_Ajax_Exception('Unknown action');
+//     }
+
+}
diff --git a/shout/config/hooks.php.dist b/shout/config/hooks.php.dist
new file mode 100644 (file)
index 0000000..a78bae8
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Shout Hooks configuration file.
+ *
+ * THE HOOKS PROVIDED IN THIS FILE ARE EXAMPLES ONLY.  DO NOT ENABLE THEM
+ * BLINDLY IF YOU DO NOT KNOW WHAT YOU ARE DOING.  YOU HAVE TO CUSTOMIZE THEM
+ * TO MATCH YOUR SPECIFIC NEEDS AND SYSTEM ENVIRONMENT.
+ *
+ * For more information please see the horde/config/hooks.php.dist file.
+ *
+ * $Id$
+ */
+
+class Kronolith_Hooks
+{
+    /**
+     * AJAX HOOK: Add user-defined AJAX action handlers.
+     *
+     * @param string $action         The AJAX action.
+     * @param Horde_Variables $vars  The URL parameters.
+     *
+     * @return mixed  The data to send to the browser (will be JSON encoded).
+     * @throws Horde_Ajax_Exception
+     */
+//     function ajaxaction($action, $vars)
+//     {
+//        switch ($action) {
+//        case 'Foo':
+//            return 'bar';
+//        }
+//
+//        throw new Horde_Ajax_Exception('Unknown action');
+//     }
+
+}