Skip to content

Commit

Permalink
Actually notify users of reported profiles
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Eshom <[email protected]>
  • Loading branch information
Oldiesmann committed Feb 26, 2014
1 parent 7b75ad3 commit 5de4360
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/Profile-View.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ function fetch_alerts($memID, $all = false)
$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
if ($alert['content_type'] == 'msg')
$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
if ($alert['content_type'] == 'profile')
$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';

if (!empty($memberContext[$alert['sender_id']]))
$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
Expand Down
2 changes: 2 additions & 0 deletions Sources/ReportToMod.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,10 @@ function reportUser($id_member, $reason)
array('$sourcedir/tasks/UserReport-Notify.php', 'UserReport_Notify_Background', serialize(array(
'report_id' => $id_report,
'user_id' => $user['id_member'],
'user_name' => $user_name,
'sender_id' => $context['user']['id'],
'sender_name' => $context['user']['name'],
'comment' => $reason,
'time' => time(),
)), 0),
array('id_task')
Expand Down
135 changes: 135 additions & 0 deletions Sources/tasks/UserReport-Notify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

/**
* This task handles notifying users when another user's profile gets reported.
*
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines http://www.simplemachines.org
* @copyright 2014 Simple Machines and individual contributors
* @license http://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1 Alpha 1
*/

class UserReport_Notify_Background extends SMF_BackgroundTask
{
public function execute()
{
global $smcFunc, $sourcedir, $modSettings, $language, $scripturl;

// Anyone with moderate_forum can see this report
require_once($sourcedir . '/Subs-Members.php');
$members = membersAllowedTo('moderate_forum');

// And don't send it to them if they're the one who reported it.
$members = array_diff($members, array($this->_details['sender_id']));

// Having successfully figured this out, now let's get the preferences of everyone.
require_once($sourcedir . '/Subs-Notify.php');
$prefs = getNotifyPrefs($members, 'msg_report', true);

// So now we find out who wants what.
$alert_bits = array(
'alert' => 0x01,
'email' => 0x02,
);
$notifies = array();

foreach ($prefs as $member => $pref_option)
{
foreach ($alert_bits as $type => $bitvalue)
if ($pref_option['msg_report'] & $bitvalue)
$notifies[$type][] = $member;
}

// 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' => 'profile',
'content_id' => $this->_details['user_id'],
'content_action' => 'report',
'is_read' => 0,
'extra' => serialize(
array(
'report_link' => '?action=moderate;area=userreports;report=' . $this->_details['report_id'], // We don't put $scripturl in these!
'user_name' => $this->_details['membername'],
)
),
);
}

$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);

// Iterate through each language, load the relevant templates and set up sending.
foreach ($emails as $this_lang => $recipients)
{
$replacements = array(
'MEMBERNAME' => $member_name,
'REPORTERNAME' => $this->_details['sender_name'],
'PROFILELINK' => $scripturl . '?action=profile;u=' . $this->_details['user_id'],
'REPORTLINK' => $scripturl . '?action=moderate;area=reports;report=' . $this->_details['report_id'],
'COMMENT' => $this->_details['comment'],
);

$emaildata = loadEmailTemplate('report_user_profile', $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, 'ureport' . $this->_details['report_id'], false, 2);
}
}

// And now we're all done.
return true;
}
}

?>
161 changes: 161 additions & 0 deletions Sources/tasks/UserReportReply-Notify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?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 2014 Simple Machines and individual contributors
* @license http://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1 Alpha 1
*/

class UserReportReply_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_forum');

// Having successfully figured this out, now let's get the preferences of everyone.
require_once($sourcedir . '/Subs-Notify.php');
$prefs = getNotifyPrefs($members, 'user_report_reply', true);

// So now we find out who wants what.
$alert_bits = array(
'alert' => 0x01,
'email' => 0x02,
);
$notifies = array();

foreach ($prefs as $member => $pref_option)
{
foreach ($alert_bits as $type => $bitvalue)
{
if ($pref_option['msg_report_reply'] & $bitvalue)
$notifies[$type][] = $member;
}
}

// 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' => 'profile',
'content_id' => $this->_details['user_id'],
'content_action' => 'report_reply',
'is_read' => 0,
'extra' => serialize(
array(
'report_link' => '?action=moderate;area=userreports;report=' . $this->_details['report_id'], // We don't put $scripturl in these!
'user_name' => $this->_details['user_name'],
)
),
);
}

$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);

// Iterate through each language, load the relevant templates and set up sending.
foreach ($emails as $this_lang => $recipients)
{
$replacements = array(
'MEMBERNAME' => $this->_details['member_name'],
'COMMENTERNAME' => $this->_details['sender_name'],
'PROFILELINK' => $scripturl . 'action=profile;u=' . $this->_details['user_id'],
'REPORTLINK' => $scripturl . '?action=moderate;area=userreports;report=' . $this->_details['report_id'],
);

$emaildata = loadEmailTemplate('reply_to_user_reports', $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, 'urptrpy' . $this->_details['comment_id'], false, 3);
}
}

// And now we're all done.
return true;
}
}

?>
2 changes: 2 additions & 0 deletions Themes/default/languages/Alerts.english.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$txt['alert_msg_like'] = '{member_link} liked your post {msg_msg}';
$txt['alert_msg_report'] = '{member_link} <a href="{scripturl}{report_link}">reported a post</a> - {msg_msg}';
$txt['alert_msg_report_reply'] = '{member_link} replied to <a href="{scripturl}{report_link}">the report</a> about {msg_msg}';
$txt['alert_profile_report'] = '{member_link} <a href="{scriptur}{report_link}">reported</a> the profile of {profile_msg}';
$txt['alert_profile_report_reply'] = '{member_link} replied to <a href="{scripturl}{report_link}">the report</a> about the profile of {profile_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)';
Expand Down
36 changes: 36 additions & 0 deletions Themes/default/languages/EmailTemplates.english.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,42 @@
{REGARDS}';

/**
@additional_params: report_user_profile
MEMBERNAME: The display name of the reported user
REPORTERNAME: The name of the person reporting the profile
PROFILELINK: The link to the profile that was reported
COMMENT: The comment left by the reporter.
@description: When a user's profile is reported
*/
$txt['report_user_profile_subject'] = 'Reported profile: {MEMBERNAME}';
$txt['report_user_profile_body'] = 'The profile of "{MEMBERNAME}" has been reported by {REPORTERNAME}.
The profile: {PROFILELINK}
Moderation center: {REPORTLINK}
The reporter has made the following comment:
{COMMENT}
{REGARDS}';

/**
@additional_params: report_user_profile
MEMBERNAME: The display name of the reported user
COMMENTERNAME: The name of the person who added the comment
PROFILELINK: The link to the profile that was reported
@description: When someone replies to a report about a profile, this can be sent to others who replied
*/
$txt['reply_to_user_report_subject'] = 'Follow-up to reported profile: {MEMBERNAME}';
$txt['reply_to_user_report_body'] = 'Previously, the profile of {MEMBERNAME} was reported.
Since then, {COMMENTERNAME} has added a comment to the report. More information can be found in the forum.
The profile: {PROFILELINK}
Moderation center: {REPORTLINK}
{REGARDS}';

/**
@additional_params: change_password
USERNAME: The user name for the member receiving the email.
Expand Down

0 comments on commit 5de4360

Please sign in to comment.