- if ($a->argc > 1 && $a->argv[1] === '@global') {
- // List of all profiles that this server recently had data from
- $global = true;
- $update_limit = date(DateTimeFormat::MYSQL, time() - 30 * 86400);
- }
- if ($a->argc > 2 && $a->argv[2] === '@me') {
- $justme = true;
- }
- if ($a->argc > 3 && $a->argv[3] === '@all') {
- $justme = false;
- }
- if ($a->argc > 3 && $a->argv[3] === '@self') {
- $justme = true;
- }
- if ($a->argc > 4 && intval($a->argv[4]) && $justme == false) {
- $cid = intval($a->argv[4]);
- }
-
- if (! $system_mode && ! $global) {
- $users = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
- where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
- DBA::escape($user)
- );
- if (! DBA::isResult($users) || $users[0]['hidewall'] || $users[0]['hide-friends']) {
- System::httpExit(404);
- }
-
- $user = $users[0];
- }
-
- if ($justme) {
- $sql_extra = " AND `contact`.`self` = 1 ";
- } else {
- $sql_extra = "";
- }
-
- if (!empty($cid)) {
- $sql_extra = sprintf(" AND `contact`.`id` = %d ", intval($cid));
- }
- if (x($_GET, 'updatedSince')) {
- $update_limit = date(DateTimeFormat::MYSQL, strtotime($_GET['updatedSince']));
- }
- if ($global) {
- $contacts = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND NOT `hide` AND `network` IN ('%s', '%s', '%s')",
- DBA::escape($update_limit),
- DBA::escape(Protocol::DFRN),
- DBA::escape(Protocol::DIASPORA),
- DBA::escape(Protocol::OSTATUS)
- );
- } elseif ($system_mode) {
- $contacts = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1
- AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) ");
- } else {
- $contacts = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
- AND (`success_update` >= `failure_update` OR `last-item` >= `failure_update`)
- AND `network` IN ('%s', '%s', '%s', '%s') $sql_extra",
- intval($user['uid']),
- DBA::escape(Protocol::DFRN),
- DBA::escape(Protocol::DIASPORA),
- DBA::escape(Protocol::OSTATUS),
- DBA::escape(Protocol::STATUSNET)
- );
- }
- if (DBA::isResult($contacts)) {
- $totalResults = intval($contacts[0]['total']);
- } else {
- $totalResults = 0;
- }