3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model;
28 * This class handles GlobalContact related functions
33 * @param integer $uid id
34 * @param integer $cid id
38 public static function countCommonFriends($uid, $cid)
40 $sourceId = Contact::getPublicIdByUserId($uid);
42 $targetIds = Contact::getPublicAndUserContacID($cid, $uid);
45 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
49 return Contact\Relation::countCommonFollows($sourceId, $targetIds['public'] ?? 0, [], $condition);
53 * @param integer $uid id
54 * @param integer $zcid zcid
58 public static function countCommonFriendsZcid($uid, $zcid)
60 $sourceId = Contact::getPublicIdByUserId($uid);
62 $targetPublicContact = DI::dba()->fetchFirst("
65 JOIN `gcontact` z ON z.`nurl` = c.`nurl`
73 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
77 return Contact\Relation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0, [], $condition);
81 * Returns the cross-section between the local user contacts and one of their contact's own relationships
82 * as known by the local node.
84 * @param integer $uid local user id
85 * @param integer $cid user contact id to compare friends with
86 * @param integer $start optional, default 0
87 * @param integer $limit optional, default 9999
88 * @param boolean $shuffle optional, default false
92 public static function commonFriends($uid, $cid, $start = 0, $limit = 9999, $shuffle = false)
94 $sourceId = Contact::getPublicIdByUserId($uid);
96 $targetIds = Contact::getPublicAndUserContacID($cid, $uid);
99 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
103 return Contact\Relation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, [], $condition, $limit, $start, $shuffle);
107 * Returns the cross-section between a local user and a remote visitor contact's own relationships
108 * as known by the local node.
110 * @param integer $uid local user id
111 * @param integer $zcid remote visitor contact zcid
112 * @param integer $start optional, default 0
113 * @param integer $limit optional, default 9999
114 * @param boolean $shuffle optional, default false
118 public static function commonFriendsZcid($uid, $zcid, $start = 0, $limit = 9999, $shuffle = false)
120 $sourceId = Contact::getPublicIdByUserId($uid);
122 $targetPublicContact = DI::dba()->fetchFirst("
125 JOIN `gcontact` z ON z.`nurl` = c.`nurl`
133 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
137 return Contact\Relation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, [], $condition, $limit, $start, $shuffle);