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\L10n;
12 use Friendica\Core\PConfig;
13 use Friendica\Core\Protocol;
14 use Friendica\Core\Renderer;
15 use Friendica\Database\DBA;
17 use Friendica\Model\Contact;
18 use Friendica\Model\User;
23 * @author Hypolite Petovan
28 * Get HTML for contact block
30 * @template widget/contacts.tpl
31 * @hook contact_block_end (contacts=>array, output=>string)
34 public static function getHTML(array $profile)
38 $shown = DI::pConfig()->get($profile['uid'], 'system', 'display_friend_count', 24);
43 if (!empty($profile['hide-friends'])) {
49 $total = DBA::count('contact', [
50 'uid' => $profile['uid'],
56 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
59 $contacts_title = L10n::t('No contacts');
64 // Only show followed for personal accounts, followers for pages
65 if ((($profile['account-type'] ?? '') ?: User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) {
66 $rel = [Contact::SHARING, Contact::FRIEND];
68 $rel = [Contact::FOLLOWER, Contact::FRIEND];
71 $contact_ids_stmt = DBA::select('contact', ['id'], [
72 'uid' => $profile['uid'],
79 'network' => Protocol::FEDERATED,
80 ], ['limit' => $shown]);
82 if (DBA::isResult($contact_ids_stmt)) {
84 while($contact = DBA::fetch($contact_ids_stmt)) {
85 $contact_ids[] = $contact["id"];
88 $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'network'], ['id' => $contact_ids]);
90 if (DBA::isResult($contacts_stmt)) {
91 $contacts_title = L10n::tt('%d Contact', '%d Contacts', $total);
94 while ($contact = DBA::fetch($contacts_stmt)) {
95 $contacts[] = $contact;
96 $micropro[] = HTML::micropro($contact, true, 'mpfriend');
100 DBA::close($contacts_stmt);
103 DBA::close($contact_ids_stmt);
106 $tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
107 $o = Renderer::replaceMacros($tpl, [
108 '$contacts' => $contacts_title,
109 '$nickname' => $profile['nickname'],
110 '$viewcontacts' => L10n::t('View Contacts'),
111 '$micropro' => $micropro,
114 $arr = ['contacts' => $contacts, 'output' => $o];
116 Hook::callAll('contact_block_end', $arr);