Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 5
0
 /**
  * Extracts all matching contacts with email address and name
  *
  * @param string $term
  * @return array
  */
 public function addBirthdays($userid, $calId)
 {
     if (!$this->contactsManager->isEnabled()) {
         return array();
     }
     $addrBooks = $this->contactsManager->getAddressBooks();
     $aContacts = array();
     foreach ($addrBooks as $key => $addrBook) {
         if (is_integer($key)) {
             $bContacts = \OCA\ContactsPlus\VCard::all($key);
             $aContacts = array_merge($aContacts, $bContacts);
         }
     }
     $sDateFormat = $this->configInfo->getUserValue($this->userId, $this->appName, 'dateformat', 'd-m-Y');
     if ($sDateFormat === 'd-m-Y') {
         $sDateFormat = 'd.m.Y';
     }
     $aResult = array();
     foreach ($aContacts as $contact) {
         $vcard = \Sabre\VObject\Reader::read($contact['carddata']);
         if (isset($vcard->BDAY)) {
             $Birthday = new \DateTime((string) $vcard->BDAY);
             $checkForm = $Birthday->format('d-m-Y');
             $temp = explode('-', $checkForm);
             $getAge = $this->getAge($temp[2], $temp[1], $temp[0]);
             $title = $contact['fullname'];
             $birthdayOutput = $Birthday->format($sDateFormat);
             $aktYear = $Birthday->format('d-m');
             $aktYear = $aktYear . date('-Y');
             $start = new \DateTime($aktYear);
             $end = new \DateTime($aktYear . ' +1 day');
             $vcalendar = new VObject('VCALENDAR');
             $vcalendar->add('PRODID', 'ownCloud Calendar');
             $vcalendar->add('VERSION', '2.0');
             $vevent = new VObject('VEVENT');
             $vcalendar->add($vevent);
             $vevent->setDateTime('CREATED', 'now');
             $vevent->add('DTSTART');
             $vevent->DTSTART->setDateTime($start);
             $vevent->add('DTEND');
             $vevent->DTEND->setDateTime($end);
             $vevent->DTSTART['VALUE'] = 'date';
             $vevent->DTEND['VALUE'] = 'date';
             $vevent->{'RRULE'} = 'FREQ=YEARLY;INTERVAL=1';
             $vevent->{'TRANSP'} = 'TRANSPARENT';
             $vevent->{'SUMMARY'} = (string) $title . ' (' . $getAge . ')';
             $description = (string) $this->l10n->t("Happy Birthday! Born on: ") . $birthdayOutput;
             $vevent->setString('DESCRIPTION', $description);
             $vevent->{'UID'} = substr(md5(rand() . time()), 0, 10);
             $insertid = Object::add($calId, $vcalendar->serialize());
             if ($this->isDuplicate($insertid)) {
                 Object::delete($insertid);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public static function addingDummyContacts($iNum)
 {
     $active_addressbooks = array();
     $active_addressbooks = Addressbook::active(\OCP\USER::getUser());
     $contacts_addressbook = array();
     $ids = array();
     foreach ($active_addressbooks as $addressbook) {
         $ids[] = $addressbook['id'];
     }
     for ($i = 0; $i < $iNum; $i++) {
         //$dummyName=self::generateFnDummy();
         $dummySure = self::generateFnDummy(10);
         $dummyLast = self::generateFnDummy(10);
         $uid = substr(md5(rand() . time()), 0, 10);
         $aid = $ids[0];
         $vcard = new VObject\Component\VCard(array('N' => array($dummySure, $dummyLast, '', '', ''), 'UID' => $uid));
         $vcard->FN = $dummySure . ' ' . $dummyLast;
         $vcard->CATEGORIES = 'familie';
         $vcard->add('TEL', '+1 555 34567 456', array('type' => 'fax'));
         $vcard->add('TEL', '+1 555 34567 457', array('type' => 'voice', 'pref' => 1));
         $vcard->add('EMAIL', '*****@*****.**', array('type' => 'work'));
         $vcard->add('EMAIL', '*****@*****.**', array('type' => 'private', 'pref' => 1));
         $id = VCard::add($aid, $vcard, null, true);
     }
 }
Ejemplo n.º 7
0
 /**
  * @NoAdminRequired
  */
 public function deletePhoto()
 {
     $id = $this->params('id');
     $vcard = ContactsApp::getContactVCard($id);
     unset($vcard->PHOTO);
     VCard::edit($id, $vcard);
     $result = ['status' => 'success', 'data' => ['id' => $id]];
     $response = new JSONResponse();
     $response->setData($result);
     return $response;
 }
Ejemplo n.º 8
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function exportBirthdays()
 {
     $bookid = $this->params('aid');
     $bookid = isset($bookid) ? $bookid : null;
     if (!is_null($bookid)) {
         $addressbook = Addressbook::find($bookid);
         $aDefNArray = array('0' => 'fname', '1' => 'lname', '3' => 'title', '4' => '');
         foreach (VCard::all($bookid) as $contact) {
             try {
                 $vcard = VObject\Reader::read($contact['carddata']);
             } catch (Exception $e) {
                 continue;
             }
             $birthday = $vcard->BDAY;
             if ((string) $birthday) {
                 $details = VCard::structureContact($vcard);
                 $BirthdayTemp = new \DateTime($birthday);
                 $checkForm = $BirthdayTemp->format('d-m-Y');
                 $temp = explode('-', $checkForm);
                 $getAge = $this->getAgeCalc($temp[2], $temp[1], $temp[0]);
                 //$getAge=$BirthdayTemp->format('d-m-Y');
                 $title = isset($vcard->FN) ? strtr($vcard->FN->getValue(), array('\\,' => ',', '\\;' => ';')) : '';
                 $sNameOutput = '';
                 if (isset($details['N'][0]['value']) && count($details['N'][0]['value']) > 0) {
                     foreach ($details['N'][0]['value'] as $key => $val) {
                         if ($val != '') {
                             $aNameOutput[$aDefNArray[$key]] = $val;
                         }
                     }
                     //$sNameOutput=isset($aNameOutput['title'])?$aNameOutput['title'].' ':'';
                     $sNameOutput .= isset($aNameOutput['lname']) ? $aNameOutput['lname'] . ' ' : '';
                     $sNameOutput .= isset($aNameOutput['fname']) ? $aNameOutput['fname'] . ' ' : '';
                     unset($aNameOutput);
                 }
                 if ($sNameOutput == '') {
                     $sNameOutput = $title;
                 }
                 $sTitle1 = (string) $this->l10n->t('%1$s (%2$s)', array($sNameOutput, $getAge));
                 $aktYear = $BirthdayTemp->format('d-m');
                 $aktYear = $aktYear . date('-Y');
                 $start = new \DateTime($aktYear);
                 $end = new \DateTime($aktYear . ' +1 day');
                 $vcalendar = new VObject\Component\VCalendar();
                 $vevent = $vcalendar->createComponent('VEVENT');
                 $vevent->add('DTSTART');
                 $vevent->DTSTART->setDateTime($start);
                 $vevent->DTSTART['VALUE'] = 'date';
                 $vevent->add('DTEND');
                 $vevent->DTEND->setDateTime($end);
                 $vevent->DTEND['VALUE'] = 'date';
                 $vevent->{'SUMMARY'} = (string) $sTitle1;
                 $vevent->{'UID'} = substr(md5(rand() . time()), 0, 10);
                 $params['events'][] = $vevent->serialize();
             }
         }
         if (is_array($params['events'])) {
             $return = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud Calendar " . \OCP\App::getAppVersion('calendar') . "\nX-WR-CALNAME: export-bday-" . $bookid . "\n";
             foreach ($params['events'] as $event) {
                 $return .= $event;
             }
             $return .= "END:VCALENDAR";
             $name = str_replace(' ', '_', $addressbook['displayname']) . '_birthdays' . '.ics';
             $response = new DataDownloadResponse($return, $name, 'text/calendar');
             return $response;
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Deletes a card
  *
  * @param mixed $addressbookid
  * @param string $carduri
  * @return bool
  */
 public function deleteCard($addressbookid, $carduri)
 {
     return VCard::deleteFromDAVData($addressbookid, $carduri);
 }
Ejemplo n.º 10
0
 /**
  * @NoAdminRequired
  */
 public function prepareIosGroups()
 {
     $pGroups = $this->params('agroups');
     $pAddrBookId = $this->params('aid');
     if ($pAddrBookId > 0) {
         $existIosGroups = ContactsApp::getIosGroups();
         $iCountExist = count($pGroups);
         $iCountIosExist = count($existIosGroups);
         if ($iCountExist < $iCountIosExist) {
             //Group Delete
             foreach ($existIosGroups as $key => $value) {
                 if (!array_key_exists($key, $pGroups)) {
                     VCard::delete($value['id']);
                 }
             }
         }
         if ($iCountExist > $iCountIosExist) {
             //Group Added
             $newGroup = array();
             foreach ($pGroups as $key => $value) {
                 if (!array_key_exists($key, $existIosGroups)) {
                     $newGroup[] = $key;
                 }
             }
             foreach ($newGroup as $val) {
                 $uid = substr(md5(rand() . time()), 0, 10);
                 $appinfo = \OCP\App::getAppInfo($this->appName);
                 $appversion = \OCP\App::getAppVersion($this->appName);
                 $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN';
                 $vcard = new \Sabre\VObject\Component\VCard(array('PRODID' => $prodid, 'VERSION' => '3.0', 'UID' => $uid));
                 $vcard->N = $val;
                 $vcard->FN = $val;
                 //X-ADDRESSBOOKSERVER-KIND:group
                 $vcard->{'X-ADDRESSBOOKSERVER-KIND'} = 'group';
                 $id = VCard::add($pAddrBookId, $vcard, null, true);
             }
         }
         $params = ['status' => 'success'];
         $response = new JSONResponse($params);
         return $response;
     }
     //END $addrBk
 }
Ejemplo n.º 11
0
 public static function getBirthdayEvents($params)
 {
     if (\OCP\Config::getUserValue(\OCP\USER::getUser(), 'calendarplus', 'calendar_birthday_' . \OCP\USER::getUser())) {
         $name = $params['calendar_id'];
         if (strpos($name, 'birthday_') != 0) {
             return;
         }
         $info = explode('_', $name);
         $aid = $info[1];
         $aDefNArray = array('0' => 'fname', '1' => 'lname', '3' => 'title', '4' => '');
         foreach (Addressbook::all($aid) as $addressbook) {
             foreach (VCard::all($addressbook['id']) as $contact) {
                 try {
                     $vcard = VObject\Reader::read($contact['carddata']);
                 } catch (Exception $e) {
                     continue;
                 }
                 $birthday = $vcard->BDAY;
                 if ((string) $birthday) {
                     $details = VCard::structureContact($vcard);
                     $BirthdayTemp = new \DateTime($birthday);
                     $checkForm = $BirthdayTemp->format('d-m-Y');
                     $temp = explode('-', $checkForm);
                     $getAge = self::getAge($temp[2], $temp[1], $temp[0]);
                     //$getAge=$BirthdayTemp->format('d-m-Y');
                     $title = isset($vcard->FN) ? strtr($vcard->FN->getValue(), array('\\,' => ',', '\\;' => ';')) : '';
                     $sNameOutput = '';
                     if (isset($details['N'][0]['value']) && count($details['N'][0]['value']) > 0) {
                         foreach ($details['N'][0]['value'] as $key => $val) {
                             if ($val != '') {
                                 $aNameOutput[$aDefNArray[$key]] = $val;
                             }
                         }
                         //$sNameOutput=isset($aNameOutput['title'])?$aNameOutput['title'].' ':'';
                         $sNameOutput .= isset($aNameOutput['lname']) ? $aNameOutput['lname'] . ' ' : '';
                         $sNameOutput .= isset($aNameOutput['fname']) ? $aNameOutput['fname'] . ' ' : '';
                         unset($aNameOutput);
                     }
                     if ($sNameOutput == '') {
                         $sNameOutput = $title;
                     }
                     $sTitle1 = (string) App::$l10n->t('%1$s (%2$s)', array($sNameOutput, $getAge));
                     $aktYear = $BirthdayTemp->format('d-m');
                     $aktYear = $aktYear . date('-Y');
                     $start = new \DateTime($aktYear);
                     $end = new \DateTime($aktYear . ' +1 day');
                     $vcalendar = new VObject\Component\VCalendar();
                     $vevent = $vcalendar->createComponent('VEVENT');
                     $vevent->add('DTSTART');
                     $vevent->DTSTART->setDateTime($start);
                     $vevent->DTSTART['VALUE'] = 'date';
                     $vevent->add('DTEND');
                     $vevent->DTEND->setDateTime($end);
                     $vevent->DTEND['VALUE'] = 'date';
                     $vevent->{'SUMMARY'} = (string) $sTitle1;
                     $vevent->{'UID'} = substr(md5(rand() . time()), 0, 10);
                     // DESCRIPTION?
                     $aktYear1 = $BirthdayTemp->format('-m-d');
                     $aktYear1 = date('Y') . $aktYear1;
                     $params['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'calendarid' => $params['calendar_id'], 'privat' => false, 'bday' => true, 'shared' => false, 'isalarm' => false, 'summary' => $sTitle1, 'start' => $aktYear1, 'allDay' => true, 'startlist' => $aktYear1, 'editable' => false, 'className' => 'birthdayevent', 'startEditable ' => false, 'durationEditable ' => false);
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 12
0
 /**
  * @NoAdminRequired
  */
 public function addProbertyToContact()
 {
     $cardId = $this->params('cardId');
     $param = trim(strip_tags($this->params('param')));
     $value = trim(strip_tags($this->params('value')));
     $vcard = ContactsApp::getContactVCard($cardId);
     $vcardMember = 'urn:uuid:' . $vcard->{'UID'};
     $property = $vcard->select($param);
     if (count($property) === 0) {
         //Neu
         $vcard->add($param, $value);
         $iNumber = 1;
     } else {
         $property = array_shift($property);
         $oldValue = stripslashes($property->getValue());
         if (!stristr($oldValue, $value)) {
             $newValue = (string) $oldValue . ',' . $value;
             $property->setValue((string) $newValue);
             $iNumber = 1;
         } else {
             $iNumber = 0;
         }
     }
     VCard::edit($cardId, $vcard);
     //IOS Support $vcardMember
     $iosSupport = $this->configInfo->getUserValue($this->userId, $this->appName, 'iossupport');
     if ($param === 'CATEGORIES' && $iosSupport) {
         if (!is_null($vcard) && !isset($vcard->REV)) {
             $rev = new \DateTime('@' . $groupData['lastmodified']);
             $vcard->REV = $rev->format(\DateTime::W3C);
         }
         $paramsGroupMembers = array();
         $iosGroupMember = $vcard->{'X-ADDRESSBOOKSERVER-MEMBER'};
         $bExist = false;
         if ($iosGroupMember) {
             foreach ($iosGroupMember as $key => $param) {
                 if ($param === $vcardMember) {
                     $bExist = true;
                 }
             }
         } else {
             $vcard->add('X-ADDRESSBOOKSERVER-MEMBER', $vcardMember);
         }
         if (!$bExist) {
             $vcard->add('X-ADDRESSBOOKSERVER-MEMBER', $vcardMember);
         }
         VCard::edit($cardId, $vcard);
     }
     if ($param === 'CATEGORIES') {
         $backgroundColor = ContactsApp::genColorCodeFromText(trim($value));
         $color = ContactsApp::generateTextColor($backgroundColor);
         $aCat['name'] = $value;
         $aCat['color'] = $color;
         $aCat['bgcolor'] = $backgroundColor;
     }
     $params = ['status' => 'success', 'data' => ['cardid' => $cardId, 'iCounter' => $iNumber, 'newcat' => $aCat]];
     $response = new JSONResponse($params);
     return $response;
 }