Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
report.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\report\controller;
015
016 use phpbb\exception\http_exception;
017 use Symfony\Component\HttpFoundation\RedirectResponse;
018
019 class report
020 {
021 /**
022 * @var \phpbb\config\config
023 */
024 protected $config;
025
026 /**
027 * @var \phpbb\user
028 */
029 protected $user;
030
031 /**
032 * @var \phpbb\template\template
033 */
034 protected $template;
035
036 /**
037 * @var \phpbb\controller\helper
038 */
039 protected $helper;
040
041 /**
042 * @var \phpbb\request\request_interface
043 */
044 protected $request;
045
046 /**
047 * @var \phpbb\captcha\factory
048 */
049 protected $captcha_factory;
050
051 /**
052 * @var string
053 */
054 protected $phpbb_root_path;
055
056 /**
057 * @var string
058 */
059 protected $php_ext;
060
061 /**
062 * @var \phpbb\report\report_handler_interface
063 */
064 protected $report_handler;
065
066 /**
067 * @var \phpbb\report\report_reason_list_provider
068 */
069 protected $report_reason_provider;
070
071 public function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\template\template $template, \phpbb\controller\helper $helper, \phpbb\request\request_interface $request, \phpbb\captcha\factory $captcha_factory, \phpbb\report\handler_factory $report_factory, \phpbb\report\report_reason_list_provider $ui_provider, $phpbb_root_path, $php_ext)
072 {
073 $this->config = $config;
074 $this->user = $user;
075 $this->template = $template;
076 $this->helper = $helper;
077 $this->request = $request;
078 $this->phpbb_root_path = $phpbb_root_path;
079 $this->php_ext = $php_ext;
080 $this->captcha_factory = $captcha_factory;
081 $this->report_handler = $report_factory;
082
083 // User interface factory
084 $this->report_reason_provider = $ui_provider;
085 }
086
087 /**
088 * Controller for /path_to_entities/{id}/report routes
089 *
090 * Because of how phpBB organizes routes $mode must be set in the route config.
091 *
092 * @param int $id ID of the entity to report
093 * @param string $mode
094 * @return \Symfony\Component\HttpFoundation\Response a Symfony response object
095 * @throws http_exception when $mode or $id is invalid for some reason
096 */
097 public function handle($id, $mode)
098 {
099 // Get report handler
100 $this->report_handler = $this->report_handler->get_instance($mode);
101
102 $this->user->add_lang('mcp');
103
104 $user_notify = ($this->user->data['is_registered']) ? $this->request->variable('notify', 0) : false;
105 $reason_id = $this->request->variable('reason_id', 0);
106 $report_text = $this->request->variable('report_text', '', true);
107
108 /**
109 * Replace Emojis and other 4bit UTF-8 chars not allowed by MySQL to UCR/NCR.
110 * Using their Numeric Character Reference's Hexadecimal notation.
111 */
112 $report_text = utf8_encode_ucr($report_text);
113
114 $submit = $this->request->variable('submit', '');
115 $cancel = $this->request->variable('cancel', '');
116
117 $error = array();
118 $s_hidden_fields = '';
119
120 $redirect_url = append_sid(
121 $this->phpbb_root_path . ( ($mode === 'pm') ? 'ucp' : 'viewtopic' ) . ".{$this->php_ext}",
122 ($mode == 'pm') ? "i=pm&mode=view&p=$id" : "p=$id"
123 );
124 $redirect_url .= ($mode === 'post') ? "#p$id" : '';
125
126 // Set up CAPTCHA if necessary
127 if ($this->config['enable_post_confirm'] && !$this->user->data['is_registered'])
128 {
129 $captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
130 $captcha->init(CONFIRM_REPORT);
131 }
132
133 //Has the report been cancelled?
134 if (!empty($cancel))
135 {
136 return new RedirectResponse($redirect_url, 302);
137 }
138
139 // Check CAPTCHA, if the form was submited
140 if (!empty($submit) && isset($captcha))
141 {
142 $captcha_template_array = $this->check_captcha($captcha);
143 $error = $captcha_template_array['error'];
144 $s_hidden_fields = $captcha_template_array['hidden_fields'];
145 }
146
147 // Handle request
148 try
149 {
150 if (!empty($submit) && count($error) === 0)
151 {
152 $this->report_handler->add_report(
153 (int) $id,
154 (int) $reason_id,
155 (string) $report_text,
156 (int) $user_notify
157 );
158
159 // Send success message
160 switch ($mode)
161 {
162 case 'pm':
163 $lang_return = $this->user->lang['RETURN_PM'];
164 $lang_success = $this->user->lang['PM_REPORTED_SUCCESS'];
165 break;
166 case 'post':
167 $lang_return = $this->user->lang['RETURN_TOPIC'];
168 $lang_success = $this->user->lang['POST_REPORTED_SUCCESS'];
169 break;
170 }
171
172 $this->helper->assign_meta_refresh_var(3, $redirect_url);
173 $message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
174 return $this->helper->message($message);
175 }
176 else
177 {
178 $this->report_handler->validate_report_request($id);
179 }
180 }
181 catch (\phpbb\report\exception\pm_reporting_disabled_exception $exception)
182 {
183 throw new http_exception(404, 'PAGE_NOT_FOUND');
184 }
185 catch (\phpbb\report\exception\already_reported_exception $exception)
186 {
187 switch ($mode)
188 {
189 case 'pm':
190 $message = $this->user->lang['ALREADY_REPORTED_PM'];
191 $message .= '<br /><br />' . sprintf($this->user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
192 break;
193 case 'post':
194 $message = $this->user->lang['ALREADY_REPORTED'];
195 $message .= '<br /><br />' . sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
196 break;
197 }
198
199 return $this->helper->message($message);
200 }
201 catch (\phpbb\report\exception\report_permission_denied_exception $exception)
202 {
203 $message = $exception->getMessage();
204 if (isset($this->user->lang[$message]))
205 {
206 $message = $this->user->lang[$message];
207 }
208
209 throw new http_exception(403, $message);
210 }
211 catch (\phpbb\report\exception\entity_not_found_exception $exception)
212 {
213 $message = $exception->getMessage();
214 if (isset($this->user->lang[$message]))
215 {
216 $message = $this->user->lang[$message];
217 }
218
219 throw new http_exception(404, $message);
220 }
221 catch (\phpbb\report\exception\empty_report_exception $exception)
222 {
223 $error[] = $this->user->lang['EMPTY_REPORT'];
224 }
225 catch (\phpbb\report\exception\invalid_report_exception $exception)
226 {
227 return $this->helper->message($exception->getMessage());
228 }
229
230 // Setting up an rendering template
231 $page_title = ($mode === 'pm') ? $this->user->lang['REPORT_MESSAGE'] : $this->user->lang['REPORT_POST'];
232 $this->assign_template_data(
233 $mode,
234 $id,
235 $reason_id,
236 $report_text,
237 $user_notify,
238 $error,
239 $s_hidden_fields,
240 ( isset($captcha) ? $captcha : false )
241 );
242
243 return $this->helper->render('report_body.html', $page_title);
244 }
245
246 /**
247 * Assigns template variables
248 *
249 * @param int $mode
250 * @param int $id
251 * @param int $reason_id
252 * @param string $report_text
253 * @param mixed $user_notify
254 * @param array $error
255 * @param string $s_hidden_fields
256 * @param mixed $captcha
257 * @return null
258 */
259 protected function assign_template_data($mode, $id, $reason_id, $report_text, $user_notify, $error = array(), $s_hidden_fields = '', $captcha = false)
260 {
261 if ($captcha !== false && $captcha->is_solved() === false)
262 {
263 $this->template->assign_vars(array(
264 'S_CONFIRM_CODE' => true,
265 'CAPTCHA_TEMPLATE' => $captcha->get_template(),
266 ));
267 }
268
269 $this->report_reason_provider->display_reasons($reason_id);
270
271 switch ($mode)
272 {
273 case 'pm':
274 $report_route = $this->helper->route('phpbb_report_pm_controller', array('id' => $id));
275 break;
276 case 'post':
277 $report_route = $this->helper->route('phpbb_report_post_controller', array('id' => $id));
278 break;
279 }
280
281 $this->template->assign_vars(array(
282 'ERROR' => (count($error) > 0) ? implode('<br />', $error) : '',
283 'S_REPORT_POST' => ($mode === 'pm') ? false : true,
284 'REPORT_TEXT' => $report_text,
285 'S_HIDDEN_FIELDS' => (!empty($s_hidden_fields)) ? $s_hidden_fields : null,
286 'S_REPORT_ACTION' => $report_route,
287
288 'S_NOTIFY' => $user_notify,
289 'S_CAN_NOTIFY' => ($this->user->data['is_registered']) ? true : false,
290 'S_IN_REPORT' => true,
291 ));
292 }
293
294 /**
295 * Check CAPTCHA
296 *
297 * @param object $captcha A phpBB CAPTCHA object
298 * @return array template variables which ensures that CAPTCHA's work correctly
299 */
300 protected function check_captcha($captcha)
301 {
302 $error = array();
303 $captcha_hidden_fields = '';
304
305 $visual_confirmation_response = $captcha->validate();
306 if ($visual_confirmation_response)
307 {
308 $error[] = $visual_confirmation_response;
309 }
310
311 if (count($error) === 0)
312 {
313 $captcha->reset();
314 }
315 else if ($captcha->is_solved() !== false)
316 {
317 $captcha_hidden_fields = build_hidden_fields($captcha->get_hidden_fields());
318 }
319
320 return array(
321 'error' => $error,
322 'hidden_fields' => $captcha_hidden_fields,
323 );
324 }
325 }
326