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 ";
50 $sql_extra = sprintf(" and `contact`.`id` = %d ",intval($cid));
53 $r = q("SELECT count(*) as `total` from `contact` where self = 1
54 and uid in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = 1) ");
57 $r = q("SELECT count(*) as `total` from `contact` where `uid` = %d and blocked = 0 and pending = 0 and hidden = 0
63 $totalResults = intval($r[0]['total']);
67 $startIndex = intval($_GET['startIndex']);
70 $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
74 $r = q("SELECT * from contact where self = 1
75 and uid in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = 1) limit %d, %d ",
82 $r = q("SELECT * from `contact` where `uid` = %d and blocked = 0 and pending = 0 and hidden = 0
83 $sql_extra LIMIT %d, %d",
91 $ret['sorted'] = 'false';
92 if(x($_GET,'filtered'))
93 $ret['filtered'] = 'false';
94 if(x($_GET,'updatedSince'))
95 $ret['updateSince'] = 'false';
97 $ret['startIndex'] = (string) $startIndex;
98 $ret['itemsPerPage'] = (string) $itemsPerPage;
99 $ret['totalResults'] = (string) $totalResults;
100 $ret['entry'] = array();
105 'displayName' => false,
107 'preferredUsername' => false,
111 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
112 foreach($fields_ret as $k => $v)
113 $fields_ret[$k] = true;
115 $fields_req = explode(',',$_GET['fields']);
116 foreach($fields_req as $f)
117 $fields_ret[trim($f)] = true;
124 if($fields_ret['id'])
125 $entry['id'] = $rr['id'];
126 if($fields_ret['displayName'])
127 $entry['displayName'] = $rr['name'];
128 if($fields_ret['urls']) {
129 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
130 if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
131 $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
133 if($fields_ret['preferredUsername'])
134 $entry['preferredUsername'] = $rr['nick'];
135 if($fields_ret['photos'])
136 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
137 $ret['entry'][] = $entry;
141 $ret['entry'][] = array();
144 http_status_exit(500);
146 if($format === 'xml') {
147 header('Content-type: text/xml');
148 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
149 http_status_exit(500);
151 if($format === 'json') {
152 header('Content-type: application/json');
153 echo json_encode($ret);
157 http_status_exit(500);