|
@@ -1,43 +1,45 @@
|
1
|
|
-<?
|
2
|
|
-class Subscriptions {
|
3
|
|
- /**
|
4
|
|
- * Parse a post/comment body for quotes and notify all quoted users that have quote notifications enabled.
|
5
|
|
- * @param string $Body
|
6
|
|
- * @param int $PostID
|
7
|
|
- * @param string $Page
|
8
|
|
- * @param int $PageID
|
9
|
|
- */
|
10
|
|
- public static function quote_notify($Body, $PostID, $Page, $PageID) {
|
11
|
|
- $QueryID = G::$DB->get_query_id();
|
12
|
|
- /*
|
13
|
|
- * Explanation of the parameters PageID and Page: Page contains where
|
14
|
|
- * this quote comes from and can be forums, artist, collages, requests
|
15
|
|
- * or torrents. The PageID contains the additional value that is
|
16
|
|
- * necessary for the users_notify_quoted table. The PageIDs for the
|
17
|
|
- * different Page are: forums: TopicID artist: ArtistID collages:
|
18
|
|
- * CollageID requests: RequestID torrents: GroupID
|
|
1
|
+<?php
|
|
2
|
+class Subscriptions
|
|
3
|
+{
|
|
4
|
+ /**
|
|
5
|
+ * Parse a post/comment body for quotes and notify all quoted users that have quote notifications enabled.
|
|
6
|
+ * @param string $Body
|
|
7
|
+ * @param int $PostID
|
|
8
|
+ * @param string $Page
|
|
9
|
+ * @param int $PageID
|
19
|
10
|
*/
|
20
|
|
- $Matches = [];
|
21
|
|
- preg_match_all('/\[quote(?:=(.*)(?:\|.*)?)?]|\[\/quote]/iU', $Body, $Matches, PREG_SET_ORDER);
|
|
11
|
+ public static function quote_notify($Body, $PostID, $Page, $PageID)
|
|
12
|
+ {
|
|
13
|
+ $QueryID = G::$DB->get_query_id();
|
|
14
|
+ /*
|
|
15
|
+ * Explanation of the parameters PageID and Page: Page contains where
|
|
16
|
+ * this quote comes from and can be forums, artist, collages, requests
|
|
17
|
+ * or torrents. The PageID contains the additional value that is
|
|
18
|
+ * necessary for the users_notify_quoted table. The PageIDs for the
|
|
19
|
+ * different Page are: forums: TopicID artist: ArtistID collages:
|
|
20
|
+ * CollageID requests: RequestID torrents: GroupID
|
|
21
|
+ */
|
|
22
|
+ $Matches = [];
|
|
23
|
+ preg_match_all('/\[quote(?:=(.*)(?:\|.*)?)?]|\[\/quote]/iU', $Body, $Matches, PREG_SET_ORDER);
|
22
|
24
|
|
23
|
|
- if (count($Matches)) {
|
24
|
|
- $Usernames = [];
|
25
|
|
- $Level = 0;
|
26
|
|
- foreach ($Matches as $M) {
|
27
|
|
- if ($M[0] != '[/quote]') {
|
28
|
|
- if ($Level == 0 && isset($M[1]) && strlen($M[1]) > 0 && preg_match(USERNAME_REGEX, $M[1])) {
|
29
|
|
- $Usernames[] = preg_replace('/(^[.,]*)|([.,]*$)/', '', $M[1]); // wut?
|
30
|
|
- }
|
31
|
|
- ++$Level;
|
32
|
|
- } else {
|
33
|
|
- --$Level;
|
|
25
|
+ if (count($Matches)) {
|
|
26
|
+ $Usernames = [];
|
|
27
|
+ $Level = 0;
|
|
28
|
+ foreach ($Matches as $M) {
|
|
29
|
+ if ($M[0] != '[/quote]') {
|
|
30
|
+ if ($Level == 0 && isset($M[1]) && strlen($M[1]) > 0 && preg_match(USERNAME_REGEX, $M[1])) {
|
|
31
|
+ $Usernames[] = preg_replace('/(^[.,]*)|([.,]*$)/', '', $M[1]); // wut?
|
|
32
|
+ }
|
|
33
|
+ ++$Level;
|
|
34
|
+ } else {
|
|
35
|
+ --$Level;
|
|
36
|
+ }
|
|
37
|
+ }
|
34
|
38
|
}
|
35
|
|
- }
|
36
|
|
- }
|
37
|
|
- // remove any dupes in the array (the fast way)
|
38
|
|
- $Usernames = array_flip(array_flip($Usernames));
|
|
39
|
+ // remove any dupes in the array (the fast way)
|
|
40
|
+ $Usernames = array_flip(array_flip($Usernames));
|
39
|
41
|
|
40
|
|
- G::$DB->query("
|
|
42
|
+ G::$DB->query("
|
41
|
43
|
SELECT m.ID
|
42
|
44
|
FROM users_main AS m
|
43
|
45
|
LEFT JOIN users_info AS i ON i.UserID = m.ID
|
|
@@ -45,152 +47,163 @@ class Subscriptions {
|
45
|
47
|
AND i.NotifyOnQuote = '1'
|
46
|
48
|
AND i.UserID != " . G::$LoggedUser['ID']);
|
47
|
49
|
|
48
|
|
- $Results = G::$DB->to_array();
|
49
|
|
- foreach ($Results as $Result) {
|
50
|
|
- $UserID = db_string($Result['ID']);
|
51
|
|
- $QuoterID = db_string(G::$LoggedUser['ID']);
|
52
|
|
- $Page = db_string($Page);
|
53
|
|
- $PageID = db_string($PageID);
|
54
|
|
- $PostID = db_string($PostID);
|
|
50
|
+ $Results = G::$DB->to_array();
|
|
51
|
+ foreach ($Results as $Result) {
|
|
52
|
+ $UserID = db_string($Result['ID']);
|
|
53
|
+ $QuoterID = db_string(G::$LoggedUser['ID']);
|
|
54
|
+ $Page = db_string($Page);
|
|
55
|
+ $PageID = db_string($PageID);
|
|
56
|
+ $PostID = db_string($PostID);
|
55
|
57
|
|
56
|
|
- G::$DB->query("
|
|
58
|
+ G::$DB->query(
|
|
59
|
+ "
|
57
|
60
|
INSERT IGNORE INTO users_notify_quoted
|
58
|
61
|
(UserID, QuoterID, Page, PageID, PostID, Date)
|
59
|
62
|
VALUES
|
60
|
63
|
( ?, ?, ?, ?, ?, NOW())",
|
61
|
|
- $Result['ID'], G::$LoggedUser['ID'], $Page, $PageID, $PostID);
|
62
|
|
- G::$Cache->delete_value("notify_quoted_$UserID");
|
63
|
|
- if ($Page == 'forums') {
|
64
|
|
- $URL = site_url() . "forums.php?action=viewthread&postid=$PostID";
|
65
|
|
- } else {
|
66
|
|
- $URL = site_url() . "comments.php?action=jump&postid=$PostID";
|
67
|
|
- }
|
|
64
|
+ $Result['ID'],
|
|
65
|
+ G::$LoggedUser['ID'],
|
|
66
|
+ $Page,
|
|
67
|
+ $PageID,
|
|
68
|
+ $PostID
|
|
69
|
+ );
|
|
70
|
+ G::$Cache->delete_value("notify_quoted_$UserID");
|
|
71
|
+ if ($Page == 'forums') {
|
|
72
|
+ $URL = site_url() . "forums.php?action=viewthread&postid=$PostID";
|
|
73
|
+ } else {
|
|
74
|
+ $URL = site_url() . "comments.php?action=jump&postid=$PostID";
|
|
75
|
+ }
|
|
76
|
+ }
|
|
77
|
+ G::$DB->set_query_id($QueryID);
|
68
|
78
|
}
|
69
|
|
- G::$DB->set_query_id($QueryID);
|
70
|
|
- }
|
71
|
79
|
|
72
|
|
- /**
|
73
|
|
- * (Un)subscribe from a forum thread.
|
74
|
|
- * If UserID == 0, G::$LoggedUser[ID] is used
|
75
|
|
- * @param int $TopicID
|
76
|
|
- * @param int $UserID
|
77
|
|
- */
|
78
|
|
- public static function subscribe($TopicID, $UserID = 0) {
|
79
|
|
- if ($UserID == 0) {
|
80
|
|
- $UserID = G::$LoggedUser['ID'];
|
81
|
|
- }
|
82
|
|
- $QueryID = G::$DB->get_query_id();
|
83
|
|
- $UserSubscriptions = self::get_subscriptions();
|
84
|
|
- $Key = self::has_subscribed($TopicID);
|
85
|
|
- if ($Key !== false) {
|
86
|
|
- G::$DB->query('
|
|
80
|
+ /**
|
|
81
|
+ * (Un)subscribe from a forum thread.
|
|
82
|
+ * If UserID == 0, G::$LoggedUser[ID] is used
|
|
83
|
+ * @param int $TopicID
|
|
84
|
+ * @param int $UserID
|
|
85
|
+ */
|
|
86
|
+ public static function subscribe($TopicID, $UserID = 0)
|
|
87
|
+ {
|
|
88
|
+ if ($UserID == 0) {
|
|
89
|
+ $UserID = G::$LoggedUser['ID'];
|
|
90
|
+ }
|
|
91
|
+ $QueryID = G::$DB->get_query_id();
|
|
92
|
+ $UserSubscriptions = self::get_subscriptions();
|
|
93
|
+ $Key = self::has_subscribed($TopicID);
|
|
94
|
+ if ($Key !== false) {
|
|
95
|
+ G::$DB->query('
|
87
|
96
|
DELETE FROM users_subscriptions
|
88
|
97
|
WHERE UserID = ' . db_string($UserID) . '
|
89
|
98
|
AND TopicID = ' . db_string($TopicID));
|
90
|
|
- unset($UserSubscriptions[$Key]);
|
91
|
|
- } else {
|
92
|
|
- G::$DB->query("
|
|
99
|
+ unset($UserSubscriptions[$Key]);
|
|
100
|
+ } else {
|
|
101
|
+ G::$DB->query("
|
93
|
102
|
INSERT IGNORE INTO users_subscriptions (UserID, TopicID)
|
94
|
103
|
VALUES ($UserID, " . db_string($TopicID) . ")");
|
95
|
|
- array_push($UserSubscriptions, $TopicID);
|
|
104
|
+ array_push($UserSubscriptions, $TopicID);
|
|
105
|
+ }
|
|
106
|
+ G::$Cache->replace_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
|
|
107
|
+ G::$Cache->delete_value("subscriptions_user_new_$UserID");
|
|
108
|
+ G::$DB->set_query_id($QueryID);
|
96
|
109
|
}
|
97
|
|
- G::$Cache->replace_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
|
98
|
|
- G::$Cache->delete_value("subscriptions_user_new_$UserID");
|
99
|
|
- G::$DB->set_query_id($QueryID);
|
100
|
|
- }
|
101
|
110
|
|
102
|
|
- /**
|
103
|
|
- * (Un)subscribe from comments.
|
104
|
|
- * If UserID == 0, G::$LoggedUser[ID] is used
|
105
|
|
- * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
|
106
|
|
- * @param int $PageID ArtistID, CollageID, RequestID or GroupID
|
107
|
|
- * @param int $UserID
|
108
|
|
- */
|
109
|
|
- public static function subscribe_comments($Page, $PageID, $UserID = 0) {
|
110
|
|
- if ($UserID == 0) {
|
111
|
|
- $UserID = G::$LoggedUser['ID'];
|
112
|
|
- }
|
113
|
|
- $QueryID = G::$DB->get_query_id();
|
114
|
|
- $UserCommentSubscriptions = self::get_comment_subscriptions();
|
115
|
|
- $Key = self::has_subscribed_comments($Page, $PageID);
|
116
|
|
- if ($Key !== false) {
|
117
|
|
- G::$DB->query("
|
|
111
|
+ /**
|
|
112
|
+ * (Un)subscribe from comments.
|
|
113
|
+ * If UserID == 0, G::$LoggedUser[ID] is used
|
|
114
|
+ * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
|
|
115
|
+ * @param int $PageID ArtistID, CollageID, RequestID or GroupID
|
|
116
|
+ * @param int $UserID
|
|
117
|
+ */
|
|
118
|
+ public static function subscribe_comments($Page, $PageID, $UserID = 0)
|
|
119
|
+ {
|
|
120
|
+ if ($UserID == 0) {
|
|
121
|
+ $UserID = G::$LoggedUser['ID'];
|
|
122
|
+ }
|
|
123
|
+ $QueryID = G::$DB->get_query_id();
|
|
124
|
+ $UserCommentSubscriptions = self::get_comment_subscriptions();
|
|
125
|
+ $Key = self::has_subscribed_comments($Page, $PageID);
|
|
126
|
+ if ($Key !== false) {
|
|
127
|
+ G::$DB->query("
|
118
|
128
|
DELETE FROM users_subscriptions_comments
|
119
|
129
|
WHERE UserID = " . db_string($UserID) . "
|
120
|
130
|
AND Page = '" . db_string($Page) . "'
|
121
|
131
|
AND PageID = " . db_string($PageID));
|
122
|
|
- unset($UserCommentSubscriptions[$Key]);
|
123
|
|
- } else {
|
124
|
|
- G::$DB->query("
|
|
132
|
+ unset($UserCommentSubscriptions[$Key]);
|
|
133
|
+ } else {
|
|
134
|
+ G::$DB->query("
|
125
|
135
|
INSERT IGNORE INTO users_subscriptions_comments
|
126
|
136
|
(UserID, Page, PageID)
|
127
|
137
|
VALUES
|
128
|
138
|
($UserID, '" . db_string($Page) . "', " . db_string($PageID) . ")");
|
129
|
|
- array_push($UserCommentSubscriptions, array($Page, $PageID));
|
|
139
|
+ array_push($UserCommentSubscriptions, array($Page, $PageID));
|
|
140
|
+ }
|
|
141
|
+ G::$Cache->replace_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
|
|
142
|
+ G::$Cache->delete_value("subscriptions_comments_user_new_$UserID");
|
|
143
|
+ G::$DB->set_query_id($QueryID);
|
130
|
144
|
}
|
131
|
|
- G::$Cache->replace_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
|
132
|
|
- G::$Cache->delete_value("subscriptions_comments_user_new_$UserID");
|
133
|
|
- G::$DB->set_query_id($QueryID);
|
134
|
|
- }
|
135
|
145
|
|
136
|
|
- /**
|
137
|
|
- * Read $UserID's subscriptions. If the cache key isn't set, it gets filled.
|
138
|
|
- * If UserID == 0, G::$LoggedUser[ID] is used
|
139
|
|
- * @param int $UserID
|
140
|
|
- * @return array Array of TopicIDs
|
141
|
|
- */
|
142
|
|
- public static function get_subscriptions($UserID = 0) {
|
143
|
|
- if ($UserID == 0) {
|
144
|
|
- $UserID = G::$LoggedUser['ID'];
|
145
|
|
- }
|
146
|
|
- $QueryID = G::$DB->get_query_id();
|
147
|
|
- $UserSubscriptions = G::$Cache->get_value("subscriptions_user_$UserID");
|
148
|
|
- if ($UserSubscriptions === false) {
|
149
|
|
- G::$DB->query('
|
|
146
|
+ /**
|
|
147
|
+ * Read $UserID's subscriptions. If the cache key isn't set, it gets filled.
|
|
148
|
+ * If UserID == 0, G::$LoggedUser[ID] is used
|
|
149
|
+ * @param int $UserID
|
|
150
|
+ * @return array Array of TopicIDs
|
|
151
|
+ */
|
|
152
|
+ public static function get_subscriptions($UserID = 0)
|
|
153
|
+ {
|
|
154
|
+ if ($UserID == 0) {
|
|
155
|
+ $UserID = G::$LoggedUser['ID'];
|
|
156
|
+ }
|
|
157
|
+ $QueryID = G::$DB->get_query_id();
|
|
158
|
+ $UserSubscriptions = G::$Cache->get_value("subscriptions_user_$UserID");
|
|
159
|
+ if ($UserSubscriptions === false) {
|
|
160
|
+ G::$DB->query('
|
150
|
161
|
SELECT TopicID
|
151
|
162
|
FROM users_subscriptions
|
152
|
163
|
WHERE UserID = ' . db_string($UserID));
|
153
|
|
- $UserSubscriptions = G::$DB->collect(0);
|
154
|
|
- G::$Cache->cache_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
|
|
164
|
+ $UserSubscriptions = G::$DB->collect(0);
|
|
165
|
+ G::$Cache->cache_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
|
|
166
|
+ }
|
|
167
|
+ G::$DB->set_query_id($QueryID);
|
|
168
|
+ return $UserSubscriptions;
|
155
|
169
|
}
|
156
|
|
- G::$DB->set_query_id($QueryID);
|
157
|
|
- return $UserSubscriptions;
|
158
|
|
- }
|
159
|
170
|
|
160
|
|
- /**
|
161
|
|
- * Same as self::get_subscriptions, but for comment subscriptions
|
162
|
|
- * @param int $UserID
|
163
|
|
- * @return array Array of ($Page, $PageID)
|
164
|
|
- */
|
165
|
|
- public static function get_comment_subscriptions($UserID = 0) {
|
166
|
|
- if ($UserID == 0) {
|
167
|
|
- $UserID = G::$LoggedUser['ID'];
|
168
|
|
- }
|
169
|
|
- $QueryID = G::$DB->get_query_id();
|
170
|
|
- $UserCommentSubscriptions = G::$Cache->get_value("subscriptions_comments_user_$UserID");
|
171
|
|
- if ($UserCommentSubscriptions === false) {
|
172
|
|
- G::$DB->query('
|
|
171
|
+ /**
|
|
172
|
+ * Same as self::get_subscriptions, but for comment subscriptions
|
|
173
|
+ * @param int $UserID
|
|
174
|
+ * @return array Array of ($Page, $PageID)
|
|
175
|
+ */
|
|
176
|
+ public static function get_comment_subscriptions($UserID = 0)
|
|
177
|
+ {
|
|
178
|
+ if ($UserID == 0) {
|
|
179
|
+ $UserID = G::$LoggedUser['ID'];
|
|
180
|
+ }
|
|
181
|
+ $QueryID = G::$DB->get_query_id();
|
|
182
|
+ $UserCommentSubscriptions = G::$Cache->get_value("subscriptions_comments_user_$UserID");
|
|
183
|
+ if ($UserCommentSubscriptions === false) {
|
|
184
|
+ G::$DB->query('
|
173
|
185
|
SELECT Page, PageID
|
174
|
186
|
FROM users_subscriptions_comments
|
175
|
187
|
WHERE UserID = ' . db_string($UserID));
|
176
|
|
- $UserCommentSubscriptions = G::$DB->to_array(false, MYSQLI_NUM);
|
177
|
|
- G::$Cache->cache_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
|
|
188
|
+ $UserCommentSubscriptions = G::$DB->to_array(false, MYSQLI_NUM);
|
|
189
|
+ G::$Cache->cache_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
|
|
190
|
+ }
|
|
191
|
+ G::$DB->set_query_id($QueryID);
|
|
192
|
+ return $UserCommentSubscriptions;
|
178
|
193
|
}
|
179
|
|
- G::$DB->set_query_id($QueryID);
|
180
|
|
- return $UserCommentSubscriptions;
|
181
|
|
- }
|
182
|
194
|
|
183
|
|
- /**
|
184
|
|
- * Returns whether or not the current user has new subscriptions. This handles both forum and comment subscriptions.
|
185
|
|
- * @return int Number of unread subscribed threads/comments
|
186
|
|
- */
|
187
|
|
- public static function has_new_subscriptions() {
|
188
|
|
- $QueryID = G::$DB->get_query_id();
|
|
195
|
+ /**
|
|
196
|
+ * Returns whether or not the current user has new subscriptions. This handles both forum and comment subscriptions.
|
|
197
|
+ * @return int Number of unread subscribed threads/comments
|
|
198
|
+ */
|
|
199
|
+ public static function has_new_subscriptions()
|
|
200
|
+ {
|
|
201
|
+ $QueryID = G::$DB->get_query_id();
|
189
|
202
|
|
190
|
|
- $NewSubscriptions = G::$Cache->get_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
|
191
|
|
- if ($NewSubscriptions === false) {
|
192
|
|
- // forum subscriptions
|
193
|
|
- G::$DB->query("
|
|
203
|
+ $NewSubscriptions = G::$Cache->get_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
|
|
204
|
+ if ($NewSubscriptions === false) {
|
|
205
|
+ // forum subscriptions
|
|
206
|
+ G::$DB->query("
|
194
|
207
|
SELECT COUNT(1)
|
195
|
208
|
FROM users_subscriptions AS s
|
196
|
209
|
LEFT JOIN forums_last_read_topics AS l ON l.UserID = s.UserID AND l.TopicID = s.TopicID
|
|
@@ -199,10 +212,10 @@ class Subscriptions {
|
199
|
212
|
WHERE " . Forums::user_forums_sql() . "
|
200
|
213
|
AND IF(t.IsLocked = '1' AND t.IsSticky = '0'" . ", t.LastPostID, IF(l.PostID IS NULL, 0, l.PostID)) < t.LastPostID
|
201
|
214
|
AND s.UserID = " . G::$LoggedUser['ID']);
|
202
|
|
- list($NewForumSubscriptions) = G::$DB->next_record();
|
|
215
|
+ list($NewForumSubscriptions) = G::$DB->next_record();
|
203
|
216
|
|
204
|
|
- // comment subscriptions
|
205
|
|
- G::$DB->query("
|
|
217
|
+ // comment subscriptions
|
|
218
|
+ G::$DB->query("
|
206
|
219
|
SELECT COUNT(1)
|
207
|
220
|
FROM users_subscriptions_comments AS s
|
208
|
221
|
LEFT JOIN users_comments_last_read AS lr ON lr.UserID = s.UserID AND lr.Page = s.Page AND lr.PageID = s.PageID
|
|
@@ -211,23 +224,24 @@ class Subscriptions {
|
211
|
224
|
WHERE s.UserID = " . G::$LoggedUser['ID'] . "
|
212
|
225
|
AND (s.Page != 'collages' OR co.Deleted = '0')
|
213
|
226
|
AND IF(lr.PostID IS NULL, 0, lr.PostID) < c.ID");
|
214
|
|
- list($NewCommentSubscriptions) = G::$DB->next_record();
|
|
227
|
+ list($NewCommentSubscriptions) = G::$DB->next_record();
|
215
|
228
|
|
216
|
|
- $NewSubscriptions = $NewForumSubscriptions + $NewCommentSubscriptions;
|
217
|
|
- G::$Cache->cache_value('subscriptions_user_new_' . G::$LoggedUser['ID'], $NewSubscriptions, 0);
|
|
229
|
+ $NewSubscriptions = $NewForumSubscriptions + $NewCommentSubscriptions;
|
|
230
|
+ G::$Cache->cache_value('subscriptions_user_new_' . G::$LoggedUser['ID'], $NewSubscriptions, 0);
|
|
231
|
+ }
|
|
232
|
+ G::$DB->set_query_id($QueryID);
|
|
233
|
+ return (int)$NewSubscriptions;
|
218
|
234
|
}
|
219
|
|
- G::$DB->set_query_id($QueryID);
|
220
|
|
- return (int)$NewSubscriptions;
|
221
|
|
- }
|
222
|
235
|
|
223
|
|
- /**
|
224
|
|
- * Returns whether or not the current user has new quote notifications.
|
225
|
|
- * @return int Number of unread quote notifications
|
226
|
|
- */
|
227
|
|
- public static function has_new_quote_notifications() {
|
228
|
|
- $QuoteNotificationsCount = G::$Cache->get_value('notify_quoted_' . G::$LoggedUser['ID']);
|
229
|
|
- if ($QuoteNotificationsCount === false) {
|
230
|
|
- $sql = "
|
|
236
|
+ /**
|
|
237
|
+ * Returns whether or not the current user has new quote notifications.
|
|
238
|
+ * @return int Number of unread quote notifications
|
|
239
|
+ */
|
|
240
|
+ public static function has_new_quote_notifications()
|
|
241
|
+ {
|
|
242
|
+ $QuoteNotificationsCount = G::$Cache->get_value('notify_quoted_' . G::$LoggedUser['ID']);
|
|
243
|
+ if ($QuoteNotificationsCount === false) {
|
|
244
|
+ $sql = "
|
231
|
245
|
SELECT COUNT(1)
|
232
|
246
|
FROM users_notify_quoted AS q
|
233
|
247
|
LEFT JOIN forums_topics AS t ON t.ID = q.PageID
|
|
@@ -237,166 +251,171 @@ class Subscriptions {
|
237
|
251
|
AND q.UnRead
|
238
|
252
|
AND (q.Page != 'forums' OR " . Forums::user_forums_sql() . ")
|
239
|
253
|
AND (q.Page != 'collages' OR c.Deleted = '0')";
|
240
|
|
- $QueryID = G::$DB->get_query_id();
|
241
|
|
- G::$DB->query($sql);
|
242
|
|
- list($QuoteNotificationsCount) = G::$DB->next_record();
|
243
|
|
- G::$DB->set_query_id($QueryID);
|
244
|
|
- G::$Cache->cache_value('notify_quoted_' . G::$LoggedUser['ID'], $QuoteNotificationsCount, 0);
|
|
254
|
+ $QueryID = G::$DB->get_query_id();
|
|
255
|
+ G::$DB->query($sql);
|
|
256
|
+ list($QuoteNotificationsCount) = G::$DB->next_record();
|
|
257
|
+ G::$DB->set_query_id($QueryID);
|
|
258
|
+ G::$Cache->cache_value('notify_quoted_' . G::$LoggedUser['ID'], $QuoteNotificationsCount, 0);
|
|
259
|
+ }
|
|
260
|
+ return (int)$QuoteNotificationsCount;
|
245
|
261
|
}
|
246
|
|
- return (int)$QuoteNotificationsCount;
|
247
|
|
- }
|
248
|
262
|
|
249
|
|
- /**
|
250
|
|
- * Returns the key which holds this $TopicID in the subscription array.
|
251
|
|
- * Use type-aware comparison operators with this! (ie. if (self::has_subscribed($TopicID) !== false) { ... })
|
252
|
|
- * @param int $TopicID
|
253
|
|
- * @return bool|int
|
254
|
|
- */
|
255
|
|
- public static function has_subscribed($TopicID) {
|
256
|
|
- $UserSubscriptions = self::get_subscriptions();
|
257
|
|
- return array_search($TopicID, $UserSubscriptions);
|
258
|
|
- }
|
|
263
|
+ /**
|
|
264
|
+ * Returns the key which holds this $TopicID in the subscription array.
|
|
265
|
+ * Use type-aware comparison operators with this! (ie. if (self::has_subscribed($TopicID) !== false) { ... })
|
|
266
|
+ * @param int $TopicID
|
|
267
|
+ * @return bool|int
|
|
268
|
+ */
|
|
269
|
+ public static function has_subscribed($TopicID)
|
|
270
|
+ {
|
|
271
|
+ $UserSubscriptions = self::get_subscriptions();
|
|
272
|
+ return array_search($TopicID, $UserSubscriptions);
|
|
273
|
+ }
|
259
|
274
|
|
260
|
|
- /**
|
261
|
|
- * Same as has_subscribed, but for comment subscriptions.
|
262
|
|
- * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
|
263
|
|
- * @param int $PageID
|
264
|
|
- * @return bool|int
|
265
|
|
- */
|
266
|
|
- public static function has_subscribed_comments($Page, $PageID) {
|
267
|
|
- $UserCommentSubscriptions = self::get_comment_subscriptions();
|
268
|
|
- return array_search(array($Page, $PageID), $UserCommentSubscriptions);
|
269
|
|
- }
|
|
275
|
+ /**
|
|
276
|
+ * Same as has_subscribed, but for comment subscriptions.
|
|
277
|
+ * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
|
|
278
|
+ * @param int $PageID
|
|
279
|
+ * @return bool|int
|
|
280
|
+ */
|
|
281
|
+ public static function has_subscribed_comments($Page, $PageID)
|
|
282
|
+ {
|
|
283
|
+ $UserCommentSubscriptions = self::get_comment_subscriptions();
|
|
284
|
+ return array_search(array($Page, $PageID), $UserCommentSubscriptions);
|
|
285
|
+ }
|
270
|
286
|
|
271
|
|
- /**
|
272
|
|
- * Clear the subscription cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
|
273
|
|
- * @param type $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
|
274
|
|
- * @param type $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
|
275
|
|
- */
|
276
|
|
- public static function flush_subscriptions($Page, $PageID) {
|
277
|
|
- $QueryID = G::$DB->get_query_id();
|
278
|
|
- if ($Page == 'forums') {
|
279
|
|
- G::$DB->query("
|
|
287
|
+ /**
|
|
288
|
+ * Clear the subscription cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
|
|
289
|
+ * @param type $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
|
|
290
|
+ * @param type $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
|
|
291
|
+ */
|
|
292
|
+ public static function flush_subscriptions($Page, $PageID)
|
|
293
|
+ {
|
|
294
|
+ $QueryID = G::$DB->get_query_id();
|
|
295
|
+ if ($Page == 'forums') {
|
|
296
|
+ G::$DB->query("
|
280
|
297
|
SELECT UserID
|
281
|
298
|
FROM users_subscriptions
|
282
|
299
|
WHERE TopicID = '$PageID'");
|
283
|
|
- } else {
|
284
|
|
- G::$DB->query("
|
|
300
|
+ } else {
|
|
301
|
+ G::$DB->query("
|
285
|
302
|
SELECT UserID
|
286
|
303
|
FROM users_subscriptions_comments
|
287
|
304
|
WHERE Page = '$Page'
|
288
|
305
|
AND PageID = '$PageID'");
|
|
306
|
+ }
|
|
307
|
+ $Subscribers = G::$DB->collect('UserID');
|
|
308
|
+ foreach ($Subscribers as $Subscriber) {
|
|
309
|
+ G::$Cache->delete_value("subscriptions_user_new_$Subscriber");
|
|
310
|
+ }
|
|
311
|
+ G::$DB->set_query_id($QueryID);
|
289
|
312
|
}
|
290
|
|
- $Subscribers = G::$DB->collect('UserID');
|
291
|
|
- foreach ($Subscribers as $Subscriber) {
|
292
|
|
- G::$Cache->delete_value("subscriptions_user_new_$Subscriber");
|
293
|
|
- }
|
294
|
|
- G::$DB->set_query_id($QueryID);
|
295
|
|
- }
|
296
|
313
|
|
297
|
|
- /**
|
298
|
|
- * Move all $Page subscriptions from $OldPageID to $NewPageID (for example when merging torrent groups).
|
299
|
|
- * Passing $NewPageID = null will delete the subscriptions.
|
300
|
|
- * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
|
301
|
|
- * @param int $OldPageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
|
302
|
|
- * @param int|null $NewPageID As $OldPageID, or null to delete the subscriptions
|
303
|
|
- */
|
304
|
|
- public static function move_subscriptions($Page, $OldPageID, $NewPageID) {
|
305
|
|
- self::flush_subscriptions($Page, $OldPageID);
|
306
|
|
- $QueryID = G::$DB->get_query_id();
|
307
|
|
- if ($Page == 'forums') {
|
308
|
|
- if ($NewPageID !== null) {
|
309
|
|
- G::$DB->query("
|
|
314
|
+ /**
|
|
315
|
+ * Move all $Page subscriptions from $OldPageID to $NewPageID (for example when merging torrent groups).
|
|
316
|
+ * Passing $NewPageID = null will delete the subscriptions.
|
|
317
|
+ * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
|
|
318
|
+ * @param int $OldPageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
|
|
319
|
+ * @param int|null $NewPageID As $OldPageID, or null to delete the subscriptions
|
|
320
|
+ */
|
|
321
|
+ public static function move_subscriptions($Page, $OldPageID, $NewPageID)
|
|
322
|
+ {
|
|
323
|
+ self::flush_subscriptions($Page, $OldPageID);
|
|
324
|
+ $QueryID = G::$DB->get_query_id();
|
|
325
|
+ if ($Page == 'forums') {
|
|
326
|
+ if ($NewPageID !== null) {
|
|
327
|
+ G::$DB->query("
|
310
|
328
|
UPDATE IGNORE users_subscriptions
|
311
|
329
|
SET TopicID = '$NewPageID'
|
312
|
330
|
WHERE TopicID = '$OldPageID'");
|
313
|
|
- // explanation see below
|
314
|
|
- G::$DB->query("
|
|
331
|
+ // explanation see below
|
|
332
|
+ G::$DB->query("
|
315
|
333
|
UPDATE IGNORE forums_last_read_topics
|
316
|
334
|
SET TopicID = $NewPageID
|
317
|
335
|
WHERE TopicID = $OldPageID");
|
318
|
|
- G::$DB->query("
|
|
336
|
+ G::$DB->query("
|
319
|
337
|
SELECT UserID, MIN(PostID)
|
320
|
338
|
FROM forums_last_read_topics
|
321
|
339
|
WHERE TopicID IN ($OldPageID, $NewPageID)
|
322
|
340
|
GROUP BY UserID
|
323
|
341
|
HAVING COUNT(1) = 2");
|
324
|
|
- $Results = G::$DB->to_array(false, MYSQLI_NUM);
|
325
|
|
- foreach ($Results as $Result) {
|
326
|
|
- G::$DB->query("
|
|
342
|
+ $Results = G::$DB->to_array(false, MYSQLI_NUM);
|
|
343
|
+ foreach ($Results as $Result) {
|
|
344
|
+ G::$DB->query("
|
327
|
345
|
UPDATE forums_last_read_topics
|
328
|
346
|
SET PostID = $Result[1]
|
329
|
347
|
WHERE TopicID = $NewPageID
|
330
|
348
|
AND UserID = $Result[0]");
|
331
|
|
- }
|
332
|
|
- }
|
333
|
|
- G::$DB->query("
|
|
349
|
+ }
|
|
350
|
+ }
|
|
351
|
+ G::$DB->query("
|
334
|
352
|
DELETE FROM users_subscriptions
|
335
|
353
|
WHERE TopicID = '$OldPageID'");
|
336
|
|
- G::$DB->query("
|
|
354
|
+ G::$DB->query("
|
337
|
355
|
DELETE FROM forums_last_read_topics
|
338
|
356
|
WHERE TopicID = $OldPageID");
|
339
|
|
- } else {
|
340
|
|
- if ($NewPageID !== null) {
|
341
|
|
- G::$DB->query("
|
|
357
|
+ } else {
|
|
358
|
+ if ($NewPageID !== null) {
|
|
359
|
+ G::$DB->query("
|
342
|
360
|
UPDATE IGNORE users_subscriptions_comments
|
343
|
361
|
SET PageID = '$NewPageID'
|
344
|
362
|
WHERE Page = '$Page'
|
345
|
363
|
AND PageID = '$OldPageID'");
|
346
|
|
- // last read handling
|
347
|
|
- // 1) update all rows that have no key collisions (i.e. users that haven't previously read both pages or if there are only comments on one page)
|
348
|
|
- G::$DB->query("
|
|
364
|
+ // last read handling
|
|
365
|
+ // 1) update all rows that have no key collisions (i.e. users that haven't previously read both pages or if there are only comments on one page)
|
|
366
|
+ G::$DB->query("
|
349
|
367
|
UPDATE IGNORE users_comments_last_read
|
350
|
368
|
SET PageID = '$NewPageID'
|
351
|
369
|
WHERE Page = '$Page'
|
352
|
370
|
AND PageID = $OldPageID");
|
353
|
|
- // 2) get all last read records with key collisions (i.e. there are records for one user for both PageIDs)
|
354
|
|
- G::$DB->query("
|
|
371
|
+ // 2) get all last read records with key collisions (i.e. there are records for one user for both PageIDs)
|
|
372
|
+ G::$DB->query("
|
355
|
373
|
SELECT UserID, MIN(PostID)
|
356
|
374
|
FROM users_comments_last_read
|
357
|
375
|
WHERE Page = '$Page'
|
358
|
376
|
AND PageID IN ($OldPageID, $NewPageID)
|
359
|
377
|
GROUP BY UserID
|
360
|
378
|
HAVING COUNT(1) = 2");
|
361
|
|
- $Results = G::$DB->to_array(false, MYSQLI_NUM);
|
362
|
|
- // 3) update rows for those people found in 2) to the earlier post
|
363
|
|
- foreach ($Results as $Result) {
|
364
|
|
- G::$DB->query("
|
|
379
|
+ $Results = G::$DB->to_array(false, MYSQLI_NUM);
|
|
380
|
+ // 3) update rows for those people found in 2) to the earlier post
|
|
381
|
+ foreach ($Results as $Result) {
|
|
382
|
+ G::$DB->query("
|
365
|
383
|
UPDATE users_comments_last_read
|
366
|
384
|
SET PostID = $Result[1]
|
367
|
385
|
WHERE Page = '$Page'
|
368
|
386
|
AND PageID = $NewPageID
|
369
|
387
|
AND UserID = $Result[0]");
|
370
|
|
- }
|
371
|
|
- }
|
372
|
|
- G::$DB->query("
|
|
388
|
+ }
|
|
389
|
+ }
|
|
390
|
+ G::$DB->query("
|
373
|
391
|
DELETE FROM users_subscriptions_comments
|
374
|
392
|
WHERE Page = '$Page'
|
375
|
393
|
AND PageID = '$OldPageID'");
|
376
|
|
- G::$DB->query("
|
|
394
|
+ G::$DB->query("
|
377
|
395
|
DELETE FROM users_comments_last_read
|
378
|
396
|
WHERE Page = '$Page'
|
379
|
397
|
AND PageID = '$OldPageID'");
|
|
398
|
+ }
|
|
399
|
+ G::$DB->set_query_id($QueryID);
|
380
|
400
|
}
|
381
|
|
- G::$DB->set_query_id($QueryID);
|
382
|
|
- }
|
383
|
401
|
|
384
|
|
- /**
|
385
|
|
- * Clear the quote notification cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
|
386
|
|
- * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
|
387
|
|
- * @param int $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
|
388
|
|
- */
|
389
|
|
- public static function flush_quote_notifications($Page, $PageID) {
|
390
|
|
- $QueryID = G::$DB->get_query_id();
|
391
|
|
- G::$DB->query("
|
|
402
|
+ /**
|
|
403
|
+ * Clear the quote notification cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
|
|
404
|
+ * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
|
|
405
|
+ * @param int $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
|
|
406
|
+ */
|
|
407
|
+ public static function flush_quote_notifications($Page, $PageID)
|
|
408
|
+ {
|
|
409
|
+ $QueryID = G::$DB->get_query_id();
|
|
410
|
+ G::$DB->query("
|
392
|
411
|
SELECT UserID
|
393
|
412
|
FROM users_notify_quoted
|
394
|
413
|
WHERE Page = '$Page'
|
395
|
414
|
AND PageID = $PageID");
|
396
|
|
- $Subscribers = G::$DB->collect('UserID');
|
397
|
|
- foreach ($Subscribers as $Subscriber) {
|
398
|
|
- G::$Cache->delete_value("notify_quoted_$Subscriber");
|
|
415
|
+ $Subscribers = G::$DB->collect('UserID');
|
|
416
|
+ foreach ($Subscribers as $Subscriber) {
|
|
417
|
+ G::$Cache->delete_value("notify_quoted_$Subscriber");
|
|
418
|
+ }
|
|
419
|
+ G::$DB->set_query_id($QueryID);
|
399
|
420
|
}
|
400
|
|
- G::$DB->set_query_id($QueryID);
|
401
|
|
- }
|
402
|
421
|
}
|