3 * @file include/common.php
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Pager;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Database\DBA;
15 use Friendica\Util\Proxy as ProxyUtils;
16 use Friendica\Util\Strings;
18 function common_content(App $a)
23 $uid = intval($a->argv[2]);
24 $cid = intval($a->argv[3]);
28 notice(L10n::t('Permission denied.') . EOL);
32 if ($cmd !== 'loc' && $cmd != 'rem') {
40 if ($cmd === 'loc' && $cid) {
41 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => $uid]);
43 if (DBA::isResult($contact)) {
44 DI::page()['aside'] = "";
45 Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
48 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['self' => true, 'uid' => $uid]);
50 if (DBA::isResult($contact)) {
51 $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate("widget/vcard.tpl"), [
52 '$name' => $contact['name'],
53 '$photo' => $contact['photo'],
54 'url' => 'contact/' . $cid
57 if (empty(DI::page()['aside'])) {
58 DI::page()['aside'] = '';
60 DI::page()['aside'] .= $vcard_widget;
64 if (!DBA::isResult($contact)) {
68 if (!$cid && Model\Profile::getMyURL()) {
69 $contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL()), 'uid' => $uid]);
70 if (DBA::isResult($contact)) {
71 $cid = $contact['id'];
73 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL())]);
74 if (DBA::isResult($gcontact)) {
75 $zcid = $gcontact['id'];
80 if ($cid == 0 && $zcid == 0) {
85 $total = Model\GContact::countCommonFriends($uid, $cid);
87 $total = Model\GContact::countCommonFriendsZcid($uid, $zcid);
91 notice(L10n::t('No contacts in common.') . EOL);
95 $pager = new Pager(DI::args()->getQueryString());
98 $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());
100 $common_friends = Model\GContact::commonFriendsZcid($uid, $zcid, $pager->getStart(), $pager->getItemsPerPage());
103 if (!DBA::isResult($common_friends)) {
110 foreach ($common_friends as $common_friend) {
111 //get further details of the contact
112 $contact_details = Model\Contact::getDetailsByURL($common_friend['url'], $uid);
114 // $rr['id'] is needed to use contact_photo_menu()
115 /// @TODO Adding '/" here avoids E_NOTICE on missing constants
116 $common_friend['id'] = $common_friend['cid'];
118 $photo_menu = Model\Contact::photoMenu($common_friend);
121 'url' => Model\Contact::magicLink($common_friend['url']),
122 'itemurl' => ($contact_details['addr'] ?? '') ?: $common_friend['url'],
123 'name' => $contact_details['name'],
124 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
125 'img_hover' => $contact_details['name'],
126 'details' => $contact_details['location'],
127 'tags' => $contact_details['keywords'],
128 'about' => $contact_details['about'],
129 'account_type' => Model\Contact::getAccountType($contact_details),
130 'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
131 'photo_menu' => $photo_menu,
139 if ($cmd === 'loc' && $cid && local_user() == $uid) {
140 $tab_str = Module\Contact::getTabsHTML($a, $contact, 5);
142 $title = L10n::t('Common Friends');
145 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
147 $o .= Renderer::replaceMacros($tpl, [
149 '$tab_str' => $tab_str,
150 '$contacts' => $entries,
151 '$paginate' => $pager->renderFull($total),