Exemple #1
0
 /**
  * 
  * @param string $query
  * @return \OCP\Search\Result
  */
 function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $searchresults = array();
     $results = ContactsApp::searchProperties($query);
     $l = \OC::$server->getL10N(ContactsApp::$appname);
     foreach ($results as $result) {
         $vcard = VCard::find($result['id']);
         $link = \OC::$server->getURLGenerator()->linkToRoute(ContactsApp::$appname . '.page.index') . '#' . urlencode($vcard['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);
         $returnData['id'] = $vcard['id'];
         $returnData['description'] = $vcard['fullname'] . ' ' . implode(', ', $props);
         $returnData['link'] = $link;
         $results[] = new Result($returnData);
     }
     return $results;
 }
Exemple #2
0
 /**
  * 
  * @param string $query
  * @return \OCP\Search\Result
  */
 function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $searchresults = array();
     $results = ContactsApp::searchProperties($query);
     $l = \OC::$server->getL10N(ContactsApp::$appname);
     foreach ($results as $result) {
         $vcard = VCard::find($result['id']);
         $link = '#' . intval($vcard['id']);
         $props = '';
         foreach (array('EMAIL', 'NICKNAME', 'ORG', 'TEL') as $searchvar) {
             if (isset($result['name']) && $searchvar == $result['name']) {
                 //\OCP\Util::writeLog(ContactsApp::$appname,'FOUND id: ' . $result['value'], \OCP\Util::DEBUG);
                 $props .= $searchvar . ':' . $result['value'] . ' ';
             }
         }
         $returnData['id'] = $vcard['id'];
         $returnData['description'] = $vcard['fullname'] . ' ' . $props;
         $returnData['link'] = $link;
         $results[] = new Result($returnData);
     }
     return $results;
 }
Exemple #3
0
 public function formatItems($items, $format, $parameters = null)
 {
     $contacts = array();
     if ($format == self::FORMAT_CONTACT) {
         foreach ($items as $item) {
             $contact = VCard::find($item['item_source']);
             $contact['fullname'] = $item['item_target'];
             $contacts[] = $contact;
         }
     }
     return $contacts;
 }
Exemple #4
0
 public function getContact($params)
 {
     //test http://{owncloudomain}/ocs/v1.php/apps/contactsplus/api/v1/contact/283
     $contact = VCard::find($params['id']);
     if (!is_null($contact['carddata'])) {
         $vcard = VObject\Reader::read($contact['carddata']);
         $details = VCard::structureContact($vcard);
         $addrInfo = AddressBook::find($contact['addressbookid']);
         $details['addressbook'] = $addrInfo['displayname'];
         $details['addressbookuri'] = $addrInfo['uri'];
     }
     return new \OC_OCS_Result($details);
 }
Exemple #5
0
 /**
  * @brief Gets the VCard as a \Sabre\VObject\Component
  * @param integer $id
  * @returns \Sabre\VObject\Component|null The card or null if the card could not be parsed.
  */
 public static function getContactVCard($id)
 {
     $card = null;
     $vcard = null;
     try {
         $card = VCard::find($id);
     } catch (\Exception $e) {
         return null;
     }
     if (!$card) {
         return null;
     }
     try {
         $vcard = VObject\Reader::read($card['carddata']);
     } catch (\Exception $e) {
         \OCP\Util::writeLog(self::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         \OCP\Util::writeLog(self::$appname, __METHOD__ . ', id: ' . $id, \OCP\Util::DEBUG);
         return null;
     }
     if (!is_null($vcard) && !isset($vcard->REV)) {
         $rev = new \DateTime('@' . $card['lastmodified']);
         $vcard->REV = $rev->format(\DateTime::W3C);
     }
     return $vcard;
 }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function exportContacts()
 {
     $bookid = $this->params('bookid');
     $bookid = isset($bookid) ? $bookid : null;
     $contactid = $this->params('contactid');
     $contactid = isset($contactid) ? $contactid : null;
     $selectedids = $this->params('selectedids');
     $selectedids = isset($selectedids) ? $selectedids : null;
     $nl = "\n";
     if (!is_null($bookid)) {
         try {
             $addressbook = Addressbook::find($bookid);
         } catch (Exception $e) {
             OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
             exit;
         }
         $start = 0;
         $ContactsOutput = '';
         $batchsize = $this->configInfo->getUserValue($this->userId, $this->appName, 'export_batch_size', 20);
         while ($cardobjects = VCard::all($bookid, $start, $batchsize, array('carddata'))) {
             foreach ($cardobjects as $card) {
                 $ContactsOutput .= $card['carddata'] . $nl;
             }
             $start += $batchsize;
         }
         $name = str_replace(' ', '_', $addressbook['displayname']) . '.vcf';
         $response = new DataDownloadResponse($ContactsOutput, $name, 'text/directory');
         return $response;
     } elseif (!is_null($contactid)) {
         try {
             $data = VCard::find($contactid);
         } catch (Exception $e) {
             OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
             exit;
         }
         $name = str_replace(' ', '_', $data['fullname']) . '.vcf';
         $response = new DataDownloadResponse($data['carddata'], $name, 'text/vcard');
         return $response;
     } elseif (!is_null($selectedids)) {
         $selectedids = explode(',', $selectedids);
         $name = (string) $this->l10n->t('%d_selected_contacts', array(count($selectedids))) . '.vcf';
         $ContactsOutput = '';
         foreach ($selectedids as $id) {
             try {
                 $data = VCard::find($id);
                 $ContactsOutput .= $data['carddata'] . $nl;
             } catch (Exception $e) {
                 continue;
             }
         }
         $response = new DataDownloadResponse($ContactsOutput, $name, 'text/directory');
         return $response;
     }
 }
 /**
  * @NoAdminRequired
  */
 public function deleteContactFromGroup()
 {
     $pIds = $this->params('id');
     $aPid = explode(',', $pIds);
     $fullname = '';
     $addrId = 0;
     foreach ($aPid as $id) {
         $vcard = ContactsApp::getContactVCard($id);
         $property = $vcard->select('CATEGORIES');
         if (count($property) === 0) {
             $oldValue = '';
         } else {
             $property = array_shift($property);
             $oldValue = stripslashes($property->getValue());
         }
         unset($vcard->CATEGORIES);
         VCard::edit($id, $vcard);
         $carddata = VCard::find($id);
         $fullname = strtoupper(substr($carddata['fullname'], 0, 1));
         $addrId = $carddata['addressbookid'];
     }
     $params = ['status' => 'success', 'data' => ['id' => $aPid[0], 'scat' => $oldValue, 'letter' => $fullname, 'count' => count($aPid), 'addrId' => $addrId]];
     $response = new JSONResponse($params);
     return $response;
 }
 /**
  * @NoAdminRequired
  */
 public function deleteContactFromGroup()
 {
     $pId = $this->params('id');
     $vcard = ContactsApp::getContactVCard($pId);
     $property = $vcard->select('CATEGORIES');
     if (count($property) === 0) {
         $oldValue = '';
     } else {
         $property = array_shift($property);
         $oldValue = stripslashes($property->getValue());
     }
     unset($vcard->CATEGORIES);
     VCard::edit($pId, $vcard);
     $carddata = VCard::find($pId);
     $fullname = strtoupper(substr($carddata['fullname'], 0, 1));
     $params = ['status' => 'success', 'data' => ['id' => $pId, 'scat' => $oldValue, 'letter' => $fullname]];
     $response = new JSONResponse($params);
     return $response;
 }