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