]> git.mxchange.org Git - friendica.git/blob - mod/common.php
Merge branch 'develop' into rewrites/dbm_is_result
[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         if(! $uid)
26                 return;
27
28         if($cmd === 'loc' && $cid) {
29                 $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
30                         intval($cid),
31                         intval($uid)
32                 );
33                 $a->page['aside'] = "";
34                 profile_load($a, "", 0, get_contact_details_by_url($c[0]["url"]));
35         } else {
36                 $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
37                         intval($uid)
38                 );
39
40                 $vcard_widget .= replace_macros(get_markup_template("vcard-widget.tpl"),array(
41                         '$name' => htmlentities($c[0]['name']),
42                         '$photo' => $c[0]['photo'],
43                         'url' => 'contacts/' . $cid
44                 ));
45
46                 if(! x($a->page,'aside'))
47                         $a->page['aside'] = '';
48                 $a->page['aside'] .= $vcard_widget;
49         }
50
51         if (! dbm::is_result($c)) {
52                 return;
53         }
54
55         if(! $cid) {
56                 if(get_my_url()) {
57                         $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
58                                 dbesc(normalise_link(get_my_url())),
59                                 intval($profile_uid)
60                         );
61                         if (dbm::is_result($r))
62                                 $cid = $r[0]['id'];
63                         else {
64                                 $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
65                                         dbesc(normalise_link(get_my_url()))
66                                 );
67                                 if (dbm::is_result($r))
68                                         $zcid = $r[0]['id'];
69                         }
70                 }
71         }
72
73
74
75         if($cid == 0 && $zcid == 0)
76                 return;
77
78
79         if($cid)
80                 $t = count_common_friends($uid, $cid);
81         else
82                 $t = count_common_friends_zcid($uid, $zcid);
83
84         if(count($t))
85                 $a->set_pager_total($t);
86         else {
87                 notice( t('No contacts in common.') . EOL);
88                 return $o;
89         }
90
91
92         if($cid)
93                 $r = common_friends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
94         else
95                 $r = common_friends_zcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
96
97
98         if (! dbm::is_result($r)) {
99                 return $o;
100         }
101
102         $id = 0;
103
104         foreach ($r as $rr) {
105
106                 //get further details of the contact
107                 $contact_details = get_contact_details_by_url($rr['url'], $uid);
108
109                 // $rr[id] is needed to use contact_photo_menu()
110                 $rr[id] = $rr[cid];
111
112                 $photo_menu = '';
113                 $photo_menu = contact_photo_menu($rr);
114
115                 $entry = array(
116                         'url'           => $rr['url'],
117                         'itemurl'       => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
118                         'name'          => $contact_details['name'],
119                         'thumb'         => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
120                         'img_hover'     => htmlentities($contact_details['name']),
121                         'details'       => $contact_details['location'],
122                         'tags'          => $contact_details['keywords'],
123                         'about'         => $contact_details['about'],
124                         'account_type'  => account_type($contact_details),
125                         'network'       => network_to_name($contact_details['network'], $contact_details['url']),
126                         'photo_menu'    => $photo_menu,
127                         'id'            => ++$id,
128                 );
129                 $entries[] = $entry;
130         }
131
132         if($cmd === 'loc' && $cid && $uid == local_user()) {
133                 $tab_str = contacts_tab($a, $cid, 4);
134         } else
135                 $title = t('Common Friends');
136
137         $tpl = get_markup_template('viewcontact_template.tpl');
138
139         $o .= replace_macros($tpl,array(
140                 '$title' => $title,
141                 '$tab_str' => $tab_str,
142                 '$contacts' => $entries,
143                 '$paginate' => paginate($a),
144         ));
145
146         return $o;
147 }