Changeset View
Changeset View
Standalone View
Standalone View
plugins/libcalendaring/libcalendaring.php
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Line(s) | |||||
{ | { | ||||
if (is_numeric($dt)) { | if (is_numeric($dt)) { | ||||
$dt = new DateTime('@'.$dt); | $dt = new DateTime('@'.$dt); | ||||
} | } | ||||
else if (is_string($dt)) { | else if (is_string($dt)) { | ||||
$dt = rcube_utils::anytodatetime($dt); | $dt = rcube_utils::anytodatetime($dt); | ||||
} | } | ||||
if ($dt instanceof DateTime && empty($dt->_dateonly) && !$dateonly) { | if (($dt instanceof DateTime || $dt instanceof DateTimeImmutable) && empty($dt->_dateonly) && !$dateonly) { | ||||
$dt->setTimezone($this->timezone); | $dt->setTimezone($this->timezone); | ||||
} | } | ||||
return $dt; | return $dt; | ||||
} | } | ||||
/** | /** | ||||
* | * | ||||
▲ Show 20 Lines • Show All 288 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
/** | /** | ||||
* Convert the alarms list items to be processed on the client | * Convert the alarms list items to be processed on the client | ||||
*/ | */ | ||||
public static function to_client_alarms($valarms) | public static function to_client_alarms($valarms) | ||||
{ | { | ||||
return array_map(function($alarm){ | return array_map(function($alarm){ | ||||
if ($alarm['trigger'] instanceof DateTime) { | if ($alarm['trigger'] instanceof DateTime || $alarm['trigger'] instanceof DateTimeImmutable) { | ||||
$alarm['trigger'] = '@' . $alarm['trigger']->format('U'); | $alarm['trigger'] = '@' . $alarm['trigger']->format('U'); | ||||
} | } | ||||
else if ($trigger = libcalendaring::parse_alarm_value($alarm['trigger'])) { | else if ($trigger = libcalendaring::parse_alarm_value($alarm['trigger'])) { | ||||
$alarm['trigger'] = $trigger[2]; | $alarm['trigger'] = $trigger[2]; | ||||
} | } | ||||
return $alarm; | return $alarm; | ||||
}, (array)$valarms); | }, (array)$valarms); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | |||||
case 'DISPLAY': | case 'DISPLAY': | ||||
$text = $rcube->gettext('libcalendaring.alarmdisplay'); | $text = $rcube->gettext('libcalendaring.alarmdisplay'); | ||||
break; | break; | ||||
case 'AUDIO': | case 'AUDIO': | ||||
$text = $rcube->gettext('libcalendaring.alarmaudio'); | $text = $rcube->gettext('libcalendaring.alarmaudio'); | ||||
break; | break; | ||||
} | } | ||||
if ($trigger instanceof DateTime) { | if ($trigger instanceof DateTime || $trigger instanceof DateTimeImmutable) { | ||||
$text .= ' ' . $rcube->gettext(array( | $text .= ' ' . $rcube->gettext(array( | ||||
'name' => 'libcalendaring.alarmat', | 'name' => 'libcalendaring.alarmat', | ||||
'vars' => array('datetime' => $rcube->format_date($trigger)) | 'vars' => array('datetime' => $rcube->format_date($trigger)) | ||||
)); | )); | ||||
} | } | ||||
else if (preg_match('/@(\d+)/', $trigger, $m)) { | else if (preg_match('/@(\d+)/', $trigger, $m)) { | ||||
$text .= ' ' . $rcube->gettext(array( | $text .= ' ' . $rcube->gettext(array( | ||||
'name' => 'libcalendaring.alarmat', | 'name' => 'libcalendaring.alarmat', | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
$alarm_prop = null; | $alarm_prop = null; | ||||
$expires = new DateTime('now - 12 hours'); | $expires = new DateTime('now - 12 hours'); | ||||
$notify_at = null; | $notify_at = null; | ||||
// handle multiple alarms | // handle multiple alarms | ||||
foreach ($rec['valarms'] as $alarm) { | foreach ($rec['valarms'] as $alarm) { | ||||
$notify_time = null; | $notify_time = null; | ||||
if ($alarm['trigger'] instanceof DateTime) { | if ($alarm['trigger'] instanceof DateTime || $alarm['trigger'] instanceof DateTimeImmutable) { | ||||
$notify_time = $alarm['trigger']; | $notify_time = $alarm['trigger']; | ||||
} | } | ||||
else if (is_string($alarm['trigger'])) { | else if (is_string($alarm['trigger'])) { | ||||
$refdate = !empty($alarm['related']) && $alarm['related'] == 'END' ? $rec['end'] : $rec['start']; | $refdate = !empty($alarm['related']) && $alarm['related'] == 'END' ? $rec['end'] : $rec['start']; | ||||
// abort if no reference date is available to compute notification time | // abort if no reference date is available to compute notification time | ||||
if (!is_a($refdate, 'DateTime')) { | if (!is_a($refdate, 'DateTime')) { | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 509 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Read the given mime message from IMAP and parse ical data | * Read the given mime message from IMAP and parse ical data | ||||
* | * | ||||
* @param string Mailbox name | * @param string Mailbox name | ||||
* @param string Message UID | * @param string Message UID | ||||
* @param string Message part ID and object index (e.g. '1.2:0') | * @param string Message part ID and object index (e.g. '1.2:0') | ||||
* @param string Object type filter (optional) | * @param string Object type filter (optional) | ||||
* | * | ||||
* @return array Hash array with the parsed iCal | * @return array Hash array with the parsed iCal | ||||
*/ | */ | ||||
public function mail_get_itip_object($mbox, $uid, $mime_id, $type = null) | public function mail_get_itip_object($mbox, $uid, $mime_id, $type = null) | ||||
{ | { | ||||
$charset = RCUBE_CHARSET; | $charset = RCUBE_CHARSET; | ||||
// establish imap connection | // establish imap connection | ||||
$imap = $this->rc->get_storage(); | $imap = $this->rc->get_storage(); | ||||
$imap->set_folder($mbox); | $imap->set_folder($mbox); | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | |||||
* @param bool All-day flag from the main event | * @param bool All-day flag from the main event | ||||
* | * | ||||
* @return mixed Format string or null if identifier cannot be generated | * @return mixed Format string or null if identifier cannot be generated | ||||
*/ | */ | ||||
public static function recurrence_instance_identifier($event, $allday = null) | public static function recurrence_instance_identifier($event, $allday = null) | ||||
{ | { | ||||
$instance_date = !empty($event['recurrence_date']) ? $event['recurrence_date'] : $event['start']; | $instance_date = !empty($event['recurrence_date']) ? $event['recurrence_date'] : $event['start']; | ||||
if ($instance_date instanceof DateTime) { | if ($instance_date instanceof DateTime || $instance_date instanceof DateTimeImmutable) { | ||||
// According to RFC5545 (3.8.4.4) RECURRENCE-ID format should | // According to RFC5545 (3.8.4.4) RECURRENCE-ID format should | ||||
// be date/date-time depending on the main event type, not the exception | // be date/date-time depending on the main event type, not the exception | ||||
if ($allday === null) { | if ($allday === null) { | ||||
$allday = !empty($event['allday']); | $allday = !empty($event['allday']); | ||||
} | } | ||||
return $instance_date->format($allday ? 'Ymd' : 'Ymd\THis'); | return $instance_date->format($allday ? 'Ymd' : 'Ymd\THis'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines |