From: Michael M Slusarz Date: Tue, 28 Jul 2009 06:47:18 +0000 (-0600) Subject: Some cleanup of search code X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=72654a9e31292a7255490835e1c3a61705b2551c;p=horde.git Some cleanup of search code --- diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index 0801e80c6..e6c391b7a 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -475,7 +475,7 @@ class IMP_Auth $conf['cookie']['domain']); /* Set up search information for the session. */ - $GLOBALS['imp_search']->sessionSetup(); + $GLOBALS['imp_search']->initialize(); /* If the user wants to run filters on login, make sure they get run. */ diff --git a/imp/lib/Folder.php b/imp/lib/Folder.php index b453bcd07..cfd168a4c 100644 --- a/imp/lib/Folder.php +++ b/imp/lib/Folder.php @@ -217,7 +217,7 @@ class IMP_Folder $this->clearFlistCache(); /* Recreate Virtual Folders. */ - $GLOBALS['imp_search']->sessionSetup(true); + $GLOBALS['imp_search']->initialize(true); /* Clear the folder from the sort prefs. */ foreach ($deleted as $val) { @@ -287,7 +287,7 @@ class IMP_Folder $imaptree->insert($folder); /* Recreate Virtual Folders. */ - $GLOBALS['imp_search']->sessionSetup(true); + $GLOBALS['imp_search']->initialize(true); return true; } diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 44c421603..cf0ddc6fa 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -231,7 +231,7 @@ class IMP /* Add the list of virtual folders to the list. */ if (!empty($options['inc_vfolder'])) { - $vfolders = $GLOBALS['imp_search']->listQueries(true); + $vfolders = $GLOBALS['imp_search']->listQueries(IMP_Search::LIST_VFOLDER); if (!empty($vfolders)) { $vfolder_sel = $GLOBALS['imp_search']->searchMboxID(); $text .= '' . "\n"; diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index 5bdcd5cee..e1697c049 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -486,7 +486,7 @@ class IMP_Imap_Tree $this->insert($this->_getList($this->_showunsub)); /* Add virtual folders to the tree. */ - $this->insertVFolders($GLOBALS['imp_search']->listQueries(true)); + $this->insertVFolders($GLOBALS['imp_search']->listQueries(IMP_Search::LIST_VFOLDER)); } /** diff --git a/imp/lib/Search.php b/imp/lib/Search.php index e58b906f4..7b2f6f6a0 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -51,6 +51,10 @@ class IMP_Search /* The mailbox search prefix. */ const MBOX_PREFIX = 'impsearch\0'; + /* Bitmask constants for listQueries(). */ + const LIST_SEARCH = 1; + const LIST_VFOLDER = 2; + /** * The ID of the current search query in use. * @@ -77,7 +81,7 @@ class IMP_Search * * @param array $params Available parameters: *
-     * 'id'  --  The ID of the search query in use.
+     * 'id' - (string) The ID of the search query in use.
      * 
*/ public function __construct($params = array()) @@ -88,11 +92,11 @@ class IMP_Search } /** - * Set up IMP_Search variables for the current session. + * Initialize the class. * * @param boolean $no_vf Don't readd the Virtual Folders. */ - public function sessionSetup($no_vf = false) + public function initialize($no_vf = false) { if (!$no_vf) { $imaptree = IMP_Imap_Tree::singleton(); @@ -283,9 +287,7 @@ class IMP_Search $vfolder = $GLOBALS['prefs']->getValue('vfolder'); if (!empty($vfolder)) { - $old_error = error_reporting(0); - $vfolder = unserialize($vfolder); - error_reporting($old_error); + $vfolder = @unserialize($vfolder); } if (empty($vfolder) || !is_array($vfolder)) { @@ -305,6 +307,7 @@ class IMP_Search protected function _saveVFolderList($vfolder) { $GLOBALS['prefs']->setValue('vfolder', serialize($vfolder)); + unset(self::$_vfolder); } /** @@ -354,13 +357,12 @@ class IMP_Search /* Create Virtual Trash with new folder list. */ $imp_folder = IMP_Folder::singleton(); $fl = $imp_folder->flist(); - $flist = array(); + $flist = array('INBOX'); foreach ($fl as $mbox) { if (!empty($mbox['val'])) { $flist[] = $mbox['val']; } } - array_unshift($flist, 'INBOX'); $query = new Horde_Imap_Client_Search_Query(); $query->flag('\\deleted', true); @@ -397,9 +399,6 @@ class IMP_Search */ public function createVINBOXFolder() { - /* Initialize IMP_Imap_Tree. */ - $imaptree = IMP_Imap_Tree::singleton(); - /* Delete the current Virtual Inbox folder, if it exists. */ $vinbox_id = $GLOBALS['prefs']->getValue('vinbox_id'); if (!empty($vinbox_id)) { @@ -412,6 +411,7 @@ class IMP_Search /* Create Virtual INBOX with nav_poll list. Filter out any nav_poll * entries that don't exist. Sort the list also. */ + $imaptree = IMP_Imap_Tree::singleton(); $flist = $imaptree->getPollList(true, true); $query = new Horde_Imap_Client_Search_Query(); @@ -461,29 +461,44 @@ class IMP_Search } /** - * Return a list of IDs and query labels, sorted by the label. + * Return a list of queryies. * - * @param boolean $vfolder If true, only return Virtual Folders? + * @param integer $mask A bitmask of the query types to return. + * IMP_Search::LIST_SEARCH and/or + * IMP_Search::LIST_VFOLDER. + * @param boolean $label If true, returns the label. Otherwise, returns + * a textual representation. * * @return array An array with the folder IDs as the key and the labels * as the value. */ - public function listQueries($vfolder = false) + public function listQueries($mask = null, $label = true) { - $vfolders = array(); + $folders = array(); if (empty($_SESSION['imp']['search'])) { - return $vfolders; + return $folders; + } + + if (is_null($mask)) { + $mask = self::LIST_SEARCH | self::LIST_VFOLDER; } foreach ($_SESSION['imp']['search'] as $key => $val) { - if (!$vfolder || !empty($val['vfolder'])) { - $vfolders[$key] = $this->getLabel($key); + if ((($mask & self::LIST_VFOLDER) && !empty($val['vfolder'])) || + (($mask & self::LIST_SEARCH) && empty($val['vfolder']))) { + $vfolders[$key] = $label + ? $this->getLabel($key) + : $this->searchQueryText($key); } } - natcasesort($vfolders); - return $vfolders; + if ($label) { + natcasesort($folders); + return $folders; + } + + return array_reverse($folders, true); } /** @@ -503,31 +518,6 @@ class IMP_Search } /** - * Return a list of search queries valid only for the current session - * (i.e. no virtual folders). - * - * @return array Keys are the search ids, values are a textual - * description of the search. - */ - public function getSearchQueries() - { - $retarray = array(); - - if (empty($_SESSION['imp']['search'])) { - return $retarray; - } - - foreach ($_SESSION['imp']['search'] as $key => $val) { - if (!$this->isVFolder($key) && - ($text = $this->searchQueryText($key))) { - $retarray[$key] = $text; - } - } - - return array_reverse($retarray, true); - } - - /** * Return search query text representation for a given search ID. * * @param string $id The search query id to use (by default, will use diff --git a/imp/lib/api.php b/imp/lib/api.php index ba3fcdfcb..3d8b7f068 100644 --- a/imp/lib/api.php +++ b/imp/lib/api.php @@ -546,7 +546,7 @@ function _imp_changeLanguage() $imp_folder->clearFlistCache(); $imaptree = IMP_Imap_Tree::singleton(); $imaptree->init(); - $GLOBALS['imp_search']->sessionSetup(true); + $GLOBALS['imp_search']->initialize(true); } /** diff --git a/imp/lib/prefs.php b/imp/lib/prefs.php index 0a17348d3..6b0eef3e7 100644 --- a/imp/lib/prefs.php +++ b/imp/lib/prefs.php @@ -215,7 +215,7 @@ function prefs_callback() if ($prefs->isDirty('use_vtrash') || $prefs->isDirty('use_vinbox')) { $imp_search = new IMP_Search(); - $imp_search->sessionSetup(true); + $imp_search->initialize(true); } if ($prefs->isDirty('subscribe') || $prefs->isDirty('tree_view')) { diff --git a/imp/search.php b/imp/search.php index fb0b8a895..48040b3a0 100644 --- a/imp/search.php +++ b/imp/search.php @@ -172,7 +172,7 @@ $t->set('label_or', Horde::label('search_match_or', _("Match Any Query"))); $t->set('match_and', ($search['match'] == null) || ($search['match'] == 'and')); $t->set('label_and', Horde::label('search_match_and', _("Match All Queries"))); -$saved_searches = $imp_search->getSearchQueries(); +$saved_searches = $imp_search->listQueries(IMP_Search::LIST_SEARCH, false); if (!empty($saved_searches)) { $ss = array(); foreach ($saved_searches as $key => $val) {