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');
33 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
37 if (!DBA::isResult($r)) {
38 System::httpExit(404, ["title" => L10n::t('Page not found.')]);
41 $a->data['user'] = $r[0];
42 $a->profile_uid = $r[0]['uid'];
43 $is_owner = (local_user() && (local_user() == $a->profile_uid));
45 Profile::load($a, $a->argv[1]);
48 function viewcontacts_content(App $a)
50 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
51 notice(L10n::t('Public access denied.') . EOL);
55 $is_owner = $a->profile['profile_uid'] == local_user();
60 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
62 if (!count($a->profile) || $a->profile['hide-friends']) {
63 notice(L10n::t('Permission denied.') . EOL);
68 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
69 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
70 AND NOT `hidden` AND NOT `archive`
71 AND `network` IN ('%s', '%s', '%s', '%s')",
72 intval($a->profile['uid']),
73 DBA::escape(Protocol::ACTIVITYPUB),
74 DBA::escape(Protocol::DFRN),
75 DBA::escape(Protocol::DIASPORA),
76 DBA::escape(Protocol::OSTATUS)
78 if (DBA::isResult($r)) {
79 $total = $r[0]['total'];
81 $pager = new Pager($a->query_string);
83 $r = q("SELECT * FROM `contact`
84 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
85 AND NOT `hidden` AND NOT `archive`
86 AND `network` IN ('%s', '%s', '%s', '%s')
87 ORDER BY `name` ASC LIMIT %d, %d",
88 intval($a->profile['uid']),
89 DBA::escape(Protocol::ACTIVITYPUB),
90 DBA::escape(Protocol::DFRN),
91 DBA::escape(Protocol::DIASPORA),
92 DBA::escape(Protocol::OSTATUS),
94 $pager->getItemsPerPage()
96 if (!DBA::isResult($r)) {
97 info(L10n::t('No contacts.').EOL);
103 foreach ($r as $rr) {
104 /// @TODO This triggers an E_NOTICE if 'self' is not there
109 $contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr);
113 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']),
114 'photo_menu' => Contact::photoMenu($rr),
115 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
116 'name' => htmlentities(substr($contact_details['name'], 0, 20)),
117 'username' => htmlentities($contact_details['name']),
118 'details' => $contact_details['location'],
119 'tags' => $contact_details['keywords'],
120 'about' => $contact_details['about'],
121 'account_type' => Contact::getAccountType($contact_details),
122 'url' => Contact::magicLink($rr['url']),
124 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
125 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
130 $tpl = Renderer::getMarkupTemplate("viewcontact_template.tpl");
131 $o .= Renderer::replaceMacros($tpl, [
132 '$title' => L10n::t('Contacts'),
133 '$contacts' => $contacts,
134 '$paginate' => $pager->renderFull($total),