3 function poco_init(&$a) {
4 require_once("include/bbcode.php");
8 if(intval(get_config('system','block_public')))
13 $user = notags(trim($a->argv[1]));
16 $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1");
18 http_status_exit(401);
22 $format = (($_GET['format']) ? $_GET['format'] : 'json');
26 if($a->argc > 2 && $a->argv[2] === '@me')
28 if($a->argc > 3 && $a->argv[3] === '@all')
30 if($a->argc > 3 && $a->argv[3] === '@self')
32 if($a->argc > 4 && intval($a->argv[4]) && $justme == false)
33 $cid = intval($a->argv[4]);
37 $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
38 where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
41 if(! count($r) || $r[0]['hidewall'] || $r[0]['hide-friends'])
42 http_status_exit(404);
48 $sql_extra = " AND `contact`.`self` = 1 ";
50 $sql_extra = " AND `contact`.`self` = 0 ";
53 $sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid));
56 $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
57 AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) ",
59 dbesc(NETWORK_DIASPORA),
60 dbesc(NETWORK_OSTATUS),
61 dbesc(NETWORK_STATUSNET)
65 $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
66 AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra",
69 dbesc(NETWORK_DIASPORA),
70 dbesc(NETWORK_OSTATUS),
71 dbesc(NETWORK_STATUSNET)
75 $totalResults = intval($r[0]['total']);
79 $startIndex = intval($_GET['startIndex']);
82 $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
86 $r = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation`, `profile`.`pub_keywords`, `profile`.`gender` AS `pgender`
87 FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
88 WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') AND `profile`.`is-default`
89 AND `contact`.`uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
91 dbesc(NETWORK_DIASPORA),
92 dbesc(NETWORK_OSTATUS),
93 dbesc(NETWORK_STATUSNET),
99 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
100 AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra LIMIT %d, %d",
101 intval($user['uid']),
103 dbesc(NETWORK_DIASPORA),
104 dbesc(NETWORK_OSTATUS),
105 dbesc(NETWORK_STATUSNET),
107 intval($itemsPerPage)
111 if(x($_GET,'sorted'))
112 $ret['sorted'] = 'false';
113 if(x($_GET,'filtered'))
114 $ret['filtered'] = 'false';
115 if(x($_GET,'updatedSince'))
116 $ret['updateSince'] = 'false';
118 $ret['startIndex'] = (string) $startIndex;
119 $ret['itemsPerPage'] = (string) $itemsPerPage;
120 $ret['totalResults'] = (string) $totalResults;
121 $ret['entry'] = array();
126 'displayName' => false,
129 'preferredUsername' => false,
132 'currentLocation' => false,
138 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
139 foreach($fields_ret as $k => $v)
140 $fields_ret[$k] = true;
142 $fields_req = explode(',',$_GET['fields']);
143 foreach($fields_req as $f)
144 $fields_ret[trim($f)] = true;
150 if (($rr['about'] == "") AND isset($rr['pabout']))
151 $rr['about'] = $rr['pabout'];
153 if (($rr['location'] == "") AND isset($rr['plocation']))
154 $rr['location'] = $rr['plocation'];
156 if (($rr['gender'] == "") AND isset($rr['pgender']))
157 $rr['gender'] = $rr['pgender'];
159 if (($rr['keywords'] == "") AND isset($rr['pub_keywords']))
160 $rr['keywords'] = $rr['pub_keywords'];
163 if($fields_ret['id'])
164 $entry['id'] = $rr['id'];
165 if($fields_ret['displayName'])
166 $entry['displayName'] = $rr['name'];
167 if($fields_ret['aboutMe'])
168 $entry['aboutMe'] = bbcode($rr['about'], false, false);
169 if($fields_ret['currentLocation'])
170 $entry['currentLocation'] = $rr['location'];
171 if($fields_ret['gender'])
172 $entry['gender'] = $rr['gender'];
173 if($fields_ret['urls']) {
174 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
175 if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
176 $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
178 if($fields_ret['preferredUsername'])
179 $entry['preferredUsername'] = $rr['nick'];
180 if($fields_ret['updated']) {
181 $entry['updated'] = $rr['success_update'];
183 if ($rr['name-date'] > $entry['updated'])
184 $entry['updated'] = $rr['name-date'];
186 if ($rr['uri-date'] > $entry['updated'])
187 $entry['updated'] = $rr['uri-date'];
189 if ($rr['avatar-date'] > $entry['updated'])
190 $entry['updated'] = $rr['avatar-date'];
192 $entry['updated'] = date("c", strtotime($entry['updated']));
194 if($fields_ret['photos'])
195 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
196 if($fields_ret['network']) {
197 $entry['network'] = $rr['network'];
198 if ($entry['network'] == NETWORK_STATUSNET)
199 $entry['network'] = NETWORK_OSTATUS;
200 if (($entry['network'] == "") AND ($rr['self']))
201 $entry['network'] = NETWORK_DFRN;
203 if($fields_ret['tags']) {
204 $tags = str_replace(","," ",$rr['keywords']);
205 $tags = explode(" ", $tags);
208 foreach ($tags as $tag) {
209 $tag = trim(strtolower($tag));
214 $entry['tags'] = array($cleaned);
217 $ret['entry'][] = $entry;
221 $ret['entry'][] = array();
224 http_status_exit(500);
226 if($format === 'xml') {
227 header('Content-type: text/xml');
228 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
231 if($format === 'json') {
232 header('Content-type: application/json');
233 echo json_encode($ret);
237 http_status_exit(500);