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