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 Active extends BaseUsers
31 protected function post(array $request = [])
33 $this->checkModerationAccess();
35 self::checkFormSecurityTokenRedirectOnError($this->baseUrl->get(true), 'moderation_users_active');
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_delete'])) {
47 foreach ($users as $uid) {
48 if ($this->session->getLocalUserId() != $uid) {
51 $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
55 $this->systemMessages->addInfo($this->tt('%s user deleted', '%s users deleted', count($users)));
58 $this->baseUrl->redirect($this->args->getQueryString());
61 protected function content(array $request = []): string
65 $action = $this->parameters['action'] ?? '';
66 $uid = $this->parameters['uid'] ?? 0;
69 $user = User::getById($uid, ['username', 'blocked']);
71 $this->systemMessages->addNotice($this->t('User not found'));
72 $this->baseUrl->redirect('moderation/users');
78 if ($this->session->getLocalUserId() != $uid) {
79 self::checkFormSecurityTokenRedirectOnError('moderation/users/active', 'moderation_users_active', 't');
83 $this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
85 $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
88 $this->baseUrl->redirect('moderation/users/active');
91 self::checkFormSecurityTokenRedirectOnError('moderation/users/active', 'moderation_users_active', 't');
93 $this->systemMessages->addNotice($this->t('User "%s" blocked', $user['username']));
94 $this->baseUrl->redirect('moderation/users/active');
97 $pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
109 $order_direction = '+';
110 if (!empty($request['o'])) {
111 $new_order = $request['o'];
112 if ($new_order[0] === '-') {
113 $order_direction = '-';
114 $new_order = substr($new_order, 1);
117 if (in_array($new_order, $valid_orders)) {
122 $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'active', $order, ($order_direction == '-'));
124 $users = array_map($this->setupUserCallback(), $users);
126 $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);
128 $count = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]);
130 $t = Renderer::getMarkupTemplate('moderation/users/active.tpl');
131 return self::getTabsHTML('active') . Renderer::replaceMacros($t, [
133 '$title' => $this->t('Moderation'),
134 '$page' => $this->t('Active Accounts'),
135 '$select_all' => $this->t('select all'),
136 '$delete' => $this->t('Delete'),
137 '$block' => $this->t('Block'),
138 '$blocked' => $this->t('User blocked'),
139 '$siteadmin' => $this->t('Site admin'),
140 '$accountexpired' => $this->t('Account expired'),
141 '$h_newuser' => $this->t('Create a new user'),
143 '$th_users' => $th_users,
144 '$order_users' => $order,
145 '$order_direction_users' => $order_direction,
147 '$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?'),
148 '$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?'),
150 '$form_security_token' => self::getFormSecurityToken('moderation_users_active'),
153 '$baseurl' => $this->baseUrl->get(true),
154 '$query_string' => $this->args->getQueryString(),
158 '$pager' => $pager->renderFull($count),