3 function poco_init(&$a) {
6 $user = notags(trim($a->argv[1]));
8 if(! x($user) || get_config('system','block_public'))
11 $format = (($_GET['format']) ? $_GET['format'] : 'json');
15 if($a->argc > 2 && $a->argv[2] === '@me')
17 if($a->argc > 3 && $a->argv[3] === '@all')
19 if($a->argc > 3 && $a->argv[3] === '@self')
21 if($a->argc > 4 && intval($a->argv[4]) && $justme == false)
22 $cid = intval($a->argv[4]);
25 $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
26 where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
29 if(! count($r) || $r[0]['hidewall'] || $r[0]['hide-friends'])
30 http_status_exit(404);
35 $sql_extra = " and `contact`.`self` = 1 ";
38 $sql_extra = sprintf(" and `contact`.`id` = %d ",intval($cid));
40 $r = q("SELECT count(*) as `total` from `contact` where `uid` = %d and blocked = 0 and pending = 0
45 $totalResults = intval($r[0]['total']);
49 $startIndex = intval($_GET['startIndex']);
52 $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
54 $r = q("SELECT * from `contact` where `uid` = %d and blocked = 0 and pending = 0
55 $sql_extra LIMIT %d, %d",
63 $ret['sorted'] = 'false';
64 if(x($_GET,'filtered'))
65 $ret['filtered'] = 'false';
66 if(x($_GET,'updatedSince'))
67 $ret['updateSince'] = 'false';
69 $ret['startIndex'] = (string) $startIndex;
70 $ret['itemsPerPage'] = (string) $itemsPerPage;
71 $ret['totalResults'] = (string) $totalResults;
72 $ret['entry'] = array();
77 'displayName' => false,
79 'preferredUsername' => false,
83 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
84 foreach($fields_ret as $k => $v)
85 $fields_ret[$k] = true;
87 $fields_req = explode(',',$_GET['fields']);
88 foreach($fields_req as $f)
89 $fields_ret[trim($f)] = true;
97 $entry['id'] = $rr['id'];
98 if($fields_ret['displayName'])
99 $entry['displayName'] = $rr['name'];
100 if($fields_ret['urls'])
101 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
102 if($fields_ret['preferredUsername'])
103 $entry['preferredUsername'] = $rr['nick'];
104 if($fields_ret['photos'])
105 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
106 $ret['entry'][] = $entry;
110 $ret['entry'][] = array();
113 http_status_exit(500);
115 if($format === 'xml') {
116 header('Content-type: text/xml');
117 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
118 http_status_exit(500);
120 if($format === 'json') {
121 header('Content-type: application/json');
122 echo json_encode($ret);
126 http_status_exit(500);