commit vendor

This commit is contained in:
2025-11-11 14:49:30 +01:00
parent f33121a308
commit 6d03080c00
2436 changed files with 483781 additions and 0 deletions

View File

@ -0,0 +1,123 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
/**
* The Available sub-component.
*
* This component adds functionality to a component, specific for AVAILABLE
* components.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Ivan Enderlin
* @license http://sabre.io/license/ Modified BSD License
*/
class Available extends VObject\Component
{
/**
* Returns the 'effective start' and 'effective end' of this VAVAILABILITY
* component.
*
* We use the DTSTART and DTEND or DURATION to determine this.
*
* The returned value is an array containing DateTimeImmutable instances.
* If either the start or end is 'unbounded' its value will be null
* instead.
*
* @return array
*/
public function getEffectiveStartEnd()
{
$effectiveStart = $this->DTSTART->getDateTime();
if (isset($this->DTEND)) {
$effectiveEnd = $this->DTEND->getDateTime();
} else {
$effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION));
}
return [$effectiveStart, $effectiveEnd];
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'UID' => 1,
'DTSTART' => 1,
'DTSTAMP' => 1,
'DTEND' => '?',
'DURATION' => '?',
'CREATED' => '?',
'DESCRIPTION' => '?',
'LAST-MODIFIED' => '?',
'RECURRENCE-ID' => '?',
'RRULE' => '?',
'SUMMARY' => '?',
'CATEGORIES' => '*',
'COMMENT' => '*',
'CONTACT' => '*',
'EXDATE' => '*',
'RDATE' => '*',
'AVAILABLE' => '*',
];
}
/**
* Validates the node for correctness.
*
* The following options are supported:
* Node::REPAIR - May attempt to automatically repair the problem.
* Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
* Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
*
* This method returns an array with detected problems.
* Every element has the following properties:
*
* * level - problem level.
* * message - A human-readable string describing the issue.
* * node - A reference to the problematic node.
*
* The level means:
* 1 - The issue was repaired (only happens if REPAIR was turned on).
* 2 - A warning.
* 3 - An error.
*
* @param int $options
*
* @return array
*/
public function validate($options = 0)
{
$result = parent::validate($options);
if (isset($this->DTEND) && isset($this->DURATION)) {
$result[] = [
'level' => 3,
'message' => 'DTEND and DURATION cannot both be present',
'node' => $this,
];
}
return $result;
}
}

View File

@ -0,0 +1,138 @@
<?php
namespace Sabre\VObject\Component;
use DateTimeImmutable;
use DateTimeInterface;
use Sabre\VObject;
use Sabre\VObject\InvalidDataException;
/**
* VAlarm component.
*
* This component contains some additional functionality specific for VALARMs.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class VAlarm extends VObject\Component
{
/**
* Returns a DateTime object when this alarm is going to trigger.
*
* This ignores repeated alarm, only the first trigger is returned.
*
* @return DateTimeImmutable
*/
public function getEffectiveTriggerTime()
{
$trigger = $this->TRIGGER;
if (!isset($trigger['VALUE']) || 'DURATION' === strtoupper($trigger['VALUE'])) {
$triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER);
$related = (isset($trigger['RELATED']) && 'END' == strtoupper($trigger['RELATED'])) ? 'END' : 'START';
$parentComponent = $this->parent;
if ('START' === $related) {
if ('VTODO' === $parentComponent->name) {
$propName = 'DUE';
} else {
$propName = 'DTSTART';
}
$effectiveTrigger = $parentComponent->$propName->getDateTime();
$effectiveTrigger = $effectiveTrigger->add($triggerDuration);
} else {
if ('VTODO' === $parentComponent->name) {
$endProp = 'DUE';
} elseif ('VEVENT' === $parentComponent->name) {
$endProp = 'DTEND';
} else {
throw new InvalidDataException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
}
if (isset($parentComponent->$endProp)) {
$effectiveTrigger = $parentComponent->$endProp->getDateTime();
$effectiveTrigger = $effectiveTrigger->add($triggerDuration);
} elseif (isset($parentComponent->DURATION)) {
$effectiveTrigger = $parentComponent->DTSTART->getDateTime();
$duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION);
$effectiveTrigger = $effectiveTrigger->add($duration);
$effectiveTrigger = $effectiveTrigger->add($triggerDuration);
} else {
$effectiveTrigger = $parentComponent->DTSTART->getDateTime();
$effectiveTrigger = $effectiveTrigger->add($triggerDuration);
}
}
} else {
$effectiveTrigger = $trigger->getDateTime();
}
return $effectiveTrigger;
}
/**
* Returns true or false depending on if the event falls in the specified
* time-range. This is used for filtering purposes.
*
* The rules used to determine if an event falls within the specified
* time-range is based on the CalDAV specification.
*
* @param DateTime $start
* @param DateTime $end
*
* @return bool
*/
public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
{
$effectiveTrigger = $this->getEffectiveTriggerTime();
if (isset($this->DURATION)) {
$duration = VObject\DateTimeParser::parseDuration($this->DURATION);
$repeat = (string) $this->REPEAT;
if (!$repeat) {
$repeat = 1;
}
$period = new \DatePeriod($effectiveTrigger, $duration, (int) $repeat);
foreach ($period as $occurrence) {
if ($start <= $occurrence && $end > $occurrence) {
return true;
}
}
return false;
} else {
return $start <= $effectiveTrigger && $end > $effectiveTrigger;
}
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'ACTION' => 1,
'TRIGGER' => 1,
'DURATION' => '?',
'REPEAT' => '?',
'ATTACH' => '?',
];
}
}

View File

@ -0,0 +1,149 @@
<?php
namespace Sabre\VObject\Component;
use DateTimeInterface;
use Sabre\VObject;
/**
* The VAvailability component.
*
* This component adds functionality to a component, specific for VAVAILABILITY
* components.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Ivan Enderlin
* @license http://sabre.io/license/ Modified BSD License
*/
class VAvailability extends VObject\Component
{
/**
* Returns true or false depending on if the event falls in the specified
* time-range. This is used for filtering purposes.
*
* The rules used to determine if an event falls within the specified
* time-range is based on:
*
* https://tools.ietf.org/html/draft-daboo-calendar-availability-05#section-3.1
*
* @return bool
*/
public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
{
list($effectiveStart, $effectiveEnd) = $this->getEffectiveStartEnd();
return
(is_null($effectiveStart) || $start < $effectiveEnd) &&
(is_null($effectiveEnd) || $end > $effectiveStart)
;
}
/**
* Returns the 'effective start' and 'effective end' of this VAVAILABILITY
* component.
*
* We use the DTSTART and DTEND or DURATION to determine this.
*
* The returned value is an array containing DateTimeImmutable instances.
* If either the start or end is 'unbounded' its value will be null
* instead.
*
* @return array
*/
public function getEffectiveStartEnd()
{
$effectiveStart = null;
$effectiveEnd = null;
if (isset($this->DTSTART)) {
$effectiveStart = $this->DTSTART->getDateTime();
}
if (isset($this->DTEND)) {
$effectiveEnd = $this->DTEND->getDateTime();
} elseif ($effectiveStart && isset($this->DURATION)) {
$effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION));
}
return [$effectiveStart, $effectiveEnd];
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'UID' => 1,
'DTSTAMP' => 1,
'BUSYTYPE' => '?',
'CLASS' => '?',
'CREATED' => '?',
'DESCRIPTION' => '?',
'DTSTART' => '?',
'LAST-MODIFIED' => '?',
'ORGANIZER' => '?',
'PRIORITY' => '?',
'SEQUENCE' => '?',
'SUMMARY' => '?',
'URL' => '?',
'DTEND' => '?',
'DURATION' => '?',
'CATEGORIES' => '*',
'COMMENT' => '*',
'CONTACT' => '*',
];
}
/**
* Validates the node for correctness.
*
* The following options are supported:
* Node::REPAIR - May attempt to automatically repair the problem.
* Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
* Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
*
* This method returns an array with detected problems.
* Every element has the following properties:
*
* * level - problem level.
* * message - A human-readable string describing the issue.
* * node - A reference to the problematic node.
*
* The level means:
* 1 - The issue was repaired (only happens if REPAIR was turned on).
* 2 - A warning.
* 3 - An error.
*
* @param int $options
*
* @return array
*/
public function validate($options = 0)
{
$result = parent::validate($options);
if (isset($this->DTEND) && isset($this->DURATION)) {
$result[] = [
'level' => 3,
'message' => 'DTEND and DURATION cannot both be present',
'node' => $this,
];
}
return $result;
}
}

View File

@ -0,0 +1,528 @@
<?php
namespace Sabre\VObject\Component;
use DateTimeInterface;
use DateTimeZone;
use Sabre\VObject;
use Sabre\VObject\Component;
use Sabre\VObject\InvalidDataException;
use Sabre\VObject\Property;
use Sabre\VObject\Recur\EventIterator;
use Sabre\VObject\Recur\NoInstancesException;
/**
* The VCalendar component.
*
* This component adds functionality to a component, specific for a VCALENDAR.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class VCalendar extends VObject\Document
{
/**
* The default name for this component.
*
* This should be 'VCALENDAR' or 'VCARD'.
*
* @var string
*/
public static $defaultName = 'VCALENDAR';
/**
* This is a list of components, and which classes they should map to.
*
* @var array
*/
public static $componentMap = [
'VCALENDAR' => self::class,
'VALARM' => VAlarm::class,
'VEVENT' => VEvent::class,
'VFREEBUSY' => VFreeBusy::class,
'VAVAILABILITY' => VAvailability::class,
'AVAILABLE' => Available::class,
'VJOURNAL' => VJournal::class,
'VTIMEZONE' => VTimeZone::class,
'VTODO' => VTodo::class,
];
/**
* List of value-types, and which classes they map to.
*
* @var array
*/
public static $valueMap = [
'BINARY' => VObject\Property\Binary::class,
'BOOLEAN' => VObject\Property\Boolean::class,
'CAL-ADDRESS' => VObject\Property\ICalendar\CalAddress::class,
'DATE' => VObject\Property\ICalendar\Date::class,
'DATE-TIME' => VObject\Property\ICalendar\DateTime::class,
'DURATION' => VObject\Property\ICalendar\Duration::class,
'FLOAT' => VObject\Property\FloatValue::class,
'INTEGER' => VObject\Property\IntegerValue::class,
'PERIOD' => VObject\Property\ICalendar\Period::class,
'RECUR' => VObject\Property\ICalendar\Recur::class,
'TEXT' => VObject\Property\Text::class,
'TIME' => VObject\Property\Time::class,
'UNKNOWN' => VObject\Property\Unknown::class, // jCard / jCal-only.
'URI' => VObject\Property\Uri::class,
'UTC-OFFSET' => VObject\Property\UtcOffset::class,
];
/**
* List of properties, and which classes they map to.
*
* @var array
*/
public static $propertyMap = [
// Calendar properties
'CALSCALE' => VObject\Property\FlatText::class,
'METHOD' => VObject\Property\FlatText::class,
'PRODID' => VObject\Property\FlatText::class,
'VERSION' => VObject\Property\FlatText::class,
// Component properties
'ATTACH' => VObject\Property\Uri::class,
'CATEGORIES' => VObject\Property\Text::class,
'CLASS' => VObject\Property\FlatText::class,
'COMMENT' => VObject\Property\FlatText::class,
'DESCRIPTION' => VObject\Property\FlatText::class,
'GEO' => VObject\Property\FloatValue::class,
'LOCATION' => VObject\Property\FlatText::class,
'PERCENT-COMPLETE' => VObject\Property\IntegerValue::class,
'PRIORITY' => VObject\Property\IntegerValue::class,
'RESOURCES' => VObject\Property\Text::class,
'STATUS' => VObject\Property\FlatText::class,
'SUMMARY' => VObject\Property\FlatText::class,
// Date and Time Component Properties
'COMPLETED' => VObject\Property\ICalendar\DateTime::class,
'DTEND' => VObject\Property\ICalendar\DateTime::class,
'DUE' => VObject\Property\ICalendar\DateTime::class,
'DTSTART' => VObject\Property\ICalendar\DateTime::class,
'DURATION' => VObject\Property\ICalendar\Duration::class,
'FREEBUSY' => VObject\Property\ICalendar\Period::class,
'TRANSP' => VObject\Property\FlatText::class,
// Time Zone Component Properties
'TZID' => VObject\Property\FlatText::class,
'TZNAME' => VObject\Property\FlatText::class,
'TZOFFSETFROM' => VObject\Property\UtcOffset::class,
'TZOFFSETTO' => VObject\Property\UtcOffset::class,
'TZURL' => VObject\Property\Uri::class,
// Relationship Component Properties
'ATTENDEE' => VObject\Property\ICalendar\CalAddress::class,
'CONTACT' => VObject\Property\FlatText::class,
'ORGANIZER' => VObject\Property\ICalendar\CalAddress::class,
'RECURRENCE-ID' => VObject\Property\ICalendar\DateTime::class,
'RELATED-TO' => VObject\Property\FlatText::class,
'URL' => VObject\Property\Uri::class,
'UID' => VObject\Property\FlatText::class,
// Recurrence Component Properties
'EXDATE' => VObject\Property\ICalendar\DateTime::class,
'RDATE' => VObject\Property\ICalendar\DateTime::class,
'RRULE' => VObject\Property\ICalendar\Recur::class,
'EXRULE' => VObject\Property\ICalendar\Recur::class, // Deprecated since rfc5545
// Alarm Component Properties
'ACTION' => VObject\Property\FlatText::class,
'REPEAT' => VObject\Property\IntegerValue::class,
'TRIGGER' => VObject\Property\ICalendar\Duration::class,
// Change Management Component Properties
'CREATED' => VObject\Property\ICalendar\DateTime::class,
'DTSTAMP' => VObject\Property\ICalendar\DateTime::class,
'LAST-MODIFIED' => VObject\Property\ICalendar\DateTime::class,
'SEQUENCE' => VObject\Property\IntegerValue::class,
// Request Status
'REQUEST-STATUS' => VObject\Property\Text::class,
// Additions from draft-daboo-valarm-extensions-04
'ALARM-AGENT' => VObject\Property\Text::class,
'ACKNOWLEDGED' => VObject\Property\ICalendar\DateTime::class,
'PROXIMITY' => VObject\Property\Text::class,
'DEFAULT-ALARM' => VObject\Property\Boolean::class,
// Additions from draft-daboo-calendar-availability-05
'BUSYTYPE' => VObject\Property\Text::class,
];
/**
* Returns the current document type.
*
* @return int
*/
public function getDocumentType()
{
return self::ICALENDAR20;
}
/**
* Returns a list of all 'base components'. For instance, if an Event has
* a recurrence rule, and one instance is overridden, the overridden event
* will have the same UID, but will be excluded from this list.
*
* VTIMEZONE components will always be excluded.
*
* @param string $componentName filter by component name
*
* @return VObject\Component[]
*/
public function getBaseComponents($componentName = null)
{
$isBaseComponent = function ($component) {
if (!$component instanceof VObject\Component) {
return false;
}
if ('VTIMEZONE' === $component->name) {
return false;
}
if (isset($component->{'RECURRENCE-ID'})) {
return false;
}
return true;
};
if ($componentName) {
// Early exit
return array_filter(
$this->select($componentName),
$isBaseComponent
);
}
$components = [];
foreach ($this->children as $childGroup) {
foreach ($childGroup as $child) {
if (!$child instanceof Component) {
// If one child is not a component, they all are so we skip
// the entire group.
continue 2;
}
if ($isBaseComponent($child)) {
$components[] = $child;
}
}
}
return $components;
}
/**
* Returns the first component that is not a VTIMEZONE, and does not have
* an RECURRENCE-ID.
*
* If there is no such component, null will be returned.
*
* @param string $componentName filter by component name
*
* @return VObject\Component|null
*/
public function getBaseComponent($componentName = null)
{
$isBaseComponent = function ($component) {
if (!$component instanceof VObject\Component) {
return false;
}
if ('VTIMEZONE' === $component->name) {
return false;
}
if (isset($component->{'RECURRENCE-ID'})) {
return false;
}
return true;
};
if ($componentName) {
foreach ($this->select($componentName) as $child) {
if ($isBaseComponent($child)) {
return $child;
}
}
return null;
}
// Searching all components
foreach ($this->children as $childGroup) {
foreach ($childGroup as $child) {
if ($isBaseComponent($child)) {
return $child;
}
}
}
return null;
}
/**
* Expand all events in this VCalendar object and return a new VCalendar
* with the expanded events.
*
* If this calendar object, has events with recurrence rules, this method
* can be used to expand the event into multiple sub-events.
*
* Each event will be stripped from its recurrence information, and only
* the instances of the event in the specified timerange will be left
* alone.
*
* In addition, this method will cause timezone information to be stripped,
* and normalized to UTC.
*
* @param DateTimeZone $timeZone reference timezone for floating dates and
* times
*
* @return VCalendar
*/
public function expand(DateTimeInterface $start, DateTimeInterface $end, DateTimeZone $timeZone = null)
{
$newChildren = [];
$recurringEvents = [];
if (!$timeZone) {
$timeZone = new DateTimeZone('UTC');
}
$stripTimezones = function (Component $component) use ($timeZone, &$stripTimezones) {
foreach ($component->children() as $componentChild) {
if ($componentChild instanceof Property\ICalendar\DateTime && $componentChild->hasTime()) {
$dt = $componentChild->getDateTimes($timeZone);
// We only need to update the first timezone, because
// setDateTimes will match all other timezones to the
// first.
$dt[0] = $dt[0]->setTimeZone(new DateTimeZone('UTC'));
$componentChild->setDateTimes($dt);
} elseif ($componentChild instanceof Component) {
$stripTimezones($componentChild);
}
}
return $component;
};
foreach ($this->children() as $child) {
if ($child instanceof Property && 'PRODID' !== $child->name) {
// We explictly want to ignore PRODID, because we want to
// overwrite it with our own.
$newChildren[] = clone $child;
} elseif ($child instanceof Component && 'VTIMEZONE' !== $child->name) {
// We're also stripping all VTIMEZONE objects because we're
// converting everything to UTC.
if ('VEVENT' === $child->name && (isset($child->{'RECURRENCE-ID'}) || isset($child->RRULE) || isset($child->RDATE))) {
// Handle these a bit later.
$uid = (string) $child->UID;
if (!$uid) {
throw new InvalidDataException('Every VEVENT object must have a UID property');
}
if (isset($recurringEvents[$uid])) {
$recurringEvents[$uid][] = clone $child;
} else {
$recurringEvents[$uid] = [clone $child];
}
} elseif ('VEVENT' === $child->name && $child->isInTimeRange($start, $end)) {
$newChildren[] = $stripTimezones(clone $child);
}
}
}
foreach ($recurringEvents as $events) {
try {
$it = new EventIterator($events, null, $timeZone);
} catch (NoInstancesException $e) {
// This event is recurring, but it doesn't have a single
// instance. We are skipping this event from the output
// entirely.
continue;
}
$it->fastForward($start);
while ($it->valid() && $it->getDTStart() < $end) {
if ($it->getDTEnd() > $start) {
$newChildren[] = $stripTimezones($it->getEventObject());
}
$it->next();
}
}
return new self($newChildren);
}
/**
* This method should return a list of default property values.
*
* @return array
*/
protected function getDefaults()
{
return [
'VERSION' => '2.0',
'PRODID' => '-//Sabre//Sabre VObject '.VObject\Version::VERSION.'//EN',
'CALSCALE' => 'GREGORIAN',
];
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'PRODID' => 1,
'VERSION' => 1,
'CALSCALE' => '?',
'METHOD' => '?',
];
}
/**
* Validates the node for correctness.
*
* The following options are supported:
* Node::REPAIR - May attempt to automatically repair the problem.
* Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
* Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
*
* This method returns an array with detected problems.
* Every element has the following properties:
*
* * level - problem level.
* * message - A human-readable string describing the issue.
* * node - A reference to the problematic node.
*
* The level means:
* 1 - The issue was repaired (only happens if REPAIR was turned on).
* 2 - A warning.
* 3 - An error.
*
* @param int $options
*
* @return array
*/
public function validate($options = 0)
{
$warnings = parent::validate($options);
if ($ver = $this->VERSION) {
if ('2.0' !== (string) $ver) {
$warnings[] = [
'level' => 3,
'message' => 'Only iCalendar version 2.0 as defined in rfc5545 is supported.',
'node' => $this,
];
}
}
$uidList = [];
$componentsFound = 0;
$componentTypes = [];
foreach ($this->children() as $child) {
if ($child instanceof Component) {
++$componentsFound;
if (!in_array($child->name, ['VEVENT', 'VTODO', 'VJOURNAL'])) {
continue;
}
$componentTypes[] = $child->name;
$uid = (string) $child->UID;
$isMaster = isset($child->{'RECURRENCE-ID'}) ? 0 : 1;
if (isset($uidList[$uid])) {
++$uidList[$uid]['count'];
if ($isMaster && $uidList[$uid]['hasMaster']) {
$warnings[] = [
'level' => 3,
'message' => 'More than one master object was found for the object with UID '.$uid,
'node' => $this,
];
}
$uidList[$uid]['hasMaster'] += $isMaster;
} else {
$uidList[$uid] = [
'count' => 1,
'hasMaster' => $isMaster,
];
}
}
}
if (0 === $componentsFound) {
$warnings[] = [
'level' => 3,
'message' => 'An iCalendar object must have at least 1 component.',
'node' => $this,
];
}
if ($options & self::PROFILE_CALDAV) {
if (count($uidList) > 1) {
$warnings[] = [
'level' => 3,
'message' => 'A calendar object on a CalDAV server may only have components with the same UID.',
'node' => $this,
];
}
if (0 === count($componentTypes)) {
$warnings[] = [
'level' => 3,
'message' => 'A calendar object on a CalDAV server must have at least 1 component (VTODO, VEVENT, VJOURNAL).',
'node' => $this,
];
}
if (count(array_unique($componentTypes)) > 1) {
$warnings[] = [
'level' => 3,
'message' => 'A calendar object on a CalDAV server may only have 1 type of component (VEVENT, VTODO or VJOURNAL).',
'node' => $this,
];
}
if (isset($this->METHOD)) {
$warnings[] = [
'level' => 3,
'message' => 'A calendar object on a CalDAV server MUST NOT have a METHOD property.',
'node' => $this,
];
}
}
return $warnings;
}
/**
* Returns all components with a specific UID value.
*
* @return array
*/
public function getByUID($uid)
{
return array_filter($this->getComponents(), function ($item) use ($uid) {
if (!$itemUid = $item->select('UID')) {
return false;
}
$itemUid = current($itemUid)->getValue();
return $uid === $itemUid;
});
}
}

View File

@ -0,0 +1,535 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
use Sabre\Xml;
/**
* The VCard component.
*
* This component represents the BEGIN:VCARD and END:VCARD found in every
* vcard.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class VCard extends VObject\Document
{
/**
* The default name for this component.
*
* This should be 'VCALENDAR' or 'VCARD'.
*
* @var string
*/
public static $defaultName = 'VCARD';
/**
* Caching the version number.
*
* @var int
*/
private $version = null;
/**
* This is a list of components, and which classes they should map to.
*
* @var array
*/
public static $componentMap = [
'VCARD' => VCard::class,
];
/**
* List of value-types, and which classes they map to.
*
* @var array
*/
public static $valueMap = [
'BINARY' => VObject\Property\Binary::class,
'BOOLEAN' => VObject\Property\Boolean::class,
'CONTENT-ID' => VObject\Property\FlatText::class, // vCard 2.1 only
'DATE' => VObject\Property\VCard\Date::class,
'DATE-TIME' => VObject\Property\VCard\DateTime::class,
'DATE-AND-OR-TIME' => VObject\Property\VCard\DateAndOrTime::class, // vCard only
'FLOAT' => VObject\Property\FloatValue::class,
'INTEGER' => VObject\Property\IntegerValue::class,
'LANGUAGE-TAG' => VObject\Property\VCard\LanguageTag::class,
'PHONE-NUMBER' => VObject\Property\VCard\PhoneNumber::class, // vCard 3.0 only
'TIMESTAMP' => VObject\Property\VCard\TimeStamp::class,
'TEXT' => VObject\Property\Text::class,
'TIME' => VObject\Property\Time::class,
'UNKNOWN' => VObject\Property\Unknown::class, // jCard / jCal-only.
'URI' => VObject\Property\Uri::class,
'URL' => VObject\Property\Uri::class, // vCard 2.1 only
'UTC-OFFSET' => VObject\Property\UtcOffset::class,
];
/**
* List of properties, and which classes they map to.
*
* @var array
*/
public static $propertyMap = [
// vCard 2.1 properties and up
'N' => VObject\Property\Text::class,
'FN' => VObject\Property\FlatText::class,
'PHOTO' => VObject\Property\Binary::class,
'BDAY' => VObject\Property\VCard\DateAndOrTime::class,
'ADR' => VObject\Property\Text::class,
'LABEL' => VObject\Property\FlatText::class, // Removed in vCard 4.0
'TEL' => VObject\Property\FlatText::class,
'EMAIL' => VObject\Property\FlatText::class,
'MAILER' => VObject\Property\FlatText::class, // Removed in vCard 4.0
'GEO' => VObject\Property\FlatText::class,
'TITLE' => VObject\Property\FlatText::class,
'ROLE' => VObject\Property\FlatText::class,
'LOGO' => VObject\Property\Binary::class,
// 'AGENT' => 'Sabre\\VObject\\Property\\', // Todo: is an embedded vCard. Probably rare, so
// not supported at the moment
'ORG' => VObject\Property\Text::class,
'NOTE' => VObject\Property\FlatText::class,
'REV' => VObject\Property\VCard\TimeStamp::class,
'SOUND' => VObject\Property\FlatText::class,
'URL' => VObject\Property\Uri::class,
'UID' => VObject\Property\FlatText::class,
'VERSION' => VObject\Property\FlatText::class,
'KEY' => VObject\Property\FlatText::class,
'TZ' => VObject\Property\Text::class,
// vCard 3.0 properties
'CATEGORIES' => VObject\Property\Text::class,
'SORT-STRING' => VObject\Property\FlatText::class,
'PRODID' => VObject\Property\FlatText::class,
'NICKNAME' => VObject\Property\Text::class,
'CLASS' => VObject\Property\FlatText::class, // Removed in vCard 4.0
// rfc2739 properties
'FBURL' => VObject\Property\Uri::class,
'CAPURI' => VObject\Property\Uri::class,
'CALURI' => VObject\Property\Uri::class,
'CALADRURI' => VObject\Property\Uri::class,
// rfc4770 properties
'IMPP' => VObject\Property\Uri::class,
// vCard 4.0 properties
'SOURCE' => VObject\Property\Uri::class,
'XML' => VObject\Property\FlatText::class,
'ANNIVERSARY' => VObject\Property\VCard\DateAndOrTime::class,
'CLIENTPIDMAP' => VObject\Property\Text::class,
'LANG' => VObject\Property\VCard\LanguageTag::class,
'GENDER' => VObject\Property\Text::class,
'KIND' => VObject\Property\FlatText::class,
'MEMBER' => VObject\Property\Uri::class,
'RELATED' => VObject\Property\Uri::class,
// rfc6474 properties
'BIRTHPLACE' => VObject\Property\FlatText::class,
'DEATHPLACE' => VObject\Property\FlatText::class,
'DEATHDATE' => VObject\Property\VCard\DateAndOrTime::class,
// rfc6715 properties
'EXPERTISE' => VObject\Property\FlatText::class,
'HOBBY' => VObject\Property\FlatText::class,
'INTEREST' => VObject\Property\FlatText::class,
'ORG-DIRECTORY' => VObject\Property\FlatText::class,
];
/**
* Returns the current document type.
*
* @return int
*/
public function getDocumentType()
{
if (!$this->version) {
$version = (string) $this->VERSION;
switch ($version) {
case '2.1':
$this->version = self::VCARD21;
break;
case '3.0':
$this->version = self::VCARD30;
break;
case '4.0':
$this->version = self::VCARD40;
break;
default:
// We don't want to cache the version if it's unknown,
// because we might get a version property in a bit.
return self::UNKNOWN;
}
}
return $this->version;
}
/**
* Converts the document to a different vcard version.
*
* Use one of the VCARD constants for the target. This method will return
* a copy of the vcard in the new version.
*
* At the moment the only supported conversion is from 3.0 to 4.0.
*
* If input and output version are identical, a clone is returned.
*
* @param int $target
*
* @return VCard
*/
public function convert($target)
{
$converter = new VObject\VCardConverter();
return $converter->convert($this, $target);
}
/**
* VCards with version 2.1, 3.0 and 4.0 are found.
*
* If the VCARD doesn't know its version, 2.1 is assumed.
*/
const DEFAULT_VERSION = self::VCARD21;
/**
* Validates the node for correctness.
*
* The following options are supported:
* Node::REPAIR - May attempt to automatically repair the problem.
*
* This method returns an array with detected problems.
* Every element has the following properties:
*
* * level - problem level.
* * message - A human-readable string describing the issue.
* * node - A reference to the problematic node.
*
* The level means:
* 1 - The issue was repaired (only happens if REPAIR was turned on)
* 2 - An inconsequential issue
* 3 - A severe issue.
*
* @param int $options
*
* @return array
*/
public function validate($options = 0)
{
$warnings = [];
$versionMap = [
self::VCARD21 => '2.1',
self::VCARD30 => '3.0',
self::VCARD40 => '4.0',
];
$version = $this->select('VERSION');
if (1 === count($version)) {
$version = (string) $this->VERSION;
if ('2.1' !== $version && '3.0' !== $version && '4.0' !== $version) {
$warnings[] = [
'level' => 3,
'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
'node' => $this,
];
if ($options & self::REPAIR) {
$this->VERSION = $versionMap[self::DEFAULT_VERSION];
}
}
if ('2.1' === $version && ($options & self::PROFILE_CARDDAV)) {
$warnings[] = [
'level' => 3,
'message' => 'CardDAV servers are not allowed to accept vCard 2.1.',
'node' => $this,
];
}
}
$uid = $this->select('UID');
if (0 === count($uid)) {
if ($options & self::PROFILE_CARDDAV) {
// Required for CardDAV
$warningLevel = 3;
$message = 'vCards on CardDAV servers MUST have a UID property.';
} else {
// Not required for regular vcards
$warningLevel = 2;
$message = 'Adding a UID to a vCard property is recommended.';
}
if ($options & self::REPAIR) {
$this->UID = VObject\UUIDUtil::getUUID();
$warningLevel = 1;
}
$warnings[] = [
'level' => $warningLevel,
'message' => $message,
'node' => $this,
];
}
$fn = $this->select('FN');
if (1 !== count($fn)) {
$repaired = false;
if (($options & self::REPAIR) && 0 === count($fn)) {
// We're going to try to see if we can use the contents of the
// N property.
if (isset($this->N)) {
$value = explode(';', (string) $this->N);
if (isset($value[1]) && $value[1]) {
$this->FN = $value[1].' '.$value[0];
} else {
$this->FN = $value[0];
}
$repaired = true;
// Otherwise, the ORG property may work
} elseif (isset($this->ORG)) {
$this->FN = (string) $this->ORG;
$repaired = true;
// Otherwise, the EMAIL property may work
} elseif (isset($this->EMAIL)) {
$this->FN = (string) $this->EMAIL;
$repaired = true;
}
}
$warnings[] = [
'level' => $repaired ? 1 : 3,
'message' => 'The FN property must appear in the VCARD component exactly 1 time',
'node' => $this,
];
}
return array_merge(
parent::validate($options),
$warnings
);
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'ADR' => '*',
'ANNIVERSARY' => '?',
'BDAY' => '?',
'CALADRURI' => '*',
'CALURI' => '*',
'CATEGORIES' => '*',
'CLIENTPIDMAP' => '*',
'EMAIL' => '*',
'FBURL' => '*',
'IMPP' => '*',
'GENDER' => '?',
'GEO' => '*',
'KEY' => '*',
'KIND' => '?',
'LANG' => '*',
'LOGO' => '*',
'MEMBER' => '*',
'N' => '?',
'NICKNAME' => '*',
'NOTE' => '*',
'ORG' => '*',
'PHOTO' => '*',
'PRODID' => '?',
'RELATED' => '*',
'REV' => '?',
'ROLE' => '*',
'SOUND' => '*',
'SOURCE' => '*',
'TEL' => '*',
'TITLE' => '*',
'TZ' => '*',
'URL' => '*',
'VERSION' => '1',
'XML' => '*',
// FN is commented out, because it's already handled by the
// validate function, which may also try to repair it.
// 'FN' => '+',
'UID' => '?',
];
}
/**
* Returns a preferred field.
*
* VCards can indicate wether a field such as ADR, TEL or EMAIL is
* preferred by specifying TYPE=PREF (vcard 2.1, 3) or PREF=x (vcard 4, x
* being a number between 1 and 100).
*
* If neither of those parameters are specified, the first is returned, if
* a field with that name does not exist, null is returned.
*
* @param string $fieldName
*
* @return VObject\Property|null
*/
public function preferred($propertyName)
{
$preferred = null;
$lastPref = 101;
foreach ($this->select($propertyName) as $field) {
$pref = 101;
if (isset($field['TYPE']) && $field['TYPE']->has('PREF')) {
$pref = 1;
} elseif (isset($field['PREF'])) {
$pref = $field['PREF']->getValue();
}
if ($pref < $lastPref || is_null($preferred)) {
$preferred = $field;
$lastPref = $pref;
}
}
return $preferred;
}
/**
* Returns a property with a specific TYPE value (ADR, TEL, or EMAIL).
*
* This function will return null if the property does not exist. If there are
* multiple properties with the same TYPE value, only one will be returned.
*
* @param string $propertyName
* @param string $type
*
* @return VObject\Property|null
*/
public function getByType($propertyName, $type)
{
foreach ($this->select($propertyName) as $field) {
if (isset($field['TYPE']) && $field['TYPE']->has($type)) {
return $field;
}
}
}
/**
* This method should return a list of default property values.
*
* @return array
*/
protected function getDefaults()
{
return [
'VERSION' => '4.0',
'PRODID' => '-//Sabre//Sabre VObject '.VObject\Version::VERSION.'//EN',
'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(),
];
}
/**
* This method returns an array, with the representation as it should be
* encoded in json. This is used to create jCard or jCal documents.
*
* @return array
*/
public function jsonSerialize()
{
// A vcard does not have sub-components, so we're overriding this
// method to remove that array element.
$properties = [];
foreach ($this->children() as $child) {
$properties[] = $child->jsonSerialize();
}
return [
strtolower($this->name),
$properties,
];
}
/**
* This method serializes the data into XML. This is used to create xCard or
* xCal documents.
*
* @param Xml\Writer $writer XML writer
*/
public function xmlSerialize(Xml\Writer $writer)
{
$propertiesByGroup = [];
foreach ($this->children() as $property) {
$group = $property->group;
if (!isset($propertiesByGroup[$group])) {
$propertiesByGroup[$group] = [];
}
$propertiesByGroup[$group][] = $property;
}
$writer->startElement(strtolower($this->name));
foreach ($propertiesByGroup as $group => $properties) {
if (!empty($group)) {
$writer->startElement('group');
$writer->writeAttribute('name', strtolower($group));
}
foreach ($properties as $property) {
switch ($property->name) {
case 'VERSION':
break;
case 'XML':
$value = $property->getParts();
$fragment = new Xml\Element\XmlFragment($value[0]);
$writer->write($fragment);
break;
default:
$property->xmlSerialize($writer);
break;
}
}
if (!empty($group)) {
$writer->endElement();
}
}
$writer->endElement();
}
/**
* Returns the default class for a property name.
*
* @param string $propertyName
*
* @return string
*/
public function getClassNameForPropertyName($propertyName)
{
$className = parent::getClassNameForPropertyName($propertyName);
// In vCard 4, BINARY no longer exists, and we need URI instead.
if (VObject\Property\Binary::class == $className && self::VCARD40 === $this->getDocumentType()) {
return VObject\Property\Uri::class;
}
return $className;
}
}

View File

@ -0,0 +1,140 @@
<?php
namespace Sabre\VObject\Component;
use DateTimeInterface;
use Sabre\VObject;
use Sabre\VObject\Recur\EventIterator;
use Sabre\VObject\Recur\NoInstancesException;
/**
* VEvent component.
*
* This component contains some additional functionality specific for VEVENT's.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class VEvent extends VObject\Component
{
/**
* Returns true or false depending on if the event falls in the specified
* time-range. This is used for filtering purposes.
*
* The rules used to determine if an event falls within the specified
* time-range is based on the CalDAV specification.
*
* @return bool
*/
public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
{
if ($this->RRULE) {
try {
$it = new EventIterator($this, null, $start->getTimezone());
} catch (NoInstancesException $e) {
// If we've caught this exception, there are no instances
// for the event that fall into the specified time-range.
return false;
}
$it->fastForward($start);
// We fast-forwarded to a spot where the end-time of the
// recurrence instance exceeded the start of the requested
// time-range.
//
// If the starttime of the recurrence did not exceed the
// end of the time range as well, we have a match.
return $it->getDTStart() < $end && $it->getDTEnd() > $start;
}
$effectiveStart = $this->DTSTART->getDateTime($start->getTimezone());
if (isset($this->DTEND)) {
// The DTEND property is considered non inclusive. So for a 3 day
// event in july, dtstart and dtend would have to be July 1st and
// July 4th respectively.
//
// See:
// http://tools.ietf.org/html/rfc5545#page-54
$effectiveEnd = $this->DTEND->getDateTime($end->getTimezone());
} elseif (isset($this->DURATION)) {
$effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION));
} elseif (!$this->DTSTART->hasTime()) {
$effectiveEnd = $effectiveStart->modify('+1 day');
} else {
$effectiveEnd = $effectiveStart;
}
return
($start < $effectiveEnd) && ($end > $effectiveStart)
;
}
/**
* This method should return a list of default property values.
*
* @return array
*/
protected function getDefaults()
{
return [
'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(),
'DTSTAMP' => gmdate('Ymd\\THis\\Z'),
];
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
$hasMethod = isset($this->parent->METHOD);
return [
'UID' => 1,
'DTSTAMP' => 1,
'DTSTART' => $hasMethod ? '?' : '1',
'CLASS' => '?',
'CREATED' => '?',
'DESCRIPTION' => '?',
'GEO' => '?',
'LAST-MODIFIED' => '?',
'LOCATION' => '?',
'ORGANIZER' => '?',
'PRIORITY' => '?',
'SEQUENCE' => '?',
'STATUS' => '?',
'SUMMARY' => '?',
'TRANSP' => '?',
'URL' => '?',
'RECURRENCE-ID' => '?',
'RRULE' => '?',
'DTEND' => '?',
'DURATION' => '?',
'ATTACH' => '*',
'ATTENDEE' => '*',
'CATEGORIES' => '*',
'COMMENT' => '*',
'CONTACT' => '*',
'EXDATE' => '*',
'REQUEST-STATUS' => '*',
'RELATED-TO' => '*',
'RESOURCES' => '*',
'RDATE' => '*',
];
}
}

View File

@ -0,0 +1,93 @@
<?php
namespace Sabre\VObject\Component;
use DateTimeInterface;
use Sabre\VObject;
/**
* The VFreeBusy component.
*
* This component adds functionality to a component, specific for VFREEBUSY
* components.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class VFreeBusy extends VObject\Component
{
/**
* Checks based on the contained FREEBUSY information, if a timeslot is
* available.
*
* @return bool
*/
public function isFree(DateTimeInterface $start, DatetimeInterface $end)
{
foreach ($this->select('FREEBUSY') as $freebusy) {
// We are only interested in FBTYPE=BUSY (the default),
// FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE.
if (isset($freebusy['FBTYPE']) && 'BUSY' !== strtoupper(substr((string) $freebusy['FBTYPE'], 0, 4))) {
continue;
}
// The freebusy component can hold more than 1 value, separated by
// commas.
$periods = explode(',', (string) $freebusy);
foreach ($periods as $period) {
// Every period is formatted as [start]/[end]. The start is an
// absolute UTC time, the end may be an absolute UTC time, or
// duration (relative) value.
list($busyStart, $busyEnd) = explode('/', $period);
$busyStart = VObject\DateTimeParser::parse($busyStart);
$busyEnd = VObject\DateTimeParser::parse($busyEnd);
if ($busyEnd instanceof \DateInterval) {
$busyEnd = $busyStart->add($busyEnd);
}
if ($start < $busyEnd && $end > $busyStart) {
return false;
}
}
}
return true;
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'UID' => 1,
'DTSTAMP' => 1,
'CONTACT' => '?',
'DTSTART' => '?',
'DTEND' => '?',
'ORGANIZER' => '?',
'URL' => '?',
'ATTENDEE' => '*',
'COMMENT' => '*',
'FREEBUSY' => '*',
'REQUEST-STATUS' => '*',
];
}
}

View File

@ -0,0 +1,101 @@
<?php
namespace Sabre\VObject\Component;
use DateTimeInterface;
use Sabre\VObject;
/**
* VJournal component.
*
* This component contains some additional functionality specific for VJOURNALs.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class VJournal extends VObject\Component
{
/**
* Returns true or false depending on if the event falls in the specified
* time-range. This is used for filtering purposes.
*
* The rules used to determine if an event falls within the specified
* time-range is based on the CalDAV specification.
*
* @return bool
*/
public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
{
$dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null;
if ($dtstart) {
$effectiveEnd = $dtstart;
if (!$this->DTSTART->hasTime()) {
$effectiveEnd = $effectiveEnd->modify('+1 day');
}
return $start <= $effectiveEnd && $end > $dtstart;
}
return false;
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'UID' => 1,
'DTSTAMP' => 1,
'CLASS' => '?',
'CREATED' => '?',
'DTSTART' => '?',
'LAST-MODIFIED' => '?',
'ORGANIZER' => '?',
'RECURRENCE-ID' => '?',
'SEQUENCE' => '?',
'STATUS' => '?',
'SUMMARY' => '?',
'URL' => '?',
'RRULE' => '?',
'ATTACH' => '*',
'ATTENDEE' => '*',
'CATEGORIES' => '*',
'COMMENT' => '*',
'CONTACT' => '*',
'DESCRIPTION' => '*',
'EXDATE' => '*',
'RELATED-TO' => '*',
'RDATE' => '*',
];
}
/**
* This method should return a list of default property values.
*
* @return array
*/
protected function getDefaults()
{
return [
'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(),
'DTSTAMP' => gmdate('Ymd\\THis\\Z'),
];
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
/**
* The VTimeZone component.
*
* This component adds functionality to a component, specific for VTIMEZONE
* components.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class VTimeZone extends VObject\Component
{
/**
* Returns the PHP DateTimeZone for this VTIMEZONE component.
*
* If we can't accurately determine the timezone, this method will return
* UTC.
*
* @return \DateTimeZone
*/
public function getTimeZone()
{
return VObject\TimeZoneUtil::getTimeZone((string) $this->TZID, $this->root);
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'TZID' => 1,
'LAST-MODIFIED' => '?',
'TZURL' => '?',
// At least 1 STANDARD or DAYLIGHT must appear.
//
// The validator is not specific yet to pick this up, so these
// rules are too loose.
'STANDARD' => '*',
'DAYLIGHT' => '*',
];
}
}

View File

@ -0,0 +1,181 @@
<?php
namespace Sabre\VObject\Component;
use DateTimeInterface;
use Sabre\VObject;
/**
* VTodo component.
*
* This component contains some additional functionality specific for VTODOs.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class VTodo extends VObject\Component
{
/**
* Returns true or false depending on if the event falls in the specified
* time-range. This is used for filtering purposes.
*
* The rules used to determine if an event falls within the specified
* time-range is based on the CalDAV specification.
*
* @return bool
*/
public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
{
$dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null;
$duration = isset($this->DURATION) ? VObject\DateTimeParser::parseDuration($this->DURATION) : null;
$due = isset($this->DUE) ? $this->DUE->getDateTime() : null;
$completed = isset($this->COMPLETED) ? $this->COMPLETED->getDateTime() : null;
$created = isset($this->CREATED) ? $this->CREATED->getDateTime() : null;
if ($dtstart) {
if ($duration) {
$effectiveEnd = $dtstart->add($duration);
return $start <= $effectiveEnd && $end > $dtstart;
} elseif ($due) {
return
($start < $due || $start <= $dtstart) &&
($end > $dtstart || $end >= $due);
} else {
return $start <= $dtstart && $end > $dtstart;
}
}
if ($due) {
return $start < $due && $end >= $due;
}
if ($completed && $created) {
return
($start <= $created || $start <= $completed) &&
($end >= $created || $end >= $completed);
}
if ($completed) {
return $start <= $completed && $end >= $completed;
}
if ($created) {
return $end > $created;
}
return true;
}
/**
* A simple list of validation rules.
*
* This is simply a list of properties, and how many times they either
* must or must not appear.
*
* Possible values per property:
* * 0 - Must not appear.
* * 1 - Must appear exactly once.
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @var array
*/
public function getValidationRules()
{
return [
'UID' => 1,
'DTSTAMP' => 1,
'CLASS' => '?',
'COMPLETED' => '?',
'CREATED' => '?',
'DESCRIPTION' => '?',
'DTSTART' => '?',
'GEO' => '?',
'LAST-MODIFIED' => '?',
'LOCATION' => '?',
'ORGANIZER' => '?',
'PERCENT' => '?',
'PRIORITY' => '?',
'RECURRENCE-ID' => '?',
'SEQUENCE' => '?',
'STATUS' => '?',
'SUMMARY' => '?',
'URL' => '?',
'RRULE' => '?',
'DUE' => '?',
'DURATION' => '?',
'ATTACH' => '*',
'ATTENDEE' => '*',
'CATEGORIES' => '*',
'COMMENT' => '*',
'CONTACT' => '*',
'EXDATE' => '*',
'REQUEST-STATUS' => '*',
'RELATED-TO' => '*',
'RESOURCES' => '*',
'RDATE' => '*',
];
}
/**
* Validates the node for correctness.
*
* The following options are supported:
* Node::REPAIR - May attempt to automatically repair the problem.
*
* This method returns an array with detected problems.
* Every element has the following properties:
*
* * level - problem level.
* * message - A human-readable string describing the issue.
* * node - A reference to the problematic node.
*
* The level means:
* 1 - The issue was repaired (only happens if REPAIR was turned on)
* 2 - An inconsequential issue
* 3 - A severe issue.
*
* @param int $options
*
* @return array
*/
public function validate($options = 0)
{
$result = parent::validate($options);
if (isset($this->DUE) && isset($this->DTSTART)) {
$due = $this->DUE;
$dtStart = $this->DTSTART;
if ($due->getValueType() !== $dtStart->getValueType()) {
$result[] = [
'level' => 3,
'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART',
'node' => $due,
];
} elseif ($due->getDateTime() < $dtStart->getDateTime()) {
$result[] = [
'level' => 3,
'message' => 'DUE must occur after DTSTART',
'node' => $due,
];
}
}
return $result;
}
/**
* This method should return a list of default property values.
*
* @return array
*/
protected function getDefaults()
{
return [
'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(),
'DTSTAMP' => date('Ymd\\THis\\Z'),
];
}
}