aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/vobject/lib/ITip/Broker.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2019-04-25 11:47:18 +0200
committerMario Vavti <mario@mariovavti.com>2019-04-25 11:47:18 +0200
commita60c2f38c689f254bd8bb8e7ea9af78bf21c1f84 (patch)
tree65d1d73918ccb1d4ccc36184d70af2e8dd91f28e /vendor/sabre/vobject/lib/ITip/Broker.php
parentf1c07977809ce3221286d53e99f0d91145b1166f (diff)
downloadvolse-hubzilla-a60c2f38c689f254bd8bb8e7ea9af78bf21c1f84.tar.gz
volse-hubzilla-a60c2f38c689f254bd8bb8e7ea9af78bf21c1f84.tar.bz2
volse-hubzilla-a60c2f38c689f254bd8bb8e7ea9af78bf21c1f84.zip
update sabre/vobject
Diffstat (limited to 'vendor/sabre/vobject/lib/ITip/Broker.php')
-rw-r--r--vendor/sabre/vobject/lib/ITip/Broker.php221
1 files changed, 97 insertions, 124 deletions
diff --git a/vendor/sabre/vobject/lib/ITip/Broker.php b/vendor/sabre/vobject/lib/ITip/Broker.php
index b954cdc8d..b1cfee367 100644
--- a/vendor/sabre/vobject/lib/ITip/Broker.php
+++ b/vendor/sabre/vobject/lib/ITip/Broker.php
@@ -35,8 +35,8 @@ use Sabre\VObject\Recur\EventIterator;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Broker {
-
+class Broker
+{
/**
* This setting determines whether the rules for the SCHEDULE-AGENT
* parameter should be followed.
@@ -104,37 +104,34 @@ class Broker {
*
* If the iTip message was not supported, we will always return false.
*
- * @param Message $itipMessage
+ * @param Message $itipMessage
* @param VCalendar $existingObject
*
* @return VCalendar|null
*/
- function processMessage(Message $itipMessage, VCalendar $existingObject = null) {
-
+ public function processMessage(Message $itipMessage, VCalendar $existingObject = null)
+ {
// We only support events at the moment.
- if ($itipMessage->component !== 'VEVENT') {
+ if ('VEVENT' !== $itipMessage->component) {
return false;
}
switch ($itipMessage->method) {
-
- case 'REQUEST' :
+ case 'REQUEST':
return $this->processMessageRequest($itipMessage, $existingObject);
- case 'CANCEL' :
+ case 'CANCEL':
return $this->processMessageCancel($itipMessage, $existingObject);
- case 'REPLY' :
+ case 'REPLY':
return $this->processMessageReply($itipMessage, $existingObject);
- default :
+ default:
// Unsupported iTip message
return;
-
}
return $existingObject;
-
}
/**
@@ -161,13 +158,13 @@ class Broker {
* organizer gets the 'declined' message.
*
* @param VCalendar|string $calendar
- * @param string|array $userHref
+ * @param string|array $userHref
* @param VCalendar|string $oldCalendar
*
* @return array
*/
- function parseEvent($calendar = null, $userHref, $oldCalendar = null) {
-
+ public function parseEvent($calendar = null, $userHref, $oldCalendar = null)
+ {
if ($oldCalendar) {
if (is_string($oldCalendar)) {
$oldCalendar = Reader::read($oldCalendar);
@@ -180,16 +177,15 @@ class Broker {
$oldEventInfo = $this->parseEventInfo($oldCalendar);
} else {
$oldEventInfo = [
- 'organizer' => null,
+ 'organizer' => null,
'significantChangeHash' => '',
- 'attendees' => [],
+ 'attendees' => [],
];
}
- $userHref = (array)$userHref;
+ $userHref = (array) $userHref;
if (!is_null($calendar)) {
-
if (is_string($calendar)) {
$calendar = Reader::read($calendar);
}
@@ -217,7 +213,6 @@ class Broker {
$eventInfo['organizer'] = $oldEventInfo['organizer'];
$eventInfo['organizerName'] = $oldEventInfo['organizerName'];
}
-
} else {
// The calendar object got deleted, we need to process this as a
// cancellation / decline.
@@ -233,19 +228,17 @@ class Broker {
$eventInfo['attendees'] = [];
// Increasing the sequence, but only if the organizer deleted
// the event.
- $eventInfo['sequence']++;
+ ++$eventInfo['sequence'];
} else {
// This is an attendee deleting the event.
foreach ($eventInfo['attendees'] as $key => $attendee) {
if (in_array($attendee['href'], $userHref)) {
- $eventInfo['attendees'][$key]['instances'] = ['master' =>
- ['id' => 'master', 'partstat' => 'DECLINED']
+ $eventInfo['attendees'][$key]['instances'] = ['master' => ['id' => 'master', 'partstat' => 'DECLINED'],
];
}
}
}
$baseCalendar = $oldCalendar;
-
}
if (in_array($eventInfo['organizer'], $userHref)) {
@@ -260,8 +253,8 @@ class Broker {
}
}
}
- return [];
+ return [];
}
/**
@@ -271,13 +264,13 @@ class Broker {
* invite, or an update to an existing one.
*
*
- * @param Message $itipMessage
+ * @param Message $itipMessage
* @param VCalendar $existingObject
*
* @return VCalendar|null
*/
- protected function processMessageRequest(Message $itipMessage, VCalendar $existingObject = null) {
-
+ protected function processMessageRequest(Message $itipMessage, VCalendar $existingObject = null)
+ {
if (!$existingObject) {
// This is a new invite, and we're just going to copy over
// all the components from the invite.
@@ -296,8 +289,8 @@ class Broker {
$existingObject->add(clone $component);
}
}
- return $existingObject;
+ return $existingObject;
}
/**
@@ -307,13 +300,13 @@ class Broker {
* attendee got removed from an event, or an event got cancelled
* altogether.
*
- * @param Message $itipMessage
+ * @param Message $itipMessage
* @param VCalendar $existingObject
*
* @return VCalendar|null
*/
- protected function processMessageCancel(Message $itipMessage, VCalendar $existingObject = null) {
-
+ protected function processMessageCancel(Message $itipMessage, VCalendar $existingObject = null)
+ {
if (!$existingObject) {
// The event didn't exist in the first place, so we're just
// ignoring this message.
@@ -323,8 +316,8 @@ class Broker {
$vevent->SEQUENCE = $itipMessage->sequence;
}
}
- return $existingObject;
+ return $existingObject;
}
/**
@@ -333,13 +326,13 @@ class Broker {
* The message is a reply. This is for example an attendee telling
* an organizer he accepted the invite, or declined it.
*
- * @param Message $itipMessage
+ * @param Message $itipMessage
* @param VCalendar $existingObject
*
* @return VCalendar|null
*/
- protected function processMessageReply(Message $itipMessage, VCalendar $existingObject = null) {
-
+ protected function processMessageReply(Message $itipMessage, VCalendar $existingObject = null)
+ {
// A reply can only be processed based on an existing object.
// If the object is not available, the reply is ignored.
if (!$existingObject) {
@@ -364,7 +357,7 @@ class Broker {
$masterObject = null;
foreach ($existingObject->VEVENT as $vevent) {
$recurId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getValue() : 'master';
- if ($recurId === 'master') {
+ if ('master' === $recurId) {
$masterObject = $vevent;
}
if (isset($instances[$recurId])) {
@@ -386,9 +379,11 @@ class Broker {
// Adding a new attendee. The iTip documentation calls this
// a party crasher.
$attendee = $vevent->add('ATTENDEE', $itipMessage->sender, [
- 'PARTSTAT' => $instances[$recurId]
+ 'PARTSTAT' => $instances[$recurId],
]);
- if ($itipMessage->senderName) $attendee['CN'] = $itipMessage->senderName;
+ if ($itipMessage->senderName) {
+ $attendee['CN'] = $itipMessage->senderName;
+ }
}
unset($instances[$recurId]);
}
@@ -401,24 +396,23 @@ class Broker {
// If we got replies to instances that did not exist in the
// original list, it means that new exceptions must be created.
foreach ($instances as $recurId => $partstat) {
-
$recurrenceIterator = new EventIterator($existingObject, $itipMessage->uid);
$found = false;
$iterations = 1000;
do {
-
$newObject = $recurrenceIterator->getEventObject();
$recurrenceIterator->next();
if (isset($newObject->{'RECURRENCE-ID'}) && $newObject->{'RECURRENCE-ID'}->getValue() === $recurId) {
$found = true;
}
- $iterations--;
-
+ --$iterations;
} while ($recurrenceIterator->valid() && !$found && $iterations);
// Invalid recurrence id. Skipping this object.
- if (!$found) continue;
+ if (!$found) {
+ continue;
+ }
unset(
$newObject->RRULE,
@@ -438,17 +432,16 @@ class Broker {
if (!$attendeeFound) {
// Adding a new attendee
$attendee = $newObject->add('ATTENDEE', $itipMessage->sender, [
- 'PARTSTAT' => $partstat
+ 'PARTSTAT' => $partstat,
]);
if ($itipMessage->senderName) {
$attendee['CN'] = $itipMessage->senderName;
}
}
$existingObject->add($newObject);
-
}
- return $existingObject;
+ return $existingObject;
}
/**
@@ -460,22 +453,22 @@ class Broker {
* specific messages for these situations.
*
* @param VCalendar $calendar
- * @param array $eventInfo
- * @param array $oldEventInfo
+ * @param array $eventInfo
+ * @param array $oldEventInfo
*
* @return array
*/
- protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo, array $oldEventInfo) {
-
+ protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo, array $oldEventInfo)
+ {
// Merging attendee lists.
$attendees = [];
foreach ($oldEventInfo['attendees'] as $attendee) {
$attendees[$attendee['href']] = [
- 'href' => $attendee['href'],
+ 'href' => $attendee['href'],
'oldInstances' => $attendee['instances'],
'newInstances' => [],
- 'name' => $attendee['name'],
- 'forceSend' => null,
+ 'name' => $attendee['name'],
+ 'forceSend' => null,
];
}
foreach ($eventInfo['attendees'] as $attendee) {
@@ -485,11 +478,11 @@ class Broker {
$attendees[$attendee['href']]['forceSend'] = $attendee['forceSend'];
} else {
$attendees[$attendee['href']] = [
- 'href' => $attendee['href'],
+ 'href' => $attendee['href'],
'oldInstances' => [],
'newInstances' => $attendee['instances'],
- 'name' => $attendee['name'],
- 'forceSend' => $attendee['forceSend'],
+ 'name' => $attendee['name'],
+ 'forceSend' => $attendee['forceSend'],
];
}
}
@@ -497,7 +490,6 @@ class Broker {
$messages = [];
foreach ($attendees as $attendee) {
-
// An organizer can also be an attendee. We should not generate any
// messages for those.
if ($attendee['href'] === $eventInfo['organizer']) {
@@ -514,7 +506,6 @@ class Broker {
$message->recipientName = $attendee['name'];
if (!$attendee['newInstances']) {
-
// If there are no instances the attendee is a part of, it
// means the attendee was removed and we need to send him a
// CANCEL.
@@ -523,8 +514,13 @@ class Broker {
// Creating the new iCalendar body.
$icalMsg = new VCalendar();
$icalMsg->METHOD = $message->method;
+
+ foreach ($calendar->select('VTIMEZONE') as $timezone) {
+ $icalMsg->add(clone $timezone);
+ }
+
$event = $icalMsg->add('VEVENT', [
- 'UID' => $message->uid,
+ 'UID' => $message->uid,
'SEQUENCE' => $message->sequence,
]);
if (isset($calendar->VEVENT->SUMMARY)) {
@@ -537,14 +533,14 @@ class Broker {
$event->add(clone $calendar->VEVENT->DURATION);
}
$org = $event->add('ORGANIZER', $eventInfo['organizer']);
- if ($eventInfo['organizerName']) $org['CN'] = $eventInfo['organizerName'];
+ if ($eventInfo['organizerName']) {
+ $org['CN'] = $eventInfo['organizerName'];
+ }
$event->add('ATTENDEE', $attendee['href'], [
'CN' => $attendee['name'],
]);
$message->significantChange = true;
-
} else {
-
// The attendee gets the updated event body
$message->method = 'REQUEST';
@@ -565,15 +561,13 @@ class Broker {
// difference in instances that the attendee is invited to.
$message->significantChange =
- $attendee['forceSend'] === 'REQUEST' ||
+ 'REQUEST' === $attendee['forceSend'] ||
array_keys($attendee['oldInstances']) != array_keys($attendee['newInstances']) ||
$oldEventInfo['significantChangeHash'] !== $eventInfo['significantChangeHash'];
foreach ($attendee['newInstances'] as $instanceId => $instanceInfo) {
-
$currentEvent = clone $eventInfo['instances'][$instanceId];
- if ($instanceId === 'master') {
-
+ if ('master' === $instanceId) {
// We need to find a list of events that the attendee
// is not a part of to add to the list of exceptions.
$exceptions = [];
@@ -610,24 +604,18 @@ class Broker {
if (!isset($attendee['PARTSTAT'])) {
$attendee['PARTSTAT'] = 'NEEDS-ACTION';
}
-
}
-
}
$icalMsg->add($currentEvent);
-
}
-
}
$message->message = $icalMsg;
$messages[] = $message;
-
}
return $messages;
-
}
/**
@@ -636,21 +624,21 @@ class Broker {
* This function figures out if we need to send a reply to an organizer.
*
* @param VCalendar $calendar
- * @param array $eventInfo
- * @param array $oldEventInfo
- * @param string $attendee
+ * @param array $eventInfo
+ * @param array $oldEventInfo
+ * @param string $attendee
*
* @return Message[]
*/
- protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo, array $oldEventInfo, $attendee) {
-
- if ($this->scheduleAgentServerRules && $eventInfo['organizerScheduleAgent'] === 'CLIENT') {
+ protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo, array $oldEventInfo, $attendee)
+ {
+ if ($this->scheduleAgentServerRules && 'CLIENT' === $eventInfo['organizerScheduleAgent']) {
return [];
}
// Don't bother generating messages for events that have already been
// cancelled.
- if ($eventInfo['status'] === 'CANCELLED') {
+ if ('CANCELLED' === $eventInfo['status']) {
return [];
}
@@ -660,26 +648,22 @@ class Broker {
$instances = [];
foreach ($oldInstances as $instance) {
-
$instances[$instance['id']] = [
- 'id' => $instance['id'],
+ 'id' => $instance['id'],
'oldstatus' => $instance['partstat'],
'newstatus' => null,
];
-
}
foreach ($eventInfo['attendees'][$attendee]['instances'] as $instance) {
-
if (isset($instances[$instance['id']])) {
$instances[$instance['id']]['newstatus'] = $instance['partstat'];
} else {
$instances[$instance['id']] = [
- 'id' => $instance['id'],
+ 'id' => $instance['id'],
'oldstatus' => null,
'newstatus' => $instance['partstat'],
];
}
-
}
// We need to also look for differences in EXDATE. If there are new
@@ -687,33 +671,29 @@ class Broker {
// event, which means we need to send DECLINED specifically for those
// instances.
// We only need to do that though, if the master event is not declined.
- if (isset($instances['master']) && $instances['master']['newstatus'] !== 'DECLINED') {
+ if (isset($instances['master']) && 'DECLINED' !== $instances['master']['newstatus']) {
foreach ($eventInfo['exdate'] as $exDate) {
-
if (!in_array($exDate, $oldEventInfo['exdate'])) {
if (isset($instances[$exDate])) {
$instances[$exDate]['newstatus'] = 'DECLINED';
} else {
$instances[$exDate] = [
- 'id' => $exDate,
+ 'id' => $exDate,
'oldstatus' => null,
'newstatus' => 'DECLINED',
];
}
}
-
}
}
// Gathering a few extra properties for each instance.
foreach ($instances as $recurId => $instanceInfo) {
-
if (isset($eventInfo['instances'][$recurId])) {
$instances[$recurId]['dtstart'] = clone $eventInfo['instances'][$recurId]->DTSTART;
} else {
$instances[$recurId]['dtstart'] = $recurId;
}
-
}
$message = new Message();
@@ -732,14 +712,13 @@ class Broker {
$hasReply = false;
foreach ($instances as $instance) {
-
- if ($instance['oldstatus'] == $instance['newstatus'] && $eventInfo['organizerForceSend'] !== 'REPLY') {
+ if ($instance['oldstatus'] == $instance['newstatus'] && 'REPLY' !== $eventInfo['organizerForceSend']) {
// Skip
continue;
}
$event = $icalMsg->add('VEVENT', [
- 'UID' => $message->uid,
+ 'UID' => $message->uid,
'SEQUENCE' => $message->sequence,
]);
$summary = isset($calendar->VEVENT->SUMMARY) ? $calendar->VEVENT->SUMMARY->getValue() : '';
@@ -773,7 +752,7 @@ class Broker {
$event->add('SUMMARY', $summary);
}
}
- if ($instance['id'] !== 'master') {
+ if ('master' !== $instance['id']) {
$dt = DateTimeParser::parse($instance['id'], $eventInfo['timezone']);
// Treat is as a DATE field
if (strlen($instance['id']) <= 8) {
@@ -787,22 +766,21 @@ class Broker {
$organizer['CN'] = $message->recipientName;
}
$attendee = $event->add('ATTENDEE', $message->sender, [
- 'PARTSTAT' => $instance['newstatus']
+ 'PARTSTAT' => $instance['newstatus'],
]);
if ($message->senderName) {
$attendee['CN'] = $message->senderName;
}
$hasReply = true;
-
}
if ($hasReply) {
$message->message = $icalMsg;
+
return [$message];
} else {
return [];
}
-
}
/**
@@ -824,12 +802,13 @@ class Broker {
* based on.
* 11. significantChangeHash
* 12. status
+ *
* @param VCalendar $calendar
*
* @return array
*/
- protected function parseEventInfo(VCalendar $calendar = null) {
-
+ protected function parseEventInfo(VCalendar $calendar = null)
+ {
$uid = null;
$organizer = null;
$organizerName = null;
@@ -868,7 +847,7 @@ class Broker {
$organizer = $vevent->ORGANIZER->getNormalizedValue();
$organizerName = isset($vevent->ORGANIZER['CN']) ? $vevent->ORGANIZER['CN'] : null;
} else {
- if ($organizer !== $vevent->ORGANIZER->getNormalizedValue()) {
+ if (strtoupper($organizer) !== strtoupper($vevent->ORGANIZER->getNormalizedValue())) {
throw new SameOrganizerForAllComponentsException('Every instance of the event must have the same organizer.');
}
}
@@ -878,7 +857,7 @@ class Broker {
null;
$organizerScheduleAgent =
isset($vevent->ORGANIZER['SCHEDULE-AGENT']) ?
- strtoupper((string)$vevent->ORGANIZER['SCHEDULE-AGENT']) :
+ strtoupper((string) $vevent->ORGANIZER['SCHEDULE-AGENT']) :
'SERVER';
}
if (is_null($sequence) && isset($vevent->SEQUENCE)) {
@@ -894,7 +873,7 @@ class Broker {
foreach ($vevent->select('RRULE') as $rr) {
foreach ($rr->getParts() as $key => $val) {
// ignore default values (https://github.com/sabre-io/vobject/issues/126)
- if ($key === 'INTERVAL' && $val == 1) {
+ if ('INTERVAL' === $key && 1 == $val) {
continue;
}
if (is_array($val)) {
@@ -911,7 +890,7 @@ class Broker {
$recurId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getValue() : 'master';
if (is_null($timezone)) {
- if ($recurId === 'master') {
+ if ('master' === $recurId) {
$timezone = $vevent->DTSTART->getDateTime()->getTimeZone();
} else {
$timezone = $vevent->{'RECURRENCE-ID'}->getDateTime()->getTimeZone();
@@ -919,10 +898,9 @@ class Broker {
}
if (isset($vevent->ATTENDEE)) {
foreach ($vevent->ATTENDEE as $attendee) {
-
if ($this->scheduleAgentServerRules &&
isset($attendee['SCHEDULE-AGENT']) &&
- strtoupper($attendee['SCHEDULE-AGENT']->getValue()) === 'CLIENT'
+ 'CLIENT' === strtoupper($attendee['SCHEDULE-AGENT']->getValue())
) {
continue;
}
@@ -936,45 +914,42 @@ class Broker {
strtoupper($attendee['SCHEDULE-FORCE-SEND']) :
null;
-
if (isset($attendees[$attendee->getNormalizedValue()])) {
$attendees[$attendee->getNormalizedValue()]['instances'][$recurId] = [
- 'id' => $recurId,
- 'partstat' => $partStat,
+ 'id' => $recurId,
+ 'partstat' => $partStat,
'forceSend' => $forceSend,
];
} else {
$attendees[$attendee->getNormalizedValue()] = [
- 'href' => $attendee->getNormalizedValue(),
+ 'href' => $attendee->getNormalizedValue(),
'instances' => [
$recurId => [
- 'id' => $recurId,
+ 'id' => $recurId,
'partstat' => $partStat,
],
],
- 'name' => isset($attendee['CN']) ? (string)$attendee['CN'] : null,
+ 'name' => isset($attendee['CN']) ? (string) $attendee['CN'] : null,
'forceSend' => $forceSend,
];
}
-
}
$instances[$recurId] = $vevent;
-
}
foreach ($this->significantChangeProperties as $prop) {
if (isset($vevent->$prop)) {
$propertyValues = $vevent->select($prop);
- $significantChangeHash .= $prop . ':';
+ $significantChangeHash .= $prop.':';
- if ($prop === 'EXDATE') {
- $significantChangeHash .= implode(',', $exdate) . ';';
- } elseif ($prop === 'RRULE') {
- $significantChangeHash .= implode(',', $rrule) . ';';
+ if ('EXDATE' === $prop) {
+ $significantChangeHash .= implode(',', $exdate).';';
+ } elseif ('RRULE' === $prop) {
+ $significantChangeHash .= implode(',', $rrule).';';
} else {
foreach ($propertyValues as $val) {
- $significantChangeHash .= $val->getValue() . ';';
+ $significantChangeHash .= $val->getValue().';';
}
}
}
@@ -996,7 +971,5 @@ class Broker {
'significantChangeHash',
'status'
);
-
}
-
}