]> git.mxchange.org Git - friendica.git/blob - src/Content/Widget/ContactBlock.php
12cd4cd87d2055a08917d624b4b14e405222a211
[friendica.git] / src / Content / Widget / ContactBlock.php
1 <?php
2
3 /*
4  * @file src/Content/Widget/ContactBlock.php
5  */
6
7 namespace Friendica\Content\Widget;
8
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
18 /**
19  * ContactBlock widget
20  *
21  * @author Hypolite Petovan
22  */
23 class ContactBlock
24 {
25         /**
26          * Get HTML for contact block
27          *
28          * @template contact_block.tpl
29          * @hook contact_block_end (contacts=>array, output=>string)
30          * @return string
31          */
32         public static function getHTML(array $profile)
33         {
34                 $o = '';
35
36                 $shown = PConfig::get($profile['uid'], 'system', 'display_friend_count', 24);
37                 if ($shown == 0) {
38                         return $o;
39                 }
40
41                 if (!empty($profile['hide-friends'])) {
42                         return $o;
43                 }
44
45                 $contacts = [];
46
47                 $total = DBA::count('contact', [
48                         'uid' => $profile['uid'],
49                         'self' => false,
50                         'blocked' => false,
51                         'pending' => false,
52                         'hidden' => false,
53                         'archive' => false,
54                         'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA],
55                 ]);
56
57                 $contacts_title = L10n::t('No contacts');
58
59                 if (!$total) {
60                         $micropro = [];
61                 } else {
62                         $contact_ids_stmt = DBA::select('contact', ['id'], [
63                                 'uid' => $profile['uid'],
64                                 'self' => false,
65                                 'blocked' => false,
66                                 'pending' => false,
67                                 'hidden' => false,
68                                 'archive' => false,
69                                 'rel' => [Contact::FOLLOWER, Contact::FRIEND],
70                                 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA],
71                         ], ['limit' => $shown]);
72
73                         if (DBA::isResult($contact_ids_stmt)) {
74                                 $contact_ids = [];
75                                 while($contact = DBA::fetch($contact_ids_stmt)) {
76                                         $contact_ids[] = $contact["id"];
77                                 }
78
79                                 $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'network'], ['id' => $contact_ids]);
80
81                                 if (DBA::isResult($contacts_stmt)) {
82                                         $contacts_title = L10n::tt('%d Contact', '%d Contacts', $total);
83                                         $micropro = [];
84
85                                         while ($contact = DBA::fetch($contacts_stmt)) {
86                                                 $contacts[] = $contact;
87                                                 $micropro[] = HTML::micropro($contact, true, 'mpfriend');
88                                         }
89                                 }
90
91                                 DBA::close($contacts_stmt);
92                         }
93
94                         DBA::close($contact_ids_stmt);
95                 }
96
97                 $tpl = Renderer::getMarkupTemplate('contact_block.tpl');
98                 $o = Renderer::replaceMacros($tpl, [
99                         '$contacts' => $contacts_title,
100                         '$nickname' => $profile['nickname'],
101                         '$viewcontacts' => L10n::t('View Contacts'),
102                         '$micropro' => $micropro,
103                 ]);
104
105                 $arr = ['contacts' => $contacts, 'output' => $o];
106
107                 Hook::callAll('contact_block_end', $arr);
108
109                 return $o;
110         }
111 }