]> git.mxchange.org Git - friendica.git/blob - mod/viewcontacts.php
Merge pull request #6977 from annando/fix-reshare
[friendica.git] / mod / viewcontacts.php
1 <?php
2 /**
3  * @file mod/viewcontacts.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Nav;
9 use Friendica\Content\Pager;
10 use Friendica\Core\Config;
11 use Friendica\Core\L10n;
12 use Friendica\Core\Protocol;
13 use Friendica\Core\Renderer;
14 use Friendica\Core\System;
15 use Friendica\Database\DBA;
16 use Friendica\Model\Contact;
17 use Friendica\Model\Profile;
18 use Friendica\Util\Proxy as ProxyUtils;
19
20 function viewcontacts_init(App $a)
21 {
22         if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
23                 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
24         }
25
26         if ($a->argc < 2) {
27                 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
28         }
29
30         Nav::setSelected('home');
31
32         $user = DBA::selectFirst('user', [], ['nickname' => $a->argv[1], 'blocked' => false]);
33         if (!DBA::isResult($user)) {
34                 System::httpExit(404, ["title" => L10n::t('Page not found.')]);
35         }
36
37         $a->data['user'] = $user;
38         $a->profile_uid  = $user['uid'];
39
40         Profile::load($a, $a->argv[1]);
41 }
42
43 function viewcontacts_content(App $a)
44 {
45         if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
46                 notice(L10n::t('Public access denied.') . EOL);
47                 return;
48         }
49
50         $is_owner = $a->profile['profile_uid'] == local_user();
51
52         // tabs
53         $o = Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
54
55         if (!count($a->profile) || $a->profile['hide-friends']) {
56                 notice(L10n::t('Permission denied.') . EOL);
57                 return $o;
58         }
59
60         $condition = [
61                 'uid'     => $a->profile['uid'],
62                 'blocked' => false,
63                 'pending' => false,
64                 'hidden'  => false,
65                 'archive' => false,
66                 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
67         ];
68
69         $total = DBA::count('contact', $condition);
70
71         $pager = new Pager($a->query_string);
72
73         $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
74
75         $contacts_stmt = DBA::select('contact', [], $condition, $params);
76
77         if (!DBA::isResult($contacts_stmt)) {
78                 info(L10n::t('No contacts.') . EOL);
79                 return $o;
80         }
81
82         $contacts = [];
83
84         while ($contact = DBA::fetch($contacts_stmt)) {
85                 /// @TODO This triggers an E_NOTICE if 'self' is not there
86                 if ($contact['self']) {
87                         continue;
88                 }
89
90                 $contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);
91
92                 $contacts[] = [
93                         'id'           => $contact['id'],
94                         'img_hover'    => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
95                         'photo_menu'   => Contact::photoMenu($contact),
96                         'thumb'        => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
97                         'name'         => substr($contact_details['name'], 0, 20),
98                         'username'     => $contact_details['name'],
99                         'details'      => $contact_details['location'],
100                         'tags'         => $contact_details['keywords'],
101                         'about'        => $contact_details['about'],
102                         'account_type' => Contact::getAccountType($contact_details),
103                         'url'          => Contact::magicLink($contact['url']),
104                         'sparkle'      => '',
105                         'itemurl'      => (($contact_details['addr'] != "") ? $contact_details['addr'] : $contact['url']),
106                         'network'      => ContactSelector::networkToName($contact['network'], $contact['url']),
107                 ];
108         }
109
110         DBA::close($contacts_stmt);
111
112         $tpl = Renderer::getMarkupTemplate("viewcontact_template.tpl");
113         $o .= Renderer::replaceMacros($tpl, [
114                 '$title'    => L10n::t('Contacts'),
115                 '$contacts' => $contacts,
116                 '$paginate' => $pager->renderFull($total),
117         ]);
118
119         return $o;
120 }