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