[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/report/controller/ -> report.php (source)

   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  namespace phpbb\report\controller;
  15  
  16  use phpbb\exception\http_exception;
  17  use Symfony\Component\HttpFoundation\RedirectResponse;
  18  
  19  class report
  20  {
  21      /**
  22       * @var \phpbb\config\config
  23       */
  24      protected $config;
  25  
  26      /**
  27       * @var \phpbb\user
  28       */
  29      protected $user;
  30  
  31      /**
  32       * @var \phpbb\template\template
  33       */
  34      protected $template;
  35  
  36      /**
  37       * @var \phpbb\controller\helper
  38       */
  39      protected $helper;
  40  
  41      /**
  42       * @var \phpbb\request\request_interface
  43       */
  44      protected $request;
  45  
  46      /**
  47       * @var \phpbb\captcha\factory
  48       */
  49      protected $captcha_factory;
  50  
  51      /**
  52       * @var string
  53       */
  54      protected $phpbb_root_path;
  55  
  56      /**
  57       * @var string
  58       */
  59      protected $php_ext;
  60  
  61      /**
  62       * @var \phpbb\report\report_handler_interface
  63       */
  64      protected $report_handler;
  65  
  66      /**
  67       * @var \phpbb\report\report_reason_list_provider
  68       */
  69      protected $report_reason_provider;
  70  
  71  	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)
  72      {
  73          $this->config            = $config;
  74          $this->user                = $user;
  75          $this->template            = $template;
  76          $this->helper            = $helper;
  77          $this->request            = $request;
  78          $this->phpbb_root_path    = $phpbb_root_path;
  79          $this->php_ext            = $php_ext;
  80          $this->captcha_factory    = $captcha_factory;
  81          $this->report_handler    = $report_factory;
  82  
  83          // User interface factory
  84          $this->report_reason_provider = $ui_provider;
  85      }
  86  
  87      /**
  88       * Controller for /path_to_entities/{id}/report routes
  89       *
  90       * Because of how phpBB organizes routes $mode must be set in the route config.
  91       *
  92       * @param int        $id        ID of the entity to report
  93       * @param string    $mode
  94       * @return \Symfony\Component\HttpFoundation\Response a Symfony response object
  95       * @throws http_exception when $mode or $id is invalid for some reason
  96       */
  97  	public function handle($id, $mode)
  98      {
  99          // 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  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1