Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 85
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
acp_ban
0.00% covered (danger)
0.00%
0 / 83
0.00% covered (danger)
0.00%
0 / 1
272
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 83
0.00% covered (danger)
0.00%
0 / 1
272
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @ignore
16*/
17
18use phpbb\ban\exception\type_not_found_exception;
19use phpbb\ban\manager;
20use phpbb\language\language;
21
22if (!defined('IN_PHPBB'))
23{
24    exit;
25}
26
27class acp_ban
28{
29    var $u_action;
30
31    function main($id, $mode)
32    {
33        global $language, $template, $request, $phpbb_dispatcher, $phpbb_container;
34        global $phpbb_root_path, $phpEx;
35
36        /** @var manager $ban_manager */
37        $ban_manager = $phpbb_container->get('ban.manager');
38
39        if (!function_exists('user_ban'))
40        {
41            include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
42        }
43
44        $bansubmit    = $request->is_set_post('bansubmit');
45        $unbansubmit = $request->is_set_post('unbansubmit');
46
47        /** @var language $language */
48        $language->add_lang(['acp/ban', 'acp/users']);
49        $this->tpl_name = 'acp_ban';
50        $form_key = 'acp_ban';
51        add_form_key($form_key);
52
53        if (($bansubmit || $unbansubmit) && !check_form_key($form_key))
54        {
55            trigger_error($language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING);
56        }
57
58        // Ban submitted?
59        if ($bansubmit)
60        {
61            // Grab the list of entries
62            $ban                = $request->variable('ban', '', true);
63            $ban_length            = $request->variable('banlength', 0);
64            $ban_length_other    = $request->variable('banlengthother', '');
65            $ban_reason            = $request->variable('banreason', '', true);
66            $ban_give_reason    = $request->variable('bangivereason', '', true);
67
68            if ($ban)
69            {
70                $abort_ban = false;
71                /**
72                * Use this event to modify the ban details before the ban is performed
73                *
74                * @event core.acp_ban_before
75                * @var    string    mode                One of the following: user, ip, email
76                * @var    string    ban                    Either string or array with usernames, ips or email addresses
77                * @var    int        ban_length            Ban length in minutes
78                * @var    string    ban_length_other    Ban length as a date (YYYY-MM-DD)
79                * @var    string    ban_reason            Ban reason displayed to moderators
80                * @var    string    ban_give_reason        Ban reason displayed to the banned user
81                * @var    mixed    abort_ban            Either false, or an error message that is displayed to the user.
82                *                                    If a string is given the bans are not issued.
83                * @since 3.1.0-RC5
84                */
85                $vars = array(
86                    'mode',
87                    'ban',
88                    'ban_length',
89                    'ban_length_other',
90                    'ban_reason',
91                    'ban_give_reason',
92                    'abort_ban',
93                );
94                extract($phpbb_dispatcher->trigger_event('core.acp_ban_before', compact($vars)));
95
96                if ($abort_ban)
97                {
98                    trigger_error($abort_ban . adm_back_link($this->u_action));
99                }
100
101                $ban_start = new \DateTime();
102                $ban_start->setTimestamp(time());
103                $ban_end = $ban_manager->get_ban_end($ban_start, $ban_length, $ban_length_other);
104
105                $ban = explode("\n", $ban);
106                try
107                {
108                    $ban_manager->ban($mode, $ban, $ban_start, $ban_end, $ban_reason, $ban_give_reason);
109                }
110                catch (\phpbb\exception\exception_interface $exception)
111                {
112                    trigger_error($language->lang_array($exception->getMessage(), $exception->get_parameters()), E_USER_WARNING);
113                }
114
115                /**
116                * Use this event to perform actions after the ban has been performed
117                *
118                * @event core.acp_ban_after
119                * @var    string    mode                One of the following: user, ip, email
120                * @var    string    ban                    Either string or array with usernames, ips or email addresses
121                * @var    int        ban_length            Ban length in minutes
122                * @var    string    ban_length_other    Ban length as a date (YYYY-MM-DD)
123                * @var    string    ban_reason            Ban reason displayed to moderators
124                * @var    string    ban_give_reason        Ban reason displayed to the banned user
125                * @since 3.1.0-RC5
126                */
127                $vars = array(
128                    'mode',
129                    'ban',
130                    'ban_length',
131                    'ban_length_other',
132                    'ban_reason',
133                    'ban_give_reason',
134                );
135                extract($phpbb_dispatcher->trigger_event('core.acp_ban_after', compact($vars)));
136
137                trigger_error($language->lang('BAN_UPDATE_SUCCESSFUL') . adm_back_link($this->u_action));
138            }
139        }
140        else if ($unbansubmit)
141        {
142            $ban = $request->variable('unban', ['']);
143
144            if ($ban)
145            {
146                $ban_manager->unban($mode, $ban);
147
148                trigger_error($language->lang('BAN_UPDATE_SUCCESSFUL') . adm_back_link($this->u_action));
149            }
150        }
151
152        // Define language vars
153        $this->page_title = $language->lang(strtoupper($mode) . '_BAN');
154
155        $l_ban_explain = $language->lang(strtoupper($mode) . '_BAN_EXPLAIN');
156        $l_unban_title = $language->lang(strtoupper($mode) . '_UNBAN');
157        $l_unban_explain = $language->lang(strtoupper($mode) . '_UNBAN_EXPLAIN');
158        $l_no_ban_cell = $language->lang(strtoupper($mode) . '_NO_BANNED');
159
160        switch ($mode)
161        {
162            case 'user':
163                $l_ban_cell = $language->lang('USERNAME');
164            break;
165
166            case 'ip':
167                $l_ban_cell = $language->lang('IP_HOSTNAME');
168            break;
169
170            case 'email':
171                $l_ban_cell = $language->lang('EMAIL_ADDRESS');
172            break;
173
174            default:
175                throw new type_not_found_exception();
176        }
177
178        display_ban_end_options();
179        display_ban_options($mode);
180
181        $template->assign_vars(array(
182            'L_TITLE'                => $this->page_title,
183            'L_EXPLAIN'                => $l_ban_explain,
184            'L_UNBAN_TITLE'            => $l_unban_title,
185            'L_UNBAN_EXPLAIN'        => $l_unban_explain,
186            'L_BAN_CELL'            => $l_ban_cell,
187            'L_NO_BAN_CELL'            => $l_no_ban_cell,
188
189            'S_USERNAME_BAN'    => $mode == 'user' ? true : false,
190
191            'U_ACTION'            => $this->u_action,
192            'U_FIND_USERNAME'    => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=acp_ban&amp;field=ban'),
193        ));
194    }
195}