- /**
- * Returns ungrouped contact count or list for user
- *
- * Returns either the total number of ungrouped contacts for the given user
- * id or a paginated list of ungrouped contacts.
- *
- * @param int $uid uid
- * @return array
- * @throws \Exception
- */
- public static function getUngroupedList($uid)
- {
- return q("SELECT *
- FROM `contact`
- WHERE `uid` = %d
- AND NOT `self`
- AND NOT `deleted`
- AND NOT `blocked`
- AND NOT `pending`
- AND `id` NOT IN (
- SELECT DISTINCT(`contact-id`)
- FROM `group_member`
- INNER JOIN `group` ON `group`.`id` = `group_member`.`gid`
- WHERE `group`.`uid` = %d
- )", intval($uid), intval($uid));
- }
-
- /**
- * Have a look at all contact tables for a given profile url.
- * This function works as a replacement for probing the contact.
- *
- * @param string $url Contact URL
- * @param integer $cid Contact ID
- *
- * @return array Contact array in the "probe" structure
- */
- private static function getProbeDataFromDatabase($url, $cid = null)
- {
- // The link could be provided as http although we stored it as https
- $ssl_url = str_replace('http://', 'https://', $url);
-
- $fields = ['id', 'uid', 'url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
- 'photo', 'keywords', 'location', 'about', 'network',
- 'priority', 'batch', 'request', 'confirm', 'poco'];
-
- if (!empty($cid)) {
- $data = DBA::selectFirst('contact', $fields, ['id' => $cid]);
- if (DBA::isResult($data)) {
- return $data;
- }
- }
-
- $data = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url)]);
-
- if (!DBA::isResult($data)) {
- $condition = ['alias' => [$url, Strings::normaliseLink($url), $ssl_url]];
- $data = DBA::selectFirst('contact', $fields, $condition);
- }
-
- if (DBA::isResult($data)) {
- // For security reasons we don't fetch key data from our users
- $data["pubkey"] = '';
- return $data;
- }
-
- $fields = ['url', 'addr', 'alias', 'notify', 'name', 'nick',
- 'photo', 'keywords', 'location', 'about', 'network'];
- $condition = ['alias' => [$url, Strings::normaliseLink($url), $ssl_url]];
- $data = DBA::selectFirst('contact', $fields, $condition);
-
- if (DBA::isResult($data)) {
- $data["pubkey"] = '';
- $data["poll"] = '';
- $data["priority"] = 0;
- $data["batch"] = '';
- $data["request"] = '';
- $data["confirm"] = '';
- $data["poco"] = '';
- return $data;
- }
-
- $data = ActivityPub::probeProfile($url, false);
- if (!empty($data)) {
- return $data;
- }
-
- $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
- 'photo', 'network', 'priority', 'batch', 'request', 'confirm'];
- $data = DBA::selectFirst('fcontact', $fields, ['url' => $url]);
-
- if (!DBA::isResult($data)) {
- $condition = ['alias' => [$url, Strings::normaliseLink($url), $ssl_url]];
- $data = DBA::selectFirst('contact', $fields, $condition);
- }
-
- if (DBA::isResult($data)) {
- $data["pubkey"] = '';
- $data["keywords"] = '';
- $data["location"] = '';
- $data["about"] = '';
- $data["poco"] = '';
- return $data;
- }
-
- return [];
- }
-