Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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: 09.10.2024, 12:54 - Dateigröße: 8.37 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\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 \phpbb\exception\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          $submit = $this->request->variable('submit', '');
109          $cancel = $this->request->variable('cancel', '');
110   
111          $error = array();
112          $s_hidden_fields = '';
113   
114          $redirect_url = append_sid(
115              $this->phpbb_root_path . ( ($mode === 'pm') ? 'ucp' : 'viewtopic' ) . ".{$this->php_ext}",
116              ($mode == 'pm') ? "i=pm&mode=view&p=$id" : "p=$id"
117          );
118          $redirect_url .= ($mode === 'post') ? "#p$id" : '';
119   
120          // Set up CAPTCHA if necessary
121          if ($this->config['enable_post_confirm'] && !$this->user->data['is_registered'])
122          {
123              $captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
124              $captcha->init(CONFIRM_REPORT);
125          }
126   
127          //Has the report been cancelled?
128          if (!empty($cancel))
129          {
130              return new RedirectResponse($redirect_url, 302);
131          }
132   
133          // Check CAPTCHA, if the form was submited
134          if (!empty($submit) && isset($captcha))
135          {
136              $captcha_template_array = $this->check_captcha($captcha);
137              $error = $captcha_template_array['error'];
138              $s_hidden_fields = $captcha_template_array['hidden_fields'];
139          }
140   
141          // Handle request
142          try
143          {
144              if (!empty($submit) && sizeof($error) === 0)
145              {
146                  $this->report_handler->add_report(
147                      (int) $id,
148                      (int) $reason_id,
149                      (string) $report_text,
150                      (int) $user_notify
151                  );
152   
153                  // Send success message
154                  switch ($mode)
155                  {
156                      case 'pm':
157                          $lang_return = $this->user->lang['RETURN_PM'];
158                          $lang_success = $this->user->lang['PM_REPORTED_SUCCESS'];
159                      break;
160                      case 'post':
161                          $lang_return = $this->user->lang['RETURN_TOPIC'];
162                          $lang_success = $this->user->lang['POST_REPORTED_SUCCESS'];
163                      break;
164                  }
165   
166                  $this->helper->assign_meta_refresh_var(3, $redirect_url);
167                  $message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
168                  return $this->helper->message($message);
169              }
170              else
171              {
172                  $this->report_handler->validate_report_request($id);
173              }
174          }
175          catch (\phpbb\report\exception\pm_reporting_disabled_exception $exception)
176          {
177              throw new http_exception(404, 'PAGE_NOT_FOUND');
178          }
179          catch (\phpbb\report\exception\already_reported_exception $exception)
180          {
181              switch ($mode)
182              {
183                  case 'pm':
184                      $message = $this->user->lang['ALREADY_REPORTED_PM'];
185                      $message .= '<br /><br />' . sprintf($this->user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
186                  break;
187                  case 'post':
188                      $message = $this->user->lang['ALREADY_REPORTED'];
189                      $message .= '<br /><br />' . sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
190                  break;
191              }
192   
193              return $this->helper->message($message);
194          }
195          catch (\phpbb\report\exception\report_permission_denied_exception $exception)
196          {
197              $message = $exception->getMessage();
198              if (isset($this->user->lang[$message]))
199              {
200                  $message = $this->user->lang[$message];
201              }
202   
203              throw new http_exception(403, $message);
204          }
205          catch (\phpbb\report\exception\entity_not_found_exception $exception)
206          {
207              $message = $exception->getMessage();
208              if (isset($this->user->lang[$message]))
209              {
210                  $message = $this->user->lang[$message];
211              }
212   
213              throw new http_exception(404, $message);
214          }
215          catch (\phpbb\report\exception\empty_report_exception $exception)
216          {
217              $error[] = $this->user->lang['EMPTY_REPORT'];
218          }
219          catch (\phpbb\report\exception\invalid_report_exception $exception)
220          {
221              return $this->helper->message($exception->getMessage());
222          }
223   
224          // Setting up an rendering template
225          $page_title = ($mode === 'pm') ? $this->user->lang['REPORT_MESSAGE'] : $this->user->lang['REPORT_POST'];
226          $this->assign_template_data(
227              $mode,
228              $id,
229              $reason_id,
230              $report_text,
231              $user_notify,
232              $error,
233              $s_hidden_fields,
234              ( isset($captcha) ? $captcha : false )
235          );
236   
237          return $this->helper->render('report_body.html', $page_title);
238      }
239   
240      /**
241       * Assigns template variables
242       *
243       * @param    int        $mode
244       * @param    int        $id
245       * @param    int        $reason_id
246       * @param    string    $report_text
247       * @param    mixed    $user_notify
248       * @param     array    $error
249       * @param    string    $s_hidden_fields
250       * @param    mixed    $captcha
251       * @return    null
252       */
253      protected function assign_template_data($mode, $id, $reason_id, $report_text, $user_notify, $error = array(), $s_hidden_fields = '', $captcha = false)
254      {
255          if ($captcha !== false && $captcha->is_solved() === false)
256          {
257              $this->template->assign_vars(array(
258                  'S_CONFIRM_CODE'    => true,
259                  'CAPTCHA_TEMPLATE'    => $captcha->get_template(),
260              ));
261          }
262   
263          $this->report_reason_provider->display_reasons($reason_id);
264   
265          switch ($mode)
266          {
267              case 'pm':
268                  $report_route = $this->helper->route('phpbb_report_pm_controller', array('id' => $id));
269              break;
270              case 'post':
271                  $report_route = $this->helper->route('phpbb_report_post_controller', array('id' => $id));
272              break;
273          }
274   
275          $this->template->assign_vars(array(
276              'ERROR'                => (sizeof($error) > 0) ? implode('<br />', $error) : '',
277              'S_REPORT_POST'        => ($mode === 'pm') ? false : true,
278              'REPORT_TEXT'        => $report_text,
279              'S_HIDDEN_FIELDS'    => (!empty($s_hidden_fields)) ? $s_hidden_fields : null,
280              'S_REPORT_ACTION'    => $report_route,
281   
282              'S_NOTIFY'            => $user_notify,
283              'S_CAN_NOTIFY'        => ($this->user->data['is_registered']) ? true : false,
284              'S_IN_REPORT'        => true,
285          ));
286      }
287   
288      /**
289       * Check CAPTCHA
290       *
291       * @param    object    $captcha    A phpBB CAPTCHA object
292       * @return    array    template variables which ensures that CAPTCHA's work correctly
293       */
294      protected function check_captcha($captcha)
295      {
296          $error = array();
297          $captcha_hidden_fields = '';
298   
299          $visual_confirmation_response = $captcha->validate();
300          if ($visual_confirmation_response)
301          {
302              $error[] = $visual_confirmation_response;
303          }
304   
305          if (sizeof($error) === 0)
306          {
307              $captcha->reset();
308          }
309          else if ($captcha->is_solved() !== false)
310          {
311              $captcha_hidden_fields = build_hidden_fields($captcha->get_hidden_fields());
312          }
313   
314          return array(
315              'error' => $error,
316              'hidden_fields' => $captcha_hidden_fields,
317          );
318      }
319  }
320