]> git.mxchange.org Git - friendica.git/blob - src/Module/Moderation/BaseUsers.php
The query condition for active users are unified
[friendica.git] / src / Module / Moderation / BaseUsers.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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\Moderation;
23
24 use Friendica\App;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Renderer;
27 use Friendica\Core\Session\Capability\IHandleUserSessions;
28 use Friendica\Database\Database;
29 use Friendica\DI;
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;
39
40 abstract class BaseUsers extends BaseModeration
41 {
42         /** @var Database */
43         protected $database;
44
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 = [])
46         {
47                 parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
48
49                 $this->database = $database;
50         }
51
52         /**
53          * Get the users moderation tabs menu
54          *
55          * @param string $selectedTab
56          * @return string HTML
57          * @throws ServiceUnavailableException
58          */
59         protected function getTabsHTML(string $selectedTab): string
60         {
61                 $all     = $this->database->count('user', ["`uid` != ?", 0]);
62                 $active  = $this->database->count('user', ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` 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]);
66
67                 $tabs = [
68                         [
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',
74                                 'accesskey' => 'a',
75                         ],
76                         [
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',
82                                 'accesskey' => 'k',
83                         ],
84                         [
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',
90                                 'accesskey' => 'p',
91                         ],
92                         [
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',
98                                 'accesskey' => 'b',
99                         ],
100                         [
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',
106                                 'accesskey' => 'd',
107                         ],
108                 ];
109
110                 $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
111                 return Renderer::replaceMacros($tpl, ['$tabs' => $tabs]);
112         }
113
114         protected function setupUserCallback(): \Closure
115         {
116                 $adminlist = User::getAdminEmailList();
117                 return function ($user) use ($adminlist) {
118                         $page_types = [
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 Group'),
122                                 User::PAGE_FLAGS_FREELOVE  => $this->t('Automatic Friend Page'),
123                                 User::PAGE_FLAGS_PRVGROUP  => $this->t('Private Group')
124                         ];
125                         $account_types = [
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 Group'),
130                                 User::ACCOUNT_TYPE_RELAY        => $this->t('Relay'),
131                         ];
132
133                         $user['page_flags_raw'] = $user['page-flags'];
134                         $user['page_flags']     = $page_types[$user['page-flags']];
135
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']] : '';
138
139                         $user['register_date'] = Temporal::getRelativeDate($user['register_date']);
140                         $user['login_date']    = Temporal::getRelativeDate($user['last-activity'], false);
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;
145
146                         return $user;
147                 };
148         }
149 }