Skip to content

Commit 75cc25c

Browse files
Emilian Grecudonici
authored andcommitted
Fix count() issues with PHP7.2 (#104)
1 parent 15c9d33 commit 75cc25c

24 files changed

Lines changed: 3822 additions & 3809 deletions

File tree

application/controllers/AdminController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function brandingAction()
236236
$values = $this->_request->getPost(); // Technically we should use *this*
237237
if ($form->isValid($_POST)) {
238238
$uploadedData = $form->getValues();
239-
239+
240240
if (empty($uploadedData['brandicon'])) {
241241
$values['brandicon'] = trim($this->_branding->getBrandIcon());
242242
$this->_flashMessenger->addMessage(
@@ -298,7 +298,7 @@ public function listresellersAction()
298298
}
299299
$resellers = $this->_panel->getResellers();
300300

301-
if ((!isset($resellers)) || (empty($resellers)) || (count($resellers) == 0)) {
301+
if ((!isset($resellers)) || (empty($resellers)) || (is_array($resellers) && count($resellers) === 0)) {
302302
$this->_flashMessenger->addMessage(
303303
array('message' => $this->t->_('Unable to retrieve resellers.'), 'status' => 'error')
304304
);

application/controllers/ResellerController.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ResellerController extends Zend_Controller_Action
5959
* @var SpamFilter_PanelSupport_Cpanel
6060
*/
6161
protected $_panel;
62-
62+
6363
public function init()
6464
{
6565
try {
@@ -135,19 +135,19 @@ public function listdomainsAction()
135135
$config = Zend_Registry::get('general_config');
136136
$this->view->isConfigured = (!empty($config->apiuser)) ? true : false;
137137
if(!$this->view->isConfigured) { return false; }
138-
138+
139139
// Items Per Page functionality
140140
$itemsPerPage = $this->_getParam('items')? (int)htmlspecialchars($this->_getParam('items')) : 25 ;
141141
if($itemsPerPage<1 || $itemsPerPage > 25){
142142
$this->view->itemsPerPageLimit = $this->t->_('The items per page parameter should be an integer greater than or equal to 1 and less than or equal to 25');
143143
$itemsPerPage = 25;
144144
}
145-
145+
146146
// Get params
147147
$filter = htmlspecialchars($this->_getParam('search'));
148148
$order = $this->_getParam('sortorder');
149149
$oldorder = SpamFilter_Panel_Cache::get( 'domains_sort_order' );
150-
150+
151151
// Get domain from cache if not root
152152
if(SpamFilter_Core::getUsername() != 'root'){
153153
$domains = SpamFilter_Panel_Cache::get(SpamFilter_Core::getDomainsCacheId());
@@ -162,8 +162,8 @@ public function listdomainsAction()
162162
if ($order != $oldorder) {
163163
$domains = $this->_panel->getSortedDomains(array ('domains' => $domains, 'order' => $order));
164164
SpamFilter_Panel_Cache::set(SpamFilter_Core::getDomainsCacheId(), $domains);
165-
}
166-
165+
}
166+
167167
// No cache set, proceed with retrieval
168168
if (empty($domains)) {
169169
$domains = $this->_panel->getDomains(
@@ -177,7 +177,7 @@ public function listdomainsAction()
177177
// Cache miss, save the data
178178
SpamFilter_Panel_Cache::set(SpamFilter_Core::getDomainsCacheId(), $domains);
179179
}
180-
180+
181181
// Proceed
182182
if ( !isset($domains))
183183
{
@@ -190,7 +190,7 @@ public function listdomainsAction()
190190
return false;
191191
}
192192

193-
if ((empty($domains)) || (count($domains) == 0) )
193+
if ((empty($domains)) || (is_countable($domains) && count($domains) === 0) )
194194
{
195195
$this->_flashMessenger->addMessage(
196196
array(
@@ -200,11 +200,11 @@ public function listdomainsAction()
200200
);
201201
return false;
202202
}
203-
203+
204204
if(!empty($filter)){
205205
$domains = $this->_panel->filterDomains(array('domains' => $domains, 'filter' => $filter));
206206
}
207-
if ((empty($domains)) || (count($domains) == 0) )
207+
if ((empty($domains)) || (is_countable($domains) && count($domains) == 0) )
208208
{
209209
$this->_flashMessenger->addMessage(
210210
array(
@@ -257,7 +257,7 @@ public function listaccountsAction()
257257
}
258258

259259
// Proceed
260-
if( (!isset($accounts)) || (empty($accounts)) || (count($accounts) == 0) )
260+
if( (!isset($accounts)) || (empty($accounts)) || (is_countable($accounts) && count($accounts) == 0) )
261261
{
262262
$this->_flashMessenger->addMessage(
263263
array(

application/views/helpers/FlashMessages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function flashMessages($translator = NULL)
4848
$output = '';
4949

5050
// If there are no messages, don't bother with this whole process.
51-
if (count($messages) > 0)
51+
if (is_array($messages) && count($messages) > 0)
5252
{
5353
// This chunk of code takes the messages (formatted as in the above sample
5454
// input) and puts them into an array of the form:

application/views/helpers/Table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function setColumns(array $columns)
112112

113113
/**
114114
* Set table summary
115-
*
115+
*
116116
* @param string $summary
117117
* @return App_View_Helper_Table
118118
*/
@@ -172,7 +172,7 @@ public function addRow($cols)
172172
*/
173173
public function setRows($rows)
174174
{
175-
if (count($rows)) {
175+
if (is_countable($rows) && count($rows)) {
176176
foreach ($rows as $r) {
177177
$this->addRow($r);
178178
}
@@ -279,7 +279,7 @@ public function toString()
279279
elseif (isset($r[$i])) {
280280
$xhtml .= stripslashes($r[$i]);
281281
}
282-
282+
283283

284284
$xhtml .= '</td>';
285285
$i++;

application/views/scripts/admin/listresellers.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</thead>
1212
<tbody>
1313
<?php
14-
if (count($this->paginator) == 0) {
14+
if ($this->paginator->count() == 0) {
1515
echo '<tr><td colspan="2">' . $this->t->_('There are no resellers in the system.') . '</td></tr>';
1616
}
1717

application/views/scripts/domain/index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if (!$this->hasAPIAccess) {
4343
</thead>
4444
<tbody>
4545
<?php
46-
if (count($this->paginator) == 0) {
46+
if ($this->paginator->count() === 0) {
4747
echo '<tr><td colspan="3">' . $this->t->_('There are no domains assigned to your account') . '</td></tr>';
4848
}
4949

application/views/scripts/reseller/listaccounts.phtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ if( !$this->isConfigured )
1616
<th><?php echo $this->t->_('Username'); ?></th>
1717
<th><?php echo $this->t->_('Primary domain'); ?></th>
1818
<th></th>
19-
</tr>
19+
</tr>
2020
</thead>
2121
<tbody>
22-
<?php
23-
if( count($this->paginator) == 0 )
22+
<?php
23+
if( $this->paginator->count() === 0 )
2424
{
2525
echo '<tr><td colspan="3">' . $this->t->_('There are no users assigned to your account') . '</td></tr>';
2626
}
2727

28-
foreach( $this->paginator as $u )
28+
foreach( $this->paginator as $u )
2929
{
3030
?>
3131
<tr>
3232
<td><?php echo $u['user']; ?></td>
3333
<td><?php echo $u['domain']; ?></td>
3434
<td><a href="?q=reseller/toggleuser/user/<?php echo $u['user']; ?>/state/enable"><?php echo $this->t->_('Enable Protection'); ?></a> | <a href="?q=reseller/toggleuser/user/<?php echo $u['user']; ?>/state/disable"><?php echo $this->t->_('Disable Protection'); ?></a></td>
3535
</tr>
36-
<?php
36+
<?php
3737
}
3838
?>
3939
</tbody>

application/views/scripts/reseller/listdomains.phtml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ if( !$this->isConfigured )
4343
parentDocumentTitle = window.top.document.title;
4444
if (parentDocumentTitle.indexOf(brandname) == -1) {
4545
window.top.document.title = parentDocumentTitle + ' - ' + brandname;
46-
}
46+
}
4747
} catch(e) {
48-
48+
4949
}
5050
});
5151
</script>
@@ -82,7 +82,7 @@ if( !$this->isConfigured )
8282
</thead>
8383
<tbody>
8484
<?php
85-
if( count($this->paginator) == 0 )
85+
if( $this->paginator->count() === 0 )
8686
{
8787
echo '<tr><td colspan="5">'. $this->t->_('No content to display') . '</td></tr>';
8888
}
@@ -246,11 +246,11 @@ if( !$this->isConfigured )
246246
window.location = goTo;
247247
return false;
248248
});
249-
249+
250250
$("#changeItems").click(function(event){
251251
event.preventDefault();
252252
changeItemsPerPage();
253-
});
253+
});
254254

255255
$("#toggleSelected").click(function(event) {
256256
event.preventDefault();
@@ -264,7 +264,7 @@ if( !$this->isConfigured )
264264
return false;
265265
});
266266

267-
267+
268268
$("#sortDomain").click(function() {
269269
var pattern = /\b\/sortorder\/[^/]*/g;
270270
var matches = pattern.exec(window.location.href);
@@ -342,27 +342,27 @@ if( !$this->isConfigured )
342342
if(items < 1 || items > 25){
343343
$("#itemsPerPageInfo").html('The items per page parameter should be an integer greater than or equal to 1 and less than or equal to 25');
344344
$("#itemsPerPageInfo").show(0);
345-
$("html, body").animate({ scrollTop: 0 }, "slow");
345+
$("html, body").animate({ scrollTop: 0 }, "slow");
346346
return false;
347347
}
348348
var pattern = /\b\/items\/[^/]*/g;
349349
var matches = pattern.exec(window.location.href);
350350
var goTo;
351351
if(matches){
352352
goTo = window.location.href.replace(matches[0], "/items/"+ items);
353-
} else {
354-
goTo = prepareURI() + '/items/' + items;
355-
}
353+
} else {
354+
goTo = prepareURI() + '/items/' + items;
355+
}
356356
window.location = goTo;
357357
return false;
358358
};
359-
359+
360360
function toggleProtection(thisObj){
361361
thisObj.hide(0);
362362
thisObj.before(loading_html);
363363
protectionRequest(thisObj);
364364
}
365-
365+
366366
function prepareURI(){
367367
var s = window.location.href;
368368
var pattern = /\?q=reseller\/listdomains/g;
@@ -388,7 +388,7 @@ if( !$this->isConfigured )
388388
protectionRequest(selected[i]);
389389
}
390390
}
391-
391+
392392
function disableButtons(){
393393
$('#sortDomain').addClass("disabled");
394394
$('.tableButtons').find('button').each(function() {

0 commit comments

Comments
 (0)