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\System;
14 use Friendica\Database\DBA;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Profile;
17 use Friendica\Util\Proxy as ProxyUtils;
19 function viewcontacts_init(App $a)
21 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
22 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
26 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
29 Nav::setSelected('home');
32 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
36 if (!DBA::isResult($r)) {
37 System::httpExit(404, ["title" => L10n::t('Page not found.')]);
40 $a->data['user'] = $r[0];
41 $a->profile_uid = $r[0]['uid'];
42 $is_owner = (local_user() && (local_user() == $a->profile_uid));
44 Profile::load($a, $a->argv[1]);
47 function viewcontacts_content(App $a)
49 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
50 notice(L10n::t('Public access denied.') . EOL);
54 $is_owner = $a->profile['profile_uid'] == local_user();
59 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
61 if (!count($a->profile) || $a->profile['hide-friends']) {
62 notice(L10n::t('Permission denied.') . EOL);
67 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
68 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
69 AND NOT `hidden` AND NOT `archive`
70 AND `network` IN ('%s', '%s', '%s')",
71 intval($a->profile['uid']),
72 DBA::escape(Protocol::DFRN),
73 DBA::escape(Protocol::DIASPORA),
74 DBA::escape(Protocol::OSTATUS)
76 if (DBA::isResult($r)) {
77 $total = $r[0]['total'];
79 $pager = new Pager($a->query_string);
81 $r = q("SELECT * FROM `contact`
82 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
83 AND NOT `hidden` AND NOT `archive`
84 AND `network` IN ('%s', '%s', '%s')
85 ORDER BY `name` ASC LIMIT %d, %d",
86 intval($a->profile['uid']),
87 DBA::escape(Protocol::DFRN),
88 DBA::escape(Protocol::DIASPORA),
89 DBA::escape(Protocol::OSTATUS),
91 $pager->getItemsPerPage()
93 if (!DBA::isResult($r)) {
94 info(L10n::t('No contacts.').EOL);
100 foreach ($r as $rr) {
101 /// @TODO This triggers an E_NOTICE if 'self' is not there
106 $contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr);
110 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']),
111 'photo_menu' => Contact::photoMenu($rr),
112 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
113 'name' => htmlentities(substr($contact_details['name'], 0, 20)),
114 'username' => htmlentities($contact_details['name']),
115 'details' => $contact_details['location'],
116 'tags' => $contact_details['keywords'],
117 'about' => $contact_details['about'],
118 'account_type' => Contact::getAccountType($contact_details),
119 'url' => Contact::magicLink($rr['url']),
121 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
122 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
127 $tpl = get_markup_template("viewcontact_template.tpl");
128 $o .= replace_macros($tpl, [
129 '$title' => L10n::t('Contacts'),
130 '$contacts' => $contacts,
131 '$paginate' => $pager->renderFull($total),