Fix PHP 7.2 Warning: count(): Parameter must be an array or an object that implements Countable

pull/6068/head
Aleksander Machniak 7 years ago
parent 5a63e52380
commit 7c6bbd81b0

@ -477,16 +477,15 @@ class rcube_sieve_engine
// Initialize the form
$rules = rcube_utils::get_input_value('r', rcube_utils::INPUT_GET);
if (!empty($rules)) {
$i = 0;
$tests = array();
foreach ($rules as $rule) {
list($header, $value) = explode(':', $rule, 2);
$tests[$i] = array(
$tests[] = array(
'type' => 'contains',
'test' => 'header',
'arg1' => $header,
'arg2' => $value,
);
$i++;
}
$this->form = array(
@ -757,7 +756,7 @@ class rcube_sieve_engine
$this->form['tests'][$i]['arg'] = $target;
if ($type != 'exists') {
if (!count($target)) {
if (empty($target)) {
$this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
}
else if (strpos($type, 'count-') === 0) {
@ -774,7 +773,7 @@ class rcube_sieve_engine
}
}
if (!preg_match('/^(regex|matches|count-)/', $type) && count($target)) {
if (!preg_match('/^(regex|matches|count-)/', $type) && !empty($target)) {
foreach ($target as $arg) {
if (!$this->validate_date_part($datepart, $arg)) {
$this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat');
@ -817,7 +816,7 @@ class rcube_sieve_engine
$this->form['tests'][$i]['header'] = $dateheader;
if ($type != 'exists') {
if (!count($target)) {
if (empty($target)) {
$this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
}
else if (strpos($type, 'count-') === 0) {
@ -834,7 +833,7 @@ class rcube_sieve_engine
}
}
if (count($target) && !preg_match('/^(regex|matches|count-)/', $type)) {
if (!empty($target) && !preg_match('/^(regex|matches|count-)/', $type)) {
foreach ($target as $arg) {
if (!$this->validate_date_part($datepart, $arg)) {
$this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat');
@ -1452,7 +1451,7 @@ class rcube_sieve_engine
// 'any' flag
if ((!isset($this->form) && empty($scr['tests']) && !empty($scr))
|| (count($scr['tests']) == 1 && $scr['tests'][0]['test'] == 'true' && !$scr['tests'][0]['not'])
|| (is_array($scr['tests']) && count($scr['tests']) == 1 && $scr['tests'][0]['test'] == 'true' && !$scr['tests'][0]['not'])
) {
$any = true;
}
@ -1587,8 +1586,17 @@ class rcube_sieve_engine
function rule_div($fid, $id, $div = true, $compact = false)
{
$rule = isset($this->form) ? $this->form['tests'][$id] : $this->script[$fid]['tests'][$id];
$rows_num = isset($this->form) ? count($this->form['tests']) : count($this->script[$fid]['tests']);
$rule = isset($this->form) ? $this->form['tests'][$id] : $this->script[$fid]['tests'][$id];
if (isset($this->form['tests'])) {
$rows_num = count($this->form['tests']);
}
else if (isset($this->script[$fid]['tests'])) {
$rows_num = count($this->script[$fid]['tests']);
}
else {
$rows_num = 0;
}
// headers select
$select_header = new html_select(array('name' => "_header[]", 'id' => 'header'.$id,
@ -2003,8 +2011,17 @@ class rcube_sieve_engine
function action_div($fid, $id, $div=true)
{
$action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id];
$rows_num = isset($this->form) ? count($this->form['actions']) : count($this->script[$fid]['actions']);
$action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id];
if (isset($this->form['actions'])) {
$rows_num = count($this->form['actions']);
}
else if (isset($this->script[$fid]['actions'])) {
$rows_num = count($this->script[$fid]['actions']);
}
else {
$rows_num = 0;
}
$out = $div ? '<div class="actionrow" id="actionrow' .$id .'">'."\n" : '';

@ -220,7 +220,7 @@ class rcube_sieve_forward extends rcube_sieve_engine
}
if (empty($forward_tests)) {
$forward_tests = $this->rc->config->get('managesieve_forward_test', array(array('test' => 'true')));
$forward_tests = (array) $this->rc->config->get('managesieve_forward_test', array(array('test' => 'true')));
}
if (!$error) {
@ -468,7 +468,7 @@ class rcube_sieve_forward extends rcube_sieve_engine
}
if (empty($forward_tests)) {
$forward_tests = $this->rc->config->get('managesieve_forward_test', array(array('test' => 'true')));
$forward_tests = (array) $this->rc->config->get('managesieve_forward_test', array(array('test' => 'true')));
}
$rule = $this->forward;

@ -287,7 +287,7 @@ class rcube_sieve_vacation extends rcube_sieve_engine
}
if (empty($vacation_tests)) {
$vacation_tests = $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
$vacation_tests = (array) $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
}
if (!$error) {
@ -378,7 +378,7 @@ class rcube_sieve_vacation extends rcube_sieve_engine
$action->add($this->plugin->gettext('vacation.copy'), 'copy');
}
if ($this->rc->config->get('managesieve_vacation') != 2 && count($this->vacation['list'])) {
if ($this->rc->config->get('managesieve_vacation') != 2 && !empty($this->vacation['list'])) {
$after = new html_select(array('name' => 'vacation_after', 'id' => 'vacation_after'));
$after->add('', '');
@ -886,7 +886,7 @@ class rcube_sieve_vacation extends rcube_sieve_engine
}
if (empty($vacation_tests)) {
$vacation_tests = $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
$vacation_tests = (array) $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
}
$rule = $this->vacation;

Loading…
Cancel
Save