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