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;
14 use Friendica\Util\Proxy as ProxyUtils;
15 use Friendica\Util\Strings;
17 require_once 'include/dba.php';
19 function common_content(App $a)
24 $uid = intval($a->argv[2]);
25 $cid = intval($a->argv[3]);
29 notice(L10n::t('Permission denied.') . EOL);
33 if ($cmd !== 'loc' && $cmd != 'rem') {
41 if ($cmd === 'loc' && $cid) {
42 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => $uid]);
44 if (DBA::isResult($contact)) {
45 $a->page['aside'] = "";
46 Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
49 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['self' => true, 'uid' => $uid]);
51 if (DBA::isResult($contact)) {
52 $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate("vcard-widget.tpl"), [
53 '$name' => htmlentities($contact['name']),
54 '$photo' => $contact['photo'],
55 'url' => 'contact/' . $cid
58 if (!x($a->page, 'aside')) {
59 $a->page['aside'] = '';
61 $a->page['aside'] .= $vcard_widget;
65 if (!DBA::isResult($contact)) {
69 if (!$cid && Model\Profile::getMyURL()) {
70 $contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL()), 'uid' => $uid]);
71 if (DBA::isResult($contact)) {
72 $cid = $contact['id'];
74 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL())]);
75 if (DBA::isResult($gcontact)) {
76 $zcid = $gcontact['id'];
81 if ($cid == 0 && $zcid == 0) {
86 $total = Model\GContact::countCommonFriends($uid, $cid);
88 $total = Model\GContact::countCommonFriendsZcid($uid, $zcid);
92 notice(L10n::t('No contacts in common.') . EOL);
96 $pager = new Pager($a->query_string);
99 $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());
101 $common_friends = Model\GContact::commonFriendsZcid($uid, $zcid, $pager->getStart(), $pager->getItemsPerPage());
104 if (!DBA::isResult($common_friends)) {
111 foreach ($common_friends as $common_friend) {
112 //get further details of the contact
113 $contact_details = Model\Contact::getDetailsByURL($common_friend['url'], $uid);
115 // $rr['id'] is needed to use contact_photo_menu()
116 /// @TODO Adding '/" here avoids E_NOTICE on missing constants
117 $common_friend['id'] = $common_friend['cid'];
119 $photo_menu = Model\Contact::photoMenu($common_friend);
122 'url' => $common_friend['url'],
123 'itemurl' => defaults($contact_details, 'addr', $common_friend['url']),
124 'name' => $contact_details['name'],
125 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
126 'img_hover' => htmlentities($contact_details['name']),
127 'details' => $contact_details['location'],
128 'tags' => $contact_details['keywords'],
129 'about' => $contact_details['about'],
130 'account_type' => Model\Contact::getAccountType($contact_details),
131 'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
132 'photo_menu' => $photo_menu,
140 if ($cmd === 'loc' && $cid && local_user() == $uid) {
141 $tab_str = Module\Contact::getTabsHTML($a, $contact, 4);
143 $title = L10n::t('Common Friends');
146 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
148 $o .= Renderer::replaceMacros($tpl, [
150 '$tab_str' => $tab_str,
151 '$contacts' => $entries,
152 '$paginate' => $pager->renderFull($total),