3 namespace Friendica\Module\Profile;
5 use Friendica\BaseModule;
6 use Friendica\Content\ContactSelector;
7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Core\Protocol;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\Session;
12 use Friendica\Database\DBA;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Profile;
16 use Friendica\Util\Proxy as ProxyUtils;
18 class Contacts extends BaseModule
20 public static function content(array $parameters = [])
22 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
23 throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
28 //@TODO: Get value from router parameters
29 $nickname = $a->argv[1];
30 $type = ($a->argv[3] ?? '') ?: 'all';
32 Nav::setSelected('home');
34 $user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
35 if (!DBA::isResult($user)) {
36 throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
39 $a->profile_uid = $user['uid'];
41 Profile::load($a, $nickname);
43 $is_owner = $a->profile['uid'] == local_user();
46 $o = Profile::getTabs($a, 'contacts', $is_owner, $nickname);
48 if (!count($a->profile) || $a->profile['hide-friends']) {
49 notice(DI::l10n()->t('Permission denied.') . EOL);
54 'uid' => $a->profile['uid'],
59 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
63 case 'followers': $condition['rel'] = [1, 3]; break;
64 case 'following': $condition['rel'] = [2, 3]; break;
65 case 'mutuals': $condition['rel'] = 3; break;
68 $total = DBA::count('contact', $condition);
70 $pager = new Pager(DI::args()->getQueryString());
72 $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
74 $contacts_stmt = DBA::select('contact', [], $condition, $params);
76 if (!DBA::isResult($contacts_stmt)) {
77 info(DI::l10n()->t('No contacts.') . EOL);
83 while ($contact = DBA::fetch($contacts_stmt)) {
84 if ($contact['self']) {
88 $contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);
91 'id' => $contact['id'],
92 'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
93 'photo_menu' => Contact::photoMenu($contact),
94 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
95 'name' => substr($contact_details['name'], 0, 20),
96 'username' => $contact_details['name'],
97 'details' => $contact_details['location'],
98 'tags' => $contact_details['keywords'],
99 'about' => $contact_details['about'],
100 'account_type' => Contact::getAccountType($contact_details),
101 'url' => Contact::magicLink($contact['url']),
103 'itemurl' => $contact_details['addr'] ? : $contact['url'],
104 'network' => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol']),
108 DBA::close($contacts_stmt);
111 case 'followers': $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total); break;
112 case 'following': $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total); break;
113 case 'mutuals': $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total); break;
115 case 'all': default: $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total); break;
118 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
119 $o .= Renderer::replaceMacros($tpl, [
121 '$nickname' => $nickname,
124 '$all_label' => DI::l10n()->t('All contacts'),
125 '$followers_label' => DI::l10n()->t('Followers'),
126 '$following_label' => DI::l10n()->t('Following'),
127 '$mutuals_label' => DI::l10n()->t('Mutual friends'),
129 '$contacts' => $contacts,
130 '$paginate' => $pager->renderFull($total),