|
@@ -1,21 +1,23 @@
|
1
|
|
-<?
|
2
|
|
-class Comments {
|
3
|
|
- /*
|
4
|
|
- * For all functions:
|
5
|
|
- * $Page = 'artist', 'collages', 'requests' or 'torrents'
|
6
|
|
- * $PageID = ArtistID, CollageID, RequestID or GroupID, respectively
|
7
|
|
- */
|
8
|
|
-
|
9
|
|
- /**
|
10
|
|
- * Post a comment on an artist, request or torrent page.
|
11
|
|
- * @param string $Page
|
12
|
|
- * @param int $PageID
|
13
|
|
- * @param string $Body
|
14
|
|
- * @return int ID of the new comment
|
15
|
|
- */
|
16
|
|
- public static function post($Page, $PageID, $Body) {
|
17
|
|
- $QueryID = G::$DB->get_query_id();
|
18
|
|
- G::$DB->query("
|
|
1
|
+<?php
|
|
2
|
+class Comments
|
|
3
|
+{
|
|
4
|
+ /*
|
|
5
|
+ * For all functions:
|
|
6
|
+ * $Page = 'artist', 'collages', 'requests' or 'torrents'
|
|
7
|
+ * $PageID = ArtistID, CollageID, RequestID or GroupID, respectively
|
|
8
|
+ */
|
|
9
|
+
|
|
10
|
+ /**
|
|
11
|
+ * Post a comment on an artist, request or torrent page.
|
|
12
|
+ * @param string $Page
|
|
13
|
+ * @param int $PageID
|
|
14
|
+ * @param string $Body
|
|
15
|
+ * @return int ID of the new comment
|
|
16
|
+ */
|
|
17
|
+ public static function post($Page, $PageID, $Body)
|
|
18
|
+ {
|
|
19
|
+ $QueryID = G::$DB->get_query_id();
|
|
20
|
+ G::$DB->query("
|
19
|
21
|
SELECT
|
20
|
22
|
CEIL(
|
21
|
23
|
(
|
|
@@ -25,36 +27,37 @@ class Comments {
|
25
|
27
|
AND PageID = $PageID
|
26
|
28
|
) / " . TORRENT_COMMENTS_PER_PAGE . "
|
27
|
29
|
) AS Pages");
|
28
|
|
- list($Pages) = G::$DB->next_record();
|
|
30
|
+ list($Pages) = G::$DB->next_record();
|
29
|
31
|
|
30
|
|
- G::$DB->query("
|
|
32
|
+ G::$DB->query("
|
31
|
33
|
INSERT INTO comments (Page, PageID, AuthorID, AddedTime, Body)
|
32
|
34
|
VALUES ('$Page', $PageID, " . G::$LoggedUser['ID'] . ", NOW(), '" . db_string($Body) . "')");
|
33
|
|
- $PostID = G::$DB->inserted_id();
|
|
35
|
+ $PostID = G::$DB->inserted_id();
|
34
|
36
|
|
35
|
|
- $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Pages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
36
|
|
- G::$Cache->delete_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID);
|
37
|
|
- G::$Cache->delete_value($Page.'_comments_'.$PageID);
|
|
37
|
+ $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Pages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
38
|
+ G::$Cache->delete_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID);
|
|
39
|
+ G::$Cache->delete_value($Page.'_comments_'.$PageID);
|
38
|
40
|
|
39
|
|
- Subscriptions::flush_subscriptions($Page, $PageID);
|
40
|
|
- Subscriptions::quote_notify($Body, $PostID, $Page, $PageID);
|
|
41
|
+ Subscriptions::flush_subscriptions($Page, $PageID);
|
|
42
|
+ Subscriptions::quote_notify($Body, $PostID, $Page, $PageID);
|
41
|
43
|
|
42
|
|
- G::$DB->set_query_id($QueryID);
|
|
44
|
+ G::$DB->set_query_id($QueryID);
|
43
|
45
|
|
44
|
|
- return $PostID;
|
45
|
|
- }
|
|
46
|
+ return $PostID;
|
|
47
|
+ }
|
46
|
48
|
|
47
|
|
- /**
|
48
|
|
- * Edit a comment
|
49
|
|
- * @param int $PostID
|
50
|
|
- * @param string $NewBody
|
51
|
|
- * @param bool $SendPM If true, send a PM to the author of the comment informing him about the edit
|
52
|
|
- * @todo move permission check out of here/remove hardcoded error(404)
|
53
|
|
- */
|
54
|
|
- public static function edit($PostID, $NewBody, $SendPM = false) {
|
55
|
|
- $QueryID = G::$DB->get_query_id();
|
|
49
|
+ /**
|
|
50
|
+ * Edit a comment
|
|
51
|
+ * @param int $PostID
|
|
52
|
+ * @param string $NewBody
|
|
53
|
+ * @param bool $SendPM If true, send a PM to the author of the comment informing him about the edit
|
|
54
|
+ * @todo move permission check out of here/remove hardcoded error(404)
|
|
55
|
+ */
|
|
56
|
+ public static function edit($PostID, $NewBody, $SendPM = false)
|
|
57
|
+ {
|
|
58
|
+ $QueryID = G::$DB->get_query_id();
|
56
|
59
|
|
57
|
|
- G::$DB->query("
|
|
60
|
+ G::$DB->query("
|
58
|
61
|
SELECT
|
59
|
62
|
Body,
|
60
|
63
|
AuthorID,
|
|
@@ -63,25 +66,25 @@ class Comments {
|
63
|
66
|
AddedTime
|
64
|
67
|
FROM comments
|
65
|
68
|
WHERE ID = $PostID");
|
66
|
|
- if (!G::$DB->has_results()) {
|
67
|
|
- return false;
|
68
|
|
- }
|
69
|
|
- list($OldBody, $AuthorID, $Page, $PageID, $AddedTime) = G::$DB->next_record();
|
|
69
|
+ if (!G::$DB->has_results()) {
|
|
70
|
+ return false;
|
|
71
|
+ }
|
|
72
|
+ list($OldBody, $AuthorID, $Page, $PageID, $AddedTime) = G::$DB->next_record();
|
70
|
73
|
|
71
|
|
- if (G::$LoggedUser['ID'] != $AuthorID && !check_perms('site_moderate_forums')) {
|
72
|
|
- return false;
|
73
|
|
- }
|
|
74
|
+ if (G::$LoggedUser['ID'] != $AuthorID && !check_perms('site_moderate_forums')) {
|
|
75
|
+ return false;
|
|
76
|
+ }
|
74
|
77
|
|
75
|
|
- G::$DB->query("
|
|
78
|
+ G::$DB->query("
|
76
|
79
|
SELECT CEIL(COUNT(ID) / " . TORRENT_COMMENTS_PER_PAGE . ") AS Page
|
77
|
80
|
FROM comments
|
78
|
81
|
WHERE Page = '$Page'
|
79
|
82
|
AND PageID = $PageID
|
80
|
83
|
AND ID <= $PostID");
|
81
|
|
- list($CommPage) = G::$DB->next_record();
|
|
84
|
+ list($CommPage) = G::$DB->next_record();
|
82
|
85
|
|
83
|
|
- // Perform the update
|
84
|
|
- G::$DB->query("
|
|
86
|
+ // Perform the update
|
|
87
|
+ G::$DB->query("
|
85
|
88
|
UPDATE comments
|
86
|
89
|
SET
|
87
|
90
|
Body = '" . db_string($NewBody) . "',
|
|
@@ -89,49 +92,50 @@ class Comments {
|
89
|
92
|
EditedTime = NOW()
|
90
|
93
|
WHERE ID = $PostID");
|
91
|
94
|
|
92
|
|
- // Update the cache
|
93
|
|
- $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $CommPage - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
94
|
|
- G::$Cache->delete_value($Page . '_comments_' . $PageID . '_catalogue_' . $CatalogueID);
|
|
95
|
+ // Update the cache
|
|
96
|
+ $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $CommPage - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
97
|
+ G::$Cache->delete_value($Page . '_comments_' . $PageID . '_catalogue_' . $CatalogueID);
|
95
|
98
|
|
96
|
|
- if ($Page == 'collages') {
|
97
|
|
- // On collages, we also need to clear the collage key (collage_$CollageID), because it has the comments in it... (why??)
|
98
|
|
- G::$Cache->delete_value('collage_' . $PageID);
|
99
|
|
- }
|
|
99
|
+ if ($Page == 'collages') {
|
|
100
|
+ // On collages, we also need to clear the collage key (collage_$CollageID), because it has the comments in it... (why??)
|
|
101
|
+ G::$Cache->delete_value('collage_' . $PageID);
|
|
102
|
+ }
|
100
|
103
|
|
101
|
|
- G::$DB->query("
|
|
104
|
+ G::$DB->query("
|
102
|
105
|
INSERT INTO comments_edits (Page, PostID, EditUser, EditTime, Body)
|
103
|
106
|
VALUES ('$Page', $PostID, " . G::$LoggedUser['ID'] . ", NOW(), '" . db_string($OldBody) . "')");
|
104
|
107
|
|
105
|
|
- G::$DB->set_query_id($QueryID);
|
|
108
|
+ G::$DB->set_query_id($QueryID);
|
106
|
109
|
|
107
|
|
- if ($SendPM && G::$LoggedUser['ID'] != $AuthorID) {
|
108
|
|
- // Send a PM to the user to notify them of the edit
|
109
|
|
- $PMSubject = "Your comment #$PostID has been edited";
|
110
|
|
- $PMurl = site_url()."comments.php?action=jump&postid=$PostID";
|
111
|
|
- $ProfLink = '[url='.site_url().'user.php?id='.G::$LoggedUser['ID'].']'.G::$LoggedUser['Username'].'[/url]';
|
112
|
|
- $PMBody = "One of your comments has been edited by $ProfLink: [url]{$PMurl}[/url]";
|
113
|
|
- Misc::send_pm($AuthorID, 0, $PMSubject, $PMBody);
|
114
|
|
- }
|
|
110
|
+ if ($SendPM && G::$LoggedUser['ID'] != $AuthorID) {
|
|
111
|
+ // Send a PM to the user to notify them of the edit
|
|
112
|
+ $PMSubject = "Your comment #$PostID has been edited";
|
|
113
|
+ $PMurl = site_url()."comments.php?action=jump&postid=$PostID";
|
|
114
|
+ $ProfLink = '[url='.site_url().'user.php?id='.G::$LoggedUser['ID'].']'.G::$LoggedUser['Username'].'[/url]';
|
|
115
|
+ $PMBody = "One of your comments has been edited by $ProfLink: [url]{$PMurl}[/url]";
|
|
116
|
+ Misc::send_pm($AuthorID, 0, $PMSubject, $PMBody);
|
|
117
|
+ }
|
115
|
118
|
|
116
|
|
- return true; // TODO: this should reflect whether or not the update was actually successful, e.g. by checking G::$DB->affected_rows after the UPDATE query
|
117
|
|
- }
|
118
|
|
-
|
119
|
|
- /**
|
120
|
|
- * Delete a comment
|
121
|
|
- * @param int $PostID
|
122
|
|
- */
|
123
|
|
- public static function delete($PostID) {
|
124
|
|
- $QueryID = G::$DB->get_query_id();
|
125
|
|
- // Get page, pageid
|
126
|
|
- G::$DB->query("SELECT Page, PageID FROM comments WHERE ID = $PostID");
|
127
|
|
- if (!G::$DB->has_results()) {
|
128
|
|
- // no such comment?
|
129
|
|
- G::$DB->set_query_id($QueryID);
|
130
|
|
- return false;
|
|
119
|
+ return true; // TODO: this should reflect whether or not the update was actually successful, e.g. by checking G::$DB->affected_rows after the UPDATE query
|
131
|
120
|
}
|
132
|
|
- list ($Page, $PageID) = G::$DB->next_record();
|
133
|
|
- // get number of pages
|
134
|
|
- G::$DB->query("
|
|
121
|
+
|
|
122
|
+ /**
|
|
123
|
+ * Delete a comment
|
|
124
|
+ * @param int $PostID
|
|
125
|
+ */
|
|
126
|
+ public static function delete($PostID)
|
|
127
|
+ {
|
|
128
|
+ $QueryID = G::$DB->get_query_id();
|
|
129
|
+ // Get page, pageid
|
|
130
|
+ G::$DB->query("SELECT Page, PageID FROM comments WHERE ID = $PostID");
|
|
131
|
+ if (!G::$DB->has_results()) {
|
|
132
|
+ // no such comment?
|
|
133
|
+ G::$DB->set_query_id($QueryID);
|
|
134
|
+ return false;
|
|
135
|
+ }
|
|
136
|
+ list($Page, $PageID) = G::$DB->next_record();
|
|
137
|
+ // get number of pages
|
|
138
|
+ G::$DB->query("
|
135
|
139
|
SELECT
|
136
|
140
|
CEIL(COUNT(ID) / " . TORRENT_COMMENTS_PER_PAGE . ") AS Pages,
|
137
|
141
|
CEIL(SUM(IF(ID <= $PostID, 1, 0)) / " . TORRENT_COMMENTS_PER_PAGE . ") AS Page
|
|
@@ -139,148 +143,151 @@ class Comments {
|
139
|
143
|
WHERE Page = '$Page'
|
140
|
144
|
AND PageID = $PageID
|
141
|
145
|
GROUP BY PageID");
|
142
|
|
- if (!G::$DB->has_results()) {
|
143
|
|
- // the comment $PostID was probably not posted on $Page
|
144
|
|
- G::$DB->set_query_id($QueryID);
|
145
|
|
- return false;
|
146
|
|
- }
|
147
|
|
- list($CommPages, $CommPage) = G::$DB->next_record();
|
|
146
|
+ if (!G::$DB->has_results()) {
|
|
147
|
+ // the comment $PostID was probably not posted on $Page
|
|
148
|
+ G::$DB->set_query_id($QueryID);
|
|
149
|
+ return false;
|
|
150
|
+ }
|
|
151
|
+ list($CommPages, $CommPage) = G::$DB->next_record();
|
148
|
152
|
|
149
|
|
- // $CommPages = number of pages in the thread
|
150
|
|
- // $CommPage = which page the post is on
|
151
|
|
- // These are set for cache clearing.
|
|
153
|
+ // $CommPages = number of pages in the thread
|
|
154
|
+ // $CommPage = which page the post is on
|
|
155
|
+ // These are set for cache clearing.
|
152
|
156
|
|
153
|
|
- G::$DB->query("
|
|
157
|
+ G::$DB->query("
|
154
|
158
|
DELETE FROM comments
|
155
|
159
|
WHERE ID = $PostID");
|
156
|
|
- G::$DB->query("
|
|
160
|
+ G::$DB->query("
|
157
|
161
|
DELETE FROM comments_edits
|
158
|
162
|
WHERE Page = '$Page'
|
159
|
163
|
AND PostID = $PostID");
|
160
|
164
|
|
161
|
|
- G::$DB->query("
|
|
165
|
+ G::$DB->query("
|
162
|
166
|
DELETE FROM users_notify_quoted
|
163
|
167
|
WHERE Page = '$Page'
|
164
|
168
|
AND PostID = $PostID");
|
165
|
169
|
|
166
|
|
- Subscriptions::flush_subscriptions($Page, $PageID);
|
167
|
|
- Subscriptions::flush_quote_notifications($Page, $PageID);
|
|
170
|
+ Subscriptions::flush_subscriptions($Page, $PageID);
|
|
171
|
+ Subscriptions::flush_quote_notifications($Page, $PageID);
|
168
|
172
|
|
169
|
|
- //We need to clear all subsequential catalogues as they've all been bumped with the absence of this post
|
170
|
|
- $ThisCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPage - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
171
|
|
- $LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
172
|
|
- for ($i = $ThisCatalogue; $i <= $LastCatalogue; ++$i) {
|
173
|
|
- G::$Cache->delete_value($Page . '_comments_' . $PageID . '_catalogue_' . $i);
|
174
|
|
- }
|
|
173
|
+ //We need to clear all subsequential catalogues as they've all been bumped with the absence of this post
|
|
174
|
+ $ThisCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPage - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
175
|
+ $LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
176
|
+ for ($i = $ThisCatalogue; $i <= $LastCatalogue; ++$i) {
|
|
177
|
+ G::$Cache->delete_value($Page . '_comments_' . $PageID . '_catalogue_' . $i);
|
|
178
|
+ }
|
175
|
179
|
|
176
|
|
- G::$Cache->delete_value($Page . '_comments_' . $PageID);
|
|
180
|
+ G::$Cache->delete_value($Page . '_comments_' . $PageID);
|
177
|
181
|
|
178
|
|
- if ($Page == 'collages') {
|
179
|
|
- // On collages, we also need to clear the collage key (collage_$CollageID), because it has the comments in it... (why??)
|
180
|
|
- G::$Cache->delete_value("collage_$PageID");
|
|
182
|
+ if ($Page == 'collages') {
|
|
183
|
+ // On collages, we also need to clear the collage key (collage_$CollageID), because it has the comments in it... (why??)
|
|
184
|
+ G::$Cache->delete_value("collage_$PageID");
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ G::$DB->set_query_id($QueryID);
|
|
188
|
+
|
|
189
|
+ return true;
|
181
|
190
|
}
|
182
|
191
|
|
183
|
|
- G::$DB->set_query_id($QueryID);
|
184
|
|
-
|
185
|
|
- return true;
|
186
|
|
- }
|
187
|
|
-
|
188
|
|
- /**
|
189
|
|
- * Get the URL to a comment, already knowing the Page and PostID
|
190
|
|
- * @param string $Page
|
191
|
|
- * @param int $PageID
|
192
|
|
- * @param int $PostID
|
193
|
|
- * @return string|bool The URL to the comment or false on error
|
194
|
|
- */
|
195
|
|
- public static function get_url($Page, $PageID, $PostID = null) {
|
196
|
|
- $Post = (!empty($PostID) ? "&postid=$PostID#post$PostID" : '');
|
197
|
|
- switch ($Page) {
|
198
|
|
- case 'artist':
|
199
|
|
- return "artist.php?id=$PageID$Post";
|
200
|
|
- case 'collages':
|
201
|
|
- return "collages.php?action=comments&collageid=$PageID$Post";
|
202
|
|
- case 'requests':
|
203
|
|
- return "requests.php?action=view&id=$PageID$Post";
|
204
|
|
- case 'torrents':
|
205
|
|
- return "torrents.php?id=$PageID$Post";
|
206
|
|
- default:
|
207
|
|
- return false;
|
|
192
|
+ /**
|
|
193
|
+ * Get the URL to a comment, already knowing the Page and PostID
|
|
194
|
+ * @param string $Page
|
|
195
|
+ * @param int $PageID
|
|
196
|
+ * @param int $PostID
|
|
197
|
+ * @return string|bool The URL to the comment or false on error
|
|
198
|
+ */
|
|
199
|
+ public static function get_url($Page, $PageID, $PostID = null)
|
|
200
|
+ {
|
|
201
|
+ $Post = (!empty($PostID) ? "&postid=$PostID#post$PostID" : '');
|
|
202
|
+ switch ($Page) {
|
|
203
|
+ case 'artist':
|
|
204
|
+ return "artist.php?id=$PageID$Post";
|
|
205
|
+ case 'collages':
|
|
206
|
+ return "collages.php?action=comments&collageid=$PageID$Post";
|
|
207
|
+ case 'requests':
|
|
208
|
+ return "requests.php?action=view&id=$PageID$Post";
|
|
209
|
+ case 'torrents':
|
|
210
|
+ return "torrents.php?id=$PageID$Post";
|
|
211
|
+ default:
|
|
212
|
+ return false;
|
|
213
|
+ }
|
208
|
214
|
}
|
209
|
|
- }
|
210
|
215
|
|
211
|
|
- /**
|
212
|
|
- * Get the URL to a comment
|
213
|
|
- * @param int $PostID
|
214
|
|
- * @return string|bool The URL to the comment or false on error
|
215
|
|
- */
|
216
|
|
- public static function get_url_query($PostID) {
|
217
|
|
- $QueryID = G::$DB->get_query_id();
|
|
216
|
+ /**
|
|
217
|
+ * Get the URL to a comment
|
|
218
|
+ * @param int $PostID
|
|
219
|
+ * @return string|bool The URL to the comment or false on error
|
|
220
|
+ */
|
|
221
|
+ public static function get_url_query($PostID)
|
|
222
|
+ {
|
|
223
|
+ $QueryID = G::$DB->get_query_id();
|
218
|
224
|
|
219
|
|
- G::$DB->query("
|
|
225
|
+ G::$DB->query("
|
220
|
226
|
SELECT Page, PageID
|
221
|
227
|
FROM comments
|
222
|
228
|
WHERE ID = $PostID");
|
223
|
|
- if (!G::$DB->has_results()) {
|
224
|
|
- error(404);
|
|
229
|
+ if (!G::$DB->has_results()) {
|
|
230
|
+ error(404);
|
|
231
|
+ }
|
|
232
|
+ list($Page, $PageID) = G::$DB->next_record();
|
|
233
|
+
|
|
234
|
+ G::$DB->set_query_id($QueryID);
|
|
235
|
+
|
|
236
|
+ return self::get_url($Page, $PageID, $PostID);
|
225
|
237
|
}
|
226
|
|
- list($Page, $PageID) = G::$DB->next_record();
|
227
|
|
-
|
228
|
|
- G::$DB->set_query_id($QueryID);
|
229
|
|
-
|
230
|
|
- return self::get_url($Page, $PageID, $PostID);
|
231
|
|
- }
|
232
|
|
-
|
233
|
|
- /**
|
234
|
|
- * Load a page's comments. This takes care of `postid` and (indirectly) `page` parameters passed in $_GET.
|
235
|
|
- * Quote notifications and last read are also handled here, unless $HandleSubscriptions = false is passed.
|
236
|
|
- * @param string $Page
|
237
|
|
- * @param int $PageID
|
238
|
|
- * @param bool $HandleSubscriptions Whether or not to handle subscriptions (last read & quote notifications)
|
239
|
|
- * @return array ($NumComments, $Page, $Thread, $LastRead)
|
240
|
|
- * $NumComments: the total number of comments on this artist/request/torrent group
|
241
|
|
- * $Page: the page we're currently on
|
242
|
|
- * $Thread: an array of all posts on this page
|
243
|
|
- * $LastRead: ID of the last comment read by the current user in this thread;
|
244
|
|
- * will be false if $HandleSubscriptions == false or if there are no comments on this page
|
245
|
|
- */
|
246
|
|
- public static function load($Page, $PageID, $HandleSubscriptions = true) {
|
247
|
|
- $QueryID = G::$DB->get_query_id();
|
248
|
|
-
|
249
|
|
- // Get the total number of comments
|
250
|
|
- $NumComments = G::$Cache->get_value($Page."_comments_$PageID");
|
251
|
|
- if ($NumComments === false) {
|
252
|
|
- G::$DB->query("
|
|
238
|
+
|
|
239
|
+ /**
|
|
240
|
+ * Load a page's comments. This takes care of `postid` and (indirectly) `page` parameters passed in $_GET.
|
|
241
|
+ * Quote notifications and last read are also handled here, unless $HandleSubscriptions = false is passed.
|
|
242
|
+ * @param string $Page
|
|
243
|
+ * @param int $PageID
|
|
244
|
+ * @param bool $HandleSubscriptions Whether or not to handle subscriptions (last read & quote notifications)
|
|
245
|
+ * @return array ($NumComments, $Page, $Thread, $LastRead)
|
|
246
|
+ * $NumComments: the total number of comments on this artist/request/torrent group
|
|
247
|
+ * $Page: the page we're currently on
|
|
248
|
+ * $Thread: an array of all posts on this page
|
|
249
|
+ * $LastRead: ID of the last comment read by the current user in this thread;
|
|
250
|
+ * will be false if $HandleSubscriptions == false or if there are no comments on this page
|
|
251
|
+ */
|
|
252
|
+ public static function load($Page, $PageID, $HandleSubscriptions = true)
|
|
253
|
+ {
|
|
254
|
+ $QueryID = G::$DB->get_query_id();
|
|
255
|
+
|
|
256
|
+ // Get the total number of comments
|
|
257
|
+ $NumComments = G::$Cache->get_value($Page."_comments_$PageID");
|
|
258
|
+ if ($NumComments === false) {
|
|
259
|
+ G::$DB->query("
|
253
|
260
|
SELECT COUNT(ID)
|
254
|
261
|
FROM comments
|
255
|
262
|
WHERE Page = '$Page'
|
256
|
263
|
AND PageID = $PageID");
|
257
|
|
- list($NumComments) = G::$DB->next_record();
|
258
|
|
- G::$Cache->cache_value($Page."_comments_$PageID", $NumComments, 0);
|
259
|
|
- }
|
260
|
|
-
|
261
|
|
- // If a postid was passed, we need to determine which page that comment is on.
|
262
|
|
- // Format::page_limit handles a potential $_GET['page']
|
263
|
|
- if (isset($_GET['postid']) && is_number($_GET['postid']) && $NumComments > TORRENT_COMMENTS_PER_PAGE) {
|
264
|
|
- G::$DB->query("
|
|
264
|
+ list($NumComments) = G::$DB->next_record();
|
|
265
|
+ G::$Cache->cache_value($Page."_comments_$PageID", $NumComments, 0);
|
|
266
|
+ }
|
|
267
|
+
|
|
268
|
+ // If a postid was passed, we need to determine which page that comment is on.
|
|
269
|
+ // Format::page_limit handles a potential $_GET['page']
|
|
270
|
+ if (isset($_GET['postid']) && is_number($_GET['postid']) && $NumComments > TORRENT_COMMENTS_PER_PAGE) {
|
|
271
|
+ G::$DB->query("
|
265
|
272
|
SELECT COUNT(ID)
|
266
|
273
|
FROM comments
|
267
|
274
|
WHERE Page = '$Page'
|
268
|
275
|
AND PageID = $PageID
|
269
|
276
|
AND ID <= $_GET[postid]");
|
270
|
|
- list($PostNum) = G::$DB->next_record();
|
271
|
|
- list($CommPage, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $PostNum);
|
272
|
|
- } else {
|
273
|
|
- list($CommPage, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $NumComments);
|
274
|
|
- }
|
275
|
|
-
|
276
|
|
- // Get the cache catalogue
|
277
|
|
- $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $CommPage - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
278
|
|
-
|
279
|
|
- // Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
|
280
|
|
- $Catalogue = G::$Cache->get_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID);
|
281
|
|
- if ($Catalogue === false) {
|
282
|
|
- $CatalogueLimit = $CatalogueID * THREAD_CATALOGUE . ', ' . THREAD_CATALOGUE;
|
283
|
|
- G::$DB->query("
|
|
277
|
+ list($PostNum) = G::$DB->next_record();
|
|
278
|
+ list($CommPage, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $PostNum);
|
|
279
|
+ } else {
|
|
280
|
+ list($CommPage, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $NumComments);
|
|
281
|
+ }
|
|
282
|
+
|
|
283
|
+ // Get the cache catalogue
|
|
284
|
+ $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $CommPage - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
285
|
+
|
|
286
|
+ // Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
|
|
287
|
+ $Catalogue = G::$Cache->get_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID);
|
|
288
|
+ if ($Catalogue === false) {
|
|
289
|
+ $CatalogueLimit = $CatalogueID * THREAD_CATALOGUE . ', ' . THREAD_CATALOGUE;
|
|
290
|
+ G::$DB->query("
|
284
|
291
|
SELECT
|
285
|
292
|
c.ID,
|
286
|
293
|
c.AuthorID,
|
|
@@ -295,20 +302,20 @@ class Comments {
|
295
|
302
|
AND c.PageID = $PageID
|
296
|
303
|
ORDER BY c.ID
|
297
|
304
|
LIMIT $CatalogueLimit");
|
298
|
|
- $Catalogue = G::$DB->to_array(false, MYSQLI_ASSOC);
|
299
|
|
- G::$Cache->cache_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
|
300
|
|
- }
|
301
|
|
-
|
302
|
|
- //This is a hybrid to reduce the catalogue down to the page elements: We use the page limit % catalogue
|
303
|
|
- $Thread = array_slice($Catalogue, ((TORRENT_COMMENTS_PER_PAGE * $CommPage - TORRENT_COMMENTS_PER_PAGE) % THREAD_CATALOGUE), TORRENT_COMMENTS_PER_PAGE, true);
|
304
|
|
-
|
305
|
|
- if ($HandleSubscriptions && count($Thread) > 0) {
|
306
|
|
- // quote notifications
|
307
|
|
- $LastPost = end($Thread);
|
308
|
|
- $LastPost = $LastPost['ID'];
|
309
|
|
- $FirstPost = reset($Thread);
|
310
|
|
- $FirstPost = $FirstPost['ID'];
|
311
|
|
- G::$DB->query("
|
|
305
|
+ $Catalogue = G::$DB->to_array(false, MYSQLI_ASSOC);
|
|
306
|
+ G::$Cache->cache_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
|
|
307
|
+ }
|
|
308
|
+
|
|
309
|
+ //This is a hybrid to reduce the catalogue down to the page elements: We use the page limit % catalogue
|
|
310
|
+ $Thread = array_slice($Catalogue, ((TORRENT_COMMENTS_PER_PAGE * $CommPage - TORRENT_COMMENTS_PER_PAGE) % THREAD_CATALOGUE), TORRENT_COMMENTS_PER_PAGE, true);
|
|
311
|
+
|
|
312
|
+ if ($HandleSubscriptions && count($Thread) > 0) {
|
|
313
|
+ // quote notifications
|
|
314
|
+ $LastPost = end($Thread);
|
|
315
|
+ $LastPost = $LastPost['ID'];
|
|
316
|
+ $FirstPost = reset($Thread);
|
|
317
|
+ $FirstPost = $FirstPost['ID'];
|
|
318
|
+ G::$DB->query("
|
312
|
319
|
UPDATE users_notify_quoted
|
313
|
320
|
SET UnRead = false
|
314
|
321
|
WHERE UserID = " . G::$LoggedUser['ID'] . "
|
|
@@ -316,126 +323,128 @@ class Comments {
|
316
|
323
|
AND PageID = $PageID
|
317
|
324
|
AND PostID >= $FirstPost
|
318
|
325
|
AND PostID <= $LastPost");
|
319
|
|
- if (G::$DB->affected_rows()) {
|
320
|
|
- G::$Cache->delete_value('notify_quoted_' . G::$LoggedUser['ID']);
|
321
|
|
- }
|
|
326
|
+ if (G::$DB->affected_rows()) {
|
|
327
|
+ G::$Cache->delete_value('notify_quoted_' . G::$LoggedUser['ID']);
|
|
328
|
+ }
|
322
|
329
|
|
323
|
|
- // last read
|
324
|
|
- G::$DB->query("
|
|
330
|
+ // last read
|
|
331
|
+ G::$DB->query("
|
325
|
332
|
SELECT PostID
|
326
|
333
|
FROM users_comments_last_read
|
327
|
334
|
WHERE UserID = " . G::$LoggedUser['ID'] . "
|
328
|
335
|
AND Page = '$Page'
|
329
|
336
|
AND PageID = $PageID");
|
330
|
|
- list($LastRead) = G::$DB->next_record();
|
331
|
|
- if ($LastRead < $LastPost) {
|
332
|
|
- G::$DB->query("
|
|
337
|
+ list($LastRead) = G::$DB->next_record();
|
|
338
|
+ if ($LastRead < $LastPost) {
|
|
339
|
+ G::$DB->query("
|
333
|
340
|
INSERT INTO users_comments_last_read
|
334
|
341
|
(UserID, Page, PageID, PostID)
|
335
|
342
|
VALUES
|
336
|
343
|
(" . G::$LoggedUser['ID'] . ", '$Page', $PageID, $LastPost)
|
337
|
344
|
ON DUPLICATE KEY UPDATE
|
338
|
345
|
PostID = $LastPost");
|
339
|
|
- G::$Cache->delete_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
|
340
|
|
- }
|
341
|
|
- } else {
|
342
|
|
- $LastRead = false;
|
343
|
|
- }
|
|
346
|
+ G::$Cache->delete_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
|
|
347
|
+ }
|
|
348
|
+ } else {
|
|
349
|
+ $LastRead = false;
|
|
350
|
+ }
|
344
|
351
|
|
345
|
|
- G::$DB->set_query_id($QueryID);
|
|
352
|
+ G::$DB->set_query_id($QueryID);
|
346
|
353
|
|
347
|
|
- return array($NumComments, $CommPage, $Thread, $LastRead);
|
348
|
|
- }
|
|
354
|
+ return array($NumComments, $CommPage, $Thread, $LastRead);
|
|
355
|
+ }
|
349
|
356
|
|
350
|
|
- /**
|
351
|
|
- * Merges all comments from $Page/$PageID into $Page/$TargetPageID. This also takes care of quote notifications, subscriptions and cache.
|
352
|
|
- * @param type $Page
|
353
|
|
- * @param type $PageID
|
354
|
|
- * @param type $TargetPageID
|
355
|
|
- */
|
356
|
|
- public static function merge($Page, $PageID, $TargetPageID) {
|
357
|
|
- $QueryID = G::$DB->get_query_id();
|
|
357
|
+ /**
|
|
358
|
+ * Merges all comments from $Page/$PageID into $Page/$TargetPageID. This also takes care of quote notifications, subscriptions and cache.
|
|
359
|
+ * @param type $Page
|
|
360
|
+ * @param type $PageID
|
|
361
|
+ * @param type $TargetPageID
|
|
362
|
+ */
|
|
363
|
+ public static function merge($Page, $PageID, $TargetPageID)
|
|
364
|
+ {
|
|
365
|
+ $QueryID = G::$DB->get_query_id();
|
358
|
366
|
|
359
|
|
- G::$DB->query("
|
|
367
|
+ G::$DB->query("
|
360
|
368
|
UPDATE comments
|
361
|
369
|
SET PageID = $TargetPageID
|
362
|
370
|
WHERE Page = '$Page'
|
363
|
371
|
AND PageID = $PageID");
|
364
|
372
|
|
365
|
|
- // quote notifications
|
366
|
|
- G::$DB->query("
|
|
373
|
+ // quote notifications
|
|
374
|
+ G::$DB->query("
|
367
|
375
|
UPDATE users_notify_quoted
|
368
|
376
|
SET PageID = $TargetPageID
|
369
|
377
|
WHERE Page = '$Page'
|
370
|
378
|
AND PageID = $PageID");
|
371
|
379
|
|
372
|
|
- // comment subscriptions
|
373
|
|
- Subscriptions::move_subscriptions($Page, $PageID, $TargetPageID);
|
|
380
|
+ // comment subscriptions
|
|
381
|
+ Subscriptions::move_subscriptions($Page, $PageID, $TargetPageID);
|
374
|
382
|
|
375
|
|
- // cache (we need to clear all comment catalogues)
|
376
|
|
- G::$DB->query("
|
|
383
|
+ // cache (we need to clear all comment catalogues)
|
|
384
|
+ G::$DB->query("
|
377
|
385
|
SELECT
|
378
|
386
|
CEIL(COUNT(ID) / " . TORRENT_COMMENTS_PER_PAGE . ") AS Pages
|
379
|
387
|
FROM comments
|
380
|
388
|
WHERE Page = '$Page'
|
381
|
389
|
AND PageID = $TargetPageID
|
382
|
390
|
GROUP BY PageID");
|
383
|
|
- list($CommPages) = G::$DB->next_record();
|
384
|
|
- $LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
385
|
|
- for ($i = 0; $i <= $LastCatalogue; ++$i) {
|
386
|
|
- G::$Cache->delete_value($Page . "_comments_$TargetPageID" . "_catalogue_$i");
|
|
391
|
+ list($CommPages) = G::$DB->next_record();
|
|
392
|
+ $LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
393
|
+ for ($i = 0; $i <= $LastCatalogue; ++$i) {
|
|
394
|
+ G::$Cache->delete_value($Page . "_comments_$TargetPageID" . "_catalogue_$i");
|
|
395
|
+ }
|
|
396
|
+ G::$Cache->delete_value($Page."_comments_$TargetPageID");
|
|
397
|
+ G::$DB->set_query_id($QueryID);
|
387
|
398
|
}
|
388
|
|
- G::$Cache->delete_value($Page."_comments_$TargetPageID");
|
389
|
|
- G::$DB->set_query_id($QueryID);
|
390
|
|
- }
|
391
|
|
-
|
392
|
|
- /**
|
393
|
|
- * Delete all comments on $Page/$PageID (deals with quote notifications and subscriptions as well)
|
394
|
|
- * @param string $Page
|
395
|
|
- * @param int $PageID
|
396
|
|
- * @return boolean
|
397
|
|
- */
|
398
|
|
- public static function delete_page($Page, $PageID) {
|
399
|
|
- $QueryID = G::$DB->get_query_id();
|
400
|
|
-
|
401
|
|
- // get number of pages
|
402
|
|
- G::$DB->query("
|
|
399
|
+
|
|
400
|
+ /**
|
|
401
|
+ * Delete all comments on $Page/$PageID (deals with quote notifications and subscriptions as well)
|
|
402
|
+ * @param string $Page
|
|
403
|
+ * @param int $PageID
|
|
404
|
+ * @return boolean
|
|
405
|
+ */
|
|
406
|
+ public static function delete_page($Page, $PageID)
|
|
407
|
+ {
|
|
408
|
+ $QueryID = G::$DB->get_query_id();
|
|
409
|
+
|
|
410
|
+ // get number of pages
|
|
411
|
+ G::$DB->query("
|
403
|
412
|
SELECT
|
404
|
413
|
CEIL(COUNT(ID) / " . TORRENT_COMMENTS_PER_PAGE . ") AS Pages
|
405
|
414
|
FROM comments
|
406
|
415
|
WHERE Page = '$Page'
|
407
|
416
|
AND PageID = $PageID
|
408
|
417
|
GROUP BY PageID");
|
409
|
|
- if (!G::$DB->has_results()) {
|
410
|
|
- return false;
|
411
|
|
- }
|
412
|
|
- list($CommPages) = G::$DB->next_record();
|
|
418
|
+ if (!G::$DB->has_results()) {
|
|
419
|
+ return false;
|
|
420
|
+ }
|
|
421
|
+ list($CommPages) = G::$DB->next_record();
|
413
|
422
|
|
414
|
|
- // Delete comments
|
415
|
|
- G::$DB->query("
|
|
423
|
+ // Delete comments
|
|
424
|
+ G::$DB->query("
|
416
|
425
|
DELETE FROM comments
|
417
|
426
|
WHERE Page = '$Page'
|
418
|
427
|
AND PageID = $PageID");
|
419
|
428
|
|
420
|
|
- // Delete quote notifications
|
421
|
|
- Subscriptions::flush_quote_notifications($Page, $PageID);
|
422
|
|
- G::$DB->query("
|
|
429
|
+ // Delete quote notifications
|
|
430
|
+ Subscriptions::flush_quote_notifications($Page, $PageID);
|
|
431
|
+ G::$DB->query("
|
423
|
432
|
DELETE FROM users_notify_quoted
|
424
|
433
|
WHERE Page = '$Page'
|
425
|
434
|
AND PageID = $PageID");
|
426
|
435
|
|
427
|
|
- // Deal with subscriptions
|
428
|
|
- Subscriptions::move_subscriptions($Page, $PageID, null);
|
|
436
|
+ // Deal with subscriptions
|
|
437
|
+ Subscriptions::move_subscriptions($Page, $PageID, null);
|
429
|
438
|
|
430
|
|
- // Clear cache
|
431
|
|
- $LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
432
|
|
- for ($i = 0; $i <= $LastCatalogue; ++$i) {
|
433
|
|
- G::$Cache->delete_value($Page . '_comments_' . $PageID . '_catalogue_' . $i);
|
434
|
|
- }
|
435
|
|
- G::$Cache->delete_value($Page.'_comments_'.$PageID);
|
|
439
|
+ // Clear cache
|
|
440
|
+ $LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
|
|
441
|
+ for ($i = 0; $i <= $LastCatalogue; ++$i) {
|
|
442
|
+ G::$Cache->delete_value($Page . '_comments_' . $PageID . '_catalogue_' . $i);
|
|
443
|
+ }
|
|
444
|
+ G::$Cache->delete_value($Page.'_comments_'.$PageID);
|
436
|
445
|
|
437
|
|
- G::$DB->set_query_id($QueryID);
|
|
446
|
+ G::$DB->set_query_id($QueryID);
|
438
|
447
|
|
439
|
|
- return true;
|
440
|
|
- }
|
|
448
|
+ return true;
|
|
449
|
+ }
|
441
|
450
|
}
|