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