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;
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 $active = DBA::count('user', ['blocked' => false, 'verified' => true, 'account_removed' => false]);
44 $pending = Register::getPendingCount();
45 $blocked = DBA::count('user', ['blocked' => true, 'verified' => true]);
46 $deleted = DBA::count('user', ['account_removed' => true]);
50 'label' => DI::l10n()->t('All') . ' (' . DBA::count('user') . ')',
51 'url' => 'admin/users',
52 'sel' => !$selectedTab || $selectedTab == 'all' ? 'active' : '',
53 'title' => DI::l10n()->t('List of all users'),
54 'id' => 'admin-users-all',
58 'label' => DI::l10n()->t('Active') . ' (' . $active . ')',
59 'url' => 'admin/users/active',
60 'sel' => $selectedTab == 'active' ? 'active' : '',
61 'title' => DI::l10n()->t('List of active accounts'),
62 'id' => 'admin-users-active',
66 'label' => DI::l10n()->t('Pending') . ($pending ? ' (' . $pending . ')' : ''),
67 'url' => 'admin/users/pending',
68 'sel' => $selectedTab == 'pending' ? 'active' : '',
69 'title' => DI::l10n()->t('List of pending registrations'),
70 'id' => 'admin-users-pending',
74 'label' => DI::l10n()->t('Blocked') . ($blocked ? ' (' . $blocked . ')' : ''),
75 'url' => 'admin/users/blocked',
76 'sel' => $selectedTab == 'blocked' ? 'active' : '',
77 'title' => DI::l10n()->t('List of blocked users'),
78 'id' => 'admin-users-blocked',
82 'label' => DI::l10n()->t('Deleted') . ($deleted ? ' (' . $deleted . ')' : ''),
83 'url' => 'admin/users/deleted',
84 'sel' => $selectedTab == 'deleted' ? 'active' : '',
85 'title' => DI::l10n()->t('List of pending user deletions'),
86 'id' => 'admin-users-deleted',
91 $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
92 return Renderer::replaceMacros($tpl, ['$tabs' => $tabs]);
95 protected static function setupUserCallback() {
96 $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
97 return function ($user) use ($adminlist) {
99 User::PAGE_FLAGS_NORMAL => DI::l10n()->t('Normal Account Page'),
100 User::PAGE_FLAGS_SOAPBOX => DI::l10n()->t('Soapbox Page'),
101 User::PAGE_FLAGS_COMMUNITY => DI::l10n()->t('Public Forum'),
102 User::PAGE_FLAGS_FREELOVE => DI::l10n()->t('Automatic Friend Page'),
103 User::PAGE_FLAGS_PRVGROUP => DI::l10n()->t('Private Forum')
106 User::ACCOUNT_TYPE_PERSON => DI::l10n()->t('Personal Page'),
107 User::ACCOUNT_TYPE_ORGANISATION => DI::l10n()->t('Organisation Page'),
108 User::ACCOUNT_TYPE_NEWS => DI::l10n()->t('News Page'),
109 User::ACCOUNT_TYPE_COMMUNITY => DI::l10n()->t('Community Forum'),
110 User::ACCOUNT_TYPE_RELAY => DI::l10n()->t('Relay'),
113 $user['page_flags_raw'] = $user['page-flags'];
114 $user['page_flags'] = $page_types[$user['page-flags']];
116 $user['account_type_raw'] = ($user['page_flags_raw'] == 0) ? $user['account-type'] : -1;
117 $user['account_type'] = ($user['page_flags_raw'] == 0) ? $account_types[$user['account-type']] : '';
119 $user['register_date'] = Temporal::getRelativeDate($user['register_date']);
120 $user['login_date'] = Temporal::getRelativeDate($user['login_date']);
121 $user['lastitem_date'] = Temporal::getRelativeDate($user['last-item']);
122 $user['is_admin'] = in_array($user['email'], $adminlist);
123 $user['is_deletable'] = !$user['account_removed'] && intval($user['uid']) != local_user();
124 $user['deleted'] = ($user['account_removed'] ? Temporal::getRelativeDate($user['account_expires_on']) : False);