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