/** */ protected function _initPages() { global $injector; $this->view->list = array(); if ($GLOBALS['browse_source_count']) { foreach (Turba::getAddressBooks() as $key => $val) { if (!empty($val['browse'])) { try { $driver = $injector->getInstance('Turba_Factory_Driver')->create($key); } catch (Turba_Exception $e) { continue; } try { $contacts = $driver->search(array(), null, 'AND', array('__key', 'name')); $contacts->reset(); } catch (Turba_Exception $e) { continue; } $url = new Horde_Core_Smartmobile_Url(); $url->add('source', $key); $url->setAnchor('entry'); $tmp = array(); while ($contact = $contacts->next()) { $name = Turba::formatName($contact); $tmp[] = array('group' => $contact->isGroup(), 'name' => strlen($name) ? $name : '[' . _("No Name") . ']', 'url' => strval($url->add('key', $contact->getValue('__key')))); } $this->view->list[$val['title']] = $tmp; } } } }
/** */ public function __construct($app, $params = array()) { parent::__construct($app, $params); foreach (Turba::getAddressBooks(Horde_Perms::READ) as $key => $addressbook) { $this->_options[$key] = $addressbook['title']; } $this->_name = _("Contact Search"); }
*/ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('turba'); $vars = Horde_Variables::getDefaultVariables(); /* Verify if the search mode variable is passed in form or is registered in * the session. Always use basic search by default. */ if ($vars->search_mode) { $session->set('turba', 'search_mode', $vars->search_mode); } if (!in_array($session->get('turba', 'search_mode'), array('basic', 'advanced', 'duplicate'))) { $session->set('turba', 'search_mode', 'basic'); } $search_mode = $session->get('turba', 'search_mode'); /* Get the current source. */ $addressBooks = Turba::getAddressBooks(); $editableAddressBooks = Turba::getAddressBooks(Horde_Perms::EDIT & Horde_Perms::DELETE, array('require_add' => true)); if ($search_mode == 'duplicate') { $addressBooks = $editableAddressBooks; } $source = $vars->get('source', Turba::$source); if (!isset($addressBooks[$source])) { $source = key($addressBooks); /* If there are absolutely no valid sources, abort. */ if (!isset($addressBooks[$source])) { $notification->push(_("No Address Books are currently available. Searching is disabled."), 'horde.error'); $page_output->header(); $notification->notify(array('listeners' => 'status')); $page_output->footer(); exit; } }
$default_source = $prefs->getValue('default_dir'); if ($next_step == Horde_Data::IMPORT_FILE) { /* Build the directory sources select widget. */ $unique_source = ''; $source_options = array(); foreach (Turba::getAddressBooks() as $key => $entry) { if (!empty($entry['export'])) { $source_options[] = '<option value="' . htmlspecialchars($key) . '">' . htmlspecialchars($entry['title']) . "</option>\n"; $unique_source = $key; } } /* Build the directory destination select widget. */ $unique_dest = ''; $dest_options = array(); $hasWriteable = false; foreach (Turba::getAddressBooks(Horde_Perms::EDIT) as $key => $entry) { $selected = $key == $default_source ? ' selected="selected"' : ''; $dest_options[] = '<option value="' . htmlspecialchars($key) . '" ' . $selected . '>' . htmlspecialchars($entry['title']) . "</option>\n"; $unique_dest = $key; $hasWriteable = true; } if (!$hasWriteable) { array_shift($templates[$next_step]); } /* Build the charset options. */ $charsets = array(); if (!empty($bad_charset)) { $charsets = $registry->nlsconfig->encodings_sort; foreach ($registry->nlsconfig->charsets as $charset) { if (!isset($charsets[$charset]) && !in_array($charset, $bad_charset)) { $charsets[$charset] = $charset;
/** */ protected function _getSource($source) { global $cfgSources, $injector, $prefs; /* Get default address book from user preferences. */ if (empty($source) && !($source = $prefs->getValue('default_dir'))) { // On new installations default_dir is not set. Try default // addressbook if it's editable. Otherwise use first editable // addressbook. $edit_sources = Turba::getAddressBooks(Horde_Perms::EDIT); $default_source = Turba::getDefaultAddressbook(); if (isset($edit_sources[$default_source])) { // use default addressbook $source = $default_source; } else { // Use first writable source $source = reset($edit_sources); } } // Check existence of and permissions on the specified source. if (!isset($cfgSources[$source])) { throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $source)); } return $source; }
/** */ public function davGetCollections($user) { global $injector, $registry; $hordeUser = $registry->convertUsername($user, true); $dav = $injector->getInstance('Horde_Dav_Storage'); $factory = $injector->getInstance('Turba_Shares'); $books = array(); foreach (Turba::getAddressBooks(Horde_Perms::SHOW) as $id => $book) { $readOnly = false; switch ($book['type']) { // Ugly hack! There is currently no clean way to retrieve address // books that the user "owns", or to find out if a SQL/LDAP/Kolab // address book contains per-user or global contacts. case 'share': $share = $factory->getShare($id); if ($user == '-system-' && strlen($share->get('owner')) || $user != '-system-' && $hordeUser != $share->get('owner') && $hordeUser != $registry->getAuth()) { continue; } $readOnly = !$share->hasPermission($hordeUser, Horde_Perms::EDIT); break; case 'facebook': case 'favourites': case 'vbook': if ($user == '-system-') { continue; } $readOnly = true; break; default: if (!Turba::permissionsFilter(array($id => $book), Horde_Perms::EDIT)) { $readOnly = true; } break; } try { $id = $dav->getExternalCollectionId($id, 'contacts') ?: $id; } catch (Horde_Dav_Exception $e) { } $books[] = array('id' => $id, 'uri' => $id, 'principaluri' => 'principals/' . $user, '{DAV:}displayname' => $book['title'], '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(array(array('contentType' => 'text/directory', 'version' => '3.0'), array('contentType' => 'text/vcard', 'version' => '3.0'), array('contentType' => 'text/x-vcard', 'version' => '2.1'))), '{http://sabredav.org/ns}read-only' => $readOnly); } return $books; }
<?php /** * Turba browse.php. * * Copyright 2000-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (ASL). If you did * did not receive this file, see http://www.horde.org/licenses/apache. * * @author Chuck Hagenbuch <*****@*****.**> * @package Turba */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('turba'); /* If default source is not browsable, try one from the addressbooks pref */ if (empty($cfgSources[Turba::$source]['browse'])) { $addressbooks = Turba::getAddressBooks(); foreach ($addressbooks as $source) { if (!empty($cfgSources[$source]['browse'])) { Turba::$source = $source; break; } } } $params = array('addSources' => $addSources, 'attributes' => $attributes, 'browse_source_count' => $browse_source_count, 'browser' => $browser, 'cfgSources' => $cfgSources, 'copymoveSources' => $copymoveSources, 'conf' => $conf, 'factory' => $injector->getInstance('Turba_Factory_Driver'), 'history' => $injector->getInstance('Horde_History'), 'notification' => $notification, 'page_output' => $page_output, 'prefs' => $prefs, 'registry' => $registry, 'source' => Turba::$source, 'turba_shares' => $injector->getInstance('Turba_Shares'), 'vars' => Horde_Variables::getDefaultVariables()); $browse = new Turba_View_Browse($params); $browse->run();
/** */ public function davGetCollections($user) { global $injector, $registry; $dav = $injector->getInstance('Horde_Dav_Storage'); $factory = $injector->getInstance('Turba_Shares'); $books = array(); foreach (Turba::getAddressBooks(Horde_Perms::SHOW) as $id => $book) { // Ugly hack! There is currently no clean way to retrieve address // books that the user "owns", or to find out if a SQL/LDAP/Kolab // address book contains per-user or global contacts. if ($book['type'] == 'share') { $share = $factory->getShare($id); if ($user == '-system-' && strlen($share->get('owner')) || $user != '-system-' && $user != $share->get('owner') && $user != $registry->getAuth()) { continue; } } if ($user == '-system-' && ($book['type'] == 'facebook' || $book['type'] == 'favourites' || $book['type'] == 'vbook')) { continue; } try { $id = $dav->getExternalCollectionId($id, 'contacts') ?: $id; } catch (Horde_Dav_Exception $e) { } $books[] = array('id' => $id, 'uri' => $id, 'principaluri' => 'principals/' . $user, '{DAV:}displayname' => $book['title'], '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(array(array('contentType' => 'text/directory', 'version' => '3.0'), array('contentType' => 'text/vcard', 'version' => '3.0'), array('contentType' => 'text/x-vcard', 'version' => '2.1')))); } return $books; }
/** * Returns a contact search result. * * @param mixed $names The search filter values. * @param array $opts Optional parameters: * - customStrict: (array) An array of fields that must match exactly. * DEFAULT: None * - fields: (array) The fields to search on. * DEFAULT: All fields * - forceSource: (boolean) Whether to use the specified sources, even * if they have been disabled in the preferences? * DEFAULT: false * - matchBegin: (boolean) Match word boundaries only? * DEFAULT: false * - returnFields: Only return these fields. * DEFAULT: Return all fields. * - rfc822Return: Return a Horde_Mail_Rfc822_List object. * DEFAULT: Returns an array of search results. * - sources: (array) The sources to search in. * DEFAULT: Search the user's default address book * - count_only: (boolean) If true, only return the count of matching * results. * DEFAULT: false (Return the full data set). * * @return mixed Either a hash containing the search results or a * Rfc822 List object (if 'rfc822Return' is true). * @throws Turba_Exception */ public function search($names = null, array $opts = array()) { global $attributes, $cfgSources, $injector; $opts = array_merge(array('fields' => array(), 'forceSource' => false, 'matchBegin' => false, 'returnFields' => array(), 'rfc822Return' => false, 'sources' => array(), 'customStrict' => array(), 'count_only' => false), $opts); $results = !empty($opts['count_only']) ? 0 : (empty($opts['rfc822Return']) ? array() : new Horde_Mail_Rfc822_List()); if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources) || is_null($names)) { return $results; } if (!is_array($names)) { $names = array($names); } if (!$opts['forceSource']) { // Make sure the selected source is activated in Turba. $addressbooks = array_keys(Turba::getAddressBooks()); foreach (array_keys($opts['sources']) as $id) { if (!in_array($opts['sources'][$id], $addressbooks)) { unset($opts['sources'][$id]); } } } // ...and ensure the default source is used as a default. if (!count($opts['sources'])) { $opts['sources'] = array(Turba::getDefaultAddressbook()); } $driver = $injector->getInstance('Turba_Factory_Driver'); foreach ($opts['sources'] as $source) { // Skip invalid sources -or- // skip sources that aren't browseable if the search is empty. if (!isset($cfgSources[$source]) || empty($cfgSources[$source]['browse']) && (!count($names) || count($names) == 1 && empty($names[0]))) { continue; } if (empty($opts['fields'][$source])) { $opts['fields'][$source] = $GLOBALS['cfgSources'][$source]['search']; } $sdriver = $driver->create($source); foreach ($names as $name) { $trimname = trim($name); $out = $criteria = array(); unset($tname); if (strlen($trimname)) { if (isset($opts['fields'][$source])) { foreach ($opts['fields'][$source] as $field) { $criteria[$field] = $trimname; } } } try { $search = $sdriver->search($criteria, Turba::getPreferredSortOrder(), 'OR', $opts['returnFields'], $opts['customStrict'], $opts['matchBegin'], $opts['count_only']); } catch (Exception $e) { continue; } if ($opts['count_only']) { $results += $search; continue; } elseif (!$search instanceof Turba_List) { continue; } $rfc822 = new Horde_Mail_Rfc822(); while ($ob = $search->next()) { $emails = $seen = array(); if ($ob->isGroup()) { /* Is a distribution list. */ $members = $ob->listMembers(); if (!$members instanceof Turba_List || !count($members)) { continue; } $listatt = $ob->getAttributes(); $listName = $ob->getValue('name'); while ($ob = $members->next()) { foreach (array_keys($ob->getAttributes()) as $key) { $value = $ob->getValue($key); if (empty($value)) { continue; } $seen_key = trim(Horde_String::lower($ob->getValue('name'))) . trim(Horde_String::lower(is_array($value) ? $value['load']['file'] : $value)); if (isset($attributes[$key]) && $attributes[$key]['type'] == 'email' && empty($seen[$seen_key])) { $emails[] = $value; $seen[$seen_key] = true; } } } if (empty($opts['rfc822Return'])) { $out[] = array('email' => implode(', ', $emails), 'id' => $listatt['__key'], 'name' => $listName, 'source' => $source); } else { $results->add(new Horde_Mail_Rfc822_Group($listName, $emails)); } } else { /* Not a group. */ $att = array('__key' => $ob->getValue('__key')); foreach (array_keys($ob->driver->getCriteria()) as $key) { $att[$key] = $ob->getValue($key); } $email = new Horde_Mail_Rfc822_List(); $display_name = $ob->hasValue('name') || !isset($ob->driver->alternativeName) ? Turba::formatName($ob) : $ob->getValue($ob->driver->alternativeName); unset($tdisplay_name); foreach (array_keys($att) as $key) { if ($ob->getValue($key) && isset($attributes[$key]) && $attributes[$key]['type'] == 'email') { $e_val = $ob->getValue($key); if (strlen($trimname)) { /* Ticket #12480: Don't return email if it * doesn't contain the search string, since * an entry can contain multiple e-mail * fields. Return all e-mails if it * occurs in the name. */ if (!isset($tname)) { $tname = Horde_String_Transliterate::toAscii($name); } if (!isset($tdisplay_name)) { $tdisplay_name = Horde_String_Transliterate::toAscii($display_name); } $add = Horde_String::ipos(Horde_String_Transliterate::toAscii($e_val), $tname) !== false || Horde_String::ipos($tdisplay_name, $tname) !== false; } else { $add = true; } if ($add) { // Multiple addresses support $email->add($rfc822->parseAddressList($e_val, array('limit' => isset($attributes[$key]['params']) && is_array($attributes[$key]['params']) && !empty($attributes[$key]['params']['allow_multi']) ? 0 : 1))); } } } if (count($email)) { foreach ($email as $val) { $seen_key = trim(Horde_String::lower($display_name)) . '/' . Horde_String::lower($val->bare_address); if (empty($seen[$seen_key])) { $seen[$seen_key] = true; if (empty($opts['rfc822Return'])) { $emails[] = $val->bare_address; } else { $val->personal = $display_name; $results->add($val); } } } } elseif (empty($opts['rfc822Return'])) { $emails[] = null; } if (empty($opts['rfc822Return'])) { foreach ($emails as $val) { $out[] = array_merge($att, array('__type' => 'Object', 'email' => $val, 'id' => $att['__key'], 'name' => $display_name, 'source' => $source)); } } } } if (!empty($out)) { $results[$name] = $out; } } } return $results; }