Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

WIP: [feature/moderator-needed] Display # of Items Requiring Moderator Attention #809

Closed
wants to merge 10 commits into from

5 participants

David King Don't Add Me To Your Organization a.k.a The Travis Bot Michael C. Jakub Senko Richard McGirr
David King
Collaborator

Old PR: #780

Display number of reported posts/PMs and unapproved topics/posts with MCP link for moderators with m_approve and m_report permissions.

Because Unknown Bliss asked me to sort of finish this up, I have begun a new pull request from my own branch so that he does not have to cherry pick my changes into the old PR. I tried to address all of the comments made on the old PR, but if I missed anything, or if you see something else that needs fixing, let me know.

EDIT: bantu suggested:

Since this is for develop, maybe the implementation should be more object oriented and "plugin-aware". Maybe it could be changed so you can just drop in files/classes to add new items requiring moderator attention. Maybe also with the ability to display some information on the index page like http://www.phpbb.com/customise/db/mod/mcp_info_on_index The exising code could be decomposed into two plugins: a) reported posts b) posts in moderation queue

I will look into this later when I have some time. Until then, this needs some testing.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 7d20c6e into f3d33bf).

Michael C.

Do you need this %d as we know it will be one? Same above.

Michael C.

Thanks

Jakub Senko
Senky commented May 22, 2012

Haven't you forget about subsilver2?

David King
Collaborator

Not forgot, just haven't gotten to it yet. This is a WIP. ;)

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 48ae5e8 into f3d33bf).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 3da0853 into f3d33bf).

Richard McGirr

Seeing as nearly all of the code is being used from a mod I wrote a while ago, wouldn't a "Gee, thanks RMcGirr83" comment in the code be apropos?

/me slaps unknownbliss

David King
Collaborator

I didnt even check this code against your MOD. I figured @unknownbliss had done it himself. I'll be sure to add a credit line for you before this gets merged, unless someone else does it first.

Michael C.

@imkingdavid It was mentioned in the RFC. Also see the first commit message. ;)

Michael C.

Perhaps this should be merged. Later on a template event can be added allowing extensions to add something here, but for now template events aren't merged so that isn't possible.

David King
Collaborator

This is being closed because Reported posts and Posts awaiting approval are two moderator-level notifications introduced by #992 so this would be redundant.

David King imkingdavid closed this October 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
7  phpBB/includes/functions.php
@@ -4802,6 +4802,13 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
4802 4802
 		'A_COOKIE_SETTINGS'		=> addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')),
4803 4803
 	));
4804 4804
 
  4805
+	// Determine the number of items requiring moderator attention
  4806
+	if (!function_exists('phpbb_mcp_quick_info'))
  4807
+	{
  4808
+		include("{$phpbb_root_path}includes/functions_display.$phpEx");
  4809
+	}
  4810
+	phpbb_mcp_quick_info();
  4811
+
4805 4812
 	$vars = array('page_title', 'display_online_list', 'item_id', 'item');
4806 4813
 	extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars)));
4807 4814
 
113  phpBB/includes/functions_display.php
@@ -1322,3 +1322,116 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $
1322 1322
 	$avatar_img .= $avatar;
1323 1323
 	return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
1324 1324
 }
  1325
+
  1326
+/**
  1327
+* Fetches the number of items which need a moderators attention
  1328
+*
  1329
+* @return null
  1330
+*/
  1331
+function phpbb_mcp_quick_info()
  1332
+{
  1333
+	global $auth, $cache, $db, $template, $user, $phpEx, $phpbb_root_path;
  1334
+
  1335
+	$m_approve = $auth->acl_getf_global('m_approve');
  1336
+	$m_report = $auth->acl_getf_global('m_report');
  1337
+
  1338
+	// We have one or both of m_report and m_approve
  1339
+	if ($m_approve || $m_report)
  1340
+	{
  1341
+		$reported_posts_count = $unapproved_posts_count = $unapproved_topics_count = 0;
  1342
+
  1343
+		$sql_where = '';
  1344
+
  1345
+		// Check for m_report
  1346
+		if ($m_report)
  1347
+		{
  1348
+			// We add a ternary conditional to allow for having both permissions
  1349
+			$sql_where .= '(' . $db->sql_in_set('forum_id', get_forum_list('m_report')) . '
  1350
+				AND post_reported = 1)' . ($m_approve ? ' OR ' : '');
  1351
+		}
  1352
+
  1353
+		// Check for m_approve
  1354
+		if ($m_approve)
  1355
+		{
  1356
+			$sql_where .= '(' . $db->sql_in_set('forum_id', get_forum_list('m_approve')) . '
  1357
+				AND post_approved = 0)';
  1358
+		
  1359
+			$sql = 'SELECT topic_first_post_id
  1360
+						FROM ' . TOPICS_TABLE . '
  1361
+					WHERE ' . $db->sql_in_set('forum_id', get_forum_list('m_approve')) . '
  1362
+						AND topic_approved = 0';
  1363
+			$result = $db->sql_query($sql);
  1364
+
  1365
+			$unapproved_topics_array = array();
  1366
+			while ($row = $db->sql_fetchrow($result))
  1367
+			{
  1368
+				$unapproved_topics_array[] = $row['topic_first_post_id'];
  1369
+			}
  1370
+			$db->sql_freeresult($result);
  1371
+
  1372
+			$unapproved_topics_count = count($unapproved_topics_array);
  1373
+
  1374
+			$sql_where .= $unapproved_topics_count ? ' AND ' . $db->sql_in_set('post_id', $unapproved_topics_array, true) : '';
  1375
+		}
  1376
+
  1377
+		// Reported Posts and Approved Posts
  1378
+		$sql = 'SELECT post_reported, post_approved
  1379
+			FROM ' . POSTS_TABLE . "
  1380
+			WHERE $sql_where";
  1381
+		$result = $db->sql_query($sql);
  1382
+
  1383
+		// Count number of unapproved and reported posts
  1384
+		while ($row = $db->sql_fetchrow($result))
  1385
+		{
  1386
+			// Count the reported posts
  1387
+			if ($row['post_reported'])
  1388
+			{
  1389
+				$reported_posts_count++;
  1390
+			}
  1391
+			// Count the unapproved posts
  1392
+			if (!$row['post_approved'])
  1393
+			{
  1394
+				$unapproved_posts_count++;
  1395
+			}
  1396
+		}
  1397
+		$db->sql_freeresult($result);
  1398
+	
  1399
+		$template->assign_vars(array(
  1400
+			'TOTAL_MODERATOR_REPORTS'		=> $user->lang('MODERATOR_REPORTED_POSTS', $reported_posts_count),
  1401
+			'TOTAL_MODERATOR_POSTS'			=> $user->lang('MODERATOR_APPROVE_POSTS', $unapproved_posts_count),
  1402
+			'TOTAL_MODERATOR_TOPICS'    	=> $user->lang('MODERATOR_APPROVE_TOPICS', $unapproved_topics_count),
  1403
+
  1404
+			'U_MODERATOR_REPORTS'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", array('i' => 'reports', 'mode' => 'reports'), true, $user->session_id),
  1405
+			'U_MODERATOR_APPROVE_POSTS'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", array('i' => 'queue', 'mode' => 'unapproved_posts'), true, $user->session_id),
  1406
+			'U_MODERATOR_APPROVE_TOPICS'    => append_sid("{$phpbb_root_path}mcp.$phpEx", array('i' => 'queue', 'mode' => 'unapproved_topics'), true, $user->session_id),
  1407
+		));
  1408
+	}
  1409
+
  1410
+    // Don't forget reported PMs
  1411
+	if ($auth->acl_getf_global('m_'))
  1412
+	{
  1413
+		$reported_pms = 0;
  1414
+
  1415
+		if (($reported_pms = $cache->get('_reported_pms')) === false)
  1416
+		{
  1417
+			$sql = 'SELECT COUNT(msg_id) AS pms_count
  1418
+				FROM ' . PRIVMSGS_TABLE . '
  1419
+				WHERE message_reported = 1';
  1420
+			$result = $db->sql_query($sql);
  1421
+			$reported_pms = (int) $db->sql_fetchfield('pms_count');
  1422
+			$db->sql_freeresult($result);
  1423
+
  1424
+			// Cache for a few minutes to optimize. Might add to topics/posts later
  1425
+			$cache->put('_reported_pms', $reported_pms, 300);
  1426
+		}
  1427
+
  1428
+		// Dump to the template
  1429
+		if ($reported_pms)
  1430
+		{
  1431
+			$template->assign_vars(array(
  1432
+				'TOTAL_MODERATOR_PMS'			=> $user->lang('MODERATOR_REPORTED_PMS', $reported_pms),
  1433
+				'U_MODERATOR_PMS'				=> append_sid("{$phpbb_root_path}mcp.$phpEx", array('i' => 'pm_reports', 'mode' => 'pm_reports'), true, $user->session_id),
  1434
+			));
  1435
+		}
  1436
+	}
  1437
+}
1  phpBB/includes/mcp/mcp_pm_reports.php
@@ -61,6 +61,7 @@ function main($id, $mode)
61 61
 				}
62 62
 
63 63
 				close_report($report_id_list, $mode, $action, true);
  64
+				$cache->purge('_reported_pms');
64 65
 
65 66
 			break;
66 67
 		}
16  phpBB/language/en/common.php
@@ -358,6 +358,22 @@
358 358
 	'MINUTES'				=> 'Minutes',
359 359
 	'MODERATE'				=> 'Moderate',
360 360
 	'MODERATOR'				=> 'Moderator',
  361
+	'MODERATOR_REPORTED_POSTS'	=> array(
  362
+		1 => '<strong>%d</strong> reported post',
  363
+		2 => '<strong>%d</strong> reported posts',
  364
+	),
  365
+	'MODERATOR_APPROVE_POSTS'	=> array(
  366
+		1 => '<strong>%d</strong> post awaiting approval',
  367
+		2 => '<strong>%d</strong> posts awaiting approval',
  368
+	),
  369
+	'MODERATOR_APPROVE_TOPICS'	=> array(
  370
+		1 => '<strong>%d</strong> topic awaiting approval',
  371
+		2 => '<strong>%d</strong> topics awaiting approval',
  372
+	),
  373
+	'MODERATOR_REPORTED_PMS'		=> array(
  374
+		1 => '<strong>%d</strong> reported PM',
  375
+		2 => '<strong>%d</strong> reported PMs',
  376
+	),
361 377
 	'MODERATORS'			=> 'Moderators',
362 378
 	'MONTH'					=> 'Month',
363 379
 	'MOVE'					=> 'Move',
2  phpBB/styles/prosilver/template/index_body.html
... ...
@@ -1,7 +1,7 @@
1 1
 <!-- INCLUDE overall_header.html -->
2 2
 
3 3
 <p class="{S_CONTENT_FLOW_END}<!-- IF S_USER_LOGGED_IN --> rightside<!-- ENDIF -->"><!-- IF S_USER_LOGGED_IN -->{LAST_VISIT_DATE}<!-- ELSE -->{CURRENT_TIME}<!-- ENDIF --></p>
4  
-<!-- IF U_MCP --><p>{CURRENT_TIME} <br />[&nbsp;<a href="{U_MCP}">{L_MCP}</a>&nbsp;]</p><!-- ELSEIF S_USER_LOGGED_IN --><p>{CURRENT_TIME}</p><!-- ENDIF -->
  4
+<!-- IF U_MCP --><p>{CURRENT_TIME} <br />[&nbsp;<a href="{U_MCP}">{L_MCP}</a><!-- IF TOTAL_MODERATOR_REPORTS --> | <a href="{U_MODERATOR_REPORTS}">{TOTAL_MODERATOR_REPORTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_POSTS --> | <a href="{U_MODERATOR_APPROVE_POSTS}">{TOTAL_MODERATOR_POSTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_TOPICS --> | <a href="{U_MODERATOR_APPROVE_TOPICS}">{TOTAL_MODERATOR_TOPICS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_PMS --> | <a href="{U_MODERATOR_PMS}">{TOTAL_MODERATOR_PMS}</a><!-- ENDIF -->&nbsp;]</p><!-- ELSEIF S_USER_LOGGED_IN --><p>{CURRENT_TIME}</p><!-- ENDIF -->
5 5
 
6 6
 <!-- IF S_DISPLAY_SEARCH or (S_USER_LOGGED_IN and not S_IS_BOT) -->
7 7
 <ul class="linklist">
2  phpBB/styles/prosilver/template/viewforum_body.html
... ...
@@ -1,5 +1,5 @@
1 1
 <!-- INCLUDE overall_header.html -->
2  
-<!-- IF U_MCP --><p>[&nbsp;<a href="{U_MCP}">{L_MCP}</a>&nbsp;]</p><!-- ENDIF -->
  2
+<!-- IF U_MCP --><p>[&nbsp;<a href="{U_MCP}">{L_MCP}</a><!-- IF TOTAL_MODERATOR_REPORTS --> | <a href="{U_MODERATOR_REPORTS}">{TOTAL_MODERATOR_REPORTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_POSTS --> | <a href="{U_MODERATOR_APPROVE_POSTS}">{TOTAL_MODERATOR_POSTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_TOPICS --> | <a href="{U_MODERATOR_APPROVE_TOPICS}">{TOTAL_MODERATOR_TOPICS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_PMS --> | <a href="{U_MODERATOR_PMS}">{TOTAL_MODERATOR_PMS}</a><!-- ENDIF -->&nbsp;]</p><!-- ENDIF -->
3 3
 <h2><a href="{U_VIEW_FORUM}">{FORUM_NAME}</a></h2>
4 4
 
5 5
 <!-- IF FORUM_DESC or MODERATORS or U_MCP -->
2  phpBB/styles/prosilver/template/viewtopic_body.html
... ...
@@ -1,5 +1,5 @@
1 1
 <!-- INCLUDE overall_header.html -->
2  
-<!-- IF U_MCP --><p>[&nbsp;<a href="{U_MCP}">{L_MCP}</a>&nbsp;]</p><!-- ENDIF -->
  2
+<!-- IF U_MCP --><p>[&nbsp;<a href="{U_MCP}">{L_MCP}</a><!-- IF TOTAL_MODERATOR_REPORTS --> | <a href="{U_MODERATOR_REPORTS}">{TOTAL_MODERATOR_REPORTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_POSTS --> | <a href="{U_MODERATOR_APPROVE_POSTS}">{TOTAL_MODERATOR_POSTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_TOPICS --> | <a href="{U_MODERATOR_APPROVE_TOPICS}">{TOTAL_MODERATOR_TOPICS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_PMS --> | <a href="{U_MODERATOR_PMS}">{TOTAL_MODERATOR_PMS}</a><!-- ENDIF -->&nbsp;]</p><!-- ENDIF -->
3 3
 <h2><a href="{U_VIEW_TOPIC}">{TOPIC_TITLE}</a></h2>
4 4
 <!-- NOTE: remove the style="display: none" when you want to have the forum description on the topic body -->
5 5
 <!-- IF FORUM_DESC --><div style="display: none !important;">{FORUM_DESC}<br /></div><!-- ENDIF -->
2  phpBB/styles/subsilver2/template/index_body.html
@@ -2,7 +2,7 @@
2 2
 
3 3
 <!-- IF U_MCP -->
4 4
 	<div id="pageheader">
5  
-		<p class="linkmcp">[ <a href="{U_MCP}">{L_MCP}</a> ]</p>
  5
+		<p class="linkmcp">[ <a href="{U_MCP}">{L_MCP}</a><!-- IF TOTAL_MODERATOR_REPORTS --> | <a href="{U_MODERATOR_REPORTS}">{TOTAL_MODERATOR_REPORTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_POSTS --> | <a href="{U_MODERATOR_APPROVE_POSTS}">{TOTAL_MODERATOR_POSTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_TOPICS --> | <a href="{U_MODERATOR_APPROVE_TOPICS}">{TOTAL_MODERATOR_TOPICS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_PMS --> | <a href="{U_MODERATOR_PMS}">{TOTAL_MODERATOR_PMS}</a><!-- ENDIF --> ]</p>
6 6
 	</div>
7 7
 
8 8
 	<br clear="all" /><br />
2  phpBB/styles/subsilver2/template/viewforum_body.html
@@ -95,7 +95,7 @@
95 95
 			<p class="moderators"><!-- IF S_SINGLE_MODERATOR -->{L_MODERATOR}<!-- ELSE -->{L_MODERATORS}<!-- ENDIF -->: {MODERATORS}</p>
96 96
 		<!-- ENDIF -->
97 97
 		<!-- IF U_MCP -->
98  
-			<p class="linkmcp">[ <a href="{U_MCP}">{L_MCP}</a> ]</p>
  98
+			<p class="linkmcp">[ <a href="{U_MCP}">{L_MCP}</a><!-- IF TOTAL_MODERATOR_REPORTS --> | <a href="{U_MODERATOR_REPORTS}">{TOTAL_MODERATOR_REPORTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_POSTS --> | <a href="{U_MODERATOR_APPROVE_POSTS}">{TOTAL_MODERATOR_POSTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_TOPICS --> | <a href="{U_MODERATOR_APPROVE_TOPICS}">{TOTAL_MODERATOR_TOPICS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_PMS --> | <a href="{U_MODERATOR_PMS}">{TOTAL_MODERATOR_PMS}</a><!-- ENDIF --> ]</p>
99 99
 		<!-- ENDIF -->
100 100
 	</div>
101 101
 
2  phpBB/styles/subsilver2/template/viewtopic_body.html
@@ -21,7 +21,7 @@
21 21
 	<p class="moderators"><!-- IF S_SINGLE_MODERATOR -->{L_MODERATOR}<!-- ELSE -->{L_MODERATORS}<!-- ENDIF -->: {MODERATORS}</p>
22 22
 <!-- ENDIF -->
23 23
 <!-- IF U_MCP -->
24  
-	<p class="linkmcp">[ <a href="{U_MCP}">{L_MCP}</a> ]</p>
  24
+	<p class="linkmcp">[ <a href="{U_MCP}">{L_MCP}</a><!-- IF TOTAL_MODERATOR_REPORTS --> | <a href="{U_MODERATOR_REPORTS}">{TOTAL_MODERATOR_REPORTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_POSTS --> | <a href="{U_MODERATOR_APPROVE_POSTS}">{TOTAL_MODERATOR_POSTS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_TOPICS --> | <a href="{U_MODERATOR_APPROVE_TOPICS}">{TOTAL_MODERATOR_TOPICS}</a><!-- ENDIF --><!-- IF TOTAL_MODERATOR_PMS --> | <a href="{U_MODERATOR_PMS}">{TOTAL_MODERATOR_PMS}</a><!-- ENDIF --> ]</p>
25 25
 <!-- ENDIF -->
26 26
 </div>
27 27
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.