]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/BaseUsers.php
Replace $this->l10n->t() with $this->t() for Modules
[friendica.git] / src / Module / Admin / BaseUsers.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module\Admin;
23
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use Friendica\Model\Register;
28 use Friendica\Model\User;
29 use Friendica\Module\BaseAdmin;
30 use Friendica\Util\Temporal;
31
32 abstract class BaseUsers extends BaseAdmin
33 {
34         /**
35          * Get the users admin tabs menu
36          *
37          * @param string $selectedTab
38          * @return string HTML
39          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
40          */
41         protected static function getTabsHTML(string $selectedTab)
42         {
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, 'account_removed' => false]);
46                 $deleted = DBA::count('user', ['account_removed' => true]);
47
48                 $tabs = [
49                         [
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',
55                                 'accesskey' => 'a',
56                         ],
57                         [
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',
63                                 'accesskey' => 'k',
64                         ],
65                         [
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',
71                                 'accesskey' => 'p',
72                         ],
73                         [
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',
79                                 'accesskey' => 'b',
80                         ],
81                         [
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',
87                                 'accesskey' => 'd',
88                         ],
89                 ];
90
91                 $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
92                 return Renderer::replaceMacros($tpl, ['$tabs' => $tabs]);
93         }
94
95         protected static function setupUserCallback() {
96                 $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
97                 return function ($user) use ($adminlist) {
98                         $page_types = [
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')
104                         ];
105                         $account_types = [
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'),
111                         ];
112
113                         $user['page_flags_raw'] = $user['page-flags'];
114                         $user['page_flags'] = $page_types[$user['page-flags']];
115
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']] : '';
118
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);
125
126                         return $user;
127                 };
128         }
129 }