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