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