From d010e1c4130cd1de967d92539b519e3d4be71c52 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 7 Apr 2010 08:32:02 -0600 Subject: [PATCH] Move addressbook param code back to the applications --- framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php | 21 ++++++++++------- imp/lib/Prefs/Ui.php | 6 ++++- kronolith/contacts.php | 6 ++--- kronolith/lib/Ajax/Imple/ContactAutoCompleter.php | 12 ++-------- kronolith/lib/Application.php | 6 ++++- kronolith/lib/Kronolith.php | 23 +++++++++++++++++++ whups/lib/Ajax/Imple/ContactAutoCompleter.php | 26 +--------------------- whups/lib/Application.php | 6 ++++- whups/lib/Whups.php | 23 +++++++++++++++++++ 9 files changed, 80 insertions(+), 49 deletions(-) diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php index 7c8c4879c..2efd02a18 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php @@ -122,9 +122,16 @@ class Horde_Core_Prefs_Ui_Widgets * search_fields contains a hash containing sources as keys and an array * of search fields as the value. * + * @param array $data Data items: + *
+     * 'fields' - (array) Hash containing addressbook sources as keys and an
+     *            array of search fields as values.
+     * 'sources' - (array) List of selected addressbooks.
+     * 
+ * * @return string HTML UI code. */ - static public function addressbooks() + static public function addressbooks($data) { global $prefs, $registry; @@ -151,20 +158,18 @@ class Horde_Core_Prefs_Ui_Widgets $writeable = array(); } - $search = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); - if (count($readable) == 1) { // Only one source, no need to display the selection widget - $search['sources'] = array_keys($readable); + $data['sources'] = array_keys($readable); } - foreach ($search['sources'] as $source) { + foreach ($data['sources'] as $source) { if (!empty($readable[$source])) { $selected[$source] = $readable[$source]; } } - foreach (array_diff(array_keys($readable), $search['sources']) as $val) { + foreach (array_diff(array_keys($readable), $data['sources']) as $val) { $unselected[$val] = $readable[$val]; } @@ -192,8 +197,8 @@ class Horde_Core_Prefs_Ui_Widgets 'name' => $field['name'], 'label' => $field['label'] ); - if (isset($search['fields'][$source]) && - in_array($field['name'], $search['fields'][$source])) { + if (isset($data['fields'][$source]) && + in_array($field['name'], $data['fields'][$source])) { $tmpsel[] = $field['name']; } } diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index 7c1e65ddd..e583faf1a 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -308,7 +308,11 @@ class IMP_Prefs_Ui return $this->_sound(); case 'sourceselect': - return Horde_Core_Prefs_Ui_Widgets::addressbooks(); + $search = IMP::getAddressbookSearchParams(); + return Horde_Core_Prefs_Ui_Widgets::addressbooks(array( + 'fields' => $search['fields'], + 'sources' => $search['sources'] + )); case 'spamselect': return $this->_spam(); diff --git a/kronolith/contacts.php b/kronolith/contacts.php index c2e901383..0b7ea8db6 100644 --- a/kronolith/contacts.php +++ b/kronolith/contacts.php @@ -33,9 +33,9 @@ $apiargs['addresses'] = array($search); $apiargs['addressbooks'] = array($source); $apiargs['fields'] = array(); -$search_fields_pref = json_decode($prefs->getValue('search_fields'), true); -if (!empty($search_fields_pref) && isset($search_fields_pref[$source])) { - $apiargs['fields'][$source] = $search_fields_pref[$source]; +$searchpref = Kronolith::getAddressbookSearchParams(); +if (isset($searchpref[$source])) { + $apiargs['fields'][$source] = $searchpref[$source]; } if ($search || $prefs->getValue('display_contact')) { diff --git a/kronolith/lib/Ajax/Imple/ContactAutoCompleter.php b/kronolith/lib/Ajax/Imple/ContactAutoCompleter.php index 38666c35a..cfc6cc69f 100644 --- a/kronolith/lib/Ajax/Imple/ContactAutoCompleter.php +++ b/kronolith/lib/Ajax/Imple/ContactAutoCompleter.php @@ -75,18 +75,10 @@ class Kronolith_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoCom $search = reset(array_filter(array_map('trim', Horde_Mime_Address::explode($addrString, ',;')))); - $src = json_decode($GLOBALS['prefs']->getValue('search_sources')); - if (!is_array($src)) { - $src = array(); - } - - $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true); - if (!is_array($fields)) { - $fields = array(); - } + $searchpref = Kronolith::getAddressbookSearchParams(); try { - $res = $GLOBALS['registry']->call('contacts/search', array($search, $src, $fields, true)); + $res = $GLOBALS['registry']->call('contacts/search', array($search, $searchpref['sources'], $searchpref['fields'], true)); } catch (Horde_Exception $e) { Horde::logMessage($e, 'ERR'); return array(); diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index e30bcfa51..15cde7d80 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -202,7 +202,11 @@ class Kronolith_Application extends Horde_Registry_Application return $this->_defaultAlarmManagement($ui); case 'sourceselect': - return Horde_Core_Prefs_Ui_Widgets::addressbooks(); + $search = Kronolith::getAddressbookSearchParams(); + return Horde_Core_Prefs_Ui_Widgets::addressbooks(array( + 'fields' => $search['fields'], + 'sources' => $search['sources'] + )); } return ''; diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index b531df23c..51761357a 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -2721,4 +2721,27 @@ class Kronolith } } + /** + * Determines parameters needed to do an address search + * + * @return array An array with two keys: 'fields' and 'sources'. + */ + static public function getAddressbookSearchParams() + { + $src = json_decode($GLOBALS['prefs']->getValue('search_sources')); + if (empty($src)) { + $src = array(); + } + + $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true); + if (empty($fields)) { + $fields = array(); + } + + return array( + 'fields' => $fields, + 'sources' => $src + ); + } + } diff --git a/whups/lib/Ajax/Imple/ContactAutoCompleter.php b/whups/lib/Ajax/Imple/ContactAutoCompleter.php index 990e8d29b..9699a8bf4 100644 --- a/whups/lib/Ajax/Imple/ContactAutoCompleter.php +++ b/whups/lib/Ajax/Imple/ContactAutoCompleter.php @@ -96,7 +96,7 @@ class Whups_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoComplet */ static public function getAddressList($search = '') { - $sparams = self::getAddressSearchParams(); + $sparams = Whups::getAddressbookSearchParams(); try { $res = $GLOBALS['registry']->call('contacts/search', array($search, $sparams['sources'], $sparams['fields'], false)); } catch (Horde_Exception $e) { @@ -127,28 +127,4 @@ class Whups_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoComplet return $search; } - /** - * Determines parameters needed to do an address search - * - * @return array An array with two keys: 'sources' and 'fields'. - */ - static public function getAddressSearchParams() - { - $src = json_decode($GLOBALS['prefs']->getValue('search_sources')); - if (!is_array($src)) { - $src = array(); - } - - - $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true); - if (!is_array($fields)) { - $fields = array(); - } - - return array( - 'fields' => $fields, - 'sources' => $src - ); - } - } diff --git a/whups/lib/Application.php b/whups/lib/Application.php index 34cc3f1fa..b6adab63d 100644 --- a/whups/lib/Application.php +++ b/whups/lib/Application.php @@ -152,7 +152,11 @@ class Whups_Application extends Horde_Registry_Application { switch ($item) { case 'sourceselect': - return Horde_Core_Prefs_Ui_Widgets::addressbooks(); + $search = Whups::getAddressbookSearchParams(); + return Horde_Core_Prefs_Ui_Widgets::addressbooks(array( + 'fields' => $search['fields'], + 'sources' => $search['sources'] + )); } return ''; diff --git a/whups/lib/Whups.php b/whups/lib/Whups.php index 1e3564190..61a02c8c4 100644 --- a/whups/lib/Whups.php +++ b/whups/lib/Whups.php @@ -998,4 +998,27 @@ class Whups { : array(); } + /** + * Determines parameters needed to do an address search + * + * @return array An array with two keys: 'sources' and 'fields'. + */ + static public function getAddressbookSearchParams() + { + $src = json_decode($GLOBALS['prefs']->getValue('search_sources')); + if (!is_array($src)) { + $src = array(); + } + + $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true); + if (!is_array($fields)) { + $fields = array(); + } + + return array( + 'fields' => $fields, + 'sources' => $src + ); + } + } -- 2.11.0