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\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\Renderer;
13 use Friendica\Core\Session;
14 use Friendica\Database\DBA;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Profile;
17 use Friendica\Util\Proxy as ProxyUtils;
19 class Contacts extends BaseModule
21 public static function content(array $parameters = [])
23 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
24 throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
29 //@TODO: Get value from router parameters
30 $nickname = $a->argv[1];
31 $type = ($a->argv[3] ?? '') ?: 'all';
33 Nav::setSelected('home');
35 $user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
36 if (!DBA::isResult($user)) {
37 throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
40 $a->profile_uid = $user['uid'];
42 Profile::load($a, $nickname);
44 $is_owner = $a->profile['profile_uid'] == local_user();
47 $o = Profile::getTabs($a, 'contacts', $is_owner, $nickname);
49 if (!count($a->profile) || $a->profile['hide-friends']) {
50 notice(L10n::t('Permission denied.') . EOL);
55 'uid' => $a->profile['uid'],
60 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
64 case 'followers': $condition['rel'] = [1, 3]; break;
65 case 'following': $condition['rel'] = [2, 3]; break;
66 case 'mutuals': $condition['rel'] = 3; break;
69 $total = DBA::count('contact', $condition);
71 $pager = new Pager($a->query_string);
73 $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
75 $contacts_stmt = DBA::select('contact', [], $condition, $params);
77 if (!DBA::isResult($contacts_stmt)) {
78 info(L10n::t('No contacts.') . EOL);
84 while ($contact = DBA::fetch($contacts_stmt)) {
85 if ($contact['self']) {
89 $contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);
92 'id' => $contact['id'],
93 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
94 'photo_menu' => Contact::photoMenu($contact),
95 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
96 'name' => substr($contact_details['name'], 0, 20),
97 'username' => $contact_details['name'],
98 'details' => $contact_details['location'],
99 'tags' => $contact_details['keywords'],
100 'about' => $contact_details['about'],
101 'account_type' => Contact::getAccountType($contact_details),
102 'url' => Contact::magicLink($contact['url']),
104 'itemurl' => $contact_details['addr'] ? : $contact['url'],
105 'network' => ContactSelector::networkToName($contact['network'], $contact['url']),
109 DBA::close($contacts_stmt);
112 case 'followers': $title = L10n::tt('Follower (%s)', 'Followers (%s)', $total); break;
113 case 'following': $title = L10n::tt('Following (%s)', 'Following (%s)', $total); break;
114 case 'mutuals': $title = L10n::tt('Mutual friend (%s)', 'Mutual friends (%s)', $total); break;
116 case 'all': default: $title = L10n::tt('Contact (%s)', 'Contacts (%s)', $total); break;
119 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
120 $o .= Renderer::replaceMacros($tpl, [
122 '$nickname' => $nickname,
125 '$all_label' => L10n::t('All contacts'),
126 '$followers_label' => L10n::t('Followers'),
127 '$following_label' => L10n::t('Following'),
128 '$mutuals_label' => L10n::t('Mutual friends'),
130 '$contacts' => $contacts,
131 '$paginate' => $pager->renderFull($total),