]> git.mxchange.org Git - friendica.git/blob - mod/viewcontacts.php
Merge pull request #1338 from annando/1501-global-contacts
[friendica.git] / mod / viewcontacts.php
1 <?php
2 require_once('include/contact_selectors.php');
3
4 function viewcontacts_init(&$a) {
5
6         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
7                 return;
8         }
9
10         profile_load($a,$a->argv[1]);
11 }
12
13
14 function viewcontacts_content(&$a) {
15
16         require_once("mod/proxy.php");
17
18         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
19                 notice( t('Public access denied.') . EOL);
20                 return;
21         }
22
23         if(((! count($a->profile)) || ($a->profile['hide-friends']))) {
24                 notice( t('Permission denied.') . EOL);
25                 return;
26         }
27
28
29         $r = q("SELECT COUNT(*) as `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ",
30                 intval($a->profile['uid'])
31         );
32         if(count($r))
33                 $a->set_pager_total($r[0]['total']);
34
35         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY `name` ASC LIMIT %d , %d ",
36                 intval($a->profile['uid']),
37                 intval($a->pager['start']),
38                 intval($a->pager['itemspage'])
39         );
40         if(! count($r)) {
41                 info( t('No contacts.') . EOL );
42                 return $o;
43         }
44
45         $contacts = array();
46
47         foreach($r as $rr) {
48                 if($rr['self'])
49                         continue;
50
51             $url = $rr['url'];
52
53                 // route DFRN profiles through the redirect
54
55                 $is_owner = ((local_user() && ($a->profile['profile_uid'] == local_user())) ? true : false);
56
57                 if($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel']))
58                         $url = 'redir/' . $rr['id'];
59                 else
60                         $url = zrl($url);
61
62                 $contacts[] = array(
63                         'id' => $rr['id'],
64                         'img_hover' => sprintf( t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']),
65                         'thumb' => proxy_url($rr['thumb']),
66                         'name' => substr($rr['name'],0,20),
67                         'username' => $rr['name'],
68                         'url' => $url,
69                         'sparkle' => '',
70                         'itemurl' => $rr['url'],
71                         'network' => network_to_name($rr['network']),
72                 );
73         }
74
75
76         $tpl = get_markup_template("viewcontact_template.tpl");
77         $o .= replace_macros($tpl, array(
78                 '$title' => t('View Contacts'),
79                 '$contacts' => $contacts,
80                 '$paginate' => paginate($a),
81         ));
82
83
84         return $o;
85 }