3 * @copyright Copyright (C) 2020, Friendica
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\Admin\Users;
24 use Friendica\Content\Pager;
25 use Friendica\Core\Renderer;
26 use Friendica\Database\DBA;
28 use Friendica\Model\User;
29 use Friendica\Module\Admin\BaseUsers;
30 use Friendica\Util\Temporal;
32 class Blocked extends BaseUsers
34 public static function post(array $parameters = [])
36 self::checkAdminAccess();
38 self::checkFormSecurityTokenRedirectOnError('/admin/users/blocked', 'admin_users_blocked');
40 $users = $_POST['user'] ?? [];
42 if (!empty($_POST['page_users_unblock'])) {
43 foreach ($users as $uid) {
44 User::block($uid, false);
46 info(DI::l10n()->tt('%s user unblocked', '%s users unblocked', count($users)));
49 if (!empty($_POST['page_users_delete'])) {
50 foreach ($users as $uid) {
51 if (local_user() != $uid) {
54 notice(DI::l10n()->t('You can\'t remove yourself'));
58 info(DI::l10n()->tt('%s user deleted', '%s users deleted', count($users)));
61 DI::baseUrl()->redirect('admin/users/blocked');
64 public static function content(array $parameters = [])
66 parent::content($parameters);
68 $action = $parameters['action'] ?? '';
69 $uid = $parameters['uid'] ?? 0;
72 $user = User::getById($uid, ['username', 'blocked']);
73 if (!DBA::isResult($user)) {
74 notice(DI::l10n()->t('User not found'));
75 DI::baseUrl()->redirect('admin/users');
76 return ''; // NOTREACHED
82 if (local_user() != $uid) {
83 self::checkFormSecurityTokenRedirectOnError('/admin/users/blocked', 'admin_users_blocked', 't');
87 notice(DI::l10n()->t('User "%s" deleted', $user['username']));
89 notice(DI::l10n()->t('You can\'t remove yourself'));
91 DI::baseUrl()->redirect('admin/users/blocked');
94 self::checkFormSecurityTokenRedirectOnError('/admin/users/blocked', 'admin_users_blocked', 't');
95 User::block($uid, false);
96 notice(DI::l10n()->t('User "%s" unblocked', $user['username']));
97 DI::baseUrl()->redirect('admin/users/blocked');
101 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100);
113 $order_direction = '+';
114 if (!empty($_GET['o'])) {
115 $new_order = $_GET['o'];
116 if ($new_order[0] === '-') {
117 $order_direction = '-';
118 $new_order = substr($new_order, 1);
121 if (in_array($new_order, $valid_orders)) {
126 $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'blocked', $order, ($order_direction == '-'));
128 $users = array_map(self::setupUserCallback(), $users);
130 $th_users = array_map(null, [DI::l10n()->t('Name'), DI::l10n()->t('Email'), DI::l10n()->t('Register date'), DI::l10n()->t('Last login'), DI::l10n()->t('Last public item'), DI::l10n()->t('Type')], $valid_orders);
132 $count = DBA::count('user', ['blocked' => true, 'verified' => true]);
134 $t = Renderer::getMarkupTemplate('admin/users/blocked.tpl');
135 return self::getTabsHTML('blocked') . Renderer::replaceMacros($t, [
137 '$title' => DI::l10n()->t('Administration'),
138 '$page' => DI::l10n()->t('Blocked Users'),
139 '$select_all' => DI::l10n()->t('select all'),
140 '$delete' => DI::l10n()->t('Delete'),
141 '$blocked' => DI::l10n()->t('User blocked'),
142 '$unblock' => DI::l10n()->t('Unblock'),
143 '$siteadmin' => DI::l10n()->t('Site admin'),
144 '$accountexpired' => DI::l10n()->t('Account expired'),
146 '$th_users' => $th_users,
147 '$order_users' => $order,
148 '$order_direction_users' => $order_direction,
150 '$confirm_delete_multi' => DI::l10n()->t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
151 '$confirm_delete' => DI::l10n()->t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
153 '$form_security_token' => self::getFormSecurityToken('admin_users_blocked'),
156 '$baseurl' => DI::baseUrl()->get(true),
157 '$query_string' => DI::args()->getQueryString(),
161 '$pager' => $pager->renderFull($count)