4 * @file src/Content/Widget/ContactBlock.php
7 namespace Friendica\Content\Widget;
9 use Friendica\Content\Text\HTML;
10 use Friendica\Core\Hook;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\Renderer;
13 use Friendica\Database\DBA;
15 use Friendica\Model\Contact;
16 use Friendica\Model\User;
21 * @author Hypolite Petovan
26 * Get HTML for contact block
28 * @template widget/contacts.tpl
29 * @hook contact_block_end (contacts=>array, output=>string)
32 public static function getHTML(array $profile)
36 $shown = DI::pConfig()->get($profile['uid'], 'system', 'display_friend_count', 24);
41 if (!empty($profile['hide-friends'])) {
47 $total = DBA::count('contact', [
48 'uid' => $profile['uid'],
54 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
57 $contacts_title = DI::l10n()->t('No contacts');
62 // Only show followed for personal accounts, followers for pages
63 if ((($profile['account-type'] ?? '') ?: User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) {
64 $rel = [Contact::SHARING, Contact::FRIEND];
66 $rel = [Contact::FOLLOWER, Contact::FRIEND];
69 $contact_ids_stmt = DBA::select('contact', ['id'], [
70 'uid' => $profile['uid'],
77 'network' => Protocol::FEDERATED,
78 ], ['limit' => $shown]);
80 if (DBA::isResult($contact_ids_stmt)) {
82 while($contact = DBA::fetch($contact_ids_stmt)) {
83 $contact_ids[] = $contact["id"];
86 $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'network'], ['id' => $contact_ids]);
88 if (DBA::isResult($contacts_stmt)) {
89 $contacts_title = DI::l10n()->tt('%d Contact', '%d Contacts', $total);
92 while ($contact = DBA::fetch($contacts_stmt)) {
93 $contacts[] = $contact;
94 $micropro[] = HTML::micropro($contact, true, 'mpfriend');
98 DBA::close($contacts_stmt);
101 DBA::close($contact_ids_stmt);
104 $tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
105 $o = Renderer::replaceMacros($tpl, [
106 '$contacts' => $contacts_title,
107 '$nickname' => $profile['nickname'],
108 '$viewcontacts' => DI::l10n()->t('View Contacts'),
109 '$micropro' => $micropro,
112 $arr = ['contacts' => $contacts, 'output' => $o];
114 Hook::callAll('contact_block_end', $arr);