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