/** * 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()); }
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); }
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"); } } }
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); }
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)); }
/** * @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; }
/** * @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; } }
/** * 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); } }
/** * @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; } }
/** * 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); } }
/** * @throws VObject\ParseException * @return VObject\Component\VCard */ private function getVCard() { if ($this->vcard === null) { $this->vcard = VObject\Reader::read($this->getEntry()); } return $this->vcard; }
/** * @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(''); }
/** * 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); }
/** * 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); } }
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); }
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))); }
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); }
/** * 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'); }
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)); }
/** * 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(); }
function testExpand() { $input = <<<ICS BEGIN:VCALENDAR VERSION:2.0 BEGIN:VEVENT UID:2CD5887F7CF4600F7A3B1F8065099E40-240BDA7121B61224 DTSTAMP;VALUE=DATE-TIME:20151014T110604Z CREATED;VALUE=DATE-TIME:20151014T110245Z LAST-MODIFIED;VALUE=DATE-TIME:20151014T110541Z DTSTART;VALUE=DATE-TIME;TZID=Europe/Berlin:20151012T020000 DTEND;VALUE=DATE-TIME;TZID=Europe/Berlin:20151012T013000 SUMMARY:Test SEQUENCE:2 RDATE;VALUE=DATE-TIME;TZID=Europe/Berlin:20151015T020000,20151017T020000,20 151018T020000,20151020T020000 TRANSP:OPAQUE CLASS:PUBLIC END:VEVENT END:VCALENDAR ICS; $vcal = Reader::read($input); $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal); $vcal = $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-12-01')); $result = iterator_to_array($vcal->VEVENT); $this->assertEquals(5, count($result)); $utc = new DateTimeZone('UTC'); $expected = [new DateTimeImmutable("2015-10-12", $utc), new DateTimeImmutable("2015-10-15", $utc), new DateTimeImmutable("2015-10-17", $utc), new DateTimeImmutable("2015-10-18", $utc), new DateTimeImmutable("2015-10-20", $utc)]; $result = array_map(function ($ev) { return $ev->DTSTART->getDateTime(); }, $result); $this->assertEquals($expected, $result); }
function testExpand() { $request = new 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="20120205T230000Z" end="20120212T225959Z"/> </C:calendar-data> <D:getetag/> </D:prop> <C:filter> <C:comp-filter name="VCALENDAR"> <C:comp-filter name="VEVENT"> <C:time-range start="20120205T230000Z" end="20120212T225959Z"/> </C:comp-filter> </C:comp-filter> </C:filter> </C:calendar-query>'); $response = $this->request($request); // 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 only expect 3 events $this->assertEquals(3, count($vObject->VEVENT), 'We got 6 events instead of 3. Output: ' . $body); // TZID should be gone $this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID'])); }
function testAddChild() { $carddata = file_get_contents(__DIR__ . '/../data/test2.vcf'); $vcard = Reader::read($carddata); $id = $this->ab->addChild($vcard); $this->assertNotEquals(false, $id); return $this->ab; }
public static function PovodArray($file) { // $text = file(static::getUpload().$file); // $text = VObject\Reader::read(fopen(static::getUpload().$file,'r')); $vcal = Reader::read(fopen(static::getUpload() . $file, 'r')); $text = json_encode($vcal->jsonSerialize()); return $text; }
function testReadQuotedPrintableCompatibilityMS() { $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\nDeutschland:okay\r\nEND:VCARD"; $result = Reader::read($data, Reader::OPTION_FORGIVING); $this->assertInstanceOf('Sabre\\VObject\\Component', $result); $this->assertEquals('VCARD', $result->name); $this->assertEquals(1, count($result->children())); $this->assertEquals("Aachen\r\nDeutschland:okay", $this->getPropertyValue($result->label)); }
public function testEscapedParameters() { $carddata = file_get_contents(__DIR__ . '/../data/test6.vcf'); $obj = \Sabre\VObject\Reader::read($carddata, \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES); $obj->validate($obj::REPAIR | $obj::UPGRADE); $this->assertEquals('3.0', (string) $obj->VERSION); $this->assertEquals('Parameters;Escaped;;;', (string) $obj->N); $this->assertEquals('TEL;TYPE=PREF;TYPE=WORK;TYPE=VOICE:123456789' . "\r\n", $obj->TEL->serialize()); }
function testMimeDir() { $input = "BEGIN:VCARD\r\nX-AWESOME;VALUE=BOOLEAN:TRUE\r\nX-SUCKS;VALUE=BOOLEAN:FALSE\r\nEND:VCARD\r\n"; $vcard = VObject\Reader::read($input); $this->assertTrue($vcard->{'X-AWESOME'}->getValue()); $this->assertFalse($vcard->{'X-SUCKS'}->getValue()); $this->assertEquals('BOOLEAN', $vcard->{'X-AWESOME'}->getValueType()); $this->assertEquals($input, $vcard->serialize()); }
public function indexAction(Request $request, SessionInterface $session) { Util::checkUserIsLoggedInAndRedirect(); $session->set('selected_product_id', SystemProduct::SYS_PRODUCT_CALENDAR); $data = null; $filename = null; if ($request->request->has('import_calendar')) { if ($request->files->has('calendar_file')) { $temporaryFileName = $_FILES['calendar_file']['tmp_name']; $calendarName = 'Imported Calendar'; $data = file_get_contents($temporaryFileName); } } if ($request->request->has('import_calendar_url')) { $url = $request->request->get('calendar_url'); $data = file_get_contents($url); } if ($data) { $calendar = VObject\Reader::read($data); $calendarChildren = $calendar->children(); foreach ($calendarChildren as $child) { if ('X-WR-CALNAME' == $child->name) { $calendarName = $child->getValue(); break; } } $calendarExists = $this->getRepository(UbirimiCalendar::class)->getByName($session->get('user/id'), $calendarName); if ($calendarExists) { $calendarName .= '_' . time(); } // deal with the events $date = Util::getServerCurrentDateTime(); $calendarId = $this->getRepository(UbirimiCalendar::class)->save($session->get('user/id'), $calendarName, null, '#A1FF9E', $date); $defaultColor = 'A1FF9E'; $events = $calendar->VEvent; for ($i = 0; $i < count($events); $i++) { $summary = $events[$i]->SUMMARY->getValue(); $description = isset($events[$i]->DESCRIPTION) ? $events[$i]->DESCRIPTION->getValue() : null; $location = $events[$i]->LOCATION->getValue(); $startTime = $events[$i]->DTSTART->getDateTime(); $startTime = $startTime->format('Y-m-d H:i:s'); $endTime = $events[$i]->DTEND->getDateTime(); if ($endTime->format('H:i:s') == '00:00:00') { $endTime = $endTime->sub(new \DateInterval('P1D')); } $endTime = $endTime->format('Y-m-d H:i:s'); $this->getRepository(CalendarEvent::class)->add($calendarId, $session->get('user/id'), $summary, $description, $location, $startTime, $endTime, $defaultColor, $date); } if ($filename) { unlink('./temp_imported_calendar/' . $filename); } return new RedirectResponse('/calendar/calendars'); } $menuSelectedCategory = 'calendars'; $sectionPageTitle = $session->get('client/settings/title_name') . ' / ' . SystemProduct::SYS_PRODUCT_CALENDAR_NAME . ' / Import'; return $this->render(__DIR__ . '/../Resources/views/Import.php', get_defined_vars()); }
/** * returns VObject of input data * * @param mixed $blob * @return \Sabre\VObject\Component\VCard */ public static function getVObject($blob) { if ($blob instanceof \Sabre\VObject\Component\VCard) { return $blob; } if (is_resource($blob)) { $blob = stream_get_contents($blob); } return \Sabre\VObject\Reader::read($blob); }
public function nextEventAction() { $adapter = $this->getAdapter(); $response = $this->getResponse(); $viewModel = $this->getViewModel(); Json::$useBuiltinEncoderDecoder = true; $id = $this->getEvent()->getRouteMatch()->getParam('id'); if (!$id) { return $response->setContent($adapter->serialize(null)); } $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $result = $em->getRepository('Phpug\\Entity\\Usergroup')->findBy(array('shortname' => $id)); if (!$result) { throw new \UnexpectedValueException(sprintf('Fehler!!')); } if (1 < count($result)) { throw new \UnexpectedValueException(sprintf('Fehler!!')); } $uri = $result[0]->icalendar_url; $data = @file_get_contents($uri); if (!$data) { throw new \UnexpectedValueException(sprintf('Could not read data')); } $now = new \DateTime(); $then = (new \DateTime())->add(new \DateInterval('P1Y')); $ical = VObject\Reader::read($data); $ical->expand($now, $then); $nextEvent = null; if (!isset($ical->VEVENT)) { throw new \UnexpectedValueException(sprintf('No Event available')); } foreach ($ical->VEVENT as $event) { if (null === $nextEvent || $nextEvent->DTSTART->getDateTime() > $event->DTSTART->getDateTime()) { $nextEvent = $event; } } if (!$nextEvent) { throw new \UnexpectedValueException(sprintf('No Event defined')); } $content = array('start' => $nextEvent->DTSTART->getDateTime()->format(\DateTime::RFC2822), 'end' => $nextEvent->DTEND->getDateTime()->format(\DateTime::RFC2822), 'location' => '', 'summary' => 'Next event', 'url' => '', 'description' => ''); if (isset($nextEvent->LOCATION)) { $content['location'] = $nextEvent->LOCATION->getValue(); } if (isset($nextEvent->SUMMARY)) { $content['summary'] = $nextEvent->SUMMARY->getValue(); } if (isset($nextEvent->URL)) { $content['url'] = $nextEvent->URL->getValue(); } if (isset($nextEvent->DESCRIPTION)) { $content['description'] = $nextEvent->DESCRIPTION->getValue(); } return $viewModel->setVariables($content); }