From 096b7a81816eaec87beff654f16dfa3cc7d14d2b Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 12 Jun 2023 12:07:58 +0200 Subject: [PATCH] Fix PHP8 warnings --- plugins/calendar/calendar.php | 8 ++-- .../calendar/drivers/kolab/kolab_calendar.php | 4 +- .../kolab/kolab_invitation_calendar.php | 2 +- plugins/kolab_2fa/kolab_2fa.php | 9 +++-- .../kolab_2fa/lib/Kolab2FA/Driver/Base.php | 2 +- .../kolab_2fa/lib/Kolab2FA/Storage/Base.php | 4 +- .../lib/Kolab2FA/Storage/RcubeUser.php | 3 +- .../kolab_delegation_engine.php | 2 +- plugins/kolab_tags/kolab_tags.php | 2 + plugins/kolab_tags/lib/kolab_tags_engine.php | 2 +- .../lib/libcalendaring_itip.php | 27 ++++++++------ plugins/libcalendaring/libcalendaring.php | 2 +- plugins/libkolab/lib/kolab_format_event.php | 11 +++--- plugins/libkolab/lib/kolab_format_xcal.php | 37 +++++++++++-------- plugins/libkolab/lib/kolab_ldap.php | 4 +- plugins/libkolab/lib/kolab_storage_config.php | 4 +- plugins/libkolab/libkolab.php | 2 +- 17 files changed, 71 insertions(+), 54 deletions(-) diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index fb9321c8..f08d8f8e 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -3186,7 +3186,7 @@ $("#rcmfd_new_category").keypress(function(event) { . ' - ' . $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-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'))) { if ($status == 'declined' - || $event['status'] == 'CANCELLED' + || ($event['status'] ?? '') == 'CANCELLED' || ($event_attendee && ($event_attendee['role'] ?? '') == 'NON-PARTICIPANT') ) { $event['free_busy'] = 'free'; @@ -3642,8 +3642,8 @@ $("#rcmfd_new_category").keypress(function(event) { } // send iTip reply - if ($event['_method'] == 'REQUEST' && !empty($organizer) && !$noreply - && !in_array(strtolower($organizer['email']), $emails) && !$error_msg + if ($event['_method'] == 'REQUEST' && !empty($organizer) && !$noreply && !$error_msg && !empty($reply_sender) + && !in_array(strtolower($organizer['email']), $emails) ) { $event['comment'] = $comment; $itip = $this->load_itip(); diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php index 3d8b5cc6..d95de4e6 100644 --- a/plugins/calendar/drivers/kolab/kolab_calendar.php +++ b/plugins/calendar/drivers/kolab/kolab_calendar.php @@ -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 if (!empty($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 diff --git a/plugins/calendar/drivers/kolab/kolab_invitation_calendar.php b/plugins/calendar/drivers/kolab/kolab_invitation_calendar.php index 5f2ac372..d8d58321 100644 --- a/plugins/calendar/drivers/kolab/kolab_invitation_calendar.php +++ b/plugins/calendar/drivers/kolab/kolab_invitation_calendar.php @@ -346,7 +346,7 @@ class kolab_invitation_calendar // set classes according to PARTSTAT $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; } diff --git a/plugins/kolab_2fa/kolab_2fa.php b/plugins/kolab_2fa/kolab_2fa.php index 6658f90b..cd60bcd7 100644 --- a/plugins/kolab_2fa/kolab_2fa.php +++ b/plugins/kolab_2fa/kolab_2fa.php @@ -257,12 +257,15 @@ class kolab_2fa extends rcube_plugin // create HTML table with two cols $table = new html_table(array('cols' => 2)); $required = count($methods) > 1 ? null : 'required'; + $row = 0; // render input for each configured auth method foreach ($methods as $i => $method) { if ($row++ > 0) { - $table->add(array('colspan' => 2, 'class' => 'title hint', 'style' => 'text-align:center'), - $this->gettext('or')); + $table->add( + ['colspan' => 2, 'class' => 'title hint', 'style' => 'text-align:center'], + $this->gettext('or') + ); } $field_id = "rcmlogin2fa$method"; @@ -314,7 +317,7 @@ class kolab_2fa extends rcube_plugin $rcmail = rcmail::get_instance(); - if ($this->drivers[$factor]) { + if (!empty($this->drivers[$factor])) { return $this->drivers[$factor]; } diff --git a/plugins/kolab_2fa/lib/Kolab2FA/Driver/Base.php b/plugins/kolab_2fa/lib/Kolab2FA/Driver/Base.php index ec90239f..b12fc7a2 100644 --- a/plugins/kolab_2fa/lib/Kolab2FA/Driver/Base.php +++ b/plugins/kolab_2fa/lib/Kolab2FA/Driver/Base.php @@ -104,7 +104,7 @@ abstract class Base $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']); } } diff --git a/plugins/kolab_2fa/lib/Kolab2FA/Storage/Base.php b/plugins/kolab_2fa/lib/Kolab2FA/Storage/Base.php index b4f36115..80e9be7e 100644 --- a/plugins/kolab_2fa/lib/Kolab2FA/Storage/Base.php +++ b/plugins/kolab_2fa/lib/Kolab2FA/Storage/Base.php @@ -79,10 +79,10 @@ abstract class Base { $this->logger = $logger; - if ($this->config['debug']) { + if (!empty($this->config['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']); } } diff --git a/plugins/kolab_2fa/lib/Kolab2FA/Storage/RcubeUser.php b/plugins/kolab_2fa/lib/Kolab2FA/Storage/RcubeUser.php index 1167aa77..74c32c92 100644 --- a/plugins/kolab_2fa/lib/Kolab2FA/Storage/RcubeUser.php +++ b/plugins/kolab_2fa/lib/Kolab2FA/Storage/RcubeUser.php @@ -172,7 +172,7 @@ class RcubeUser extends Base { if ($user = $this->get_user($this->username)) { $prefs = $user->get_prefs(); - return (array)$prefs[$this->key2property('blob')]; + return (array) ($prefs[$this->key2property('blob')] ?? []); } return null; @@ -191,5 +191,4 @@ class RcubeUser extends Base // default return 'kolab_2fa_' . $key; } - } diff --git a/plugins/kolab_delegation/kolab_delegation_engine.php b/plugins/kolab_delegation/kolab_delegation_engine.php index c8884b89..075430f7 100644 --- a/plugins/kolab_delegation/kolab_delegation_engine.php +++ b/plugins/kolab_delegation/kolab_delegation_engine.php @@ -531,7 +531,7 @@ class kolab_delegation_engine 'realname' => $realname, 'imap_uid' => $imap_uid, 'email' => $email, - 'organization' => $organization, + 'organization' => $organization ?? null, ); } diff --git a/plugins/kolab_tags/kolab_tags.php b/plugins/kolab_tags/kolab_tags.php index ec47f7f3..71485d8c 100644 --- a/plugins/kolab_tags/kolab_tags.php +++ b/plugins/kolab_tags/kolab_tags.php @@ -28,6 +28,8 @@ class kolab_tags extends rcube_plugin public $home; private $engine; + private $mail_headers_done = false; + public function init() { diff --git a/plugins/kolab_tags/lib/kolab_tags_engine.php b/plugins/kolab_tags/lib/kolab_tags_engine.php index 10f8f5db..223244c2 100644 --- a/plugins/kolab_tags/lib/kolab_tags_engine.php +++ b/plugins/kolab_tags/lib/kolab_tags_engine.php @@ -361,7 +361,7 @@ class kolab_tags_engine foreach ($taglist as $tag) { $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']); $tags[] = $tag; } diff --git a/plugins/libcalendaring/lib/libcalendaring_itip.php b/plugins/libcalendaring/lib/libcalendaring_itip.php index 680d79e1..0e2e18d4 100644 --- a/plugins/libcalendaring/lib/libcalendaring_itip.php +++ b/plugins/libcalendaring/lib/libcalendaring_itip.php @@ -216,11 +216,11 @@ class libcalendaring_itip $replying_attendee = null; $reply_attendees = array(); foreach ($event['attendees'] as $attendee) { - if ($attendee['role'] == 'ORGANIZER') { + if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') { $reply_attendees[] = $attendee; } // 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['sent-by'] = 'mailto:' . $from_utf; } @@ -242,7 +242,7 @@ class libcalendaring_itip array_unshift($reply_attendees, $replying_attendee); $event['attendees'] = $reply_attendees; } - if ($event['recurrence']) { + if (!empty($event['recurrence'])) { unset($event['recurrence']['EXCEPTIONS']); } } @@ -488,12 +488,16 @@ class libcalendaring_itip if ($attendee['role'] != 'ORGANIZER' && strcasecmp($attendee['email'], $event['attendee']) == 0) { $status_lc = strtolower($status); if (in_array($status_lc, $this->rsvp_status)) { - $html = html::div('rsvp-status ' . $status_lc, $this->gettext(array( - 'name' => 'attendee' . $status_lc, - 'vars' => array( - 'delegatedto' => rcube::Q($event['delegated-to'] ?: ($attendee['delegated-to'] ?: '?')), - ) - ))); + $delegatee = !empty($event['delegated-to']) ? $event['delegated-to'] + : (!empty($attendee['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'; @@ -624,6 +628,7 @@ class libcalendaring_itip 'method' => $method, 'task' => $task, 'mime_id' => $mime_id, + 'rsvp' => false, ); // 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) { $metadata['attendee'] = $attendee['email']; $rsvp_status = strtoupper($attendee['status']); - if ($attendee['delegated-to']) { + if (!empty($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) { foreach ($attendees as $_attendee) { - if ($attendee['role'] == 'ORGANIZER') { + if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') { continue; } if (!empty($attendee[$email_field]) && self::compare_email($attendee[$email_field], $email, $email_utf)) { diff --git a/plugins/libcalendaring/libcalendaring.php b/plugins/libcalendaring/libcalendaring.php index aad7ce97..291aa270 100644 --- a/plugins/libcalendaring/libcalendaring.php +++ b/plugins/libcalendaring/libcalendaring.php @@ -1478,7 +1478,7 @@ class libcalendaring extends rcube_plugin // is not overriden by NEEDS-ACTION if it was already set // which could happen if you work with shared events 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) { if ($attendee['email'] == $_attendee['email']) { $new['attendees'][$i]['status'] = $_attendee['status']; diff --git a/plugins/libkolab/lib/kolab_format_event.php b/plugins/libkolab/lib/kolab_format_event.php index 5b74ed91..496a877b 100644 --- a/plugins/libkolab/lib/kolab_format_event.php +++ b/plugins/libkolab/lib/kolab_format_event.php @@ -60,8 +60,8 @@ class kolab_format_event extends kolab_format_xcal parent::set($object); // do the hard work of setting object values - $this->obj->setStart(self::get_datetime($object['start'], null, $object['allday'])); - $this->obj->setEnd(self::get_datetime($object['end'], null, $object['allday'])); + $this->obj->setStart(self::get_datetime($object['start'], null, !empty($object['allday']))); + $this->obj->setEnd(self::get_datetime($object['end'], null, !empty($object['allday']))); $this->obj->setTransparency($object['free_busy'] == 'free'); $status = kolabformat::StatusUndefined; @@ -97,7 +97,8 @@ class kolab_format_event extends kolab_format_xcal $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); @@ -272,7 +273,7 @@ class kolab_format_event extends kolab_format_xcal $tags = parent::get_tags($obj); $object = $obj ?: $this->data; - foreach ((array)$object['categories'] as $cat) { + foreach ((array) ($object['categories'] ?? []) as $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 if (!isset($exception['allday'])) { - $exception['allday'] = $master['allday']; + $exception['allday'] = !empty($master['allday']); } return $exception; diff --git a/plugins/libkolab/lib/kolab_format_xcal.php b/plugins/libkolab/lib/kolab_format_xcal.php index e4417199..5e57d91d 100644 --- a/plugins/libkolab/lib/kolab_format_xcal.php +++ b/plugins/libkolab/lib/kolab_format_xcal.php @@ -348,7 +348,7 @@ abstract class kolab_format_xcal extends kolab_format $this->obj->setSummary($object['title']); $this->obj->setLocation($object['location'] ?? null); $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->setUrl(strval($object['url'] ?? null)); @@ -359,10 +359,13 @@ abstract class kolab_format_xcal extends kolab_format // process event attendees $attendees = new vectorattendee; foreach ((array)($object['attendees'] ?? []) as $i => $attendee) { - if ($attendee['role'] == 'ORGANIZER') { + if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') { $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->setName($attendee['name']); @@ -371,12 +374,16 @@ abstract class kolab_format_xcal extends kolab_format $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->setContact($cr); - $att->setPartStat($this->part_status_map[$attendee['status']]); - $att->setRole($this->role_map[$attendee['role']] ?: kolabformat::Required); - $att->setCutype($this->cutype_map[$attendee['cutype']] ?: kolabformat::CutypeIndividual); - $att->setRSVP((bool)$attendee['rsvp']); + $att->setPartStat($partstat); + $att->setRole($role ?: kolabformat::Required); + $att->setCutype($cutype ?: kolabformat::CutypeIndividual); + $att->setRSVP(!empty($attendee['rsvp'])); if (!empty($attendee['delegated-from'])) { $vdelegators = new vectorcontactref; @@ -407,9 +414,9 @@ abstract class kolab_format_xcal extends kolab_format } $this->obj->setAttendees($attendees); - if ($object['organizer']) { - $organizer = new ContactReference(ContactReference::EmailReference, $object['organizer']['email']); - $organizer->setName($object['organizer']['name']); + if (!empty($object['organizer'])) { + $organizer = new ContactReference(ContactReference::EmailReference, $object['organizer']['email'] ?? null); + $organizer->setName($object['organizer']['name'] ?? ''); $this->obj->setOrganizer($organizer); } @@ -529,8 +536,8 @@ abstract class kolab_format_xcal extends kolab_format $recipients->push(new ContactReference(ContactReference::EmailReference, $email)); } $alarm = new Alarm( - strval($valarm['summary'] ?: $object['title']), - strval($valarm['description'] ?: $object['description']), + strval(!empty($valarm['summary']) ? $valarm['summary'] : $object['title']), + strval(!empty($valarm['description']) ? $valarm['description'] : $object['description']), $recipients ); } @@ -566,15 +573,15 @@ abstract class kolab_format_xcal extends kolab_format continue; } - $related = strtoupper($valarm['related']) == 'END' ? kolabformat::End : kolabformat::Start; + $related = strtoupper($valarm['related'] ?? '') == 'END' ? kolabformat::End : kolabformat::Start; $alarm->setRelativeStart($duration, $related); } - if ($valarm['duration']) { + if (!empty($valarm['duration'])) { try { $d = new DateInterval($valarm['duration']); $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) { // ignore diff --git a/plugins/libkolab/lib/kolab_ldap.php b/plugins/libkolab/lib/kolab_ldap.php index 46085b86..dcad03aa 100644 --- a/plugins/libkolab/lib/kolab_ldap.php +++ b/plugins/libkolab/lib/kolab_ldap.php @@ -510,7 +510,7 @@ class kolab_ldap extends rcube_ldap_generic // if not set it means we use this LDAP object for other // purposes, e.g. kolab_delegation, then username with // correct domain is in a session - if (!$user) { + if (!$user && !empty($_SESSION['username'])) { $user = $_SESSION['username']; } @@ -533,7 +533,7 @@ class kolab_ldap extends rcube_ldap_generic } // realmed username (with domain) - if (strpos($user, '@')) { + if ($user && strpos($user, '@')) { list($usr, $dom) = explode('@', $user); // unrealm domain, user login can contain a domain alias diff --git a/plugins/libkolab/lib/kolab_storage_config.php b/plugins/libkolab/lib/kolab_storage_config.php index 9168c2c2..dcc2d138 100644 --- a/plugins/libkolab/lib/kolab_storage_config.php +++ b/plugins/libkolab/lib/kolab_storage_config.php @@ -778,10 +778,10 @@ class kolab_storage_config } 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; } - else if ($search_msg) { + else if (!empty($search_msg)) { foreach ($tag['members'] as $m) { if (strpos($m, $search_msg) !== false) { $result[] = $tag; diff --git a/plugins/libkolab/libkolab.php b/plugins/libkolab/libkolab.php index e770586c..3c0c3864 100644 --- a/plugins/libkolab/libkolab.php +++ b/plugins/libkolab/libkolab.php @@ -358,7 +358,7 @@ class libkolab extends rcube_plugin */ public static function recurrence_id_format($event) { - return $event['allday'] ? 'Ymd' : 'Ymd\THis'; + return !empty($event['allday']) ? 'Ymd' : 'Ymd\THis'; } /**