Skip to content

Commit

Permalink
Fix count() issues with PHP7.2 (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilian Grecu authored and donici committed Aug 19, 2019
1 parent 15c9d33 commit 75cc25c
Show file tree
Hide file tree
Showing 24 changed files with 3,822 additions and 3,809 deletions.
4 changes: 2 additions & 2 deletions application/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function brandingAction()
$values = $this->_request->getPost(); // Technically we should use *this*
if ($form->isValid($_POST)) {
$uploadedData = $form->getValues();

if (empty($uploadedData['brandicon'])) {
$values['brandicon'] = trim($this->_branding->getBrandIcon());
$this->_flashMessenger->addMessage(
Expand Down Expand Up @@ -298,7 +298,7 @@ public function listresellersAction()
}
$resellers = $this->_panel->getResellers();

if ((!isset($resellers)) || (empty($resellers)) || (count($resellers) == 0)) {
if ((!isset($resellers)) || (empty($resellers)) || (is_array($resellers) && count($resellers) === 0)) {
$this->_flashMessenger->addMessage(
array('message' => $this->t->_('Unable to retrieve resellers.'), 'status' => 'error')
);
Expand Down
22 changes: 11 additions & 11 deletions application/controllers/ResellerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ResellerController extends Zend_Controller_Action
* @var SpamFilter_PanelSupport_Cpanel
*/
protected $_panel;

public function init()
{
try {
Expand Down Expand Up @@ -135,19 +135,19 @@ public function listdomainsAction()
$config = Zend_Registry::get('general_config');
$this->view->isConfigured = (!empty($config->apiuser)) ? true : false;
if(!$this->view->isConfigured) { return false; }

// Items Per Page functionality
$itemsPerPage = $this->_getParam('items')? (int)htmlspecialchars($this->_getParam('items')) : 25 ;
if($itemsPerPage<1 || $itemsPerPage > 25){
$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');
$itemsPerPage = 25;
}

// Get params
$filter = htmlspecialchars($this->_getParam('search'));
$order = $this->_getParam('sortorder');
$oldorder = SpamFilter_Panel_Cache::get( 'domains_sort_order' );

// Get domain from cache if not root
if(SpamFilter_Core::getUsername() != 'root'){
$domains = SpamFilter_Panel_Cache::get(SpamFilter_Core::getDomainsCacheId());
Expand All @@ -162,8 +162,8 @@ public function listdomainsAction()
if ($order != $oldorder) {
$domains = $this->_panel->getSortedDomains(array ('domains' => $domains, 'order' => $order));
SpamFilter_Panel_Cache::set(SpamFilter_Core::getDomainsCacheId(), $domains);
}
}

// No cache set, proceed with retrieval
if (empty($domains)) {
$domains = $this->_panel->getDomains(
Expand All @@ -177,7 +177,7 @@ public function listdomainsAction()
// Cache miss, save the data
SpamFilter_Panel_Cache::set(SpamFilter_Core::getDomainsCacheId(), $domains);
}

// Proceed
if ( !isset($domains))
{
Expand All @@ -190,7 +190,7 @@ public function listdomainsAction()
return false;
}

if ((empty($domains)) || (count($domains) == 0) )
if ((empty($domains)) || (is_countable($domains) && count($domains) === 0) )
{
$this->_flashMessenger->addMessage(
array(
Expand All @@ -200,11 +200,11 @@ public function listdomainsAction()
);
return false;
}

if(!empty($filter)){
$domains = $this->_panel->filterDomains(array('domains' => $domains, 'filter' => $filter));
}
if ((empty($domains)) || (count($domains) == 0) )
if ((empty($domains)) || (is_countable($domains) && count($domains) == 0) )
{
$this->_flashMessenger->addMessage(
array(
Expand Down Expand Up @@ -257,7 +257,7 @@ public function listaccountsAction()
}

// Proceed
if( (!isset($accounts)) || (empty($accounts)) || (count($accounts) == 0) )
if( (!isset($accounts)) || (empty($accounts)) || (is_countable($accounts) && count($accounts) == 0) )
{
$this->_flashMessenger->addMessage(
array(
Expand Down
2 changes: 1 addition & 1 deletion application/views/helpers/FlashMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function flashMessages($translator = NULL)
$output = '';

// If there are no messages, don't bother with this whole process.
if (count($messages) > 0)
if (is_array($messages) && count($messages) > 0)
{
// This chunk of code takes the messages (formatted as in the above sample
// input) and puts them into an array of the form:
Expand Down
6 changes: 3 additions & 3 deletions application/views/helpers/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function setColumns(array $columns)

/**
* Set table summary
*
*
* @param string $summary
* @return App_View_Helper_Table
*/
Expand Down Expand Up @@ -172,7 +172,7 @@ public function addRow($cols)
*/
public function setRows($rows)
{
if (count($rows)) {
if (is_countable($rows) && count($rows)) {
foreach ($rows as $r) {
$this->addRow($r);
}
Expand Down Expand Up @@ -279,7 +279,7 @@ public function toString()
elseif (isset($r[$i])) {
$xhtml .= stripslashes($r[$i]);
}


$xhtml .= '</td>';
$i++;
Expand Down
2 changes: 1 addition & 1 deletion application/views/scripts/admin/listresellers.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</thead>
<tbody>
<?php
if (count($this->paginator) == 0) {
if ($this->paginator->count() == 0) {
echo '<tr><td colspan="2">' . $this->t->_('There are no resellers in the system.') . '</td></tr>';
}

Expand Down
2 changes: 1 addition & 1 deletion application/views/scripts/domain/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (!$this->hasAPIAccess) {
</thead>
<tbody>
<?php
if (count($this->paginator) == 0) {
if ($this->paginator->count() === 0) {
echo '<tr><td colspan="3">' . $this->t->_('There are no domains assigned to your account') . '</td></tr>';
}

Expand Down
10 changes: 5 additions & 5 deletions application/views/scripts/reseller/listaccounts.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ if( !$this->isConfigured )
<th><?php echo $this->t->_('Username'); ?></th>
<th><?php echo $this->t->_('Primary domain'); ?></th>
<th></th>
</tr>
</tr>
</thead>
<tbody>
<?php
if( count($this->paginator) == 0 )
<?php
if( $this->paginator->count() === 0 )
{
echo '<tr><td colspan="3">' . $this->t->_('There are no users assigned to your account') . '</td></tr>';
}

foreach( $this->paginator as $u )
foreach( $this->paginator as $u )
{
?>
<tr>
<td><?php echo $u['user']; ?></td>
<td><?php echo $u['domain']; ?></td>
<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>
</tr>
<?php
<?php
}
?>
</tbody>
Expand Down
26 changes: 13 additions & 13 deletions application/views/scripts/reseller/listdomains.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ if( !$this->isConfigured )
parentDocumentTitle = window.top.document.title;
if (parentDocumentTitle.indexOf(brandname) == -1) {
window.top.document.title = parentDocumentTitle + ' - ' + brandname;
}
}
} catch(e) {

}
});
</script>
Expand Down Expand Up @@ -82,7 +82,7 @@ if( !$this->isConfigured )
</thead>
<tbody>
<?php
if( count($this->paginator) == 0 )
if( $this->paginator->count() === 0 )
{
echo '<tr><td colspan="5">'. $this->t->_('No content to display') . '</td></tr>';
}
Expand Down Expand Up @@ -246,11 +246,11 @@ if( !$this->isConfigured )
window.location = goTo;
return false;
});

$("#changeItems").click(function(event){
event.preventDefault();
changeItemsPerPage();
});
});

$("#toggleSelected").click(function(event) {
event.preventDefault();
Expand All @@ -264,7 +264,7 @@ if( !$this->isConfigured )
return false;
});


$("#sortDomain").click(function() {
var pattern = /\b\/sortorder\/[^/]*/g;
var matches = pattern.exec(window.location.href);
Expand Down Expand Up @@ -342,27 +342,27 @@ if( !$this->isConfigured )
if(items < 1 || items > 25){
$("#itemsPerPageInfo").html('The items per page parameter should be an integer greater than or equal to 1 and less than or equal to 25');
$("#itemsPerPageInfo").show(0);
$("html, body").animate({ scrollTop: 0 }, "slow");
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
}
var pattern = /\b\/items\/[^/]*/g;
var matches = pattern.exec(window.location.href);
var goTo;
if(matches){
goTo = window.location.href.replace(matches[0], "/items/"+ items);
} else {
goTo = prepareURI() + '/items/' + items;
}
} else {
goTo = prepareURI() + '/items/' + items;
}
window.location = goTo;
return false;
};

function toggleProtection(thisObj){
thisObj.hide(0);
thisObj.before(loading_html);
protectionRequest(thisObj);
}

function prepareURI(){
var s = window.location.href;
var pattern = /\?q=reseller\/listdomains/g;
Expand All @@ -388,7 +388,7 @@ if( !$this->isConfigured )
protectionRequest(selected[i]);
}
}

function disableButtons(){
$('#sortDomain').addClass("disabled");
$('.tableButtons').find('button').each(function() {
Expand Down
Loading

0 comments on commit 75cc25c

Please sign in to comment.