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