]> git.mxchange.org Git - friendica.git/blob - src/Module/Moderation/Users/Pending.php
Merge pull request #12169 from MrPetovan/bug/7574-notifications-deleted-users
[friendica.git] / src / Module / Moderation / Users / Pending.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\Moderation\Users;
23
24 use Friendica\Content\Pager;
25 use Friendica\Core\Renderer;
26 use Friendica\Model\Register;
27 use Friendica\Model\User;
28 use Friendica\Module\Moderation\BaseUsers;
29
30 class Pending extends BaseUsers
31 {
32         protected function post(array $request = [])
33         {
34                 $this->checkModerationAccess();
35
36                 self::checkFormSecurityTokenRedirectOnError('moderation/users/pending', 'admin_users_pending');
37
38                 $pending = $request['pending'] ?? [];
39
40                 if (!empty($request['page_users_approve'])) {
41                         foreach ($pending as $hash) {
42                                 User::allow($hash);
43                         }
44                         $this->systemMessages->addInfo($this->tt('%s user approved', '%s users approved', count($pending)));
45                 }
46
47                 if (!empty($request['page_users_deny'])) {
48                         foreach ($pending as $hash) {
49                                 User::deny($hash);
50                         }
51                         $this->systemMessages->addInfo($this->tt('%s registration revoked', '%s registrations revoked', count($pending)));
52                 }
53
54                 $this->baseUrl->redirect('moderation/users/pending');
55         }
56
57         protected function content(array $request = []): string
58         {
59                 parent::content();
60
61                 $action = $this->parameters['action'] ?? '';
62                 $uid    = $this->parameters['uid'] ?? 0;
63
64                 if ($uid) {
65                         $user = User::getById($uid, ['username', 'blocked']);
66                         if (!$user) {
67                                 $this->systemMessages->addNotice($this->t('User not found'));
68                                 $this->baseUrl->redirect('moderation/users');
69                         }
70                 }
71
72                 switch ($action) {
73                         case 'allow':
74                                 self::checkFormSecurityTokenRedirectOnError('moderation/users/pending', 'admin_users_pending', 't');
75                                 User::allow(Register::getPendingForUser($uid)['hash'] ?? '');
76                                 $this->systemMessages->addNotice($this->t('Account approved.'));
77                                 $this->baseUrl->redirect('moderation/users/pending');
78                                 break;
79                         case 'deny':
80                                 self::checkFormSecurityTokenRedirectOnError('moderation/users/pending', 'admin_users_pending', 't');
81                                 User::deny(Register::getPendingForUser($uid)['hash'] ?? '');
82                                 $this->systemMessages->addNotice($this->t('Registration revoked'));
83                                 $this->baseUrl->redirect('moderation/users/pending');
84                                 break;
85                 }
86
87                 $pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
88
89                 $pending = Register::getPending($pager->getStart(), $pager->getItemsPerPage());
90
91                 $count = Register::getPendingCount();
92
93                 $t = Renderer::getMarkupTemplate('moderation/users/pending.tpl');
94                 return self::getTabsHTML('pending') . Renderer::replaceMacros($t, [
95                         // strings //
96                         '$title' => $this->t('Administration'),
97                         '$page' => $this->t('User registrations awaiting review'),
98                         '$select_all' => $this->t('select all'),
99                         '$th_pending' => [$this->t('Request date'), $this->t('Name'), $this->t('Email')],
100                         '$no_pending' => $this->t('No registrations.'),
101                         '$pendingnotetext' => $this->t('Note from the user'),
102                         '$approve' => $this->t('Approve'),
103                         '$deny' => $this->t('Deny'),
104
105                         '$form_security_token' => self::getFormSecurityToken('admin_users_pending'),
106
107                         // values //
108                         '$baseurl' => $this->baseUrl->get(true),
109                         '$query_string' => $this->args->getQueryString(),
110
111                         '$pending' => $pending,
112                         '$count' => $count,
113                         '$pager' => $pager->renderFull($count),
114                 ]);
115         }
116 }