forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquote.php
More file actions
216 lines (186 loc) · 5.69 KB
/
Copy pathquote.php
File metadata and controls
216 lines (186 loc) · 5.69 KB
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
/**
*
* @package notifications
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\notification\type;
/**
* Post quoting notifications class
* This class handles notifying users when they have been quoted in a post
*
* @package notifications
*/
class quote extends \phpbb\notification\type\post
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'quote';
}
/**
* regular expression to match to find usernames
*
* @var string
*/
protected static $regular_expression_match = '#\[quote="(.+?)"#';
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_QUOTE';
/**
* Notification option data (for outputting to the user)
*
* @var bool|array False if the service should use it's default data
* Array of data (including keys 'id', 'lang', and 'group')
*/
public static $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_QUOTE',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/**
* Is available
*/
public function is_available()
{
return true;
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$usernames = false;
preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames);
if (empty($usernames[1]))
{
return array();
}
$usernames[1] = array_unique($usernames[1]);
$usernames = array_map('utf8_clean_string', $usernames[1]);
$users = array();
$sql = 'SELECT user_id
FROM ' . USERS_TABLE . '
WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . '
AND user_id <> ' . (int) $post['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$users[] = $row['user_id'];
}
$this->db->sql_freeresult($result);
if (empty($users))
{
return array();
}
sort($users);
$auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']);
if (empty($auth_read))
{
return array();
}
$notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options);
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$update_notifications = array();
$sql = 'SELECT n.*
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
AND n.notification_read = 0
AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
// Do not create a new notification
unset($notify_users[$row['user_id']]);
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
$sql = 'UPDATE ' . $this->notifications_table . '
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
WHERE notification_id = ' . $row['notification_id'];
$this->db->sql_query($sql);
}
$this->db->sql_freeresult($result);
return $notify_users;
}
/**
* Update a notification
*
* @param array $data Data specific for this type that will be updated
*/
public function update_notifications($post)
{
$old_notifications = array();
$sql = 'SELECT n.user_id
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
AND n.item_id = ' . self::get_item_id($post) . '
AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$old_notifications[] = $row['user_id'];
}
$this->db->sql_freeresult($result);
// Find the new users to notify
$notifications = $this->find_users_for_notification($post);
// Find the notifications we must delete
$remove_notifications = array_diff($old_notifications, array_keys($notifications));
// Find the notifications we must add
$add_notifications = array();
foreach (array_diff(array_keys($notifications), $old_notifications) as $user_id)
{
$add_notifications[$user_id] = $notifications[$user_id];
}
// Add the necessary notifications
$this->notification_manager->add_notifications_for_users($this->get_type(), $post, $add_notifications);
// Remove the necessary notifications
if (!empty($remove_notifications))
{
$sql = 'DELETE FROM ' . $this->notifications_table . '
WHERE notification_type_id = ' . (int) $this->notification_type_id . '
AND item_id = ' . self::get_item_id($post) . '
AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
$this->db->sql_query($sql);
}
// return true to continue with the update code in the notifications service (this will update the rest of the notifications)
return true;
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'quote';
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
$user_data = $this->user_loader->get_user($this->get_data('poster_id'));
return array_merge(parent::get_email_template_variables(), array(
'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']),
));
}
}