]> git.mxchange.org Git - friendica.git/blob - mod/common.php
little revision
[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' => $a->get_baseurl() . '/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 .= '<h2>' . t('Common Friends') . '</h2>';
45
46
47         if(! $cid) {
48                 if(get_my_url()) {
49                         $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
50                                 dbesc(normalise_link(get_my_url())),
51                                 intval($profile_uid)
52                         );
53                         if(count($r))
54                                 $cid = $r[0]['id'];
55                         else {
56                                 $r = q("select id from gcontact where nurl = '%s' limit 1",
57                                         dbesc(normalise_link(get_my_url()))
58                                 );
59                                 if(count($r))
60                                         $zcid = $r[0]['id'];
61                         }
62                 }
63         }
64
65
66
67         if($cid == 0 && $zcid == 0)
68                 return; 
69
70
71         if($cid)
72                 $t = count_common_friends($uid,$cid);
73         else
74                 $t = count_common_friends_zcid($uid,$zcid);
75
76
77         $a->set_pager_total($t);
78
79         if(! $t) {
80                 notice( t('No contacts in common.') . EOL);
81                 return $o;
82         }
83
84
85         if($cid)
86                 $r = common_friends($uid,$cid);
87         else
88                 $r = common_friends_zcid($uid,$zcid);
89
90
91         if(! count($r)) {
92                 return $o;
93         }
94
95         $tpl = get_markup_template('common_friends.tpl');
96
97         foreach($r as $rr) {
98                         
99                 $o .= replace_macros($tpl,array(
100                         '$url' => $rr['url'],
101                         '$name' => $rr['name'],
102                         '$photo' => $rr['photo'],
103                         '$tags' => ''
104                 ));
105         }
106
107         $o .= cleardiv();
108 //      $o .= paginate($a);
109         return $o;
110 }