]> git.mxchange.org Git - friendica.git/blob - mod/viewcontacts.php
Yeah, and again notices ... (#5536)
[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\DBA;
11 use Friendica\Model\Contact;
12 use Friendica\Model\Profile;
13 use Friendica\Util\Proxy as ProxyUtils;
14 use Friendica\Core\System;
15
16 function viewcontacts_init(App $a)
17 {
18         if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
19                 return;
20         }
21
22         if ($a->argc < 2) {
23                 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
24         }
25
26         Nav::setSelected('home');
27
28         $nick = $a->argv[1];
29         $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
30                 DBA::escape($nick)
31         );
32
33         if (!DBA::isResult($r)) {
34                 return;
35         }
36
37         $a->data['user'] = $r[0];
38         $a->profile_uid = $r[0]['uid'];
39         $is_owner = (local_user() && (local_user() == $a->profile_uid));
40
41         Profile::load($a, $a->argv[1]);
42 }
43
44 function viewcontacts_content(App $a)
45 {
46         if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
47                 notice(L10n::t('Public access denied.') . EOL);
48                 return;
49         }
50
51         $is_owner = $a->profile['profile_uid'] == local_user();
52
53         $o = "";
54
55         // tabs
56         $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
57
58         if (!count($a->profile) || $a->profile['hide-friends']) {
59                 notice(L10n::t('Permission denied.') . EOL);
60                 return $o;
61         }
62
63         $r = q("SELECT COUNT(*) AS `total` FROM `contact`
64                 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
65                         AND NOT `hidden` AND NOT `archive`
66                         AND `network` IN ('%s', '%s', '%s')",
67                 intval($a->profile['uid']),
68                 DBA::escape(NETWORK_DFRN),
69                 DBA::escape(NETWORK_DIASPORA),
70                 DBA::escape(NETWORK_OSTATUS)
71         );
72         if (DBA::isResult($r)) {
73                 $a->set_pager_total($r[0]['total']);
74         }
75
76         $r = q("SELECT * FROM `contact`
77                 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
78                         AND NOT `hidden` AND NOT `archive`
79                         AND `network` IN ('%s', '%s', '%s')
80                 ORDER BY `name` ASC LIMIT %d, %d",
81                 intval($a->profile['uid']),
82                 DBA::escape(NETWORK_DFRN),
83                 DBA::escape(NETWORK_DIASPORA),
84                 DBA::escape(NETWORK_OSTATUS),
85                 intval($a->pager['start']),
86                 intval($a->pager['itemspage'])
87         );
88         if (!DBA::isResult($r)) {
89                 info(L10n::t('No contacts.').EOL);
90                 return $o;
91         }
92
93         $contacts = [];
94
95         foreach ($r as $rr) {
96                 /// @TODO This triggers an E_NOTICE if 'self' is not there
97                 if ($rr['self']) {
98                         continue;
99                 }
100
101                 $contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr);
102
103                 $contacts[] = [
104                         'id' => $rr['id'],
105                         'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']),
106                         'photo_menu' => Contact::photoMenu($rr),
107                         'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::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'  => Contact::getAccountType($contact_details),
114                         'url' => Contact::magicLink($rr['url']),
115                         'sparkle' => '',
116                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
117                         'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
118                 ];
119         }
120
121
122         $tpl = get_markup_template("viewcontact_template.tpl");
123         $o .= replace_macros($tpl, [
124                 '$title' => L10n::t('Contacts'),
125                 '$contacts' => $contacts,
126                 '$paginate' => paginate($a),
127         ]);
128
129         return $o;
130 }