3 * @copyright Copyright (C) 2010-2021, the Friendica project
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\Content\Widget;
24 use Friendica\Content\Text\HTML;
25 use Friendica\Core\Hook;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Database\DBA;
30 use Friendica\Model\Contact;
31 use Friendica\Model\User;
36 * @author Hypolite Petovan
41 * Get HTML for contact block
43 * @template widget/contacts.tpl
44 * @hook contact_block_end (contacts=>array, output=>string)
47 public static function getHTML(array $profile)
51 $shown = DI::pConfig()->get($profile['uid'], 'system', 'display_friend_count', 24);
56 if (!empty($profile['hide-friends'])) {
62 $total = DBA::count('contact', [
63 'uid' => $profile['uid'],
70 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
73 $contacts_title = DI::l10n()->t('No contacts');
78 // Only show followed for personal accounts, followers for pages
79 if ((($profile['account-type'] ?? '') ?: User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) {
80 $rel = [Contact::SHARING, Contact::FRIEND];
82 $rel = [Contact::FOLLOWER, Contact::FRIEND];
85 $contact_ids_stmt = DBA::select('contact', ['id'], [
86 'uid' => $profile['uid'],
93 'network' => Protocol::FEDERATED,
94 ], ['limit' => $shown]);
96 if (DBA::isResult($contact_ids_stmt)) {
98 while($contact = DBA::fetch($contact_ids_stmt)) {
99 $contact_ids[] = $contact["id"];
102 $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'avatar', 'network'], ['id' => $contact_ids]);
104 if (DBA::isResult($contacts_stmt)) {
105 $contacts_title = DI::l10n()->tt('%d Contact', '%d Contacts', $total);
108 while ($contact = DBA::fetch($contacts_stmt)) {
109 $contacts[] = $contact;
110 $micropro[] = HTML::micropro($contact, true, 'mpfriend');
114 DBA::close($contacts_stmt);
117 DBA::close($contact_ids_stmt);
120 $tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
121 $o = Renderer::replaceMacros($tpl, [
122 '$contacts' => $contacts_title,
123 '$nickname' => $profile['nickname'],
124 '$viewcontacts' => DI::l10n()->t('View Contacts'),
125 '$micropro' => $micropro,
128 $arr = ['contacts' => $contacts, 'output' => $o];
130 Hook::callAll('contact_block_end', $arr);