From 75ab5eafc12c62ea3f04305c7733723a8792df21 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 2 Mar 2009 12:43:29 -0700 Subject: [PATCH] Consolidate composeLink() functions --- imp/lib/DIMP.php | 27 --------------------------- imp/lib/IMP.php | 28 +++++++++++++++++++++++----- imp/lib/api.php | 4 +--- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/imp/lib/DIMP.php b/imp/lib/DIMP.php index 4ae929f86..dab0afc6c 100644 --- a/imp/lib/DIMP.php +++ b/imp/lib/DIMP.php @@ -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\'));'; - } - } diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 3a2197bde..c809714f5 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -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); } /** diff --git a/imp/lib/api.php b/imp/lib/api.php index 6166af1de..ffbe676ca 100644 --- a/imp/lib/api.php +++ b/imp/lib/api.php @@ -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; -- 2.11.0