]> git.mxchange.org Git - friendica.git/blob - mod/viewcontacts.php
ping: cleanup
[friendica.git] / mod / viewcontacts.php
1 <?php
2 require_once('include/Contact.php');
3 require_once('include/contact_selectors.php');
4
5 function viewcontacts_init(&$a) {
6
7         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
8                 return;
9         }
10
11         nav_set_selected('home');
12
13         if($a->argc > 1) {
14                 $nick = $a->argv[1];
15                 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
16                         dbesc($nick)
17                 );
18
19                 if(! count($r))
20                         return;
21
22                 $a->data['user'] = $r[0];
23                 $a->profile_uid = $r[0]['uid'];
24                 $is_owner = (local_user() && (local_user() == $a->profile_uid));
25
26                 profile_load($a,$a->argv[1]);
27         }
28 }
29
30
31 function viewcontacts_content(&$a) {
32         require_once("mod/proxy.php");
33
34         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
35                 notice( t('Public access denied.') . EOL);
36                 return;
37         }
38
39         if(((! count($a->profile)) || ($a->profile['hide-friends']))) {
40                 notice( t('Permission denied.') . EOL);
41                 return;
42         }
43
44         $o = "";
45
46         // tabs
47         $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
48
49         $r = q("SELECT COUNT(*) AS `total` FROM `contact`
50                 WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
51                         AND `network` IN ('%s', '%s', '%s')",
52                 intval($a->profile['uid']),
53                 dbesc(NETWORK_DFRN),
54                 dbesc(NETWORK_DIASPORA),
55                 dbesc(NETWORK_OSTATUS)
56         );
57         if(count($r))
58                 $a->set_pager_total($r[0]['total']);
59
60         $r = q("SELECT * FROM `contact`
61                 WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
62                         AND `network` IN ('%s', '%s', '%s')
63                 ORDER BY `name` ASC LIMIT %d, %d",
64                 intval($a->profile['uid']),
65                 dbesc(NETWORK_DFRN),
66                 dbesc(NETWORK_DIASPORA),
67                 dbesc(NETWORK_OSTATUS),
68                 intval($a->pager['start']),
69                 intval($a->pager['itemspage'])
70         );
71         if(!count($r)) {
72                 info(t('No contacts.').EOL);
73                 return $o;
74         }
75
76         $contacts = array();
77
78         foreach($r as $rr) {
79                 if($rr['self'])
80                         continue;
81
82                 $url = $rr['url'];
83
84                 // route DFRN profiles through the redirect
85
86                 $is_owner = ((local_user() && ($a->profile['profile_uid'] == local_user())) ? true : false);
87
88                 if($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel']))
89                         $url = 'redir/' . $rr['id'];
90                 else
91                         $url = zrl($url);
92
93                 $contact_details = get_contact_details_by_url($rr['url'], $a->profile['uid']);
94
95                 $contacts[] = array(
96                         'id' => $rr['id'],
97                         'img_hover' => sprintf( t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']),
98                         'photo_menu' => contact_photo_menu($rr),
99                         'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
100                         'name' => htmlentities(substr($rr['name'],0,20)),
101                         'username' => htmlentities($rr['name']),
102                         'details'       => $contact_details['location'],
103                         'tags'          => $contact_details['keywords'],
104                         'about'         => $contact_details['about'],
105                         'account_type'  => (($contact_details['community']) ? t('Forum') : ''),
106                         'url' => $url,
107                         'sparkle' => '',
108                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
109                         'network' => network_to_name($rr['network'], $rr['url']),
110                 );
111         }
112
113
114         $tpl = get_markup_template("viewcontact_template.tpl");
115         $o .= replace_macros($tpl, array(
116                 '$title' => t('Contacts'),
117                 '$contacts' => $contacts,
118                 '$paginate' => paginate($a),
119         ));
120
121
122         return $o;
123 }