|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Simple Machines Forum (SMF) |
|
5
|
|
|
* |
|
6
|
|
|
* @package SMF |
|
7
|
|
|
* @author Simple Machines http://www.simplemachines.org |
|
8
|
|
|
* @copyright 2019 Simple Machines and individual contributors |
|
9
|
|
|
* @license http://www.simplemachines.org/about/smf/license.php BSD |
|
10
|
|
|
* |
|
11
|
|
|
* @version 2.1 RC2 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
if (!defined('SMF')) |
|
15
|
|
|
die('No direct access...'); |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Fetches the list of preferences (or a single/subset of preferences) for |
|
19
|
|
|
* notifications for one or more users. |
|
20
|
|
|
* |
|
21
|
|
|
* @param int|array $members A user id or an array of (integer) user ids to load preferences for |
|
22
|
|
|
* @param string|array $prefs An empty string to load all preferences, or a string (or array) of preference name(s) to load |
|
23
|
|
|
* @param bool $process_default Whether to apply the default values to the members' values or not. |
|
24
|
|
|
* @return array An array of user ids => array (pref name -> value), with user id 0 representing the defaults |
|
25
|
|
|
*/ |
|
26
|
|
|
function getNotifyPrefs($members, $prefs = '', $process_default = false) |
|
27
|
|
|
{ |
|
28
|
|
|
global $smcFunc; |
|
29
|
|
|
|
|
30
|
|
|
// We want this as an array whether it is or not. |
|
31
|
|
|
$members = is_array($members) ? $members : (array) $members; |
|
32
|
|
|
|
|
33
|
|
|
if (!empty($prefs)) |
|
34
|
|
|
$prefs = is_array($prefs) ? $prefs : (array) $prefs; |
|
35
|
|
|
|
|
36
|
|
|
$result = array(); |
|
37
|
|
|
|
|
38
|
|
|
// We want to now load the default, which is stored with a member id of 0. |
|
39
|
|
|
$members[] = 0; |
|
40
|
|
|
|
|
41
|
|
|
$request = $smcFunc['db_query']('', ' |
|
42
|
|
|
SELECT id_member, alert_pref, alert_value |
|
43
|
|
|
FROM {db_prefix}user_alerts_prefs |
|
44
|
|
|
WHERE id_member IN ({array_int:members})' . (!empty($prefs) ? ' |
|
45
|
|
|
AND alert_pref IN ({array_string:prefs})' : ''), |
|
46
|
|
|
array( |
|
47
|
|
|
'members' => $members, |
|
48
|
|
|
'prefs' => $prefs, |
|
49
|
|
|
) |
|
50
|
|
|
); |
|
51
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
52
|
|
|
$result[$row['id_member']][$row['alert_pref']] = $row['alert_value']; |
|
53
|
|
|
|
|
54
|
|
|
// We may want to keep the default values separate from a given user's. Or we might not. |
|
55
|
|
|
if ($process_default && isset($result[0])) |
|
56
|
|
|
{ |
|
57
|
|
|
foreach ($members as $member) |
|
58
|
|
|
if (isset($result[$member])) |
|
59
|
|
|
$result[$member] += $result[0]; |
|
60
|
|
|
else |
|
61
|
|
|
$result[$member] = $result[0]; |
|
62
|
|
|
|
|
63
|
|
|
unset ($result[0]); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $result; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Sets the list of preferences for a single user. |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $memID The user whose preferences you are setting |
|
73
|
|
|
* @param array $prefs An array key of pref -> value |
|
74
|
|
|
*/ |
|
75
|
|
|
function setNotifyPrefs($memID, $prefs = array()) |
|
76
|
|
|
{ |
|
77
|
|
|
global $smcFunc; |
|
78
|
|
|
|
|
79
|
|
|
if (empty($prefs) || !is_int($memID)) |
|
80
|
|
|
return; |
|
81
|
|
|
|
|
82
|
|
|
$update_rows = array(); |
|
83
|
|
|
foreach ($prefs as $k => $v) |
|
84
|
|
|
$update_rows[] = array($memID, $k, $v); |
|
85
|
|
|
|
|
86
|
|
|
$smcFunc['db_insert']('replace', |
|
87
|
|
|
'{db_prefix}user_alerts_prefs', |
|
88
|
|
|
array('id_member' => 'int', 'alert_pref' => 'string', 'alert_value' => 'int'), |
|
89
|
|
|
$update_rows, |
|
90
|
|
|
array('id_member', 'alert_pref') |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Deletes notification preference |
|
96
|
|
|
* |
|
97
|
|
|
* @param int $memID The user whose preference you're setting |
|
98
|
|
|
* @param array $prefs The preferences to delete |
|
99
|
|
|
*/ |
|
100
|
|
|
function deleteNotifyPrefs($memID, array $prefs) |
|
101
|
|
|
{ |
|
102
|
|
|
global $smcFunc; |
|
103
|
|
|
|
|
104
|
|
|
if (empty($prefs) || empty($memID)) |
|
105
|
|
|
return; |
|
106
|
|
|
|
|
107
|
|
|
$smcFunc['db_query']('', ' |
|
108
|
|
|
DELETE FROM {db_prefix}user_alerts_prefs |
|
109
|
|
|
WHERE id_member = {int:member} |
|
110
|
|
|
AND alert_pref IN ({array_string:prefs})', |
|
111
|
|
|
array( |
|
112
|
|
|
'member' => $memID, |
|
113
|
|
|
'prefs' => $prefs, |
|
114
|
|
|
) |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Deletes notification preference |
|
120
|
|
|
* |
|
121
|
|
|
* @param int $memID The user whose preference you're setting |
|
122
|
|
|
* @param array $prefs The preferences to delete |
|
123
|
|
|
*/ |
|
124
|
|
|
function unsubscribeMail($memID) |
|
125
|
|
|
{ |
|
126
|
|
|
global $smcFunc; |
|
127
|
|
|
|
|
128
|
|
|
if (empty($memID)) |
|
129
|
|
|
return; |
|
130
|
|
|
|
|
131
|
|
|
$skipPref = array('alert_timeout'); |
|
132
|
|
|
|
|
133
|
|
|
$smcFunc['db_query']('', ' |
|
134
|
|
|
UPDATE {db_prefix}user_alerts_prefs |
|
135
|
|
|
SET alert_value - 2 |
|
136
|
|
|
WHERE id_member = {int:member} |
|
137
|
|
|
AND alert_pref NOT IN ({array_string:skipPref}) |
|
138
|
|
|
AND (2 & alert_value) = 2', |
|
139
|
|
|
array( |
|
140
|
|
|
'member' => $memID, |
|
141
|
|
|
'skipPref' => $skipPref, |
|
142
|
|
|
) |
|
143
|
|
|
); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
?> |