Add IMP::newmailAlerts()
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 24 Dec 2009 05:15:07 +0000 (22:15 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 24 Dec 2009 05:31:47 +0000 (22:31 -0700)
imp/folders.php
imp/lib/Block/summary.php
imp/lib/IMP.php
imp/mailbox.php

index fc34674..8a7705b 100644 (file)
@@ -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 '</form></div>';
 
-$notification->notify(array('listeners' => 'audio'));
 require $registry->get('templates', 'horde') . '/common-footer.inc';
index 6ea08a7..cfed2bc 100644 (file)
@@ -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) {
index dc84478..1707745 100644 (file)
@@ -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, "'/") . '\');';
+    }
+
+
 }
index 3cb328a..3d900fc 100644 (file)
@@ -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);
     }
 }