From: Michael M Slusarz Date: Thu, 21 Jan 2010 18:20:27 +0000 (-0700) Subject: Add hook to allow for easy definition of additional AJAX actions X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=eeb4f50a298246d1b9114aee6792d430b4fc805a;p=horde.git Add hook to allow for easy definition of additional AJAX actions --- diff --git a/framework/Ajax/lib/Horde/Ajax/Application/Base.php b/framework/Ajax/lib/Horde/Ajax/Application/Base.php index 6ed882d84..86b926542 100644 --- a/framework/Ajax/lib/Horde/Ajax/Application/Base.php +++ b/framework/Ajax/lib/Horde/Ajax/Application/Base.php @@ -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.'); } diff --git a/horde/config/hooks.php.dist b/horde/config/hooks.php.dist index c4f2eabf6..7034bdfd2 100644 --- a/horde/config/hooks.php.dist +++ b/horde/config/hooks.php.dist @@ -115,6 +115,26 @@ * 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$ diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index d0db740d0..fb9e90c56 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -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 index 000000000..d1eed4377 --- /dev/null +++ b/kronolith/config/hooks.php.dist @@ -0,0 +1,35 @@ +