From 823d7ba42ac619010fa786936ad625461e27e56d Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 31 Jul 2011 22:22:34 -0700 Subject: [PATCH] api/friends/ids, api/followers/ids --- include/api.php | 64 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/include/api.php b/include/api.php index 45ca6f1a82..7b3dd866ce 100644 --- a/include/api.php +++ b/include/api.php @@ -209,7 +209,7 @@ $extra_query = "AND `contact`.`nick` = '%s' "; } - if (is_null($user)){ + if (is_null($user) && $a->argc > 3){ list($user, $null) = explode(".",$a->argv[3]); if(is_numeric($user)){ $user = intval($user); @@ -262,14 +262,26 @@ // count friends $r = q("SELECT COUNT(`id`) as `count` FROM `contact` - WHERE `uid` = %d + WHERE `uid` = %d AND `rel` IN ( %d, %d ) AND `self`=0 AND `blocked`=0", - intval($uinfo[0]['uid']) + intval($uinfo[0]['uid']), + intval(REL_FAN), + intval(REL_BUD) ); $countfriends = $r[0]['count']; + $r = q("SELECT COUNT(`id`) as `count` FROM `contact` + WHERE `uid` = %d AND `rel` IN ( %d, %d ) + AND `self`=0 AND `blocked`=0", + intval($uinfo[0]['uid']), + intval(REL_VIP), + intval(REL_BUD) + ); + $countfollowers = $r[0]['count']; + if(! $uinfo[0]['self']) { $countfriends = 0; + $countfollowers = 0; } $ret = Array( @@ -290,7 +302,7 @@ 'statuses_count' => $countitms, #XXX: fix me 'lang' => 'en', #XXX: fix me 'description' => '', - 'followers_count' => $countfriends, #XXX: fix me + 'followers_count' => $countfollowers, #XXX: fix me 'favourites_count' => 0, 'contributors_enabled' => false, 'follow_request_sent' => false, @@ -795,3 +807,47 @@ } } api_register_func('api/statusnet/version','api_statusnet_version',false); + + + function api_ff_ids(&$a,$type,$qtype) { + if(! local_user()) + return false; + + if($qtype == 'friends') + $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(REL_FAN), intval(REL_BUD)); + if($qtype == 'followers') + $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(REL_VIP), intval(REL_BUD)); + + + $r = q("SELECT id FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 $sql_extra", + intval(local_user()) + ); + + if(is_array($r)) { + if($type === 'xml') { + header("Content-type: application/xml"); + echo '' . "\r\n" . '' . "\r\n"; + foreach($r as $rr) + echo '' . $rr['id'] . '' . "\r\n"; + echo '' . "\r\n"; + killme(); + } + elseif($type === 'json') { + $ret = array(); + header("Content-type: application/json"); + foreach($r as $rr) $ret[] = $rr['id']; + echo json_encode($ret); + killme(); + } + } + } + + function api_friends_ids(&$a,$type) { + api_ff_ids($a,$type,'friends'); + } + function api_followers_ids(&$a,$type) { + api_ff_ids($a,$type,'followers'); + } + api_register_func('api/friends/ids','api_friends_ids',true); + api_register_func('api/followers/ids','api_followers_ids',true); +