Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

report.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 8.83 KiB


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