]> git.mxchange.org Git - friendica.git/blob - mod/common.php
Bugfix: The user id wasn't fetched correctly.
[friendica.git] / mod / common.php
1 <?php
2
3 require_once('include/socgraph.php');
4
5 function common_content(&$a) {
6
7         $o = '';
8
9         $cmd = $a->argv[1];
10         $uid = intval($a->argv[2]);
11         $cid = intval($a->argv[3]);
12         $zcid = 0;
13
14         if($cmd !== 'loc' && $cmd != 'rem')
15                 return;
16         if(! $uid)
17                 return;
18
19         if($cmd === 'loc' && $cid) {    
20                 $c = q("select name, url, photo from contact where id = %d and uid = %d limit 1",
21                         intval($cid),
22                         intval($uid)
23                 );
24         }
25         else {
26                 $c = q("select name, url, photo from contact where self = 1 and uid = %d limit 1",
27                         intval($uid)
28                 );
29         }       
30
31         $vcard_widget .= replace_macros(get_markup_template("vcard-widget.tpl"),array(
32                 '$name' => $c[0]['name'],
33                 '$photo' => $c[0]['photo'],
34                 'url' => z_root() . '/contacts/' . $cid
35         ));
36
37         if(! x($a->page,'aside'))
38                 $a->page['aside'] = '';
39         $a->page['aside'] .= $vcard_widget;
40
41         if(! count($c))
42                 return;
43
44         $o .= replace_macros(get_markup_template("section_title.tpl"),array(
45                 '$title' => t('Common Friends')
46         ));
47
48
49         if(! $cid) {
50                 if(get_my_url()) {
51                         $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
52                                 dbesc(normalise_link(get_my_url())),
53                                 intval($profile_uid)
54                         );
55                         if(count($r))
56                                 $cid = $r[0]['id'];
57                         else {
58                                 $r = q("select id from gcontact where nurl = '%s' limit 1",
59                                         dbesc(normalise_link(get_my_url()))
60                                 );
61                                 if(count($r))
62                                         $zcid = $r[0]['id'];
63                         }
64                 }
65         }
66
67
68
69         if($cid == 0 && $zcid == 0)
70                 return; 
71
72
73         if($cid)
74                 $t = count_common_friends($uid,$cid);
75         else
76                 $t = count_common_friends_zcid($uid,$zcid);
77
78
79         $a->set_pager_total($t);
80
81         if(! $t) {
82                 notice( t('No contacts in common.') . EOL);
83                 return $o;
84         }
85
86
87         if($cid)
88                 $r = common_friends($uid,$cid);
89         else
90                 $r = common_friends_zcid($uid,$zcid);
91
92
93         if(! count($r)) {
94                 return $o;
95         }
96
97         $tpl = get_markup_template('common_friends.tpl');
98
99         foreach($r as $rr) {
100                         
101                 $o .= replace_macros($tpl,array(
102                         '$url' => $rr['url'],
103                         '$name' => $rr['name'],
104                         '$photo' => $rr['photo'],
105                         '$tags' => ''
106                 ));
107         }
108
109         $o .= cleardiv();
110 //      $o .= paginate($a);
111         return $o;
112 }