]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact/Contacts.php
Merge pull request #8909 from MrPetovan/task/ex_auth
[friendica.git] / src / Module / Contact / Contacts.php
1 <?php
2
3 namespace Friendica\Module\Contact;
4
5 use Friendica\BaseModule;
6 use Friendica\Content\Pager;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\Session;
9 use Friendica\DI;
10 use Friendica\Model;
11 use Friendica\Module;
12 use Friendica\Network\HTTPException;
13
14 class Contacts extends BaseModule
15 {
16         public static function content(array $parameters = [])
17         {
18                 $app = DI::app();
19
20                 if (!local_user()) {
21                         throw new HTTPException\ForbiddenException();
22                 }
23
24                 $cid = $parameters['id'];
25                 $type = $parameters['type'] ?? 'all';
26
27                 if (!$cid) {
28                         throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
29                 }
30
31                 $contact = Model\Contact::getById($cid, []);
32                 if (empty($contact)) {
33                         throw new HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
34                 }
35
36                 $localContactId = Model\Contact::getPublicIdByUserId(local_user());
37
38                 Model\Profile::load($app, '', $contact);
39
40                 $condition = [
41                         'blocked' => false,
42                         'self' => false,
43                         'hidden' => false,
44                 ];
45
46                 $noresult_label = DI::l10n()->t('No known contacts.');
47
48                 switch ($type) {
49                         case 'followers':
50                                 $total = Model\Contact\Relation::countFollowers($cid, $condition);
51                                 break;
52                         case 'following':
53                                 $total = Model\Contact\Relation::countFollows($cid, $condition);
54                                 break;
55                         case 'mutuals':
56                                 $total = Model\Contact\Relation::countMutuals($cid, $condition);
57                                 break;
58                         case 'common':
59                                 $condition = [
60                                         'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
61                                         $localContactId,
62                                 ];
63                                 $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
64                                 $noresult_label = DI::l10n()->t('No common contacts.');
65                                 break;
66                         default:
67                                 $total = Model\Contact\Relation::countAll($cid, $condition);
68                 }
69
70                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
71                 $desc = '';
72
73                 switch ($type) {
74                         case 'followers':
75                                 $friends = Model\Contact\Relation::listFollowers($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
76                                 $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
77                                 break;
78                         case 'following':
79                                 $friends = Model\Contact\Relation::listFollows($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
80                                 $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
81                                 break;
82                         case 'mutuals':
83                                 $friends = Model\Contact\Relation::listMutuals($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
84                                 $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
85                                 $desc = DI::l10n()->t(
86                                         'These contacts both follow and are followed by <strong>%s</strong>.',
87                                         htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
88                                 );
89                                 break;
90                         case 'common':
91                                 $friends = Model\Contact\Relation::listCommon($localContactId, $cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
92                                 $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
93                                 $desc = DI::l10n()->t(
94                                         'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
95                                         htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
96                                 );
97                                 break;
98                         default:
99                                 $friends = Model\Contact\Relation::listAll($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
100                                 $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
101                 }
102
103                 $o = Module\Contact::getTabsHTML($contact, Module\Contact::TAB_CONTACTS);
104
105                 $tabs = self::getContactFilterTabs('contact/' . $cid, $type, true);
106
107                 $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $friends);
108
109                 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
110                 $o .= Renderer::replaceMacros($tpl, [
111                         '$title'    => $title,
112                         '$desc'     => $desc,
113                         '$tabs'     => $tabs,
114
115                         '$noresult_label'  => $noresult_label,
116
117                         '$contacts' => $contacts,
118                         '$paginate' => $pager->renderFull($total),
119                 ]);
120
121                 return $o;
122         }
123 }