Fix PHP8 warnings

This commit is contained in:
Aleksander Machniak 2023-06-06 14:52:01 +02:00
parent 2b29e447ba
commit 609336d71f
14 changed files with 79 additions and 58 deletions

View file

@ -812,7 +812,7 @@ class kolab_calendar extends kolab_storage_folder_api
// Modify invitation status class name, when invitation calendars are disabled // Modify invitation status class name, when invitation calendars are disabled
// we'll use opacity only for declined/needs-action events // we'll use opacity only for declined/needs-action events
$record['className'] = str_replace('-invitation', '', $record['className']); $record['className'] = str_replace('-invitation', '', $record['className'] ?? '');
} }
// add instance identifier to first occurrence (master event) // add instance identifier to first occurrence (master event)

View file

@ -778,6 +778,7 @@ class kolab_contacts extends rcube_addressbook
} }
else { else {
// remove from distribution lists // remove from distribution lists
if (!empty($this->groupmembers[$id])) {
foreach ((array) $this->groupmembers[$id] as $gid) { foreach ((array) $this->groupmembers[$id] as $gid) {
if (!$is_mailto || $gid == $this->gid) { if (!$is_mailto || $gid == $this->gid) {
$this->remove_from_group($gid, $id); $this->remove_from_group($gid, $id);
@ -786,6 +787,8 @@ class kolab_contacts extends rcube_addressbook
// clear internal cache // clear internal cache
unset($this->groupmembers[$id]); unset($this->groupmembers[$id]);
}
$count++; $count++;
} }
} }
@ -1398,7 +1401,7 @@ class kolab_contacts extends rcube_addressbook
'birthday' => '', 'birthday' => '',
'anniversary' => '', 'anniversary' => '',
'freebusyurl' => '', 'freebusyurl' => '',
'photo' => $contact['photo'] 'photo' => $contact['photo'] ?? null
); );
} }
} }

View file

@ -473,7 +473,7 @@ class kolab_delegation extends rcube_plugin
$delegate = $engine->delegate_get($id); $delegate = $engine->delegate_get($id);
} }
if ($delegate) { if (!empty($delegate)) {
$input = new html_hiddenfield(array('name' => $field_id, 'id' => $field_id, 'size' => 40)); $input = new html_hiddenfield(array('name' => $field_id, 'id' => $field_id, 'size' => 40));
$input = rcube::Q($delegate['name']) . $input->show($id); $input = rcube::Q($delegate['name']) . $input->show($id);
@ -511,7 +511,7 @@ class kolab_delegation extends rcube_plugin
$delegate = $engine->delegate_get($id); $delegate = $engine->delegate_get($id);
} }
$folder_data = $engine->list_folders($delegate['uid']); $folder_data = $engine->list_folders(!empty($delegate) ? $delegate['uid'] : null);
$use_fieldsets = rcube_utils::get_boolean($attrib['use-fieldsets']); $use_fieldsets = rcube_utils::get_boolean($attrib['use-fieldsets']);
$rights = array(); $rights = array();
$folder_groups = array(); $folder_groups = array();
@ -521,6 +521,8 @@ class kolab_delegation extends rcube_plugin
$rights[$folder_name] = $folder['rights']; $rights[$folder_name] = $folder['rights'];
} }
$html = '';
// build block for every folder type // build block for every folder type
foreach ($folder_groups as $type => $group) { foreach ($folder_groups as $type => $group) {
if (empty($group)) { if (empty($group)) {
@ -550,8 +552,8 @@ class kolab_delegation extends rcube_plugin
private function delegate_folders_block($a_folders, $attrib, $rights) private function delegate_folders_block($a_folders, $attrib, $rights)
{ {
$path = 'plugins/kolab_delegation/' . $this->skin_path . '/'; $path = 'plugins/kolab_delegation/' . $this->skin_path . '/';
$read_ico = $attrib['readicon'] ? html::img(array('src' => $path . $attrib['readicon'], 'title' => $this->gettext('read'))) : ''; $read_ico = !empty($attrib['readicon']) ? html::img(array('src' => $path . $attrib['readicon'], 'title' => $this->gettext('read'))) : '';
$write_ico = $attrib['writeicon'] ? html::img(array('src' => $path . $attrib['writeicon'], 'title' => $this->gettext('write'))) : ''; $write_ico = !empty($attrib['writeicon']) ? html::img(array('src' => $path . $attrib['writeicon'], 'title' => $this->gettext('write'))) : '';
$table = new html_table(array('cellspacing' => 0, 'class' => 'table-striped')); $table = new html_table(array('cellspacing' => 0, 'class' => 'table-striped'));
$table->add_header(array('class' => 'read checkbox-cell', 'title' => $this->gettext('read'), 'tabindex' => 0), $read_ico); $table->add_header(array('class' => 'read checkbox-cell', 'title' => $this->gettext('read'), 'tabindex' => 0), $read_ico);

View file

@ -38,6 +38,7 @@ class kolab_delegation_engine
private $ldap_dn; private $ldap_dn;
private $cache = array(); private $cache = array();
private $folder_types = array('mail', 'event', 'task'); private $folder_types = array('mail', 'event', 'task');
private $supported;
const ACL_READ = 1; const ACL_READ = 1;
const ACL_WRITE = 2; const ACL_WRITE = 2;
@ -378,7 +379,7 @@ class kolab_delegation_engine
// Definition of read and write ACL // Definition of read and write ACL
$right_types = $this->right_types(); $right_types = $this->right_types();
$delegate_lc = strtolower($delegate); $delegate_lc = strtolower((string) $delegate);
foreach ($folders as $folder) { foreach ($folders as $folder) {
// get only folders in personal namespace // get only folders in personal namespace
@ -387,8 +388,8 @@ class kolab_delegation_engine
} }
$rights = null; $rights = null;
$type = $metadata[$folder] ?: 'mail'; $type = !empty($metadata[$folder]) ? $metadata[$folder] : 'mail';
list($class, $subclass) = explode('.', $type); list($class, $subclass) = strpos($type, '.') ? explode('.', $type) : [$type, ''];
if (!in_array($class, $this->folder_types)) { if (!in_array($class, $this->folder_types)) {
continue; continue;
@ -398,7 +399,7 @@ class kolab_delegation_engine
if ($delegate) { if ($delegate) {
// @TODO: cache ACL // @TODO: cache ACL
$imap_acl = $storage->get_acl($folder); $imap_acl = $storage->get_acl($folder);
if (!empty($imap_acl) && (($acl = $imap_acl[$delegate]) || ($acl = $imap_acl[$delegate_lc]))) { if (!empty($imap_acl) && (($acl = ($imap_acl[$delegate] ?? null)) || ($acl = ($imap_acl[$delegate_lc] ?? null)))) {
if ($this->acl_compare($acl, $right_types[self::ACL_WRITE])) { if ($this->acl_compare($acl, $right_types[self::ACL_WRITE])) {
$rights = self::ACL_WRITE; $rights = self::ACL_WRITE;
} }

View file

@ -532,7 +532,7 @@ class kolab_folders extends rcube_plugin
/** /**
* Checks if IMAP server supports any of METADATA, ANNOTATEMORE, ANNOTATEMORE2 * Checks if IMAP server supports any of METADATA, ANNOTATEMORE, ANNOTATEMORE2
* *
* @return boolean * @return bool
*/ */
function metadata_support() function metadata_support()
{ {
@ -552,7 +552,13 @@ class kolab_folders extends rcube_plugin
*/ */
function get_folder_type($folder) function get_folder_type($folder)
{ {
return explode('.', (string)kolab_storage::folder_type($folder)); $type = explode('.', (string)kolab_storage::folder_type($folder));
if (!isset($type[1])) {
$type[1] = null;
}
return $type;
} }
/** /**
@ -561,7 +567,7 @@ class kolab_folders extends rcube_plugin
* @param string $folder Folder name * @param string $folder Folder name
* @param string $type Content type * @param string $type Content type
* *
* @return boolean True on success * @return bool True on success
*/ */
function set_folder_type($folder, $type = 'mail') function set_folder_type($folder, $type = 'mail')
{ {

View file

@ -484,10 +484,9 @@ class kolab_notes extends rcube_plugin
// post-filter search results // post-filter search results
if (strlen($search)) { if (strlen($search)) {
$matches = 0; $matches = 0;
$contents = mb_strtolower( $desc = $this->is_html($record) ? strip_tags($record['description']) : ($record['description'] ?? '');
$record['title'] . $contents = mb_strtolower($record['title'] . $desc);
($this->is_html($record) ? strip_tags($record['description']) : $record['description'])
);
foreach ($words as $word) { foreach ($words as $word) {
if (mb_strpos($contents, $word) !== false) { if (mb_strpos($contents, $word) !== false) {
$matches++; $matches++;
@ -615,7 +614,7 @@ class kolab_notes extends rcube_plugin
$action = rcube_utils::get_input_value('_do', rcube_utils::INPUT_POST); $action = rcube_utils::get_input_value('_do', rcube_utils::INPUT_POST);
$note = rcube_utils::get_input_value('_data', rcube_utils::INPUT_POST, true); $note = rcube_utils::get_input_value('_data', rcube_utils::INPUT_POST, true);
$success = $silent = false; $success = $silent = $refresh = false;
switch ($action) { switch ($action) {
case 'new': case 'new':
case 'edit': case 'edit':
@ -1266,7 +1265,9 @@ class kolab_notes extends rcube_plugin
private function is_html($note) private function is_html($note)
{ {
// check for opening and closing <html> or <body> tags // check for opening and closing <html> or <body> tags
return (preg_match('/<(html|body)(\s+[a-z]|>)/', $note['description'], $m) && strpos($note['description'], '</'.$m[1].'>') > 0); return !empty($note['description'])
&& preg_match('/<(html|body)(\s+[a-z]|>)/', $note['description'], $m)
&& strpos($note['description'], '</' . $m[1] . '>') > 0;
} }
/** /**

View file

@ -445,7 +445,7 @@ class kolab_tags_engine
$class = 'rcube_result_' . ($args['threading'] ? 'thread' : 'index'); $class = 'rcube_result_' . ($args['threading'] ? 'thread' : 'index');
$result = $args['threading'] ? '* THREAD' : '* SORT'; $result = $args['threading'] ? '* THREAD' : '* SORT';
$args['result'] = new $class($folder, $result); $args['result'] = new $class($args['folder'] ?? 'INBOX', $result);
} }
} }

View file

@ -65,7 +65,7 @@ class kolab_format_configuration extends kolab_format
case 'file_driver': case 'file_driver':
$driver = new FileDriver($object['driver'], $object['title']); $driver = new FileDriver($object['driver'], $object['title']);
$driver->setEnabled((bool) $object['enabled']); $driver->setEnabled(!empty($object['enabled']));
foreach ($this->driver_settings_fields as $field) { foreach ($this->driver_settings_fields as $field) {
$value = $object[$field]; $value = $object[$field];
@ -78,7 +78,7 @@ class kolab_format_configuration extends kolab_format
break; break;
case 'relation': case 'relation':
$relation = new Relation(strval($object['name']), strval($object['category'])); $relation = new Relation(strval($object['name'] ?? ''), strval($object['category'] ?? ''));
if (!empty($object['color'])) { if (!empty($object['color'])) {
$relation->setColor($object['color']); $relation->setColor($object['color']);

View file

@ -60,8 +60,9 @@ class kolab_format_distributionlist extends kolab_format
continue; continue;
} }
if (!$seen[$key]++) { if (empty($seen[$key])) {
$members->push($m); $members->push($m);
$seen[$key] = true;
} }
else { else {
// remove dupes for caching // remove dupes for caching

View file

@ -239,13 +239,13 @@ class kolab_format_event extends kolab_format_xcal
$recurrence_id_format = libkolab::recurrence_id_format($object); $recurrence_id_format = libkolab::recurrence_id_format($object);
$instance_id = $recurrence_id instanceof DateTimeInterface ? $recurrence_id->format($recurrence_id_format) : strval($recurrence_id); $instance_id = $recurrence_id instanceof DateTimeInterface ? $recurrence_id->format($recurrence_id_format) : strval($recurrence_id);
if ($object['recurrence_date'] instanceof DateTimeInterface) { if (!empty($object['recurrence_date']) && $object['recurrence_date'] instanceof DateTimeInterface) {
if ($object['recurrence_date']->format($recurrence_id_format) == $instance_id) { if ($object['recurrence_date']->format($recurrence_id_format) == $instance_id) {
$result = $object; $result = $object;
} }
} }
if (!$result && is_array($object['exceptions'])) { if (!$result && !empty($object['exceptions']) && is_array($object['exceptions'])) {
foreach ($object['exceptions'] as $exception) { foreach ($object['exceptions'] as $exception) {
if ($exception['_instance'] == $instance_id) { if ($exception['_instance'] == $instance_id) {
$result = $exception; $result = $exception;

View file

@ -423,14 +423,14 @@ abstract class kolab_format_xcal extends kolab_format
if (!empty($object['recurrence']['FREQ'])) { if (!empty($object['recurrence']['FREQ'])) {
$freq = $object['recurrence']['FREQ']; $freq = $object['recurrence']['FREQ'];
$bysetpos = explode(',', $object['recurrence']['BYSETPOS']); $bysetpos = isset($object['recurrence']['BYSETPOS']) ? explode(',', $object['recurrence']['BYSETPOS']) : [];
$rr->setFrequency($this->rrule_type_map[$freq]); $rr->setFrequency($this->rrule_type_map[$freq]);
if ($object['recurrence']['INTERVAL']) if ($object['recurrence']['INTERVAL'])
$rr->setInterval(intval($object['recurrence']['INTERVAL'])); $rr->setInterval(intval($object['recurrence']['INTERVAL']));
if ($object['recurrence']['BYDAY']) { if (!empty($object['recurrence']['BYDAY'])) {
$byday = new vectordaypos; $byday = new vectordaypos;
foreach (explode(',', $object['recurrence']['BYDAY']) as $day) { foreach (explode(',', $object['recurrence']['BYDAY']) as $day) {
$occurrence = 0; $occurrence = 0;
@ -455,32 +455,38 @@ abstract class kolab_format_xcal extends kolab_format
$rr->setByday($byday); $rr->setByday($byday);
} }
if ($object['recurrence']['BYMONTHDAY']) { if (!empty($object['recurrence']['BYMONTHDAY'])) {
$bymday = new vectori; $bymday = new vectori;
foreach (explode(',', $object['recurrence']['BYMONTHDAY']) as $day) foreach (explode(',', $object['recurrence']['BYMONTHDAY']) as $day) {
$bymday->push(intval($day)); $bymday->push(intval($day));
}
$rr->setBymonthday($bymday); $rr->setBymonthday($bymday);
} }
if ($object['recurrence']['BYMONTH']) { if (!empty($object['recurrence']['BYMONTH'])) {
$bymonth = new vectori; $bymonth = new vectori;
foreach (explode(',', $object['recurrence']['BYMONTH']) as $month) foreach (explode(',', $object['recurrence']['BYMONTH']) as $month)
$bymonth->push(intval($month)); $bymonth->push(intval($month));
$rr->setBymonth($bymonth); $rr->setBymonth($bymonth);
} }
if ($object['recurrence']['COUNT']) if (!empty($object['recurrence']['COUNT'])) {
$rr->setCount(intval($object['recurrence']['COUNT'])); $rr->setCount(intval($object['recurrence']['COUNT']));
else if ($object['recurrence']['UNTIL']) }
else if (!empty($object['recurrence']['UNTIL'])) {
$rr->setEnd(self::get_datetime($object['recurrence']['UNTIL'], null, true, $start_tz)); $rr->setEnd(self::get_datetime($object['recurrence']['UNTIL'], null, true, $start_tz));
}
if ($rr->isValid()) { if ($rr->isValid()) {
// add exception dates (only if recurrence rule is valid) // add exception dates (only if recurrence rule is valid)
if (!empty($object['recurrence']['EXDATE'])) {
$exdates = new vectordatetime; $exdates = new vectordatetime;
foreach ((array)$object['recurrence']['EXDATE'] as $exdate) foreach ((array)$object['recurrence']['EXDATE'] as $exdate) {
$exdates->push(self::get_datetime($exdate, null, true, $start_tz)); $exdates->push(self::get_datetime($exdate, null, true, $start_tz));
}
$this->obj->setExceptionDates($exdates); $this->obj->setExceptionDates($exdates);
} }
}
else { else {
rcube::raise_error(array( rcube::raise_error(array(
'code' => 600, 'type' => 'php', 'code' => 600, 'type' => 'php',
@ -495,8 +501,9 @@ abstract class kolab_format_xcal extends kolab_format
// save recurrence dates (aka RDATE) // save recurrence dates (aka RDATE)
if (!empty($object['recurrence']['RDATE'])) { if (!empty($object['recurrence']['RDATE'])) {
$rdates = new vectordatetime; $rdates = new vectordatetime;
foreach ((array)$object['recurrence']['RDATE'] as $rdate) foreach ((array)$object['recurrence']['RDATE'] as $rdate) {
$rdates->push(self::get_datetime($rdate, null, true, $start_tz)); $rdates->push(self::get_datetime($rdate, null, true, $start_tz));
}
$this->obj->setRecurrenceDates($rdates); $this->obj->setRecurrenceDates($rdates);
} }

View file

@ -1273,7 +1273,7 @@ class kolab_storage
if (self::folder_is_subscribed($folder)) { if (self::folder_is_subscribed($folder)) {
return true; return true;
} }
else if (!is_array($_SESSION['kolab_subscribed_folders']) || !in_array($folder, $_SESSION['kolab_subscribed_folders'])) { else if (empty($_SESSION['kolab_subscribed_folders']) || !in_array($folder, $_SESSION['kolab_subscribed_folders'])) {
$_SESSION['kolab_subscribed_folders'][] = $folder; $_SESSION['kolab_subscribed_folders'][] = $folder;
return true; return true;
} }
@ -1300,7 +1300,7 @@ class kolab_storage
// temporary/session subscription // temporary/session subscription
if ($temp) { if ($temp) {
if (is_array($_SESSION['kolab_subscribed_folders']) && ($i = array_search($folder, $_SESSION['kolab_subscribed_folders'])) !== false) { if (!empty($_SESSION['kolab_subscribed_folders']) && ($i = array_search($folder, $_SESSION['kolab_subscribed_folders'])) !== false) {
unset($_SESSION['kolab_subscribed_folders'][$i]); unset($_SESSION['kolab_subscribed_folders'][$i]);
} }
return true; return true;
@ -1622,7 +1622,7 @@ class kolab_storage
// truncate folder path to top-level folders of the 'other' namespace // truncate folder path to top-level folders of the 'other' namespace
$foldername = join($delimiter, array_slice($path, 0, $path_len + 1)); $foldername = join($delimiter, array_slice($path, 0, $path_len + 1));
if (!$folders[$foldername]) { if (empty($folders[$foldername])) {
$folders[$foldername] = new kolab_storage_folder_user($foldername, $other_ns); $folders[$foldername] = new kolab_storage_folder_user($foldername, $other_ns);
} }
} }
@ -1630,8 +1630,8 @@ class kolab_storage
// for every (subscribed) user folder, list all (unsubscribed) subfolders // for every (subscribed) user folder, list all (unsubscribed) subfolders
foreach ($folders as $userfolder) { foreach ($folders as $userfolder) {
foreach ((array) self::list_folders($userfolder->name . $delimiter, '*', $type, false, $folderdata) as $foldername) { foreach ((array) self::list_folders($userfolder->name . $delimiter, '*', $type, false, $folderdata) as $foldername) {
if (!$folders[$foldername]) { if (empty($folders[$foldername])) {
$folders[$foldername] = new kolab_storage_folder($foldername, $type, $folderdata[$foldername]); $folders[$foldername] = new kolab_storage_folder($foldername, $type, $folderdata[$foldername] ?? null);
$userfolder->children[] = $folders[$foldername]; $userfolder->children[] = $folders[$foldername];
} }
} }

View file

@ -609,7 +609,7 @@ class kolab_storage_folder extends kolab_storage_folder_api
// copy attachments from old message // copy attachments from old message
$copyfrom = $object['_copyfrom'] ?? ($object['_msguid'] ?? null); $copyfrom = $object['_copyfrom'] ?? ($object['_msguid'] ?? null);
if (!empty($copyfrom) && ($old = $this->cache->get($copyfrom, $type, $object['_mailbox']))) { if (!empty($copyfrom) && ($old = $this->cache->get($copyfrom, $type, $object['_mailbox'])) && !empty($old['_attachments'])) {
foreach ((array)$old['_attachments'] as $key => $att) { foreach ((array)$old['_attachments'] as $key => $att) {
if (!isset($object['_attachments'][$key])) { if (!isset($object['_attachments'][$key])) {
$object['_attachments'][$key] = $old['_attachments'][$key]; $object['_attachments'][$key] = $old['_attachments'][$key];
@ -1003,7 +1003,7 @@ class kolab_storage_folder extends kolab_storage_folder_api
foreach ((array)($object['_attachments'] ?? []) as $key => $att) { foreach ((array)($object['_attachments'] ?? []) as $key => $att) {
if (empty($att['content']) && !empty($att['id'])) { if (empty($att['content']) && !empty($att['id'])) {
// @TODO: use IMAP CATENATE to skip attachment fetch+push operation // @TODO: use IMAP CATENATE to skip attachment fetch+push operation
$msguid = $object['_copyfrom'] ?: ($object['_msguid'] ?: $object['uid']); $msguid = !empty($object['_copyfrom']) ? $object['_copyfrom'] : (!empty($object['_msguid']) ? $object['_msguid'] : $object['uid']);
if ($is_file) { if ($is_file) {
$att['path'] = tempnam($temp_dir, 'rcmAttmnt'); $att['path'] = tempnam($temp_dir, 'rcmAttmnt');
if (($fp = fopen($att['path'], 'w')) && $this->get_attachment($msguid, $att['id'], $object['_mailbox'], false, $fp, true)) { if (($fp = fopen($att['path'], 'w')) && $this->get_attachment($msguid, $att['id'], $object['_mailbox'], false, $fp, true)) {

View file

@ -335,15 +335,15 @@ class tasklist_kolab_driver extends tasklist_driver
$this->_read_lists(); $this->_read_lists();
// create list and folder instance if necesary // create list and folder instance if necesary
if (!$this->lists[$id]) { if (empty($this->lists[$id])) {
$folder = kolab_storage::get_folder(kolab_storage::id_decode($id)); $folder = kolab_storage::get_folder(kolab_storage::id_decode($id));
if ($folder->type) { if ($folder && $folder->type) {
$this->folders[$id] = $folder; $this->folders[$id] = $folder;
$this->lists[$id] = $this->folder_props($folder, $this->rc->config->get('kolab_tasklists', array())); $this->lists[$id] = $this->folder_props($folder, $this->rc->config->get('kolab_tasklists', array()));
} }
} }
return $this->folders[$id]; return $this->folders[$id] ?? null;
} }
@ -455,7 +455,7 @@ class tasklist_kolab_driver extends tasklist_driver
$ret |= $folder->activate(intval($prop['active'])); $ret |= $folder->activate(intval($prop['active']));
// apply to child folders, too // apply to child folders, too
if ($prop['recursive']) { if (!empty($prop['recursive'])) {
foreach ((array) kolab_storage::list_folders($folder->name, '*', 'task') as $subfolder) { foreach ((array) kolab_storage::list_folders($folder->name, '*', 'task') as $subfolder) {
if (isset($prop['permanent'])) if (isset($prop['permanent']))
($prop['permanent'] ? kolab_storage::folder_subscribe($subfolder) : kolab_storage::folder_unsubscribe($subfolder)); ($prop['permanent'] ? kolab_storage::folder_subscribe($subfolder) : kolab_storage::folder_unsubscribe($subfolder));
@ -640,13 +640,13 @@ class tasklist_kolab_driver extends tasklist_driver
// query Kolab storage // query Kolab storage
$query = array(); $query = array();
if ($filter['mask'] & tasklist::FILTER_MASK_COMPLETE) if (!empty($filter['mask']) && $filter['mask'] & tasklist::FILTER_MASK_COMPLETE)
$query[] = array('tags','~','x-complete'); $query[] = array('tags','~','x-complete');
else if (empty($filter['since'])) else if (empty($filter['since']))
$query[] = array('tags','!~','x-complete'); $query[] = array('tags','!~','x-complete');
// full text search (only works with cache enabled) // full text search (only works with cache enabled)
if ($filter['search']) { if (!empty($filter['search'])) {
$search = mb_strtolower($filter['search']); $search = mb_strtolower($filter['search']);
foreach (rcube_utils::normalize_string($search, true) as $word) { foreach (rcube_utils::normalize_string($search, true) as $word) {
$query[] = array('words', '~', $word); $query[] = array('words', '~', $word);