]> git.mxchange.org Git - friendica.git/blob - mod/common.php
Merge pull request #6977 from annando/fix-reshare
[friendica.git] / mod / common.php
1 <?php
2 /**
3  * @file include/common.php
4  */
5
6 use Friendica\App;
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;
12 use Friendica\Model;
13 use Friendica\Module;
14 use Friendica\Util\Proxy as ProxyUtils;
15 use Friendica\Util\Strings;
16
17 function common_content(App $a)
18 {
19         $o = '';
20
21         $cmd = $a->argv[1];
22         $uid = intval($a->argv[2]);
23         $cid = intval($a->argv[3]);
24         $zcid = 0;
25
26         if (!local_user()) {
27                 notice(L10n::t('Permission denied.') . EOL);
28                 return;
29         }
30
31         if ($cmd !== 'loc' && $cmd != 'rem') {
32                 return;
33         }
34
35         if (!$uid) {
36                 return;
37         }
38
39         if ($cmd === 'loc' && $cid) {
40                 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => $uid]);
41
42                 if (DBA::isResult($contact)) {
43                         $a->page['aside'] = "";
44                         Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
45                 }
46         } else {
47                 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['self' => true, 'uid' => $uid]);
48
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
54                         ]);
55
56                         if (empty($a->page['aside'])) {
57                                 $a->page['aside'] = '';
58                         }
59                         $a->page['aside'] .= $vcard_widget;
60                 }
61         }
62
63         if (!DBA::isResult($contact)) {
64                 return;
65         }
66
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'];
71                 } else {
72                         $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL())]);
73                         if (DBA::isResult($gcontact)) {
74                                 $zcid = $gcontact['id'];
75                         }
76                 }
77         }
78
79         if ($cid == 0 && $zcid == 0) {
80                 return;
81         }
82
83         if ($cid) {
84                 $total = Model\GContact::countCommonFriends($uid, $cid);
85         } else {
86                 $total = Model\GContact::countCommonFriendsZcid($uid, $zcid);
87         }
88
89         if ($total < 1) {
90                 notice(L10n::t('No contacts in common.') . EOL);
91                 return $o;
92         }
93
94         $pager = new Pager($a->query_string);
95
96         if ($cid) {
97                 $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());
98         } else {
99                 $common_friends = Model\GContact::commonFriendsZcid($uid, $zcid, $pager->getStart(), $pager->getItemsPerPage());
100         }
101
102         if (!DBA::isResult($common_friends)) {
103                 return $o;
104         }
105
106         $id = 0;
107
108         $entries = [];
109         foreach ($common_friends as $common_friend) {
110                 //get further details of the contact
111                 $contact_details = Model\Contact::getDetailsByURL($common_friend['url'], $uid);
112
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'];
116
117                 $photo_menu = Model\Contact::photoMenu($common_friend);
118
119                 $entry = [
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,
131                         'id'           => ++$id,
132                 ];
133                 $entries[] = $entry;
134         }
135
136         $title = '';
137         $tab_str = '';
138         if ($cmd === 'loc' && $cid && local_user() == $uid) {
139                 $tab_str = Module\Contact::getTabsHTML($a, $contact, 4);
140         } else {
141                 $title = L10n::t('Common Friends');
142         }
143
144         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
145
146         $o .= Renderer::replaceMacros($tpl, [
147                 '$title'    => $title,
148                 '$tab_str'  => $tab_str,
149                 '$contacts' => $entries,
150                 '$paginate' => $pager->renderFull($total),
151         ]);
152
153         return $o;
154 }