From aa548be3b95f1a4292f51e0758e80d759a9b14d1 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:33:54 +0100 Subject: [PATCH] Introduced is_filled_array() + added some missing array initialization Signed-off-by: Roland Haeder --- boot.php | 4 ++++ mod/message.php | 10 ++++++---- mod/ping.php | 25 +++++++++++++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/boot.php b/boot.php index d82669f231..bf98cf5c3a 100644 --- a/boot.php +++ b/boot.php @@ -2138,3 +2138,7 @@ function argv($x) { return ''; } + +function is_filled_array ($array) { + return (is_array($array) && count($array) > 0); +} diff --git a/mod/message.php b/mod/message.php index 734bf34710..6e176f7123 100644 --- a/mod/message.php +++ b/mod/message.php @@ -8,7 +8,7 @@ function message_init(&$a) { $tabs = ''; if ($a->argc >1 && is_numeric($a->argv[1])) { - $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); + $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); } $new = array( @@ -360,11 +360,13 @@ function message_content(&$a) { dbesc($myprofile) ); - if(count($r)) $a->set_pager_total($r[0]['total']); + if (is_filled_array($r)) { + $a->set_pager_total($r[0]['total']); + } $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']); - if(! count($r)) { + if(! is_filled_array($r)) { info( t('No messages.') . EOL); return $o; } @@ -542,7 +544,7 @@ function get_messages($user, $lstart, $lend) { ); } -function render_messages($msg, $t) { +function render_messages(array $msg, $t) { $a = get_app(); diff --git a/mod/ping.php b/mod/ping.php index 2eb94576b3..8deab28ed2 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -32,6 +32,8 @@ function ping_init(&$a) { $dislikes = array(); $friends = array(); $posts = array(); + $regs = array(); + $mails = array(); $home = 0; $network = 0; @@ -49,7 +51,7 @@ function ping_init(&$a) { intval(local_user()), intval(local_user()) ); - if(count($r)) { + if(is_filled_array($r)) { $arr = array('items' => $r); call_hooks('network_ping', $arr); @@ -116,8 +118,6 @@ function ping_init(&$a) { $intro = count($intros1) + count($intros2); $intros = $intros1+$intros2; - - $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ; $mails = q("SELECT * FROM `mail` WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ", @@ -150,7 +150,7 @@ function ping_init(&$a) { dbesc(datetime_convert('UTC','UTC','now')) ); - if($ev && count($ev)) { + if(is_filled_array($ev)) { $all_events = intval($ev[0]['total']); if($all_events) { @@ -219,7 +219,7 @@ function ping_init(&$a) { $home\r\n"; if ($register!=0) echo "$register"; - if (count($groups_unseen)) { + if ( is_filled_array($groups_unseen) ) { echo ''; foreach ($groups_unseen as $it) if ($it['count'] > 0) @@ -228,7 +228,7 @@ function ping_init(&$a) { echo ""; } - if (count($forums_unseen)) { + if ( is_filled_array($forums_unseen) ) { echo ''; foreach ($forums_unseen as $it) if ($it['count'] > 0) @@ -245,8 +245,8 @@ function ping_init(&$a) { $birthdays_today\r\n"; - if(count($notifs) && (! $sysnotify)) { - foreach($notifs as $zz) { + if (is_filled_array($notifs) && (! $sysnotify)) { + foreach ($notifs as $zz) { if($zz['seen'] == 0) $sysnotify ++; } @@ -255,7 +255,7 @@ function ping_init(&$a) { echo ' '; // merge all notification types in one array - if ($intro>0){ + if ( is_filled_array($intros) ) { foreach ($intros as $i) { $n = array( 'href' => $a->get_baseurl().'/notifications/intros/'.$i['id'], @@ -270,7 +270,7 @@ function ping_init(&$a) { } } - if ($mail>0){ + if ( is_filled_array($mails) ) { foreach ($mails as $i) { $n = array( 'href' => $a->get_baseurl().'/message/'.$i['id'], @@ -285,7 +285,7 @@ function ping_init(&$a) { } } - if ($register>0){ + if ( is_filled_array($regs) ) { foreach ($regs as $i) { $n = array( 'href' => $a->get_baseurl().'/admin/users/', @@ -299,6 +299,7 @@ function ping_init(&$a) { $notifs[] = $n; } } + // sort notifications by $[]['date'] $sort_function = function($a, $b) { $adate = date($a['date']); @@ -310,7 +311,7 @@ function ping_init(&$a) { }; usort($notifs, $sort_function); - if(count($notifs)) { + if( is_filled_array($notifs) ) { foreach($notifs as $n) { echo xmlize($n); } -- 2.39.5