Consolidate composeLink() functions
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 2 Mar 2009 19:43:29 +0000 (12:43 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 2 Mar 2009 19:43:29 +0000 (12:43 -0700)
imp/lib/DIMP.php
imp/lib/IMP.php
imp/lib/api.php

index 4ae929f..dab0afc 100644 (file)
@@ -492,31 +492,4 @@ class DIMP
         return array();
     }
 
-    /**
-     * Returns the appropriate link to call the message composition screen.
-     *
-     * @param mixed $args   List of arguments to pass to compose.php. If this
-     *                      is passed in as a string, it will be parsed as a
-     *                      toaddress?subject=foo&cc=ccaddress (mailto-style)
-     *                      string.
-     * @param array $extra  Hash of extra, non-standard arguments to pass to
-     *                      compose.php.
-     *
-     * @return string  The link to the message composition screen.
-     */
-    static public function composeLink($args = array(), $extra = array())
-    {
-        // IE 6 & 7 handles window.open() URL param strings differently if
-        // triggered via an href or an onclick.  Since we have no hint
-        // at this point where this link will be used, we have to always
-        // encode the params and explicitly call rawurlencode() in
-        // compose.php.
-        $args = IMP::composeLinkArgs($args, $extra);
-        $encode_args = array('popup' => 1);
-        foreach ($args as $k => $v) {
-            $encode_args[$k] = rawurlencode($v);
-        }
-        return 'javascript:void(window.open(\'' . Util::addParameter(Horde::applicationUrl('compose-dimp.php'), $encode_args, null, false) . '\', \'\', \'width=820,height=610,status=1,scrollbars=yes,resizable=yes\'));';
-    }
-
 }
index 3a2197b..c809714 100644 (file)
@@ -410,15 +410,33 @@ class IMP
      *                      string.
      * @param array $extra  Hash of extra, non-standard arguments to pass to
      *                      compose.php.
+     * @param string $view  The IMP view to create a link for.
      *
      * @return string  The link to the message composition screen.
      */
-    static public function composeLink($args = array(), $extra = array())
+    static public function composeLink($args = array(), $extra = array(),
+                                       $view = null)
     {
         $args = self::composeLinkArgs($args, $extra);
-        $is_mimp = ($_SESSION['imp']['view'] == 'mimp');
 
-        if (!$is_mimp &&
+        if (is_null($view)) {
+            $view = $_SESSION['imp']['view'];
+        }
+
+        if ($view == 'dimp') {
+            // IE 6 & 7 handles window.open() URL param strings differently if
+            // triggered via an href or an onclick.  Since we have no hint
+            // at this point where this link will be used, we have to always
+            // encode the params and explicitly call rawurlencode() in
+            // compose.php.
+            $encode_args = array('popup' => 1);
+            foreach ($args as $k => $v) {
+                $encode_args[$k] = rawurlencode($v);
+            }
+            return 'javascript:void(window.open(\'' . Util::addParameter(Horde::applicationUrl('compose-dimp.php'), $encode_args, null, false) . '\', \'\', \'width=820,height=610,status=1,scrollbars=yes,resizable=yes\'));';
+        }
+
+        if (($view != 'mimp') &&
             $GLOBALS['prefs']->getValue('compose_popup') &&
             $GLOBALS['browser']->hasFeature('javascript')) {
             Horde::addScriptFile('prototype.js', 'horde', true);
@@ -427,9 +445,9 @@ class IMP
                 $args['to'] = addcslashes($args['to'], '\\"');
             }
             return "javascript:" . self::popupIMPString('compose.php', $args);
-        } else {
-            return Util::addParameter(Horde::applicationUrl($is_mimp ? 'compose-mimp.php' : 'compose.php'), $args);
         }
+
+        return Util::addParameter(Horde::applicationUrl(($view == 'mimp') ? 'compose-mimp.php' : 'compose.php'), $args);
     }
 
     /**
index 6166af1..ffbe676 100644 (file)
@@ -205,9 +205,7 @@ function _imp_batchCompose($args = array(), $extra = array())
 
     $links = array();
     foreach ($args as $i => $arg) {
-        $links[$i] = ($_SESSION['imp']['view'] == 'dimp')
-            ? DIMP::composeLink($arg, !empty($extra[$i]) ? $extra[$i] : array())
-            : IMP::composeLink($arg, !empty($extra[$i]) ? $extra[$i] : array());
+        $links[$i] = IMP::composeLink($arg, !empty($extra[$i]) ? $extra[$i] : array());
     }
 
     return $links;