public function createCalendar() { $record = $this->record; $this->log->debug(__CLASS__ . '::' . __METHOD__ . ' | Start CRM ID:' . $record['crmid']); $calType = $record['activitytype'] == 'Task' ? 'VTODO' : 'VEVENT'; $endField = $this->getEndFieldName($calType); $vcalendar = new Sabre\VObject\Component\VCalendar(); $vcalendar->PRODID = '-//' . self::PRODID . ' V' . vglobal('YetiForce_current_version') . '//'; $start = $record['date_start'] . ' ' . $record['time_start']; $end = $record['due_date'] . ' ' . $record['time_end']; if ($record['allday']) { $startDT = new \DateTime($start); $DTSTART = $vcalendar->createProperty('DTSTART', $startDT); $endDT = new DateTime($end); $endDT->modify('+1 day'); $DTEND = $vcalendar->createProperty($endField, $endDT); $DTEND['VALUE'] = 'DATE'; $DTSTART['VALUE'] = 'DATE'; } else { $startDT = $DTSTART = new \DateTime($start); $endDT = $DTEND = new \DateTime($end); } $cal = $vcalendar->createComponent($calType); //$cal->add($vcalendar->createProperty('CREATED', new \DateTime($record['createdtime']))); //$cal->add($vcalendar->createProperty('LAST-MODIFIED', new \DateTime($record['modifiedtime']))); $cal->add($vcalendar->createProperty('SUMMARY', $record['subject'])); $cal->add($vcalendar->createProperty('DTSTART', $DTSTART)); $cal->add($vcalendar->createProperty($endField, $DTEND)); $cal->add($vcalendar->createProperty('CLASS', $record['visibility'] == 'Private' ? 'PRIVATE' : 'PUBLIC')); $cal->add($vcalendar->createProperty('PRIORITY', $this->getPriority($record['priority'], false))); $status = $this->getStatus($record['status'], false); if ($status) { $cal->add($vcalendar->createProperty('STATUS', $status, false)); } $state = $this->getState($record['state'], false); if ($state) { $cal->add($vcalendar->createProperty('TRANSP', $state, false)); } if (!empty($record['location'])) { $cal->add($vcalendar->createProperty('LOCATION', $record['location'])); } if (!empty($record['description'])) { $cal->add($vcalendar->createProperty('DESCRIPTION', $record['description'])); } $vcalendar->add($cal); $dtz = date_default_timezone_get(); $vTimeZone = self::getVTimeZone($vcalendar, $dtz, $startDT->getTimestamp(), $endDT->getTimestamp()); $vcalendar->add($vTimeZone); $calendarData = $vcalendar->serialize(); $modifiedtime = strtotime($record['modifiedtime']); $extraData = $this->getDenormalizedData($calendarData); $calUri = date('Y-m-d\\THis') . '-' . $record['crmid']; $stmt = $this->pdo->prepare('INSERT INTO dav_calendarobjects (calendarid, uri, calendardata, lastmodified, etag, size, componenttype, firstoccurence, lastoccurence, uid, crmid) VALUES (?,?,?,?,?,?,?,?,?,?,?)'); $stmt->execute([$this->calendarId, $calUri . '.ics', $calendarData, $modifiedtime, $extraData['etag'], $extraData['size'], $extraData['componentType'], $extraData['firstOccurence'], $extraData['lastOccurence'], $calUri, $record['crmid']]); $this->addChange($calUri, 1); $this->log->debug(__CLASS__ . '::' . __METHOD__ . ' | End'); }
/** * beforeGetProperties * * This method handler is invoked before any after properties for a * resource are fetched. This allows us to add in any CalDAV specific * properties. * * @param string $path * @param \Sabre\DAV\INode $node * @param array $requestedProperties * @param array $returnedProperties * @return void */ public function beforeGetProperties($path, \Sabre\DAV\INode $node, &$requestedProperties, &$returnedProperties) { if ($node instanceof \Sabre\CalDAV\ICalendar || $node instanceof Calendar_Frontend_WebDAV) { $vcalendar = new \Sabre\VObject\Component\VCalendar(); $property = '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}default-alarm-vevent-datetime'; if (in_array($property, $requestedProperties)) { unset($requestedProperties[array_search($property, $requestedProperties)]); $valarm = $vcalendar->create('VALARM'); $valarm->add('ACTION', 'NONE'); $valarm->add('TRIGGER', '19760401T005545Z', array('VALUE' => 'DATE-TIME')); $valarm->add('UID', 'E35C3EB2-4DC1-4223-AA5D-B4B491F2C111'); // Taking out \r to not screw up the xml output $returnedProperties[200][$property] = str_replace("\r", "", $valarm->serialize()); } $property = '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}default-alarm-vevent-date'; if (in_array($property, $requestedProperties)) { unset($requestedProperties[array_search($property, $requestedProperties)]); $valarm = $vcalendar->create('VALARM'); // $valarm->add('ACTION', 'AUDIO'); // $valarm->add('ATTACH', 'Basso', array('VALUE' => 'URI')); // $valarm->add('TRIGGER', '-PT15H'); $valarm->add('ACTION', 'NONE'); $valarm->add('TRIGGER', '19760401T005545Z', array('VALUE' => 'DATE-TIME')); $valarm->add('UID', '17DC9682-230E-47D6-A035-EEAB602B1229'); // Taking out \r to not screw up the xml output $returnedProperties[200][$property] = str_replace("\r", "", $valarm->serialize()); } $property = '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}default-alarm-vtodo-datetime'; if (in_array($property, $requestedProperties)) { unset($requestedProperties[array_search($property, $requestedProperties)]); $valarm = $vcalendar->create('VALARM'); $valarm->add('ACTION', 'NONE'); $valarm->add('TRIGGER', '19760401T005545Z', array('VALUE' => 'DATE-TIME')); $valarm->add('UID', 'D35C3EB2-4DC1-4223-AA5D-B4B491F2C111'); // Taking out \r to not screw up the xml output $returnedProperties[200][$property] = str_replace("\r", "", $valarm->serialize()); } $property = '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}default-alarm-vtodo-date'; if (in_array($property, $requestedProperties)) { unset($requestedProperties[array_search($property, $requestedProperties)]); $valarm = $vcalendar->create('VALARM'); // $valarm->add('ACTION', 'AUDIO'); // $valarm->add('ATTACH', 'Basso', array('VALUE' => 'URI')); // $valarm->add('TRIGGER', '-PT15H'); $valarm->add('ACTION', 'NONE'); $valarm->add('TRIGGER', '19760401T005545Z', array('VALUE' => 'DATE-TIME')); $valarm->add('UID', '27DC9682-230E-47D6-A035-EEAB602B1229'); // Taking out \r to not screw up the xml output $returnedProperties[200][$property] = str_replace("\r", "", $valarm->serialize()); } } }
/** * convert Tinebase_Record_RecordSet to Sabre\VObject\Component * * @param Tinebase_Record_RecordSet $_records * @return Sabre\VObject\Component */ public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records) { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Events: ' . print_r($_records->toArray(), true)); } // required vcalendar fields $version = Tinebase_Application::getInstance()->getApplicationByName('Calendar')->version; $vcalendar = new \Sabre\VObject\Component\VCalendar(array('PRODID' => "-//tine20.com//Tine 2.0 Calendar V{$version}//EN", 'VERSION' => '2.0', 'CALSCALE' => 'GREGORIAN')); if (isset($this->_method)) { $vcalendar->add('METHOD', $this->_method); } $originatorTz = $_records->getFirstRecord() ? $_records->getFirstRecord()->originator_tz : NULL; if (empty($originatorTz)) { throw new Tinebase_Exception_Record_Validation('originator_tz needed for conversion to Sabre\\VObject\\Component'); } try { $vcalendar->add(new Sabre_VObject_Component_VTimezone($originatorTz)); } catch (Exception $e) { Tinebase_Exception::log($e); throw new Tinebase_Exception_Record_Validation('Bad Timezone: ' . $originatorTz); } foreach ($_records as $_record) { $this->_convertCalendarModelEvent($vcalendar, $_record); if ($_record->exdate instanceof Tinebase_Record_RecordSet) { $_record->exdate->addIndices(array('is_deleted')); $eventExceptions = $_record->exdate->filter('is_deleted', false); foreach ($eventExceptions as $eventException) { $this->_convertCalendarModelEvent($vcalendar, $eventException, $_record); } } } $this->_afterFromTine20Model($vcalendar); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' card ' . $vcalendar->serialize()); } return $vcalendar; }
function post() { if (!local_channel() || get_pconfig(local_channel(), 'cdav', 'enabled') != 1) { return; } $channel = \App::get_channel(); $principalUri = 'principals/' . $channel['channel_address']; if (!cdav_principal($principalUri)) { return; } if (\DBA::$dba && \DBA::$dba->connected) { $pdovars = \DBA::$dba->pdo_get(); } else { killme(); } $pdo = new \PDO($pdovars[0], $pdovars[1], $pdovars[2]); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); require_once 'vendor/autoload.php'; if (argc() == 2 && argv(1) === 'calendar') { $caldavBackend = new \Sabre\CalDAV\Backend\PDO($pdo); $calendars = $caldavBackend->getCalendarsForUser($principalUri); //create new calendar if ($_REQUEST['{DAV:}displayname'] && $_REQUEST['create']) { do { $duplicate = false; $calendarUri = random_string(40); $r = q("SELECT uri FROM calendarinstances WHERE principaluri = '%s' AND uri = '%s' LIMIT 1", dbesc($principalUri), dbesc($calendarUri)); if (count($r)) { $duplicate = true; } } while ($duplicate == true); $properties = ['{DAV:}displayname' => $_REQUEST['{DAV:}displayname'], '{http://apple.com/ns/ical/}calendar-color' => $_REQUEST['color'], '{urn:ietf:params:xml:ns:caldav}calendar-description' => $channel['channel_name']]; $id = $caldavBackend->createCalendar($principalUri, $calendarUri, $properties); // set new calendar to be visible set_pconfig(local_channel(), 'cdav_calendar', $id[0], 1); } //create new calendar object via ajax request if ($_REQUEST['submit'] === 'create_event' && $_REQUEST['title'] && $_REQUEST['target'] && $_REQUEST['dtstart']) { $id = explode(':', $_REQUEST['target']); if (!cdav_perms($id[0], $calendars, true)) { return; } $title = $_REQUEST['title']; $dtstart = new \DateTime($_REQUEST['dtstart']); if ($_REQUEST['dtend']) { $dtend = new \DateTime($_REQUEST['dtend']); } $description = $_REQUEST['description']; $location = $_REQUEST['location']; do { $duplicate = false; $objectUri = random_string(40) . '.ics'; $r = q("SELECT uri FROM calendarobjects WHERE calendarid = %s AND uri = '%s' LIMIT 1", intval($id[0]), dbesc($objectUri)); if (count($r)) { $duplicate = true; } } while ($duplicate == true); $vcalendar = new \Sabre\VObject\Component\VCalendar(['VEVENT' => ['SUMMARY' => $title, 'DTSTART' => $dtstart]]); if ($dtend) { $vcalendar->VEVENT->add('DTEND', $dtend); } if ($description) { $vcalendar->VEVENT->add('DESCRIPTION', $description); } if ($location) { $vcalendar->VEVENT->add('LOCATION', $location); } $calendarData = $vcalendar->serialize(); $caldavBackend->createCalendarObject($id, $objectUri, $calendarData); killme(); } //edit calendar name and color if ($_REQUEST['{DAV:}displayname'] && $_REQUEST['edit'] && $_REQUEST['id']) { $id = explode(':', $_REQUEST['id']); if (!cdav_perms($id[0], $calendars)) { return; } $mutations = ['{DAV:}displayname' => $_REQUEST['{DAV:}displayname'], '{http://apple.com/ns/ical/}calendar-color' => $_REQUEST['color']]; $patch = new \Sabre\DAV\PropPatch($mutations); $caldavBackend->updateCalendar($id, $patch); $patch->commit(); } //edit calendar object via ajax request if ($_REQUEST['submit'] === 'update_event' && $_REQUEST['uri'] && $_REQUEST['title'] && $_REQUEST['target'] && $_REQUEST['dtstart']) { $id = explode(':', $_REQUEST['target']); if (!cdav_perms($id[0], $calendars, true)) { return; } $uri = $_REQUEST['uri']; $title = $_REQUEST['title']; $dtstart = new \DateTime($_REQUEST['dtstart']); $dtend = $_REQUEST['dtend'] ? new \DateTime($_REQUEST['dtend']) : ''; $description = $_REQUEST['description']; $location = $_REQUEST['location']; $object = $caldavBackend->getCalendarObject($id, $uri); $vcalendar = \Sabre\VObject\Reader::read($object['calendardata']); if ($title) { $vcalendar->VEVENT->SUMMARY = $title; } if ($dtstart) { $vcalendar->VEVENT->DTSTART = $dtstart; } if ($dtend) { $vcalendar->VEVENT->DTEND = $dtend; } else { unset($vcalendar->VEVENT->DTEND); } if ($description) { $vcalendar->VEVENT->DESCRIPTION = $description; } if ($location) { $vcalendar->VEVENT->LOCATION = $location; } $calendarData = $vcalendar->serialize(); $caldavBackend->updateCalendarObject($id, $uri, $calendarData); killme(); } //delete calendar object via ajax request if ($_REQUEST['delete'] && $_REQUEST['uri'] && $_REQUEST['target']) { $id = explode(':', $_REQUEST['target']); if (!cdav_perms($id[0], $calendars, true)) { return; } $uri = $_REQUEST['uri']; $caldavBackend->deleteCalendarObject($id, $uri); killme(); } //edit calendar object date/timeme via ajax request (drag and drop) if ($_REQUEST['update'] && $_REQUEST['id'] && $_REQUEST['uri']) { $id = [$_REQUEST['id'][0], $_REQUEST['id'][1]]; if (!cdav_perms($id[0], $calendars, true)) { return; } $uri = $_REQUEST['uri']; $dtstart = new \DateTime($_REQUEST['dtstart']); $dtend = $_REQUEST['dtend'] ? new \DateTime($_REQUEST['dtend']) : ''; $object = $caldavBackend->getCalendarObject($id, $uri); $vcalendar = \Sabre\VObject\Reader::read($object['calendardata']); if ($dtstart) { $vcalendar->VEVENT->DTSTART = $dtstart; } if ($dtend) { $vcalendar->VEVENT->DTEND = $dtend; } else { unset($vcalendar->VEVENT->DTEND); } $calendarData = $vcalendar->serialize(); $caldavBackend->updateCalendarObject($id, $uri, $calendarData); killme(); } //share a calendar - this only works on local system (with channels on the same server) if ($_REQUEST['sharee'] && $_REQUEST['share']) { $id = [intval($_REQUEST['calendarid']), intval($_REQUEST['instanceid'])]; if (!cdav_perms($id[0], $calendars)) { return; } $hash = $_REQUEST['sharee']; $sharee_arr = channelx_by_hash($hash); $sharee = new \Sabre\DAV\Xml\Element\Sharee(); $sharee->href = 'mailto:' . $sharee_arr['channel_hash']; $sharee->principal = 'principals/' . $sharee_arr['channel_address']; $sharee->access = intval($_REQUEST['access']); $sharee->properties = ['{DAV:}displayname' => $channel['channel_name']]; $caldavBackend->updateInvites($id, [$sharee]); } } if (argc() >= 2 && argv(1) === 'addressbook') { $carddavBackend = new \Sabre\CardDAV\Backend\PDO($pdo); $addressbooks = $carddavBackend->getAddressBooksForUser($principalUri); //create new addressbook if ($_REQUEST['{DAV:}displayname'] && $_REQUEST['create']) { do { $duplicate = false; $addressbookUri = random_string(20); $r = q("SELECT uri FROM addressbooks WHERE principaluri = '%s' AND uri = '%s' LIMIT 1", dbesc($principalUri), dbesc($addressbookUri)); if (count($r)) { $duplicate = true; } } while ($duplicate == true); $properties = ['{DAV:}displayname' => $_REQUEST['{DAV:}displayname']]; $carddavBackend->createAddressBook($principalUri, $addressbookUri, $properties); } //edit addressbook if ($_REQUEST['{DAV:}displayname'] && $_REQUEST['edit'] && intval($_REQUEST['id'])) { $id = $_REQUEST['id']; if (!cdav_perms($id, $addressbooks)) { return; } $mutations = ['{DAV:}displayname' => $_REQUEST['{DAV:}displayname']]; $patch = new \Sabre\DAV\PropPatch($mutations); $carddavBackend->updateAddressBook($id, $patch); $patch->commit(); } //create addressbook card if ($_REQUEST['create'] && $_REQUEST['target'] && $_REQUEST['fn']) { $id = $_REQUEST['target']; do { $duplicate = false; $uri = random_string(40) . '.vcf'; $r = q("SELECT uri FROM cards WHERE addressbookid = %s AND uri = '%s' LIMIT 1", intval($id), dbesc($uri)); if (count($r)) { $duplicate = true; } } while ($duplicate == true); //TODO: this mostly duplictes the procedure in update addressbook card. should move this part to a function to avoid duplication $fn = $_REQUEST['fn']; $vcard = new \Sabre\VObject\Component\VCard(['FN' => $fn, 'N' => array_reverse(explode(' ', $fn))]); $org = $_REQUEST['org']; if ($org) { $vcard->ORG = $org; } $title = $_REQUEST['title']; if ($title) { $vcard->TITLE = $title; } $tel = $_REQUEST['tel']; $tel_type = $_REQUEST['tel_type']; if ($tel) { $i = 0; foreach ($tel as $item) { if ($item) { $vcard->add('TEL', $item, ['type' => $tel_type[$i]]); } $i++; } } $email = $_REQUEST['email']; $email_type = $_REQUEST['email_type']; if ($email) { $i = 0; foreach ($email as $item) { if ($item) { $vcard->add('EMAIL', $item, ['type' => $email_type[$i]]); } $i++; } } $impp = $_REQUEST['impp']; $impp_type = $_REQUEST['impp_type']; if ($impp) { $i = 0; foreach ($impp as $item) { if ($item) { $vcard->add('IMPP', $item, ['type' => $impp_type[$i]]); } $i++; } } $url = $_REQUEST['url']; $url_type = $_REQUEST['url_type']; if ($url) { $i = 0; foreach ($url as $item) { if ($item) { $vcard->add('URL', $item, ['type' => $url_type[$i]]); } $i++; } } $adr = $_REQUEST['adr']; $adr_type = $_REQUEST['adr_type']; if ($adr) { $i = 0; foreach ($adr as $item) { if ($item) { $vcard->add('ADR', $item, ['type' => $adr_type[$i]]); } $i++; } } $note = $_REQUEST['note']; if ($note) { $vcard->NOTE = $note; } $cardData = $vcard->serialize(); $carddavBackend->createCard($id, $uri, $cardData); } //edit addressbook card if ($_REQUEST['update'] && $_REQUEST['uri'] && $_REQUEST['target']) { $id = $_REQUEST['target']; if (!cdav_perms($id, $addressbooks)) { return; } $uri = $_REQUEST['uri']; $object = $carddavBackend->getCard($id, $uri); $vcard = \Sabre\VObject\Reader::read($object['carddata']); $fn = $_REQUEST['fn']; if ($fn) { $vcard->FN = $fn; $vcard->N = array_reverse(explode(' ', $fn)); } $org = $_REQUEST['org']; if ($org) { $vcard->ORG = $org; } else { unset($vcard->ORG); } $title = $_REQUEST['title']; if ($title) { $vcard->TITLE = $title; } else { unset($vcard->TITLE); } $tel = $_REQUEST['tel']; $tel_type = $_REQUEST['tel_type']; if ($tel) { $i = 0; unset($vcard->TEL); foreach ($tel as $item) { if ($item) { $vcard->add('TEL', $item, ['type' => $tel_type[$i]]); } $i++; } } else { unset($vcard->TEL); } $email = $_REQUEST['email']; $email_type = $_REQUEST['email_type']; if ($email) { $i = 0; unset($vcard->EMAIL); foreach ($email as $item) { if ($item) { $vcard->add('EMAIL', $item, ['type' => $email_type[$i]]); } $i++; } } else { unset($vcard->EMAIL); } $impp = $_REQUEST['impp']; $impp_type = $_REQUEST['impp_type']; if ($impp) { $i = 0; unset($vcard->IMPP); foreach ($impp as $item) { if ($item) { $vcard->add('IMPP', $item, ['type' => $impp_type[$i]]); } $i++; } } else { unset($vcard->IMPP); } $url = $_REQUEST['url']; $url_type = $_REQUEST['url_type']; if ($url) { $i = 0; unset($vcard->URL); foreach ($url as $item) { if ($item) { $vcard->add('URL', $item, ['type' => $url_type[$i]]); } $i++; } } else { unset($vcard->URL); } $adr = $_REQUEST['adr']; $adr_type = $_REQUEST['adr_type']; if ($adr) { $i = 0; unset($vcard->ADR); foreach ($adr as $item) { if ($item) { $vcard->add('ADR', $item, ['type' => $adr_type[$i]]); } $i++; } } else { unset($vcard->ADR); } $note = $_REQUEST['note']; if ($note) { $vcard->NOTE = $note; } else { unset($vcard->NOTE); } $cardData = $vcard->serialize(); $carddavBackend->updateCard($id, $uri, $cardData); } //delete addressbook card if ($_REQUEST['delete'] && $_REQUEST['uri'] && $_REQUEST['target']) { $id = $_REQUEST['target']; if (!cdav_perms($id, $addressbooks)) { return; } $uri = $_REQUEST['uri']; $carddavBackend->deleteCard($id, $uri); } } //Import calendar or addressbook if ($_FILES && array_key_exists('userfile', $_FILES) && intval($_FILES['userfile']['size']) && $_REQUEST['target']) { $src = @file_get_contents($_FILES['userfile']['tmp_name']); if ($src) { if ($_REQUEST['c_upload']) { $id = explode(':', $_REQUEST['target']); $ext = 'ics'; $table = 'calendarobjects'; $column = 'calendarid'; $objects = new \Sabre\VObject\Splitter\ICalendar($src); $profile = \Sabre\VObject\Node::PROFILE_CALDAV; $backend = new \Sabre\CalDAV\Backend\PDO($pdo); } if ($_REQUEST['a_upload']) { $id[] = intval($_REQUEST['target']); $ext = 'vcf'; $table = 'cards'; $column = 'addressbookid'; $objects = new \Sabre\VObject\Splitter\VCard($src); $profile = \Sabre\VObject\Node::PROFILE_CARDDAV; $backend = new \Sabre\CardDAV\Backend\PDO($pdo); } while ($object = $objects->getNext()) { if ($_REQUEST['a_upload']) { $object = $object->convert(\Sabre\VObject\Document::VCARD40); } $ret = $object->validate($profile & \Sabre\VObject\Node::REPAIR); //level 3 Means that the document is invalid, //level 2 means a warning. A warning means it's valid but it could cause interopability issues, //level 1 means that there was a problem earlier, but the problem was automatically repaired. if ($ret[0]['level'] < 3) { do { $duplicate = false; $objectUri = random_string(40) . '.' . $ext; $r = q("SELECT uri FROM {$table} WHERE {$column} = %d AND uri = '%s' LIMIT 1", dbesc($id[0]), dbesc($objectUri)); if (count($r)) { $duplicate = true; } } while ($duplicate == true); if ($_REQUEST['c_upload']) { $backend->createCalendarObject($id, $objectUri, $object->serialize()); } if ($_REQUEST['a_upload']) { $backend->createCard($id[0], $objectUri, $object->serialize()); } } else { if ($_REQUEST['c_upload']) { notice('<strong>' . t('INVALID EVENT DISMISSED!') . '</strong>' . EOL . '<strong>' . t('Summary: ') . '</strong>' . ($object->VEVENT->SUMMARY ? $object->VEVENT->SUMMARY : t('Unknown')) . EOL . '<strong>' . t('Date: ') . '</strong>' . ($object->VEVENT->DTSTART ? $object->VEVENT->DTSTART : t('Unknown')) . EOL . '<strong>' . t('Reason: ') . '</strong>' . $ret[0]['message'] . EOL); } if ($_REQUEST['a_upload']) { notice('<strong>' . t('INVALID CARD DISMISSED!') . '</strong>' . EOL . '<strong>' . t('Name: ') . '</strong>' . ($object->FN ? $object->FN : t('Unknown')) . EOL . '<strong>' . t('Reason: ') . '</strong>' . $ret[0]['message'] . EOL); } } } } @unlink($src); } }
public static function createVCalendarFromRequest($request) { $vcalendar = new \Sabre\VObject\Component\VCalendar(); $vcalendar->PRODID = 'ownCloud Calendar'; $vcalendar->VERSION = '2.0'; $vtodo = $vcalendar->createComponent('VTODO'); $vcalendar->add($vtodo); $vtodo->CREATED = new \DateTime('now', new \DateTimeZone('UTC')); $vtodo->UID = \Sabre\VObject\UUIDUtil::getUUID(); return self::updateVCalendarFromRequest($request, $vcalendar); }
/** * @dataProvider values */ function testGetNormalizedValue($expected, $input) { $vobj = new \Sabre\VObject\Component\VCalendar(); $property = $vobj->add('ATTENDEE', $input); $this->assertEquals($expected, $property->getNormalizedValue()); }
<?php /** * @var Termin[] $alle_termine */ Header("Content-Type: text/calendar"); $vcalendar = new \Sabre\VObject\Component\VCalendar(); foreach ($alle_termine as $curr_termin) { $vcalendar->add('VEVENT', $curr_termin->getVEventParams()); } echo $vcalendar->serialize();
/** * Generate an event to show in the calendar * * @return \Sabre\VObject\Component\VCalendar|null */ public function getBirthdayEvent() { if (!isset($this->BDAY)) { return null; } $birthday = $this->BDAY; if ((string) $birthday) { $title = str_replace('{name}', strtr((string) $this->FN, array('\\,' => ',', '\\;' => ';')), App::$l10n->t('{name}\'s Birthday')); try { $date = new \DateTime($birthday); } catch (Exception $e) { return null; } $vCal = new \Sabre\VObject\Component\VCalendar(); $vCal->VERSION = '2.0'; $vEvent = $vCal->createComponent('VEVENT'); $vEvent->add('DTSTART'); $vEvent->DTSTART->setDateTime($date); $vEvent->DTSTART['VALUE'] = 'DATE'; $vEvent->add('DTEND'); $date->add(new \DateInterval('P1D')); $vEvent->DTEND->setDateTime($date); $vEvent->DTEND['VALUE'] = 'DATE'; $lm = new \DateTime('@' . $this->lastModified()); $lm->setTimeZone(new \DateTimeZone('UTC')); $vEvent->DTSTAMP->setDateTime($lm); $vEvent->{'UID'} = $this->UID; $vEvent->{'RRULE'} = 'FREQ=YEARLY'; $vEvent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')'; $vEvent->{'TRANSP'} = 'TRANSPARENT'; $alarm = $vCal->createComponent('VALARM'); $alarm->{'TRIGGER'} = '-PT0H'; $alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION'])); $alarm->add($vCal->createProperty('DESCRIPTION', $title . ' (' . $date->format('Y') . ')')); $vEvent->add($alarm); $appInfo = \OCP\App::getAppInfo('contacts'); $appVersion = \OCP\App::getAppVersion('contacts'); $vCal->PRODID = '-//ownCloud//NONSGML ' . $appInfo['name'] . ' ' . $appVersion . '//EN'; $vCal->add($vEvent); return $vCal; } return null; }
/** * generate VTimezone for given folder * * @param string|Tinebase_Model_Application $applicationName * @return string */ public static function getCalendarVTimezone($applicationName) { $timezone = Tinebase_Core::getPreference()->getValueForUser(Tinebase_Preference::TIMEZONE, Tinebase_Core::getUser()->getId()); $application = $applicationName instanceof Tinebase_Model_Application ? $applicationName : Tinebase_Application::getInstance()->getApplicationByName($applicationName); // create vcalendar object with timezone information $vcalendar = new \Sabre\VObject\Component\VCalendar(array('PRODID' => "-//tine20.org//Tine 2.0 {$application->name} V{$application->version}//EN", 'VERSION' => '2.0', 'CALSCALE' => 'GREGORIAN')); $vcalendar->add(new Sabre_VObject_Component_VTimezone($timezone)); // Taking out \r to not screw up the xml output return str_replace("\r", "", $vcalendar->serialize()); }
/** * @param Sabre\VObject\Component\VCalendar $vObject * @return Sabre\VObject\Component\VEvent|null */ function dav_get_eventComponent(&$vObject) { $component = null; $componentType = ""; foreach ($vObject->getComponents() as $component) { if ($component->name !== 'VTIMEZONE') { $componentType = $component->name; break; } } if ($componentType != "VEVENT") { return null; } return $component; }
/** * @brief Add property to vobject * @param object $name of property * @param object $value of property * @param object $parameters of property * @returns Sabre_VObject_Property newly created */ public function addProperty($name, $value, $parameters = array()) { if (is_array($value)) { $value = self::escapeSemicolons($value); } $vcalendar = new \Sabre\VObject\Component\VCalendar(); $property = $vcalendar->createProperty($name, $value); foreach ($parameters as $name => $value) { $property->parameters[] = $vcalendar->createProperty($name, $value); } $this->vobject->add($property); return $property; }
/** * @brief creates an VCalendar Object from the request data * @param array $request * @return object created $vcalendar */ public static function createVCalendarFromRequest($request) { $vcalendar = new \Sabre\VObject\Component\VCalendar(); $vcalendar->PRODID = 'ownCloud Calendar'; $vcalendar->VERSION = '2.0'; $vevent = $vcalendar->createComponent('VEVENT'); $vcalendar->add($vevent); $now = new DateTime('now'); $now->setTimeZone(new \DateTimeZone('UTC')); $vevent->CREATED = $now; $uid = substr(md5(rand() . time()), 0, 10); $vevent->UID = $uid; return self::updateVCalendarFromRequest($request, $vcalendar); }
/** * Generate an event to show in the calendar * * @return \Sabre\VObject\Component\VCalendar|null */ public function getBirthdayEvent() { if (!isset($this->BDAY)) { return null; } $birthday = $this->BDAY; if ((string) $birthday) { $title = str_replace('{name}', strtr((string) $this->FN, array('\\,' => ',', '\\;' => ';')), App::$l10n->t('{name}\'s Birthday')); try { $date = new \DateTime($birthday); } catch (Exception $e) { return null; } $vCal = new \Sabre\VObject\Component\VCalendar(); $vCal->VERSION = '2.0'; $vEvent = $vCal->createComponent('VEVENT'); $vEvent->add('DTSTART'); $vEvent->DTSTART->setDateTime($date); $vEvent->DTSTART['VALUE'] = 'date'; $vEvent->add('DURATION', 'P1D'); $vEvent->{'UID'} = $this->UID; $vEvent->{'RRULE'} = 'FREQ=YEARLY'; $vEvent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')'; $vEvent->{'TRANSP'} = 'TRANSPARENT'; $appInfo = \OCP\App::getAppInfo('contacts'); $appVersion = \OCP\App::getAppVersion('contacts'); $vCal->PRODID = '-//ownCloud//NONSGML ' . $appInfo['name'] . ' ' . $appVersion . '//EN'; $vCal->add($vEvent); return $vCal; } return null; }
public function addEvent($calendar, $titulo, $descripcion, $fecha) { //FIXME esto debería ser una variable $location = "Uroges Cruces"; echo "Vamos a crear {$calendar},{$titulo},{$descripcion},{$fecha} "; $uid = strtoupper(\Rhumsaa\Uuid\Uuid::uuid4()); $inicio = new \DateTime($fecha); $inicio = "VALUE=DATE:" . $fecha; //$inicio = $inicio->setTimezone(new DateTimezone("europe/madrid")); $now = new DateTime("now"); //$now = $now->setTimezone(new DateTimezone("europe/madrid")); $vcalendar = new \Sabre\VObject\Component\VCalendar(); $event = $vcalendar->add('VEVENT', ['CREATED' => $now, 'UID' => $uid, 'SUMMARY' => $titulo, 'DESCRIPTION' => $descripcion, 'DTSTART' => $fecha, 'DTSTAMP' => $now, 'LAST-MODIFIED' => $now, 'TRANSP' => "TRANSPARENT", 'SEQUENCE' => 0]); //$vcalendar->add($event); $etag = md5($vcalendar->serialize()); $startdate = $event->DTSTART->getDateTime()->getTimeStamp(); $enddate = $startdate; $size = strlen($vcalendar->serialize()); //echo "Tenemos el vclandera:<pre>"; //echo $vcalendar->serialize(); //echo "</pre>"; //echo "Vamos a introducir en BBDD el etag $etag el size $size y el tiempo $startdate"; $ret = $this->db->insert('oc_clndr_objects', array('calendardata' => $vcalendar->serialize(), 'uri' => $uid . ".ics", 'calendarid' => $calendar, 'startdate' => $startdate, 'enddate' => $enddate, 'lastmodified' => $now->getTimestamp())); $id = $this->db->lastInsertId(); //Actualizamos el ctag del calendario $this->updateSyncToken($calendar); //echo "Insercion hecha con ID: ".$id; //echo "Vamos a introducir en BBDD el etag $etag el size $size y el tiempo $startdate"; return $id; }
/** * convert calendar event to \Sabre\VObject\Component * * @param Tasks_Model_Task $_vtodo * @param Tasks_Model_Task $mainTask * @return \Sabre\VObject\Component */ protected function _convertTasksModelTask(Sabre\VObject\Component\VCalendar $vcalendar, Tasks_Model_Task $task, Tasks_Model_Task $mainTask = null) { // clone the event and change the timezone $task = clone $task; if (!empty($task->originator_tz)) { $task->setTimezone($task->originator_tz); } $vtodo = $vcalendar->create('VTODO'); $vtodo->add('CREATED', $task->creation_time->getClone()->setTimezone('UTC')); $lastModifiedDateTime = $task->last_modified_time ? $task->last_modified_time : $task->creation_time; $vtodo->add('LAST-MODIFIED', $lastModifiedDateTime->getClone()->setTimezone('UTC')); $vtodo->add('DTSTAMP', Tinebase_DateTime::now()); $vtodo->add('UID', $task->uid); $vtodo->add('SEQUENCE', !empty($task->seq) ? $task->seq : 1); if (isset($task->dtstart)) { $vtodo->add('DTSTART', $task->dtstart); } if (isset($task->due)) { $vtodo->add('DUE', $task->due); } if (isset($task->completed)) { $vtodo->add('COMPLETED', $task->completed); } switch ($task->priority) { case 'LOW': $vtodo->add('PRIORITY', 9); break; case 'NORMAL': $vtodo->add('PRIORITY', 0); break; case 'HIGH': case 'URGENT': $vtodo->add('PRIORITY', 1); break; } if (!empty($task->percent)) { $vtodo->add('PERCENT-COMPLETE', $task->percent); } // task organizer if (!empty($task->organizer)) { $organizerContact = $task->resolveOrganizer(); if ($organizerContact instanceof Addressbook_Model_Contact && !empty($organizerContact->email)) { $organizer = $vtodo->add('ORGANIZER', 'mailto:' . $organizerContact->email, array('CN' => $organizerContact->n_fileas, 'EMAIL' => $organizerContact->email)); } } $optionalProperties = array('class', 'description', 'geo', 'location', 'summary', 'status', 'url'); foreach ($optionalProperties as $property) { if (!empty($task->{$property})) { $vtodo->add($property, $task->{$property}); } } // categories if (!isset($task->tags)) { $task->tags = Tinebase_Tags::getInstance()->getTagsOfRecord($task); } if (isset($task->tags) && count($task->tags) > 0) { $vtodo->add('CATEGORIES', (array) $task->tags->name); } if ($task->alarms) { // fake X-MOZ-LASTACK $vtodo->add('X-MOZ-LASTACK', $task->creation_time->getClone()->setTimezone('UTC'), array('VALUE' => 'DATE-TIME')); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' event ' . print_r($task->alarms, TRUE)); } foreach ($task->alarms as $alarm) { $valarm = $vcalendar->create('VALARM'); $valarm->add('ACTION', 'DISPLAY'); $valarm->add('DESCRIPTION', $task->summary); if (is_numeric($alarm->minutes_before)) { if ($task->dtstart == $alarm->alarm_time) { $periodString = 'PT0S'; } else { $interval = $task->due->diff($alarm->alarm_time); $periodString = sprintf('%sP%s%s%s%s', $interval->format('%r'), $interval->format('%d') > 0 ? $interval->format('%dD') : null, $interval->format('%h') > 0 || $interval->format('%i') > 0 ? 'T' : null, $interval->format('%h') > 0 ? $interval->format('%hH') : null, $interval->format('%i') > 0 ? $interval->format('%iM') : null); } # TRIGGER;VALUE=DURATION:-PT1H15M $trigger = $valarm->add('TRIGGER', $periodString); $trigger['VALUE'] = "DURATION"; } else { # TRIGGER;VALUE=DATE-TIME:... $trigger = $valarm->add('TRIGGER', $alarm->alarm_time->getClone()->setTimezone('UTC')->format('Ymd\\THis\\Z')); $trigger['VALUE'] = "DATE-TIME"; } $vtodo->add($valarm); } } $vcalendar->add($vtodo); }
/** * Returns a list of calendar objects. * * This method should work identical to getCalendarObject, but instead * return all the calendar objects in the list as an array. * * If the backend supports this, it may allow for some speed-ups. * * @param mixed $calendarId * @param array $uris * @return array * @throws DAV\Exception\NotFound */ function getMultipleCalendarObjects($calendarId, array $uris) { $return = []; foreach ($uris as $uri) { /** @var Termin $termin */ $termin = Termin::model()->findByPk($uri); if (!$termin) { throw new \Sabre\DAV\Exception\NotFound('Calendar not found'); } $vcalendar = new \Sabre\VObject\Component\VCalendar(); $vcalendar->add('VEVENT', $termin->getVEventParams()); $calendardata = $vcalendar->serialize(); $return[] = ['id' => $termin->id, 'uri' => $termin->id, 'lastmodified' => $termin->datum_letzte_aenderung, 'etag' => rand(0, 999999999999), 'calendarid' => $calendarId, 'calendardata' => $calendardata, 'size' => strlen($calendardata), 'component' => 'VEVENT']; } return $return; }