|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This task handles notifying users when another member's profile gets reported. |
|
5
|
|
|
* |
|
6
|
|
|
* Simple Machines Forum (SMF) |
|
7
|
|
|
* |
|
8
|
|
|
* @package SMF |
|
9
|
|
|
* @author Simple Machines http://www.simplemachines.org |
|
10
|
|
|
* @copyright 2019 Simple Machines and individual contributors |
|
11
|
|
|
* @license http://www.simplemachines.org/about/smf/license.php BSD |
|
12
|
|
|
* |
|
13
|
|
|
* @version 2.1 RC2 |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class MemberReport_Notify_Background |
|
18
|
|
|
*/ |
|
19
|
|
|
class MemberReport_Notify_Background extends SMF_BackgroundTask |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
23
|
|
|
* @return bool Always returns true. |
|
24
|
|
|
*/ |
|
25
|
|
|
public function execute() |
|
26
|
|
|
{ |
|
27
|
|
|
global $smcFunc, $sourcedir, $modSettings, $language, $scripturl; |
|
28
|
|
|
|
|
29
|
|
|
// Anyone with moderate_forum can see this report |
|
30
|
|
|
require_once($sourcedir . '/Subs-Members.php'); |
|
31
|
|
|
$members = membersAllowedTo('moderate_forum'); |
|
32
|
|
|
|
|
33
|
|
|
// And don't send it to them if they're the one who reported it. |
|
34
|
|
|
$members = array_diff($members, array($this->_details['sender_id'])); |
|
35
|
|
|
|
|
36
|
|
|
// Having successfully figured this out, now let's get the preferences of everyone. |
|
37
|
|
|
require_once($sourcedir . '/Subs-Notify.php'); |
|
38
|
|
|
$prefs = getNotifyPrefs($members, 'member_report', true); |
|
39
|
|
|
|
|
40
|
|
|
// So now we find out who wants what. |
|
41
|
|
|
$alert_bits = array( |
|
42
|
|
|
'alert' => self::RECEIVE_NOTIFY_ALERT, |
|
43
|
|
|
'email' => self::RECEIVE_NOTIFY_EMAIL, |
|
44
|
|
|
); |
|
45
|
|
|
$notifies = array(); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($prefs as $member => $pref_option) |
|
48
|
|
|
{ |
|
49
|
|
|
foreach ($alert_bits as $type => $bitvalue) |
|
50
|
|
|
if ($pref_option['member_report'] & $bitvalue) |
|
51
|
|
|
$notifies[$type][] = $member; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// Firstly, anyone who wants alerts. |
|
55
|
|
|
if (!empty($notifies['alert'])) |
|
56
|
|
|
{ |
|
57
|
|
|
// Alerts are relatively easy. |
|
58
|
|
|
$insert_rows = array(); |
|
59
|
|
|
foreach ($notifies['alert'] as $member) |
|
60
|
|
|
{ |
|
61
|
|
|
$insert_rows[] = array( |
|
62
|
|
|
'alert_time' => $this->_details['time'], |
|
63
|
|
|
'id_member' => $member, |
|
64
|
|
|
'id_member_started' => $this->_details['sender_id'], |
|
65
|
|
|
'member_name' => $this->_details['sender_name'], |
|
66
|
|
|
'content_type' => 'member', |
|
67
|
|
|
'content_id' => $this->_details['user_id'], |
|
68
|
|
|
'content_action' => 'report', |
|
69
|
|
|
'is_read' => 0, |
|
70
|
|
|
'extra' => $smcFunc['json_encode']( |
|
71
|
|
|
array( |
|
72
|
|
|
'report_link' => '?action=moderate;area=reportedmembers;sa=details;rid=' . $this->_details['report_id'], // We don't put $scripturl in these! |
|
73
|
|
|
'user_name' => $this->_details['user_name'], |
|
74
|
|
|
) |
|
75
|
|
|
), |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$smcFunc['db_insert']('insert', |
|
80
|
|
|
'{db_prefix}user_alerts', |
|
81
|
|
|
array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', |
|
82
|
|
|
'member_name' => 'string', 'content_type' => 'string', 'content_id' => 'int', |
|
83
|
|
|
'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'), |
|
84
|
|
|
$insert_rows, |
|
85
|
|
|
array('id_alert') |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
// And update the count of alerts for those people. |
|
89
|
|
|
updateMemberData($notifies['alert'], array('alerts' => '+')); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
// Secondly, anyone who wants emails. |
|
93
|
|
|
if (!empty($notifies['email'])) |
|
94
|
|
|
{ |
|
95
|
|
|
// Emails are a bit complicated. We have to do language stuff. |
|
96
|
|
|
require_once($sourcedir . '/Subs-Post.php'); |
|
97
|
|
|
require_once($sourcedir . '/ScheduledTasks.php'); |
|
98
|
|
|
loadEssentialThemeData(); |
|
99
|
|
|
|
|
100
|
|
|
// First, get everyone's language and details. |
|
101
|
|
|
$emails = array(); |
|
102
|
|
|
$request = $smcFunc['db_query']('', ' |
|
103
|
|
|
SELECT id_member, lngfile, email_address |
|
104
|
|
|
FROM {db_prefix}members |
|
105
|
|
|
WHERE id_member IN ({array_int:members})', |
|
106
|
|
|
array( |
|
107
|
|
|
'members' => $notifies['email'], |
|
108
|
|
|
) |
|
109
|
|
|
); |
|
110
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
111
|
|
|
{ |
|
112
|
|
|
if (empty($row['lngfile'])) |
|
113
|
|
|
$row['lngfile'] = $language; |
|
114
|
|
|
$emails[$row['lngfile']][$row['id_member']] = $row['email_address']; |
|
115
|
|
|
} |
|
116
|
|
|
$smcFunc['db_free_result']($request); |
|
117
|
|
|
|
|
118
|
|
|
// Iterate through each language, load the relevant templates and set up sending. |
|
119
|
|
|
foreach ($emails as $this_lang => $recipients) |
|
120
|
|
|
{ |
|
121
|
|
|
$replacements = array( |
|
122
|
|
|
'MEMBERNAME' => $this->_details['user_name'], |
|
123
|
|
|
'REPORTERNAME' => $this->_details['sender_name'], |
|
124
|
|
|
'PROFILELINK' => $scripturl . '?action=profile;u=' . $this->_details['user_id'], |
|
125
|
|
|
'REPORTLINK' => $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $this->_details['report_id'], |
|
126
|
|
|
'COMMENT' => $this->_details['comment'], |
|
127
|
|
|
); |
|
128
|
|
|
|
|
129
|
|
|
$emaildata = loadEmailTemplate('report_member_profile', $replacements, empty($modSettings['userLanguage']) ? $language : $this_lang); |
|
130
|
|
|
|
|
131
|
|
|
// And do the actual sending... |
|
132
|
|
|
foreach ($recipients as $id_member => $email_address) |
|
133
|
|
|
sendmail($email_address, $emaildata['subject'], $emaildata['body'], null, 'ureport' . $this->_details['report_id'], $emaildata['is_html'], 2); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
// And now we're all done. |
|
138
|
|
|
return true; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
?> |