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\Database\DBA;
11 use Friendica\Model\Contact;
12 use Friendica\Model\Profile;
13 use Friendica\Util\Proxy as ProxyUtils;
14 use Friendica\Core\System;
16 function viewcontacts_init(App $a)
18 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
23 System::httpExit(403, ["title" => L10n::t('Access denied.')]);
26 Nav::setSelected('home');
29 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
33 if (!DBA::isResult($r)) {
37 $a->data['user'] = $r[0];
38 $a->profile_uid = $r[0]['uid'];
39 $is_owner = (local_user() && (local_user() == $a->profile_uid));
41 Profile::load($a, $a->argv[1]);
44 function viewcontacts_content(App $a)
46 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
47 notice(L10n::t('Public access denied.') . EOL);
51 $is_owner = $a->profile['profile_uid'] == local_user();
56 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
58 if (!count($a->profile) || $a->profile['hide-friends']) {
59 notice(L10n::t('Permission denied.') . EOL);
63 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
64 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
65 AND NOT `hidden` AND NOT `archive`
66 AND `network` IN ('%s', '%s', '%s')",
67 intval($a->profile['uid']),
68 DBA::escape(NETWORK_DFRN),
69 DBA::escape(NETWORK_DIASPORA),
70 DBA::escape(NETWORK_OSTATUS)
72 if (DBA::isResult($r)) {
73 $a->set_pager_total($r[0]['total']);
76 $r = q("SELECT * FROM `contact`
77 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
78 AND NOT `hidden` AND NOT `archive`
79 AND `network` IN ('%s', '%s', '%s')
80 ORDER BY `name` ASC LIMIT %d, %d",
81 intval($a->profile['uid']),
82 DBA::escape(NETWORK_DFRN),
83 DBA::escape(NETWORK_DIASPORA),
84 DBA::escape(NETWORK_OSTATUS),
85 intval($a->pager['start']),
86 intval($a->pager['itemspage'])
88 if (!DBA::isResult($r)) {
89 info(L10n::t('No contacts.').EOL);
96 /// @TODO This triggers an E_NOTICE if 'self' is not there
101 $contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr);
105 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']),
106 'photo_menu' => Contact::photoMenu($rr),
107 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
108 'name' => htmlentities(substr($contact_details['name'], 0, 20)),
109 'username' => htmlentities($contact_details['name']),
110 'details' => $contact_details['location'],
111 'tags' => $contact_details['keywords'],
112 'about' => $contact_details['about'],
113 'account_type' => Contact::getAccountType($contact_details),
114 'url' => Contact::magicLink($rr['url']),
116 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
117 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
122 $tpl = get_markup_template("viewcontact_template.tpl");
123 $o .= replace_macros($tpl, [
124 '$title' => L10n::t('Contacts'),
125 '$contacts' => $contacts,
126 '$paginate' => paginate($a),