Ejemplo n.º 1
0
 /**
  * @brief construct a vcard in Sabre format
  * @param integer $aid Addressbook Id
  * @param OC_VObject $vcard VCard
  * @return array
  */
 public static function getSabreFormatCard($aid, $vcard)
 {
     /*
      * array return format :
      * array( 'id' => 'bbcca2d1535', 
      *        'permissions' => 32, 
      *        'displayname' => 'Jane Doe', 
      *        'carddata' => $data)
      */
     $FN = (string) $vcard->FN;
     $UID = (string) $vcard->UID;
     $REV = (string) $vcard->REV;
     if (isset($vcard->{'X-URI'})) {
         $URI = (string) $vcard->{'X-URI'};
     } else {
         if (isset($vcard->UID)) {
             $URI = (string) $vcard->UID . '.vcf';
         } else {
             $URI = (string) $vcard->{'X-LDAP-DN'};
         }
     }
     return array('id' => $UID, 'permissions' => \OCP\PERMISSION_ALL, 'displayname' => $FN, 'carddata' => $vcard->serialize(), 'uri' => $URI, 'lastmodified' => $REV);
 }
Ejemplo n.º 2
0
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos($name, 'birthday_') != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             //$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             $vevent->setString('UID', substr(md5(rand() . time()), 0, 10));
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR");
         }
     }
 }