]> git.mxchange.org Git - friendica.git/blob - mod/viewcontacts.php
Merge pull request #2104 from rabuzarus/2611_contacts_directory
[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         profile_load($a,$a->argv[1]);
12 }
13
14
15 function viewcontacts_content(&$a) {
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`
30                 WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
31                         AND `network` IN ('%s', '%s', '%s')",
32                 intval($a->profile['uid']),
33                 dbesc(NETWORK_DFRN),
34                 dbesc(NETWORK_DIASPORA),
35                 dbesc(NETWORK_OSTATUS)
36         );
37         if(count($r))
38                 $a->set_pager_total($r[0]['total']);
39
40         $r = q("SELECT * FROM `contact`
41                 WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
42                         AND `network` IN ('%s', '%s', '%s')
43                 ORDER BY `name` ASC LIMIT %d, %d",
44                 intval($a->profile['uid']),
45                 dbesc(NETWORK_DFRN),
46                 dbesc(NETWORK_DIASPORA),
47                 dbesc(NETWORK_OSTATUS),
48                 intval($a->pager['start']),
49                 intval($a->pager['itemspage'])
50         );
51         if(!count($r)) {
52                 info(t('No contacts.').EOL);
53                 return $o;
54         }
55
56         $contacts = array();
57
58         foreach($r as $rr) {
59                 if($rr['self'])
60                         continue;
61
62                 $url = $rr['url'];
63
64                 // route DFRN profiles through the redirect
65
66                 $is_owner = ((local_user() && ($a->profile['profile_uid'] == local_user())) ? true : false);
67
68                 if($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel']))
69                         $url = 'redir/' . $rr['id'];
70                 else
71                         $url = zrl($url);
72
73                 $contact_details = get_contact_details_by_url($rr['url'], $a->profile['uid']);
74
75                 $contacts[] = array(
76                         'id' => $rr['id'],
77                         'img_hover' => sprintf( t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']),
78                         'photo_menu' => contact_photo_menu($rr),
79                         'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
80                         'name' => htmlentities(substr($rr['name'],0,20)),
81                         'username' => htmlentities($rr['name']),
82                         'details'       => $contact_details['location'],
83                         'tags'          => $contact_details['keywords'],
84                         'about'         => $contact_details['about'],
85                         'account_type'  => (($contact_details['community']) ? t('Forum') : ''),
86                         'url' => $url,
87                         'sparkle' => '',
88                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
89                         'network' => network_to_name($rr['network'], $rr['url']),
90                 );
91         }
92
93
94         $tpl = get_markup_template("viewcontact_template.tpl");
95         $o .= replace_macros($tpl, array(
96                 '$title' => t('View Contacts'),
97                 '$contacts' => $contacts,
98                 '$paginate' => paginate($a),
99         ));
100
101
102         return $o;
103 }