From 9b55b8e1d072028d9c354791460db3f3e5442729 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 26 Jan 2010 13:09:28 -0700 Subject: [PATCH] Improvements to folder summary blocks. Consolidate duplicate code. Use LIST-STATUS output, if available. --- imp/lib/Block/Foldersummary.php | 57 ++-------------------- imp/lib/Block/summary.php | 80 +++++-------------------------- imp/lib/Ui/Block.php | 103 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 123 deletions(-) create mode 100644 imp/lib/Ui/Block.php diff --git a/imp/lib/Block/Foldersummary.php b/imp/lib/Block/Foldersummary.php index 352d2bf9c..743841c46 100644 --- a/imp/lib/Block/Foldersummary.php +++ b/imp/lib/Block/Foldersummary.php @@ -14,61 +14,10 @@ class IMP_Block_Foldersummary extends Horde_Block protected function _content() { - /* Filter on INBOX display, if requested. */ - if ($GLOBALS['prefs']->getValue('filter_on_display')) { - $imp_filter = new IMP_Filter(); - $imp_filter->filter('INBOX'); - } + $imp_ui = new IMP_Ui_Block(); + list($html,) = $imp_ui->folderSummary('dimp'); - /* Get list of mailboxes to poll. */ - $imptree = IMP_Imap_Tree::singleton(); - $folders = $imptree->getPollList(true); - - $anyUnseen = false; - $newmsgs = array(); - $html = ''; - - foreach ($folders as $folder) { - if (($folder == 'INBOX') || - ($_SESSION['imp']['protocol'] != 'pop')) { - $info = $imptree->getElementInfo($folder); - if (!empty($info)) { - if (empty($this->_params['show_unread']) || - !empty($info['unseen'])) { - if (!empty($info['newmsg'])) { - $newmsgs[$folder] = $info['newmsg']; - } - $html .= ''; - } - } - } - } - - $html .= '
'; - if (!empty($info['unseen'])) { - $html .= ''; - $anyUnseen = true; - } - $html .= '' . IMP::displayFolder($folder) . ''; - if (!empty($info['unseen'])) { - $html .= ''; - } - $html .= '' . - (!empty($info['unseen']) ? '' . $info['unseen'] . '' : '0') . - (!empty($this->_params['show_total']) ? '(' . $info['messages'] . ')' : '') . - '
'; - - if (count($newmsgs) == 0 && !empty($this->_params['show_unread'])) { - if (count($folders) == 0) { - $html = _("No folders are being checked for new mail."); - } elseif (!$anyUnseen) { - $html = '' . _("No folders with unseen messages") . ''; - } elseif ($GLOBALS['prefs']->getValue('nav_popup')) { - $html = '' . _("No folders with new messages") . ''; - } - } - - return $html; + return '' . $html . '
'; } } diff --git a/imp/lib/Block/summary.php b/imp/lib/Block/summary.php index 2cefa9a02..de9bf08df 100644 --- a/imp/lib/Block/summary.php +++ b/imp/lib/Block/summary.php @@ -33,92 +33,34 @@ class Horde_Block_imp_summary extends Horde_Block protected function _content() { - global $notification, $prefs, $registry; + $imp_ui = new IMP_Ui_Block(); + list($html_out, $newmsgs) = $imp_ui->folderSummary('imp'); $html = ''; - /* Filter on INBOX display, if requested. */ - if ($prefs->getValue('filter_on_display')) { - $imp_filter = new IMP_Filter(); - $imp_filter->filter('INBOX'); - } - - /* Get list of mailboxes to poll. */ - $imaptree = IMP_Imap_Tree::singleton(); - $folders = $imaptree->getPollList(true); - /* Quota info, if available. */ $quota_msg = Horde_Util::bufferOutput(array('IMP', 'quota')); if (!empty($quota_msg)) { $html .= ''; } - $anyUnseen = false; - $mbox_url = Horde::applicationUrl('mailbox.php', true); - $newmsgs = array(); - - foreach ($folders as $folder) { - if (($folder == 'INBOX') || - ($_SESSION['imp']['protocol'] != 'pop')) { - $info = $imaptree->getElementInfo($folder); - if (!empty($info)) { - if (empty($this->_params['show_unread']) || - !empty($info['unseen'])) { - if (!empty($info['recent'])) { - $newmsgs[$folder] = $info['recent']; - } - $url = $mbox_url->copy()->add(array('no_newmail_popup' => 1, 'mailbox' => $folder)); - $html .= ''; - } - } - } - } - - $html .= '
' . $quota_msg . '
'; - if (!empty($info['unseen'])) { - $html .= ''; - $anyUnseen = true; - } - $html .= Horde::link($url) . IMP::displayFolder($folder) . ''; - if (!empty($info['unseen'])) { - $html .= ''; - } - $html .= '' . - (!empty($info['unseen']) ? '' . $info['unseen'] . '' : '0') . - (!empty($this->_params['show_total']) ? '(' . $info['messages'] . ')' : '') . - '
'; - /* Check to see if user wants new mail notification, but only * if the user is logged into IMP. */ - if ($prefs->getValue('nav_popup')) { - // Always include these scripts so they'll be there if - // there's new mail in later dynamic updates. + if ($GLOBALS['prefs']->getValue('nav_popup')) { + /* Always include these scripts so they'll be there if there's + * new mail in later dynamic updates. */ Horde::addScriptFile('effects.js', 'horde'); Horde::addScriptFile('redbox.js', 'horde'); } - if (!empty($newmsgs)) { - /* Open the mailbox R/W to ensure the 'recent' flags are cleared - * from the current mailbox. */ - foreach ($newmsgs as $mbox => $nm) { - $GLOBALS['imp_imap']->ob()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE); - } - - 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) { - $html .= _("No folders are being checked for new mail."); - } elseif (!$anyUnseen) { - $html .= '' . _("No folders with unseen messages") . ''; - } elseif ($prefs->getValue('nav_popup')) { - $html .= '' . _("No folders with new messages") . ''; - } + if (!empty($newmsgs) && + ($GLOBALS['prefs']->getValue('nav_audio') || + $GLOBALS['prefs']->getValue('nav_popup'))) { + $html .= Horde_Util::bufferOutput(IMP::newmailAlerts($newmsgs)) . + Horde_Util::bufferOutput(array($GLOBALS['notification'], 'notify'), array('listeners' => 'audio')); } - return $html; + return $html . $html_out . ''; } } diff --git a/imp/lib/Ui/Block.php b/imp/lib/Ui/Block.php new file mode 100644 index 000000000..b408d7117 --- /dev/null +++ b/imp/lib/Ui/Block.php @@ -0,0 +1,103 @@ + + * @package IMP + */ +class IMP_Ui_Block +{ + /** + * Render folder summary information. + * + * @param string $mode Either 'dimp' or 'imp' - defines how links are + * generated. + * + * @return array The HTML code and an array with mailboxes containing new + * messages as the keys and the number of recent messages + * as the values. + */ + public function folderSummary($mode) + { + /* Filter on INBOX display, if requested. */ + if ($GLOBALS['prefs']->getValue('filter_on_display')) { + $imp_filter = new IMP_Filter(); + $imp_filter->filter('INBOX'); + } + + /* Get list of mailboxes to poll. */ + $imptree = IMP_Imap_Tree::singleton(); + $poll = $imptree->getPollList(true); + $status = $GLOBALS['imp_imap']->ob()->statusMultiple($poll, Horde_Imap_Client::STATUS_UNSEEN | Horde_Imap_Client::STATUS_MESSAGES | Horde_Imap_Client::STATUS_RECENT); + + $anyUnseen = false; + $html = ''; + $newmsgs = array(); + + if ($mode == 'imp') { + $mbox_url = Horde::applicationUrl('mailbox.php', true); + } + + foreach ($poll as $folder) { + if (isset($status[$folder]) && + (($folder == 'INBOX') || + ($_SESSION['imp']['protocol'] != 'pop')) && + (empty($this->_params['show_unread']) || + !empty($status[$folder]['unseen']))) { + if (!empty($status[$folder]['recent'])) { + $newmsgs[$folder] = $status[$folder]['recent']; + } + + if ($mode == 'imp') { + $onclick = 'self.location=\'' . $mbox_url->copy()->add(array('no_newmail_popup' => 1, 'mailbox' => $folder)) . '\''; + } else { + $onclick = 'DimpBase.go(\'folder:' . htmlspecialchars($folder) . '\');return false;'; + } + + $html .= ''; + + if (!empty($status[$folder]['unseen'])) { + $html .= ''; + $anyUnseen = true; + } + + $html .= (($mode == 'imp') ? Horde::link($url) : '') . IMP::displayFolder($folder) . ''; + + if (!empty($status[$folder]['unseen'])) { + $html .= ''; + } + $html .= '' . + (!empty($status[$folder]['unseen']) ? '' . $status[$folder]['unseen'] . '' : '0') . + (!empty($this->_params['show_total']) ? '(' . $status[$folder]['messages'] . ')' : '') . + ''; + } + } + + $html .= ''; + + if (!empty($newmsgs)) { + /* Open the mailbox R/W to ensure the 'recent' flags are cleared + * from the current mailbox. */ + foreach ($newmsgs as $mbox => $nm) { + $GLOBALS['imp_imap']->ob()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE); + } + } elseif (!empty($this->_params['show_unread'])) { + if (count($folders) == 0) { + $html = _("No folders are being checked for new mail."); + } elseif (!$anyUnseen) { + $html = '' . _("No folders with unseen messages") . ''; + } elseif ($GLOBALS['prefs']->getValue('nav_popup')) { + $html = '' . _("No folders with new messages") . ''; + } + } + + return array($html, $newmsgs); + } + +} -- 2.11.0