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\Admin;
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
27 use Friendica\Model\Register;
28 use Friendica\Model\User;
29 use Friendica\Module\BaseAdmin;
30 use Friendica\Util\Temporal;
32 abstract class BaseUsers extends BaseAdmin
35 * Get the users admin tabs menu
37 * @param string $selectedTab
39 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
41 protected static function getTabsHTML(string $selectedTab)
43 $all = DBA::count('user', ["`uid` != ?", 0]);
44 $active = DBA::count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]);
45 $pending = Register::getPendingCount();
46 $blocked = DBA::count('user', ['blocked' => true, 'verified' => true, 'account_removed' => false]);
47 $deleted = DBA::count('user', ['account_removed' => true]);
51 'label' => DI::l10n()->t('All') . ' (' . $all . ')',
52 'url' => 'admin/users',
53 'sel' => !$selectedTab || $selectedTab == 'all' ? 'active' : '',
54 'title' => DI::l10n()->t('List of all users'),
55 'id' => 'admin-users-all',
59 'label' => DI::l10n()->t('Active') . ' (' . $active . ')',
60 'url' => 'admin/users/active',
61 'sel' => $selectedTab == 'active' ? 'active' : '',
62 'title' => DI::l10n()->t('List of active accounts'),
63 'id' => 'admin-users-active',
67 'label' => DI::l10n()->t('Pending') . ($pending ? ' (' . $pending . ')' : ''),
68 'url' => 'admin/users/pending',
69 'sel' => $selectedTab == 'pending' ? 'active' : '',
70 'title' => DI::l10n()->t('List of pending registrations'),
71 'id' => 'admin-users-pending',
75 'label' => DI::l10n()->t('Blocked') . ($blocked ? ' (' . $blocked . ')' : ''),
76 'url' => 'admin/users/blocked',
77 'sel' => $selectedTab == 'blocked' ? 'active' : '',
78 'title' => DI::l10n()->t('List of blocked users'),
79 'id' => 'admin-users-blocked',
83 'label' => DI::l10n()->t('Deleted') . ($deleted ? ' (' . $deleted . ')' : ''),
84 'url' => 'admin/users/deleted',
85 'sel' => $selectedTab == 'deleted' ? 'active' : '',
86 'title' => DI::l10n()->t('List of pending user deletions'),
87 'id' => 'admin-users-deleted',
92 $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
93 return Renderer::replaceMacros($tpl, ['$tabs' => $tabs]);
96 protected static function setupUserCallback() {
97 $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
98 return function ($user) use ($adminlist) {
100 User::PAGE_FLAGS_NORMAL => DI::l10n()->t('Normal Account Page'),
101 User::PAGE_FLAGS_SOAPBOX => DI::l10n()->t('Soapbox Page'),
102 User::PAGE_FLAGS_COMMUNITY => DI::l10n()->t('Public Forum'),
103 User::PAGE_FLAGS_FREELOVE => DI::l10n()->t('Automatic Friend Page'),
104 User::PAGE_FLAGS_PRVGROUP => DI::l10n()->t('Private Forum')
107 User::ACCOUNT_TYPE_PERSON => DI::l10n()->t('Personal Page'),
108 User::ACCOUNT_TYPE_ORGANISATION => DI::l10n()->t('Organisation Page'),
109 User::ACCOUNT_TYPE_NEWS => DI::l10n()->t('News Page'),
110 User::ACCOUNT_TYPE_COMMUNITY => DI::l10n()->t('Community Forum'),
111 User::ACCOUNT_TYPE_RELAY => DI::l10n()->t('Relay'),
114 $user['page_flags_raw'] = $user['page-flags'];
115 $user['page_flags'] = $page_types[$user['page-flags']];
117 $user['account_type_raw'] = ($user['page_flags_raw'] == 0) ? $user['account-type'] : -1;
118 $user['account_type'] = ($user['page_flags_raw'] == 0) ? $account_types[$user['account-type']] : '';
120 $user['register_date'] = Temporal::getRelativeDate($user['register_date']);
121 $user['login_date'] = Temporal::getRelativeDate($user['login_date']);
122 $user['lastitem_date'] = Temporal::getRelativeDate($user['last-item']);
123 $user['is_admin'] = in_array($user['email'], $adminlist);
124 $user['is_deletable'] = !$user['account_removed'] && intval($user['uid']) != local_user();
125 $user['deleted'] = ($user['account_removed'] ? Temporal::getRelativeDate($user['account_expires_on']) : False);