作者:hesai
项目:tasks-
/**
* read object from calendar data
*
* @param \OCA\Tasks\Db\Tasks $task
* @return mixed
*/
private function readTask($task)
{
if (is_null($task->getSummary())) {
return false;
}
return \Sabre\VObject\Reader::read($task->getCalendardata());
}
作者:bogolubo
项目:owncollab_talks-
function testQueryTimerange()
{
$request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', ['Content-Type' => 'application/xml', 'Depth' => '1']);
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120226T230000Z" end="20120228T225959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
$this->fail('Got no events instead of 1. Output: ' . $response->body);
}
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
// We expect 1 event
$this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
}
作者:netcon-sourc
项目:app
public static function getBirthdayEvents($parameters)
{
$name = $parameters['calendar_id'];
if (strpos($name, 'birthday_') != 0) {
return;
}
$info = explode('_', $name);
$aid = $info[1];
Addressbook::find($aid);
foreach (VCard::all($aid) as $contact) {
try {
$vcard = VObject\Reader::read($contact['carddata']);
} catch (Exception $e) {
continue;
}
$birthday = $vcard->BDAY;
if ($birthday) {
$date = new \DateTime($birthday);
$vevent = VObject\Component::create('VEVENT');
//$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
$vevent->add('DTSTART');
$vevent->DTSTART->setDateTime($date, VObject\Property\DateTime::DATE);
$vevent->add('DURATION', 'P1D');
$vevent->{'UID'} = substr(md5(rand() . time()), 0, 10);
// DESCRIPTION?
$vevent->{'RRULE'} = 'FREQ=YEARLY';
$title = str_replace('{name}', $vcard->FN, 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");
}
}
}
作者:Radiergumm
项目:anacronis
function process($input, $existingObject = null, $expected = false)
{
$version = \Sabre\VObject\Version::VERSION;
$vcal = Reader::read($input);
foreach ($vcal->getComponents() as $mainComponent) {
break;
}
$message = new Message();
$message->message = $vcal;
$message->method = isset($vcal->METHOD) ? $vcal->METHOD->getValue() : null;
$message->component = $mainComponent->name;
$message->uid = $mainComponent->UID->getValue();
$message->sequence = isset($vcal->VEVENT[0]) ? (string) $vcal->VEVENT[0]->SEQUENCE : null;
if ($message->method === 'REPLY') {
$message->sender = $mainComponent->ATTENDEE->getValue();
$message->senderName = isset($mainComponent->ATTENDEE['CN']) ? $mainComponent->ATTENDEE['CN']->getValue() : null;
$message->recipient = $mainComponent->ORGANIZER->getValue();
$message->recipientName = isset($mainComponent->ORGANIZER['CN']) ? $mainComponent->ORGANIZER['CN'] : null;
}
$broker = new Broker();
if (is_string($existingObject)) {
$existingObject = str_replace('%foo%', "VERSION:2.0\nPRODID:-//Sabre//Sabre VObject {$version}//EN\nCALSCALE:GREGORIAN", $existingObject);
$existingObject = Reader::read($existingObject);
}
$result = $broker->processMessage($message, $existingObject);
if (is_null($expected)) {
$this->assertTrue(!$result);
return;
}
$this->assertVObjectEqualsVObject($expected, $result);
}
作者:ZerGabrie
项目:friendica-addon
function testIssue205()
{
$request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120325T220000Z" end="20120401T215959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:comp-filter name="VALARM">
<C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
$this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
$this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
$this->assertEquals(1, count($vObject->VEVENT));
}
作者:CDN-Spark
项目:ownclou
/**
* @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 = \Sabre\VObject\Reader::read($card['carddata']);
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
\OCP\Util::writeLog('contacts', __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;
}
作者:sebbie4
项目:casebo
/**
* @dataProvider provider
*/
function testValid($icalObject, $filters, $outcome)
{
$validator = new CalendarQueryValidator();
// Wrapping filter in a VCALENDAR component filter, as this is always
// there anyway.
$filters = array('name' => 'VCALENDAR', 'comp-filters' => array($filters), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => null);
$vObject = VObject\Reader::read($icalObject);
switch ($outcome) {
case 0:
$this->assertFalse($validator->validate($vObject, $filters));
break;
case 1:
$this->assertTrue($validator->validate($vObject, $filters));
break;
case -1:
try {
$validator->validate($vObject, $filters);
$this->fail('This test was supposed to fail');
} catch (\Exception $e) {
// We need to test something to be valid for phpunit strict
// mode.
$this->assertTrue(true);
}
break;
}
}
作者:amin-hedayat
项目:calendar-rewor
/**
* Constructor
*
* The splitter should receive an readable file stream as it's input.
*
* @param string|resource|array $input
* @param int $options Parser options, see the OPTIONS constants.
*/
public function __construct($input, $options = 0)
{
$data = Reader::readJSON($input, $options);
$vtimezones = array();
$components = array();
foreach ($data->children() as $component) {
if (!$component instanceof Component) {
continue;
}
// Get all timezones
if ($component->name === 'VTIMEZONE') {
$this->vtimezones[(string) $component->TZID] = $component;
continue;
}
// Get component UID for recurring Events search
if (!$component->UID) {
$component->UID = sha1(microtime()) . '-vobjectimport';
}
$uid = (string) $component->UID;
// Take care of recurring events
if (!array_key_exists($uid, $this->objects)) {
$this->objects[$uid] = new VCalendar();
}
$this->objects[$uid]->add(clone $component);
}
}
作者:TamirA
项目:hubzill
/**
* @dataProvider provider
*/
function testValid($icalObject, $filters, $outcome)
{
$validator = new CalendarQueryValidator();
// Wrapping filter in a VCALENDAR component filter, as this is always
// there anyway.
$filters = array('name' => 'VCALENDAR', 'comp-filters' => array($filters), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => null);
$vObject = VObject\Reader::read($icalObject);
switch ($outcome) {
case 0:
$this->assertFalse($validator->validate($vObject, $filters));
break;
case 1:
$this->assertTrue($validator->validate($vObject, $filters));
break;
case -1:
try {
$validator->validate($vObject, $filters);
} catch (DAV\Exception $e) {
// Success
} catch (\LogicException $e) {
// Success
}
break;
}
}
作者:samj191
项目:rep
/**
* Constructor
*
* The splitter should receive an readable file stream as it's input.
*
* @param resource $input
* @param int $options Parser options, see the OPTIONS constants.
*/
public function __construct($input, $options = 0)
{
$data = VObject\Reader::read($input, $options);
$vtimezones = array();
$components = array();
if (!$data instanceof VObject\Component\VCalendar) {
throw new VObject\ParseException('Supplied input could not be parsed as VCALENDAR.');
}
foreach ($data->children() as $component) {
if (!$component instanceof VObject\Component) {
continue;
}
// Get all timezones
if ($component->name === 'VTIMEZONE') {
$this->vtimezones[(string) $component->TZID] = $component;
continue;
}
// Get component UID for recurring Events search
if (!$component->UID) {
$component->UID = sha1(microtime()) . '-vobjectimport';
}
$uid = (string) $component->UID;
// Take care of recurring events
if (!array_key_exists($uid, $this->objects)) {
$this->objects[$uid] = new VCalendar();
}
$this->objects[$uid]->add(clone $component);
}
}
作者:pigull
项目:owncloud-sipgat
/**
* @throws VObject\ParseException
* @return VObject\Component\VCard
*/
private function getVCard()
{
if ($this->vcard === null) {
$this->vcard = VObject\Reader::read($this->getEntry());
}
return $this->vcard;
}
作者:evanj
项目:cor
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$principalBackend = new Principal($this->config, $this->userManager);
$this->backend = new CardDavBackend($this->dbConnection, $principalBackend);
// ensure system addressbook exists
$systemAddressBook = $this->ensureSystemAddressBookExists();
$converter = new Converter();
$output->writeln('Syncing users ...');
$progress = new ProgressBar($output);
$progress->start();
$this->userManager->callForAllUsers(function ($user) use($systemAddressBook, $converter, $progress) {
/** @var IUser $user */
$name = $user->getBackendClassName();
$userId = $user->getUID();
$cardId = "{$name}:{$userId}.vcf";
$card = $this->backend->getCard($systemAddressBook['id'], $cardId);
if ($card === false) {
$vCard = $converter->createCardFromUser($user);
$this->backend->createCard($systemAddressBook['id'], $cardId, $vCard->serialize());
} else {
$vCard = Reader::read($card['carddata']);
if ($converter->updateCard($vCard, $user)) {
$this->backend->updateCard($systemAddressBook['id'], $cardId, $vCard->serialize());
}
}
$progress->advance();
});
$progress->finish();
$output->writeln('');
}
作者:bodu
项目:joran
/**
* A pretty slow test. Had to be marked as 'medium' for phpunit to not die
* after 1 second. Would be good to optimize later.
*
* @medium
*/
function testGetDTEnd()
{
$ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.4//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND;TZID=America/New_York:20070925T170000
UID:uuid
DTSTAMP:19700101T000000Z
LOCATION:
DESCRIPTION:
STATUS:CONFIRMED
SEQUENCE:18
SUMMARY:Stuff
DTSTART;TZID=America/New_York:20070925T160000
CREATED:20071004T144642Z
RRULE:FREQ=MONTHLY;INTERVAL=1;UNTIL=20071030T035959Z;BYDAY=5TU
END:VEVENT
END:VCALENDAR
ICS;
$vObject = Reader::read($ics);
$it = new Recur\EventIterator($vObject, (string) $vObject->VEVENT->UID);
while ($it->valid()) {
$it->next();
}
// If we got here, it means we were successful. The bug that was in the
// system before would fail on the 5th tuesday of the month, if the 5th
// tuesday did not exist.
$this->assertTrue(true);
}
作者:TamirA
项目:hubzill
/**
* Constructor
*
* The splitter should receive an readable file stream as it's input.
*
* @param resource $input
*/
public function __construct($input)
{
$data = VObject\Reader::read(stream_get_contents($input));
$vtimezones = array();
$components = array();
foreach ($data->children as $component) {
if (!$component instanceof VObject\Component) {
continue;
}
// Get all timezones
if ($component->name === 'VTIMEZONE') {
$this->vtimezones[(string) $component->TZID] = $component;
continue;
}
// Get component UID for recurring Events search
if ($component->UID) {
$uid = (string) $component->UID;
} else {
// Generating a random UID
$uid = sha1(microtime()) . '-vobjectimport';
}
// Take care of recurring events
if (!array_key_exists($uid, $this->objects)) {
$this->objects[$uid] = VObject\Component::create('VCALENDAR');
}
$this->objects[$uid]->add(clone $component);
}
}
作者:ddolbi
项目:sabre-vobjec
function testRemoveFirstEvent()
{
$input = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:foobar
DTSTART:20140803T120000Z
RRULE:FREQ=WEEKLY
EXDATE:20140803T120000Z
SUMMARY:Original
END:VEVENT
END:VCALENDAR
ICS;
$vcal = Reader::read($input);
$vcal = $vcal->expand(new DateTime('2014-08-01'), new DateTime('2014-08-19'));
$expected = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:foobar
DTSTART:20140810T120000Z
SUMMARY:Original
RECURRENCE-ID:20140810T120000Z
END:VEVENT
BEGIN:VEVENT
UID:foobar
DTSTART:20140817T120000Z
SUMMARY:Original
RECURRENCE-ID:20140817T120000Z
END:VEVENT
END:VCALENDAR
ICS;
$this->assertVObjEquals($expected, $vcal);
}
作者:floffel0
项目:pydio-cor
function testIsFree()
{
$input = <<<BLA
BEGIN:VCALENDAR
BEGIN:VFREEBUSY
FREEBUSY;FBTYPE=FREE:20120912T000500Z/PT1H
FREEBUSY;FBTYPE=BUSY:20120912T010000Z/20120912T020000Z
FREEBUSY;FBTYPE=BUSY-TENTATIVE:20120912T020000Z/20120912T030000Z
FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20120912T030000Z/20120912T040000Z
FREEBUSY;FBTYPE=BUSY:20120912T050000Z/20120912T060000Z,20120912T080000Z/20120912T090000Z
FREEBUSY;FBTYPE=BUSY:20120912T100000Z/PT1H
END:VFREEBUSY
END:VCALENDAR
BLA;
$obj = VObject\Reader::read($input);
$vfb = $obj->VFREEBUSY;
$tz = new \DateTimeZone('UTC');
$this->assertFalse($vfb->isFree(new \DateTime('2012-09-12 01:15:00', $tz), new \DateTime('2012-09-12 01:45:00', $tz)));
$this->assertFalse($vfb->isFree(new \DateTime('2012-09-12 08:05:00', $tz), new \DateTime('2012-09-12 08:10:00', $tz)));
$this->assertFalse($vfb->isFree(new \DateTime('2012-09-12 10:15:00', $tz), new \DateTime('2012-09-12 10:45:00', $tz)));
// Checking whether the end time is treated as non-inclusive
$this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 09:00:00', $tz), new \DateTime('2012-09-12 09:15:00', $tz)));
$this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 09:45:00', $tz), new \DateTime('2012-09-12 10:00:00', $tz)));
$this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 11:00:00', $tz), new \DateTime('2012-09-12 12:00:00', $tz)));
}
作者:ddolbi
项目:sabre-vobjec
function testExpand()
{
$input = <<<ICS
BEGIN:VCALENDAR
BEGIN:VEVENT
UID:foo
DTEND;TZID=Europe/Moscow:20130710T120000
DTSTART;TZID=Europe/Moscow:20130710T110000
RRULE:FREQ=DAILY;UNTIL=20130712T195959Z
END:VEVENT
BEGIN:VEVENT
UID:foo
DTEND;TZID=Europe/Moscow:20130713T120000
DTSTART;TZID=Europe/Moscow:20130713T110000
RECURRENCE-ID;TZID=Europe/Moscow:20130711T110000
END:VEVENT
END:VCALENDAR
ICS;
$vcal = Reader::read($input);
$this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
$it = new Recur\EventIterator($vcal, 'foo');
$result = iterator_to_array($it);
$tz = new DateTimeZone('Europe/Moscow');
$expected = [new DateTimeImmutable('2013-07-10 11:00:00', $tz), new DateTimeImmutable('2013-07-12 11:00:00', $tz), new DateTimeImmutable('2013-07-13 11:00:00', $tz)];
$this->assertEquals($expected, $result);
}
作者:bodu
项目:joran
/**
* This tests the expansion of dates with DAILY frequency in RRULE with BYMONTH restrictions
*/
function testExpand()
{
$ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.4//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND:20070925T183000Z
UID:uuid
DTSTAMP:19700101T000000Z
LOCATION:
DESCRIPTION:
STATUS:CONFIRMED
SEQUENCE:18
SUMMARY:Stuff
DTSTART:20070925T160000Z
CREATED:20071004T144642Z
RRULE:FREQ=DAILY;BYMONTH=9,10;BYDAY=SU
END:VEVENT
END:VCALENDAR
ICS;
$vcal = Reader::read($ics);
$this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
$vcal->expand(new DateTime('2013-09-28'), new DateTime('2014-09-11'));
foreach ($vcal->VEVENT as $event) {
$dates[] = $event->DTSTART->getValue();
}
$expectedDates = array("20130929T160000Z", "20131006T160000Z", "20131013T160000Z", "20131020T160000Z", "20131027T160000Z", "20140907T160000Z");
$this->assertEquals($expectedDates, $dates, 'Recursed dates are restricted by month');
}
作者:BlaBlaNe
项目:hubzill
function testFlaw()
{
$input = <<<HI
BEGIN:VCALENDAR
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Asia/Pyongyang
X-LIC-LOCATION:Asia/Pyongyang
BEGIN:STANDARD
TZOFFSETFROM:+0900
TZOFFSETTO:+0900
TZNAME:KST
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20111118T010857Z
LAST-MODIFIED:20111118T010937Z
DTSTAMP:20111118T010937Z
UID:a03245b3-9947-9a48-a088-863c74e0fdd8
SUMMARY:New Event
RRULE:FREQ=YEARLY
DTSTART;TZID=Asia/Pyongyang:19960102T111500
DTEND;TZID=Asia/Pyongyang:19960102T121500
END:VEVENT
END:VCALENDAR
HI;
$validator = new CalendarQueryValidator();
$filters = ['name' => 'VCALENDAR', 'comp-filters' => [['name' => 'VEVENT', 'comp-filters' => [], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => ['start' => new \DateTime('2011-12-01'), 'end' => new \DateTime('2012-02-01')]]], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => null];
$input = VObject\Reader::read($input);
$this->assertTrue($validator->validate($input, $filters));
}
作者:Theodi
项目:theodia.or
/**
* Import all event for a calendar
* @param \Application\Model\Calendar $calendar
*/
public function import(Calendar $calendar)
{
$url = $calendar->getUrl();
$document = Reader::read(fopen($url, 'r'));
$this->importCalendar($calendar, $document);
$this->getEntityManager()->flush();
}