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