]> git.mxchange.org Git - friendica.git/blob - mod/common.php
Fixes:
[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\Core\L10n;
9 use Friendica\Database\DBA;
10 use Friendica\Database\DBM;
11 use Friendica\Model\Contact;
12 use Friendica\Model\GContact;
13 use Friendica\Model\Profile;
14
15 require_once 'include/dba.php';
16 require_once 'mod/contacts.php';
17
18 function common_content(App $a)
19 {
20         $o = '';
21
22         $cmd = $a->argv[1];
23         $uid = intval($a->argv[2]);
24         $cid = intval($a->argv[3]);
25         $zcid = 0;
26
27         if (!local_user()) {
28                 notice(L10n::t('Permission denied.') . EOL);
29                 return;
30         }
31
32         if ($cmd !== 'loc' && $cmd != 'rem') {
33                 return;
34         }
35
36         if (!$uid) {
37                 return;
38         }
39
40         if ($cmd === 'loc' && $cid) {
41                 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo'], ['id' => $cid, 'uid' => $uid]);
42
43                 if (DBM::is_result($contact)) {
44                         $a->page['aside'] = "";
45                         Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
46                 }
47         } else {
48                 $contact = DBA::selectFirst('contact', ['name', 'url', 'photo'], ['self' => true, 'uid' => $uid]);
49
50                 if (DBM::is_result($contact)) {
51                         $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [
52                                 '$name' => htmlentities($contact['name']),
53                                 '$photo' => $contact['photo'],
54                                 'url' => 'contacts/' . $cid
55                         ]);
56
57                         if (!x($a->page, 'aside')) {
58                                 $a->page['aside'] = '';
59                         }
60                         $a->page['aside'] .= $vcard_widget;
61                 }
62         }
63
64         if (!DBM::is_result($contact)) {
65                 return;
66         }
67
68         if (!$cid && Profile::getMyURL()) {
69                 $contact = DBA::selectFirst('contact', ['id'], ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $uid]);
70                 if (DBM::is_result($contact)) {
71                         $cid = $contact['id'];
72                 } else {
73                         $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
74                         if (DBM::is_result($gcontact)) {
75                                 $zcid = $gcontact['id'];
76                         }
77                 }
78         }
79
80         if ($cid == 0 && $zcid == 0) {
81                 return;
82         }
83
84         if ($cid) {
85                 $t = GContact::countCommonFriends($uid, $cid);
86         } else {
87                 $t = GContact::countCommonFriendsZcid($uid, $zcid);
88         }
89
90         if ($t > 0) {
91                 $a->set_pager_total($t);
92         } else {
93                 notice(L10n::t('No contacts in common.') . EOL);
94                 return $o;
95         }
96
97         if ($cid) {
98                 $r = GContact::commonFriends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
99         } else {
100                 $r = GContact::commonFriendsZcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
101         }
102
103         if (!DBM::is_result($r)) {
104                 return $o;
105         }
106
107         $id = 0;
108
109         $entries = [];
110         foreach ($r as $rr) {
111                 //get further details of the contact
112                 $contact_details = Contact::getDetailsByURL($rr['url'], $uid);
113
114                 // $rr['id'] is needed to use contact_photo_menu()
115                 /// @TODO Adding '/" here avoids E_NOTICE on missing constants
116                 $rr['id'] = $rr['cid'];
117
118                 $photo_menu = Contact::photoMenu($rr);
119
120                 $entry = [
121                         'url'          => $rr['url'],
122                         'itemurl'      => defaults($contact_details, 'addr', $rr['url']),
123                         'name'         => $contact_details['name'],
124                         'thumb'        => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
125                         'img_hover'    => htmlentities($contact_details['name']),
126                         'details'      => $contact_details['location'],
127                         'tags'         => $contact_details['keywords'],
128                         'about'        => $contact_details['about'],
129                         'account_type' => Contact::getAccountType($contact_details),
130                         'network'      => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
131                         'photo_menu'   => $photo_menu,
132                         'id'           => ++$id,
133                 ];
134                 $entries[] = $entry;
135         }
136
137         $title = '';
138         $tab_str = '';
139         if ($cmd === 'loc' && $cid && local_user() == $uid) {
140                 $tab_str = contacts_tab($a, $cid, 4);
141         } else {
142                 $title = L10n::t('Common Friends');
143         }
144
145         $tpl = get_markup_template('viewcontact_template.tpl');
146
147         $o .= replace_macros($tpl, [
148                 '$title'    => $title,
149                 '$tab_str'  => $tab_str,
150                 '$contacts' => $entries,
151                 '$paginate' => paginate($a),
152         ]);
153
154         return $o;
155 }