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` FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
87 WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
88 AND `contact`.`uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
90 dbesc(NETWORK_DIASPORA),
91 dbesc(NETWORK_OSTATUS),
92 dbesc(NETWORK_STATUSNET),
98 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
99 AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra LIMIT %d, %d",
100 intval($user['uid']),
102 dbesc(NETWORK_DIASPORA),
103 dbesc(NETWORK_OSTATUS),
104 dbesc(NETWORK_STATUSNET),
106 intval($itemsPerPage)
110 if(x($_GET,'sorted'))
111 $ret['sorted'] = 'false';
112 if(x($_GET,'filtered'))
113 $ret['filtered'] = 'false';
114 if(x($_GET,'updatedSince'))
115 $ret['updateSince'] = 'false';
117 $ret['startIndex'] = (string) $startIndex;
118 $ret['itemsPerPage'] = (string) $itemsPerPage;
119 $ret['totalResults'] = (string) $totalResults;
120 $ret['entry'] = array();
125 'displayName' => false,
128 'preferredUsername' => false,
131 'currentLocation' => false,
135 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
136 foreach($fields_ret as $k => $v)
137 $fields_ret[$k] = true;
139 $fields_req = explode(',',$_GET['fields']);
140 foreach($fields_req as $f)
141 $fields_ret[trim($f)] = true;
147 if (($rr['about'] == "") AND isset($rr['pabout']))
148 $rr['about'] = $rr['pabout'];
150 if (($rr['location'] == "") AND isset($rr['plocation']))
151 $rr['location'] = $rr['plocation'];
154 if($fields_ret['id'])
155 $entry['id'] = $rr['id'];
156 if($fields_ret['displayName'])
157 $entry['displayName'] = $rr['name'];
158 if($fields_ret['aboutMe'])
159 $entry['aboutMe'] = bbcode($rr['about'], false, false);
160 if($fields_ret['currentLocation'])
161 $entry['currentLocation'] = $rr['location'];
162 if($fields_ret['urls']) {
163 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
164 if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
165 $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
167 if($fields_ret['preferredUsername'])
168 $entry['preferredUsername'] = $rr['nick'];
169 if($fields_ret['updated']) {
170 $entry['updated'] = $rr['success_update'];
172 if ($rr['name-date'] > $entry['updated'])
173 $entry['updated'] = $rr['name-date'];
175 if ($rr['uri-date'] > $entry['updated'])
176 $entry['updated'] = $rr['uri-date'];
178 if ($rr['avatar-date'] > $entry['updated'])
179 $entry['updated'] = $rr['avatar-date'];
181 $entry['updated'] = date("c", strtotime($entry['updated']));
183 if($fields_ret['photos'])
184 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
185 if($fields_ret['network']) {
186 $entry['network'] = $rr['network'];
187 if ($entry['network'] == NETWORK_STATUSNET)
188 $entry['network'] = NETWORK_OSTATUS;
189 if (($entry['network'] == "") AND ($rr['self']))
190 $entry['network'] = NETWORK_DFRN;
192 $ret['entry'][] = $entry;
196 $ret['entry'][] = array();
199 http_status_exit(500);
201 if($format === 'xml') {
202 header('Content-type: text/xml');
203 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
206 if($format === 'json') {
207 header('Content-type: application/json');
208 echo json_encode($ret);
212 http_status_exit(500);