Skip to content

Commit a089ff5

Browse files
committed
[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
1 parent 2c0b125 commit a089ff5

26 files changed

Lines changed: 1208 additions & 343 deletions

phpBB/config/default/container/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ imports:
1313
- { resource: services_notification.yml }
1414
- { resource: services_password.yml }
1515
- { resource: services_profilefield.yml }
16+
- { resource: services_report.yml }
1617
- { resource: services_text_formatter.yml }
1718
- { resource: services_twig.yml }
1819
- { resource: services_user.yml }
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
services:
2+
# ----- Report controller -----
3+
phpbb.report.controller:
4+
class: phpbb\report\controller\report
5+
arguments:
6+
- @config
7+
- @user
8+
- @template
9+
- @controller.helper
10+
- @request
11+
- @captcha.factory
12+
- @phpbb.report.handler_factory
13+
- @phpbb.report.report_reason_list_provider
14+
- %core.root_path%
15+
- %core.php_ext%
16+
17+
# ----- Report handler factory -----
18+
phpbb.report.handler_factory:
19+
class: phpbb\report\handler_factory
20+
arguments:
21+
- @service_container
22+
23+
# ----- Report UI provider -----
24+
phpbb.report.report_reason_list_provider:
25+
class: phpbb\report\report_reason_list_provider
26+
arguments:
27+
- @dbal.conn.driver
28+
- @template
29+
- @user
30+
31+
# ----- Report handlers -----
32+
# Scope MUST be prototype for all the handlers to work correctly.
33+
phpbb.report.handlers.report_handler_pm:
34+
class: phpbb\report\report_handler_pm
35+
scope: prototype
36+
arguments:
37+
- @dbal.conn.driver
38+
- @dispatcher
39+
- @config
40+
- @auth
41+
- @user
42+
- @notification_manager
43+
44+
phpbb.report.handlers.report_handler_post:
45+
class: phpbb\report\report_handler_post
46+
scope: prototype
47+
arguments:
48+
- @dbal.conn.driver
49+
- @dispatcher
50+
- @config
51+
- @auth
52+
- @user
53+
- @notification_manager
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
phpbb_report_pm_controller:
2+
path: /pm/{id}/report
3+
methods: [GET, POST]
4+
defaults:
5+
_controller: phpbb.report.controller:handle
6+
mode: "pm"
7+
requirements:
8+
id: \d+
9+
10+
phpbb_report_post_controller:
11+
path: /post/{id}/report
12+
methods: [GET, POST]
13+
defaults:
14+
_controller: phpbb.report.controller:handle
15+
mode: "post"
16+
requirements:
17+
id: \d+

phpBB/config/default/routing/routing.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
phpbb_help_routing:
1212
resource: "help.yml"
1313
prefix: /help
14+
15+
phpbb_report_routing:
16+
resource: "report.yml"

phpBB/includes/functions_display.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,33 +1097,14 @@ function display_custom_bbcodes()
10971097

10981098
/**
10991099
* Display reasons
1100+
*
1101+
* @deprecated 3.2.0-dev
11001102
*/
11011103
function display_reasons($reason_id = 0)
11021104
{
1103-
global $db, $user, $template;
1104-
1105-
$sql = 'SELECT *
1106-
FROM ' . REPORTS_REASONS_TABLE . '
1107-
ORDER BY reason_order ASC';
1108-
$result = $db->sql_query($sql);
1105+
global $phpbb_container;
11091106

1110-
while ($row = $db->sql_fetchrow($result))
1111-
{
1112-
// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
1113-
if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
1114-
{
1115-
$row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
1116-
$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
1117-
}
1118-
1119-
$template->assign_block_vars('reason', array(
1120-
'ID' => $row['reason_id'],
1121-
'TITLE' => $row['reason_title'],
1122-
'DESCRIPTION' => $row['reason_description'],
1123-
'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false)
1124-
);
1125-
}
1126-
$db->sql_freeresult($result);
1107+
$phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id);
11271108
}
11281109

11291110
/**

phpBB/includes/mcp/mcp_queue.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,11 +1402,6 @@ static public function disapprove_posts($post_id_list, $id, $mode)
14021402
}
14031403
else
14041404
{
1405-
if (!function_exists('display_reasons'))
1406-
{
1407-
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1408-
}
1409-
14101405
$show_notify = false;
14111406

14121407
foreach ($post_info as $post_data)
@@ -1426,7 +1421,7 @@ static public function disapprove_posts($post_id_list, $id, $mode)
14261421
$confirm_template = 'mcp_approve.html';
14271422
if ($is_disapproving)
14281423
{
1429-
display_reasons($reason_id);
1424+
$phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id);
14301425
}
14311426
else
14321427
{

phpBB/includes/ucp/ucp_pm_viewmessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
232232

233233
'U_DELETE' => ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '',
234234
'U_EMAIL' => $user_info['email'],
235-
'U_REPORT' => ($config['allow_pm_report']) ? append_sid("{$phpbb_root_path}report.$phpEx", "pm=" . $message_row['msg_id']) : '',
235+
'U_REPORT' => ($config['allow_pm_report']) ? $phpbb_container->get('controller.helper')->route('phpbb_report_pm_controller', array('id' => $message_row['msg_id'])) : '',
236236
'U_QUOTE' => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=quote&f=$folder_id&p=" . $message_row['msg_id'] : '',
237237
'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'] : '',
238238
'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'] : '',

phpBB/phpbb/controller/helper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,20 @@ public function message($message, array $parameters = array(), $title = 'INFORMA
223223
return $this->render('message_body.html', $this->user->lang($title), $code);
224224
}
225225

226+
/**
227+
* Assigns automatic refresh time meta tag in template
228+
*
229+
* @param int $time time in seconds, when redirection should occur
230+
* @param string $url the URL where the user should be redirected
231+
* @return null
232+
*/
233+
public function assign_meta_refresh_var($time, $url)
234+
{
235+
$this->template->assign_vars(array(
236+
'META' => '<meta http-equiv="refresh" content="' . $time . '; url=' . $url . '" />',
237+
));
238+
}
239+
226240
/**
227241
* Return the current url
228242
*

0 commit comments

Comments
 (0)