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 and archive = 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 and archive = 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,
110 'preferredUsername' => false,
114 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
115 foreach($fields_ret as $k => $v)
116 $fields_ret[$k] = true;
118 $fields_req = explode(',',$_GET['fields']);
119 foreach($fields_req as $f)
120 $fields_ret[trim($f)] = true;
127 if($fields_ret['id'])
128 $entry['id'] = $rr['id'];
129 if($fields_ret['displayName'])
130 $entry['displayName'] = $rr['name'];
131 if($fields_ret['urls']) {
132 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
133 if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
134 $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
136 if($fields_ret['preferredUsername'])
137 $entry['preferredUsername'] = $rr['nick'];
138 if($fields_ret['updated']) {
139 $entry['updated'] = $rr['success_update'];
141 if ($rr['name-date'] > $entry['updated'])
142 $entry['updated'] = $rr['name-date'];
144 if ($rr['uri-date'] > $entry['updated'])
145 $entry['updated'] = $rr['uri-date'];
147 if ($rr['avatar-date'] > $entry['updated'])
148 $entry['updated'] = $rr['avatar-date'];
150 $entry['updated'] = date("c", strtotime($entry['updated']));
152 if($fields_ret['photos'])
153 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
154 $ret['entry'][] = $entry;
158 $ret['entry'][] = array();
161 http_status_exit(500);
163 if($format === 'xml') {
164 header('Content-type: text/xml');
165 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
168 if($format === 'json') {
169 header('Content-type: application/json');
170 echo json_encode($ret);
174 http_status_exit(500);