From f83a504da139faf2e1707679cde9255b458b79e3 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 15 Jul 2012 21:06:07 -0700 Subject: more work on json notifications, now working except for notify popup --- mod/ping.php | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'mod') diff --git a/mod/ping.php b/mod/ping.php index 05287e499..2d7163c54 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -8,10 +8,34 @@ function ping_init(&$a) { $result = array(); $notifs = array(); + $result['notify'] = 0; + $result['home'] = 0; + $result['network'] = 0; + $result['intros'] = 0; + $result['mail'] = 0; + $result['register'] = 0; + $result['notice'] = array(); + $result['info'] = array(); + + header("content-type: application/json"); - if((! local_user()) || ((intval($_GET['uid'])) && (intval($_GET['uid']) != local_user()))) { - $result[] = array('success' => false, 'message' => 'Authentication error'); + $result['invalid'] = ((intval($_GET['uid'])) && (intval($_GET['uid']) != local_user()) ? 1 : 0); + + if(x($_SESSION,'sysmsg')){ + foreach ($_SESSION['sysmsg'] as $m){ + $result['notice'][] = array('message' => $m); + } + unset($_SESSION['sysmsg']); + } + if(x($_SESSION,'sysmsg_info')){ + foreach ($_SESSION['sysmsg_info'] as $m){ + $result['info'][] = array('message' => $m); + } + unset($_SESSION['sysmsg_info']); + } + + if((! local_user()) || ($result['invalid'])) { echo json_encode($result); killme(); } @@ -58,16 +82,6 @@ function ping_init(&$a) { } - $result['notify'] = 0; - $result['home'] = 0; - $result['network'] = 0; - $result['intros'] = 0; - $result['mail'] = 0; - $result['register'] = 0; - $result['notice'] = array(); - $result['info'] = array(); - - $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_user()) @@ -106,8 +120,8 @@ function ping_init(&$a) { WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0", intval(local_user()) ); - - $intro = count($intros1) + count($intros2); + + $intros = count($intros1) + count($intros2); $result['intros'] = intval($intros); $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ; @@ -124,19 +138,6 @@ function ping_init(&$a) { if($regs) $result['register'] = intval($regs[0]['total']); } - - if(x($_SESSION,'sysmsg')){ - foreach ($_SESSION['sysmsg'] as $m){ - $result['notice'][] = $m; - } - unset($_SESSION['sysmsg']); - } - if(x($_SESSION,'sysmsg_info')){ - foreach ($_SESSION['sysmsg_info'] as $m){ - $result['info'][] = $m; - } - unset($_SESSION['sysmsg_info']); - } echo json_encode($result); killme(); -- cgit v1.2.3