2010-07-20 05:52:31 +00:00
< ? php
2012-07-13 14:09:29 +00:00
require_once ( 'include/bbcode.php' );
2012-05-22 23:01:07 +00:00
2012-07-13 14:09:29 +00:00
function ping_init ( & $a ) {
2011-09-28 07:30:22 +00:00
2012-07-13 14:09:29 +00:00
$result = array ();
$notifs = array ();
2012-05-22 23:01:07 +00:00
2012-07-16 04:06:07 +00:00
$result [ 'notify' ] = 0 ;
$result [ 'home' ] = 0 ;
$result [ 'network' ] = 0 ;
$result [ 'intros' ] = 0 ;
$result [ 'mail' ] = 0 ;
$result [ 'register' ] = 0 ;
$result [ 'notice' ] = array ();
$result [ 'info' ] = array ();
2012-07-26 05:55:43 +00:00
$t0 = dba_timer ();
2012-07-16 04:06:07 +00:00
2012-07-13 14:09:29 +00:00
header ( " content-type: application/json " );
2012-05-22 23:01:07 +00:00
2012-07-16 04:06:07 +00:00
$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' ])) {
2012-07-13 14:09:29 +00:00
echo json_encode ( $result );
killme ();
}
2012-02-24 00:50:29 +00:00
2012-07-13 14:09:29 +00:00
if ( $a -> argc > 1 && $a -> argv [ 1 ] === 'notify' ) {
2012-03-01 00:26:07 +00:00
$t = q ( " select count(*) as total from notify where uid = %d and seen = 0 " ,
2012-02-22 03:03:55 +00:00
intval ( local_user ())
);
2012-03-01 00:26:07 +00:00
if ( $t && intval ( $t [ 0 ][ 'total' ]) > 49 ) {
$z = q ( " select * from notify where uid = %d
and seen = 0 order by date desc limit 0 , 50 " ,
intval ( local_user ())
);
}
else {
$z1 = q ( " select * from notify where uid = %d
and seen = 0 order by date desc limit 0 , 50 " ,
intval ( local_user ())
);
$z2 = q ( " select * from notify where uid = %d
and seen = 1 order by date desc limit 0 , % d " ,
intval ( local_user ()),
intval ( 50 - intval ( $t [ 0 ][ 'total' ]))
);
$z = array_merge ( $z1 , $z2 );
}
2012-07-13 14:09:29 +00:00
if ( count ( $z )) {
foreach ( $z as $zz ) {
$notifs [] = array (
'notify_link' => $a -> get_baseurl () . '/notify/view/' . $zz [ 'id' ],
'name' => $zz [ 'name' ],
'url' => $zz [ 'url' ],
'photo' => $zz [ 'photo' ],
'when' => relative_date ( $zz [ 'date' ]),
2012-07-18 05:11:24 +00:00
'class' => (( $zz [ 'seen' ]) ? 'notify-seen' : 'notify-unseen' ),
2012-07-13 14:09:29 +00:00
'message' => strip_tags ( bbcode ( $zz [ 'msg' ]))
);
2011-09-28 07:30:22 +00:00
}
2011-08-23 11:52:20 +00:00
}
2012-07-13 14:09:29 +00:00
echo json_encode ( array ( 'notify' => $notifs ));
killme ();
2011-09-28 07:30:22 +00:00
2012-07-13 14:09:29 +00:00
}
$t = q ( " select count(*) as total from notify where uid = %d and seen = 0 " ,
intval ( local_user ())
);
if ( $t )
$result [ 'notify' ] = intval ( $t [ 0 ][ 'total' ]);
2012-07-26 05:55:43 +00:00
$t1 = dba_timer ();
2012-07-13 14:09:29 +00:00
$r = q ( " SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,
`item` . `author-link` , `item` . `author-avatar` , `item` . `created` , `item` . `object` ,
`pitem` . `author-name` as `pname` , `pitem` . `author-link` as `plink`
FROM `item` INNER JOIN `item` as `pitem` ON `pitem` . `id` = `item` . `parent`
WHERE `item` . `unseen` = 1 AND `item` . `visible` = 1 AND
`item` . `deleted` = 0 AND `item` . `uid` = % d
ORDER BY `item` . `created` DESC " ,
intval ( local_user ())
);
if ( count ( $r )) {
foreach ( $r as $it ) {
if ( $it [ 'wall' ])
$result [ 'home' ] ++ ;
else
$result [ 'network' ] ++ ;
2011-09-28 07:30:22 +00:00
}
2012-07-13 14:09:29 +00:00
}
2011-08-17 19:59:06 +00:00
2012-07-26 05:55:43 +00:00
$t2 = dba_timer ();
2012-07-13 14:09:29 +00:00
$intros1 = q ( " SELECT `intro`.`id`, `intro`.`datetime`,
`fcontact` . `name` , `fcontact` . `url` , `fcontact` . `photo`
FROM `intro` LEFT JOIN `fcontact` ON `intro` . `fid` = `fcontact` . `id`
WHERE `intro` . `uid` = % d AND `intro` . `blocked` = 0 AND `intro` . `ignore` = 0 AND `intro` . `fid` != 0 " ,
intval ( local_user ())
);
2012-07-26 05:55:43 +00:00
$t3 = dba_timer ();
2012-07-13 14:09:29 +00:00
$intros2 = q ( " SELECT `intro`.`id`, `intro`.`datetime`,
`contact` . `name` , `contact` . `url` , `contact` . `photo`
FROM `intro` LEFT JOIN `contact` ON `intro` . `contact-id` = `contact` . `id`
WHERE `intro` . `uid` = % d AND `intro` . `blocked` = 0 AND `intro` . `ignore` = 0 AND `intro` . `contact-id` != 0 " ,
intval ( local_user ())
);
2012-07-16 04:06:07 +00:00
$intros = count ( $intros1 ) + count ( $intros2 );
2012-07-13 14:09:29 +00:00
$result [ 'intros' ] = intval ( $intros );
2012-07-26 05:55:43 +00:00
$t4 = dba_timer ();
2012-07-13 14:09:29 +00:00
$myurl = $a -> get_baseurl () . '/profile/' . $a -> user [ 'nickname' ] ;
$mails = q ( " SELECT *, COUNT(*) AS `total` FROM `mail`
WHERE `uid` = % d AND `seen` = 0 AND `from-url` != '%s' " ,
intval ( local_user ()),
dbesc ( $myurl )
);
if ( $mails )
$result [ 'mail' ] = intval ( $mails [ 0 ][ 'total' ]);
if ( $a -> config [ 'register_policy' ] == REGISTER_APPROVE && is_site_admin ()){
$regs = q ( " SELECT `contact`.`name`, `contact`.`url`, `contact`.`micro`, `register`.`created`, COUNT(*) as `total` FROM `contact` RIGHT JOIN `register` ON `register`.`uid`=`contact`.`uid` WHERE `contact`.`self`=1 " );
if ( $regs )
$result [ 'register' ] = intval ( $regs [ 0 ][ 'total' ]);
}
2012-07-26 05:55:43 +00:00
$t5 = dba_timer ();
$x = json_encode ( $result );
2011-09-05 12:01:21 +00:00
2012-07-26 05:55:43 +00:00
$t6 = dba_timer ();
// logger('ping timer: ' . sprintf('%01.4f %01.4f %01.4f %01.4f %01.4f %01.4f',$t6 - $t5, $t5 - $t4, $t4 - $t3, $t3 - $t2, $t2 - $t1, $t1 - $t0));
echo $x ;
2010-07-20 05:52:31 +00:00
killme ();
2012-07-13 14:09:29 +00:00
2010-07-20 05:52:31 +00:00
}