3 * @file mod/viewcontacts.php
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;
17 function viewcontacts_init(App $a)
19 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
20 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
24 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
27 Nav::setSelected('home');
30 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
34 if (!DBA::isResult($r)) {
35 System::httpExit(404, ["title" => L10n::t('Page not found.')]);
38 $a->data['user'] = $r[0];
39 $a->profile_uid = $r[0]['uid'];
40 $is_owner = (local_user() && (local_user() == $a->profile_uid));
42 Profile::load($a, $a->argv[1]);
45 function viewcontacts_content(App $a)
47 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
48 notice(L10n::t('Public access denied.') . EOL);
52 $is_owner = $a->profile['profile_uid'] == local_user();
57 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
59 if (!count($a->profile) || $a->profile['hide-friends']) {
60 notice(L10n::t('Permission denied.') . EOL);
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)
73 if (DBA::isResult($r)) {
74 $a->set_pager_total($r[0]['total']);
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'])
89 if (!DBA::isResult($r)) {
90 info(L10n::t('No contacts.').EOL);
97 /// @TODO This triggers an E_NOTICE if 'self' is not there
102 $contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr);
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']),
117 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
118 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
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),