فهرست منبع

! And now it's possible to get notified if someone replies to a moderation report you previously replied to.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 11 سال پیش
والد
کامیت
b0734cc5a2

+ 19 - 2
Sources/ModerationCenter.php

@@ -889,6 +889,24 @@ function ModReport()
 				),
 				array('id_comment')
 			);
+			$last_comment = $smcFunc['db_insert_id']('{db_prefix}log_comments', 'id_comment');
+
+			// And get ready to notify people.
+			$smcFunc['db_insert']('insert',
+				'{db_prefix}background_tasks',
+				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
+				array('$sourcedir/tasks/MsgReportReply-Notify.php', 'MsgReportReply_Notify_Background', serialize(array(
+					'report_id' => $_REQUEST['report'],
+					'comment_id' => $last_comment,
+					'msg_id' => $row['id_msg'],
+					'topic_id' => $row['id_topic'],
+					'board_id' => $row['id_board'],
+					'sender_id' => $user_info['id'],
+					'sender_name' => $user_info['name'],
+					'time' => time(),
+				)), 0),
+				array('id_task')
+			);
 
 			// Redirect to prevent double submittion.
 			redirectexit($scripturl . '?action=moderate;area=reports;report=' . $_REQUEST['report']);
@@ -955,10 +973,9 @@ function ModReport()
 		FROM {db_prefix}log_comments AS lc
 			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
 		WHERE lc.id_notice = {int:id_report}
-			AND lc.comment_type = {string:reportc}',
+			AND lc.comment_type = {literal:reportc}',
 		array(
 			'id_report' => $context['report']['id'],
-			'reportc' => 'reportc',
 		)
 	);
 	while ($row = $smcFunc['db_fetch_assoc']($request))

+ 213 - 0
Sources/tasks/MsgReportReply-Notify.php

@@ -0,0 +1,213 @@
+<?php
+
+/**
+ * This task handles notifying users when they've commented to a moderation report and
+ * someone else replies to them.
+ *
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines http://www.simplemachines.org
+ * @copyright 2013 Simple Machines and individual contributors
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+class MsgReportReply_Notify_Background extends SMF_BackgroundTask
+{
+	public function execute()
+	{
+		global $smcFunc, $sourcedir, $modSettings, $language, $scripturl;
+
+		// Let's see. Let us, first of all, establish the list of possible people.
+		$possible_members = array();
+		$request = $smcFunc['db_query']('', '
+			SELECT id_member
+			FROM {db_prefix}log_comments
+			WHERE id_notice = {int:report}
+				AND comment_type = {literal:reportc}
+				AND id_comment < {int:last_comment}',
+			array(
+				'report' => $this->_details['report_id'],
+				'last_comment' => $this->_details['comment_id'],
+			)
+		);
+		while ($row = $smcFunc['db_fetch_row']($request))
+			$possible_members[] = $row[0];
+		$smcFunc['db_free_result']($request);
+
+		// Presumably, there are some people?
+		if (!empty($possible_members))
+		{
+			$possible_members = array_flip(array_flip($possible_members));
+			$possible_members = array_diff($possible_members, array($this->_details['sender_id']));
+		}
+		if (empty($possible_members))
+			return true;
+
+		// We need to know who can moderate this board - and therefore who can see this report.
+		// First up, people who have moderate_board in the board this topic was in.
+		require_once($sourcedir . '/Subs-Members.php');
+		$members = membersAllowedTo('moderate_board', $this->_details['board_id']);
+
+		// Second, anyone assigned to be a moderator of this board directly.
+		$request = $smcFunc['db_query']('', '
+			SELECT id_member
+			FROM {db_prefix}moderators
+			WHERE id_board = {int:current_board}',
+			array(
+				'current_board' => $this->_details['board_id'],
+			)
+		);
+		while ($row = $smcFunc['db_fetch_assoc']($request))
+			$members[] = $row['id_member'];
+		$smcFunc['db_free_result']($request);
+
+		// Thirdly, anyone assigned to be a moderator of this group as a group->board moderator.
+		$request = $smcFunc['db_query']('', '
+			SELECT mem.id_member
+			FROM {db_prefix}members AS mem, {db_prefix}moderator_groups AS bm
+			WHERE bm.id_board = {int:current_board}
+				AND(
+					mem.id_group = bm.id_group
+					OR FIND_IN_SET(bm.id_group, mem.additional_groups) != 0
+				)',
+			array(
+				'current_board' => $this->_details['board_id'],
+			)
+		);
+
+		while ($row = $smcFunc['db_fetch_assoc']($request))
+			$members[] = $row['id_member'];
+		$smcFunc['db_free_result']($request);
+
+		// So now we have two lists: the people who replied to a report in the past,
+		// and all the possible people who could see said report.
+		$members = array_intersect($possible_members, $members);
+
+		// Having successfully figured this out, now let's get the preferences of everyone.
+		require_once($sourcedir . '/Subs-Notify.php');
+		$prefs = getNotifyPrefs($members, 'msg_report_reply', true);
+
+		// So now we find out who wants what.
+		$alert_bits = array(
+			'alert' => 0x01,
+			'email' => 0x02,
+		);
+		$notifies = array();
+		print_r($prefs);
+
+		foreach ($prefs as $member => $pref_option)
+		{
+			foreach ($alert_bits as $type => $bitvalue)
+			{
+				if ($pref_option['msg_report_reply'] & $bitvalue)
+					$notifies[$type][] = $member;
+			}
+		}
+
+		print_r($notifies);
+
+		// Firstly, anyone who wants alerts.
+		if (!empty($notifies['alert']))
+		{
+			// Alerts are relatively easy.
+			$insert_rows = array();
+			foreach ($notifies['alert'] as $member)
+			{
+				$insert_rows[] = array(
+					'alert_time' => $this->_details['time'],
+					'id_member' => $member,
+					'id_member_started' => $this->_details['sender_id'],
+					'member_name' => $this->_details['sender_name'],
+					'content_type' => 'msg',
+					'content_id' => $this->_details['msg_id'],
+					'content_action' => 'report_reply',
+					'is_read' => 0,
+					'extra' => serialize(
+						array(
+							'report_link' => $scripturl . '?action=moderate;area=reports;report=' . $this->_details['report_id'],
+						)
+					),
+				);
+			}
+
+			$smcFunc['db_insert']('insert',
+				'{db_prefix}user_alerts',
+				array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int',
+					'member_name' => 'string', 'content_type' => 'string', 'content_id' => 'int',
+					'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
+				$insert_rows,
+				array('id_alert')
+			);
+
+			// And update the count of alerts for those people.
+			updateMemberData($notifies['alert'], array('alerts' => '+'));
+		}
+
+		// Secondly, anyone who wants emails.
+		if (!empty($notifies['email']))
+		{
+			// Emails are a bit complicated. We have to do language stuff.
+			require_once($sourcedir . '/Subs-Post.php');
+			require_once($sourcedir . '/ScheduledTasks.php');
+			loadEssentialThemeData();
+
+			// First, get everyone's language and details.
+			$emails = array();
+			$request = $smcFunc['db_query']('', '
+				SELECT id_member, lngfile, email_address
+				FROM {db_prefix}members
+				WHERE id_member IN ({array_int:members})',
+				array(
+					'members' => $notifies['email'],
+				)
+			);
+			while ($row = $smcFunc['db_fetch_assoc']($request))
+			{
+				if (empty($row['lngfile']))
+					$row['lngfile'] = $language;
+				$emails[$row['lngfile']][$row['id_member']] = $row['email_address'];
+			}
+			$smcFunc['db_free_result']($request);
+
+			// Second, get some details that might be nice for the report email.
+			// We don't bother cluttering up the tasks data for this, when it's really no bother to fetch it.
+			$request = $smcFunc['db_query']('', '
+				SELECT lr.subject, lr.membername, lr.body
+				FROM {db_prefix}log_reported AS lr
+				WHERE id_report = {int:report}',
+				array(
+					'report' => $this->_details['report_id'],
+				)
+			);
+			list ($subject, $poster_name, $comment) = $smcFunc['db_fetch_row']($request);
+			$smcFunc['db_free_result']($request);
+
+			// Third, iterate through each language, load the relevant templates and set up sending.
+			foreach ($emails as $this_lang => $recipients)
+			{
+				echo 'Emailing (' . $this_lang . ') to ' . print_r($recipients, true);
+				$replacements = array(
+					'TOPICSUBJECT' => $subject,
+					'POSTERNAME' => $poster_name,
+					'COMMENTERNAME' => $this->_details['sender_name'],
+					'TOPICLINK' => $scripturl . '?topic=' . $this->_details['topic_id'] . '.msg' . $this->_details['msg_id'] . '#msg' . $this->_details['msg_id'],
+					'REPORTLINK' => $scripturl . '?action=moderate;area=reports;report=' . $this->_details['report_id'],
+				);
+
+				$emaildata = loadEmailTemplate('reply_to_moderator', $replacements, empty($modSettings['userLanguage']) ? $language : $this_lang);
+
+				// And do the actual sending...
+				foreach ($recipients as $id_member => $email_address)
+					sendmail($email_address, $emaildata['subject'], $emaildata['body'], null, null, false, 3);
+			}
+		}
+
+		// And now we're all done.
+		return true;
+	}
+}
+
+?>

+ 1 - 0
Themes/default/languages/Alerts.english.php

@@ -12,6 +12,7 @@ $txt['alerts_no_unread'] = 'No unread alerts.';
 
 $txt['alert_msg_like'] = '{member_link} liked your post {msg_msg}';
 $txt['alert_msg_report'] = '{member_link} <a href="{report_link}">reported a post</a> - {msg_msg}';
+$txt['alert_msg_report_reply'] = '{member_link} replied to <a href="{report_link}">the report</a> about {msg_msg}';
 $txt['alert_member_register_standard'] = '{member_link} just signed up';
 $txt['alert_member_register_approval'] = '{member_link} just signed up (account requires approval)';
 $txt['alert_member_register_activation'] = '{member_link} just signed up (account requires activation)';

+ 20 - 1
Themes/default/languages/EmailTemplates.english.php

@@ -461,7 +461,7 @@ $txt['send_email_body'] = '{EMAILBODY}';
 /**
 	@additional_params: report_to_moderator
 		TOPICSUBJECT: The subject of the reported post.
-		POSTERNAME: The report post's author's name.
+		POSTERNAME: The reported post's author's name.
 		REPORTERNAME: The name of the person reporting the post.
 		TOPICLINK: The url of the post that is being reported.
 		REPORTLINK: The url of the moderation center report.
@@ -479,6 +479,25 @@ The reporter has made the following comment:
 
 {REGARDS}';
 
+/**
+	@additional_params: report_to_moderator
+		TOPICSUBJECT: The subject of the reported post.
+		POSTERNAME: The reported post's author's name.
+		COMMENTERNAME: The name of the person who replied to the report.
+		TOPICLINK: The url of the post that is being reported.
+		REPORTLINK: The url of the moderation center report.
+	@description: When a moderator replies to a moderation report, this can be sent to the other moderators who previously replied.
+*/
+$txt['reply_to_moderator_subject'] = 'Follow-up to reported post: {TOPICSUBJECT} by {POSTERNAME}';
+$txt['reply_to_moderator_body'] = 'Previously, "{TOPICSUBJECT}" was reported to moderators.
+
+Since then, {COMMENTERNAME} has added a comment to the report. More information can be found in the forum.
+
+The topic: {TOPICLINK}
+Moderation center: {REPORTLINK}
+
+{REGARDS}';
+
 /**
 	@additional_params: change_password
 		USERNAME: The user name for the member receiving the email.

+ 2 - 1
other/install_2-1_mysql.sql

@@ -2144,7 +2144,8 @@ INSERT INTO {$db_prefix}user_alerts_prefs
 VALUES (0, 'member_group_request', 1),
 	(0, 'member_register', 1),
 	(0, 'msg_like', 1),
-	(0, 'msg_report', 1);
+	(0, 'msg_report', 1),
+	(0, 'msg_report_reply', 1);
 # --------------------------------------------------------
 
 #

+ 1 - 0
other/install_2-1_postgresql.sql

@@ -2697,6 +2697,7 @@ INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) V
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_register', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_like', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report', 1);
+INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report_reply', 1);
 # --------------------------------------------------------
 
 #

+ 1 - 0
other/install_2-1_sqlite.sql

@@ -2305,6 +2305,7 @@ INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) V
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_register', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_like', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report', 1);
+INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report_reply', 1);
 # --------------------------------------------------------
 
 #

+ 1 - 0
other/install_2-1_sqlite3.sql

@@ -2305,6 +2305,7 @@ INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) V
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_register', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_like', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report', 1);
+INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report_reply', 1);
 # --------------------------------------------------------
 
 #

+ 2 - 1
other/upgrade_2-1_mysql.sql

@@ -314,7 +314,8 @@ INSERT INTO {$db_prefix}user_alerts_prefs
 VALUES (0, 'member_group_request', 1),
 	(0, 'member_register', 1),
 	(0, 'msg_like', 1),
-	(0, 'msg_report', 1);
+	(0, 'msg_report', 1),
+	(0, 'msg_report_reply', 1);
 ---#
 
 /******************************************************************************/

+ 1 - 0
other/upgrade_2-1_postgresql.sql

@@ -389,6 +389,7 @@ INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) V
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_register', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_like', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report', 1);
+INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report_reply', 1);
 ---#
 
 /******************************************************************************/

+ 1 - 0
other/upgrade_2-1_sqlite.sql

@@ -368,6 +368,7 @@ INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) V
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'member_register', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_like', 1);
 INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report', 1);
+INSERT INTO {$db_prefix}user_alerts_prefs (id_member, alert_pref, alert_value) VALUES (0, 'msg_report_reply', 1);
 ---#
 
 /******************************************************************************/