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')",
72 intval($a->profile['uid']),
73 DBA::escape(Protocol::DFRN),
74 DBA::escape(Protocol::DIASPORA),
75 DBA::escape(Protocol::OSTATUS)
77 if (DBA::isResult($r)) {
78 $total = $r[0]['total'];
80 $pager = new Pager($a->query_string);
82 $r = q("SELECT * FROM `contact`
83 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
84 AND NOT `hidden` AND NOT `archive`
85 AND `network` IN ('%s', '%s', '%s')
86 ORDER BY `name` ASC LIMIT %d, %d",
87 intval($a->profile['uid']),
88 DBA::escape(Protocol::DFRN),
89 DBA::escape(Protocol::DIASPORA),
90 DBA::escape(Protocol::OSTATUS),
92 $pager->getItemsPerPage()
94 if (!DBA::isResult($r)) {
95 info(L10n::t('No contacts.').EOL);
101 foreach ($r as $rr) {
102 /// @TODO This triggers an E_NOTICE if 'self' is not there
107 $contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr);
111 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']),
112 'photo_menu' => Contact::photoMenu($rr),
113 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
114 'name' => htmlentities(substr($contact_details['name'], 0, 20)),
115 'username' => htmlentities($contact_details['name']),
116 'details' => $contact_details['location'],
117 'tags' => $contact_details['keywords'],
118 'about' => $contact_details['about'],
119 'account_type' => Contact::getAccountType($contact_details),
120 'url' => Contact::magicLink($rr['url']),
122 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
123 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
128 $tpl = Renderer::getMarkupTemplate("viewcontact_template.tpl");
129 $o .= Renderer::replaceMacros($tpl, [
130 '$title' => L10n::t('Contacts'),
131 '$contacts' => $contacts,
132 '$paginate' => $pager->renderFull($total),