2011-05-20 19:04:25 +02:00
|
|
|
<?php
|
2011-08-21 12:48:33 +02:00
|
|
|
|
|
|
|
/**
|
2013-07-23 17:14:11 +02:00
|
|
|
* iCalendar functions for the libcalendaring plugin
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
2011-12-07 12:51:23 +01:00
|
|
|
* @author Thomas Bruederli <bruederli@kolabsys.com>
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
2015-03-10 15:38:45 +01:00
|
|
|
* Copyright (C) 2013-2015, Kolab Systems AG <contact@kolabsys.com>
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-10-27 10:20:46 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-21 12:48:33 +02:00
|
|
|
*/
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
use Sabre\VObject;
|
|
|
|
use Sabre\VObject\DateTimeParser;
|
2013-09-13 09:47:40 +02:00
|
|
|
|
2011-07-29 09:19:18 +02:00
|
|
|
/**
|
|
|
|
* Class to parse and build vCalendar (iCalendar) files
|
|
|
|
*
|
2014-11-10 16:32:15 +01:00
|
|
|
* Uses the Sabre VObject library, version 3.x.
|
2011-07-29 09:19:18 +02:00
|
|
|
*/
|
2024-01-25 13:47:41 +01:00
|
|
|
|
2022-11-30 12:54:29 +01:00
|
|
|
class libcalendaring_vcalendar implements Iterator
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2013-07-23 17:14:11 +02:00
|
|
|
private $timezone;
|
2023-01-03 10:42:54 +01:00
|
|
|
private $attach_uri;
|
|
|
|
private $prodid;
|
2024-01-24 11:24:41 +01:00
|
|
|
private $type_component_map = ['event' => 'VEVENT', 'task' => 'VTODO'];
|
|
|
|
private $attendee_keymap = [
|
2014-11-12 19:03:06 +01:00
|
|
|
'name' => 'CN',
|
|
|
|
'status' => 'PARTSTAT',
|
|
|
|
'role' => 'ROLE',
|
|
|
|
'cutype' => 'CUTYPE',
|
|
|
|
'rsvp' => 'RSVP',
|
|
|
|
'delegated-from' => 'DELEGATED-FROM',
|
|
|
|
'delegated-to' => 'DELEGATED-TO',
|
|
|
|
'schedule-status' => 'SCHEDULE-STATUS',
|
2017-07-04 14:27:19 +00:00
|
|
|
'schedule-agent' => 'SCHEDULE-AGENT',
|
2017-04-04 12:17:17 +02:00
|
|
|
'sent-by' => 'SENT-BY',
|
2024-01-24 11:24:41 +01:00
|
|
|
];
|
|
|
|
private $organizer_keymap = [
|
2017-04-04 12:17:17 +02:00
|
|
|
'name' => 'CN',
|
|
|
|
'schedule-status' => 'SCHEDULE-STATUS',
|
2017-07-04 14:27:19 +00:00
|
|
|
'schedule-agent' => 'SCHEDULE-AGENT',
|
2017-04-04 12:17:17 +02:00
|
|
|
'sent-by' => 'SENT-BY',
|
2024-01-24 11:24:41 +01:00
|
|
|
];
|
2013-10-17 13:10:19 +02:00
|
|
|
private $iteratorkey = 0;
|
|
|
|
private $charset;
|
|
|
|
private $forward_exceptions;
|
2014-02-28 12:41:31 +01:00
|
|
|
private $vhead;
|
2013-10-17 13:10:19 +02:00
|
|
|
private $fp;
|
2024-01-24 11:24:41 +01:00
|
|
|
private $vtimezones = [];
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
public $method;
|
2013-09-12 10:57:22 +02:00
|
|
|
public $agent = '';
|
2024-01-24 11:24:41 +01:00
|
|
|
public $objects = [];
|
|
|
|
public $freebusy = [];
|
2024-01-25 13:47:41 +01:00
|
|
|
public $sender;
|
|
|
|
public $message_date;
|
|
|
|
public $mime_id;
|
2014-09-22 11:03:11 +02:00
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
2024-01-24 11:24:41 +01:00
|
|
|
public function __construct($tz = null)
|
2013-07-23 17:14:11 +02:00
|
|
|
{
|
2013-07-24 18:05:04 +02:00
|
|
|
$this->timezone = $tz;
|
2023-01-03 10:42:54 +01:00
|
|
|
$this->prodid = '-//Roundcube ' . RCUBE_VERSION . '//Sabre VObject ' . VObject\Version::VERSION . '//EN';
|
2011-07-29 09:19:18 +02:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setter for timezone information
|
|
|
|
*/
|
|
|
|
public function set_timezone($tz)
|
|
|
|
{
|
|
|
|
$this->timezone = $tz;
|
2011-10-12 19:44:38 +02:00
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
/**
|
|
|
|
* Setter for URI template for attachment links
|
|
|
|
*/
|
|
|
|
public function set_attach_uri($uri)
|
|
|
|
{
|
|
|
|
$this->attach_uri = $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setter for a custom PRODID attribute
|
|
|
|
*/
|
|
|
|
public function set_prodid($prodid)
|
|
|
|
{
|
|
|
|
$this->prodid = $prodid;
|
|
|
|
}
|
|
|
|
|
2013-09-12 10:57:22 +02:00
|
|
|
/**
|
|
|
|
* Setter for a user-agent string to tweak input/output accordingly
|
|
|
|
*/
|
|
|
|
public function set_agent($agent)
|
|
|
|
{
|
|
|
|
$this->agent = $agent;
|
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
/**
|
|
|
|
* Free resources by clearing member vars
|
|
|
|
*/
|
|
|
|
public function reset()
|
|
|
|
{
|
2014-02-28 12:41:31 +01:00
|
|
|
$this->vhead = '';
|
2013-07-23 17:14:11 +02:00
|
|
|
$this->method = '';
|
2024-01-24 11:24:41 +01:00
|
|
|
$this->objects = [];
|
|
|
|
$this->freebusy = [];
|
|
|
|
$this->vtimezones = [];
|
2013-10-17 13:10:19 +02:00
|
|
|
$this->iteratorkey = 0;
|
|
|
|
|
|
|
|
if ($this->fp) {
|
|
|
|
fclose($this->fp);
|
|
|
|
$this->fp = null;
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Import events from iCalendar format
|
|
|
|
*
|
2022-12-09 14:39:46 +01:00
|
|
|
* @param string vCalendar input
|
|
|
|
* @param string Input charset (from envelope)
|
|
|
|
* @param bool True if parsing exceptions should be forwarded to the caller
|
|
|
|
*
|
2013-07-23 17:14:11 +02:00
|
|
|
* @return array List of events extracted from the input
|
|
|
|
*/
|
2013-10-17 13:10:19 +02:00
|
|
|
public function import($vcal, $charset = 'UTF-8', $forward_exceptions = false, $memcheck = true)
|
2013-07-23 17:14:11 +02:00
|
|
|
{
|
|
|
|
// TODO: convert charset to UTF-8 if other
|
|
|
|
|
|
|
|
try {
|
2013-10-16 12:46:13 +02:00
|
|
|
// estimate the memory usage and try to avoid fatal errors when allowed memory gets exhausted
|
2013-10-17 13:10:19 +02:00
|
|
|
if ($memcheck) {
|
2014-03-18 12:08:54 +01:00
|
|
|
$count = substr_count($vcal, 'BEGIN:VEVENT') + substr_count($vcal, 'BEGIN:VTODO');
|
2024-01-24 11:24:41 +01:00
|
|
|
$expected_memory = $count * 70 * 1024; // assume ~ 70K per event (empirically determined)
|
2013-10-16 12:46:13 +02:00
|
|
|
|
2013-10-17 13:10:19 +02:00
|
|
|
if (!rcube_utils::mem_check($expected_memory)) {
|
|
|
|
throw new Exception("iCal file too big");
|
|
|
|
}
|
2013-10-16 12:46:13 +02:00
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
$vobject = VObject\Reader::read($vcal, VObject\Reader::OPTION_FORGIVING | VObject\Reader::OPTION_IGNORE_INVALID_LINES);
|
2024-01-24 11:24:41 +01:00
|
|
|
if ($vobject) {
|
2013-07-23 17:14:11 +02:00
|
|
|
return $this->import_from_vobject($vobject);
|
2024-01-24 11:24:41 +01:00
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
2013-09-19 11:01:13 +02:00
|
|
|
if ($forward_exceptions) {
|
|
|
|
throw $e;
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
|
|
|
rcube::raise_error(
|
|
|
|
[
|
2013-10-17 13:10:19 +02:00
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
2024-01-24 11:24:41 +01:00
|
|
|
'message' => "iCal data parse error: " . $e->getMessage()],
|
|
|
|
true,
|
|
|
|
false
|
|
|
|
);
|
2013-10-17 13:10:19 +02:00
|
|
|
}
|
2011-11-11 13:22:40 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2022-12-09 14:39:46 +01:00
|
|
|
return [];
|
2011-10-12 19:44:38 +02:00
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
/**
|
|
|
|
* Read iCalendar events from a file
|
|
|
|
*
|
2022-12-09 14:39:46 +01:00
|
|
|
* @param string File path to read from
|
|
|
|
* @param string Input charset (from envelope)
|
|
|
|
* @param bool True if parsing exceptions should be forwarded to the caller
|
|
|
|
*
|
2013-07-23 17:14:11 +02:00
|
|
|
* @return array List of events extracted from the file
|
|
|
|
*/
|
2013-09-19 11:01:13 +02:00
|
|
|
public function import_from_file($filepath, $charset = 'UTF-8', $forward_exceptions = false)
|
2013-07-23 17:14:11 +02:00
|
|
|
{
|
2013-10-17 13:10:19 +02:00
|
|
|
if ($this->fopen($filepath, $charset, $forward_exceptions)) {
|
|
|
|
while ($this->_parse_next(false)) {
|
|
|
|
// nop
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($this->fp);
|
|
|
|
$this->fp = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->objects;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a file to read iCalendar events sequentially
|
|
|
|
*
|
|
|
|
* @param string File path to read from
|
|
|
|
* @param string Input charset (from envelope)
|
|
|
|
* @param boolean True if parsing exceptions should be forwarded to the caller
|
|
|
|
* @return boolean True if file contents are considered valid
|
|
|
|
*/
|
|
|
|
public function fopen($filepath, $charset = 'UTF-8', $forward_exceptions = false)
|
|
|
|
{
|
|
|
|
$this->reset();
|
|
|
|
|
|
|
|
// just to be sure...
|
|
|
|
@ini_set('auto_detect_line_endings', true);
|
|
|
|
|
|
|
|
$this->charset = $charset;
|
|
|
|
$this->forward_exceptions = $forward_exceptions;
|
|
|
|
$this->fp = fopen($filepath, 'r');
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
// check file content first
|
2013-10-17 13:10:19 +02:00
|
|
|
$begin = fread($this->fp, 1024);
|
2013-07-23 17:14:11 +02:00
|
|
|
if (!preg_match('/BEGIN:VCALENDAR/i', $begin)) {
|
2013-10-17 13:10:19 +02:00
|
|
|
return false;
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
2013-10-17 13:10:19 +02:00
|
|
|
fseek($this->fp, 0);
|
|
|
|
return $this->_parse_next();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the next event/todo/freebusy object from the input file
|
|
|
|
*/
|
|
|
|
private function _parse_next($reset = true)
|
|
|
|
{
|
|
|
|
if ($reset) {
|
|
|
|
$this->iteratorkey = 0;
|
2024-01-24 11:24:41 +01:00
|
|
|
$this->objects = [];
|
|
|
|
$this->freebusy = [];
|
2013-10-17 13:10:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$next = $this->_next_component();
|
|
|
|
$buffer = $next;
|
|
|
|
|
|
|
|
// load the next component(s) too, as they could contain recurrence exceptions
|
|
|
|
while (preg_match('/(RRULE|RECURRENCE-ID)[:;]/i', $next)) {
|
|
|
|
$next = $this->_next_component();
|
|
|
|
$buffer .= $next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the vevent block surrounded with the vcalendar heading
|
|
|
|
if (strlen($buffer) && preg_match('/BEGIN:(VEVENT|VTODO|VFREEBUSY)/i', $buffer)) {
|
|
|
|
try {
|
|
|
|
$this->import($this->vhead . $buffer . "END:VCALENDAR", $this->charset, true, false);
|
2024-01-24 11:24:41 +01:00
|
|
|
} catch (Exception $e) {
|
2013-10-17 13:10:19 +02:00
|
|
|
if ($this->forward_exceptions) {
|
|
|
|
throw new VObject\ParseException($e->getMessage() . " in\n" . $buffer);
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2013-10-17 13:10:19 +02:00
|
|
|
// write the failing section to error log
|
2024-01-24 11:24:41 +01:00
|
|
|
rcube::raise_error(
|
|
|
|
[
|
2013-10-17 13:10:19 +02:00
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
2024-01-24 11:24:41 +01:00
|
|
|
'message' => $e->getMessage() . " in\n" . $buffer],
|
|
|
|
true,
|
|
|
|
false
|
|
|
|
);
|
2013-10-17 13:10:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// advance to next
|
|
|
|
return $this->_parse_next($reset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count($this->objects) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to read the next calendar component from the file
|
|
|
|
*/
|
|
|
|
private function _next_component()
|
|
|
|
{
|
|
|
|
$buffer = '';
|
2014-02-28 12:41:31 +01:00
|
|
|
$vcalendar_head = false;
|
2013-10-17 13:10:19 +02:00
|
|
|
while (($line = fgets($this->fp, 1024)) !== false) {
|
2014-02-28 12:41:31 +01:00
|
|
|
// ignore END:VCALENDAR lines
|
|
|
|
if (preg_match('/END:VCALENDAR/i', $line)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// read vcalendar header (with timezone defintion)
|
|
|
|
if (preg_match('/BEGIN:VCALENDAR/i', $line)) {
|
|
|
|
$this->vhead = '';
|
|
|
|
$vcalendar_head = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// end of VCALENDAR header part
|
|
|
|
if ($vcalendar_head && preg_match('/BEGIN:(VEVENT|VTODO|VFREEBUSY)/i', $line)) {
|
|
|
|
$vcalendar_head = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($vcalendar_head) {
|
|
|
|
$this->vhead .= $line;
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2014-02-28 12:41:31 +01:00
|
|
|
$buffer .= $line;
|
|
|
|
if (preg_match('/END:(VEVENT|VTODO|VFREEBUSY)/i', $line)) {
|
|
|
|
break;
|
|
|
|
}
|
2013-10-17 13:10:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $buffer;
|
2011-07-29 17:51:04 +02:00
|
|
|
}
|
2011-10-12 22:39:14 +02:00
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
/**
|
|
|
|
* Import objects from an already parsed Sabre\VObject\Component object
|
|
|
|
*
|
|
|
|
* @param object Sabre\VObject\Component to read from
|
|
|
|
* @return array List of events extracted from the file
|
|
|
|
*/
|
|
|
|
public function import_from_vobject($vobject)
|
|
|
|
{
|
2024-01-24 11:24:41 +01:00
|
|
|
$seen = [];
|
|
|
|
$exceptions = [];
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
if ($vobject->name == 'VCALENDAR') {
|
|
|
|
$this->method = strval($vobject->METHOD);
|
2013-09-12 10:57:22 +02:00
|
|
|
$this->agent = strval($vobject->PRODID);
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2015-04-22 17:00:23 +02:00
|
|
|
foreach ($vobject->getComponents() as $ve) {
|
2013-07-23 17:14:11 +02:00
|
|
|
if ($ve->name == 'VEVENT' || $ve->name == 'VTODO') {
|
|
|
|
// convert to hash array representation
|
|
|
|
$object = $this->_to_array($ve);
|
|
|
|
|
2015-03-09 12:30:53 +01:00
|
|
|
// temporarily store this as exception
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($object['recurrence_date'])) {
|
2015-03-09 12:30:53 +01:00
|
|
|
$exceptions[] = $object;
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif (empty($seen[$object['uid']])) {
|
2020-12-26 20:41:54 +01:00
|
|
|
$seen[$object['uid']] = true;
|
2013-07-23 17:14:11 +02:00
|
|
|
$this->objects[] = $object;
|
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif ($ve->name == 'VFREEBUSY') {
|
2013-08-25 12:35:41 +02:00
|
|
|
$this->objects[] = $this->_parse_freebusy($ve);
|
2013-08-24 16:43:02 +02:00
|
|
|
}
|
2011-10-12 22:39:14 +02:00
|
|
|
}
|
2015-03-09 12:30:53 +01:00
|
|
|
|
|
|
|
// add exceptions to the according master events
|
|
|
|
foreach ($exceptions as $exception) {
|
|
|
|
$uid = $exception['uid'];
|
|
|
|
|
|
|
|
// make this exception the master
|
2020-12-26 20:41:54 +01:00
|
|
|
if (empty($seen[$uid])) {
|
|
|
|
$seen[$uid] = true;
|
2015-03-09 12:30:53 +01:00
|
|
|
$this->objects[] = $exception;
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2015-03-09 12:30:53 +01:00
|
|
|
foreach ($this->objects as $i => $object) {
|
|
|
|
// add as exception to existing entry with a matching UID
|
|
|
|
if ($object['uid'] == $uid) {
|
|
|
|
$this->objects[$i]['exceptions'][] = $exception;
|
|
|
|
|
|
|
|
if (!empty($object['recurrence'])) {
|
|
|
|
$this->objects[$i]['recurrence']['EXCEPTIONS'] = &$this->objects[$i]['exceptions'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->objects;
|
|
|
|
}
|
|
|
|
|
2013-08-24 16:43:02 +02:00
|
|
|
/**
|
|
|
|
* Getter for free-busy periods
|
|
|
|
*/
|
|
|
|
public function get_busy_periods()
|
|
|
|
{
|
2024-01-24 11:24:41 +01:00
|
|
|
$out = [];
|
2013-08-24 16:43:02 +02:00
|
|
|
foreach ((array)$this->freebusy['periods'] as $period) {
|
|
|
|
if ($period[2] != 'FREE') {
|
|
|
|
$out[] = $period;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
2013-09-12 10:57:22 +02:00
|
|
|
/**
|
|
|
|
* Helper method to determine whether the connected client is an Apple device
|
|
|
|
*/
|
|
|
|
private function is_apple()
|
|
|
|
{
|
|
|
|
return stripos($this->agent, 'Apple') !== false
|
|
|
|
|| stripos($this->agent, 'Mac OS X') !== false
|
|
|
|
|| stripos($this->agent, 'iOS/') !== false;
|
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
/**
|
|
|
|
* Convert the given VEvent object to a libkolab compatible array representation
|
|
|
|
*
|
|
|
|
* @param object Vevent object to convert
|
|
|
|
* @return array Hash array with object properties
|
|
|
|
*/
|
|
|
|
private function _to_array($ve)
|
|
|
|
{
|
2024-01-24 11:24:41 +01:00
|
|
|
$event = [
|
2014-02-28 16:12:24 +01:00
|
|
|
'uid' => self::convert_string($ve->UID),
|
|
|
|
'title' => self::convert_string($ve->SUMMARY),
|
2013-07-23 17:14:11 +02:00
|
|
|
'_type' => $ve->name == 'VTODO' ? 'task' : 'event',
|
|
|
|
// set defaults
|
|
|
|
'priority' => 0,
|
2024-01-24 11:24:41 +01:00
|
|
|
'attendees' => [],
|
|
|
|
'x-custom' => [],
|
|
|
|
];
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2013-08-30 14:58:16 +02:00
|
|
|
// Catch possible exceptions when date is invalid (Bug #2144)
|
|
|
|
// We can skip these fields, they aren't critical
|
2024-01-24 11:24:41 +01:00
|
|
|
foreach (['CREATED' => 'created', 'LAST-MODIFIED' => 'changed', 'DTSTAMP' => 'changed'] as $attr => $field) {
|
2013-08-30 14:58:16 +02:00
|
|
|
try {
|
2020-12-26 20:41:54 +01:00
|
|
|
if (empty($event[$field]) && !empty($ve->{$attr})) {
|
2013-09-04 09:19:26 +02:00
|
|
|
$event[$field] = $ve->{$attr}->getDateTime();
|
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// map other attributes to internal fields
|
2022-11-29 15:54:43 +01:00
|
|
|
foreach ($ve->children() as $prop) {
|
2024-01-24 11:24:41 +01:00
|
|
|
if (!($prop instanceof VObject\Property)) {
|
2013-07-23 17:14:11 +02:00
|
|
|
continue;
|
2024-01-24 11:24:41 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2014-11-10 16:32:15 +01:00
|
|
|
$value = strval($prop);
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
switch ($prop->name) {
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'DTSTART':
|
|
|
|
case 'DTEND':
|
|
|
|
case 'DUE':
|
|
|
|
$propmap = ['DTSTART' => 'start', 'DTEND' => 'end', 'DUE' => 'due'];
|
|
|
|
$event[$propmap[$prop->name]] = self::convert_datetime($prop);
|
|
|
|
break;
|
2014-10-14 09:21:51 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'TRANSP':
|
|
|
|
$event['free_busy'] = strval($prop) == 'TRANSPARENT' ? 'free' : 'busy';
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'STATUS':
|
|
|
|
if ($value == 'TENTATIVE') {
|
|
|
|
$event['free_busy'] = 'tentative';
|
|
|
|
} elseif ($value == 'CANCELLED') {
|
|
|
|
$event['cancelled'] = true;
|
|
|
|
} elseif ($value == 'COMPLETED') {
|
|
|
|
$event['complete'] = 100;
|
|
|
|
}
|
2015-05-27 12:31:29 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
$event['status'] = $value;
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'COMPLETED':
|
|
|
|
if (self::convert_datetime($prop)) {
|
|
|
|
$event['status'] = 'COMPLETED';
|
|
|
|
$event['complete'] = 100;
|
|
|
|
}
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'PRIORITY':
|
|
|
|
if (is_numeric($value)) {
|
|
|
|
$event['priority'] = $value;
|
|
|
|
}
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'RRULE':
|
|
|
|
$params = !empty($event['recurrence']) && is_array($event['recurrence']) ? $event['recurrence'] : [];
|
|
|
|
// parse recurrence rule attributes
|
|
|
|
foreach ($prop->getParts() as $k => $v) {
|
|
|
|
$params[strtoupper($k)] = is_array($v) ? implode(',', $v) : $v;
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
if (!empty($params['UNTIL'])) {
|
|
|
|
$params['UNTIL'] = date_create($params['UNTIL']);
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
if (empty($params['INTERVAL'])) {
|
|
|
|
$params['INTERVAL'] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$event['recurrence'] = array_filter($params);
|
|
|
|
break;
|
2014-02-28 16:12:24 +01:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'EXDATE':
|
|
|
|
if (!empty($value)) {
|
|
|
|
$exdates = array_map(function ($_) { return is_array($_) ? $_[0] : $_; }, self::convert_datetime($prop, true));
|
|
|
|
if (!empty($event['recurrence']['EXDATE'])) {
|
|
|
|
$event['recurrence']['EXDATE'] = array_merge($event['recurrence']['EXDATE'], $exdates);
|
|
|
|
} else {
|
|
|
|
$event['recurrence']['EXDATE'] = $exdates;
|
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'RDATE':
|
|
|
|
if (!empty($value)) {
|
|
|
|
$rdates = array_map(function ($_) { return is_array($_) ? $_[0] : $_; }, self::convert_datetime($prop, true));
|
|
|
|
if (!empty($event['recurrence']['RDATE'])) {
|
|
|
|
$event['recurrence']['RDATE'] = array_merge($event['recurrence']['RDATE'], $rdates);
|
|
|
|
} else {
|
|
|
|
$event['recurrence']['RDATE'] = $rdates;
|
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'RECURRENCE-ID':
|
|
|
|
$event['recurrence_date'] = self::convert_datetime($prop);
|
|
|
|
if ($prop->offsetGet('RANGE') == 'THISANDFUTURE' || $prop->offsetGet('THISANDFUTURE') !== null) {
|
|
|
|
$event['thisandfuture'] = true;
|
|
|
|
}
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'RELATED-TO':
|
|
|
|
$reltype = $prop->offsetGet('RELTYPE');
|
|
|
|
if ($reltype == 'PARENT' || $reltype === null) {
|
|
|
|
$event['parent_id'] = $value;
|
|
|
|
}
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'SEQUENCE':
|
|
|
|
$event['sequence'] = intval($value);
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'PERCENT-COMPLETE':
|
|
|
|
$event['complete'] = intval($value);
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'LOCATION':
|
|
|
|
case 'DESCRIPTION':
|
|
|
|
case 'URL':
|
|
|
|
case 'COMMENT':
|
|
|
|
$event[strtolower($prop->name)] = self::convert_string($prop);
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'CATEGORY':
|
|
|
|
case 'CATEGORIES':
|
|
|
|
if (!empty($event['categories'])) {
|
|
|
|
$event['categories'] = array_merge((array) $event['categories'], $prop->getParts());
|
|
|
|
} else {
|
|
|
|
$event['categories'] = $prop->getParts();
|
|
|
|
}
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'X-MICROSOFT-CDO-BUSYSTATUS':
|
|
|
|
if ($value == 'OOF') {
|
|
|
|
$event['free_busy'] = 'outofoffice';
|
|
|
|
} elseif (in_array($value, ['FREE', 'BUSY', 'TENTATIVE'])) {
|
|
|
|
$event['free_busy'] = strtolower($value);
|
|
|
|
}
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'ATTENDEE':
|
|
|
|
case 'ORGANIZER':
|
|
|
|
$params = ['RSVP' => false];
|
|
|
|
foreach ($prop->parameters() as $pname => $pvalue) {
|
|
|
|
switch ($pname) {
|
|
|
|
case 'RSVP': $params[$pname] = strtolower($pvalue) == 'true';
|
|
|
|
break;
|
|
|
|
case 'CN': $params[$pname] = self::unescape($pvalue);
|
|
|
|
break;
|
|
|
|
default: $params[$pname] = strval($pvalue);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
$attendee = self::map_keys($params, array_flip($this->attendee_keymap));
|
|
|
|
$attendee['email'] = preg_replace('!^mailto:!i', '', $value);
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
if ($prop->name == 'ORGANIZER') {
|
|
|
|
$attendee['role'] = 'ORGANIZER';
|
|
|
|
$attendee['status'] = 'ACCEPTED';
|
|
|
|
$event['organizer'] = $attendee;
|
2017-07-04 14:27:19 +00:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
if (array_key_exists('schedule-agent', $attendee)) {
|
|
|
|
$schedule_agent = $attendee['schedule-agent'];
|
|
|
|
}
|
|
|
|
} elseif (empty($event['organizer']) || $attendee['email'] != $event['organizer']['email']) {
|
|
|
|
$event['attendees'][] = $attendee;
|
2017-07-04 14:27:19 +00:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'ATTACH':
|
|
|
|
$params = self::parameters_array($prop);
|
|
|
|
if (substr($value, 0, 4) == 'http' && !strpos($value, ':attachment:')) {
|
|
|
|
$event['links'][] = $value;
|
|
|
|
} elseif (!empty($params['VALUE']) && strtoupper($params['VALUE']) == 'BINARY') {
|
|
|
|
$attachment = self::map_keys($params, [
|
|
|
|
'FMTTYPE' => 'mimetype',
|
|
|
|
'X-LABEL' => 'name',
|
|
|
|
'X-APPLE-FILENAME' => 'name',
|
|
|
|
'X-SIZE' => 'size',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$attachment['data'] = $value;
|
|
|
|
$attachment['size'] ??= strlen($value);
|
|
|
|
$attachment['id'] = md5(($attachment['mimetype'] ?? 'application/octet-stream') . ($attachment['name'] ?? 'noname'));
|
|
|
|
|
|
|
|
$event['attachments'][] = $attachment;
|
|
|
|
}
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
default:
|
|
|
|
if (substr($prop->name, 0, 2) == 'X-') {
|
|
|
|
$event['x-custom'][] = [$prop->name, strval($value)];
|
|
|
|
}
|
|
|
|
break;
|
2011-10-12 22:39:14 +02:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
2011-10-12 22:39:14 +02:00
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
// check DURATION property if no end date is set
|
|
|
|
if (empty($event['end']) && $ve->DURATION) {
|
|
|
|
try {
|
|
|
|
$duration = new DateInterval(strval($ve->DURATION));
|
|
|
|
$end = clone $event['start'];
|
|
|
|
$end->add($duration);
|
|
|
|
$event['end'] = $end;
|
2024-01-24 11:24:41 +01:00
|
|
|
} catch (\Exception $e) {
|
2013-07-23 17:14:11 +02:00
|
|
|
trigger_error(strval($e), E_USER_WARNING);
|
|
|
|
}
|
2011-10-12 22:39:14 +02:00
|
|
|
}
|
|
|
|
|
2013-07-24 18:59:09 +02:00
|
|
|
// validate event dates
|
|
|
|
if ($event['_type'] == 'event') {
|
2020-12-26 20:41:54 +01:00
|
|
|
$event['allday'] = !empty($event['start']->_dateonly);
|
2013-02-28 10:44:15 +01:00
|
|
|
|
2016-07-29 06:54:48 -04:00
|
|
|
// events may lack the DTEND property, set it to DTSTART (RFC5545 3.6.1)
|
|
|
|
if (empty($event['end'])) {
|
2014-03-04 08:55:06 +01:00
|
|
|
$event['end'] = clone $event['start'];
|
|
|
|
}
|
2013-07-24 18:59:09 +02:00
|
|
|
// shift end-date by one day (except Thunderbird)
|
2024-01-24 11:24:41 +01:00
|
|
|
elseif ($event['allday'] && is_object($event['end'])) {
|
2013-07-24 18:59:09 +02:00
|
|
|
$event['end']->sub(new \DateInterval('PT23H'));
|
|
|
|
}
|
2013-02-28 10:44:15 +01:00
|
|
|
|
2013-07-24 18:59:09 +02:00
|
|
|
// sanity-check and fix end date
|
2013-09-19 11:01:13 +02:00
|
|
|
if (!empty($event['end']) && $event['end'] < $event['start']) {
|
2013-07-24 18:59:09 +02:00
|
|
|
$event['end'] = clone $event['start'];
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// make organizer part of the attendees list for compatibility reasons
|
2014-07-30 17:40:53 +02:00
|
|
|
if (!empty($event['organizer']) && is_array($event['attendees']) && $event['_type'] == 'event') {
|
2013-07-23 17:14:11 +02:00
|
|
|
array_unshift($event['attendees'], $event['organizer']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// find alarms
|
2013-10-29 14:55:02 +01:00
|
|
|
foreach ($ve->select('VALARM') as $valarm) {
|
2015-08-07 06:43:59 -04:00
|
|
|
$action = 'DISPLAY';
|
2013-07-23 17:14:11 +02:00
|
|
|
$trigger = null;
|
2024-01-24 11:24:41 +01:00
|
|
|
$alarm = [];
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2022-11-29 15:54:43 +01:00
|
|
|
foreach ($valarm->children() as $prop) {
|
2014-11-10 16:32:15 +01:00
|
|
|
$value = strval($prop);
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
switch ($prop->name) {
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'TRIGGER':
|
|
|
|
foreach ($prop->parameters as $param) {
|
|
|
|
if ($param->name == 'VALUE' && $param->getValue() == 'DATE-TIME') {
|
|
|
|
$trigger = '@' . $prop->getDateTime()->format('U');
|
|
|
|
$alarm['trigger'] = $prop->getDateTime();
|
|
|
|
} elseif ($param->name == 'RELATED') {
|
|
|
|
$alarm['related'] = $param->getValue();
|
|
|
|
}
|
2015-08-07 06:43:59 -04:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
if (!$trigger && ($values = libcalendaring::parse_alarm_value($value))) {
|
|
|
|
$trigger = $values[2];
|
2015-08-07 06:43:59 -04:00
|
|
|
}
|
2014-04-03 18:38:26 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
if (empty($alarm['trigger'])) {
|
|
|
|
$alarm['trigger'] = rtrim(preg_replace('/([A-Z])0[WDHMS]/', '\\1', $value), 'T');
|
|
|
|
// if all 0-values have been stripped, assume 'at time'
|
|
|
|
if ($alarm['trigger'] == 'P') {
|
|
|
|
$alarm['trigger'] = 'PT0S';
|
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ACTION':
|
|
|
|
$action = $alarm['action'] = strtoupper($value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'SUMMARY':
|
|
|
|
case 'DESCRIPTION':
|
|
|
|
case 'DURATION':
|
|
|
|
$alarm[strtolower($prop->name)] = self::convert_string($prop);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'REPEAT':
|
|
|
|
$alarm['repeat'] = intval($value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ATTENDEE':
|
|
|
|
$alarm['attendees'][] = preg_replace('!^mailto:!i', '', $value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ATTACH':
|
|
|
|
$params = self::parameters_array($prop);
|
|
|
|
if (strlen($value) && (preg_match('/^[a-z]+:/', $value) || strtoupper($params['VALUE']) == 'URI')) {
|
|
|
|
// we only support URI-type of attachments here
|
|
|
|
$alarm['uri'] = $value;
|
|
|
|
}
|
|
|
|
break;
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 18:38:26 +02:00
|
|
|
if ($action != 'NONE') {
|
2020-12-26 20:41:54 +01:00
|
|
|
// store first alarm in legacy property
|
|
|
|
if ($trigger && empty($event['alarms'])) {
|
2014-04-03 17:39:26 +02:00
|
|
|
$event['alarms'] = $trigger . ':' . $action;
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2014-04-03 18:38:26 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($alarm['trigger'])) {
|
2014-04-03 18:38:26 +02:00
|
|
|
$event['valarms'][] = $alarm;
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2013-10-29 14:55:02 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
2013-07-24 18:59:09 +02:00
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
// assign current timezone to event start/end
|
2022-11-29 15:54:43 +01:00
|
|
|
if (!empty($event['start']) && $event['start'] instanceof DateTimeInterface) {
|
2019-05-31 09:19:04 +00:00
|
|
|
$this->_apply_timezone($event['start']);
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2013-07-23 17:14:11 +02:00
|
|
|
unset($event['start']);
|
2011-07-29 09:19:18 +02:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2022-11-29 15:54:43 +01:00
|
|
|
if (!empty($event['end']) && $event['end'] instanceof DateTimeInterface) {
|
2019-05-31 09:19:04 +00:00
|
|
|
$this->_apply_timezone($event['end']);
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2013-07-23 17:14:11 +02:00
|
|
|
unset($event['end']);
|
2011-07-27 17:42:45 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 15:21:32 +01:00
|
|
|
// some iTip CANCEL messages only contain the start date
|
2020-12-26 20:41:54 +01:00
|
|
|
if (empty($event['end']) && !empty($event['start']) && $this->method == 'CANCEL') {
|
2014-11-12 15:21:32 +01:00
|
|
|
$event['end'] = clone $event['start'];
|
|
|
|
}
|
|
|
|
|
2017-07-04 14:27:19 +00:00
|
|
|
// T2531: Remember SCHEDULE-AGENT in custom property to properly
|
|
|
|
// support event updates via CalDAV when SCHEDULE-AGENT=CLIENT is used
|
|
|
|
if (isset($schedule_agent)) {
|
2024-01-24 11:24:41 +01:00
|
|
|
$event['x-custom'][] = ['SCHEDULE-AGENT', $schedule_agent];
|
2017-07-04 14:27:19 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
// minimal validation
|
2013-09-19 11:01:13 +02:00
|
|
|
if (empty($event['uid']) || ($event['_type'] == 'event' && empty($event['start']) != empty($event['end']))) {
|
2013-07-23 17:14:11 +02:00
|
|
|
throw new VObject\ParseException('Object validation failed: missing mandatory object properties');
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
2019-05-31 09:19:04 +00:00
|
|
|
/**
|
|
|
|
* Apply user timezone to DateTime object
|
2024-01-25 13:47:41 +01:00
|
|
|
*
|
|
|
|
* @param DateTime $date
|
2019-05-31 09:19:04 +00:00
|
|
|
*/
|
|
|
|
private function _apply_timezone(&$date)
|
|
|
|
{
|
|
|
|
if (empty($this->timezone)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For date-only we'll keep the date and time intact
|
2021-02-01 08:30:34 +01:00
|
|
|
if (!empty($date->_dateonly)) {
|
2022-11-29 15:54:43 +01:00
|
|
|
$dt = new libcalendaring_datetime(null, $this->timezone);
|
2019-05-31 09:19:04 +00:00
|
|
|
$dt->setDate($date->format('Y'), $date->format('n'), $date->format('j'));
|
|
|
|
$dt->setTime($date->format('G'), $date->format('i'), 0);
|
|
|
|
$date = $dt;
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2019-05-31 09:19:04 +00:00
|
|
|
$date->setTimezone($this->timezone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 16:43:02 +02:00
|
|
|
/**
|
|
|
|
* Parse the given vfreebusy component into an array representation
|
|
|
|
*/
|
|
|
|
private function _parse_freebusy($ve)
|
|
|
|
{
|
2022-12-15 10:06:29 +01:00
|
|
|
$this->freebusy = ['_type' => 'freebusy', 'periods' => []];
|
|
|
|
$seen = [];
|
2013-08-24 16:43:02 +02:00
|
|
|
|
2022-11-29 15:54:43 +01:00
|
|
|
foreach ($ve->children() as $prop) {
|
2024-01-24 11:24:41 +01:00
|
|
|
if (!($prop instanceof VObject\Property)) {
|
2013-08-24 16:43:02 +02:00
|
|
|
continue;
|
2024-01-24 11:24:41 +01:00
|
|
|
}
|
2013-08-24 16:43:02 +02:00
|
|
|
|
2014-11-10 16:32:15 +01:00
|
|
|
$value = strval($prop);
|
|
|
|
|
2013-08-24 16:43:02 +02:00
|
|
|
switch ($prop->name) {
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'CREATED':
|
|
|
|
case 'LAST-MODIFIED':
|
|
|
|
case 'DTSTAMP':
|
|
|
|
case 'DTSTART':
|
|
|
|
case 'DTEND':
|
|
|
|
$propmap = [
|
|
|
|
'DTSTART' => 'start',
|
|
|
|
'DTEND' => 'end',
|
|
|
|
'CREATED' => 'created',
|
|
|
|
'LAST-MODIFIED' => 'changed',
|
|
|
|
'DTSTAMP' => 'changed',
|
|
|
|
];
|
|
|
|
$this->freebusy[$propmap[$prop->name]] = self::convert_datetime($prop);
|
|
|
|
break;
|
2013-08-24 16:43:02 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'ORGANIZER':
|
|
|
|
$this->freebusy['organizer'] = preg_replace('!^mailto:!i', '', $value);
|
|
|
|
break;
|
2013-08-24 16:43:02 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'FREEBUSY':
|
|
|
|
// The freebusy component can hold more than 1 value, separated by commas.
|
|
|
|
$periods = explode(',', $value);
|
|
|
|
$fbtype = strval($prop['FBTYPE']) ?: 'BUSY';
|
2013-08-24 16:43:02 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
// skip dupes
|
|
|
|
if (!empty($seen[$value . ':' . $fbtype])) {
|
|
|
|
break;
|
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
$seen[$value . ':' . $fbtype] = true;
|
2013-08-25 12:35:41 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
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.
|
|
|
|
[$busyStart, $busyEnd] = explode('/', $period);
|
2013-08-24 16:43:02 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
$busyStart = DateTimeParser::parse($busyStart);
|
|
|
|
$busyEnd = DateTimeParser::parse($busyEnd);
|
|
|
|
if ($busyEnd instanceof \DateInterval) {
|
|
|
|
$tmp = clone $busyStart;
|
|
|
|
$tmp->add($busyEnd);
|
|
|
|
$busyEnd = $tmp;
|
|
|
|
}
|
2013-08-24 16:43:02 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
if ($busyEnd && $busyEnd > $busyStart) {
|
|
|
|
$this->freebusy['periods'][] = [$busyStart, $busyEnd, $fbtype];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-08-24 16:43:02 +02:00
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
case 'COMMENT':
|
|
|
|
$this->freebusy['comment'] = $value;
|
2013-08-24 16:43:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->freebusy;
|
|
|
|
}
|
|
|
|
|
2014-02-28 16:12:24 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function convert_string($prop)
|
|
|
|
{
|
2014-11-10 16:32:15 +01:00
|
|
|
return strval($prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function unescape($prop)
|
|
|
|
{
|
|
|
|
return str_replace('\,', ',', strval($prop));
|
2014-02-28 16:12:24 +01:00
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
/**
|
|
|
|
* Helper method to correctly interpret an all-day date value
|
|
|
|
*/
|
2014-02-28 16:12:24 +01:00
|
|
|
public static function convert_datetime($prop, $as_array = false)
|
2013-07-23 17:14:11 +02:00
|
|
|
{
|
|
|
|
if (empty($prop)) {
|
2022-11-29 15:54:43 +01:00
|
|
|
return $as_array ? [] : null;
|
2013-05-16 13:32:01 +02:00
|
|
|
}
|
2022-11-29 15:54:43 +01:00
|
|
|
|
|
|
|
if ($prop instanceof VObject\Property\ICalendar\DateTime) {
|
2014-11-10 16:32:15 +01:00
|
|
|
if (count($prop->getDateTimes()) > 1) {
|
2022-11-29 15:54:43 +01:00
|
|
|
$dt = [];
|
2014-11-10 16:32:15 +01:00
|
|
|
$dateonly = !$prop->hasTime();
|
2022-11-29 15:54:43 +01:00
|
|
|
|
2014-11-10 16:32:15 +01:00
|
|
|
foreach ($prop->getDateTimes() as $item) {
|
2022-12-07 14:50:50 +01:00
|
|
|
$item = self::toDateTime($item);
|
2014-11-10 16:32:15 +01:00
|
|
|
$item->_dateonly = $dateonly;
|
|
|
|
$dt[] = $item;
|
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2022-12-07 14:50:50 +01:00
|
|
|
$dt = self::toDateTime($prop->getDateTime());
|
2014-11-10 16:32:15 +01:00
|
|
|
if (!$prop->hasTime()) {
|
|
|
|
$dt->_dateonly = true;
|
|
|
|
}
|
2014-02-28 16:12:24 +01:00
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif ($prop instanceof VObject\Property\ICalendar\Period) {
|
2022-11-29 15:54:43 +01:00
|
|
|
$dt = [];
|
2014-11-10 16:32:15 +01:00
|
|
|
foreach ($prop->getParts() as $val) {
|
2014-02-28 16:12:24 +01:00
|
|
|
try {
|
2024-01-24 11:24:41 +01:00
|
|
|
[$start, $end] = explode('/', $val);
|
2014-11-10 16:32:15 +01:00
|
|
|
$start = DateTimeParser::parseDateTime($start);
|
|
|
|
|
|
|
|
// This is a duration value.
|
|
|
|
if ($end[0] === 'P') {
|
|
|
|
$dur = DateTimeParser::parseDuration($end);
|
|
|
|
$end = clone $start;
|
|
|
|
$end->add($dur);
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2014-11-10 16:32:15 +01:00
|
|
|
$end = DateTimeParser::parseDateTime($end);
|
|
|
|
}
|
2022-11-29 15:54:43 +01:00
|
|
|
|
2022-12-07 14:50:50 +01:00
|
|
|
$dt[] = [self::toDateTime($start), self::toDateTime($end)];
|
2024-01-24 11:24:41 +01:00
|
|
|
} catch (Exception $e) {
|
2014-02-28 16:12:24 +01:00
|
|
|
// ignore single date parse errors
|
|
|
|
}
|
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif ($prop instanceof \DateTimeInterface) {
|
2022-12-07 14:50:50 +01:00
|
|
|
$dt = self::toDateTime($prop);
|
2011-07-06 22:42:23 +02:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2014-02-28 16:12:24 +01:00
|
|
|
// force return value to array if requested
|
2024-01-24 10:59:25 +01:00
|
|
|
if ($as_array) {
|
|
|
|
if (empty($dt)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_array($dt) ? $dt : [$dt];
|
2014-02-28 16:12:24 +01:00
|
|
|
}
|
|
|
|
|
2024-01-24 10:59:25 +01:00
|
|
|
return $dt ?? null;
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Sabre\VObject\Property instance from a PHP DateTime object
|
|
|
|
*
|
2024-01-24 10:59:25 +01:00
|
|
|
* @param object VObject\Document parent node to create property for
|
|
|
|
* @param string Property name
|
|
|
|
* @param DateTime Date time object
|
|
|
|
* @param bool Set as UTC date
|
|
|
|
* @param bool Set as VALUE=DATE property
|
|
|
|
*
|
|
|
|
* @return Sabre\VObject\Property
|
2013-07-23 17:14:11 +02:00
|
|
|
*/
|
2014-11-12 11:54:24 +01:00
|
|
|
public function datetime_prop($cal, $name, $dt, $utc = false, $dateonly = null, $set_type = false)
|
2013-07-23 17:14:11 +02:00
|
|
|
{
|
2024-01-24 10:59:25 +01:00
|
|
|
$tz = null;
|
|
|
|
$is_utc = false;
|
|
|
|
|
|
|
|
if ($dt) {
|
|
|
|
if ($utc) {
|
|
|
|
$dt->setTimeZone(new \DateTimeZone('UTC'));
|
|
|
|
$is_utc = true;
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
|
|
|
$is_utc = ($tz = $dt->getTimezone()) && in_array($tz->getName(), ['UTC','GMT','Z']);
|
2024-01-24 10:59:25 +01:00
|
|
|
}
|
2014-11-10 16:32:15 +01:00
|
|
|
}
|
2024-01-24 10:59:25 +01:00
|
|
|
|
|
|
|
$is_dateonly = $dateonly === null && $dt ? !empty($dt->_dateonly) : (bool) $dateonly;
|
2014-11-12 11:54:24 +01:00
|
|
|
$vdt = $cal->createProperty($name, $dt, null, $is_dateonly ? 'DATE' : 'DATE-TIME');
|
2014-11-10 16:32:15 +01:00
|
|
|
|
|
|
|
if ($is_dateonly) {
|
|
|
|
$vdt['VALUE'] = 'DATE';
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif ($set_type) {
|
2014-11-12 11:54:24 +01:00
|
|
|
$vdt['VALUE'] = 'DATE-TIME';
|
|
|
|
}
|
2014-09-22 11:03:11 +02:00
|
|
|
|
|
|
|
// register timezone for VTIMEZONE block
|
|
|
|
if (!$is_utc && !$dateonly && $tz && ($tzname = $tz->getName())) {
|
|
|
|
$ts = $dt->format('U');
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($this->vtimezones[$tzname])) {
|
2014-09-22 11:03:11 +02:00
|
|
|
$this->vtimezones[$tzname][0] = min($this->vtimezones[$tzname][0], $ts);
|
|
|
|
$this->vtimezones[$tzname][1] = max($this->vtimezones[$tzname][1], $ts);
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
|
|
|
$this->vtimezones[$tzname] = [$ts, $ts];
|
2014-09-22 11:03:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
return $vdt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy values from one hash array to another using a key-map
|
|
|
|
*/
|
|
|
|
public static function map_keys($values, $map)
|
|
|
|
{
|
2024-01-24 11:24:41 +01:00
|
|
|
$out = [];
|
2013-07-23 17:14:11 +02:00
|
|
|
foreach ($map as $from => $to) {
|
2024-01-24 11:24:41 +01:00
|
|
|
if (isset($values[$from])) {
|
|
|
|
$out[$to] = is_array($values[$from]) ? implode(',', $values[$from]) : $values[$from];
|
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static function parameters_array($prop)
|
|
|
|
{
|
2024-01-24 11:24:41 +01:00
|
|
|
$params = [];
|
2014-11-10 16:32:15 +01:00
|
|
|
foreach ($prop->parameters() as $name => $value) {
|
2015-04-28 15:48:27 +02:00
|
|
|
$params[strtoupper($name)] = strval($value);
|
2011-08-04 23:54:29 +02:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export events to iCalendar format
|
|
|
|
*
|
|
|
|
* @param array Events as array
|
|
|
|
* @param string VCalendar method to advertise
|
|
|
|
* @param boolean Directly send data to stdout instead of returning
|
|
|
|
* @param callable Callback function to fetch attachment contents, false if no attachment export
|
2014-09-22 11:03:11 +02:00
|
|
|
* @param boolean Add VTIMEZONE block with timezone definitions for the included events
|
2013-07-23 17:14:11 +02:00
|
|
|
* @return string Events in iCalendar format (http://tools.ietf.org/html/rfc5545)
|
|
|
|
*/
|
2014-09-22 11:03:11 +02:00
|
|
|
public function export($objects, $method = null, $write = false, $get_attachment = false, $with_timezones = true)
|
2013-07-23 17:14:11 +02:00
|
|
|
{
|
2013-10-01 11:55:10 +02:00
|
|
|
$this->method = $method;
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
// encapsulate in VCALENDAR container
|
2014-11-10 16:32:15 +01:00
|
|
|
$vcal = new VObject\Component\VCalendar();
|
2024-01-25 13:47:41 +01:00
|
|
|
$vcal->VERSION = '2.0'; // @phpstan-ignore-line
|
|
|
|
$vcal->PRODID = $this->prodid; // @phpstan-ignore-line
|
|
|
|
$vcal->CALSCALE = 'GREGORIAN'; // @phpstan-ignore-line
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
if (!empty($method)) {
|
2024-01-25 13:47:41 +01:00
|
|
|
$vcal->METHOD = $method; // @phpstan-ignore-line
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// write vcalendar header
|
|
|
|
if ($write) {
|
|
|
|
echo preg_replace('/END:VCALENDAR[\r\n]*$/m', '', $vcal->serialize());
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($objects as $object) {
|
2024-01-24 11:24:41 +01:00
|
|
|
$this->_to_ical($object, !$write ? $vcal : false, $get_attachment);
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
2014-09-22 11:03:11 +02:00
|
|
|
// include timezone information
|
|
|
|
if ($with_timezones || !empty($method)) {
|
|
|
|
foreach ($this->vtimezones as $tzid => $range) {
|
2014-11-10 16:32:15 +01:00
|
|
|
$vt = self::get_vtimezone($tzid, $range[0], $range[1], $vcal);
|
2014-09-22 11:03:11 +02:00
|
|
|
if (empty($vt)) {
|
|
|
|
continue; // no timezone information found
|
|
|
|
}
|
|
|
|
|
2015-03-18 12:59:39 +01:00
|
|
|
if ($write) {
|
|
|
|
echo $vt->serialize();
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2015-03-18 12:59:39 +01:00
|
|
|
$vcal->add($vt);
|
2014-09-22 11:03:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
if ($write) {
|
|
|
|
echo "END:VCALENDAR\r\n";
|
|
|
|
return true;
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2013-07-23 17:14:11 +02:00
|
|
|
return $vcal->serialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:51:33 +01:00
|
|
|
/**
|
|
|
|
* Converts internal event representation to Sabre component
|
|
|
|
*
|
|
|
|
* @param array Event
|
|
|
|
* @param callable Callback function to fetch attachment contents, false if no attachment export
|
|
|
|
*
|
|
|
|
* @return Sabre\VObject\Component\VEvent Sabre component
|
|
|
|
*/
|
|
|
|
public function toSabreComponent($object, $get_attachment = false)
|
|
|
|
{
|
|
|
|
$vcal = new VObject\Component\VCalendar();
|
|
|
|
|
|
|
|
$this->_to_ical($object, $vcal, $get_attachment);
|
|
|
|
|
|
|
|
return $vcal->getBaseComponent();
|
|
|
|
}
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
/**
|
|
|
|
* Build a valid iCal format block from the given event
|
|
|
|
*
|
|
|
|
* @param array Hash array with event/task properties from libkolab
|
|
|
|
* @param object VCalendar object to append event to or false for directly sending data to stdout
|
|
|
|
* @param callable Callback function to fetch attachment contents, false if no attachment export
|
|
|
|
* @param object RECURRENCE-ID property when serializing a recurrence exception
|
|
|
|
*/
|
|
|
|
private function _to_ical($event, $vcal, $get_attachment, $recurrence_id = null)
|
|
|
|
{
|
2020-12-26 20:41:54 +01:00
|
|
|
$type = !empty($event['_type']) ? $event['_type'] : 'event';
|
2014-11-10 16:32:15 +01:00
|
|
|
|
|
|
|
$cal = $vcal ?: new VObject\Component\VCalendar();
|
|
|
|
$ve = $cal->create($this->type_component_map[$type]);
|
|
|
|
$ve->UID = $event['uid'];
|
2013-10-01 11:55:10 +02:00
|
|
|
|
|
|
|
// set DTSTAMP according to RFC 5545, 3.8.7.2.
|
2017-06-29 13:08:35 +00:00
|
|
|
$dtstamp = !empty($event['changed']) && empty($this->method) ? $event['changed'] : new DateTime('now', new \DateTimeZone('UTC'));
|
2016-03-24 14:05:36 +01:00
|
|
|
$ve->DTSTAMP = $this->datetime_prop($cal, 'DTSTAMP', $dtstamp, true);
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
// all-day events end the next day
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['allday']) && !empty($event['end'])) {
|
2022-12-09 15:02:06 +01:00
|
|
|
$event['end'] = self::toDateTime($event['end']);
|
2013-07-23 17:14:11 +02:00
|
|
|
$event['end']->add(new \DateInterval('P1D'));
|
|
|
|
$event['end']->_dateonly = true;
|
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['created'])) {
|
2014-11-10 16:32:15 +01:00
|
|
|
$ve->add($this->datetime_prop($cal, 'CREATED', $event['created'], true));
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
|
|
|
if (!empty($event['changed'])) {
|
2014-11-10 16:32:15 +01:00
|
|
|
$ve->add($this->datetime_prop($cal, 'LAST-MODIFIED', $event['changed'], true));
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
|
|
|
if (!empty($event['start'])) {
|
|
|
|
$ve->add($this->datetime_prop($cal, 'DTSTART', $event['start'], false, !empty($event['allday'])));
|
|
|
|
}
|
|
|
|
if (!empty($event['end'])) {
|
|
|
|
$ve->add($this->datetime_prop($cal, 'DTEND', $event['end'], false, !empty($event['allday'])));
|
|
|
|
}
|
|
|
|
if (!empty($event['due'])) {
|
|
|
|
$ve->add($this->datetime_prop($cal, 'DUE', $event['due'], false));
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2015-02-15 14:32:31 +01:00
|
|
|
// we're exporting a recurrence instance only
|
2022-11-29 15:54:43 +01:00
|
|
|
if (!$recurrence_id && !empty($event['recurrence_date']) && $event['recurrence_date'] instanceof DateTimeInterface) {
|
2020-12-26 20:41:54 +01:00
|
|
|
$recurrence_id = $this->datetime_prop($cal, 'RECURRENCE-ID', $event['recurrence_date'], false, !empty($event['allday']));
|
|
|
|
if (!empty($event['thisandfuture'])) {
|
2015-02-15 14:32:31 +01:00
|
|
|
$recurrence_id->add('RANGE', 'THISANDFUTURE');
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2015-02-15 14:32:31 +01:00
|
|
|
}
|
|
|
|
|
2014-11-10 16:32:15 +01:00
|
|
|
if ($recurrence_id) {
|
2013-07-23 17:14:11 +02:00
|
|
|
$ve->add($recurrence_id);
|
2014-11-10 16:32:15 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2022-12-02 14:51:33 +01:00
|
|
|
if (!empty($event['title'])) {
|
|
|
|
$ve->add('SUMMARY', $event['title']);
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['location'])) {
|
2014-11-10 16:32:15 +01:00
|
|
|
$ve->add($this->is_apple() ? new vobject_location_property($cal, 'LOCATION', $event['location']) : $cal->create('LOCATION', $event['location']));
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2022-12-02 14:51:33 +01:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['description'])) {
|
2024-01-24 11:24:41 +01:00
|
|
|
$ve->add('DESCRIPTION', strtr($event['description'], ["\r\n" => "\n", "\r" => "\n"])); // normalize line endings
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (isset($event['sequence'])) {
|
2013-07-23 17:14:11 +02:00
|
|
|
$ve->add('SEQUENCE', $event['sequence']);
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['recurrence']) && !$recurrence_id) {
|
2015-03-05 14:31:38 +01:00
|
|
|
$exdates = $rdates = null;
|
|
|
|
if (isset($event['recurrence']['EXDATE'])) {
|
|
|
|
$exdates = $event['recurrence']['EXDATE'];
|
2013-07-23 17:14:11 +02:00
|
|
|
unset($event['recurrence']['EXDATE']); // don't serialize EXDATEs into RRULE value
|
|
|
|
}
|
2015-03-05 14:31:38 +01:00
|
|
|
if (isset($event['recurrence']['RDATE'])) {
|
|
|
|
$rdates = $event['recurrence']['RDATE'];
|
2014-02-28 16:12:24 +01:00
|
|
|
unset($event['recurrence']['RDATE']); // don't serialize RDATEs into RRULE value
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['recurrence']['FREQ'])) {
|
|
|
|
$ve->add('RRULE', libcalendaring::to_rrule($event['recurrence'], !empty($event['allday'])));
|
2014-02-28 16:12:24 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
|
|
|
// add EXDATEs each one per line (for Thunderbird Lightning)
|
2015-03-05 14:31:38 +01:00
|
|
|
if (is_array($exdates)) {
|
2018-12-13 12:36:20 +00:00
|
|
|
foreach ($exdates as $exdate) {
|
2022-11-29 15:54:43 +01:00
|
|
|
if ($exdate instanceof DateTimeInterface) {
|
2018-12-13 12:36:20 +00:00
|
|
|
$ve->add($this->datetime_prop($cal, 'EXDATE', $exdate));
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 16:12:24 +01:00
|
|
|
// add RDATEs
|
2018-12-13 12:36:20 +00:00
|
|
|
if (is_array($rdates)) {
|
|
|
|
foreach ($rdates as $rdate) {
|
2018-12-13 14:25:56 +01:00
|
|
|
$ve->add($this->datetime_prop($cal, 'RDATE', $rdate));
|
2014-11-10 16:32:15 +01:00
|
|
|
}
|
2014-02-28 16:12:24 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['categories'])) {
|
2014-11-10 16:32:15 +01:00
|
|
|
$cat = $cal->create('CATEGORIES');
|
2013-07-23 17:14:11 +02:00
|
|
|
$cat->setParts((array)$event['categories']);
|
|
|
|
$ve->add($cat);
|
|
|
|
}
|
|
|
|
|
2014-01-23 15:50:04 +01:00
|
|
|
if (!empty($event['free_busy'])) {
|
2013-07-24 18:59:09 +02:00
|
|
|
$ve->add('TRANSP', $event['free_busy'] == 'free' ? 'TRANSPARENT' : 'OPAQUE');
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2014-01-23 15:50:04 +01:00
|
|
|
// for Outlook clients we provide the X-MICROSOFT-CDO-BUSYSTATUS property
|
|
|
|
if (stripos($this->agent, 'outlook') !== false) {
|
|
|
|
$ve->add('X-MICROSOFT-CDO-BUSYSTATUS', $event['free_busy'] == 'outofoffice' ? 'OOF' : strtoupper($event['free_busy']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['priority'])) {
|
|
|
|
$ve->add('PRIORITY', $event['priority']);
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['cancelled'])) {
|
2013-07-23 17:14:11 +02:00
|
|
|
$ve->add('STATUS', 'CANCELLED');
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif (!empty($event['free_busy']) && $event['free_busy'] == 'tentative') {
|
2013-07-23 17:14:11 +02:00
|
|
|
$ve->add('STATUS', 'TENTATIVE');
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif (!empty($event['complete']) && $event['complete'] == 100) {
|
2013-07-23 17:14:11 +02:00
|
|
|
$ve->add('STATUS', 'COMPLETED');
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif (!empty($event['status'])) {
|
2014-04-03 15:07:47 +02:00
|
|
|
$ve->add('STATUS', $event['status']);
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
|
2013-07-24 18:59:09 +02:00
|
|
|
if (!empty($event['complete'])) {
|
2013-07-23 17:14:11 +02:00
|
|
|
$ve->add('PERCENT-COMPLETE', intval($event['complete']));
|
2015-05-27 12:31:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apple iCal and BusyCal required the COMPLETED date to be set in order to consider a task complete
|
2020-12-26 20:41:54 +01:00
|
|
|
if (
|
|
|
|
(!empty($event['status']) && $event['status'] == 'COMPLETED')
|
|
|
|
|| (!empty($event['complete']) && $event['complete'] == 100)
|
|
|
|
) {
|
|
|
|
$completed = !empty($event['changed']) ? $event['changed'] : new DateTime('now - 1 hour');
|
|
|
|
$ve->add($this->datetime_prop($cal, 'COMPLETED', $completed, true));
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['valarms'])) {
|
2014-04-03 17:39:26 +02:00
|
|
|
foreach ($event['valarms'] as $alarm) {
|
2014-11-10 16:32:15 +01:00
|
|
|
$va = $cal->createComponent('VALARM');
|
2014-04-03 17:39:26 +02:00
|
|
|
$va->action = $alarm['action'];
|
2022-11-29 15:54:43 +01:00
|
|
|
if ($alarm['trigger'] instanceof DateTimeInterface) {
|
2014-11-12 11:54:24 +01:00
|
|
|
$va->add($this->datetime_prop($cal, 'TRIGGER', $alarm['trigger'], true, null, true));
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
|
|
|
$alarm_props = [];
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($alarm['related']) && strtoupper($alarm['related']) == 'END') {
|
2015-08-07 06:43:59 -04:00
|
|
|
$alarm_props['RELATED'] = 'END';
|
|
|
|
}
|
|
|
|
$va->add('TRIGGER', $alarm['trigger'], $alarm_props);
|
2014-04-03 17:39:26 +02:00
|
|
|
}
|
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($alarm['action']) && $alarm['action'] == 'EMAIL') {
|
|
|
|
if (!empty($alarm['attendees'])) {
|
|
|
|
foreach ((array) $alarm['attendees'] as $attendee) {
|
|
|
|
$va->add('ATTENDEE', 'mailto:' . $attendee);
|
|
|
|
}
|
2014-04-03 17:39:26 +02:00
|
|
|
}
|
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($alarm['description'])) {
|
|
|
|
$va->add('DESCRIPTION', $alarm['description']);
|
2014-04-03 17:39:26 +02:00
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($alarm['summary'])) {
|
2014-04-03 17:39:26 +02:00
|
|
|
$va->add('SUMMARY', $alarm['summary']);
|
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($alarm['duration'])) {
|
2014-04-03 17:39:26 +02:00
|
|
|
$va->add('DURATION', $alarm['duration']);
|
2020-12-26 20:41:54 +01:00
|
|
|
$va->add('REPEAT', !empty($alarm['repeat']) ? intval($alarm['repeat']) : 0);
|
2014-04-03 17:39:26 +02:00
|
|
|
}
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($alarm['uri'])) {
|
2024-01-24 11:24:41 +01:00
|
|
|
$va->add('ATTACH', $alarm['uri'], ['VALUE' => 'URI']);
|
2014-04-03 19:19:14 +02:00
|
|
|
}
|
2014-04-03 17:39:26 +02:00
|
|
|
$ve->add($va);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// legacy support
|
2024-01-24 11:24:41 +01:00
|
|
|
elseif (!empty($event['alarms'])) {
|
2014-11-10 16:32:15 +01:00
|
|
|
$va = $cal->createComponent('VALARM');
|
2024-01-24 11:24:41 +01:00
|
|
|
[$trigger, $va->action] = explode(':', $event['alarms']);
|
2015-01-22 12:17:33 -05:00
|
|
|
$val = libcalendaring::parse_alarm_value($trigger);
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($val[3])) {
|
2014-04-17 17:49:00 +02:00
|
|
|
$va->add('TRIGGER', $val[3]);
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif ($val[0] instanceof DateTimeInterface) {
|
2014-11-12 11:54:24 +01:00
|
|
|
$va->add($this->datetime_prop($cal, 'TRIGGER', $val[0], true, null, true));
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
$ve->add($va);
|
|
|
|
}
|
|
|
|
|
2017-07-04 14:27:19 +00:00
|
|
|
// Find SCHEDULE-AGENT
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['x-custom'])) {
|
|
|
|
foreach ((array) $event['x-custom'] as $prop) {
|
|
|
|
if ($prop[0] === 'SCHEDULE-AGENT') {
|
|
|
|
$schedule_agent = $prop[1];
|
|
|
|
}
|
2017-07-04 14:27:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['attendees'])) {
|
|
|
|
foreach ((array) $event['attendees'] as $attendee) {
|
2023-04-19 15:25:24 +02:00
|
|
|
if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') {
|
2024-01-24 11:24:41 +01:00
|
|
|
if (empty($event['organizer'])) {
|
2020-12-26 20:41:54 +01:00
|
|
|
$event['organizer'] = $attendee;
|
2024-01-24 11:24:41 +01:00
|
|
|
}
|
|
|
|
} elseif (!empty($attendee['email'])) {
|
2020-12-26 20:41:54 +01:00
|
|
|
if (isset($attendee['rsvp'])) {
|
|
|
|
$attendee['rsvp'] = $attendee['rsvp'] ? 'TRUE' : null;
|
|
|
|
}
|
2017-07-04 14:27:19 +00:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
$mailto = $attendee['email'];
|
|
|
|
$attendee = array_filter(self::map_keys($attendee, $this->attendee_keymap));
|
2017-07-04 14:27:19 +00:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (isset($schedule_agent) && !isset($attendee['SCHEDULE-AGENT'])) {
|
|
|
|
$attendee['SCHEDULE-AGENT'] = $schedule_agent;
|
|
|
|
}
|
2017-07-04 14:27:19 +00:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
$ve->add('ATTENDEE', 'mailto:' . $mailto, $attendee);
|
|
|
|
}
|
2013-07-24 18:05:04 +02:00
|
|
|
}
|
2013-07-04 17:07:58 +02:00
|
|
|
}
|
2013-02-28 10:44:15 +01:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['organizer'])) {
|
2017-07-04 14:27:19 +00:00
|
|
|
$organizer = array_filter(self::map_keys($event['organizer'], $this->organizer_keymap));
|
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (isset($schedule_agent) && !isset($organizer['SCHEDULE-AGENT'])) {
|
2017-07-04 14:27:19 +00:00
|
|
|
$organizer['SCHEDULE-AGENT'] = $schedule_agent;
|
|
|
|
}
|
|
|
|
|
|
|
|
$ve->add('ORGANIZER', 'mailto:' . $event['organizer']['email'], $organizer);
|
2013-02-28 10:44:15 +01:00
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['url'])) {
|
|
|
|
foreach ((array) $event['url'] as $url) {
|
|
|
|
if (!empty($url)) {
|
|
|
|
$ve->add('URL', $url);
|
|
|
|
}
|
2013-07-24 18:05:04 +02:00
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
2012-07-11 09:59:53 +02:00
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
if (!empty($event['parent_id'])) {
|
2024-01-24 11:24:41 +01:00
|
|
|
$ve->add('RELATED-TO', $event['parent_id'], ['RELTYPE' => 'PARENT']);
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
2012-07-11 09:59:53 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['comment'])) {
|
2014-03-18 18:05:48 +01:00
|
|
|
$ve->add('COMMENT', $event['comment']);
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2014-03-18 18:05:48 +01:00
|
|
|
|
2014-11-21 10:03:18 +01:00
|
|
|
$memory_limit = parse_bytes(ini_get('memory_limit'));
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
// export attachments
|
|
|
|
if (!empty($event['attachments'])) {
|
2022-12-15 10:06:29 +01:00
|
|
|
foreach ((array) $event['attachments'] as $idx => $attach) {
|
2013-07-23 17:14:11 +02:00
|
|
|
// check available memory and skip attachment export if we can't buffer it
|
2014-11-21 10:03:18 +01:00
|
|
|
// @todo: use rcube_utils::mem_check()
|
2024-01-24 11:24:41 +01:00
|
|
|
if (is_callable($get_attachment) && $memory_limit > 0 && ($memory_used = function_exists('memory_get_usage') ? memory_get_usage() : 16 * 1024 * 1024)
|
2022-12-15 10:06:29 +01:00
|
|
|
&& !empty($attach['size']) && $memory_used + $attach['size'] * 3 > $memory_limit
|
|
|
|
) {
|
2013-07-23 17:14:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-12-15 10:06:29 +01:00
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
// embed attachments using the given callback function
|
2022-12-15 10:06:29 +01:00
|
|
|
if (is_callable($get_attachment) && ($data = call_user_func($get_attachment, $attach['id'] ?? $idx, $event))) {
|
2013-07-23 17:14:11 +02:00
|
|
|
// embed attachments for iCal
|
2024-01-24 11:24:41 +01:00
|
|
|
$ve->add(
|
|
|
|
'ATTACH',
|
2014-11-10 16:32:15 +01:00
|
|
|
$data,
|
2022-12-15 10:06:29 +01:00
|
|
|
array_filter([
|
|
|
|
'VALUE' => 'BINARY',
|
|
|
|
'ENCODING' => 'BASE64',
|
|
|
|
'FMTTYPE' => $attach['mimetype'] ?? null,
|
|
|
|
'X-LABEL' => $attach['name'] ?? null,
|
|
|
|
'X-SIZE' => $attach['size'] ?? null,
|
|
|
|
])
|
|
|
|
);
|
2013-07-23 17:14:11 +02:00
|
|
|
unset($data); // attempt to free memory
|
|
|
|
}
|
|
|
|
// list attachments as absolute URIs
|
2024-01-24 11:24:41 +01:00
|
|
|
elseif (!empty($this->attach_uri)) {
|
|
|
|
$ve->add(
|
|
|
|
'ATTACH',
|
2022-12-15 10:06:29 +01:00
|
|
|
strtr($this->attach_uri, [
|
|
|
|
'{{id}}' => urlencode($attach['id'] ?? $idx),
|
2013-07-23 17:14:11 +02:00
|
|
|
'{{name}}' => urlencode($attach['name']),
|
|
|
|
'{{mimetype}}' => urlencode($attach['mimetype']),
|
2022-12-15 10:06:29 +01:00
|
|
|
]),
|
|
|
|
['FMTTYPE' => $attach['mimetype'], 'VALUE' => 'URI']
|
|
|
|
);
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-06 17:15:45 +02:00
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['links'])) {
|
|
|
|
foreach ((array) $event['links'] as $uri) {
|
|
|
|
$ve->add('ATTACH', $uri);
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// add custom properties
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['x-custom'])) {
|
|
|
|
foreach ((array) $event['x-custom'] as $prop) {
|
|
|
|
$ve->add($prop[0], $prop[1]);
|
|
|
|
}
|
2013-07-23 17:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// append to vcalendar container
|
|
|
|
if ($vcal) {
|
|
|
|
$vcal->add($ve);
|
2024-01-24 11:24:41 +01:00
|
|
|
} else { // serialize and send to stdout
|
2013-07-23 17:14:11 +02:00
|
|
|
echo $ve->serialize();
|
|
|
|
}
|
2011-07-27 17:42:45 +02:00
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
// append recurrence exceptions
|
2020-12-26 20:41:54 +01:00
|
|
|
if (!empty($event['recurrence']) && !empty($event['recurrence']['EXCEPTIONS'])) {
|
2013-07-23 17:14:11 +02:00
|
|
|
foreach ($event['recurrence']['EXCEPTIONS'] as $ex) {
|
2020-12-26 20:41:54 +01:00
|
|
|
$exdate = !empty($ex['recurrence_date']) ? $ex['recurrence_date'] : $ex['start'];
|
|
|
|
$recurrence_id = $this->datetime_prop($cal, 'RECURRENCE-ID', $exdate, false, !empty($event['allday']));
|
|
|
|
if (!empty($ex['thisandfuture'])) {
|
2015-02-12 10:08:22 +01:00
|
|
|
$recurrence_id->add('RANGE', 'THISANDFUTURE');
|
2020-12-26 20:41:54 +01:00
|
|
|
}
|
2022-10-12 13:36:57 +02:00
|
|
|
|
|
|
|
$ex['uid'] = $ve->UID;
|
|
|
|
|
2013-07-23 17:14:11 +02:00
|
|
|
$this->_to_ical($ex, $vcal, $get_attachment, $recurrence_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-27 17:42:45 +02:00
|
|
|
|
2014-09-22 11:03:11 +02:00
|
|
|
/**
|
|
|
|
* Returns a VTIMEZONE component for a Olson timezone identifier
|
|
|
|
* with daylight transitions covering the given date range.
|
|
|
|
*
|
|
|
|
* @param string Timezone ID as used in PHP's Date functions
|
|
|
|
* @param integer Unix timestamp with first date/time in this timezone
|
|
|
|
* @param integer Unix timestap with last date/time in this timezone
|
2019-10-04 13:48:44 +02:00
|
|
|
* @param VObject\Component\VCalendar Optional VCalendar component
|
2014-09-22 11:03:11 +02:00
|
|
|
*
|
|
|
|
* @return mixed A Sabre\VObject\Component object representing a VTIMEZONE definition
|
|
|
|
* or false if no timezone information is available
|
|
|
|
*/
|
2014-11-10 16:32:15 +01:00
|
|
|
public static function get_vtimezone($tzid, $from = 0, $to = 0, $cal = null)
|
2014-09-22 11:03:11 +02:00
|
|
|
{
|
2019-10-04 13:48:44 +02:00
|
|
|
// TODO: Consider using tzurl.org database for better interoperability e.g. with Outlook
|
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
if (!$from) {
|
|
|
|
$from = time();
|
|
|
|
}
|
|
|
|
if (!$to) {
|
|
|
|
$to = $from;
|
|
|
|
}
|
|
|
|
if (!$cal) {
|
|
|
|
$cal = new VObject\Component\VCalendar();
|
|
|
|
}
|
2014-09-22 11:03:11 +02:00
|
|
|
|
|
|
|
if (is_string($tzid)) {
|
|
|
|
try {
|
|
|
|
$tz = new \DateTimeZone($tzid);
|
2024-01-24 11:24:41 +01:00
|
|
|
} catch (\Exception $e) {
|
2014-09-22 11:03:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2024-01-24 11:24:41 +01:00
|
|
|
} elseif (is_a($tzid, '\\DateTimeZone')) {
|
2014-09-22 11:03:11 +02:00
|
|
|
$tz = $tzid;
|
|
|
|
}
|
|
|
|
|
2020-12-26 20:41:54 +01:00
|
|
|
if (empty($tz) || !is_a($tz, '\\DateTimeZone')) {
|
2014-09-22 11:03:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$year = 86400 * 360;
|
|
|
|
$transitions = $tz->getTransitions($from - $year, $to + $year);
|
|
|
|
|
2019-10-04 13:48:44 +02:00
|
|
|
// Make sure VTIMEZONE contains at least one STANDARD/DAYLIGHT component
|
|
|
|
// when there's only one transition in specified time period (T5626)
|
|
|
|
if (count($transitions) == 1) {
|
|
|
|
// Get more transitions and use OFFSET from the previous to last
|
|
|
|
$more_transitions = $tz->getTransitions(0, $to + $year);
|
|
|
|
if (count($more_transitions) > 1) {
|
|
|
|
$index = count($more_transitions) - 2;
|
|
|
|
$tzfrom = $more_transitions[$index]['offset'] / 3600;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 16:32:15 +01:00
|
|
|
$vt = $cal->createComponent('VTIMEZONE');
|
2014-09-22 11:03:11 +02:00
|
|
|
$vt->TZID = $tz->getName();
|
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
$std = null;
|
|
|
|
$dst = null;
|
2024-01-24 10:59:25 +01:00
|
|
|
$t_dst = $t_std = 0;
|
2014-09-22 11:03:11 +02:00
|
|
|
foreach ($transitions as $i => $trans) {
|
|
|
|
$cmp = null;
|
|
|
|
|
2019-10-04 13:48:44 +02:00
|
|
|
if (!isset($tzfrom)) {
|
2014-09-22 11:03:11 +02:00
|
|
|
$tzfrom = $trans['offset'] / 3600;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trans['isdst']) {
|
|
|
|
$t_dst = $trans['ts'];
|
2014-11-10 16:32:15 +01:00
|
|
|
$dst = $cal->createComponent('DAYLIGHT');
|
2014-09-22 11:03:11 +02:00
|
|
|
$cmp = $dst;
|
2024-01-24 11:24:41 +01:00
|
|
|
} else {
|
2014-09-22 11:03:11 +02:00
|
|
|
$t_std = $trans['ts'];
|
2014-11-10 16:32:15 +01:00
|
|
|
$std = $cal->createComponent('STANDARD');
|
2014-09-22 11:03:11 +02:00
|
|
|
$cmp = $std;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cmp) {
|
|
|
|
$dt = new DateTime($trans['time']);
|
|
|
|
$offset = $trans['offset'] / 3600;
|
|
|
|
|
|
|
|
$cmp->DTSTART = $dt->format('Ymd\THis');
|
2015-06-04 17:11:16 +02:00
|
|
|
$cmp->TZOFFSETFROM = sprintf('%+03d%02d', floor($tzfrom), ($tzfrom - floor($tzfrom)) * 60);
|
|
|
|
$cmp->TZOFFSETTO = sprintf('%+03d%02d', floor($offset), ($offset - floor($offset)) * 60);
|
2014-09-22 11:03:11 +02:00
|
|
|
|
|
|
|
if (!empty($trans['abbr'])) {
|
|
|
|
$cmp->TZNAME = $trans['abbr'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$tzfrom = $offset;
|
|
|
|
$vt->add($cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we covered the entire date range
|
|
|
|
if ($std && $dst && min($t_std, $t_dst) < $from && max($t_std, $t_dst) > $to) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add X-MICROSOFT-CDO-TZID if available
|
|
|
|
$microsoftExchangeMap = array_flip(VObject\TimeZoneUtil::$microsoftExchangeMap);
|
|
|
|
if (array_key_exists($tz->getName(), $microsoftExchangeMap)) {
|
|
|
|
$vt->add('X-MICROSOFT-CDO-TZID', $microsoftExchangeMap[$tz->getName()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $vt;
|
|
|
|
}
|
|
|
|
|
2022-12-07 14:50:50 +01:00
|
|
|
/**
|
|
|
|
* Convert DateTime into libcalendaring_datetime
|
|
|
|
*/
|
|
|
|
private static function toDateTime($date)
|
|
|
|
{
|
|
|
|
return libcalendaring_datetime::createFromFormat(
|
|
|
|
'Y-m-d\\TH:i:s',
|
|
|
|
$date->format('Y-m-d\\TH:i:s'),
|
|
|
|
$date->getTimezone()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-10-17 13:10:19 +02:00
|
|
|
|
|
|
|
/*** Implement PHP 5 Iterator interface to make foreach work ***/
|
|
|
|
|
2021-10-24 09:32:52 +02:00
|
|
|
#[\ReturnTypeWillChange]
|
2024-01-24 11:24:41 +01:00
|
|
|
public function current()
|
2013-10-17 13:10:19 +02:00
|
|
|
{
|
|
|
|
return $this->objects[$this->iteratorkey];
|
|
|
|
}
|
|
|
|
|
2021-10-24 09:32:52 +02:00
|
|
|
#[\ReturnTypeWillChange]
|
2024-01-24 11:24:41 +01:00
|
|
|
public function key()
|
2013-10-17 13:10:19 +02:00
|
|
|
{
|
|
|
|
return $this->iteratorkey;
|
|
|
|
}
|
|
|
|
|
2021-10-24 09:32:52 +02:00
|
|
|
#[\ReturnTypeWillChange]
|
2024-01-24 11:24:41 +01:00
|
|
|
public function next()
|
2013-10-17 13:10:19 +02:00
|
|
|
{
|
|
|
|
$this->iteratorkey++;
|
|
|
|
|
|
|
|
// read next chunk if we're reading from a file
|
2020-12-26 20:41:54 +01:00
|
|
|
if (empty($this->objects[$this->iteratorkey]) && $this->fp) {
|
2013-10-17 13:10:19 +02:00
|
|
|
$this->_parse_next(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->valid();
|
|
|
|
}
|
|
|
|
|
2021-10-24 09:32:52 +02:00
|
|
|
#[\ReturnTypeWillChange]
|
2024-01-24 11:24:41 +01:00
|
|
|
public function rewind()
|
2013-10-17 13:10:19 +02:00
|
|
|
{
|
|
|
|
$this->iteratorkey = 0;
|
|
|
|
}
|
|
|
|
|
2021-10-24 09:32:52 +02:00
|
|
|
#[\ReturnTypeWillChange]
|
2024-01-24 11:24:41 +01:00
|
|
|
public function valid()
|
2013-10-17 13:10:19 +02:00
|
|
|
{
|
|
|
|
return !empty($this->objects[$this->iteratorkey]);
|
|
|
|
}
|
|
|
|
|
2011-10-27 10:20:46 +02:00
|
|
|
}
|
2013-09-12 10:57:22 +02:00
|
|
|
|
2013-09-13 09:47:40 +02:00
|
|
|
|
2013-09-12 10:57:22 +02:00
|
|
|
/**
|
2014-11-10 16:32:15 +01:00
|
|
|
* Override Sabre\VObject\Property\Text that quotes commas in the location property
|
2013-09-12 10:57:22 +02:00
|
|
|
* because Apple clients treat that property as list.
|
|
|
|
*/
|
2014-11-10 16:32:15 +01:00
|
|
|
class vobject_location_property extends VObject\Property\Text
|
2013-09-12 10:57:22 +02:00
|
|
|
{
|
|
|
|
/**
|
2014-11-10 16:32:15 +01:00
|
|
|
* List of properties that are considered 'structured'.
|
2013-09-12 10:57:22 +02:00
|
|
|
*
|
2014-11-10 16:32:15 +01:00
|
|
|
* @var array
|
2013-09-12 10:57:22 +02:00
|
|
|
*/
|
2022-11-30 12:54:29 +01:00
|
|
|
protected $structuredValues = [
|
2014-11-10 16:32:15 +01:00
|
|
|
// vCard
|
|
|
|
'N',
|
|
|
|
'ADR',
|
|
|
|
'ORG',
|
|
|
|
'GENDER',
|
|
|
|
'LOCATION',
|
|
|
|
// iCalendar
|
|
|
|
'REQUEST-STATUS',
|
2022-11-30 12:54:29 +01:00
|
|
|
];
|
2013-09-12 10:57:22 +02:00
|
|
|
}
|