1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-07 15:05:43 +02:00

[ticket/13654] Moving reporting into controller

Moving report.php's content into different services and controllers to
better comply with the MVC model.

Also implementing:
 * Replacement for reasons_display()
 * Adding assign_meta_refresh_var() to \controller\helper
 * Adding separate routes for easy configuration
 * Updating unit tests to expect to correct results
 * Add BC tests

PHPBB3-13654
This commit is contained in:
MateBartus 2015-02-25 21:13:20 +01:00
parent 2c0b1252c8
commit a089ff5eb0
26 changed files with 1208 additions and 343 deletions

View File

@ -13,6 +13,7 @@ imports:
- { resource: services_notification.yml }
- { resource: services_password.yml }
- { resource: services_profilefield.yml }
- { resource: services_report.yml }
- { resource: services_text_formatter.yml }
- { resource: services_twig.yml }
- { resource: services_user.yml }

View File

@ -0,0 +1,53 @@
services:
# ----- Report controller -----
phpbb.report.controller:
class: phpbb\report\controller\report
arguments:
- @config
- @user
- @template
- @controller.helper
- @request
- @captcha.factory
- @phpbb.report.handler_factory
- @phpbb.report.report_reason_list_provider
- %core.root_path%
- %core.php_ext%
# ----- Report handler factory -----
phpbb.report.handler_factory:
class: phpbb\report\handler_factory
arguments:
- @service_container
# ----- Report UI provider -----
phpbb.report.report_reason_list_provider:
class: phpbb\report\report_reason_list_provider
arguments:
- @dbal.conn.driver
- @template
- @user
# ----- Report handlers -----
# Scope MUST be prototype for all the handlers to work correctly.
phpbb.report.handlers.report_handler_pm:
class: phpbb\report\report_handler_pm
scope: prototype
arguments:
- @dbal.conn.driver
- @dispatcher
- @config
- @auth
- @user
- @notification_manager
phpbb.report.handlers.report_handler_post:
class: phpbb\report\report_handler_post
scope: prototype
arguments:
- @dbal.conn.driver
- @dispatcher
- @config
- @auth
- @user
- @notification_manager

View File

@ -0,0 +1,17 @@
phpbb_report_pm_controller:
path: /pm/{id}/report
methods: [GET, POST]
defaults:
_controller: phpbb.report.controller:handle
mode: "pm"
requirements:
id: \d+
phpbb_report_post_controller:
path: /post/{id}/report
methods: [GET, POST]
defaults:
_controller: phpbb.report.controller:handle
mode: "post"
requirements:
id: \d+

View File

@ -11,3 +11,6 @@
phpbb_help_routing:
resource: "help.yml"
prefix: /help
phpbb_report_routing:
resource: "report.yml"

View File

@ -1097,33 +1097,14 @@ function display_custom_bbcodes()
/**
* Display reasons
*
* @deprecated 3.2.0-dev
*/
function display_reasons($reason_id = 0)
{
global $db, $user, $template;
global $phpbb_container;
$sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . '
ORDER BY reason_order ASC';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
{
$row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
}
$template->assign_block_vars('reason', array(
'ID' => $row['reason_id'],
'TITLE' => $row['reason_title'],
'DESCRIPTION' => $row['reason_description'],
'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false)
);
}
$db->sql_freeresult($result);
$phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id);
}
/**

View File

@ -1402,11 +1402,6 @@ class mcp_queue
}
else
{
if (!function_exists('display_reasons'))
{
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
}
$show_notify = false;
foreach ($post_info as $post_data)
@ -1426,7 +1421,7 @@ class mcp_queue
$confirm_template = 'mcp_approve.html';
if ($is_disapproving)
{
display_reasons($reason_id);
$phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id);
}
else
{

View File

@ -232,7 +232,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
'U_DELETE' => ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '',
'U_EMAIL' => $user_info['email'],
'U_REPORT' => ($config['allow_pm_report']) ? append_sid("{$phpbb_root_path}report.$phpEx", "pm=" . $message_row['msg_id']) : '',
'U_REPORT' => ($config['allow_pm_report']) ? $phpbb_container->get('controller.helper')->route('phpbb_report_pm_controller', array('id' => $message_row['msg_id'])) : '',
'U_QUOTE' => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=quote&f=$folder_id&p=" . $message_row['msg_id'] : '',
'U_EDIT' => (($message_row['message_time'] > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time']) && $folder_id == PRIVMSGS_OUTBOX && $auth->acl_get('u_pm_edit')) ? "$url&mode=compose&action=edit&f=$folder_id&p=" . $message_row['msg_id'] : '',
'U_POST_REPLY_PM' => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=reply&f=$folder_id&p=" . $message_row['msg_id'] : '',

View File

@ -223,6 +223,20 @@ class helper
return $this->render('message_body.html', $this->user->lang($title), $code);
}
/**
* Assigns automatic refresh time meta tag in template
*
* @param int $time time in seconds, when redirection should occur
* @param string $url the URL where the user should be redirected
* @return null
*/
public function assign_meta_refresh_var($time, $url)
{
$this->template->assign_vars(array(
'META' => '<meta http-equiv="refresh" content="' . $time . '; url=' . $url . '" />',
));
}
/**
* Return the current url
*

View File

@ -0,0 +1,319 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report\controller;
use phpbb\exception\http_exception;
use Symfony\Component\HttpFoundation\RedirectResponse;
class report
{
/**
* @var \phpbb\config\db
*/
protected $config;
/**
* @var \phpbb\user
*/
protected $user;
/**
* @var \phpbb\template\template
*/
protected $template;
/**
* @var \phpbb\controller\helper
*/
protected $helper;
/**
* @var \phpbb\request\request_interface
*/
protected $request;
/**
* @var \phpbb\captcha\factory
*/
protected $captcha_factory;
/**
* @var string
*/
protected $phpbb_root_path;
/**
* @var string
*/
protected $php_ext;
/**
* @var \phpbb\report\report_handler_interface
*/
protected $report_handler;
/**
* @var \phpbb\report\report_reason_list_provider
*/
protected $report_reason_provider;
public function __construct(\phpbb\config\db $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)
{
$this->config = $config;
$this->user = $user;
$this->template = $template;
$this->helper = $helper;
$this->request = $request;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->captcha_factory = $captcha_factory;
$this->report_handler = $report_factory;
// User interface factory
$this->report_reason_provider = $ui_provider;
}
/**
* Controller for /path_to_entities/{id}/report routes
*
* Because of how phpBB organizes routes $mode must be set in the route config.
*
* @param int $id ID of the entity to report
* @param string $mode
* @return \Symfony\Component\HttpFoundation\Response a Symfony response object
* @throws \phpbb\exception\http_exception when $mode or $id is invalid for some reason
*/
public function handle($id, $mode)
{
// Get report handler
$this->report_handler = $this->report_handler->get_instance($mode);
$this->user->add_lang('mcp');
$user_notify = ($this->user->data['is_registered']) ? $this->request->variable('notify', 0) : false;
$reason_id = $this->request->variable('reason_id', 0);
$report_text = $this->request->variable('report_text', '', true);
$submit = $this->request->variable('submit', '');
$cancel = $this->request->variable('cancel', '');
$error = array();
$s_hidden_fields = '';
$redirect_url = append_sid(
$this->phpbb_root_path . ( ($mode === 'pm') ? 'ucp' : 'viewtopic' ) . ".{$this->php_ext}",
($mode == 'pm') ? "i=pm&mode=view&p=$id" : "p=$id"
);
$redirect_url .= ($mode === 'post') ? "#p$id" : '';
// Set up CAPTCHA if necessary
if ($this->config['enable_post_confirm'] && !$this->user->data['is_registered'])
{
$captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
$captcha->init(CONFIRM_REPORT);
}
//Has the report been cancelled?
if (!empty($cancel))
{
return new RedirectResponse($redirect_url, 302);
}
// Check CAPTCHA, if the form was submited
if (!empty($submit) && isset($captcha))
{
$captcha_template_array = $this->check_captcha($captcha);
$error = $captcha_template_array['error'];
$s_hidden_fields = $captcha_template_array['hidden_fields'];
}
// Handle request
try
{
if (!empty($submit) && sizeof($error) === 0)
{
$this->report_handler->add_report(
(int) $id,
(int) $reason_id,
(string) $report_text,
(int) $user_notify
);
// Send success message
switch ($mode)
{
case 'pm':
$lang_return = $this->user->lang['RETURN_PM'];
$lang_success = $this->user->lang['PM_REPORTED_SUCCESS'];
break;
case 'post':
$lang_return = $this->user->lang['RETURN_TOPIC'];
$lang_success = $this->user->lang['POST_REPORTED_SUCCESS'];
break;
}
$this->helper->assign_meta_refresh_var(3, $redirect_url);
$message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
return $this->helper->message($message);
}
else
{
$this->report_handler->validate_report_request($id);
}
}
catch (\phpbb\report\exception\pm_reporting_disabled_exception $exception)
{
throw new http_exception(404, 'PAGE_NOT_FOUND');
}
catch (\phpbb\report\exception\already_reported_exception $exception)
{
switch ($mode)
{
case 'pm':
$message = $this->user->lang['ALREADY_REPORTED_PM'];
$message .= '<br /><br />' . sprintf($this->user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
break;
case 'post':
$message = $this->user->lang['ALREADY_REPORTED'];
$message .= '<br /><br />' . sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
break;
}
return $this->helper->message($message);
}
catch (\phpbb\report\exception\report_permission_denied_exception $exception)
{
$message = $exception->getMessage();
if (isset($this->user->lang[$message]))
{
$message = $this->user->lang[$message];
}
throw new http_exception(403, $message);
}
catch (\phpbb\report\exception\entity_not_found_exception $exception)
{
$message = $exception->getMessage();
if (isset($this->user->lang[$message]))
{
$message = $this->user->lang[$message];
}
throw new http_exception(404, $message);
}
catch (\phpbb\report\exception\empty_report_exception $exception)
{
$error[] = $this->user->lang['EMPTY_REPORT'];
}
catch (\phpbb\report\exception\invalid_report_exception $exception)
{
return $this->helper->message($exception->getMessage());
}
// Setting up an rendering template
$page_title = ($mode === 'pm') ? $this->user->lang['REPORT_MESSAGE'] : $this->user->lang['REPORT_POST'];
$this->assign_template_data(
$mode,
$id,
$reason_id,
$report_text,
$user_notify,
$error,
$s_hidden_fields,
( isset($captcha) ? $captcha : false )
);
return $this->helper->render('report_body.html', $page_title);
}
/**
* Assigns template variables
*
* @param int $mode
* @param int $id
* @param int $reason_id
* @param string $report_text
* @param mixed $user_notify
* @param array $error
* @param string $s_hidden_fields
* @param mixed $captcha
* @return null
*/
protected function assign_template_data($mode, $id, $reason_id, $report_text, $user_notify, $error = array(), $s_hidden_fields = '', $captcha = false)
{
if ($captcha !== false && $captcha->is_solved() === false)
{
$this->template->assign_vars(array(
'S_CONFIRM_CODE' => true,
'CAPTCHA_TEMPLATE' => $captcha->get_template(),
));
}
$this->report_reason_provider->display_reasons($reason_id);
switch ($mode)
{
case 'pm':
$report_route = $this->helper->route('phpbb_report_pm_controller', array('id' => $id));
break;
case 'post':
$report_route = $this->helper->route('phpbb_report_post_controller', array('id' => $id));
break;
}
$this->template->assign_vars(array(
'ERROR' => (sizeof($error) > 0) ? implode('<br />', $error) : '',
'S_REPORT_POST' => ($mode === 'pm') ? false : true,
'REPORT_TEXT' => $report_text,
'S_HIDDEN_FIELDS' => (!empty($s_hidden_fields)) ? $s_hidden_fields : null,
'S_REPORT_ACTION' => $report_route,
'S_NOTIFY' => $user_notify,
'S_CAN_NOTIFY' => ($this->user->data['is_registered']) ? true : false,
'S_IN_REPORT' => true,
));
}
/**
* Check CAPTCHA
*
* @param object $captcha A phpBB CAPTCHA object
* @return array template variables which ensures that CAPTCHA's work correctly
*/
protected function check_captcha($captcha)
{
$error = array();
$captcha_hidden_fields = '';
$visual_confirmation_response = $captcha->validate();
if ($visual_confirmation_response)
{
$error[] = $visual_confirmation_response;
}
if (sizeof($error) === 0)
{
$captcha->reset();
}
else if ($captcha->is_solved() !== false)
{
$captcha_hidden_fields = build_hidden_fields($captcha->get_hidden_fields());
}
return array(
'error' => $error,
'hidden_fields' => $captcha_hidden_fields,
);
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report\exception;
class already_reported_exception extends invalid_report_exception
{
}

View File

@ -0,0 +1,22 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report\exception;
class empty_report_exception extends invalid_report_exception
{
public function __construct()
{
parent::__construct('EMPTY_REPORT');
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report\exception;
class entity_not_found_exception extends invalid_report_exception
{
}

View File

@ -0,0 +1,21 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report\exception;
use \phpbb\exception\runtime_exception;
class factory_invalid_argument_exception extends runtime_exception
{
}

View File

@ -0,0 +1,21 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report\exception;
use \phpbb\exception\runtime_exception;
class invalid_report_exception extends runtime_exception
{
}

View File

@ -0,0 +1,22 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report\exception;
class pm_reporting_disabled_exception extends invalid_report_exception
{
public function __construct()
{
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report\exception;
class report_permission_denied_exception extends invalid_report_exception
{
}

View File

@ -0,0 +1,56 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report;
use phpbb\report\exception\factory_invalid_argument_exception;
class handler_factory
{
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* Constructor
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
*/
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container)
{
$this->container = $container;
}
/**
* Return a new instance of an appropriate report handler
*
* @param string $type
* @return \phpbb\report\report_handler_interface
* @throws \phpbb\report\exception\factory_invalid_argument_exception if $type is not valid
*/
public function get_instance($type)
{
switch ($type)
{
case 'pm':
return $this->container->get('phpbb.report.handlers.report_handler_pm');
break;
case 'post':
return $this->container->get('phpbb.report.handlers.report_handler_post');
break;
}
throw new factory_invalid_argument_exception();
}
}

View File

@ -0,0 +1,104 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report;
abstract class report_handler implements report_handler_interface
{
/**
* @var \phpbb\db\driver\driver_interface
*/
protected $db;
/**
* @var \phpbb\event\dispatcher_interface
*/
protected $dispatcher;
/**
* @var \phpbb\config\db
*/
protected $config;
/**
* @var \phpbb\auth\auth
*/
protected $auth;
/**
* @var \phpbb\user
*/
protected $user;
/**
* @var \phpbb\notification\manager
*/
protected $notifications;
/**
* @var array
*/
protected $report_data;
/**
* Construtor
*
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\event\dispatcher_interface $dispatcher
* @param \phpbb\config\db $config
* @param \phpbb\auth\auth $auth
* @param \phpbb\user $user
* @param \phpbb\notification\manager $notification
*/
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\config\db $config, \phpbb\auth\auth $auth, \phpbb\user $user, \phpbb\notification\manager $notification)
{
$this->db = $db;
$this->dispatcher = $dispatcher;
$this->config = $config;
$this->auth = $auth;
$this->user = $user;
$this->notifications = $notification;
$this->report_data = array();
}
/**
* Creates a report entity in the database
*
* @param array $report_data
* @return int the ID of the created entity
*/
protected function create_report(array $report_data)
{
$sql_ary = array(
'reason_id' => (int) $report_data['reason_id'],
'post_id' => $report_data['post_id'],
'pm_id' => $report_data['pm_id'],
'user_id' => (int) $this->user->data['user_id'],
'user_notify' => (int) $report_data['user_notify'],
'report_closed' => 0,
'report_time' => (int) time(),
'report_text' => (string) $report_data['report_text'],
'reported_post_text' => $report_data['reported_post_text'],
'reported_post_uid' => $report_data['reported_post_uid'],
'reported_post_bitfield' => $report_data['reported_post_bitfield'],
'reported_post_enable_bbcode' => $report_data['reported_post_enable_bbcode'],
'reported_post_enable_smilies' => $report_data['reported_post_enable_smilies'],
'reported_post_enable_magic_url' => $report_data['reported_post_enable_magic_url'],
);
$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->db->sql_query($sql);
return $this->db->sql_nextid();
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report;
interface report_handler_interface
{
/**
* Reports a message
*
* @param int $id
* @param int $reason_id
* @param string $report_text
* @param int $user_notify
* @return null
* @throws \phpbb\report\exception\empty_report_exception when the given report is empty
* @throws \phpbb\report\exception\already_reported_exception when the entity is already reported
* @throws \phpbb\report\exception\entity_not_found_exception when the entity does not exist or the user does not have viewing permissions for it
* @throws \phpbb\report\exception\invalid_report_exception when the entity cannot be reported for some other reason
*/
public function add_report($id, $reason_id, $report_text, $user_notify);
/**
* Checks if the message is reportable
*
* @param int $id
* @return null
* @throws \phpbb\report\exception\already_reported_exception when the entity is already reported
* @throws \phpbb\report\exception\entity_not_found_exception when the entity does not exist or the user does not have viewing permissions for it
* @throws \phpbb\report\exception\invalid_report_exception when the entity cannot be reported for some other reason
*/
public function validate_report_request($id);
}

View File

@ -0,0 +1,137 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report;
use phpbb\report\exception\empty_report_exception;
use phpbb\report\exception\already_reported_exception;
use phpbb\report\exception\pm_reporting_disabled_exception;
use phpbb\report\exception\entity_not_found_exception;
class report_handler_pm extends report_handler
{
/**
* {@inheritdoc}
* @throws \phpbb\report\exception\pm_reporting_disabled_exception when PM reporting is disabled on the board
*/
public function add_report($id, $reason_id, $report_text, $user_notify)
{
// Cast the input variables
$id = (int) $id;
$reason_id = (int) $reason_id;
$report_text = (string) $report_text;
$user_notify = (int) $user_notify;
$this->validate_report_request($id);
$sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row || (empty($report_text) && strtolower($row['reason_title']) === 'other'))
{
throw new empty_report_exception();
}
$report_data = array(
'reason_id' => $reason_id,
'post_id' => 0,
'pm_id' => $id,
'user_notify' => $user_notify,
'report_text' => $report_text,
'reported_post_text' => $this->report_data['message_text'],
'reported_post_uid' => $this->report_data['bbcode_bitfield'],
'reported_post_bitfield' => $this->report_data['bbcode_uid'],
'reported_post_enable_bbcode' => $this->report_data['enable_bbcode'],
'reported_post_enable_smilies' => $this->report_data['enable_smilies'],
'reported_post_enable_magic_url' => $this->report_data['enable_magic_url'],
);
$report_id = $this->create_report($report_data);
$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
SET message_reported = 1
WHERE msg_id = ' . $id;
$this->db->sql_query($sql);
$sql_ary = array(
'msg_id' => $id,
'user_id' => ANONYMOUS,
'author_id' => (int) $this->report_data['author_id'],
'pm_deleted' => 0,
'pm_new' => 0,
'pm_unread' => 0,
'pm_replied' => 0,
'pm_marked' => 0,
'pm_forwarded' => 0,
'folder_id' => PRIVMSGS_INBOX,
);
$sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->db->sql_query($sql);
$this->notifications->add_notifications('notification.type.report_pm', array_merge($this->report_data, $row, array(
'report_text' => $report_text,
'from_user_id' => $this->report_data['author_id'],
'report_id' => $report_id,
)));
}
/**
* {@inheritdoc}
* @throws \phpbb\report\exception\pm_reporting_disabled_exception when PM reporting is disabled on the board
*/
public function validate_report_request($id)
{
$id = (int) $id;
// Check if reporting PMs is enabled
if (!$this->config['allow_pm_report'])
{
throw new pm_reporting_disabled_exception();
}
else if ($id <= 0)
{
throw new entity_not_found_exception('NO_POST_SELECTED');
}
// Grab all relevant data
$sql = 'SELECT p.*, pt.*
FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . " pt
WHERE p.msg_id = $id
AND p.msg_id = pt.msg_id
AND (p.author_id = " . $this->user->data['user_id'] . "
OR pt.user_id = " . $this->user->data['user_id'] . ")";
$result = $this->db->sql_query($sql);
$report_data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
// Check if message exists
if (!$report_data)
{
$this->user->add_lang('ucp');
throw new entity_not_found_exception('NO_MESSAGE');
}
// Check if message is already reported
if ($report_data['message_reported'])
{
throw new already_reported_exception();
}
$this->report_data = $report_data;
}
}

View File

@ -0,0 +1,175 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report;
use phpbb\report\exception\invalid_report_exception;
use phpbb\report\exception\empty_report_exception;
use phpbb\report\exception\already_reported_exception;
use phpbb\report\exception\entity_not_found_exception;
use phpbb\report\exception\report_permission_denied_exception;
class report_handler_post extends report_handler
{
/**
* @var array
*/
protected $forum_data;
/**
* {@inheritdoc}
* @throws \phpbb\report\exception\report_permission_denied_exception when the user does not have permission to report the post
*/
public function add_report($id, $reason_id, $report_text, $user_notify)
{
// Cast the input variables
$id = (int) $id;
$reason_id = (int) $reason_id;
$report_text = (string) $report_text;
$user_notify = (int) $user_notify;
$this->validate_report_request($id);
$sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row || (empty($report_text) && strtolower($row['reason_title']) === 'other'))
{
throw new empty_report_exception();
}
$report_data = array(
'reason_id' => $reason_id,
'post_id' => $id,
'pm_id' => 0,
'user_notify' => $user_notify,
'report_text' => $report_text,
'reported_post_text' => $this->report_data['post_text'],
'reported_post_uid' => $this->report_data['bbcode_bitfield'],
'reported_post_bitfield' => $this->report_data['bbcode_uid'],
'reported_post_enable_bbcode' => $this->report_data['enable_bbcode'],
'reported_post_enable_smilies' => $this->report_data['enable_smilies'],
'reported_post_enable_magic_url' => $this->report_data['enable_magic_url'],
);
$report_id = $this->create_report($report_data);
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_reported = 1
WHERE post_id = ' . $id;
$this->db->sql_query($sql);
if (!$this->report_data['topic_reported'])
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_reported = 1
WHERE topic_id = ' . $this->report_data['topic_id'] . '
OR topic_moved_id = ' . $this->report_data['topic_id'];
$this->db->sql_query($sql);
}
$this->notifications->add_notifications('notification.type.report_post', array_merge($this->report_data, $row, $this->forum_data, array(
'report_text' => $report_text,
)));
}
/**
* {@inheritdoc}
* @throws \phpbb\report\exception\report_permission_denied_exception when the user does not have permission to report the post
*/
public function validate_report_request($id)
{
$id = (int) $id;
// Check if id is valid
if ($id <= 0)
{
throw new entity_not_found_exception('NO_POST_SELECTED');
}
// Grab all relevant data
$sql = 'SELECT t.*, p.*
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
WHERE p.post_id = $id
AND p.topic_id = t.topic_id";
$result = $this->db->sql_query($sql);
$report_data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$report_data)
{
throw new entity_not_found_exception('POST_NOT_EXIST');
}
$forum_id = (int) $report_data['forum_id'];
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $forum_id;
$result = $this->db->sql_query($sql);
$forum_data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$forum_data)
{
throw new invalid_report_exception('FORUM_NOT_EXIST');
}
$acl_check_ary = array(
'f_list' => 'POST_NOT_EXIST',
'f_read' => 'USER_CANNOT_READ',
'f_report' => 'USER_CANNOT_REPORT'
);
/**
* This event allows you to do extra auth checks and verify if the user
* has the required permissions
*
* @event core.report_post_auth
* @var array forum_data All data available from the forums table on this post's forum
* @var array report_data All data available from the topics and the posts tables on this post (and its topic)
* @var array acl_check_ary An array with the ACL to be tested. The evaluation is made in the same order as the array is sorted
* The key is the ACL name and the value is the language key for the error message.
* @since 3.1.3-RC1
*/
$vars = array(
'forum_data',
'report_data',
'acl_check_ary',
);
extract($this->dispatcher->trigger_event('core.report_post_auth', compact($vars)));
$this->auth->acl($this->user->data);
foreach ($acl_check_ary as $acl => $error)
{
if (!$this->auth->acl_get($acl, $forum_id))
{
throw new report_permission_denied_exception($error);
}
}
unset($acl_check_ary);
if ($report_data['post_reported'])
{
throw new already_reported_exception();
}
$this->report_data = $report_data;
$this->forum_data = $forum_data;
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\report;
class report_reason_list_provider
{
/**
* @var \phpbb\db\driver\driver_interface
*/
protected $db;
/**
* @var \phpbb\template\template
*/
protected $template;
/**
* @var \phpbb\user
*/
protected $user;
/**
* Constructor
*
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\template\template $template
* @param \phpbb\user $user
*/
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user)
{
$this->db = $db;
$this->template = $template;
$this->user = $user;
}
/**
* Sets template variables to render report reasons select HTML input
*
* @param int $reason_id
* @return null
*/
public function display_reasons($reason_id = 0)
{
$sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . '
ORDER BY reason_order ASC';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
if (isset($this->user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($this->user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
{
$row['reason_description'] = $this->user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
$row['reason_title'] = $this->user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
}
$this->template->assign_block_vars('reason', array(
'ID' => $row['reason_id'],
'TITLE' => $row['reason_title'],
'DESCRIPTION' => $row['reason_description'],
'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false,
));
}
$this->db->sql_freeresult($result);
}
}

View File

@ -11,6 +11,8 @@
*
*/
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* @ignore
*/
@ -18,322 +20,22 @@ define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mcp');
$forum_id = $request->variable('f', 0);
$post_id = $request->variable('p', 0);
$pm_id = $request->variable('pm', 0);
$reason_id = $request->variable('reason_id', 0);
$report_text = $request->variable('report_text', '', true);
$user_notify = ($user->data['is_registered']) ? $request->variable('notify', 0) : false;
$submit = (isset($_POST['submit'])) ? true : false;
$redirect_route_name = ($pm_id === 0) ? 'phpbb_report_post_controller' : 'phpbb_report_pm_controller';
if (!$post_id && (!$pm_id || !$config['allow_pm_report']))
{
trigger_error('NO_POST_SELECTED');
}
if ($post_id)
{
$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=$post_id") . "#p$post_id";
$return_forum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
$pm_id = 0;
}
else
{
$redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
$return_forum_url = '';
$post_id = 0;
$forum_id = 0;
}
// Has the report been cancelled?
if (isset($_POST['cancel']))
{
redirect($redirect_url);
}
if ($post_id)
{
// Grab all relevant data
$sql = 'SELECT t.*, p.*
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
WHERE p.post_id = $post_id
AND p.topic_id = t.topic_id";
$result = $db->sql_query($sql);
$report_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$report_data)
{
trigger_error('POST_NOT_EXIST');
}
$forum_id = (int) $report_data['forum_id'];
$topic_id = (int) $report_data['topic_id'];
$reported_post_text = $report_data['post_text'];
$reported_post_bitfield = $report_data['bbcode_bitfield'];
$reported_post_uid = $report_data['bbcode_uid'];
$reported_post_enable_bbcode = $report_data['enable_bbcode'];
$reported_post_enable_smilies = $report_data['enable_smilies'];
$reported_post_enable_magic_url = $report_data['enable_magic_url'];
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $forum_id;
$result = $db->sql_query($sql);
$forum_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$forum_data)
{
trigger_error('FORUM_NOT_EXIST');
}
// Check required permissions
$acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
/**
* This event allows you to do extra auth checks and verify if the user
* has the required permissions
*
* @event core.report_post_auth
* @var array forum_data All data available from the forums table on this post's forum
* @var array report_data All data available from the topics and the posts tables on this post (and its topic)
* @var array acl_check_ary An array with the ACL to be tested. The evaluation is made in the same order as the array is sorted
* The key is the ACL name and the value is the language key for the error message.
* @since 3.1.3-RC1
*/
$vars = array(
'forum_data',
'report_data',
'acl_check_ary',
);
extract($phpbb_dispatcher->trigger_event('core.report_post_auth', compact($vars)));
foreach ($acl_check_ary as $acl => $error)
{
if (!$auth->acl_get($acl, $forum_id))
{
trigger_error($error);
}
}
unset($acl_check_ary);
if ($report_data['post_reported'])
{
$message = $user->lang['ALREADY_REPORTED'];
$message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
trigger_error($message);
}
}
else
{
// Grab all relevant data
$sql = 'SELECT p.*, pt.*
FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . " pt
WHERE p.msg_id = $pm_id
AND p.msg_id = pt.msg_id
AND (p.author_id = " . $user->data['user_id'] . " OR pt.user_id = " . $user->data['user_id'] . ")";
$result = $db->sql_query($sql);
$report_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$report_data)
{
$user->add_lang('ucp');
trigger_error('NO_MESSAGE');
}
if ($report_data['message_reported'])
{
$message = $user->lang['ALREADY_REPORTED_PM'];
$message .= '<br /><br />' . sprintf($user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
trigger_error($message);
}
$reported_post_text = $report_data['message_text'];
$reported_post_bitfield = $report_data['bbcode_bitfield'];
$reported_post_uid = $report_data['bbcode_uid'];
$reported_post_enable_bbcode = $report_data['enable_bbcode'];
$reported_post_enable_smilies = $report_data['enable_smilies'];
$reported_post_enable_magic_url = $report_data['enable_magic_url'];
}
if ($config['enable_post_confirm'] && !$user->data['is_registered'])
{
$captcha = $phpbb_container->get('captcha.factory')->get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_REPORT);
}
$error = array();
$s_hidden_fields = '';
// Submit report?
if ($submit && $reason_id)
{
if (isset($captcha))
{
$visual_confirmation_response = $captcha->validate();
if ($visual_confirmation_response)
{
$error[] = $visual_confirmation_response;
}
}
$sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
{
$error[] = $user->lang('EMPTY_REPORT');
}
if (!sizeof($error))
{
if (isset($captcha))
{
$captcha->reset();
}
$sql_ary = array(
'reason_id' => (int) $reason_id,
'post_id' => $post_id,
'pm_id' => $pm_id,
'user_id' => (int) $user->data['user_id'],
'user_notify' => (int) $user_notify,
'report_closed' => 0,
'report_time' => (int) time(),
'report_text' => (string) $report_text,
'reported_post_text' => $reported_post_text,
'reported_post_uid' => $reported_post_uid,
'reported_post_bitfield' => $reported_post_bitfield,
'reported_post_enable_bbcode' => $reported_post_enable_bbcode,
'reported_post_enable_smilies' => $reported_post_enable_smilies,
'reported_post_enable_magic_url' => $reported_post_enable_magic_url,
);
$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$report_id = $db->sql_nextid();
/* @var $phpbb_notifications \phpbb\notification\manager */
$phpbb_notifications = $phpbb_container->get('notification_manager');
if ($post_id)
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_reported = 1
WHERE post_id = ' . $post_id;
$db->sql_query($sql);
if (!$report_data['topic_reported'])
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_reported = 1
WHERE topic_id = ' . $report_data['topic_id'] . '
OR topic_moved_id = ' . $report_data['topic_id'];
$db->sql_query($sql);
}
$lang_return = $user->lang['RETURN_TOPIC'];
$lang_success = $user->lang['POST_REPORTED_SUCCESS'];
$phpbb_notifications->add_notifications('notification.type.report_post', array_merge($report_data, $row, $forum_data, array(
'report_text' => $report_text,
)));
}
else
{
$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
SET message_reported = 1
WHERE msg_id = ' . $pm_id;
$db->sql_query($sql);
$sql_ary = array(
'msg_id' => $pm_id,
'user_id' => ANONYMOUS,
'author_id' => (int) $report_data['author_id'],
'pm_deleted' => 0,
'pm_new' => 0,
'pm_unread' => 0,
'pm_replied' => 0,
'pm_marked' => 0,
'pm_forwarded' => 0,
'folder_id' => PRIVMSGS_INBOX,
);
$sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$lang_return = $user->lang['RETURN_PM'];
$lang_success = $user->lang['PM_REPORTED_SUCCESS'];
$phpbb_notifications->add_notifications('notification.type.report_pm', array_merge($report_data, $row, array(
'report_text' => $report_text,
'from_user_id' => $report_data['author_id'],
'report_id' => $report_id,
)));
}
meta_refresh(3, $redirect_url);
$message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
if ($return_forum_url)
{
$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
}
trigger_error($message);
}
else if (isset($captcha) && $captcha->is_solved() !== false)
{
$s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields());
}
}
// Generate the reasons
display_reasons($reason_id);
$page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
if (isset($captcha) && $captcha->is_solved() === false)
{
$template->assign_vars(array(
'S_CONFIRM_CODE' => true,
'CAPTCHA_TEMPLATE' => $captcha->get_template(),
));
}
$template->assign_vars(array(
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
'S_REPORT_POST' => ($pm_id) ? false : true,
'REPORT_TEXT' => $report_text,
'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id),
'S_HIDDEN_FIELDS' => (sizeof($s_hidden_fields)) ? $s_hidden_fields : null,
'S_NOTIFY' => $user_notify,
'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false,
'S_IN_REPORT' => true,
));
generate_forum_nav($forum_data);
// Start output of page
page_header($page_title);
$template->set_filenames(array(
'body' => 'report_body.html')
/** @var \phpbb\controller\helper $controller_helper */
$controller_helper = $phpbb_container->get('controller.helper');
$response = new RedirectResponse(
$controller_helper->route($redirect_route_name, array(
'id' => ($pm_id === 0) ? $post_id : $pm_id,
)),
301
);
page_footer();
$response->send();

View File

@ -1832,7 +1832,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
'U_JABBER' => $user_cache[$poster_id]['jabber'],
'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p={$row['post_id']}&amp;f=$forum_id&amp;redirect=" . urlencode(str_replace('&amp;', '&', $viewtopic_url . '&amp;p=' . $row['post_id'] . '#p' . $row['post_id']))),
'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $row['post_id']) : '',
'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? $phpbb_container->get('controller.helper')->route('phpbb_report_post_controller', array('id' => $row['post_id'])) : '',
'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
'U_MCP_RESTORE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_data['topic_visibility'] != ITEM_DELETED) ? 'deleted_posts' : 'deleted_topics') . '&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',

View File

@ -0,0 +1,43 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
/**
* @group functional
*/
class phpbb_functional_controllers_compatibility_test extends phpbb_functional_test_case
{
public function test_report_compatibility()
{
$this->assert301('report.php?f=1&p=1', 'app.php/post/1/report');
$this->assert301('report.php?p=1', 'app.php/post/1/report');
$this->assert301('report.php?pm=1', 'app.php/pm/1/report');
}
protected function assert301($from, $to)
{
self::$client->followRedirects(false);
self::request('GET', $from, array(), false);
// Fix sid issues
$location = self::$client->getResponse()->getHeader('Location');
$location = preg_replace('#sid=[^&]+(&(amp;)?)?#', '', $location);
if (substr($location, -1) === '?')
{
$location = substr($location, 0, -1);
}
$this->assertEquals(301, self::$client->getResponse()->getStatus());
$this->assertStringEndsWith($to, $location);
}
}

View File

@ -18,12 +18,13 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca
{
public function test_guest_report_post()
{
$crawler = self::request('GET', 'report.php?f=2&p=1');
$crawler = self::request('GET', 'app.php/post/1/report', array(), false);
$this->assert_response_html(403);
$this->add_lang('mcp');
$this->assertContains($this->lang('USER_CANNOT_REPORT'), $crawler->filter('html')->text());
$this->set_reporting_guest(1);
$crawler = self::request('GET', 'report.php?f=2&p=1');
$crawler = self::request('GET', 'app.php/post/1/report');
$this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text());
$this->set_reporting_guest(-1);
}
@ -31,7 +32,7 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca
public function test_user_report_post()
{
$this->login();
$crawler = self::request('GET', 'report.php?f=2&p=1');
$crawler = self::request('GET', 'app.php/post/1/report');
$this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text());
$this->add_lang('mcp');