Fix PHP8 warnings

This commit is contained in:
Aleksander Machniak 2023-06-12 12:07:58 +02:00
parent 6841eb8207
commit 096b7a8181
17 changed files with 71 additions and 54 deletions

View file

@ -3186,7 +3186,7 @@ $("#rcmfd_new_category").keypress(function(event) {
. ' - ' . $this->rc->format_date($end, $this->rc->config->get('time_format')); . ' - ' . $this->rc->format_date($end, $this->rc->config->get('time_format'));
} }
return html::div(rtrim('event-row ' . ($class ?: $event['className'])), return html::div(rtrim('event-row ' . ($class ?: ($event['className'] ?? ''))),
html::span('event-date', $time) html::span('event-date', $time)
. html::span('event-title', rcube::Q($event['title'])) . html::span('event-title', rcube::Q($event['title']))
); );
@ -3561,7 +3561,7 @@ $("#rcmfd_new_category").keypress(function(event) {
} }
else if (!$existing && ($status != 'declined' || $this->rc->config->get('kolab_invitation_calendars'))) { else if (!$existing && ($status != 'declined' || $this->rc->config->get('kolab_invitation_calendars'))) {
if ($status == 'declined' if ($status == 'declined'
|| $event['status'] == 'CANCELLED' || ($event['status'] ?? '') == 'CANCELLED'
|| ($event_attendee && ($event_attendee['role'] ?? '') == 'NON-PARTICIPANT') || ($event_attendee && ($event_attendee['role'] ?? '') == 'NON-PARTICIPANT')
) { ) {
$event['free_busy'] = 'free'; $event['free_busy'] = 'free';
@ -3642,8 +3642,8 @@ $("#rcmfd_new_category").keypress(function(event) {
} }
// send iTip reply // send iTip reply
if ($event['_method'] == 'REQUEST' && !empty($organizer) && !$noreply if ($event['_method'] == 'REQUEST' && !empty($organizer) && !$noreply && !$error_msg && !empty($reply_sender)
&& !in_array(strtolower($organizer['email']), $emails) && !$error_msg && !in_array(strtolower($organizer['email']), $emails)
) { ) {
$event['comment'] = $comment; $event['comment'] = $comment;
$itip = $this->load_itip(); $itip = $this->load_itip();

View file

@ -231,7 +231,7 @@ class kolab_calendar extends kolab_storage_folder_api
} }
} }
return $this->events[$id]; return $this->events[$id] ?? null;
} }
/** /**
@ -322,7 +322,7 @@ class kolab_calendar extends kolab_storage_folder_api
// remember seen categories // remember seen categories
if (!empty($event['categories'])) { if (!empty($event['categories'])) {
$cat = is_array($event['categories']) ? $event['categories'][0] : $event['categories']; $cat = is_array($event['categories']) ? $event['categories'][0] : $event['categories'];
$this->categories[$cat]++; $this->categories[$cat] = ($this->categories[$cat] ?? 0) + 1;
} }
// list events in requested time window // list events in requested time window

View file

@ -346,7 +346,7 @@ class kolab_invitation_calendar
// set classes according to PARTSTAT // set classes according to PARTSTAT
$event = kolab_driver::add_partstat_class($event, $this->partstats); $event = kolab_driver::add_partstat_class($event, $this->partstats);
if (strpos($event['className'], 'fc-invitation-') !== false) { if (!empty($event['className']) && strpos($event['className'], 'fc-invitation-') !== false) {
$event['calendar'] = $this->id; $event['calendar'] = $this->id;
} }

View file

@ -257,12 +257,15 @@ class kolab_2fa extends rcube_plugin
// create HTML table with two cols // create HTML table with two cols
$table = new html_table(array('cols' => 2)); $table = new html_table(array('cols' => 2));
$required = count($methods) > 1 ? null : 'required'; $required = count($methods) > 1 ? null : 'required';
$row = 0;
// render input for each configured auth method // render input for each configured auth method
foreach ($methods as $i => $method) { foreach ($methods as $i => $method) {
if ($row++ > 0) { if ($row++ > 0) {
$table->add(array('colspan' => 2, 'class' => 'title hint', 'style' => 'text-align:center'), $table->add(
$this->gettext('or')); ['colspan' => 2, 'class' => 'title hint', 'style' => 'text-align:center'],
$this->gettext('or')
);
} }
$field_id = "rcmlogin2fa$method"; $field_id = "rcmlogin2fa$method";
@ -314,7 +317,7 @@ class kolab_2fa extends rcube_plugin
$rcmail = rcmail::get_instance(); $rcmail = rcmail::get_instance();
if ($this->drivers[$factor]) { if (!empty($this->drivers[$factor])) {
return $this->drivers[$factor]; return $this->drivers[$factor];
} }

View file

@ -104,7 +104,7 @@ abstract class Base
$this->config = array_merge($this->config, $config); $this->config = array_merge($this->config, $config);
} }
if ($config['storage']) { if (!empty($config['storage'])) {
$this->storage = \Kolab2FA\Storage\Base::factory($config['storage'], $config['storage_config']); $this->storage = \Kolab2FA\Storage\Base::factory($config['storage'], $config['storage_config']);
} }
} }

View file

@ -79,10 +79,10 @@ abstract class Base
{ {
$this->logger = $logger; $this->logger = $logger;
if ($this->config['debug']) { if (!empty($this->config['debug'])) {
$this->logger->set_level(LOG_DEBUG); $this->logger->set_level(LOG_DEBUG);
} }
else if ($this->config['loglevel']) { else if (!empty($this->config['loglevel'])) {
$this->logger->set_level($this->config['loglevel']); $this->logger->set_level($this->config['loglevel']);
} }
} }

View file

@ -172,7 +172,7 @@ class RcubeUser extends Base
{ {
if ($user = $this->get_user($this->username)) { if ($user = $this->get_user($this->username)) {
$prefs = $user->get_prefs(); $prefs = $user->get_prefs();
return (array)$prefs[$this->key2property('blob')]; return (array) ($prefs[$this->key2property('blob')] ?? []);
} }
return null; return null;
@ -191,5 +191,4 @@ class RcubeUser extends Base
// default // default
return 'kolab_2fa_' . $key; return 'kolab_2fa_' . $key;
} }
} }

View file

@ -531,7 +531,7 @@ class kolab_delegation_engine
'realname' => $realname, 'realname' => $realname,
'imap_uid' => $imap_uid, 'imap_uid' => $imap_uid,
'email' => $email, 'email' => $email,
'organization' => $organization, 'organization' => $organization ?? null,
); );
} }

View file

@ -28,6 +28,8 @@ class kolab_tags extends rcube_plugin
public $home; public $home;
private $engine; private $engine;
private $mail_headers_done = false;
public function init() public function init()
{ {

View file

@ -361,7 +361,7 @@ class kolab_tags_engine
foreach ($taglist as $tag) { foreach ($taglist as $tag) {
$tag = $this->parse_tag($tag, true, false); $tag = $this->parse_tag($tag, true, false);
if (in_array($uid, (array)$tag['uids'][$folder])) { if (!empty($tag['uids'][$folder]) && in_array($uid, (array) $tag['uids'][$folder])) {
unset($tag['uids']); unset($tag['uids']);
$tags[] = $tag; $tags[] = $tag;
} }

View file

@ -216,11 +216,11 @@ class libcalendaring_itip
$replying_attendee = null; $replying_attendee = null;
$reply_attendees = array(); $reply_attendees = array();
foreach ($event['attendees'] as $attendee) { foreach ($event['attendees'] as $attendee) {
if ($attendee['role'] == 'ORGANIZER') { if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') {
$reply_attendees[] = $attendee; $reply_attendees[] = $attendee;
} }
// we accept on behalf of a resource // we accept on behalf of a resource
else if (strcasecmp($attendee['email'], $event['_resource']) == 0) { else if (isset($event['_resource']) && strcasecmp($attendee['email'], $event['_resource']) == 0) {
$replying_attendee = $attendee; $replying_attendee = $attendee;
$replying_attendee['sent-by'] = 'mailto:' . $from_utf; $replying_attendee['sent-by'] = 'mailto:' . $from_utf;
} }
@ -242,7 +242,7 @@ class libcalendaring_itip
array_unshift($reply_attendees, $replying_attendee); array_unshift($reply_attendees, $replying_attendee);
$event['attendees'] = $reply_attendees; $event['attendees'] = $reply_attendees;
} }
if ($event['recurrence']) { if (!empty($event['recurrence'])) {
unset($event['recurrence']['EXCEPTIONS']); unset($event['recurrence']['EXCEPTIONS']);
} }
} }
@ -488,12 +488,16 @@ class libcalendaring_itip
if ($attendee['role'] != 'ORGANIZER' && strcasecmp($attendee['email'], $event['attendee']) == 0) { if ($attendee['role'] != 'ORGANIZER' && strcasecmp($attendee['email'], $event['attendee']) == 0) {
$status_lc = strtolower($status); $status_lc = strtolower($status);
if (in_array($status_lc, $this->rsvp_status)) { if (in_array($status_lc, $this->rsvp_status)) {
$html = html::div('rsvp-status ' . $status_lc, $this->gettext(array( $delegatee = !empty($event['delegated-to']) ? $event['delegated-to']
'name' => 'attendee' . $status_lc, : (!empty($attendee['delegated-to']) ? $attendee['delegated-to'] : '?');
'vars' => array(
'delegatedto' => rcube::Q($event['delegated-to'] ?: ($attendee['delegated-to'] ?: '?')), $html = html::div(
) 'rsvp-status ' . $status_lc,
))); $this->gettext([
'name' => 'attendee' . $status_lc,
'vars' => ['delegatedto' => rcube::Q($delegatee)]
])
);
} }
$action = $attendee['status'] == $status || !$latest ? '' : 'update'; $action = $attendee['status'] == $status || !$latest ? '' : 'update';
@ -624,6 +628,7 @@ class libcalendaring_itip
'method' => $method, 'method' => $method,
'task' => $task, 'task' => $task,
'mime_id' => $mime_id, 'mime_id' => $mime_id,
'rsvp' => false,
); );
// create buttons to be activated from async request checking existence of this event in local calendars // create buttons to be activated from async request checking existence of this event in local calendars
@ -638,7 +643,7 @@ class libcalendaring_itip
if ($attendee) { if ($attendee) {
$metadata['attendee'] = $attendee['email']; $metadata['attendee'] = $attendee['email'];
$rsvp_status = strtoupper($attendee['status']); $rsvp_status = strtoupper($attendee['status']);
if ($attendee['delegated-to']) { if (!empty($attendee['delegated-to'])) {
$metadata['delegated-to'] = $attendee['delegated-to']; $metadata['delegated-to'] = $attendee['delegated-to'];
} }
} }
@ -1007,7 +1012,7 @@ class libcalendaring_itip
*/ */
public function find_attendee_by_email($attendees, $email_field, $email, $email_utf = null) { public function find_attendee_by_email($attendees, $email_field, $email, $email_utf = null) {
foreach ($attendees as $_attendee) { foreach ($attendees as $_attendee) {
if ($attendee['role'] == 'ORGANIZER') { if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') {
continue; continue;
} }
if (!empty($attendee[$email_field]) && self::compare_email($attendee[$email_field], $email, $email_utf)) { if (!empty($attendee[$email_field]) && self::compare_email($attendee[$email_field], $email, $email_utf)) {

View file

@ -1478,7 +1478,7 @@ class libcalendaring extends rcube_plugin
// is not overriden by NEEDS-ACTION if it was already set // is not overriden by NEEDS-ACTION if it was already set
// which could happen if you work with shared events // which could happen if you work with shared events
foreach ((array) $new['attendees'] as $i => $attendee) { foreach ((array) $new['attendees'] as $i => $attendee) {
if ($attendee['email'] && $attendee['status'] == 'NEEDS-ACTION') { if ($attendee['email'] && ($attendee['status'] ?? '') == 'NEEDS-ACTION') {
foreach ($old['attendees'] as $_attendee) { foreach ($old['attendees'] as $_attendee) {
if ($attendee['email'] == $_attendee['email']) { if ($attendee['email'] == $_attendee['email']) {
$new['attendees'][$i]['status'] = $_attendee['status']; $new['attendees'][$i]['status'] = $_attendee['status'];

View file

@ -60,8 +60,8 @@ class kolab_format_event extends kolab_format_xcal
parent::set($object); parent::set($object);
// do the hard work of setting object values // do the hard work of setting object values
$this->obj->setStart(self::get_datetime($object['start'], null, $object['allday'])); $this->obj->setStart(self::get_datetime($object['start'], null, !empty($object['allday'])));
$this->obj->setEnd(self::get_datetime($object['end'], null, $object['allday'])); $this->obj->setEnd(self::get_datetime($object['end'], null, !empty($object['allday'])));
$this->obj->setTransparency($object['free_busy'] == 'free'); $this->obj->setTransparency($object['free_busy'] == 'free');
$status = kolabformat::StatusUndefined; $status = kolabformat::StatusUndefined;
@ -97,7 +97,8 @@ class kolab_format_event extends kolab_format_xcal
$compacted['recurrence_date'] = $recurrence_id; $compacted['recurrence_date'] = $recurrence_id;
} }
$exevent->obj->setRecurrenceID(self::get_datetime($recurrence_id ?: $exception['start'], null, $object['allday']), (bool)$exception['thisandfuture']); $ex_dt = self::get_datetime($recurrence_id ?: $exception['start'], null, !empty($object['allday']));
$exevent->obj->setRecurrenceID($ex_dt, !empty($exception['thisandfuture']));
$vexceptions->push($exevent->obj); $vexceptions->push($exevent->obj);
@ -272,7 +273,7 @@ class kolab_format_event extends kolab_format_xcal
$tags = parent::get_tags($obj); $tags = parent::get_tags($obj);
$object = $obj ?: $this->data; $object = $obj ?: $this->data;
foreach ((array)$object['categories'] as $cat) { foreach ((array) ($object['categories'] ?? []) as $cat) {
$tags[] = rcube_utils::normalize_string($cat); $tags[] = rcube_utils::normalize_string($cat);
} }
@ -294,7 +295,7 @@ class kolab_format_event extends kolab_format_xcal
// preserve this property for date serialization // preserve this property for date serialization
if (!isset($exception['allday'])) { if (!isset($exception['allday'])) {
$exception['allday'] = $master['allday']; $exception['allday'] = !empty($master['allday']);
} }
return $exception; return $exception;

View file

@ -348,7 +348,7 @@ abstract class kolab_format_xcal extends kolab_format
$this->obj->setSummary($object['title']); $this->obj->setSummary($object['title']);
$this->obj->setLocation($object['location'] ?? null); $this->obj->setLocation($object['location'] ?? null);
$this->obj->setDescription($object['description']); $this->obj->setDescription($object['description']);
$this->obj->setPriority($object['priority']); $this->obj->setPriority($object['priority'] ?? null);
$this->obj->setCategories(self::array2vector($object['categories'] ?? null)); $this->obj->setCategories(self::array2vector($object['categories'] ?? null));
$this->obj->setUrl(strval($object['url'] ?? null)); $this->obj->setUrl(strval($object['url'] ?? null));
@ -359,10 +359,13 @@ abstract class kolab_format_xcal extends kolab_format
// process event attendees // process event attendees
$attendees = new vectorattendee; $attendees = new vectorattendee;
foreach ((array)($object['attendees'] ?? []) as $i => $attendee) { foreach ((array)($object['attendees'] ?? []) as $i => $attendee) {
if ($attendee['role'] == 'ORGANIZER') { if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') {
$object['organizer'] = $attendee; $object['organizer'] = $attendee;
} }
else if ($attendee['email'] != $object['organizer']['email']) { else if (
!empty($attendee['email'])
&& (empty($object['organizer']['email']) || $attendee['email'] != $object['organizer']['email'])
) {
$cr = new ContactReference(ContactReference::EmailReference, $attendee['email']); $cr = new ContactReference(ContactReference::EmailReference, $attendee['email']);
$cr->setName($attendee['name']); $cr->setName($attendee['name']);
@ -371,12 +374,16 @@ abstract class kolab_format_xcal extends kolab_format
$object['attendees'][$i]['rsvp'] = $attendee['rsvp'] = $reschedule; $object['attendees'][$i]['rsvp'] = $attendee['rsvp'] = $reschedule;
} }
$cutype = $this->cutype_map[$attendee['cutype'] ?? -1] ?? null;
$partstat = $this->part_status_map[$attendee['status'] ?? -1] ?? null;
$role = $this->role_map[$attendee['role'] ?? -1] ?? null;
$att = new Attendee; $att = new Attendee;
$att->setContact($cr); $att->setContact($cr);
$att->setPartStat($this->part_status_map[$attendee['status']]); $att->setPartStat($partstat);
$att->setRole($this->role_map[$attendee['role']] ?: kolabformat::Required); $att->setRole($role ?: kolabformat::Required);
$att->setCutype($this->cutype_map[$attendee['cutype']] ?: kolabformat::CutypeIndividual); $att->setCutype($cutype ?: kolabformat::CutypeIndividual);
$att->setRSVP((bool)$attendee['rsvp']); $att->setRSVP(!empty($attendee['rsvp']));
if (!empty($attendee['delegated-from'])) { if (!empty($attendee['delegated-from'])) {
$vdelegators = new vectorcontactref; $vdelegators = new vectorcontactref;
@ -407,9 +414,9 @@ abstract class kolab_format_xcal extends kolab_format
} }
$this->obj->setAttendees($attendees); $this->obj->setAttendees($attendees);
if ($object['organizer']) { if (!empty($object['organizer'])) {
$organizer = new ContactReference(ContactReference::EmailReference, $object['organizer']['email']); $organizer = new ContactReference(ContactReference::EmailReference, $object['organizer']['email'] ?? null);
$organizer->setName($object['organizer']['name']); $organizer->setName($object['organizer']['name'] ?? '');
$this->obj->setOrganizer($organizer); $this->obj->setOrganizer($organizer);
} }
@ -529,8 +536,8 @@ abstract class kolab_format_xcal extends kolab_format
$recipients->push(new ContactReference(ContactReference::EmailReference, $email)); $recipients->push(new ContactReference(ContactReference::EmailReference, $email));
} }
$alarm = new Alarm( $alarm = new Alarm(
strval($valarm['summary'] ?: $object['title']), strval(!empty($valarm['summary']) ? $valarm['summary'] : $object['title']),
strval($valarm['description'] ?: $object['description']), strval(!empty($valarm['description']) ? $valarm['description'] : $object['description']),
$recipients $recipients
); );
} }
@ -566,15 +573,15 @@ abstract class kolab_format_xcal extends kolab_format
continue; continue;
} }
$related = strtoupper($valarm['related']) == 'END' ? kolabformat::End : kolabformat::Start; $related = strtoupper($valarm['related'] ?? '') == 'END' ? kolabformat::End : kolabformat::Start;
$alarm->setRelativeStart($duration, $related); $alarm->setRelativeStart($duration, $related);
} }
if ($valarm['duration']) { if (!empty($valarm['duration'])) {
try { try {
$d = new DateInterval($valarm['duration']); $d = new DateInterval($valarm['duration']);
$duration = new Duration($d->d, $d->h, $d->i, $d->s); $duration = new Duration($d->d, $d->h, $d->i, $d->s);
$alarm->setDuration($duration, intval($valarm['repeat'])); $alarm->setDuration($duration, intval($valarm['repeat'] ?? 0));
} }
catch (Exception $e) { catch (Exception $e) {
// ignore // ignore

View file

@ -510,7 +510,7 @@ class kolab_ldap extends rcube_ldap_generic
// if not set it means we use this LDAP object for other // if not set it means we use this LDAP object for other
// purposes, e.g. kolab_delegation, then username with // purposes, e.g. kolab_delegation, then username with
// correct domain is in a session // correct domain is in a session
if (!$user) { if (!$user && !empty($_SESSION['username'])) {
$user = $_SESSION['username']; $user = $_SESSION['username'];
} }
@ -533,7 +533,7 @@ class kolab_ldap extends rcube_ldap_generic
} }
// realmed username (with domain) // realmed username (with domain)
if (strpos($user, '@')) { if ($user && strpos($user, '@')) {
list($usr, $dom) = explode('@', $user); list($usr, $dom) = explode('@', $user);
// unrealm domain, user login can contain a domain alias // unrealm domain, user login can contain a domain alias

View file

@ -778,10 +778,10 @@ class kolab_storage_config
} }
foreach ($tags as $tag) { foreach ($tags as $tag) {
if ($search_uid && in_array($search_uid, (array) $tag['members'])) { if (!empty($search_uid) && in_array($search_uid, (array) $tag['members'])) {
$result[] = $tag; $result[] = $tag;
} }
else if ($search_msg) { else if (!empty($search_msg)) {
foreach ($tag['members'] as $m) { foreach ($tag['members'] as $m) {
if (strpos($m, $search_msg) !== false) { if (strpos($m, $search_msg) !== false) {
$result[] = $tag; $result[] = $tag;

View file

@ -358,7 +358,7 @@ class libkolab extends rcube_plugin
*/ */
public static function recurrence_id_format($event) public static function recurrence_id_format($event)
{ {
return $event['allday'] ? 'Ymd' : 'Ymd\THis'; return !empty($event['allday']) ? 'Ymd' : 'Ymd\THis';
} }
/** /**