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 * FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
87 AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
89 dbesc(NETWORK_DIASPORA),
90 dbesc(NETWORK_OSTATUS),
91 dbesc(NETWORK_STATUSNET),
97 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
98 AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra LIMIT %d, %d",
101 dbesc(NETWORK_DIASPORA),
102 dbesc(NETWORK_OSTATUS),
103 dbesc(NETWORK_STATUSNET),
105 intval($itemsPerPage)
109 if(x($_GET,'sorted'))
110 $ret['sorted'] = 'false';
111 if(x($_GET,'filtered'))
112 $ret['filtered'] = 'false';
113 if(x($_GET,'updatedSince'))
114 $ret['updateSince'] = 'false';
116 $ret['startIndex'] = (string) $startIndex;
117 $ret['itemsPerPage'] = (string) $itemsPerPage;
118 $ret['totalResults'] = (string) $totalResults;
119 $ret['entry'] = array();
124 'displayName' => false,
127 'preferredUsername' => false,
130 'currentLocation' => false,
134 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
135 foreach($fields_ret as $k => $v)
136 $fields_ret[$k] = true;
138 $fields_req = explode(',',$_GET['fields']);
139 foreach($fields_req as $f)
140 $fields_ret[trim($f)] = true;
147 if($fields_ret['id'])
148 $entry['id'] = $rr['id'];
149 if($fields_ret['displayName'])
150 $entry['displayName'] = $rr['name'];
151 if($fields_ret['aboutMe'])
152 $entry['aboutMe'] = bbcode($rr['about'], false, false);
153 if($fields_ret['currentLocation'])
154 $entry['currentLocation'] = $rr['location'];
155 if($fields_ret['urls']) {
156 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
157 if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
158 $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
160 if($fields_ret['preferredUsername'])
161 $entry['preferredUsername'] = $rr['nick'];
162 if($fields_ret['updated']) {
163 $entry['updated'] = $rr['success_update'];
165 if ($rr['name-date'] > $entry['updated'])
166 $entry['updated'] = $rr['name-date'];
168 if ($rr['uri-date'] > $entry['updated'])
169 $entry['updated'] = $rr['uri-date'];
171 if ($rr['avatar-date'] > $entry['updated'])
172 $entry['updated'] = $rr['avatar-date'];
174 $entry['updated'] = date("c", strtotime($entry['updated']));
176 if($fields_ret['photos'])
177 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
178 if($fields_ret['network']) {
179 $entry['network'] = $rr['network'];
180 if ($entry['network'] == NETWORK_STATUSNET)
181 $entry['network'] = NETWORK_OSTATUS;
182 if (($entry['network'] == "") AND ($rr['self']))
183 $entry['network'] = NETWORK_DFRN;
185 $ret['entry'][] = $entry;
189 $ret['entry'][] = array();
192 http_status_exit(500);
194 if($format === 'xml') {
195 header('Content-type: text/xml');
196 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
199 if($format === 'json') {
200 header('Content-type: application/json');
201 echo json_encode($ret);
205 http_status_exit(500);