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