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\Pager;
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
29 use Friendica\Util\Strings;
31 function common_content(App $a)
36 $uid = intval($a->argv[2]);
37 $cid = intval($a->argv[3]);
41 notice(DI::l10n()->t('Permission denied.'));
45 if ($cmd !== 'loc' && $cmd != 'rem') {
53 if ($cmd === 'loc' && $cid) {
54 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => $uid]);
56 if (DBA::isResult($contact)) {
57 DI::page()['aside'] = "";
58 Model\Profile::load($a, "", Model\Contact::getByURL($contact["url"], false));
61 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['self' => true, 'uid' => $uid]);
63 if (DBA::isResult($contact)) {
64 $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
65 '$name' => $contact['name'],
66 '$photo' => $contact['photo'],
67 'url' => 'contact/' . $cid
70 if (empty(DI::page()['aside'])) {
71 DI::page()['aside'] = '';
73 DI::page()['aside'] .= $vcard_widget;
77 if (!DBA::isResult($contact)) {
81 if (!$cid && Model\Profile::getMyURL()) {
82 $contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL()), 'uid' => $uid]);
83 if (DBA::isResult($contact)) {
84 $cid = $contact['id'];
86 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL())]);
87 if (DBA::isResult($gcontact)) {
88 $zcid = $gcontact['id'];
93 if ($cid == 0 && $zcid == 0) {
98 $total = Model\GContact::countCommonFriends($uid, $cid);
100 $total = Model\GContact::countCommonFriendsZcid($uid, $zcid);
104 notice(DI::l10n()->t('No contacts in common.'));
108 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
111 $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());
113 $common_friends = Model\GContact::commonFriendsZcid($uid, $zcid, $pager->getStart(), $pager->getItemsPerPage());
116 if (!DBA::isResult($common_friends)) {
122 if ($cmd === 'loc' && $cid && local_user() == $uid) {
123 $tab_str = Module\Contact::getTabsHTML($a, $contact, 5);
125 $title = DI::l10n()->t('Common Friends');
129 foreach ($common_friends as $common_friend) {
130 $contact = Model\Contact::getByURLForUser($common_friend['url'], local_user());
131 if (!empty($contact)) {
132 $entries[] = Module\Contact::getContactTemplateVars($contact);
136 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
138 $o .= Renderer::replaceMacros($tpl, [
140 '$tab_str' => $tab_str,
141 '$contacts' => $entries,
142 '$paginate' => $pager->renderFull($total),