4 function poco_init(&$a) {
7 $user = notags(trim($a->argv[1]));
9 if(! x($user) || get_config('system','block_public'))
10 http_status_exit(401);
12 $format = (($_GET['format']) ? $_GET['format'] : 'json');
16 if($a->argc > 2 && $a->argv[2] === '@me')
18 if($a->argc > 3 && $a->argv[3] === '@all')
20 if($a->argc > 3 && $a->argv[3] === '@self')
22 if($a->argc > 4 && intval($a->argv[4]) && $justme == false)
23 $cid = intval($a->argv[4]);
26 $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
27 where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
30 if(! count($r) || $r[0]['hidewall'] || $r[0]['hide-friends'])
31 http_status_exit(404);
36 $sql_extra = " and `contact`.`self` = 1 ";
39 $sql_extra = sprintf(" and `contact`.`id` = %d ",intval($cid));
41 $r = q("SELECT count(*) as `total` from `contact` where `uid` = %d and blocked = 0 and pending = 0
46 $totalResults = intval($r[0]['total']);
50 $startIndex = intval($_GET['startIndex']);
53 $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
55 $r = q("SELECT * from `contact` where `uid` = %d and blocked = 0 and pending = 0
56 $sql_extra LIMIT %d, %d",
64 $ret['sorted'] = 'false';
65 if(x($_GET,'filtered'))
66 $ret['filtered'] = 'false';
67 if(x($_GET,'updatedSince'))
68 $ret['updateSince'] = 'false';
70 $ret['startIndex'] = $startIndex;
71 $ret['itemsPerPage'] = $itemsPerPage;
72 $ret['totalResults'] = $totalResults;
73 $ret['entry'] = array();
78 'displayName' => false,
80 'preferredName' => false,
84 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
85 foreach($fields_ret as $f)
88 $fields_req = explode(',',$_GET['fields']);
89 foreach($fields_req as $f)
90 $fields_ret[trim($f)] = true;
98 $entry['id'] = $rr['id'];
99 if($fields_ret['displayName'])
100 $entry['displayName'] = $rr['name'];
101 if($fields_ret['urls'])
102 $entry['urls'] = array('value' => $rr['url'], 'type' => 'profile');
103 if($fields_ret['preferredUsername'])
104 $entry['preferredUsername'] = $rr['nick'];
105 if($fields_ret['photos'])
106 $entry['photos'] = array('value' => $rr['photo'], 'type' => 'profile');
107 $ret['entry'][] = $entry;
111 $ret['entry'][] = array();
114 http_status_exit(500);
116 if($format === 'xml') {
117 header('Content-type: text/xml');
118 echo replace_macros(get_markup_template('poco.xml',array('response' => $ret)));
119 http_status_exit(500);
122 if($format === 'json') {
123 header('Content-type: application/json');
124 echo json_encode($ret);
128 http_status_exit(500);