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'));
}
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();

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
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

View file

@ -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;
}

View file

@ -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];
}

View file

@ -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']);
}
}

View file

@ -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']);
}
}

View file

@ -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;
}
}

View file

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

View file

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

View file

@ -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;
}

View file

@ -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)) {

View file

@ -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'];

View file

@ -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;

View file

@ -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

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
// 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

View file

@ -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;

View file

@ -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';
}
/**