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 function common_content(App $a)
22 $uid = intval($a->argv[2]);
23 $cid = intval($a->argv[3]);
27 notice(L10n::t('Permission denied.') . EOL);
31 if ($cmd !== 'loc' && $cmd != 'rem') {
39 if ($cmd === 'loc' && $cid) {
40 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => $uid]);
42 if (DBA::isResult($contact)) {
43 $a->page['aside'] = "";
44 Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
47 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['self' => true, 'uid' => $uid]);
49 if (DBA::isResult($contact)) {
50 $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate("vcard-widget.tpl"), [
51 '$name' => $contact['name'],
52 '$photo' => $contact['photo'],
53 'url' => 'contact/' . $cid
56 if (empty($a->page['aside'])) {
57 $a->page['aside'] = '';
59 $a->page['aside'] .= $vcard_widget;
63 if (!DBA::isResult($contact)) {
67 if (!$cid && Model\Profile::getMyURL()) {
68 $contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL()), 'uid' => $uid]);
69 if (DBA::isResult($contact)) {
70 $cid = $contact['id'];
72 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL())]);
73 if (DBA::isResult($gcontact)) {
74 $zcid = $gcontact['id'];
79 if ($cid == 0 && $zcid == 0) {
84 $total = Model\GContact::countCommonFriends($uid, $cid);
86 $total = Model\GContact::countCommonFriendsZcid($uid, $zcid);
90 notice(L10n::t('No contacts in common.') . EOL);
94 $pager = new Pager($a->query_string);
97 $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());
99 $common_friends = Model\GContact::commonFriendsZcid($uid, $zcid, $pager->getStart(), $pager->getItemsPerPage());
102 if (!DBA::isResult($common_friends)) {
109 foreach ($common_friends as $common_friend) {
110 //get further details of the contact
111 $contact_details = Model\Contact::getDetailsByURL($common_friend['url'], $uid);
113 // $rr['id'] is needed to use contact_photo_menu()
114 /// @TODO Adding '/" here avoids E_NOTICE on missing constants
115 $common_friend['id'] = $common_friend['cid'];
117 $photo_menu = Model\Contact::photoMenu($common_friend);
120 'url' => Model\Contact::magicLink($common_friend['url']),
121 'itemurl' => defaults($contact_details, 'addr', $common_friend['url']),
122 'name' => $contact_details['name'],
123 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
124 'img_hover' => $contact_details['name'],
125 'details' => $contact_details['location'],
126 'tags' => $contact_details['keywords'],
127 'about' => $contact_details['about'],
128 'account_type' => Model\Contact::getAccountType($contact_details),
129 'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
130 'photo_menu' => $photo_menu,
138 if ($cmd === 'loc' && $cid && local_user() == $uid) {
139 $tab_str = Module\Contact::getTabsHTML($a, $contact, 4);
141 $title = L10n::t('Common Friends');
144 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
146 $o .= Renderer::replaceMacros($tpl, [
148 '$tab_str' => $tab_str,
149 '$contacts' => $entries,
150 '$paginate' => $pager->renderFull($total),