3 * @file mod/viewcontacts.php
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;
20 function viewcontacts_init(App $a)
22 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
23 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
27 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
30 Nav::setSelected('home');
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.')]);
37 $a->data['user'] = $user;
38 $a->profile_uid = $user['uid'];
40 Profile::load($a, $a->argv[1]);
43 function viewcontacts_content(App $a)
45 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
46 notice(L10n::t('Public access denied.') . EOL);
50 $is_owner = $a->profile['profile_uid'] == local_user();
53 $o = Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
55 if (!count($a->profile) || $a->profile['hide-friends']) {
56 notice(L10n::t('Permission denied.') . EOL);
61 'uid' => $a->profile['uid'],
66 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
69 $total = DBA::count('contact', $condition);
71 $pager = new Pager($a->query_string);
73 $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
75 $contacts_stmt = DBA::select('contact', [], $condition, $params);
77 if (!DBA::isResult($contacts_stmt)) {
78 info(L10n::t('No contacts.') . EOL);
84 while ($contact = DBA::fetch($contacts_stmt)) {
85 /// @TODO This triggers an E_NOTICE if 'self' is not there
86 if ($contact['self']) {
90 $contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);
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']),
105 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $contact['url']),
106 'network' => ContactSelector::networkToName($contact['network'], $contact['url']),
110 DBA::close($contacts_stmt);
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),