Introduced is_filled_array() + added some missing array initialization

Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2016-03-01 14:33:54 +01:00
parent c54e38fddb
commit 2c37eab808
3 changed files with 23 additions and 16 deletions

View file

@ -2149,3 +2149,7 @@ function argv($x) {
return ''; return '';
} }
function is_filled_array ($array) {
return (is_array($array) && count($array) > 0);
}

View file

@ -8,7 +8,7 @@ function message_init(&$a) {
$tabs = ''; $tabs = '';
if ($a->argc >1 && is_numeric($a->argv[1])) { 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( $new = array(
@ -360,11 +360,13 @@ function message_content(&$a) {
dbesc($myprofile) 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']); $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']);
if(! count($r)) { if(! is_filled_array($r)) {
info( t('No messages.') . EOL); info( t('No messages.') . EOL);
return $o; 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(); $a = get_app();

View file

@ -32,6 +32,8 @@ function ping_init(&$a) {
$dislikes = array(); $dislikes = array();
$friends = array(); $friends = array();
$posts = array(); $posts = array();
$regs = array();
$mails = array();
$home = 0; $home = 0;
$network = 0; $network = 0;
@ -49,7 +51,7 @@ function ping_init(&$a) {
intval(local_user()), intval(local_user()) intval(local_user()), intval(local_user())
); );
if(count($r)) { if(is_filled_array($r)) {
$arr = array('items' => $r); $arr = array('items' => $r);
call_hooks('network_ping', $arr); call_hooks('network_ping', $arr);
@ -116,8 +118,6 @@ function ping_init(&$a) {
$intro = count($intros1) + count($intros2); $intro = count($intros1) + count($intros2);
$intros = $intros1+$intros2; $intros = $intros1+$intros2;
$myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ; $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
$mails = q("SELECT * FROM `mail` $mails = q("SELECT * FROM `mail`
WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ", WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
@ -150,7 +150,7 @@ function ping_init(&$a) {
dbesc(datetime_convert('UTC','UTC','now')) dbesc(datetime_convert('UTC','UTC','now'))
); );
if($ev && count($ev)) { if(is_filled_array($ev)) {
$all_events = intval($ev[0]['total']); $all_events = intval($ev[0]['total']);
if($all_events) { if($all_events) {
@ -219,7 +219,7 @@ function ping_init(&$a) {
<home>$home</home>\r\n"; <home>$home</home>\r\n";
if ($register!=0) echo "<register>$register</register>"; if ($register!=0) echo "<register>$register</register>";
if (count($groups_unseen)) { if ( is_filled_array($groups_unseen) ) {
echo '<groups>'; echo '<groups>';
foreach ($groups_unseen as $it) foreach ($groups_unseen as $it)
if ($it['count'] > 0) if ($it['count'] > 0)
@ -228,7 +228,7 @@ function ping_init(&$a) {
echo "</groups>"; echo "</groups>";
} }
if (count($forums_unseen)) { if ( is_filled_array($forums_unseen) ) {
echo '<forums>'; echo '<forums>';
foreach ($forums_unseen as $it) foreach ($forums_unseen as $it)
if ($it['count'] > 0) if ($it['count'] > 0)
@ -245,8 +245,8 @@ function ping_init(&$a) {
<birthdays-today>$birthdays_today</birthdays-today>\r\n"; <birthdays-today>$birthdays_today</birthdays-today>\r\n";
if(count($notifs) && (! $sysnotify)) { if (is_filled_array($notifs) && (! $sysnotify)) {
foreach($notifs as $zz) { foreach ($notifs as $zz) {
if($zz['seen'] == 0) if($zz['seen'] == 0)
$sysnotify ++; $sysnotify ++;
} }
@ -255,7 +255,7 @@ function ping_init(&$a) {
echo ' <notif count="'. ($sysnotify + $intro + $mail + $register) .'">'; echo ' <notif count="'. ($sysnotify + $intro + $mail + $register) .'">';
// merge all notification types in one array // merge all notification types in one array
if ($intro>0){ if ( is_filled_array($intros) ) {
foreach ($intros as $i) { foreach ($intros as $i) {
$n = array( $n = array(
'href' => $a->get_baseurl().'/notifications/intros/'.$i['id'], '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) { foreach ($mails as $i) {
$n = array( $n = array(
'href' => $a->get_baseurl().'/message/'.$i['id'], '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) { foreach ($regs as $i) {
$n = array( $n = array(
'href' => $a->get_baseurl().'/admin/users/', 'href' => $a->get_baseurl().'/admin/users/',
@ -299,6 +299,7 @@ function ping_init(&$a) {
$notifs[] = $n; $notifs[] = $n;
} }
} }
// sort notifications by $[]['date'] // sort notifications by $[]['date']
$sort_function = function($a, $b) { $sort_function = function($a, $b) {
$adate = date($a['date']); $adate = date($a['date']);
@ -310,7 +311,7 @@ function ping_init(&$a) {
}; };
usort($notifs, $sort_function); usort($notifs, $sort_function);
if(count($notifs)) { if( is_filled_array($notifs) ) {
foreach($notifs as $n) { foreach($notifs as $n) {
echo xmlize($n); echo xmlize($n);
} }