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;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Renderer;
27 use Friendica\Core\Session\Capability\IHandleUserSessions;
28 use Friendica\Database\Database;
30 use Friendica\Model\Register;
31 use Friendica\Model\User;
32 use Friendica\Module\BaseModeration;
33 use Friendica\Module\Response;
34 use Friendica\Navigation\SystemMessages;
35 use Friendica\Network\HTTPException\ServiceUnavailableException;
36 use Friendica\Util\Profiler;
37 use Friendica\Util\Temporal;
38 use Psr\Log\LoggerInterface;
40 abstract class BaseUsers extends BaseModeration
45 public function __construct(Database $database, App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
47 parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
49 $this->database = $database;
53 * Get the users moderation tabs menu
55 * @param string $selectedTab
57 * @throws ServiceUnavailableException
59 protected function getTabsHTML(string $selectedTab): string
61 $all = $this->database->count('user', ["`uid` != ?", 0]);
62 $active = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]);
63 $pending = Register::getPendingCount();
64 $blocked = $this->database->count('user', ['blocked' => true, 'verified' => true, 'account_removed' => false]);
65 $deleted = $this->database->count('user', ['account_removed' => true]);
69 'label' => $this->t('All') . ' (' . $all . ')',
70 'url' => 'moderation/users',
71 'sel' => !$selectedTab || $selectedTab == 'all' ? 'active' : '',
72 'title' => $this->t('List of all users'),
73 'id' => 'admin-users-all',
77 'label' => $this->t('Active') . ' (' . $active . ')',
78 'url' => 'moderation/users/active',
79 'sel' => $selectedTab == 'active' ? 'active' : '',
80 'title' => $this->t('List of active accounts'),
81 'id' => 'admin-users-active',
85 'label' => $this->t('Pending') . ($pending ? ' (' . $pending . ')' : ''),
86 'url' => 'moderation/users/pending',
87 'sel' => $selectedTab == 'pending' ? 'active' : '',
88 'title' => $this->t('List of pending registrations'),
89 'id' => 'admin-users-pending',
93 'label' => $this->t('Blocked') . ($blocked ? ' (' . $blocked . ')' : ''),
94 'url' => 'moderation/users/blocked',
95 'sel' => $selectedTab == 'blocked' ? 'active' : '',
96 'title' => $this->t('List of blocked users'),
97 'id' => 'admin-users-blocked',
101 'label' => $this->t('Deleted') . ($deleted ? ' (' . $deleted . ')' : ''),
102 'url' => 'moderation/users/deleted',
103 'sel' => $selectedTab == 'deleted' ? 'active' : '',
104 'title' => $this->t('List of pending user deletions'),
105 'id' => 'admin-users-deleted',
110 $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
111 return Renderer::replaceMacros($tpl, ['$tabs' => $tabs]);
114 protected function setupUserCallback(): \Closure
116 $adminlist = User::getAdminEmailList();
117 return function ($user) use ($adminlist) {
119 User::PAGE_FLAGS_NORMAL => $this->t('Normal Account Page'),
120 User::PAGE_FLAGS_SOAPBOX => $this->t('Soapbox Page'),
121 User::PAGE_FLAGS_COMMUNITY => $this->t('Public Forum'),
122 User::PAGE_FLAGS_FREELOVE => $this->t('Automatic Friend Page'),
123 User::PAGE_FLAGS_PRVGROUP => $this->t('Private Forum')
126 User::ACCOUNT_TYPE_PERSON => $this->t('Personal Page'),
127 User::ACCOUNT_TYPE_ORGANISATION => $this->t('Organisation Page'),
128 User::ACCOUNT_TYPE_NEWS => $this->t('News Page'),
129 User::ACCOUNT_TYPE_COMMUNITY => $this->t('Community Forum'),
130 User::ACCOUNT_TYPE_RELAY => $this->t('Relay'),
133 $user['page_flags_raw'] = $user['page-flags'];
134 $user['page_flags'] = $page_types[$user['page-flags']];
136 $user['account_type_raw'] = ($user['page_flags_raw'] == 0) ? $user['account-type'] : -1;
137 $user['account_type'] = ($user['page_flags_raw'] == 0) ? $account_types[$user['account-type']] : '';
139 $user['register_date'] = Temporal::getRelativeDate($user['register_date']);
140 $user['login_date'] = Temporal::getRelativeDate($user['last-activity']);
141 $user['lastitem_date'] = Temporal::getRelativeDate($user['last-item']);
142 $user['is_admin'] = in_array($user['email'], $adminlist);
143 $user['is_deletable'] = !$user['account_removed'] && intval($user['uid']) != $this->session->getLocalUserId();
144 $user['deleted'] = $user['account_removed'] ? Temporal::getRelativeDate($user['account_expires_on']) : false;