Skip to content

Commit

Permalink
Fix PHP 7.2 Warning: count(): Parameter must be an array or an object…
Browse files Browse the repository at this point in the history
… that implements Countable
  • Loading branch information
alecpl committed Dec 20, 2017
1 parent 1c10231 commit 9c542f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
@@ -1,7 +1,7 @@
CHANGELOG Roundcube Webmail
===========================

- Fix a couple of warnings on PHP 7.2
- Fix a couple of warnings on PHP 7.2 (#6098)
- Fix broken long filenames when using imap4d server - workaround server bug (#6048)
- Fix so temp_dir misconfiguration prints an error to the log (#6045)
- Fix untagged COPYUID responses handling - again (#5982)
Expand Down
41 changes: 29 additions & 12 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
Expand Up @@ -467,16 +467,15 @@ function actions()
// 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(
Expand Down Expand Up @@ -744,7 +743,7 @@ function save()
$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) {
Expand All @@ -761,7 +760,7 @@ function save()
}
}

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');
Expand Down Expand Up @@ -804,7 +803,7 @@ function save()
$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) {
Expand All @@ -821,7 +820,7 @@ function save()
}
}

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');
Expand Down Expand Up @@ -1432,7 +1431,7 @@ function filter_form($attrib)

// '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;
}
Expand Down Expand Up @@ -1530,8 +1529,17 @@ function filter_form($attrib)

function rule_div($fid, $id, $div=true)
{
$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,
Expand Down Expand Up @@ -1934,8 +1942,17 @@ private static function rule_test(&$rule)

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" : '';

Expand Down
6 changes: 3 additions & 3 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
Expand Up @@ -287,7 +287,7 @@ private function vacation_post()
}

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) {
Expand Down Expand Up @@ -378,7 +378,7 @@ public function vacation_form($attrib)
$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('', '');
Expand Down Expand Up @@ -887,7 +887,7 @@ public function set_vacation($data)
}

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;
Expand Down

0 comments on commit 9c542f9

Please sign in to comment.