]> git.mxchange.org Git - friendica.git/blob - mod/common.php
Merge pull request #4035 from friendica/revert-4031-task/3878-move-objects-to-model
[friendica.git] / mod / common.php
1 <?php
2 /**
3  * @file include/common.php
4  */
5 use Friendica\App;
6 use Friendica\Database\DBM;
7 use Friendica\Model\GlobalContact;
8 use Friendica\Object\Contact;
9
10 require_once 'include/contact_selectors.php';
11 require_once 'mod/contacts.php';
12
13 function common_content(App $a) {
14
15         $o = '';
16
17         $cmd = $a->argv[1];
18         $uid = intval($a->argv[2]);
19         $cid = intval($a->argv[3]);
20         $zcid = 0;
21
22         if (! local_user()) {
23                 notice( t('Permission denied.') . EOL);
24                 return;
25         }
26
27         if ($cmd !== 'loc' && $cmd != 'rem') {
28                 return;
29         }
30
31         if (! $uid) {
32                 return;
33         }
34
35         if ($cmd === 'loc' && $cid) {
36                 $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
37                         intval($cid),
38                         intval($uid)
39                 );
40                 /// @TODO Handle $c with DBM::is_result()
41                 $a->page['aside'] = "";
42                 profile_load($a, "", 0, Contact::getDetailsByURL($c[0]["url"]));
43         } else {
44                 $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
45                         intval($uid)
46                 );
47                 /// @TODO Handle $c with DBM::is_result()
48
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) {
66                 if(get_my_url()) {
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 = GlobalContact::countCommonFriends($uid, $cid);
89         } else {
90                 $t = GlobalContact::countCommonFriendsZcid($uid, $zcid);
91         }
92
93         if (count($t)) {
94                 $a->set_pager_total($t);
95         } else {
96                 notice(t('No contacts in common.') . EOL);
97                 return $o;
98         }
99
100
101         if ($cid) {
102                 $r = GlobalContact::commonFriends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
103         } else {
104                 $r = GlobalContact::commonFriendsZcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
105         }
106
107
108         if (! DBM::is_result($r)) {
109                 return $o;
110         }
111
112         $id = 0;
113
114         foreach ($r as $rr) {
115
116                 //get further details of the contact
117                 $contact_details = Contact::getDetailsByURL($rr['url'], $uid);
118
119                 // $rr['id'] is needed to use contact_photo_menu()
120                 /// @TODO Adding '/" here avoids E_NOTICE on missing constants
121                 $rr['id'] = $rr['cid'];
122
123                 $photo_menu = '';
124                 $photo_menu = Contact::photoMenu($rr);
125
126                 $entry = array(
127                         'url'          => $rr['url'],
128                         'itemurl'      => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
129                         'name'         => $contact_details['name'],
130                         'thumb'        => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
131                         'img_hover'    => htmlentities($contact_details['name']),
132                         'details'      => $contact_details['location'],
133                         'tags'         => $contact_details['keywords'],
134                         'about'        => $contact_details['about'],
135                         'account_type' => Contact::getAccountType($contact_details),
136                         'network'      => network_to_name($contact_details['network'], $contact_details['url']),
137                         'photo_menu'   => $photo_menu,
138                         'id'           => ++$id,
139                 );
140                 $entries[] = $entry;
141         }
142
143         if ($cmd === 'loc' && $cid && $uid == local_user()) {
144                 $tab_str = contacts_tab($a, $cid, 4);
145         } else {
146                 $title = t('Common Friends');
147         }
148
149         $tpl = get_markup_template('viewcontact_template.tpl');
150
151         $o .= replace_macros($tpl,array(
152                 '$title'    => $title,
153                 '$tab_str'  => $tab_str,
154                 '$contacts' => $entries,
155                 '$paginate' => paginate($a),
156         ));
157
158         return $o;
159 }