From 12e455a324a5a44ca84c3d8939d50484eb9d9ad8 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sat, 30 Jan 2010 19:58:26 -0700 Subject: [PATCH] Convert some singletons to injector usage --- imp/acl.php | 4 +- imp/compose.php | 2 +- imp/folders-mimp.php | 2 +- imp/folders.php | 15 +++--- imp/lib/Accounts.php | 22 -------- imp/lib/Ajax/Application.php | 58 ++++++++-------------- imp/lib/Api.php | 21 +++----- imp/lib/Application.php | 28 +++++------ imp/lib/Block/tree_folders.php | 2 +- imp/lib/Compose.php | 9 ++-- imp/lib/Filter.php | 20 ++++---- imp/lib/Folder.php | 49 ++++-------------- imp/lib/IMP.php | 4 +- imp/lib/Imap/Acl.php | 25 +--------- imp/lib/Imap/Flags.php | 22 -------- imp/lib/Imap/Tree.php | 43 +++------------- imp/lib/Injector/Binder/Imaptree.php | 40 +++++++++++++++ .../LoginTasks/SystemTask/GarbageCollection.php | 3 +- imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php | 2 +- imp/lib/LoginTasks/Task/PurgeSentmail.php | 4 +- imp/lib/LoginTasks/Task/PurgeSpam.php | 6 +-- imp/lib/LoginTasks/Task/PurgeTrash.php | 6 +-- imp/lib/LoginTasks/Task/RenameSentmailMonthly.php | 2 +- imp/lib/Message.php | 29 ++--------- imp/lib/Search.php | 18 +++---- imp/lib/Spam.php | 4 +- imp/lib/Ui/Block.php | 3 +- imp/lib/Ui/Folder.php | 3 +- imp/lib/Ui/Message.php | 3 +- imp/lib/Ui/Search.php | 2 +- imp/lib/Views/Compose.php | 2 +- imp/lib/Views/ListMessages.php | 6 +-- imp/mailbox-mimp.php | 6 +-- imp/mailbox.php | 20 +++----- imp/message-mimp.php | 5 +- imp/message.php | 4 +- imp/rss.php | 3 +- imp/search.php | 2 +- imp/templates/index/index-dimp.inc | 3 +- imp/templates/javascript_defs_dimp.php | 3 +- imp/templates/prefs/accountsmanagement.inc | 3 +- imp/templates/prefs/flagmanagement.inc | 3 +- imp/thread.php | 3 +- 43 files changed, 170 insertions(+), 344 deletions(-) create mode 100644 imp/lib/Injector/Binder/Imaptree.php diff --git a/imp/acl.php b/imp/acl.php index c2eaa8247..d4caf715f 100644 --- a/imp/acl.php +++ b/imp/acl.php @@ -24,7 +24,7 @@ if ($prefs->isLocked('acl') || empty($_SESSION['imp']['acl'])) { } try { - $ACLDriver = IMP_Imap_Acl::singleton(); + $ACLDriver = $injector->getInstance('IMP_Imap_Acl'); } catch (Horde_Exception $e) { $notification->push(_("This server does not support sharing folders."), 'horde.error'); header('Location: ' . $prefs_url); @@ -116,7 +116,7 @@ case 'imp_acl_set': break; } -$imp_folder = IMP_Folder::singleton(); +$imp_folder = $injector->getInstance('IMP_Folder'); $rights = $ACLDriver->getRights(); if (empty($folder)) { diff --git a/imp/compose.php b/imp/compose.php index 6baf98658..caede20fb 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -964,7 +964,7 @@ if ($redirect) { /* Check to make sure the sent-mail folder is created - it needs * to exist to show up in drop-down list. */ - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $injector->getInstance('IMP_Folder'); if (!$imp_folder->exists($sent_mail_folder)) { $imp_folder->create($sent_mail_folder, true); } diff --git a/imp/folders-mimp.php b/imp/folders-mimp.php index 62d1db566..af5c3c47f 100644 --- a/imp/folders-mimp.php +++ b/imp/folders-mimp.php @@ -31,7 +31,7 @@ $subscribe = $prefs->getValue('subscribe'); $showAll = (!$subscribe || $_SESSION['imp']['showunsub']); /* Initialize the IMP_Imap_Tree object. */ -$imptree = IMP_Imap_Tree::singleton(); +$imptree = $injector->getInstance('IMP_Imap_Tree'); $mask = IMP_Imap_Tree::NEXT_SHOWCLOSED; /* Toggle subscribed view, if necessary. */ diff --git a/imp/folders.php b/imp/folders.php index 4cc17cd8d..652bbce02 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -40,10 +40,10 @@ Horde::addInlineScript(array( )); /* Initialize the IMP_Folder object. */ -$imp_folder = IMP_Folder::singleton(); +$imp_folder = $injector->getInstance('IMP_Folder'); /* Initialize the IMP_Imap_Tree object. */ -$imaptree = IMP_Imap_Tree::singleton(); +$imaptree = $injector->getInstance('IMP_Imap_Tree'); /* $folder_list is already encoded in UTF7-IMAP. */ $folder_list = Horde_Util::getFormData('folder_list', array()); @@ -87,8 +87,7 @@ case 'rebuild_tree': case 'expunge_folder': if (!empty($folder_list)) { - $imp_message = IMP_Message::singleton(); - $imp_message->expungeMailbox(array_flip($folder_list)); + $injector->getInstance('IMP_Message')->expungeMailbox(array_flip($folder_list)); } break; @@ -228,16 +227,14 @@ case 'nopoll_folder': case 'folders_empty_mailbox': if (!empty($folder_list)) { - $imp_message = IMP_Message::singleton(); - $imp_message->emptyMailbox($folder_list); + $injector->getInstance('IMP_Message')->emptyMailbox($folder_list); } break; case 'mark_folder_seen': case 'mark_folder_unseen': if (!empty($folder_list)) { - $imp_message = IMP_Message::singleton(); - $imp_message->flagAllInMailbox(array('seen'), $folder_list, ($actionID == 'mark_folder_seen')); + $injector->getInstance('IMP_Message')->flagAllInMailbox(array('seen'), $folder_list, ($actionID == 'mark_folder_seen')); } break; @@ -305,7 +302,7 @@ case 'mbox_size': $loop = array(); $rowct = $sum = 0; - $imp_message = IMP_Message::singleton(); + $imp_message = $injector->getInstance('IMP_Message'); foreach ($folder_list as $val) { $size = $imp_message->sizeMailbox($val, false); diff --git a/imp/lib/Accounts.php b/imp/lib/Accounts.php index eeeca1f44..22f22926c 100644 --- a/imp/lib/Accounts.php +++ b/imp/lib/Accounts.php @@ -14,13 +14,6 @@ class IMP_Accounts { /** - * Singleton instance. - * - * @var IMP_Accounts - */ - static protected $_instance; - - /** * The cached list of accounts. * * @var array @@ -28,21 +21,6 @@ class IMP_Accounts protected $_accounts = null; /** - * Attempts to return a reference to a concrete object instance. - * It will only create a new instance if no instance currently exists. - * - * @return IMP_Accounts The created concrete instance. - */ - static public function singleton() - { - if (!isset(self::$_instance)) { - self::$_instance = new self(); - } - - return self::$_instance; - } - - /** * Save the accounts list to the prefs backend. */ protected function _save() diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index bfbbd8d63..461cde7bf 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -71,15 +71,14 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imptree = IMP_Imap_Tree::singleton(); + $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $imptree->eltDiffStart(); - $imp_folder = IMP_Folder::singleton(); - $new = Horde_String::convertCharset($vars->mbox, Horde_Nls::getCharset(), 'UTF7-IMAP'); try { $new = $imptree->createMailboxName($vars->parent, $new); - if ($result = $imp_folder->create($new, $GLOBALS['prefs']->getValue('subscribe'))) { + + if ($result =$GLOBALS['injector']->getInstance('IMP_Folder')->create($new, $GLOBALS['prefs']->getValue('subscribe'))) { $result = new stdClass; $result->mailbox = $this->_getMailboxResponse($imptree); } @@ -115,7 +114,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imptree = IMP_Imap_Tree::singleton(); + $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $imptree->eltDiffStart(); if ($GLOBALS['imp_search']->isEditableVFolder($vars->mbox)) { @@ -123,8 +122,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base $GLOBALS['imp_search']->deleteSearchQuery($vars->mbox); $result = true; } else { - $imp_folder = IMP_Folder::singleton(); - $result = $imp_folder->delete(array($vars->mbox)); + $result = $GLOBALS['injector']->getInstance('IMP_Folder')->delete(array($vars->mbox)); } if ($result) { @@ -161,18 +159,16 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imptree = IMP_Imap_Tree::singleton(); + $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $imptree->eltDiffStart(); - $imp_folder = IMP_Folder::singleton(); $result = false; try { $new = Horde_String::convertCharset($imptree->createMailboxName($vars->new_parent, $vars->new_name), Horde_Nls::getCharset(), 'UTF7-IMAP'); if (($vars->old_name != $new) && - $imp_folder->rename($vars->old_name, $new)) { - + $GLOBALS['injector']->getInstance('IMP_Folder')->rename($vars->old_name, $new)) { $result = new stdClass; $result->mailbox = $this->_getMailboxResponse($imptree); } @@ -203,8 +199,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imp_message = IMP_Message::singleton(); - $imp_message->emptyMailbox(array($vars->mbox)); + $GLOBALS['injector']->getInstance('IMP_Message')->emptyMailbox(array($vars->mbox)); $result = new stdClass; $result->mbox = $vars->mbox; @@ -239,8 +234,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imp_message = IMP_Message::singleton(); - $result = $imp_message->flagAllInMailbox($flags, array($vars->mbox), $vars->set); + $result = $GLOBALS['injector']->getInstance('IMP_Message')->flagAllInMailbox($flags, array($vars->mbox), $vars->set); if ($result) { $result = new stdClass; @@ -286,7 +280,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base */ public function ListMailboxes($vars) { - $imptree = IMP_Imap_Tree::singleton(); + $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $mask = IMP_Imap_Tree::FLIST_CONTAINER | IMP_Imap_Tree::FLIST_VFOLDER | IMP_Imap_Tree::FLIST_ELT; if ($vars->unsub) { $mask |= IMP_Imap_Tree::FLIST_UNSUB; @@ -359,12 +353,11 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base public function Poll($vars) { $changed = false; - $imptree = IMP_Imap_Tree::singleton(); $result = new stdClass; $result->poll = array(); - foreach ($GLOBALS['imp_imap']->ob()->statusMultiple($imptree->getPollList(), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) { + foreach ($GLOBALS['imp_imap']->ob()->statusMultiple($GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) { $result->poll[$key] = intval($val['unseen']); } @@ -409,7 +402,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base $display_folder = IMP::displayFolder($vars->mbox); - $imptree = IMP_Imap_Tree::singleton(); + $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $result = new stdClass; $result->add = intval($vars->add); @@ -448,7 +441,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); return $vars->sub ? $imp_folder->subscribe(array($vars->mbox)) : $imp_folder->unsubscribe(array($vars->mbox)); @@ -537,8 +530,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imp_message = IMP_Message::singleton(); - $result = $imp_message->copy($vars->mboxto, 'move', $indices); + $result = $GLOBALS['injector']->getInstance('IMP_Message')->copy($vars->mboxto, 'move', $indices); if ($result) { $result = $this->_generateDeleteResult($vars, $indices, $change); @@ -587,9 +579,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imp_message = IMP_Message::singleton(); - - if ($result = $imp_message->copy($vars->mboxto, 'copy', $indices)) { + if ($result = $GLOBALS['injector']->getInstance('IMP_Message')->copy($vars->mboxto, 'copy', $indices)) { if ($poll = $this->_getPollInformation($vars->mboxto)) { $result->poll = array_merge(isset($result->poll) ? $result->poll : array(), $poll); } @@ -626,7 +616,6 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base } $flags = Horde_Serialize::unserialize($vars->flags, Horde_Serialize::JSON); - $imp_message = IMP_Message::singleton(); $result = false; $set = $notset = array(); @@ -639,11 +628,11 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base } if (!empty($set)) { - $result = $imp_message->flag($set, $indices, true); + $result = $GLOBALS['injector']->getInstance('IMP_Message')->flag($set, $indices, true); } if (!empty($notset)) { - $result = $imp_message->flag($notset, $indices, false); + $result = $GLOBALS['injector']->getInstance('IMP_Message')->flag($notset, $indices, false); } return $result @@ -673,10 +662,9 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base return false; } - $imp_message = IMP_Message::singleton(); $change = $this->_changed($vars, true); - if ($imp_message->delete($indices)) { + if ($GLOBALS['injector']->getInstance('IMP_Message')->delete($indices)) { return $this->_generateDeleteResult($vars, $indices, $change, !$GLOBALS['prefs']->getValue('hide_deleted') && !$GLOBALS['prefs']->getValue('use_trash')); } @@ -1031,9 +1019,8 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base $imp_compose->destroy(false); if ($draft_uid = $imp_compose->getMetadata('draft_uid')) { - $imp_message = IMP_Message::singleton(); $idx_array = array($draft_uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)); - $imp_message->delete($idx_array, array('nuke' => true)); + $GLOBALS['injector']->getInstance('IMP_Message')->delete($idx_array, array('nuke' => true)); } return true; @@ -1168,8 +1155,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base $change = ($sort['by'] == Horde_Imap_Client::SORT_THREAD); } - $imp_message = IMP_Message::singleton(); - $expunged = $imp_message->expungeMailbox(array($vars->view => 1), array('list' => true)); + $expunged = $GLOBALS['injector']->getInstance('IMP_Message')->expungeMailbox(array($vars->view => 1), array('list' => true)); if (empty($expunged[$mbox])) { return false; @@ -1446,7 +1432,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base /* Use IMP_Tree to determine whether the sent mail folder was * created. */ - $imptree = IMP_Imap_Tree::singleton(); + $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $imptree->eltDiffStart(); $options = array( @@ -1768,7 +1754,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base */ protected function _getPollInformation($mbox) { - $imptree = IMP_Imap_Tree::singleton(); + $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $elt = $imptree->get($mbox); if (!$imptree->isPolled($elt)) { return array(); diff --git a/imp/lib/Api.php b/imp/lib/Api.php index 6ee4bfbbe..9d0ec8eca 100644 --- a/imp/lib/Api.php +++ b/imp/lib/Api.php @@ -69,8 +69,7 @@ class IMP_Api extends Horde_Registry_Api */ public function folderlist() { - $imp_folder = IMP_Folder::singleton(); - return $imp_folder->flist(); + return $GLOBALS['injector']->getInstance('IMP_Folder')->flist(); } /** @@ -83,9 +82,8 @@ class IMP_Api extends Horde_Registry_Api */ public function createFolder($folder) { - $imp_folder = IMP_Folder::singleton(); $fname = $GLOBALS['imp_imap']->appendNamespace($folder); - return $imp_folder->create($fname, $GLOBALS['prefs']->getValue('subscribe')) + return $GLOBALS['injector']->getInstance('IMP_Folder')->create($fname, $GLOBALS['prefs']->getValue('subscribe')) ? $fname : false; } @@ -101,8 +99,7 @@ class IMP_Api extends Horde_Registry_Api */ public function deleteMessages($mailbox, $indices) { - $imp_message = IMP_Message::singleton(); - return $imp_message->delete(array($mailbox => $indices), array('nuke' => true)); + return $GLOBALS['injector']->getInstance('IMP_Message')->delete(array($mailbox => $indices), array('nuke' => true)); } /** @@ -116,8 +113,7 @@ class IMP_Api extends Horde_Registry_Api */ public function copyMessages($mailbox, $indices, $target) { - $imp_message = IMP_Message::singleton(); - return $imp_message->copy($target, 'copy', array($mailbox => $indices), true); + return $GLOBALS['injector']->getInstance('IMP_Message')->copy($target, 'copy', array($mailbox => $indices), true); } /** @@ -131,8 +127,7 @@ class IMP_Api extends Horde_Registry_Api */ public function moveMessages($mailbox, $indices, $target) { - $imp_message = IMP_Message::singleton(); - return $imp_message->copy($target, 'move', array($mailbox => $indices), true); + return $GLOBALS['injector']->getInstance('IMP_Message')->copy($target, 'move', array($mailbox => $indices), true); } /** @@ -147,8 +142,7 @@ class IMP_Api extends Horde_Registry_Api */ public function flagMessages($mailbox, $indices, $flags, $set) { - $imp_message = IMP_Message::singleton(); - return $imp_message->flag($flags, array($mailbox => $indices), $set); + return $GLOBALS['injector']->getInstance('IMP_Message')->flag($flags, array($mailbox => $indices), $set); } /** @@ -237,8 +231,7 @@ class IMP_Api extends Horde_Registry_Api $opts['mailbox'] = $mailbox; } - $imp_flags = IMP_Imap_Flags::singleton(); - return $imp_flags->getList($opts); + return $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList($opts); } } diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 8f0a4569d..4a6c42655 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -101,6 +101,8 @@ class IMP_Application extends Horde_Registry_Application Horde_Nls::setTimeZone(); } + $GLOBALS['injector']->addBinder('IMP_Imap_Tree', new IMP_Injector_Binder_Imaptree()); + // Initialize global $imp_imap object. $GLOBALS['imp_imap'] = new IMP_Imap(); @@ -195,12 +197,9 @@ class IMP_Application extends Horde_Registry_Application } } - if (($permission == 'max_folders') && empty($opts['value'])) { - $folder = IMP_Folder::singleton(); - $allowed = $allowed > count($folder->flist_IMP(array(), false)); - } - - return $allowed; + return (($permission == 'max_folders') && empty($opts['value'])) + ? $allowed > count($GLOBALS['injector']->getInstance('IMP_Folder')->flist_IMP(array(), false)) + : $allowed; } /* Horde_Auth_Application methods. */ @@ -667,7 +666,7 @@ class IMP_Application extends Horde_Registry_Application } if (!empty($sent_mail_folder)) { - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); if (!$imp_folder->exists($sent_mail_folder)) { $imp_folder->create($sent_mail_folder, $GLOBALS['prefs']->getValue('subscribe')); } @@ -694,8 +693,7 @@ class IMP_Application extends Horde_Registry_Application } else { if (empty($folder) && !empty($new)) { $folder = $GLOBALS['imp_imap']->appendNamespace($new); - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->create($folder, $GLOBALS['prefs']->getValue('subscribe'))) { + if (!$GLOBALS['injector']->getInstance('IMP_Folder')->create($folder, $GLOBALS['prefs']->getValue('subscribe'))) { $folder = null; } } @@ -788,7 +786,7 @@ class IMP_Application extends Horde_Registry_Application */ protected function _prefsFlagManagement() { - $imp_flags = IMP_Imap_Flags::singleton(); + $imp_flags = $GLOBALS['injector']->getInstance('IMP_Imap_Flags'); $action = Horde_Util::getFormData('flag_action'); $data = Horde_Util::getFormData('flag_data'); @@ -858,7 +856,7 @@ class IMP_Application extends Horde_Registry_Application $label = $vars->accounts_server . ':' . $port . ' [' . $vars->accounts_type . ']'; } - $imp_accounts = IMP_Accounts::singleton(); + $imp_accounts = $GLOBALS['injector']->getInstance('IMP_Accounts'); $imp_accounts->addAccount(array( 'label' => $label, 'port' => $port, @@ -874,7 +872,7 @@ class IMP_Application extends Horde_Registry_Application break; case 'delete': - $imp_accounts = IMP_Accounts::singleton(); + $imp_accounts = $GLOBALS['injector']->getInstance('IMP_Accounts'); $tmp = $imp_accounts->getAccount($vars->accounts_data); if ($imp_accounts->deleteAccount($vars->accounts_data)) { $GLOBALS['notification']->push(sprintf(_("Account \"%s\" deleted."), $tmp['server']), 'horde.success'); @@ -1026,10 +1024,8 @@ class IMP_Application extends Horde_Registry_Application */ protected function _mailboxesChanged() { - $imp_folder = IMP_Folder::singleton(); - $imp_folder->clearFlistCache(); - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->init(); + $GLOBALS['injector']->getInstance('IMP_Folder')->clearFlistCache(); + $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->init(); } } diff --git a/imp/lib/Block/tree_folders.php b/imp/lib/Block/tree_folders.php index edd2ac2a9..382684362 100644 --- a/imp/lib/Block/tree_folders.php +++ b/imp/lib/Block/tree_folders.php @@ -47,7 +47,7 @@ class Horde_Block_imp_tree_folders extends Horde_Block $name_url = Horde::applicationUrl('mailbox.php')->add('no_newmail_popup', 1); /* Initialize the IMP_Tree object. */ - $imaptree = IMP_Imap_Tree::singleton(); + $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $mask = IMP_Imap_Tree::NEXT_SHOWCLOSED; if ($GLOBALS['prefs']->getValue('subscribe')) { $mask |= IMP_Imap_Tree::NEXT_SHOWSUB; diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 975f7e80d..388188c38 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -158,8 +158,7 @@ class IMP_Compose !$this->getMetadata('resume')) || ($success && $GLOBALS['prefs']->getValue('auto_delete_drafts'))) && ($uid = $this->getMetadata('draft_uid'))) { - $imp_message = IMP_Message::singleton(); - $imp_message->delete(array($uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)), array('nuke' => true)); + $GLOBALS['injector']->getInstance('IMP_Message')->delete(array($uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)), array('nuke' => true)); } $this->deleteAllAttachments(); @@ -291,7 +290,7 @@ class IMP_Compose throw new IMP_Compose_Exception(_("Saving the draft failed. No draft folder specified.")); } - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); /* Check for access to drafts folder. */ if (!$imp_folder->exists($drafts_mbox) && @@ -594,7 +593,7 @@ class IMP_Compose IMP_Maillog::log($this->_metadata['reply_type'], $this->_metadata['in_reply_to'], $recipients); } - $imp_message = IMP_Message::singleton(); + $imp_message = $GLOBALS['injector']->getInstance('IMP_Message'); $reply_uid = array($this->_metadata['uid'] . IMP::IDX_SEP . $this->_metadata['mailbox']); switch ($this->_metadata['reply_type']) { @@ -651,7 +650,7 @@ class IMP_Compose /* Generate the message string. */ $fcc = $mime_message->toString(array('defserver' => $_SESSION['imp']['maildomain'], 'headers' => $headers, 'stream' => true)); - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); if (!$imp_folder->exists($opts['sent_folder'])) { $imp_folder->create($opts['sent_folder'], $prefs->getValue('subscribe')); diff --git a/imp/lib/Filter.php b/imp/lib/Filter.php index ef6538d5e..6eab2e350 100644 --- a/imp/lib/Filter.php +++ b/imp/lib/Filter.php @@ -57,20 +57,18 @@ class IMP_Filter */ public function blacklistMessage($indices, $show_link = true) { - if ($this->_processBWlist($indices, _("your blacklist"), 'blacklistFrom', 'showBlacklist', $show_link)) { - $imp_message = IMP_Message::singleton(); + if (!$this->_processBWlist($indices, _("your blacklist"), 'blacklistFrom', 'showBlacklist', $show_link) || + !($msg_count = $GLOBALS['injector']->getInstance('IMP_Message')->delete($indices))) { + return false; + } - if (($msg_count = $imp_message->delete($indices))) { - if ($msg_count == 1) { - $GLOBALS['notification']->push(_("The message has been deleted."), 'horde.message'); - } else { - $GLOBALS['notification']->push(_("The messages have been deleted."), 'horde.message'); - } - return true; - } + if ($msg_count == 1) { + $GLOBALS['notification']->push(_("The message has been deleted."), 'horde.message'); + } else { + $GLOBALS['notification']->push(_("The messages have been deleted."), 'horde.message'); } - return false; + return true; } /** diff --git a/imp/lib/Folder.php b/imp/lib/Folder.php index 21571cffc..8d0836197 100644 --- a/imp/lib/Folder.php +++ b/imp/lib/Folder.php @@ -18,13 +18,6 @@ class IMP_Folder { /** - * Singleton instance. - * - * @var IMP_Folder - */ - static protected $_instance = null; - - /** * Keep around identical lists so that we don't hit the server more that * once in the same page for the same thing. * @@ -40,25 +33,9 @@ class IMP_Folder protected $_cacheid = null; /** - * Returns a reference to the global IMP_Folder object, only creating it - * if it doesn't already exist. This ensures that only one IMP_Folder - * instance is instantiated for any given session. - * - * @return IMP_Folder The IMP_Folder instance. - */ - static public function singleton() - { - if (is_null(self::$_instance)) { - self::$_instance = new self(); - } - - return self::$_instance; - } - - /** * Constructor. */ - protected function __construct() + public function __construct() { if (!empty($GLOBALS['conf']['server']['cache_folders'])) { $this->_cacheid = 'imp_folder_cache|' . Horde_Auth::getAuth(); @@ -121,7 +98,7 @@ class IMP_Folder return $this->_listCache[$sig]; } - $imaptree = IMP_Imap_Tree::singleton(); + $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $list_mask = IMP_Imap_Tree::FLIST_CONTAINER | IMP_Imap_Tree::FLIST_OB; if (!$sub) { @@ -198,10 +175,7 @@ class IMP_Folder } if (!empty($deleted)) { - /* Update the IMAP_Tree cache. */ - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->delete($deleted); - + $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->delete($deleted); $this->_onDelete($deleted); } @@ -284,9 +258,8 @@ class IMP_Folder /* Reset the folder cache. */ $this->clearFlistCache(); - /* Update the IMAP_Tree object. */ - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->insert($folder); + /* Update the mailbox tree. */ + $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->insert($folder); /* Recreate Virtual Folders. */ $GLOBALS['imp_search']->initialize(true); @@ -303,7 +276,7 @@ class IMP_Folder */ public function exists($folder) { - $imaptree = IMP_Imap_Tree::singleton(); + $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); $elt = $imaptree->get($folder); if ($elt) { return !$imaptree->isContainer($elt); @@ -344,7 +317,7 @@ class IMP_Folder $deleted = array($old); $inserted = array($new); - $imaptree = IMP_Imap_Tree::singleton(); + $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); /* Get list of any folders that are underneath this one. */ $all_folders = array_merge(array($old), $imaptree->folderList(IMP_Imap_Tree::FLIST_UNSUB, $old)); @@ -405,9 +378,7 @@ class IMP_Folder } if (!empty($subscribed)) { - /* Initialize the IMAP_Tree object. */ - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->subscribe($subscribed); + $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->subscribe($subscribed); /* Reset the folder cache. */ $this->clearFlistCache(); @@ -451,9 +422,7 @@ class IMP_Folder } if (!empty($unsubscribed)) { - /* Initialize the IMAP_Tree object. */ - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->unsubscribe($unsubscribed); + $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->unsubscribe($unsubscribed); /* Reset the folder cache. */ $this->clearFlistCache(); diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 1207b3edd..48ef92efd 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -148,14 +148,12 @@ class IMP */ static public function flistSelect($options = array()) { - $imp_folder = IMP_Folder::singleton(); - /* Don't filter here - since we are going to parse through every * member of the folder list below anyway, we can filter at that time. * This allows us the have a single cached value for the folder list * rather than a cached value for each different mailbox we may * visit. */ - $mailboxes = $imp_folder->flist(); + $mailboxes = $GLOBALS['injector']->getInstance('IMP_Folder')->flist(); $text = ''; if (!empty($options['heading']) && diff --git a/imp/lib/Imap/Acl.php b/imp/lib/Imap/Acl.php index 8d9c88f45..aff704f1a 100644 --- a/imp/lib/Imap/Acl.php +++ b/imp/lib/Imap/Acl.php @@ -13,13 +13,6 @@ class IMP_Imap_Acl { /** - * Singleton instance. - * - * @var IMP_Imap_Acl - */ - static protected $_instance = null; - - /** * Hash containing the list of possible rights and a human readable * description of each. * @@ -36,27 +29,11 @@ class IMP_Imap_Acl protected $_protected; /** - * Attempts to return a reference to a concrete object instance. - * It will only create a new instance if no instance currently exists. - * - * @return IMP_Imap_Acl The created concrete instance. - * @throws Horde_Exception - */ - static public function singleton() - { - if (!self::$_instance) { - self::$_instance = new self(); - } - - return self::$_instance; - } - - /** * Constructor. * * @throws Horde_Exception */ - protected function __construct() + public function __construct() { if ($_SESSION['imp']['protocol'] != 'imap') { throw new Horde_Exception(_("ACL requires an IMAP server.")); diff --git a/imp/lib/Imap/Flags.php b/imp/lib/Imap/Flags.php index 47ba846c2..eeedf95e3 100644 --- a/imp/lib/Imap/Flags.php +++ b/imp/lib/Imap/Flags.php @@ -17,13 +17,6 @@ class IMP_Imap_Flags const PREFIX = 'impflag'; /** - * Singleton instance. - * - * @var IMP_Imap_Flags - */ - static protected $_instance; - - /** * The cached list of flags. * * @var array @@ -31,21 +24,6 @@ class IMP_Imap_Flags protected $_flags = null; /** - * Attempts to return a reference to a concrete object instance. - * It will only create a new instance if no instance currently exists. - * - * @return IMP_Imap_Flags The created concrete instance. - */ - static public function singleton() - { - if (!isset(self::$_instance)) { - self::$_instance = new self(); - } - - return self::$_instance; - } - - /** * Save the flag list to the prefs backend. */ protected function _save() diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index d1bf571a9..cdec50b38 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -64,11 +64,11 @@ class IMP_Imap_Tree const OTHER_KEY = 'other\0'; /** - * Singleton instance + * The cache ID value. * - * @var IMP_Imap_Tree + * @var string */ - static protected $_instance; + public $cacheId; /** * Array containing the mailbox tree. @@ -204,33 +204,9 @@ class IMP_Imap_Tree protected $_eltCache; /** - * Attempts to return a reference to a concrete IMP_Imap_Tree instance. - * - * If an IMP_Imap_Tree object is currently stored in the cache, re-create - * that object. Else, create a new instance. Ensures that only one - * instance is available at any time. - * - * @return IMP_Imap_Tree The object or null. - */ - static public function singleton() - { - if (!isset(self::$_instance)) { - if (!empty($_SESSION['imp']['cache']['tree'])) { - self::$_instance = @unserialize($GLOBALS['injector']->getInstance('Horde_Cache')->get($_SESSION['imp']['cache']['tree'], 86400)); - } - - if (empty(self::$_instance)) { - self::$_instance = new self(); - } - } - - return self::$_instance; - } - - /** * Constructor. */ - protected function __construct() + public function __construct() { if ($_SESSION['imp']['protocol'] == 'imap') { $ns = $GLOBALS['imp_imap']->getNamespaceList(); @@ -241,10 +217,6 @@ class IMP_Imap_Tree : $ns; } - if ($imp_cache = $GLOBALS['injector']->getInstance('Horde_Cache')) { - $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth()); - } - $this->init(); $this->__wakeup(); } @@ -273,9 +245,8 @@ class IMP_Imap_Tree { /* We only need to store the object if using Horde_Cache and the tree * has changed. */ - if (!empty($this->_changed) && - isset($_SESSION['imp']['cache']['tree'])) { - $GLOBALS['injector']->getInstance('Horde_Cache')->set($_SESSION['imp']['cache']['tree'], serialize($this), 86400); + if (!empty($this->_changed) && $this->cacheId) { + $GLOBALS['injector']->getInstance('Horde_Cache')->set($this->cacheId, serialize($this), 86400); } } @@ -1206,8 +1177,8 @@ class IMP_Imap_Tree } $changed = false; + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); - $imp_folder = IMP_Folder::singleton(); $this->getPollList(); foreach ($id as $val) { if (!$this->isSubscribed($this->_tree[$val])) { diff --git a/imp/lib/Injector/Binder/Imaptree.php b/imp/lib/Injector/Binder/Imaptree.php new file mode 100644 index 000000000..e974f8b54 --- /dev/null +++ b/imp/lib/Injector/Binder/Imaptree.php @@ -0,0 +1,40 @@ + + * @package IMP + */ +class IMP_Injector_Binder_Imaptree implements Horde_Injector_Binder +{ + /** + * If an IMP_Imap_Tree object is currently stored in the cache, re-create + * that object. Else, create a new instance. + */ + public function create(Horde_Injector $injector) + { + $cache = $injector->getInstance('Horde_Cache'); + + if (empty($_SESSION['imp']['cache']['tree'])) { + $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth()); + } elseif ($instance = @unserialize($cache->get($_SESSION['imp']['cache']['tree'], 86400))) { + return $instance; + } + + $instance = new IMP_Imap_Tree(); + $instance->cacheId = $_SESSION['imp']['cache']['tree']; + + return $instance; + } + + public function equals(Horde_Injector_Binder $binder) + { + return false; + } + +} diff --git a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php index b70d92900..f9093c0ae 100644 --- a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php +++ b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php @@ -25,8 +25,7 @@ class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_Syste public function execute() { /* Purge non-existent nav_poll entries. */ - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->getPollList(true, true); + $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(true, true); /* Do garbage collection on sentmail entries. */ $sentmail = IMP_Sentmail::factory(); diff --git a/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php b/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php index 892828303..ffe416367 100644 --- a/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php +++ b/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php @@ -35,7 +35,7 @@ class IMP_LoginTasks_Task_DeleteSentmailMonthly extends Horde_LoginTasks_Task old sent-mail folders. Then sort this array according to the date. */ $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp')); - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); $sent_mail_folders = $identity->getAllSentmailFolders(); $folder_array = array(); diff --git a/imp/lib/LoginTasks/Task/PurgeSentmail.php b/imp/lib/LoginTasks/Task/PurgeSentmail.php index 137c16303..37f0fc94e 100644 --- a/imp/lib/LoginTasks/Task/PurgeSentmail.php +++ b/imp/lib/LoginTasks/Task/PurgeSentmail.php @@ -35,8 +35,8 @@ class IMP_LoginTasks_Task_PurgeSentmail extends Horde_LoginTasks_Task */ public function execute() { - $imp_folder = IMP_Folder::singleton(); - $imp_message = IMP_Message::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); + $imp_message = $GLOBALS['injector']->getInstance('IMP_Message'); $mbox_list = $this->_getFolders(); diff --git a/imp/lib/LoginTasks/Task/PurgeSpam.php b/imp/lib/LoginTasks/Task/PurgeSpam.php index eea026c77..5dfe8dda1 100644 --- a/imp/lib/LoginTasks/Task/PurgeSpam.php +++ b/imp/lib/LoginTasks/Task/PurgeSpam.php @@ -41,8 +41,7 @@ class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task } /* Make sure the Spam folder exists. */ - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->exists($spam_folder)) { + if (!$GLOBALS['injector']->getInstance('IMP_Folder')->exists($spam_folder)) { return false; } @@ -60,8 +59,7 @@ class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task } /* Go through the message list and delete the messages. */ - $imp_message = IMP_Message::singleton(); - if ($imp_message->delete(array($spam_folder => $msg_ids), array('nuke' => true))) { + if ($GLOBALS['injector']->getInstance('IMP_Message')->delete(array($spam_folder => $msg_ids), array('nuke' => true))) { $msgcount = count($msg_ids); $GLOBALS['notification']->push(sprintf(ngettext("Purging %d message from Spam folder.", "Purging %d messages from Spam folder.", $msgcount), $msgcount), 'horde.message'); } diff --git a/imp/lib/LoginTasks/Task/PurgeTrash.php b/imp/lib/LoginTasks/Task/PurgeTrash.php index cda5c3711..10b2fbfc6 100644 --- a/imp/lib/LoginTasks/Task/PurgeTrash.php +++ b/imp/lib/LoginTasks/Task/PurgeTrash.php @@ -41,8 +41,7 @@ class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task } /* Make sure the Trash folder exists. */ - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->exists($trash_folder)) { + if (!$GLOBALS['injector']->getInstance('IMP_Folder')->exists($trash_folder)) { return false; } @@ -60,8 +59,7 @@ class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task } /* Go through the message list and delete the messages. */ - $imp_message = IMP_Message::singleton(); - if ($imp_message->delete(array($trash_folder => $msg_ids), array('nuke' => true))) { + if ($GLOBALS['injector']->getInstance('IMP_Message')->delete(array($trash_folder => $msg_ids), array('nuke' => true))) { $msgcount = count($msg_ids); $GLOBALS['notification']->push(sprintf(ngettext("Purging %d message from Trash folder.", "Purging %d messages from Trash folder.", $msgcount), $msgcount), 'horde.message'); } diff --git a/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php b/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php index 2bd62658e..e9cd6e5d6 100644 --- a/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php +++ b/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php @@ -34,7 +34,7 @@ class IMP_LoginTasks_Task_RenameSentmailMonthly extends Horde_LoginTasks_Task $success = true; $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp')); - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); foreach ($identity->getAllSentmailfolders() as $sent_folder) { /* Display a message to the user and rename the folder. diff --git a/imp/lib/Message.php b/imp/lib/Message.php index f54ebdeb6..6f54f6385 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -19,13 +19,6 @@ class IMP_Message { /** - * The singleton IMP_Message instance - * - * @var IMP_Message - */ - protected static $_instance = null; - - /** * Using POP to access mailboxes? * * @var boolean @@ -33,25 +26,9 @@ class IMP_Message protected $_usepop = false; /** - * Returns a reference to the global IMP_Message object, only creating it - * if it doesn't already exist. This ensures that only one IMP_Message - * instance is instantiated for any given session. - * - * @return IMP_Message The IMP_Message instance. - */ - public static function singleton() - { - if (!self::$_instance) { - self::$_instance = new self(); - } - - return self::$_instance; - } - - /** * Constructor. */ - protected function __construct() + public function __construct() { if ($_SESSION['imp']['protocol'] == 'pop') { $this->_usepop = true; @@ -92,7 +69,7 @@ class IMP_Message } if ($new) { - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); if (!$imp_folder->exists($targetMbox) && !$imp_folder->create($targetMbox, $prefs->getValue('subscribe'))) { return false; @@ -197,7 +174,7 @@ class IMP_Message /* Check for Trash folder. */ $use_trash_folder = !$this->_usepop && empty($options['nuke']) && !$use_vtrash && $use_trash; if ($use_trash_folder) { - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); if (!$imp_folder->exists($trash) && !$imp_folder->create($trash, $prefs->getValue('subscribe'))) { diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 0c624ff02..628d225a2 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -118,7 +118,7 @@ class IMP_Search public function initialize($no_vf = false) { if (!$no_vf) { - $imaptree = IMP_Imap_Tree::singleton(); + $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree'); foreach ($this->_getVFolderList() as $key => $val) { if (!empty($val['v']) && !$this->isEditableVFolder($key)) { @@ -227,10 +227,8 @@ class IMP_Search */ public function flagFields() { - $imp_flags = IMP_Imap_Flags::singleton(); - $flist = $imp_flags->getFlagList(null); - $flags = array(); + $flist = $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getFlagList(null); for ($i = 0, $cnt = count($flist['set']); $i < $cnt; ++$i) { $flags[$flist['set'][$i]['f']] = $flist['set'][$i]['l']; @@ -396,8 +394,7 @@ class IMP_Search $this->_saveVFolderList($vfolders); if (!$no_delete) { - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->delete($id); + $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->delete($id); } } } @@ -497,8 +494,7 @@ class IMP_Search $this->_saveVFolderList($vfolders); } - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->insertVFolders(array($id => $label)); + $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->insertVFolders(array($id => $label)); return $id; } @@ -519,8 +515,7 @@ class IMP_Search } /* Create Virtual Trash with new folder list. */ - $imp_folder = IMP_Folder::singleton(); - $fl = $imp_folder->flist(); + $fl = $GLOBALS['injector']->getInstance('IMP_Folder')->flist(); $flist = array('INBOX'); foreach ($fl as $mbox) { if (!empty($mbox['val'])) { @@ -574,8 +569,7 @@ class IMP_Search } /* Create Virtual INBOX with nav_poll list. */ - $imaptree = IMP_Imap_Tree::singleton(); - $flist = $imaptree->getPollList(); + $flist = $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(); $query = new Horde_Imap_Client_Search_Query(); $query->flag('\\seen', false); diff --git a/imp/lib/Spam.php b/imp/lib/Spam.php index 701056ded..cbea196fe 100644 --- a/imp/lib/Spam.php +++ b/imp/lib/Spam.php @@ -180,7 +180,7 @@ class IMP_Spam switch ($action) { case 'spam': if ($result = $GLOBALS['prefs']->getValue('delete_spam_after_report')) { - $imp_message = IMP_Message::singleton(); + $imp_message = $GLOBALS['injector']->getInstance('IMP_Message'); switch ($result) { case 1: $msg_count = $imp_message->delete($indices); @@ -212,7 +212,7 @@ class IMP_Spam case 'notspam': if ($result = $GLOBALS['prefs']->getValue('move_ham_after_report')) { - $imp_message = IMP_Message::singleton(); + $imp_message = $GLOBALS['injector']->getInstance('IMP_Message'); if (!$imp_message->copy('INBOX', 'move', $indices)) { $result = 0; } diff --git a/imp/lib/Ui/Block.php b/imp/lib/Ui/Block.php index c6bf4c090..665198871 100644 --- a/imp/lib/Ui/Block.php +++ b/imp/lib/Ui/Block.php @@ -32,8 +32,7 @@ class IMP_Ui_Block } /* Get list of mailboxes to poll. */ - $imptree = IMP_Imap_Tree::singleton(); - $poll = $imptree->getPollList(true); + $poll = $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->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; diff --git a/imp/lib/Ui/Folder.php b/imp/lib/Ui/Folder.php index eec6742e1..4ffff82bf 100644 --- a/imp/lib/Ui/Folder.php +++ b/imp/lib/Ui/Folder.php @@ -58,12 +58,11 @@ class IMP_Ui_Folder $dir2 = $elt['user_icon'] ? Horde::img($elt['icon'], $elt['alt'], null, $elt['icondir']) : ''; - $imaptree = IMP_Imap_Tree::singleton(); if ($elt['children'] && isset($options['expand_url'])) { $dir = $options['expand_url']->copy()->add('folder', $elt['value']); - if ($imaptree->isOpen($elt['base_elt'])) { + if ($GLOBALS['injector']->getInstance('IMP_Imap_Tree')->isOpen($elt['base_elt'])) { if (!is_null($dir)) { $dir->add('actionID', 'collapse_folder'); $alt = _("Collapse Folder"); diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php index a48eb3f7f..3006815f1 100644 --- a/imp/lib/Ui/Message.php +++ b/imp/lib/Ui/Message.php @@ -119,8 +119,7 @@ class IMP_Ui_Message $success = true; if ($mdn_flag) { - $imp_message = IMP_Message::singleton(); - $imp_message->flag(array('$MDNSent'), $uid . IMP::IDX_SEP . $mailbox, true); + $GLOBALS['injector']->getInstance('IMP_Message')->flag(array('$MDNSent'), $uid . IMP::IDX_SEP . $mailbox, true); } } catch (Horde_Mime_Exception $e) { $success = false; diff --git a/imp/lib/Ui/Search.php b/imp/lib/Ui/Search.php index 254703d0f..af4449163 100644 --- a/imp/lib/Ui/Search.php +++ b/imp/lib/Ui/Search.php @@ -27,7 +27,7 @@ class IMP_Ui_Search $search_array = array(); $search_fields = $GLOBALS['imp_search']->searchFields(); $flag_fields = $GLOBALS['imp_search']->flagFields(); - $imp_flags = IMP_Imap_Flags::singleton(); + $imp_flags = $GLOBALS['injector']->getInstance('IMP_Imap_Flags'); $or_search = false; foreach ($search as $rule) { diff --git a/imp/lib/Views/Compose.php b/imp/lib/Views/Compose.php index b36717332..91fa395bd 100644 --- a/imp/lib/Views/Compose.php +++ b/imp/lib/Views/Compose.php @@ -94,7 +94,7 @@ class IMP_Views_Compose /* Create list for sent-mail selection. */ if (!empty($GLOBALS['conf']['user']['select_sentmail_folder']) && !$GLOBALS['prefs']->isLocked('sent_mail_folder')) { - $imp_folder = IMP_Folder::singleton(); + $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); /* Check to make sure the sent-mail folders are created - they * need to exist to show up in drop-down list. */ diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index ef15ea8d4..2783d6309 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -133,8 +133,7 @@ class IMP_Views_ListMessages * is a chance that the mailbox doesn't exist. If there is at least * 1 message, we don't need this check. */ if (empty($msgcount) && !$is_search) { - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->exists($mbox)) { + if (!$GLOBALS['injector']->getInstance('IMP_Folder')->exists($mbox)) { $GLOBALS['notification']->push(sprintf(_("Mailbox %s does not exist."), IMP::getLabel($mbox)), 'horde.error'); } @@ -374,8 +373,7 @@ class IMP_Views_ListMessages } } - $imp_flags = IMP_Imap_Flags::singleton(); - $flag_parse = $imp_flags->parse(array( + $flag_parse = $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->parse(array( 'atc' => isset($ob['structure']) ? $ob['structure'] : null, 'flags' => $ob['flags'], 'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to']), diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php index b14cd7156..924716feb 100644 --- a/imp/mailbox-mimp.php +++ b/imp/mailbox-mimp.php @@ -44,8 +44,7 @@ case 'm': // 'e' = expunge mailbox case 'e': if (!$readonly) { - $imp_message = IMP_Message::singleton(); - $imp_message->expungeMailbox(array($imp_mbox['mailbox'] => 1)); + $injector->getInstance('IMP_Message')->expungeMailbox(array($imp_mbox['mailbox'] => 1)); } break; @@ -138,8 +137,7 @@ while (list(,$ob) = each($mbox_info['overview'])) { } /* Get flag information. */ - $imp_flags = IMP_Imap_Flags::singleton(); - $flag_parse = $imp_flags->parse(array( + $flag_parse = $injector->getInstance('IMP_Imap_Flags')->parse(array( 'flags' => $ob['flags'], 'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to']), 'priority' => $ob['headers'] diff --git a/imp/mailbox.php b/imp/mailbox.php index 8272ba3e0..53273bc81 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -73,7 +73,7 @@ if (!is_array(($indices = Horde_Util::getFormData('indices')))) { } $do_filter = false; -$imp_flags = IMP_Imap_Flags::singleton(); +$imp_flags = $injector->getInstance('IMP_Imap_Flags'); $open_compose_window = null; /* Run through the action handlers */ @@ -140,29 +140,26 @@ case 'fwd_digest': case 'delete_messages': if (!empty($indices)) { - $imp_message = IMP_Message::singleton(); - $imp_message->delete($indices); + $injector->getInstance('IMP_Message')->delete($indices); } break; case 'undelete_messages': if (!empty($indices)) { - $imp_message = IMP_Message::singleton(); - $imp_message->undelete($indices); + $injector->getInstance('IMP_Message')->undelete($indices); } break; case 'move_messages': case 'copy_messages': if (!empty($indices) && !empty($targetMbox)) { - $imp_message = IMP_Message::singleton(); if (!empty($newMbox) && ($newMbox == 1)) { $targetMbox = IMP::folderPref($targetMbox, true); $newMbox = true; } else { $newMbox = false; } - $imp_message->copy($targetMbox, ($actionID == 'move_messages') ? 'move' : 'copy', $indices, $newMbox); + $injector->getInstance('IMP_Message')->copy($targetMbox, ($actionID == 'move_messages') ? 'move' : 'copy', $indices, $newMbox); } break; @@ -170,8 +167,7 @@ case 'flag_messages': $flag = Horde_Util::getPost('flag'); if ($flag && !empty($indices)) { $flag = $imp_flags->parseFormId($flag); - $imp_message = IMP_Message::singleton(); - $imp_message->flag(array($flag['flag']), $indices, $flag['set']); + $injector->getInstance('IMP_Message')->flag(array($flag['flag']), $indices, $flag['set']); } break; @@ -181,8 +177,7 @@ case 'hide_deleted': break; case 'expunge_mailbox': - $imp_message = IMP_Message::singleton(); - $imp_message->expungeMailbox(array($imp_mbox['mailbox'] => 1)); + $injector->getInstance('IMP_Message')->expungeMailbox(array($imp_mbox['mailbox'] => 1)); break; case 'filter': @@ -190,8 +185,7 @@ case 'filter': break; case 'empty_mailbox': - $imp_message = IMP_Message::singleton(); - $imp_message->emptyMailbox(array($imp_mbox['mailbox'])); + $injector->getInstance('IMP_Message')->emptyMailbox(array($imp_mbox['mailbox'])); break; case 'view_messages': diff --git a/imp/message-mimp.php b/imp/message-mimp.php index 1ac7677de..66bac71da 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -28,7 +28,7 @@ if (!$imp_mailbox->isValidIndex(false)) { exit; } -$imp_message = IMP_Message::singleton(); +$imp_message = $injector->getInstance('IMP_Message'); $imp_hdr_ui = new IMP_Ui_Headers(); $imp_ui = new IMP_Ui_Message(); @@ -220,8 +220,7 @@ if (!empty($msgAddresses)) { } } -$imp_flags = IMP_Imap_Flags::singleton(); -$flag_parse = $imp_flags->parse(array( +$flag_parse = $injector->getInstance('IMP_Imap_Flags')->parse(array( 'flags' => $flags, 'personal' => $match_identity )); diff --git a/imp/message.php b/imp/message.php index b2af2ee94..9aea21ddf 100644 --- a/imp/message.php +++ b/imp/message.php @@ -38,7 +38,7 @@ if (!$imp_mailbox->isValidIndex(false)) { } /* Initialize IMP_Message object. */ -$imp_message = IMP_Message::singleton(); +$imp_message = $injector->getInstance('IMP_Message'); /* Initialize the user's identities. */ $user_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp')); @@ -67,7 +67,7 @@ $mailbox_name = $index_array['mailbox']; $uid = $index_array['uid']; $indices_array = array($mailbox_name => array($uid)); -$imp_flags = IMP_Imap_Flags::singleton(); +$imp_flags = $injector->getInstance('IMP_Imap_Flags'); $imp_hdr_ui = new IMP_Ui_Headers(); $imp_ui = new IMP_Ui_Message(); diff --git a/imp/rss.php b/imp/rss.php index dcadcd6da..71a69d64c 100644 --- a/imp/rss.php +++ b/imp/rss.php @@ -35,8 +35,7 @@ if (!empty($request)) { $mailbox = $imp_imap->appendNamespace(preg_replace('/\//', $ns_info['delimiter'], trim($request_parts[0], '/'))); /* Make sure mailbox exists or else exit immediately. */ - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->exists($mailbox)) { + if (!$injector->getInstance('IMP_Folder')->exists($mailbox)) { exit; } } diff --git a/imp/search.php b/imp/search.php index c44acb77c..8c4ef4dc0 100644 --- a/imp/search.php +++ b/imp/search.php @@ -86,7 +86,7 @@ if (!empty($criteria)) { } /* Generate master folder list. */ -$imp_imap_tree = IMP_Imap_Tree::singleton(); +$imp_imap_tree = $injector->getInstance('IMP_Imap_Tree'); $mask = IMP_Imap_Tree::NEXT_SHOWCLOSED; $subscribe = $prefs->getValue('subscribe'); if ($subscribe || !Horde_Util::getFormData('show_unsub')) { diff --git a/imp/templates/index/index-dimp.inc b/imp/templates/index/index-dimp.inc index 33fadda6a..9da8d6bd0 100644 --- a/imp/templates/index/index-dimp.inc +++ b/imp/templates/index/index-dimp.inc @@ -18,8 +18,7 @@ $has_whitelist = $registry->hasMethod('mail/whitelistFrom'); $show_quota = (isset($_SESSION['imp']['quota']) && is_array($_SESSION['imp']['quota'])); // Get the list of available IMAP flags -$imp_flags = IMP_Imap_Flags::singleton(); -$flag_list = $imp_flags->getList(array('imap' => true)); +$flag_list = $injector->getInstance('IMP_Imap_Flags')->getList(array('imap' => true)); function _simpleButton($id, $text, $image, $nodisplay = false) { diff --git a/imp/templates/javascript_defs_dimp.php b/imp/templates/javascript_defs_dimp.php index 3ef144058..970c7938e 100644 --- a/imp/templates/javascript_defs_dimp.php +++ b/imp/templates/javascript_defs_dimp.php @@ -27,8 +27,7 @@ foreach ($dimp_block_list as $block) { } /* Generate flag array. */ -$imp_flags = IMP_Imap_Flags::singleton(); -foreach ($imp_flags->getList(array('fgcolor' => true)) as $val) { +foreach ($GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList(array('fgcolor' => true)) as $val) { $flags[$val['flag']] = array_filter(array( 'b' => isset($val['b']) ? $val['b'] : null, 'c' => $val['c'], diff --git a/imp/templates/prefs/accountsmanagement.inc b/imp/templates/prefs/accountsmanagement.inc index b24817ab9..05eb85cad 100644 --- a/imp/templates/prefs/accountsmanagement.inc +++ b/imp/templates/prefs/accountsmanagement.inc @@ -50,8 +50,7 @@ " /> getList(); +$accounts_list = $GLOBALS['injector']->getInstance('IMP_Accounts')->getList(); $delete_img = Horde::img('delete.png'); ?> diff --git a/imp/templates/prefs/flagmanagement.inc b/imp/templates/prefs/flagmanagement.inc index e70da8dcd..4c9518b79 100644 --- a/imp/templates/prefs/flagmanagement.inc +++ b/imp/templates/prefs/flagmanagement.inc @@ -1,7 +1,6 @@ getList(array('div' => true, 'fgcolor' => true)); +$flaglist = $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList(array('div' => true, 'fgcolor' => true)); /* Get the graphics. */ $picker_img = Horde::img('colorpicker.png', _("Color Picker"), '', $registry->getImageDir('horde')); diff --git a/imp/thread.php b/imp/thread.php index 1a49e88cb..bb5520de8 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -136,8 +136,7 @@ foreach ($loop_array as $mbox => $idxlist) { } /* Flag messages as seen. */ -$imp_message = IMP_Message::singleton(); -$imp_message->flag(array('\\seen'), $loop_array); +$injector->getInstance('IMP_Message')->flag(array('\\seen'), $loop_array); $template = $injector->createInstance('Horde_Template'); $template->setOption('gettext', true); -- 2.11.0