Some documentation in mod/ping.php an reduced default logging.

It is now LOGGER_DATA as it returns the json data contents.
This commit is contained in:
Klaus Weidenbach 2014-06-30 22:16:21 +02:00
parent 6bd9492e77
commit 13098ba8d8

View File

@ -1,9 +1,21 @@
<?php <?php
/**
* @file mod/ping.php
*
*/
require_once('include/bbcode.php'); require_once('include/bbcode.php');
require_once('include/notify.php'); require_once('include/notify.php');
/**
* @brief do several updates when pinged.
*
* This function does several tasks. Whenever called it checks for new messages,
* introductions, notifications, etc. and returns a json with the results.
*
* @param App &$a
* @result JSON
*/
function ping_init(&$a) { function ping_init(&$a) {
$result = array(); $result = array();
@ -48,7 +60,6 @@ function ping_init(&$a) {
killme(); killme();
} }
if(get_observer_hash() && (! $result['invalid'])) { if(get_observer_hash() && (! $result['invalid'])) {
$r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1", $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1",
dbesc(get_observer_hash()), dbesc(get_observer_hash()),
@ -80,8 +91,8 @@ function ping_init(&$a) {
killme(); killme();
} }
// mark all items read
if(x($_REQUEST, 'markRead') && local_user()) { if(x($_REQUEST, 'markRead') && local_user()) {
switch($_REQUEST['markRead']) { switch($_REQUEST['markRead']) {
case 'network': case 'network':
$r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and uid = %d", $r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and uid = %d",
@ -90,7 +101,6 @@ function ping_init(&$a) {
intval(local_user()) intval(local_user())
); );
break; break;
case 'home': case 'home':
$r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and (item_flags & %d) and uid = %d", $r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and (item_flags & %d) and uid = %d",
intval(ITEM_UNSEEN), intval(ITEM_UNSEEN),
@ -111,19 +121,16 @@ function ping_init(&$a) {
intval(local_user()) intval(local_user())
); );
break; break;
case 'notify': case 'notify':
$r = q("update notify set seen = 1 where uid = %d", $r = q("update notify set seen = 1 where uid = %d",
intval(local_user()) intval(local_user())
); );
break; break;
default: default:
break; break;
} }
} }
if(argc() > 1 && argv(1) === 'notify') { if(argc() > 1 && argv(1) === 'notify') {
$t = q("select count(*) as total from notify where uid = %d and seen = 0", $t = q("select count(*) as total from notify where uid = %d and seen = 0",
intval(local_user()) intval(local_user())
@ -163,12 +170,9 @@ function ping_init(&$a) {
echo json_encode(array('notify' => $notifs)); echo json_encode(array('notify' => $notifs));
killme(); killme();
} }
if(argc() > 1 && argv(1) === 'messages') { if(argc() > 1 && argv(1) === 'messages') {
$channel = $a->get_channel(); $channel = $a->get_channel();
$t = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan $t = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan
where channel_id = %d and not ( mail_flags & %d ) and not (mail_flags & %d ) where channel_id = %d and not ( mail_flags & %d ) and not (mail_flags & %d )
@ -196,14 +200,9 @@ function ping_init(&$a) {
echo json_encode(array('notify' => $notifs)); echo json_encode(array('notify' => $notifs));
killme(); killme();
} }
if(argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) { if(argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) {
$result = array(); $result = array();
$r = q("SELECT * FROM item $r = q("SELECT * FROM item
@ -221,14 +220,12 @@ function ping_init(&$a) {
$result[] = format_notification($item); $result[] = format_notification($item);
} }
} }
logger('ping: ' . print_r($result,true)); logger('ping (network||home): ' . print_r($result, true), LOGGER_DATA);
echo json_encode(array('notify' => $result)); echo json_encode(array('notify' => $result));
killme(); killme();
} }
if(argc() > 1 && (argv(1) === 'intros')) { if(argc() > 1 && (argv(1) === 'intros')) {
$result = array(); $result = array();
$r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash
@ -251,14 +248,12 @@ function ping_init(&$a) {
); );
} }
} }
logger('ping: ' . print_r($result,true)); logger('ping (intros): ' . print_r($result, true), LOGGER_DATA);
echo json_encode(array('notify' => $result)); echo json_encode(array('notify' => $result));
killme(); killme();
} }
if(argc() > 1 && (argv(1) === 'all_events')) { if(argc() > 1 && (argv(1) === 'all_events')) {
$bd_format = t('g A l F d') ; // 8 AM Friday January 18 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
$result = array(); $result = array();
@ -283,7 +278,6 @@ function ping_init(&$a) {
$when = day_translate(datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : ''); $when = day_translate(datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
$result[] = array( $result[] = array(
'notify_link' => $a->get_baseurl() . '/events', // FIXME this takes you to an edit page and it may not be yours, we really want to just view the single event --> '/events/event/' . $rr['event_hash'], 'notify_link' => $a->get_baseurl() . '/events', // FIXME this takes you to an edit page and it may not be yours, we really want to just view the single event --> '/events/event/' . $rr['event_hash'],
'name' => $rr['xchan_name'], 'name' => $rr['xchan_name'],
@ -295,22 +289,18 @@ function ping_init(&$a) {
); );
} }
} }
logger('ping: ' . print_r($result,true)); logger('ping (all_events): ' . print_r($result, true), LOGGER_DATA);
echo json_encode(array('notify' => $result)); echo json_encode(array('notify' => $result));
killme(); killme();
} }
// Normal ping - just the counts // Normal ping - just the counts
$t = q("select count(*) as total from notify where uid = %d and seen = 0", $t = q("select count(*) as total from notify where uid = %d and seen = 0",
intval(local_user()) intval(local_user())
); );
if($t) if($t)
$result['notify'] = intval($t[0]['total']); $result['notify'] = intval($t[0]['total']);
$t1 = dba_timer(); $t1 = dba_timer();
$r = q("SELECT id, item_restrict, item_flags FROM item $r = q("SELECT id, item_restrict, item_flags FROM item
@ -321,7 +311,6 @@ function ping_init(&$a) {
); );
if(count($r)) { if(count($r)) {
$arr = array('items' => $r); $arr = array('items' => $r);
call_hooks('network_ping', $arr); call_hooks('network_ping', $arr);
@ -333,7 +322,6 @@ function ping_init(&$a) {
} }
} }
$t2 = dba_timer(); $t2 = dba_timer();
$intr = q("select count(abook_id) as total from abook where (abook_flags & %d) and abook_channel = %d", $intr = q("select count(abook_id) as total from abook where (abook_flags & %d) and abook_channel = %d",
@ -409,6 +397,4 @@ function ping_init(&$a) {
echo $x; echo $x;
killme(); killme();
} }