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 AND `network` IN ('%s', '%s', '%s', '%s', '')
56 AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) ",
58 dbesc(NETWORK_DIASPORA),
59 dbesc(NETWORK_OSTATUS),
60 dbesc(NETWORK_STATUSNET)
64 $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
65 AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra",
68 dbesc(NETWORK_DIASPORA),
69 dbesc(NETWORK_OSTATUS),
70 dbesc(NETWORK_STATUSNET)
74 $totalResults = intval($r[0]['total']);
78 $startIndex = intval($_GET['startIndex']);
81 $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
85 $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
86 AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
88 dbesc(NETWORK_DIASPORA),
89 dbesc(NETWORK_OSTATUS),
90 dbesc(NETWORK_STATUSNET),
96 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
97 AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra LIMIT %d, %d",
100 dbesc(NETWORK_DIASPORA),
101 dbesc(NETWORK_OSTATUS),
102 dbesc(NETWORK_STATUSNET),
104 intval($itemsPerPage)
108 if(x($_GET,'sorted'))
109 $ret['sorted'] = 'false';
110 if(x($_GET,'filtered'))
111 $ret['filtered'] = 'false';
112 if(x($_GET,'updatedSince'))
113 $ret['updateSince'] = 'false';
115 $ret['startIndex'] = (string) $startIndex;
116 $ret['itemsPerPage'] = (string) $itemsPerPage;
117 $ret['totalResults'] = (string) $totalResults;
118 $ret['entry'] = array();
123 'displayName' => false,
126 'preferredUsername' => false,
131 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
132 foreach($fields_ret as $k => $v)
133 $fields_ret[$k] = true;
135 $fields_req = explode(',',$_GET['fields']);
136 foreach($fields_req as $f)
137 $fields_ret[trim($f)] = true;
144 if($fields_ret['id'])
145 $entry['id'] = $rr['id'];
146 if($fields_ret['displayName'])
147 $entry['displayName'] = $rr['name'];
148 if($fields_ret['urls']) {
149 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
150 if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
151 $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
153 if($fields_ret['preferredUsername'])
154 $entry['preferredUsername'] = $rr['nick'];
155 if($fields_ret['updated']) {
156 $entry['updated'] = $rr['success_update'];
158 if ($rr['name-date'] > $entry['updated'])
159 $entry['updated'] = $rr['name-date'];
161 if ($rr['uri-date'] > $entry['updated'])
162 $entry['updated'] = $rr['uri-date'];
164 if ($rr['avatar-date'] > $entry['updated'])
165 $entry['updated'] = $rr['avatar-date'];
167 $entry['updated'] = date("c", strtotime($entry['updated']));
169 if($fields_ret['photos'])
170 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
171 if($fields_ret['network']) {
172 $entry['network'] = $rr['network'];
173 if ($entry['network'] == NETWORK_STATUSNET)
174 $entry['network'] = NETWORK_OSTATUS;
176 $ret['entry'][] = $entry;
180 $ret['entry'][] = array();
183 http_status_exit(500);
185 if($format === 'xml') {
186 header('Content-type: text/xml');
187 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
190 if($format === 'json') {
191 header('Content-type: application/json');
192 echo json_encode($ret);
196 http_status_exit(500);