]> git.mxchange.org Git - friendica.git/blob - mod/common.php
Merge pull request #1338 from annando/1501-global-contacts
[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         $a->page['aside'] .= '<div class="vcard">' 
32                 . '<div class="fn label">' . $c[0]['name'] . '</div>' 
33                 . '<div id="profile-photo-wrapper">'
34                 . '<img class="photo" width="175" height="175" 
35                 src="' . $c[0]['photo'] . '" alt="' . $c[0]['name'] . '" /></div>'
36                 . '</div>';
37         
38
39         if(! count($c))
40                 return;
41
42         $o .= '<h2>' . t('Common Friends') . '</h2>';
43
44
45         if(! $cid) {
46                 if(get_my_url()) {
47                         $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
48                                 dbesc(normalise_link(get_my_url())),
49                                 intval($profile_uid)
50                         );
51                         if(count($r))
52                                 $cid = $r[0]['id'];
53                         else {
54                                 $r = q("select id from gcontact where nurl = '%s' limit 1",
55                                         dbesc(normalise_link(get_my_url()))
56                                 );
57                                 if(count($r))
58                                         $zcid = $r[0]['id'];
59                         }
60                 }
61         }
62
63
64
65         if($cid == 0 && $zcid == 0)
66                 return; 
67
68
69         if($cid)
70                 $t = count_common_friends($uid,$cid);
71         else
72                 $t = count_common_friends_zcid($uid,$zcid);
73
74
75         $a->set_pager_total($t);
76
77         if(! $t) {
78                 notice( t('No contacts in common.') . EOL);
79                 return $o;
80         }
81
82
83         if($cid)
84                 $r = common_friends($uid,$cid);
85         else
86                 $r = common_friends_zcid($uid,$zcid);
87
88
89         if(! count($r)) {
90                 return $o;
91         }
92
93         $tpl = get_markup_template('common_friends.tpl');
94
95         foreach($r as $rr) {
96                         
97                 $o .= replace_macros($tpl,array(
98                         '$url' => $rr['url'],
99                         '$name' => $rr['name'],
100                         '$photo' => $rr['photo'],
101                         '$tags' => ''
102                 ));
103         }
104
105         $o .= cleardiv();
106 //      $o .= paginate($a);
107         return $o;
108 }