Browse Source

Don't do DB calls in the middle of a loop!!!

Signed-off-by: Suki <[email protected]>
Suki 10 years ago
parent
commit
a381d1aeaa
2 changed files with 8 additions and 2 deletions
  1. 6 0
      Sources/ModerationCenter.php
  2. 2 2
      Themes/default/ModerationCenter.template.php

+ 6 - 0
Sources/ModerationCenter.php

@@ -655,9 +655,11 @@ function ReportedPosts()
 	);
 	$context['reports'] = array();
 	$report_ids = array();
+	$report_boards_ids = array();
 	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
 	{
 		$report_ids[] = $row['id_report'];
+		$report_boards_ids[] = $row['id_board'];
 		$context['reports'][$row['id_report']] = array(
 			'id' => $row['id_report'],
 			'alternate' => $i % 2,
@@ -715,6 +717,10 @@ function ReportedPosts()
 		}
 		$smcFunc['db_free_result']($request);
 	}
+
+	// Get the boards where the current user can remove any message.
+	$context['report_remove_any_boards'] = $user_info['is_admin'] ? $report_boards_ids : array_intersect($report_boards_ids, boardsAllowedTo('remove_any'));
+	$context['report_manage_bans'] = allowedTo('manage_bans');
 }
 
 /**

+ 2 - 2
Themes/default/ModerationCenter.template.php

@@ -237,12 +237,12 @@ function template_reported_posts()
 					<li><a href="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';close=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a></li>';
 
 		// Delete message button.
-		if (!$report['closed'] && allowedTo('remove_any', $report['topic']['id_board']))
+		if (!$report['closed'] && (is_array($context['report_remove_any_boards']) && in_array($report['topic']['id_board'], $context['report_remove_any_boards'])))
 			echo '
 					<li><a href="', $scripturl, '?action=deletemsg;topic=', $report['topic']['id'] ,'.0;msg=', $report['topic']['id_msg'] ,';', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'' , $txt['mc_reportedp_delete_confirm'] , '\');">', $delete_button, '</a></li>';
 
 		// Ban this user button.
-		if (!$report['closed'] && allowedTo('manage_bans', $report['topic']['id_board']))
+		if (!$report['closed'] && !empty($context['report_manage_bans']))
 			echo '
 					<li><a href="', $scripturl, '?action=admin;area=ban;sa=add;u=', $report['author']['id'] ,';', $context['session_var'], '=', $context['session_id'], '">', $ban_button, '</a></li>';