3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Profile;
24 use Friendica\Content\ContactSelector;
25 use Friendica\Content\Nav;
26 use Friendica\Content\Pager;
27 use Friendica\Core\Protocol;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Session;
30 use Friendica\Database\DBA;
32 use Friendica\Model\Contact;
33 use Friendica\Model\Profile;
34 use Friendica\Module\BaseProfile;
36 class Contacts extends BaseProfile
38 public static function content(array $parameters = [])
40 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
41 throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
46 //@TODO: Get value from router parameters
47 $nickname = $a->argv[1];
48 $type = ($a->argv[3] ?? '') ?: 'all';
50 Nav::setSelected('home');
52 $user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
53 if (!DBA::isResult($user)) {
54 throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
57 $a->profile_uid = $user['uid'];
59 Profile::load($a, $nickname);
61 $is_owner = $a->profile['uid'] == local_user();
63 $o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
65 if (!count($a->profile) || $a->profile['hide-friends']) {
66 notice(DI::l10n()->t('Permission denied.'));
71 'uid' => $a->profile['uid'],
76 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
80 case 'followers': $condition['rel'] = [1, 3]; break;
81 case 'following': $condition['rel'] = [2, 3]; break;
82 case 'mutuals': $condition['rel'] = 3; break;
85 $total = DBA::count('contact', $condition);
87 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
89 $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
91 $contacts_stmt = DBA::select('contact', [], $condition, $params);
93 if (!DBA::isResult($contacts_stmt)) {
94 notice(DI::l10n()->t('No contacts.'));
100 while ($contact = DBA::fetch($contacts_stmt)) {
101 if ($contact['self']) {
105 $contact_details = Contact::getByURLForUser($contact['url'], $a->profile['uid']) ?: $contact;
108 'id' => $contact['id'],
109 'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
110 'photo_menu' => Contact::photoMenu($contact),
111 'thumb' => Contact::getThumb($contact_details),
112 'name' => substr($contact_details['name'], 0, 20),
113 'username' => $contact_details['name'],
114 'details' => $contact_details['location'],
115 'tags' => $contact_details['keywords'],
116 'about' => $contact_details['about'],
117 'account_type' => Contact::getAccountType($contact_details),
118 'url' => Contact::magicLink($contact['url']),
120 'itemurl' => $contact_details['addr'] ? : $contact['url'],
121 'network' => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol']),
125 DBA::close($contacts_stmt);
128 case 'followers': $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total); break;
129 case 'following': $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total); break;
130 case 'mutuals': $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total); break;
132 case 'all': default: $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total); break;
135 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
136 $o .= Renderer::replaceMacros($tpl, [
138 '$nickname' => $nickname,
141 '$all_label' => DI::l10n()->t('All contacts'),
142 '$followers_label' => DI::l10n()->t('Followers'),
143 '$following_label' => DI::l10n()->t('Following'),
144 '$mutuals_label' => DI::l10n()->t('Mutual friends'),
146 '$contacts' => $contacts,
147 '$paginate' => $pager->renderFull($total),