3 function poco_init(&$a) {
7 if(intval(get_config('system','block_public')))
12 $user = notags(trim($a->argv[1]));
15 $c = q("select * from pconfig where cat = 'system' and k = 'suggestme' and v = 1");
17 http_status_exit(401);
21 $format = (($_GET['format']) ? $_GET['format'] : 'json');
25 if($a->argc > 2 && $a->argv[2] === '@me')
27 if($a->argc > 3 && $a->argv[3] === '@all')
29 if($a->argc > 3 && $a->argv[3] === '@self')
31 if($a->argc > 4 && intval($a->argv[4]) && $justme == false)
32 $cid = intval($a->argv[4]);
36 $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
37 where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
40 if(! count($r) || $r[0]['hidewall'] || $r[0]['hide-friends'])
41 http_status_exit(404);
47 $sql_extra = " and `contact`.`self` = 1 ";
49 $sql_extra = " and `contact`.`self` = 0 ";
52 $sql_extra = sprintf(" and `contact`.`id` = %d ",intval($cid));
55 $r = q("SELECT count(*) as `total` from `contact` where self = 1
56 and uid in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = 1) ");
59 $r = q("SELECT count(*) as `total` from `contact` where `uid` = %d and blocked = 0 and pending = 0 and hidden = 0
65 $totalResults = intval($r[0]['total']);
69 $startIndex = intval($_GET['startIndex']);
72 $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
76 $r = q("SELECT * from contact where self = 1
77 and uid in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = 1) limit %d, %d ",
84 $r = q("SELECT * from `contact` where `uid` = %d and blocked = 0 and pending = 0 and hidden = 0
85 $sql_extra LIMIT %d, %d",
93 $ret['sorted'] = 'false';
94 if(x($_GET,'filtered'))
95 $ret['filtered'] = 'false';
96 if(x($_GET,'updatedSince'))
97 $ret['updateSince'] = 'false';
99 $ret['startIndex'] = (string) $startIndex;
100 $ret['itemsPerPage'] = (string) $itemsPerPage;
101 $ret['totalResults'] = (string) $totalResults;
102 $ret['entry'] = array();
107 'displayName' => false,
109 'preferredUsername' => false,
113 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
114 foreach($fields_ret as $k => $v)
115 $fields_ret[$k] = true;
117 $fields_req = explode(',',$_GET['fields']);
118 foreach($fields_req as $f)
119 $fields_ret[trim($f)] = true;
126 if($fields_ret['id'])
127 $entry['id'] = $rr['id'];
128 if($fields_ret['displayName'])
129 $entry['displayName'] = $rr['name'];
130 if($fields_ret['urls']) {
131 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
132 if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
133 $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
135 if($fields_ret['preferredUsername'])
136 $entry['preferredUsername'] = $rr['nick'];
137 if($fields_ret['photos'])
138 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
139 $ret['entry'][] = $entry;
143 $ret['entry'][] = array();
146 http_status_exit(500);
148 if($format === 'xml') {
149 header('Content-type: text/xml');
150 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
151 http_status_exit(500);
153 if($format === 'json') {
154 header('Content-type: application/json');
155 echo json_encode($ret);
159 http_status_exit(500);