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;
16 use Friendica\Model\Contact;
17 use Friendica\Model\User;
22 * @author Hypolite Petovan
27 * Get HTML for contact block
29 * @template widget/contacts.tpl
30 * @hook contact_block_end (contacts=>array, output=>string)
33 public static function getHTML(array $profile)
37 $shown = PConfig::get($profile['uid'], 'system', 'display_friend_count', 24);
42 if (!empty($profile['hide-friends'])) {
48 $total = DBA::count('contact', [
49 'uid' => $profile['uid'],
55 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA],
58 $contacts_title = L10n::t('No contacts');
63 // Only show followed for personal accounts, followers for pages
64 if (defaults($profile, 'account-type', User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) {
65 $rel = [Contact::SHARING, Contact::FRIEND];
67 $rel = [Contact::FOLLOWER, Contact::FRIEND];
70 $contact_ids_stmt = DBA::select('contact', ['id'], [
71 'uid' => $profile['uid'],
78 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA],
79 ], ['limit' => $shown]);
81 if (DBA::isResult($contact_ids_stmt)) {
83 while($contact = DBA::fetch($contact_ids_stmt)) {
84 $contact_ids[] = $contact["id"];
87 $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'network'], ['id' => $contact_ids]);
89 if (DBA::isResult($contacts_stmt)) {
90 $contacts_title = L10n::tt('%d Contact', '%d Contacts', $total);
93 while ($contact = DBA::fetch($contacts_stmt)) {
94 $contacts[] = $contact;
95 $micropro[] = HTML::micropro($contact, true, 'mpfriend');
99 DBA::close($contacts_stmt);
102 DBA::close($contact_ids_stmt);
105 $tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
106 $o = Renderer::replaceMacros($tpl, [
107 '$contacts' => $contacts_title,
108 '$nickname' => $profile['nickname'],
109 '$viewcontacts' => L10n::t('View Contacts'),
110 '$micropro' => $micropro,
113 $arr = ['contacts' => $contacts, 'output' => $o];
115 Hook::callAll('contact_block_end', $arr);