Allow a callback function to be defined for this filter.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 17 Aug 2010 04:18:53 +0000 (22:18 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 17 Aug 2010 04:25:53 +0000 (22:25 -0600)
framework/Core/lib/Horde/Core/Text/Filter/Emails.php

index 065b807..2de2747 100644 (file)
@@ -25,12 +25,16 @@ class Horde_Core_Text_Filter_Emails extends Horde_Text_Filter_Emails
      *                 Only if no mail/compose registry API method exists
      *                 otherwise.
      *                 DEFAULT: false
+     * callback - (callback) Use this callback instead of the mail/compose
+     *            API call.
+     *            DEFAULT: Use mail/compose API call.
      * </pre>
      */
     public function __construct(array $params = array())
     {
         $this->_params = array_merge(array(
-            'always_mailto' => false
+            'always_mailto' => false,
+            'callback' => null
         ), $this->_params, $params);
 
         parent::__construct($params);
@@ -46,7 +50,8 @@ class Horde_Core_Text_Filter_Emails extends Horde_Text_Filter_Emails
     protected function _regexCallback($matches)
     {
         if ($this->_params['always_mailto'] ||
-            !$GLOBALS['registry']->hasMethod('mail/compose')) {
+            (!$this->_params['callback'] &&
+             !$GLOBALS['registry']->hasMethod('mail/compose'))) {
             return parent::_regexCallback($matches);
         }
 
@@ -62,7 +67,9 @@ class Horde_Core_Text_Filter_Emails extends Horde_Text_Filter_Emails
 
         parse_str($args, $extra);
         try {
-            $url = strval($GLOBALS['registry']->call('mail/compose', array(array('to' => $email), $extra)));
+            $url = $this->_params['callback']
+                ? strval(call_user_func($this->_params['callback'], array('to' => $email), $extra))
+                : strval($GLOBALS['registry']->call('mail/compose', array(array('to' => $email), $extra)));
         } catch (Horde_Exception $e) {
             return parent::_regexCallback($matches);
         }