1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216:
<?php
class MsgReportReply_Notify_Background extends SMF_BackgroundTask
{
public function execute()
{
global $smcFunc, $sourcedir, $modSettings, $language, $scripturl;
$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);
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;
require_once($sourcedir . '/Subs-Members.php');
$members = membersAllowedTo('moderate_board', $this->_details['board_id']);
$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);
$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);
$members = array_intersect($possible_members, $members);
require_once($sourcedir . '/Subs-Notify.php');
$prefs = getNotifyPrefs($members, 'msg_report_reply', true);
$alert_bits = array(
'alert' => self::RECEIVE_NOTIFY_ALERT,
'email' => self::RECEIVE_NOTIFY_EMAIL,
);
$notifies = array();
foreach ($prefs as $member => $pref_option)
{
foreach ($alert_bits as $type => $bitvalue)
{
if ($pref_option['msg_report_reply'] & $bitvalue)
$notifies[$type][] = $member;
}
}
if (!empty($notifies['alert']))
{
$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' => $smcFunc['json_encode'](
array(
'report_link' => '?action=moderate;area=reportedposts;sa=details;rid=' . $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')
);
updateMemberData($notifies['alert'], array('alerts' => '+'));
}
if (!empty($notifies['email']))
{
require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/ScheduledTasks.php');
loadEssentialThemeData();
$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);
$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);
foreach ($emails as $this_lang => $recipients)
{
$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=reportedposts;sa=details;rid=' . $this->_details['report_id'],
);
$emaildata = loadEmailTemplate('reply_to_moderator', $replacements, empty($modSettings['userLanguage']) ? $language : $this_lang);
foreach ($recipients as $id_member => $email_address)
sendmail($email_address, $emaildata['subject'], $emaildata['body'], null, 'rptrpy' . $this->_details['comment_id'], $emaildata['is_html'], 3);
}
}
return true;
}
}
?>