From 727dbedf976187d37ac36a524c58a77cd13f3d0f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 23 Dec 2009 22:15:07 -0700 Subject: [PATCH] Add IMP::newmailAlerts() --- imp/folders.php | 11 +---- imp/lib/Block/summary.php | 11 ++--- imp/lib/IMP.php | 109 +++++++++++++++++++++++++++------------------- imp/mailbox.php | 10 +---- 4 files changed, 71 insertions(+), 70 deletions(-) diff --git a/imp/folders.php b/imp/folders.php index fc34674bb..8a7705ba7 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -418,15 +418,7 @@ if (!empty($newmsgs)) { $imp_imap->ob()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE); } - if ($prefs->getValue('nav_popup')) { - Horde::addInlineScript(( - IMP::getNewMessagePopup($newmsgs) - ), 'dom'); - } - - if (($sound = $prefs->getValue('nav_audio'))) { - $notification->push($registry->getImageDir() . '/audio/' . $sound, 'audio'); - } + IMP::newmailAlerts($newmsgs); } /* Get the tree images. */ @@ -490,5 +482,4 @@ if (count($rows) > 10) { /* No need for extra template - close out the tags here. */ echo ''; -$notification->notify(array('listeners' => 'audio')); require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/imp/lib/Block/summary.php b/imp/lib/Block/summary.php index 6ea08a7d0..cfed2bc66 100644 --- a/imp/lib/Block/summary.php +++ b/imp/lib/Block/summary.php @@ -110,14 +110,9 @@ class Horde_Block_imp_summary extends Horde_Block $GLOBALS['imp_imap']->ob()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE); } - if ($prefs->getValue('nav_popup')) { - $html .= Horde_Util::bufferOutput(Horde::addInlineScript((IMP::getNewMessagePopup($newmsgs)), 'dom')); - } - - if (($sound = $prefs->getValue('nav_audio'))) { - $notification->push($registry->getImageDir() . - '/audio/' . $sound, 'audio'); - $html .= Horde_Util::bufferOutput(array($notification, 'notify'), array('listeners' => 'audio')); + if ($prefs->getValue('nav_audio') || $prefs->getValue('nav_popup')) { + $html .= Horde_Util::bufferOutput(IMP::newmailAlerts($newmsgs)) . + Horde_Util::bufferOutput(array($notification, 'notify'), array('listeners' => 'audio')); } } elseif (!empty($this->_params['show_unread'])) { if (count($folders) == 0) { diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index dc8447885..1707745d2 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -638,50 +638,6 @@ class IMP } /** - * Outputs the necessary javascript code to display the new mail - * notification message. - * - * @param mixed $var Either an associative array with mailbox names as - * the keys and the message count as the values or - * an integer indicating the number of new messages - * in the current mailbox. - * - * @return string The javascript for the popup message. - */ - static public function getNewMessagePopup($var) - { - $t = new Horde_Template(); - $t->setOption('gettext', true); - if (is_array($var)) { - if (empty($var)) { - return; - } - $folders = array(); - foreach ($var as $mb => $nm) { - $folders[] = array( - 'url' => self::generateIMPUrl('mailbox.php', $mb)->add('no_newmail_popup', 1), - 'name' => htmlspecialchars(self::displayFolder($mb)), - 'new' => (int)$nm, - ); - } - $t->set('folders', $folders); - - if (($_SESSION['imp']['protocol'] != 'pop') && - $GLOBALS['prefs']->getValue('use_vinbox') && - ($vinbox_id = $GLOBALS['prefs']->getValue('vinbox_id'))) { - $t->set('vinbox', Horde::link(self::generateIMPUrl('mailbox.php', $GLOBALS['imp_search']->createSearchID($vinbox_id))->add('no_newmail_popup', 1))); - } - } else { - $t->set('msg', ($var == 1) ? _("You have 1 new message.") : sprintf(_("You have %s new messages."), $var)); - } - $t_html = str_replace("\n", ' ', $t->fetch(IMP_TEMPLATES . '/newmsg/alert.html')); - - Horde::addScriptFile('effects.js', 'horde'); - Horde::addScriptFile('redbox.js', 'horde'); - return 'RedBox.overlay = false; RedBox.showHtml(\'' . addcslashes($t_html, "'/") . '\');'; - } - - /** * Get message indices list. * * @param mixed $indices The following inputs are allowed: @@ -1183,4 +1139,69 @@ class IMP } } + /** + * Output configured alerts for newmail. + * + * @param mixed $var Either an associative array with mailbox names as + * the keys and the message count as the values or + * an integer indicating the number of new messages + * in the current mailbox. + * + * @param integer $msgs The number of new messages. + */ + static public function newmailAlerts($var) + { + if ($GLOBALS['prefs']->getValue('nav_popup')) { + Horde::addInlineScript(array( + self::_getNewMessagePopup($var) + ), 'dom'); + } + + if ($sound = $GLOBALS['prefs']->getValue('nav_audio')) { + $GLOBALS['notification']->push($GLOBALS['registry']->getImageDir() . '/audio/' . $sound, 'audio'); + } + } + + /** + * Outputs the necessary javascript code to display the new mail + * notification message. + * + * @param mixed $var See self::newmailAlerts(). + * + * @return string The javascript for the popup message. + */ + static protected function _getNewMessagePopup($var) + { + $t = new Horde_Template(); + $t->setOption('gettext', true); + if (is_array($var)) { + if (empty($var)) { + return; + } + $folders = array(); + foreach ($var as $mb => $nm) { + $folders[] = array( + 'url' => self::generateIMPUrl('mailbox.php', $mb)->add('no_newmail_popup', 1), + 'name' => htmlspecialchars(self::displayFolder($mb)), + 'new' => (int)$nm, + ); + } + $t->set('folders', $folders); + + if (($_SESSION['imp']['protocol'] != 'pop') && + $GLOBALS['prefs']->getValue('use_vinbox') && + ($vinbox_id = $GLOBALS['prefs']->getValue('vinbox_id'))) { + $t->set('vinbox', Horde::link(self::generateIMPUrl('mailbox.php', $GLOBALS['imp_search']->createSearchID($vinbox_id))->add('no_newmail_popup', 1))); + } + } else { + $t->set('msg', ($var == 1) ? _("You have 1 new message.") : sprintf(_("You have %s new messages."), $var)); + } + $t_html = str_replace("\n", ' ', $t->fetch(IMP_TEMPLATES . '/newmsg/alert.html')); + + Horde::addScriptFile('effects.js', 'horde'); + Horde::addScriptFile('redbox.js', 'horde'); + return 'RedBox.overlay = false; RedBox.showHtml(\'' . addcslashes($t_html, "'/") . '\');'; + } + + } diff --git a/imp/mailbox.php b/imp/mailbox.php index 3cb328ad7..3d900fce8 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -391,14 +391,8 @@ if (!empty($newmsgs)) { $imp_imap->ob()->openMailbox($imp_mbox['mailbox'], Horde_Imap_Client::OPEN_READWRITE); if (!Horde_Util::getFormData('no_newmail_popup')) { - /* Newmail audio. */ - if (($sound = $prefs->getValue('nav_audio'))) { - $notification->push($registry->getImageDir() . '/audio/' . $sound, 'audio'); - } - /* Newmail alert. */ - if ($prefs->getValue('nav_popup')) { - Horde::addInlineScript(IMP::getNewMessagePopup($newmsgs), 'dom'); - } + /* Newmail alerts. */ + IMP::newmailAlerts($newmsgs); } } -- 2.11.0