From 5f67e6287071e73f6bb5249f27032b8d3798aacf Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 28 May 2009 05:56:22 -0600 Subject: [PATCH] Abstract this code out --- imp/lib/Imap/Flags.php | 29 +++++++++++++++++++++++++++++ imp/mailbox.php | 24 +++--------------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/imp/lib/Imap/Flags.php b/imp/lib/Imap/Flags.php index 3959995dc..21b710c2f 100644 --- a/imp/lib/Imap/Flags.php +++ b/imp/lib/Imap/Flags.php @@ -349,6 +349,35 @@ class IMP_Imap_Flags } /** + * Get the list of set/unset actions for use in dropdown lists. + * + * @param string $mbox The current mailbox. + * + * @return array An array with 2 elements: 'set' and 'unset'. + */ + public function getFlagList($mbox) + { + $ret = array('set' => array(), 'unset' => array()); + + foreach ($this->getList(array('imap' => true, 'mailbox' => $mbox)) as $val) { + $tmp = array( + 'f' => $val['flag'], + 'l' => $val['l'] + ); + + /* Check for 'opposite' flag actions. */ + $act1 = isset($val['n']) ? 'unset' : 'set'; + $act2 = ($act1 == 'set') ? 'unset' : 'set'; + + $ret[$act1][] = $tmp; + $tmp['f'] = '0' . $val['flag']; + $ret[$act2][] = $tmp; + } + + return $ret; + } + + /** * Output a DIV element to display the icon. * * @param string $c A classname. diff --git a/imp/mailbox.php b/imp/mailbox.php index 3ddc7717d..8b3f84e0c 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -505,27 +505,9 @@ if ($pageOb['msgcount']) { $n_template->set('use_pop', $_SESSION['imp']['protocol'] == 'pop'); if (!$n_template->get('use_pop')) { - $flaglist_set = $flaglist_unset = array(); - foreach ($imp_flags->getList(array('imap' => true, 'mailbox' => $search_mbox ? null : $imp_mbox['mailbox'])) as $val) { - $tmp = array( - 'f' => $val['flag'], - 'l' => $val['l'] - ); - - /* These entries are 'opposite' flag actions. */ - if (isset($val['n'])) { - $flaglist_unset[] = $tmp; - $tmp['f'] = '0' . $val['flag']; - $flaglist_set[] = $tmp; - } else { - $flaglist_set[] = $tmp; - $tmp['f'] = '0' . $val['flag']; - $flaglist_unset[] = $tmp; - } - } - - $n_template->set('flaglist_set', $flaglist_set); - $n_template->set('flaglist_unset', $flaglist_unset); + $tmp = $imp_flags->getFlagList($search_mbox ? null : $imp_mbox['mailbox']); + $n_template->set('flaglist_set', $tmp['set']); + $n_template->set('flaglist_unset', $tmp['unset']); if ($n_template->get('use_folders')) { $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget moveAction', '', '', _("Move"), true)); -- 2.11.0