]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact/Contacts.php
Removed redundant maximagesize = INF statements
[friendica.git] / src / Module / Contact / Contacts.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Contact;
23
24 use Friendica\BaseModule;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Widget;
27 use Friendica\Core\Renderer;
28 use Friendica\DI;
29 use Friendica\Model;
30 use Friendica\Model\User;
31 use Friendica\Module;
32 use Friendica\Network\HTTPException;
33
34 class Contacts extends BaseModule
35 {
36         protected function content(array $request = []): string
37         {
38                 if (!DI::userSession()->getLocalUserId()) {
39                         throw new HTTPException\ForbiddenException();
40                 }
41
42                 $cid = $this->parameters['id'];
43                 $type = $this->parameters['type'] ?? 'all';
44                 $accounttype = $_GET['accounttype'] ?? '';
45                 $accounttypeid = User::getAccountTypeByString($accounttype);
46
47                 if (!$cid) {
48                         throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
49                 }
50
51                 $contact = Model\Contact::getById($cid, []);
52                 if (empty($contact)) {
53                         throw new HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
54                 }
55
56                 $localContactId = Model\Contact::getPublicIdByUserId(DI::userSession()->getLocalUserId());
57
58                 DI::page()['aside'] = Widget\VCard::getHTML($contact);
59
60                 $condition = [
61                         'blocked' => false,
62                         'self' => false,
63                         'hidden' => false,
64                         'failed' => false,
65                 ];
66
67                 if (isset($accounttypeid)) {
68                         $condition['contact-type'] = $accounttypeid;
69                 }
70
71                 $noresult_label = DI::l10n()->t('No known contacts.');
72
73                 switch ($type) {
74                         case 'followers':
75                                 $total = Model\Contact\Relation::countFollowers($cid, $condition);
76                                 break;
77                         case 'following':
78                                 $total = Model\Contact\Relation::countFollows($cid, $condition);
79                                 break;
80                         case 'mutuals':
81                                 $total = Model\Contact\Relation::countMutuals($cid, $condition);
82                                 break;
83                         case 'common':
84                                 $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
85                                 $noresult_label = DI::l10n()->t('No common contacts.');
86                                 break;
87                         default:
88                                 $total = Model\Contact\Relation::countAll($cid, $condition);
89                 }
90
91                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
92                 $desc = '';
93
94                 switch ($type) {
95                         case 'followers':
96                                 $friends = Model\Contact\Relation::listFollowers($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
97                                 $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
98                                 break;
99                         case 'following':
100                                 $friends = Model\Contact\Relation::listFollows($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
101                                 $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
102                                 break;
103                         case 'mutuals':
104                                 $friends = Model\Contact\Relation::listMutuals($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
105                                 $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
106                                 $desc = DI::l10n()->t(
107                                         'These contacts both follow and are followed by <strong>%s</strong>.',
108                                         htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
109                                 );
110                                 break;
111                         case 'common':
112                                 $friends = Model\Contact\Relation::listCommon($localContactId, $cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
113                                 $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
114                                 $desc = DI::l10n()->t(
115                                         'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
116                                         htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
117                                 );
118                                 break;
119                         default:
120                                 $friends = Model\Contact\Relation::listAll($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
121                                 $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
122                 }
123
124                 $o = Module\Contact::getTabsHTML($contact, Module\Contact::TAB_CONTACTS);
125
126                 $tabs = self::getContactFilterTabs('contact/' . $cid, $type, true);
127
128                 $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $friends);
129
130                 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
131                 $o .= Renderer::replaceMacros($tpl, [
132                         '$title'    => $title,
133                         '$desc'     => $desc,
134                         '$tabs'     => $tabs,
135
136                         '$noresult_label'  => $noresult_label,
137
138                         '$contacts' => $contacts,
139                         '$paginate' => $pager->renderFull($total),
140                 ]);
141
142                 DI::page()['aside'] .= Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);
143
144                 return $o;
145         }
146 }