3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module\Moderation\Users;
24 use Friendica\Content\Pager;
25 use Friendica\Core\Renderer;
26 use Friendica\Model\User;
27 use Friendica\Module\Moderation\BaseUsers;
29 class Index extends BaseUsers
31 protected function post(array $request = [])
33 $this->checkModerationAccess();
35 self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users');
37 $users = $request['user'] ?? [];
39 if (!empty($request['page_users_block'])) {
40 foreach ($users as $uid) {
43 $this->systemMessages->addInfo($this->tt('%s user blocked', '%s users blocked', count($users)));
46 if (!empty($request['page_users_unblock'])) {
47 foreach ($users as $uid) {
48 User::block($uid, false);
50 $this->systemMessages->addInfo($this->tt('%s user unblocked', '%s users unblocked', count($users)));
53 if (!empty($request['page_users_delete'])) {
54 foreach ($users as $uid) {
55 if ($this->session->getLocalUserId() != $uid) {
58 $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
62 $this->systemMessages->addInfo($this->tt('%s user deleted', '%s users deleted', count($users)));
65 $this->baseUrl->redirect($this->args->getQueryString());
68 protected function content(array $request = []): string
72 $action = $this->parameters['action'] ?? '';
73 $uid = $this->parameters['uid'] ?? 0;
76 $user = User::getById($uid, ['username', 'blocked']);
78 $this->systemMessages->addNotice($this->t('User not found'));
79 $this->baseUrl->redirect('moderation/users');
85 if ($this->session->getLocalUserId() != $uid) {
86 self::checkFormSecurityTokenRedirectOnError($this->baseUrl->get(true), 'moderation_users', 't');
90 $this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
92 $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
95 $this->baseUrl->redirect('moderation/users');
98 self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users', 't');
100 $this->systemMessages->addNotice($this->t('User "%s" blocked', $user['username']));
101 $this->baseUrl->redirect('moderation/users');
104 self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users', 't');
105 User::block($uid, false);
106 $this->systemMessages->addNotice($this->t('User "%s" unblocked', $user['username']));
107 $this->baseUrl->redirect('moderation/users');
111 $pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
123 $order_direction = '+';
124 if (!empty($request['o'])) {
125 $new_order = $request['o'];
126 if ($new_order[0] === '-') {
127 $order_direction = '-';
128 $new_order = substr($new_order, 1);
131 if (in_array($new_order, $valid_orders)) {
136 $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, ($order_direction == '-'));
138 $users = array_map($this->setupUserCallback(), $users);
140 $th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
142 $count = $this->database->count('user', ["`uid` != ?", 0]);
144 $t = Renderer::getMarkupTemplate('moderation/users/index.tpl');
145 return self::getTabsHTML('all') . Renderer::replaceMacros($t, [
147 '$title' => $this->t('Moderation'),
148 '$page' => $this->t('Users'),
149 '$select_all' => $this->t('select all'),
150 '$h_deleted' => $this->t('User waiting for permanent deletion'),
151 '$delete' => $this->t('Delete'),
152 '$block' => $this->t('Block'),
153 '$blocked' => $this->t('User blocked'),
154 '$unblock' => $this->t('Unblock'),
155 '$siteadmin' => $this->t('Site admin'),
156 '$accountexpired' => $this->t('Account expired'),
158 '$h_users' => $this->t('Users'),
159 '$h_newuser' => $this->t('Create a new user'),
160 '$th_deleted' => [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Permanent deletion')],
161 '$th_users' => $th_users,
162 '$order_users' => $order,
163 '$order_direction_users' => $order_direction,
165 '$confirm_delete_multi' => $this->t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
166 '$confirm_delete' => $this->t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
168 '$form_security_token' => self::getFormSecurityToken('moderation_users'),
171 '$baseurl' => $this->baseUrl->get(true),
172 '$query_string' => $this->args->getQueryString(),
176 '$pager' => $pager->renderFull($count),