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/>.
23 use Friendica\Content\ContactSelector;
24 use Friendica\Content\Pager;
25 use Friendica\Core\Renderer;
26 use Friendica\Database\DBA;
30 use Friendica\Util\Proxy as ProxyUtils;
31 use Friendica\Util\Strings;
33 function common_content(App $a)
38 $uid = intval($a->argv[2]);
39 $cid = intval($a->argv[3]);
43 notice(DI::l10n()->t('Permission denied.'));
47 if ($cmd !== 'loc' && $cmd != 'rem') {
55 if ($cmd === 'loc' && $cid) {
56 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => $uid]);
58 if (DBA::isResult($contact)) {
59 DI::page()['aside'] = "";
60 Model\Profile::load($a, "", Model\Contact::getByURL($contact["url"], false));
63 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['self' => true, 'uid' => $uid]);
65 if (DBA::isResult($contact)) {
66 $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
67 '$name' => $contact['name'],
68 '$photo' => $contact['photo'],
69 'url' => 'contact/' . $cid
72 if (empty(DI::page()['aside'])) {
73 DI::page()['aside'] = '';
75 DI::page()['aside'] .= $vcard_widget;
79 if (!DBA::isResult($contact)) {
83 if (!$cid && Model\Profile::getMyURL()) {
84 $contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL()), 'uid' => $uid]);
85 if (DBA::isResult($contact)) {
86 $cid = $contact['id'];
88 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL())]);
89 if (DBA::isResult($gcontact)) {
90 $zcid = $gcontact['id'];
95 if ($cid == 0 && $zcid == 0) {
100 $total = Model\GContact::countCommonFriends($uid, $cid);
102 $total = Model\GContact::countCommonFriendsZcid($uid, $zcid);
106 notice(DI::l10n()->t('No contacts in common.'));
110 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
113 $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());
115 $common_friends = Model\GContact::commonFriendsZcid($uid, $zcid, $pager->getStart(), $pager->getItemsPerPage());
118 if (!DBA::isResult($common_friends)) {
125 foreach ($common_friends as $common_friend) {
126 //get further details of the contact
127 $contact_details = Model\Contact::getByURLForUser($common_friend['url'], $uid);
129 // $rr['id'] is needed to use contact_photo_menu()
130 /// @TODO Adding '/" here avoids E_NOTICE on missing constants
131 $common_friend['id'] = $common_friend['cid'];
133 $photo_menu = Model\Contact::photoMenu($common_friend);
136 'url' => Model\Contact::magicLink($common_friend['url']),
137 'itemurl' => ($contact_details['addr'] ?? '') ?: $common_friend['url'],
138 'name' => $contact_details['name'],
139 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
140 'img_hover' => $contact_details['name'],
141 'details' => $contact_details['location'],
142 'tags' => $contact_details['keywords'],
143 'about' => $contact_details['about'],
144 'account_type' => Model\Contact::getAccountType($contact_details),
145 'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
146 'photo_menu' => $photo_menu,
154 if ($cmd === 'loc' && $cid && local_user() == $uid) {
155 $tab_str = Module\Contact::getTabsHTML($a, $contact, 5);
157 $title = DI::l10n()->t('Common Friends');
160 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
162 $o .= Renderer::replaceMacros($tpl, [
164 '$tab_str' => $tab_str,
165 '$contacts' => $entries,
166 '$paginate' => $pager->renderFull($total),