From 7fc86fd4b01e44a934ac5afd01c04555a76a680f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 1 Oct 2010 11:13:19 -0600 Subject: [PATCH] IMP_Compose implements Countable (returns number of attachments) --- imp/compose.php | 6 +++--- imp/lib/Compose.php | 29 +++++++++++++++-------------- imp/lib/Dimp.php | 2 +- imp/lib/Views/Compose.php | 3 +-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/imp/compose.php b/imp/compose.php index 98aa99f3c..1a4430c8b 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -609,7 +609,7 @@ $cancel_url = ''; if ($isPopup) { /* If the attachments cache is not empty, we must reload this page * and delete the attachments. */ - if ($imp_compose->numberOfAttachments()) { + if (count($imp_compose)) { $cancel_url = Horde::selfUrl()->setRaw(true)->add(array( 'actionID' => 'cancel_compose', 'composeCache' => $composeCacheID, @@ -619,7 +619,7 @@ if ($isPopup) { } else { /* If the attachments cache is not empty, we must reload this page and delete the attachments. */ - if ($imp_compose->numberOfAttachments()) { + if (count($imp_compose)) { $cancel_url = $imp_ui->mailboxReturnUrl(Horde::selfUrl()->setRaw(true))->add(array( 'actionID' => 'cancel_compose', 'composeCache' => $composeCacheID @@ -1021,7 +1021,7 @@ if ($redirect) { $t->set('attach_options', $attach_options); } - $t->set('numberattach', $imp_compose->numberOfAttachments()); + $t->set('numberattach', count($imp_compose)); if ($t->get('numberattach')) { $atc = array(); $v = $injector->getInstance('Horde_Mime_Viewer'); diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 81405305f..15b30a4ac 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -13,7 +13,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Compose +class IMP_Compose implements Countable { /* The virtual path to use for VFS data. */ const VFS_ATTACH_PATH = '.horde/imp/compose'; @@ -632,7 +632,6 @@ class IMP_Compose $imp_message->flag(array('\\answered'), $reply_uid); $imp_message->flag(array('\\flagged'), $reply_uid, false); break; - } } @@ -1115,7 +1114,7 @@ class IMP_Compose /* Add attachments now. */ $attach_flag = true; - if (empty($options['noattach']) && $this->numberOfAttachments()) { + if (empty($options['noattach']) && count($this)) { if (($this->_linkAttach && $GLOBALS['conf']['compose']['link_attachments']) || !empty($GLOBALS['conf']['compose']['link_all_attachments'])) { @@ -2139,16 +2138,6 @@ class IMP_Compose } /** - * Returns the number of attachments currently in this message. - * - * @return integer The number of attachments in this message. - */ - public function numberOfAttachments() - { - return count($this->_cache); - } - - /** * Returns the size of the attachments in bytes. * * @return integer The size of the attachments (in bytes). @@ -2301,7 +2290,7 @@ class IMP_Compose public function additionalAttachmentsAllowed() { return empty($GLOBALS['conf']['compose']['attach_count_limit']) || - ($GLOBALS['conf']['compose']['attach_count_limit'] - $this->numberOfAttachments()); + ($GLOBALS['conf']['compose']['attach_count_limit'] - count($this)); } /** @@ -2908,4 +2897,16 @@ class IMP_Compose return $search; } + /* Countable methods. */ + + /** + * Returns the number of attachments currently in this message. + * + * @return integer The number of attachments in this message. + */ + public function count() + { + return count($this->_cache); + } + } diff --git a/imp/lib/Dimp.php b/imp/lib/Dimp.php index 01a2cd564..888423e3c 100644 --- a/imp/lib/Dimp.php +++ b/imp/lib/Dimp.php @@ -109,7 +109,7 @@ class IMP_Dimp { $fwd_list = array(); - if ($imp_compose->numberOfAttachments()) { + if (count($imp_compose)) { foreach ($imp_compose->getAttachments() as $atc_num => $data) { $mime = $data['part']; diff --git a/imp/lib/Views/Compose.php b/imp/lib/Views/Compose.php index 07b050fd0..3130c47a6 100644 --- a/imp/lib/Views/Compose.php +++ b/imp/lib/Views/Compose.php @@ -58,8 +58,7 @@ class IMP_Views_Compose $imp_ui = $injector->getInstance('IMP_Ui_Compose'); $result['js'] = array_merge($result['js'], $imp_ui->identityJs()); - if ($t->get('composeCache') && - $imp_compose->numberOfAttachments()) { + if ($t->get('composeCache') && count($imp_compose)) { foreach ($imp_compose->getAttachments() as $num => $atc) { $mime = $atc['part']; $opts = Horde_Serialize::serialize(array( -- 2.11.0