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', '')
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)
63 $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
64 AND `network` IN ('%s', '%s', '%s', '') $sql_extra",
67 dbesc(NETWORK_DIASPORA),
68 dbesc(NETWORK_OSTATUS)
72 $totalResults = intval($r[0]['total']);
76 $startIndex = intval($_GET['startIndex']);
79 $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
83 $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '')
84 AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
86 dbesc(NETWORK_DIASPORA),
87 dbesc(NETWORK_OSTATUS),
93 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
94 AND `network` IN ('%s', '%s', '%s', '') $sql_extra LIMIT %d, %d",
97 dbesc(NETWORK_DIASPORA),
98 dbesc(NETWORK_OSTATUS),
100 intval($itemsPerPage)
104 if(x($_GET,'sorted'))
105 $ret['sorted'] = 'false';
106 if(x($_GET,'filtered'))
107 $ret['filtered'] = 'false';
108 if(x($_GET,'updatedSince'))
109 $ret['updateSince'] = 'false';
111 $ret['startIndex'] = (string) $startIndex;
112 $ret['itemsPerPage'] = (string) $itemsPerPage;
113 $ret['totalResults'] = (string) $totalResults;
114 $ret['entry'] = array();
119 'displayName' => false,
122 'preferredUsername' => false,
126 if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
127 foreach($fields_ret as $k => $v)
128 $fields_ret[$k] = true;
130 $fields_req = explode(',',$_GET['fields']);
131 foreach($fields_req as $f)
132 $fields_ret[trim($f)] = true;
139 if($fields_ret['id'])
140 $entry['id'] = $rr['id'];
141 if($fields_ret['displayName'])
142 $entry['displayName'] = $rr['name'];
143 if($fields_ret['urls']) {
144 $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
145 if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
146 $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
148 if($fields_ret['preferredUsername'])
149 $entry['preferredUsername'] = $rr['nick'];
150 if($fields_ret['updated']) {
151 $entry['updated'] = $rr['success_update'];
153 if ($rr['name-date'] > $entry['updated'])
154 $entry['updated'] = $rr['name-date'];
156 if ($rr['uri-date'] > $entry['updated'])
157 $entry['updated'] = $rr['uri-date'];
159 if ($rr['avatar-date'] > $entry['updated'])
160 $entry['updated'] = $rr['avatar-date'];
162 $entry['updated'] = date("c", strtotime($entry['updated']));
164 if($fields_ret['photos'])
165 $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
166 $ret['entry'][] = $entry;
170 $ret['entry'][] = array();
173 http_status_exit(500);
175 if($format === 'xml') {
176 header('Content-type: text/xml');
177 echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
180 if($format === 'json') {
181 header('Content-type: application/json');
182 echo json_encode($ret);
186 http_status_exit(500);