예제 #1
0
 public function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $searchresults = array();
     $results = \OCP\Contacts::search($query, array('N', 'FN', 'EMAIL', 'NICKNAME', 'ORG'));
     $l = new \OC_l10n('contacts');
     foreach ($results as $result) {
         $link = \OCP\Util::linkToRoute('contacts_index') . '#' . $result['id'];
         $props = array();
         $display = isset($result['FN']) && $result['FN'] ? $result['FN'] : null;
         foreach (array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) {
             if (isset($result[$searchvar]) && $result[$searchvar]) {
                 if (is_array($result[$searchvar])) {
                     $result[$searchvar] = array_filter($result[$searchvar]);
                 }
                 $prop = is_array($result[$searchvar]) ? implode(',', $result[$searchvar]) : $result[$searchvar];
                 $props[] = $prop;
                 $display = $display ?: $result[$searchvar];
             }
         }
         $props = array_map($unescape, $props);
         $searchresults[] = new \OC_Search_Result($display, implode(', ', $props), $link, (string) $l->t('Contact'), null);
         //$name,$text,$link,$type
     }
     return $searchresults;
 }
예제 #2
0
 /**
  * Search for contacts
  *
  * @param string $query
  * @return array list of \OCA\Calendar\Search\Contact
  */
 function search($query)
 {
     $_results = \OCP\Contacts::search($query, array('N', 'FN', 'EMAIL', 'NICKNAME', 'ORG'));
     $results = array();
     foreach ($_results as $_result) {
         $results[] = new \OCA\Contacts\Search\Contact($_result);
     }
     return $results;
 }
예제 #3
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sQuery
  * @param int $iLimit = 20
  *
  * @return array
  */
 public function Process($oAccount, $sQuery, $iLimit = 20)
 {
     $aResult = array();
     try {
         if (!$oAccount || !\RainLoop\Utils::IsOwnCloud() || !\class_exists('\\OCP\\Contacts') || !\OCP\Contacts::isEnabled() || !\class_exists('\\OCP\\User') || !\OCP\User::isLoggedIn()) {
             return $aResult;
         }
         $aSearchResult = \OCP\Contacts::search($sQuery, array('FN', 'EMAIL'));
         //$this->oLogger->WriteDump($aSearchResult);
         $aPreResult = array();
         if (\is_array($aSearchResult) && 0 < \count($aSearchResult)) {
             foreach ($aSearchResult as $aContact) {
                 if (0 >= $iLimit) {
                     break;
                 }
                 $sUid = empty($aContact['UID']) ? '' : $aContact['UID'];
                 if (!empty($sUid)) {
                     $sFullName = isset($aContact['FN']) ? \trim($aContact['FN']) : '';
                     $mEmails = isset($aContact['EMAIL']) ? $aContact['EMAIL'] : '';
                     if (!\is_array($mEmails)) {
                         $mEmails = array($mEmails);
                     }
                     if (!isset($aPreResult[$sUid])) {
                         $aPreResult[$sUid] = array();
                     }
                     foreach ($mEmails as $sEmail) {
                         $sEmail = \trim($sEmail);
                         if (!empty($sEmail)) {
                             $iLimit--;
                             $aPreResult[$sUid][] = array($sEmail, $sFullName);
                         }
                     }
                 }
             }
             $aPreResult = \array_values($aPreResult);
             //				$this->oLogger->WriteDump($aPreResult);
             foreach ($aPreResult as $aData) {
                 foreach ($aData as $aSubData) {
                     $aResult[] = $aSubData;
                 }
             }
         }
         unset($aSearchResult, $aPreResult);
     } catch (\Exception $oException) {
         if ($this->oLogger) {
             $this->oLogger->WriteException($oException);
         }
     }
     return $aResult;
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sQuery
  * @param int $iLimit = 20
  *
  * @return array
  */
 public function Process($oAccount, $sQuery, $iLimit = 20)
 {
     $iInputLimit = $iLimit;
     $aResult = array();
     $sQuery = \trim($sQuery);
     try {
         if ('' === $sQuery || !$oAccount || !\RainLoop\Utils::IsOwnCloudLoggedIn() || !\class_exists('OCP\\Contacts') || !\OCP\Contacts::isEnabled()) {
             return $aResult;
         }
         $aSearchResult = \OCP\Contacts::search($sQuery, array('FN', 'EMAIL'));
         //$this->oLogger->WriteDump($aSearchResult);
         $aHashes = array();
         if (\is_array($aSearchResult) && 0 < \count($aSearchResult)) {
             foreach ($aSearchResult as $aContact) {
                 if (0 >= $iLimit) {
                     break;
                 }
                 $sUid = empty($aContact['UID']) ? '' : $aContact['UID'];
                 if (!empty($sUid)) {
                     $sFullName = isset($aContact['FN']) ? \trim($aContact['FN']) : '';
                     $mEmails = isset($aContact['EMAIL']) ? $aContact['EMAIL'] : '';
                     if (!\is_array($mEmails)) {
                         $mEmails = array($mEmails);
                     }
                     foreach ($mEmails as $sEmail) {
                         $sHash = '"' . $sFullName . '" <' . $sEmail . '>';
                         if (!isset($aHashes[$sHash])) {
                             $aHashes[$sHash] = true;
                             $aResult[] = array($sEmail, $sFullName);
                             $iLimit--;
                         }
                     }
                 }
             }
             $aResult = \array_slice($aResult, 0, $iInputLimit);
         }
         unset($aSearchResult, $aHashes);
     } catch (\Exception $oException) {
         if ($this->oLogger) {
             $this->oLogger->WriteException($oException);
         }
     }
     return $aResult;
 }
예제 #5
0
파일: mail.php 프로젝트: netcon-source/apps
 /**
  * Extracts all matching contacts with email address and name
  *
  * @param $term
  * @return array
  */
 public static function getMatchingRecipient($term)
 {
     if (!\OCP\Contacts::isEnabled()) {
         return array();
     }
     $result = \OCP\Contacts::search($term, array('FN', 'EMAIL'));
     $receivers = array();
     foreach ($result as $r) {
         $id = $r['id'];
         $fn = $r['FN'];
         $email = $r['EMAIL'];
         if (!is_array($email)) {
             $email = array($email);
         }
         // loop through all email addresses of this contact
         foreach ($email as $e) {
             $displayName = $fn . " <{$e}>";
             $receivers[] = array('id' => $id, 'label' => $displayName, 'value' => $displayName);
         }
     }
     return $receivers;
 }
예제 #6
0
 function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $app = new App();
     $searchresults = array();
     $results = \OCP\Contacts::search($query, array('N', 'FN', 'EMAIL', 'NICKNAME', 'ORG'));
     $l = new \OC_l10n('contacts');
     foreach ($results as $result) {
         $link = \OCP\Util::linkToRoute('contacts_index') . '#' . $result['id'];
         $props = array();
         foreach (array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) {
             if (isset($result[$searchvar]) && count($result[$searchvar]) > 0 && strlen($result[$searchvar][0]) > 3) {
                 $props = array_merge($props, $result[$searchvar]);
             }
         }
         $props = array_map($unescape, $props);
         $searchresults[] = new \OC_Search_Result($result['FN'], implode(', ', $props), $link, (string) $l->t('Contact'));
         //$name,$text,$link,$type
     }
     return $searchresults;
 }
예제 #7
0
 public static function search($str)
 {
     // The API is not active -> nothing to do
     if (!\OCP\Contacts::isEnabled() || strlen($str) < 3) {
         return array();
     }
     $result = \OCP\Contacts::search($str, array('FN', 'EMAIL'));
     $receivers = array();
     foreach ($result as $r) {
         $id = $r['id'];
         $fn = $r['FN'];
         $email = $r['EMAIL'];
         if (!is_array($email)) {
             $email = array($email);
         }
         // loop through all email addresses of this contact
         foreach ($email as $e) {
             $displayName = $fn . " <{$e}>";
             $receivers[] = array('id' => $id, 'label' => $displayName, 'value' => $displayName);
         }
     }
     return $receivers;
 }
예제 #8
0
<?php

\OCP\User::checkLoggedIn();
$result = \OCP\Contacts::search($_REQUEST['term'], array('FN', 'ADR'));
$contacts = array();
foreach ($result as $r) {
    if (!isset($r['ADR'])) {
        continue;
    }
    $tmp = $r['ADR'][0];
    $address = trim(implode(" ", $tmp));
    $contacts[] = array('label' => $address);
}
\OCP\JSON::EncodedPrint($contacts);
예제 #9
0
\Sabre\VObject\Property::$classMap['ADR'] = '\\OC\\VObject\\CompoundProperty';
\Sabre\VObject\Property::$classMap['GEO'] = '\\OC\\VObject\\CompoundProperty';
\Sabre\VObject\Property::$classMap['ORG'] = '\\OC\\VObject\\CompoundProperty';
\OC::$server->getNavigationManager()->add(array('id' => 'contacts', 'order' => 10, 'href' => \OCP\Util::linkToRoute('contacts_index'), 'icon' => \OCP\Util::imagePath('contacts', 'contacts.svg'), 'name' => \OCP\Util::getL10N('contacts')->t('Contacts')));
$api = new API('contacts');
$api->connectHook('OC_User', 'post_createUser', '\\OCA\\Contacts\\Hooks', 'userCreated');
$api->connectHook('OC_User', 'post_deleteUser', '\\OCA\\Contacts\\Hooks', 'userDeleted');
$api->connectHook('OCA\\Contacts', 'pre_deleteAddressBook', '\\OCA\\Contacts\\Hooks', 'addressBookDeletion');
$api->connectHook('OCA\\Contacts', 'pre_deleteContact', '\\OCA\\Contacts\\Hooks', 'contactDeletion');
$api->connectHook('OCA\\Contacts', 'post_createContact', 'OCA\\Contacts\\Hooks', 'contactAdded');
$api->connectHook('OCA\\Contacts', 'post_updateContact', '\\OCA\\Contacts\\Hooks', 'contactUpdated');
$api->connectHook('OCA\\Contacts', 'scanCategories', '\\OCA\\Contacts\\Hooks', 'scanCategories');
$api->connectHook('OCA\\Contacts', 'indexProperties', '\\OCA\\Contacts\\Hooks', 'indexProperties');
$api->connectHook('OC_Calendar', 'getEvents', 'OCA\\Contacts\\Hooks', 'getBirthdayEvents');
$api->connectHook('OC_Calendar', 'getSources', 'OCA\\Contacts\\Hooks', 'getCalenderSources');
\OCP\Util::addscript('contacts', 'loader');
\OCP\Util::addscript('contacts', 'admin');
\OC_Search::registerProvider('OCA\\Contacts\\Search\\Provider');
//\OCP\Share::registerBackend('contact', 'OCA\Contacts\Share_Backend_Contact');
\OCP\Share::registerBackend('addressbook', 'OCA\\Contacts\\Share\\Addressbook', 'contact');
//\OCP\App::registerPersonal('contacts','personalsettings');
\OCP\App::registerAdmin('contacts', 'admin');
if (\OCP\User::isLoggedIn()) {
    $app = new App($api->getUserId());
    $addressBooks = $app->getAddressBooksForUser();
    foreach ($addressBooks as $addressBook) {
        if ($addressBook->isActive()) {
            \OCP\Contacts::registerAddressBook($addressBook->getSearchProvider());
        }
    }
}
예제 #10
0
 protected function setUp()
 {
     parent::setUp();
     \OCP\Contacts::clear();
 }
예제 #11
0
파일: app.php 프로젝트: CDN-Sparks/owncloud
\Sabre\VObject\Property::$classMap['X-EVOLUTION-FILE-AS'] = '\\OC\\VObject\\StringProperty';
\Sabre\VObject\Property::$classMap['N'] = '\\OC\\VObject\\CompoundProperty';
\Sabre\VObject\Property::$classMap['ADR'] = '\\OC\\VObject\\CompoundProperty';
\Sabre\VObject\Property::$classMap['GEO'] = '\\OC\\VObject\\CompoundProperty';
\Sabre\VObject\Property::$classMap['ORG'] = '\\OC\\VObject\\CompoundProperty';
\OC::$server->getNavigationManager()->add(array('id' => 'contacts', 'order' => 10, 'href' => \OCP\Util::linkToRoute('contacts_index'), 'icon' => \OCP\Util::imagePath('contacts', 'contacts.svg'), 'name' => \OCP\Util::getL10N('contacts')->t('Contacts')));
$api = new API('contacts');
$api->connectHook('OC_User', 'post_createUser', '\\OCA\\Contacts\\Hooks', 'userCreated');
$api->connectHook('OC_User', 'post_deleteUser', '\\OCA\\Contacts\\Hooks', 'userDeleted');
$api->connectHook('OCA\\Contacts', 'pre_deleteAddressBook', '\\OCA\\Contacts\\Hooks', 'addressBookDeletion');
$api->connectHook('OCA\\Contacts', 'pre_deleteContact', '\\OCA\\Contacts\\Hooks', 'contactDeletion');
$api->connectHook('OCA\\Contacts', 'post_createContact', 'OCA\\Contacts\\Hooks', 'contactAdded');
$api->connectHook('OCA\\Contacts', 'post_updateContact', '\\OCA\\Contacts\\Hooks', 'contactUpdated');
$api->connectHook('OCA\\Contacts', 'scanCategories', '\\OCA\\Contacts\\Hooks', 'scanCategories');
$api->connectHook('OCA\\Contacts', 'indexProperties', '\\OCA\\Contacts\\Hooks', 'indexProperties');
$api->connectHook('OC_Calendar', 'getEvents', 'OCA\\Contacts\\Hooks', 'getBirthdayEvents');
$api->connectHook('OC_Calendar', 'getSources', 'OCA\\Contacts\\Hooks', 'getCalenderSources');
\OCP\Util::addscript('contacts', 'loader');
\OC_Search::registerProvider('OCA\\Contacts\\SearchProvider');
//\OCP\Share::registerBackend('contact', 'OCA\Contacts\Share_Backend_Contact');
\OCP\Share::registerBackend('addressbook', 'OCA\\Contacts\\Share\\Addressbook', 'contact');
//\OCP\App::registerPersonal('contacts','personalsettings');
if (\OCP\User::isLoggedIn()) {
    $app = new App($api->getUserId());
    $addressBooks = $app->getAddressBooksForUser();
    foreach ($addressBooks as $addressBook) {
        if ($addressBook->isActive()) {
            \OCP\Contacts::registerAddressBook(new AddressbookProvider($addressBook));
        }
    }
}
예제 #12
0
 public function testSearchInAddressBook()
 {
     // create mock for the addressbook
     $stub1 = $this->getMockForAbstractClass("OCP\\IAddressBook", array('getKey', 'getDisplayName', 'search'));
     $stub2 = $this->getMockForAbstractClass("OCP\\IAddressBook", array('getKey', 'getDisplayName', 'search'));
     $searchResult1 = array(array('id' => 0, 'FN' => 'Frank Karlitschek', 'EMAIL' => 'a@b.c', 'GEO' => '37.386013;-122.082932'), array('id' => 5, 'FN' => 'Klaas Freitag', 'EMAIL' => array('d@e.f', 'g@h.i')));
     $searchResult2 = array(array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c'), array('id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => array('d@e.f', 'g@h.i')));
     // setup return for method calls for $stub1
     $stub1->expects($this->any())->method('getKey')->will($this->returnValue('SIMPLE_ADDRESS_BOOK1'));
     $stub1->expects($this->any())->method('getDisplayName')->will($this->returnValue('Address book ownCloud Inc'));
     $stub1->expects($this->any())->method('search')->will($this->returnValue($searchResult1));
     // setup return for method calls for $stub2
     $stub2->expects($this->any())->method('getKey')->will($this->returnValue('SIMPLE_ADDRESS_BOOK2'));
     $stub2->expects($this->any())->method('getDisplayName')->will($this->returnValue('Address book ownCloud Community'));
     $stub2->expects($this->any())->method('search')->will($this->returnValue($searchResult2));
     // register the address books
     \OCP\Contacts::registerAddressBook($stub1);
     \OCP\Contacts::registerAddressBook($stub2);
     $all_books = \OCP\Contacts::getAddressBooks();
     // assert the count - doesn't hurt
     $this->assertEquals(2, count($all_books));
     // perform the search
     $result = \OCP\Contacts::search('x', array());
     // we expect 4 hits
     $this->assertEquals(4, count($result));
 }