本文整理汇总了PHP中Sabre\VObject\Component类的典型用法代码示例。如果您正苦于以下问题:PHP Component类的具体用法?PHP Component怎么用?PHP Component使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Component类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendMessage
/**
* Sends one or more iTip messages through email.
*
* @param string $originator Originator Email
* @param array $recipients Array of email addresses
* @param VObject\Component $vObject
* @param string $principal Principal Url of the originator
* @return void
*/
public function sendMessage($originator, array $recipients, VObject\Component $vObject, $principal)
{
foreach ($recipients as $recipient) {
$to = $recipient;
$replyTo = $originator;
$subject = 'SabreDAV iTIP message';
switch (strtoupper($vObject->METHOD)) {
case 'REPLY':
$subject = 'Response for: ' . $vObject->VEVENT->SUMMARY;
break;
case 'REQUEST':
$subject = 'Invitation for: ' . $vObject->VEVENT->SUMMARY;
break;
case 'CANCEL':
$subject = 'Cancelled event: ' . $vObject->VEVENT->SUMMARY;
break;
}
$headers = array();
$headers[] = 'Reply-To: ' . $replyTo;
$headers[] = 'From: ' . $this->senderEmail;
$headers[] = 'Content-Type: text/calendar; method=' . (string) $vObject->method . '; charset=utf-8';
if (DAV\Server::$exposeVersion) {
$headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION . '-' . DAV\Version::STABILITY;
}
$vcalBody = $vObject->serialize();
$this->mail($to, $subject, $vcalBody, $headers);
}
}
示例2: getValueOrEmpty
private function getValueOrEmpty(\Sabre\VObject\Component $component, $property)
{
$value = $component->__get($property);
if ($value) {
return $value->getValue();
} else {
return '';
}
}
示例3: __construct
/**
* 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);
}
}
示例4: testYearlyByMonthLoop
/**
* Different bug, also likely an infinite loop.
*/
function testYearlyByMonthLoop()
{
$ev = Component::create('VEVENT');
$ev->UID = 'uuid';
$ev->DTSTART = '20120101T154500';
$ev->DTSTART['TZID'] = 'Europe/Berlin';
$ev->RRULE = 'FREQ=YEARLY;INTERVAL=1;UNTIL=20120203T225959Z;BYMONTH=2;BYSETPOS=1;BYDAY=SU,MO,TU,WE,TH,FR,SA';
$ev->DTEND = '20120101T164500';
$ev->DTEND['TZID'] = 'Europe/Berlin';
// This recurrence rule by itself is a yearly rule that should happen
// every february.
//
// The BYDAY part expands this to every day of the month, but the
// BYSETPOS limits this to only the 1st day of the month. Very crazy
// way to specify this, and could have certainly been a lot easier.
$cal = Component::create('VCALENDAR');
$cal->add($ev);
$it = new RecurrenceIterator($cal, 'uuid');
$it->fastForward(new DateTime('2012-01-29 23:00:00', new DateTimeZone('UTC')));
$collect = array();
while ($it->valid()) {
$collect[] = $it->getDTSTART();
if ($it->getDTSTART() > new DateTime('2013-02-05 22:59:59', new DateTimeZone('UTC'))) {
break;
}
$it->next();
}
$this->assertEquals(array(new DateTime('2012-02-01 15:45:00', new DateTimeZone('Europe/Berlin'))), $collect);
}
示例5: writeXml
/**
* Serializes a xCal or xCard object.
*
* @param Component $component
*
* @return string
*/
static function writeXml(Component $component)
{
$writer = new Xml\Writer();
$writer->openMemory();
$writer->setIndent(true);
$writer->startDocument('1.0', 'utf-8');
if ($component instanceof Component\VCalendar) {
$writer->startElement('icalendar');
$writer->writeAttribute('xmlns', Parser\Xml::XCAL_NAMESPACE);
} else {
$writer->startElement('vcards');
$writer->writeAttribute('xmlns', Parser\Xml::XCARD_NAMESPACE);
}
$component->xmlSerialize($writer);
$writer->endElement();
return $writer->outputMemory();
}
示例6: testZeroInterval
/**
* Something, somewhere produced an ics with an interval set to 0. Because
* this means we increase the current day (or week, month) by 0, this also
* results in an infinite loop.
*
* @expectedException InvalidArgumentException
* @return void
*/
function testZeroInterval()
{
$ev = Component::create('VEVENT');
$ev->UID = 'uuid';
$ev->DTSTART = '20120824T145700Z';
$ev->RRULE = 'FREQ=YEARLY;INTERVAL=0';
$cal = Component::create('VCALENDAR');
$cal->add($ev);
$it = new RecurrenceIterator($cal, 'uuid');
$it->fastForward(new DateTime('2013-01-01 23:00:00', new DateTimeZone('UTC')));
// if we got this far.. it means we are no longer infinitely looping
}
示例7: testAlarmWayBefore
function testAlarmWayBefore()
{
$vevent = VObject\Component::create('VEVENT');
$vevent->DTSTART = '20120101T120000Z';
$vevent->UID = 'bla';
$valarm = VObject\Component::create('VALARM');
$valarm->TRIGGER = '-P2W1D';
$vevent->add($valarm);
$vcalendar = VObject\Component::create('VCALENDAR');
$vcalendar->add($vevent);
$filter = array('name' => 'VCALENDAR', 'is-not-defined' => false, 'time-range' => null, 'prop-filters' => array(), 'comp-filters' => array(array('name' => 'VEVENT', 'is-not-defined' => false, 'time-range' => null, 'prop-filters' => array(), 'comp-filters' => array(array('name' => 'VALARM', 'is-not-defined' => false, 'prop-filters' => array(), 'comp-filters' => array(), 'time-range' => array('start' => new DateTime('2011-12-10'), 'end' => new DateTime('2011-12-20')))))));
$validator = new Sabre_CalDAV_CalendarQueryValidator();
$this->assertTrue($validator->validate($vcalendar, $filter));
}
示例8: generateICS
/**
* Merges all calendar objects, and builds one big ics export
*
* @param array $nodes
* @return string
*/
public function generateICS(array $nodes)
{
$calendar = new VObject\Component('vcalendar');
$calendar->version = '2.0';
if (Sabre_DAV_Server::$exposeVersion) {
$calendar->prodid = '-//SabreDAV//SabreDAV ' . Sabre_DAV_Version::VERSION . '//EN';
} else {
$calendar->prodid = '-//SabreDAV//SabreDAV//EN';
}
$calendar->calscale = 'GREGORIAN';
$collectedTimezones = array();
$timezones = array();
$objects = array();
foreach ($nodes as $node) {
if (!isset($node[200]['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data'])) {
continue;
}
$nodeData = $node[200]['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data'];
$nodeComp = VObject\Reader::read($nodeData);
foreach ($nodeComp->children() as $child) {
switch ($child->name) {
case 'VEVENT':
case 'VTODO':
case 'VJOURNAL':
$objects[] = $child;
break;
// VTIMEZONE is special, because we need to filter out the duplicates
// VTIMEZONE is special, because we need to filter out the duplicates
case 'VTIMEZONE':
// Naively just checking tzid.
if (in_array((string) $child->TZID, $collectedTimezones)) {
continue;
}
$timezones[] = $child;
$collectedTimezones[] = $child->TZID;
break;
}
}
}
foreach ($timezones as $tz) {
$calendar->add($tz);
}
foreach ($objects as $obj) {
$calendar->add($obj);
}
return $calendar->serialize();
}
示例9: timeRangeTestData
public function timeRangeTestData()
{
$tests = array();
$vjournal = Component::create('VJOURNAL');
$vjournal->DTSTART = '20111223T120000Z';
$tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vjournal2 = Component::create('VJOURNAL');
$vjournal2->DTSTART = '20111223';
$vjournal2->DTSTART['VALUE'] = 'DATE';
$tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vjournal3 = Component::create('VJOURNAL');
$tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), false);
$tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
return $tests;
}
示例10: ldapToVCard
/**
* @brief transform a ldap entry into an VCard object
* for each ldap entry which is like "property: value"
* to a VCard entry which is like "PROPERTY[;PARAMETER=param]:value"
* @param array $ldap_entry
* @return OC_VCard
*/
public function ldapToVCard($ldapEntry)
{
$vcard = \Sabre\VObject\Component::create('VCARD');
$vcard->REV = $this->convertDate($ldapEntry['modifytimestamp'][0])->format(\DateTime::W3C);
//error_log("modifytimestamp: ".$vcard->REV);
$vcard->{'X-LDAP-DN'} = base64_encode($ldapEntry['dn']);
// OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' vcard is '.$vcard->serialize(), \OCP\Util::DEBUG);
for ($i = 0; $i < $ldapEntry["count"]; $i++) {
// ldap property name : $ldap_entry[$i]
$lProperty = $ldapEntry[$i];
for ($j = 0; $j < $ldapEntry[$lProperty]["count"]; $j++) {
// What to do :
// convert the ldap property into vcard property, type and position (if needed)
// $v_params format: array('property' => property, 'type' => array(types), 'position' => position)
$v_params = $this->getVCardProperty($lProperty);
foreach ($v_params as $v_param) {
if (isset($v_param['unassigned'])) {
// if the value comes from the unassigned entry, it's a vcard property dumped
try {
$property = \Sabre\VObject\Reader::read($ldapEntry[$lProperty][$j]);
$vcard->add($property);
} catch (exception $e) {
}
} else {
// Checks if a same kind of property already exists in the VCard (property and parameters)
// if so, sets a property variable with the current data
// else, creates a property variable
$v_property = $this->getOrCreateVCardProperty($vcard, $v_param, $j);
// modify the property with the new data
if (strcasecmp($v_param['image'], 'true') == 0) {
$this->updateVCardImageProperty($v_property, $ldapEntry[$lProperty][$j], $vcard->VERSION);
} else {
$this->updateVCardProperty($v_property, $ldapEntry[$lProperty][$j], $v_param['position']);
}
}
}
}
}
if (!isset($vcard->UID)) {
$vcard->UID = base64_encode($ldapEntry['dn']);
}
return $vcard;
}
示例11: calendarAction
/**
* Create online calendar for user
*
* @Route("/{username}.ics")
*
* @param string $username User to create the calendar for
* @return Symfony\Component\HttpFoundation\Response
*/
public function calendarAction($username)
{
$user = $this->get('user_provider')->loadUserByUsername($username);
$om = $this->getObjectManager('VIB\\FliesBundle\\Entity\\Vial');
$calendar = VObject\Component::create('VCALENDAR');
$calendar->VERSION = '2.0';
$field = 'X-WR-CALNAME';
$calendar->{$field} = $user->getShortName() . '\'s flywork';
$stockDates = $om->getRepository('VIB\\FliesBundle\\Entity\\StockVial')->getFlipDates($user);
foreach ($stockDates as $stockDate) {
$event = VObject\Component::create('VEVENT');
$calendar->add($event);
$event->SUMMARY = 'Transfer stocks';
$dtstart = VObject\Property::create('DTSTART');
$dtstart->setDateTime($stockDate, VObject\Property\DateTime::DATE);
$event->DTSTART = $dtstart;
$alarm = VObject\Component::create('VALARM');
$event->add($alarm);
$alarm->TRIGGER = 'PT8H';
$alarm->ACTION = 'DISPLAY';
}
$crossDates = $om->getRepository('VIB\\FliesBundle\\Entity\\CrossVial')->getFlipDates($user);
foreach ($crossDates as $crossDate) {
$crossDates[] = $crossDate;
$event = VObject\Component::create('VEVENT');
$calendar->add($event);
$event->SUMMARY = 'Check crosses';
$dtstart = VObject\Property::create('DTSTART');
$dtstart->setDateTime($crossDate, VObject\Property\DateTime::DATE);
$event->DTSTART = $dtstart;
$alarm = VObject\Component::create('VALARM');
$event->add($alarm);
$alarm->TRIGGER = 'PT8H';
$alarm->ACTION = 'DISPLAY';
}
return new Response($calendar->serialize(), 200, array('Content-Type' => 'text/calendar; charset=utf-8', 'Content-Disposition' => 'inline; filename="calendar.ics"'));
}
示例12: timeRangeTestData
public function timeRangeTestData()
{
$tests = array();
$vtodo = Component::create('VTODO');
$vtodo->DTSTART = '20111223T120000Z';
$tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vtodo2 = clone $vtodo;
$vtodo2->DURATION = 'P1D';
$tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vtodo3 = clone $vtodo;
$vtodo3->DUE = '20111225';
$tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vtodo4 = Component::create('VTODO');
$vtodo4->DUE = '20111225';
$tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vtodo5 = Component::create('VTODO');
$vtodo5->COMPLETED = '20111225';
$tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vtodo6 = Component::create('VTODO');
$vtodo6->CREATED = '20111225';
$tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vtodo7 = Component::create('VTODO');
$vtodo7->CREATED = '20111225';
$vtodo7->COMPLETED = '20111226';
$tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vtodo7 = Component::create('VTODO');
$tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), true);
return $tests;
}
示例13: _fromTine20ModelAddPhoto
/**
* add photo data to VCard
*
* @param Addressbook_Model_Contact $record
* @param \Sabre\VObject\Component $card
*/
protected function _fromTine20ModelAddPhoto(Addressbook_Model_Contact $record, \Sabre\VObject\Component $card)
{
if (!empty($record->jpegphoto)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__);
try {
$jpegData = $record->getSmallContactImage($this->_maxPhotoSize);
$card->add('PHOTO', $jpegData, array('TYPE' => 'JPEG', 'ENCODING' => 'b'));
} catch (Exception $e) {
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Image for contact {$record->getId()} not found or invalid: {$e->getMessage()}");
}
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
}
}
}
}
示例14: convertElementToVCard
/**
* @brief converts a ldif into a owncloud VCard
* @param $element the VCard element to convert
* @return VCard
*/
public function convertElementToVCard($element) {
$dest = \Sabre\VObject\Component::create('VCARD');
foreach ($element as $ldifProperty) {
$importEntry = $this->getImportEntry($ldifProperty[0]);
if ($importEntry) {
$value = $ldifProperty[1];
if (isset($importEntry['remove'])) {
$value = str_replace($importEntry['remove'], '', $ldifProperty[1]);
}
$values = array($value);
if (isset($importEntry['separator'])) {
$values = explode($importEntry['separator'], $value);
}
foreach ($values as $oneValue) {
$this->convertElementToProperty($oneValue, $importEntry, $dest);
}
} else {
$property = \Sabre\VObject\Property::create("X-Unknown-Element", ''.StringUtil::convertToUTF8($ldifProperty[1]));
$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($ldifProperty[0]));
$dest->add($property);
}
}
$dest->validate(\Sabre\VObject\Component\VCard::REPAIR);
return $dest;
}
示例15: getFreeBusyForEmail
/**
* Returns free-busy information for a specific address. The returned
* data is an array containing the following properties:
*
* calendar-data : A VFREEBUSY VObject
* request-status : an iTip status code.
* href: The principal's email address, as requested
*
* The following request status codes may be returned:
* * 2.0;description
* * 3.7;description
*
* @param string $email address
* @param \DateTime $start
* @param \DateTime $end
* @param VObject\Component $request
* @return array
*/
protected function getFreeBusyForEmail($email, \DateTime $start, \DateTime $end, VObject\Component $request)
{
$caldavNS = '{' . Plugin::NS_CALDAV . '}';
$aclPlugin = $this->server->getPlugin('acl');
if (substr($email, 0, 7) === 'mailto:') {
$email = substr($email, 7);
}
$result = $aclPlugin->principalSearch(array('{http://sabredav.org/ns}email-address' => $email), array('{DAV:}principal-URL', $caldavNS . 'calendar-home-set', '{http://sabredav.org/ns}email-address'));
if (!count($result)) {
return array('request-status' => '3.7;Could not find principal', 'href' => 'mailto:' . $email);
}
if (!isset($result[0][200][$caldavNS . 'calendar-home-set'])) {
return array('request-status' => '3.7;No calendar-home-set property found', 'href' => 'mailto:' . $email);
}
$homeSet = $result[0][200][$caldavNS . 'calendar-home-set']->getHref();
// Grabbing the calendar list
$objects = array();
foreach ($this->server->tree->getNodeForPath($homeSet)->getChildren() as $node) {
if (!$node instanceof ICalendar) {
continue;
}
$aclPlugin->checkPrivileges($homeSet . $node->getName(), $caldavNS . 'read-free-busy');
// Getting the list of object uris within the time-range
$urls = $node->calendarQuery(array('name' => 'VCALENDAR', 'comp-filters' => array(array('name' => 'VEVENT', 'comp-filters' => array(), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => array('start' => $start, 'end' => $end))), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => null));
$calObjects = array_map(function ($url) use($node) {
$obj = $node->getChild($url)->get();
return $obj;
}, $urls);
$objects = array_merge($objects, $calObjects);
}
$vcalendar = VObject\Component::create('VCALENDAR');
$vcalendar->VERSION = '2.0';
$vcalendar->METHOD = 'REPLY';
$vcalendar->CALSCALE = 'GREGORIAN';
$vcalendar->PRODID = '-//SabreDAV//SabreDAV ' . DAV\Version::VERSION . '//EN';
$generator = new VObject\FreeBusyGenerator();
$generator->setObjects($objects);
$generator->setTimeRange($start, $end);
$generator->setBaseObject($vcalendar);
$result = $generator->getResult();
$vcalendar->VFREEBUSY->ATTENDEE = 'mailto:' . $email;
$vcalendar->VFREEBUSY->UID = (string) $request->VFREEBUSY->UID;
$vcalendar->VFREEBUSY->ORGANIZER = clone $request->VFREEBUSY->ORGANIZER;
return array('calendar-data' => $result, 'request-status' => '2.0;Success', 'href' => 'mailto:' . $email);
}