|
@@ -1,17 +1,19 @@
|
1
|
|
-<?
|
2
|
|
-class Forums {
|
3
|
|
- /**
|
4
|
|
- * Get information on a thread.
|
5
|
|
- *
|
6
|
|
- * @param int $ThreadID the thread ID.
|
7
|
|
- * @param boolean $Return indicates whether thread info should be returned.
|
8
|
|
- * @param Boolean $SelectiveCache cache thread info.
|
9
|
|
- * @return array holding thread information.
|
10
|
|
- */
|
11
|
|
- public static function get_thread_info($ThreadID, $Return = true, $SelectiveCache = false) {
|
12
|
|
- if ((!$ThreadInfo = G::$Cache->get_value('thread_' . $ThreadID . '_info')) || !isset($ThreadInfo['Ranking'])) {
|
13
|
|
- $QueryID = G::$DB->get_query_id();
|
14
|
|
- G::$DB->query("
|
|
1
|
+<?php
|
|
2
|
+class Forums
|
|
3
|
+{
|
|
4
|
+ /**
|
|
5
|
+ * Get information on a thread.
|
|
6
|
+ *
|
|
7
|
+ * @param int $ThreadID the thread ID.
|
|
8
|
+ * @param boolean $Return indicates whether thread info should be returned.
|
|
9
|
+ * @param Boolean $SelectiveCache cache thread info.
|
|
10
|
+ * @return array holding thread information.
|
|
11
|
+ */
|
|
12
|
+ public static function get_thread_info($ThreadID, $Return = true, $SelectiveCache = false)
|
|
13
|
+ {
|
|
14
|
+ if ((!$ThreadInfo = G::$Cache->get_value('thread_' . $ThreadID . '_info')) || !isset($ThreadInfo['Ranking'])) {
|
|
15
|
+ $QueryID = G::$DB->get_query_id();
|
|
16
|
+ G::$DB->query("
|
15
|
17
|
SELECT
|
16
|
18
|
t.Title,
|
17
|
19
|
t.ForumID,
|
|
@@ -28,15 +30,15 @@ class Forums {
|
28
|
30
|
LEFT JOIN forums_polls AS p ON p.TopicID = t.ID
|
29
|
31
|
WHERE t.ID = ?
|
30
|
32
|
GROUP BY fp.TopicID", $ThreadID);
|
31
|
|
- if (!G::$DB->has_results()) {
|
32
|
|
- G::$DB->set_query_id($QueryID);
|
33
|
|
- return null;
|
34
|
|
- }
|
35
|
|
- $ThreadInfo = G::$DB->next_record(MYSQLI_ASSOC, false);
|
36
|
|
- if ($ThreadInfo['StickyPostID']) {
|
37
|
|
- $ThreadInfo['Posts']--;
|
38
|
|
- G::$DB->query(
|
39
|
|
- "SELECT
|
|
33
|
+ if (!G::$DB->has_results()) {
|
|
34
|
+ G::$DB->set_query_id($QueryID);
|
|
35
|
+ return null;
|
|
36
|
+ }
|
|
37
|
+ $ThreadInfo = G::$DB->next_record(MYSQLI_ASSOC, false);
|
|
38
|
+ if ($ThreadInfo['StickyPostID']) {
|
|
39
|
+ $ThreadInfo['Posts']--;
|
|
40
|
+ G::$DB->query(
|
|
41
|
+ "SELECT
|
40
|
42
|
p.ID,
|
41
|
43
|
p.AuthorID,
|
42
|
44
|
p.AddedTime,
|
|
@@ -47,53 +49,58 @@ class Forums {
|
47
|
49
|
FROM forums_posts AS p
|
48
|
50
|
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
|
49
|
51
|
WHERE p.TopicID = ?
|
50
|
|
- AND p.ID = ?", $ThreadID, $ThreadInfo['StickyPostID']);
|
51
|
|
- list ($ThreadInfo['StickyPost']) = G::$DB->to_array(false, MYSQLI_ASSOC);
|
52
|
|
- }
|
53
|
|
- G::$DB->set_query_id($QueryID);
|
54
|
|
- if (!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
|
55
|
|
- G::$Cache->cache_value('thread_' . $ThreadID . '_info', $ThreadInfo, 0);
|
56
|
|
- }
|
57
|
|
- }
|
58
|
|
- if ($Return) {
|
59
|
|
- return $ThreadInfo;
|
|
52
|
+ AND p.ID = ?",
|
|
53
|
+ $ThreadID,
|
|
54
|
+ $ThreadInfo['StickyPostID']
|
|
55
|
+ );
|
|
56
|
+ list($ThreadInfo['StickyPost']) = G::$DB->to_array(false, MYSQLI_ASSOC);
|
|
57
|
+ }
|
|
58
|
+ G::$DB->set_query_id($QueryID);
|
|
59
|
+ if (!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
|
|
60
|
+ G::$Cache->cache_value('thread_' . $ThreadID . '_info', $ThreadInfo, 0);
|
|
61
|
+ }
|
|
62
|
+ }
|
|
63
|
+ if ($Return) {
|
|
64
|
+ return $ThreadInfo;
|
|
65
|
+ }
|
60
|
66
|
}
|
61
|
|
- }
|
62
|
67
|
|
63
|
|
- /**
|
64
|
|
- * Checks whether user has permissions on a forum.
|
65
|
|
- *
|
66
|
|
- * @param int $ForumID the forum ID.
|
67
|
|
- * @param string $Perm the permissision to check, defaults to 'Read'
|
68
|
|
- * @return boolean true if user has permission
|
69
|
|
- */
|
70
|
|
- public static function check_forumperm($ForumID, $Perm = 'Read') {
|
71
|
|
- $Forums = self::get_forums();
|
72
|
|
- if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 1) {
|
73
|
|
- return true;
|
74
|
|
- }
|
75
|
|
- if ($ForumID == DONOR_FORUM && Donations::has_donor_forum(G::$LoggedUser['ID'])) {
|
76
|
|
- return true;
|
77
|
|
- }
|
78
|
|
- if ($Forums[$ForumID]['MinClass' . $Perm] > G::$LoggedUser['Class'] && (!isset(G::$LoggedUser['CustomForums'][$ForumID]) || G::$LoggedUser['CustomForums'][$ForumID] == 0)) {
|
79
|
|
- return false;
|
80
|
|
- }
|
81
|
|
- if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 0) {
|
82
|
|
- return false;
|
|
68
|
+ /**
|
|
69
|
+ * Checks whether user has permissions on a forum.
|
|
70
|
+ *
|
|
71
|
+ * @param int $ForumID the forum ID.
|
|
72
|
+ * @param string $Perm the permissision to check, defaults to 'Read'
|
|
73
|
+ * @return boolean true if user has permission
|
|
74
|
+ */
|
|
75
|
+ public static function check_forumperm($ForumID, $Perm = 'Read')
|
|
76
|
+ {
|
|
77
|
+ $Forums = self::get_forums();
|
|
78
|
+ if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 1) {
|
|
79
|
+ return true;
|
|
80
|
+ }
|
|
81
|
+ if ($ForumID == DONOR_FORUM && Donations::has_donor_forum(G::$LoggedUser['ID'])) {
|
|
82
|
+ return true;
|
|
83
|
+ }
|
|
84
|
+ if ($Forums[$ForumID]['MinClass' . $Perm] > G::$LoggedUser['Class'] && (!isset(G::$LoggedUser['CustomForums'][$ForumID]) || G::$LoggedUser['CustomForums'][$ForumID] == 0)) {
|
|
85
|
+ return false;
|
|
86
|
+ }
|
|
87
|
+ if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 0) {
|
|
88
|
+ return false;
|
|
89
|
+ }
|
|
90
|
+ return true;
|
83
|
91
|
}
|
84
|
|
- return true;
|
85
|
|
- }
|
86
|
92
|
|
87
|
|
- /**
|
88
|
|
- * Gets basic info on a forum.
|
89
|
|
- *
|
90
|
|
- * @param int $ForumID the forum ID.
|
91
|
|
- */
|
92
|
|
- public static function get_forum_info($ForumID) {
|
93
|
|
- $Forum = G::$Cache->get_value("ForumInfo_$ForumID");
|
94
|
|
- if (!$Forum) {
|
95
|
|
- $QueryID = G::$DB->get_query_id();
|
96
|
|
- G::$DB->query("
|
|
93
|
+ /**
|
|
94
|
+ * Gets basic info on a forum.
|
|
95
|
+ *
|
|
96
|
+ * @param int $ForumID the forum ID.
|
|
97
|
+ */
|
|
98
|
+ public static function get_forum_info($ForumID)
|
|
99
|
+ {
|
|
100
|
+ $Forum = G::$Cache->get_value("ForumInfo_$ForumID");
|
|
101
|
+ if (!$Forum) {
|
|
102
|
+ $QueryID = G::$DB->get_query_id();
|
|
103
|
+ G::$DB->query("
|
97
|
104
|
SELECT
|
98
|
105
|
Name,
|
99
|
106
|
MinClassRead,
|
|
@@ -104,48 +111,50 @@ class Forums {
|
104
|
111
|
LEFT JOIN forums_topics ON forums_topics.ForumID = forums.ID
|
105
|
112
|
WHERE forums.ID = ?
|
106
|
113
|
GROUP BY ForumID", $ForumID);
|
107
|
|
- if (!G::$DB->has_results()) {
|
108
|
|
- return false;
|
109
|
|
- }
|
110
|
|
- // Makes an array, with $Forum['Name'], etc.
|
111
|
|
- $Forum = G::$DB->next_record(MYSQLI_ASSOC);
|
|
114
|
+ if (!G::$DB->has_results()) {
|
|
115
|
+ return false;
|
|
116
|
+ }
|
|
117
|
+ // Makes an array, with $Forum['Name'], etc.
|
|
118
|
+ $Forum = G::$DB->next_record(MYSQLI_ASSOC);
|
112
|
119
|
|
113
|
|
- G::$DB->set_query_id($QueryID);
|
|
120
|
+ G::$DB->set_query_id($QueryID);
|
114
|
121
|
|
115
|
|
- G::$Cache->cache_value("ForumInfo_$ForumID", $Forum, 86400);
|
|
122
|
+ G::$Cache->cache_value("ForumInfo_$ForumID", $Forum, 86400);
|
|
123
|
+ }
|
|
124
|
+ return $Forum;
|
116
|
125
|
}
|
117
|
|
- return $Forum;
|
118
|
|
- }
|
119
|
126
|
|
120
|
|
- /**
|
121
|
|
- * Get the forum categories
|
122
|
|
- * @return array ForumCategoryID => Name
|
123
|
|
- */
|
124
|
|
- public static function get_forum_categories() {
|
125
|
|
- $ForumCats = G::$Cache->get_value('forums_categories');
|
126
|
|
- if ($ForumCats === false) {
|
127
|
|
- $QueryID = G::$DB->get_query_id();
|
128
|
|
- G::$DB->query("
|
|
127
|
+ /**
|
|
128
|
+ * Get the forum categories
|
|
129
|
+ * @return array ForumCategoryID => Name
|
|
130
|
+ */
|
|
131
|
+ public static function get_forum_categories()
|
|
132
|
+ {
|
|
133
|
+ $ForumCats = G::$Cache->get_value('forums_categories');
|
|
134
|
+ if ($ForumCats === false) {
|
|
135
|
+ $QueryID = G::$DB->get_query_id();
|
|
136
|
+ G::$DB->query("
|
129
|
137
|
SELECT ID, Name
|
130
|
138
|
FROM forums_categories");
|
131
|
|
- $ForumCats = [];
|
132
|
|
- while (list ($ID, $Name) = G::$DB->next_record()) {
|
133
|
|
- $ForumCats[$ID] = $Name;
|
134
|
|
- }
|
135
|
|
- G::$DB->set_query_id($QueryID);
|
136
|
|
- G::$Cache->cache_value('forums_categories', $ForumCats, 0);
|
|
139
|
+ $ForumCats = [];
|
|
140
|
+ while (list($ID, $Name) = G::$DB->next_record()) {
|
|
141
|
+ $ForumCats[$ID] = $Name;
|
|
142
|
+ }
|
|
143
|
+ G::$DB->set_query_id($QueryID);
|
|
144
|
+ G::$Cache->cache_value('forums_categories', $ForumCats, 0);
|
|
145
|
+ }
|
|
146
|
+ return $ForumCats;
|
137
|
147
|
}
|
138
|
|
- return $ForumCats;
|
139
|
|
- }
|
140
|
148
|
|
141
|
|
- /**
|
142
|
|
- * Get the forums
|
143
|
|
- * @return array ForumID => (various information about the forum)
|
144
|
|
- */
|
145
|
|
- public static function get_forums() {
|
146
|
|
- if (!$Forums = G::$Cache->get_value('forums_list')) {
|
147
|
|
- $QueryID = G::$DB->get_query_id();
|
148
|
|
- G::$DB->query("
|
|
149
|
+ /**
|
|
150
|
+ * Get the forums
|
|
151
|
+ * @return array ForumID => (various information about the forum)
|
|
152
|
+ */
|
|
153
|
+ public static function get_forums()
|
|
154
|
+ {
|
|
155
|
+ if (!$Forums = G::$Cache->get_value('forums_list')) {
|
|
156
|
+ $QueryID = G::$DB->get_query_id();
|
|
157
|
+ G::$DB->query("
|
149
|
158
|
SELECT
|
150
|
159
|
f.ID,
|
151
|
160
|
f.CategoryID,
|
|
@@ -169,72 +178,75 @@ class Forums {
|
169
|
178
|
LEFT JOIN forums_topics AS t ON t.ID = f.LastPostTopicID
|
170
|
179
|
GROUP BY f.ID
|
171
|
180
|
ORDER BY fc.Sort, fc.Name, f.CategoryID, f.Sort");
|
172
|
|
- $Forums = G::$DB->to_array('ID', MYSQLI_ASSOC, false);
|
|
181
|
+ $Forums = G::$DB->to_array('ID', MYSQLI_ASSOC, false);
|
173
|
182
|
|
174
|
|
- G::$DB->query("
|
|
183
|
+ G::$DB->query("
|
175
|
184
|
SELECT ForumID, ThreadID
|
176
|
185
|
FROM forums_specific_rules");
|
177
|
|
- $SpecificRules = [];
|
178
|
|
- while (list($ForumID, $ThreadID) = G::$DB->next_record(MYSQLI_NUM, false)) {
|
179
|
|
- $SpecificRules[$ForumID][] = $ThreadID;
|
180
|
|
- }
|
181
|
|
- G::$DB->set_query_id($QueryID);
|
182
|
|
- foreach ($Forums as $ForumID => &$Forum) {
|
183
|
|
- if (isset($SpecificRules[$ForumID])) {
|
184
|
|
- $Forum['SpecificRules'] = $SpecificRules[$ForumID];
|
185
|
|
- } else {
|
186
|
|
- $Forum['SpecificRules'] = [];
|
|
186
|
+ $SpecificRules = [];
|
|
187
|
+ while (list($ForumID, $ThreadID) = G::$DB->next_record(MYSQLI_NUM, false)) {
|
|
188
|
+ $SpecificRules[$ForumID][] = $ThreadID;
|
|
189
|
+ }
|
|
190
|
+ G::$DB->set_query_id($QueryID);
|
|
191
|
+ foreach ($Forums as $ForumID => &$Forum) {
|
|
192
|
+ if (isset($SpecificRules[$ForumID])) {
|
|
193
|
+ $Forum['SpecificRules'] = $SpecificRules[$ForumID];
|
|
194
|
+ } else {
|
|
195
|
+ $Forum['SpecificRules'] = [];
|
|
196
|
+ }
|
|
197
|
+ }
|
|
198
|
+ G::$Cache->cache_value('forums_list', $Forums, 0);
|
187
|
199
|
}
|
188
|
|
- }
|
189
|
|
- G::$Cache->cache_value('forums_list', $Forums, 0);
|
|
200
|
+ return $Forums;
|
190
|
201
|
}
|
191
|
|
- return $Forums;
|
192
|
|
- }
|
193
|
202
|
|
194
|
|
- /**
|
195
|
|
- * Get all forums that the current user has special access to ("Extra forums" in the profile)
|
196
|
|
- * @return array Array of ForumIDs
|
197
|
|
- */
|
198
|
|
- public static function get_permitted_forums() {
|
199
|
|
- if (isset(G::$LoggedUser['CustomForums'])) {
|
200
|
|
- return (array)array_keys(G::$LoggedUser['CustomForums'], 1);
|
201
|
|
- } else {
|
202
|
|
- return [];
|
|
203
|
+ /**
|
|
204
|
+ * Get all forums that the current user has special access to ("Extra forums" in the profile)
|
|
205
|
+ * @return array Array of ForumIDs
|
|
206
|
+ */
|
|
207
|
+ public static function get_permitted_forums()
|
|
208
|
+ {
|
|
209
|
+ if (isset(G::$LoggedUser['CustomForums'])) {
|
|
210
|
+ return (array)array_keys(G::$LoggedUser['CustomForums'], 1);
|
|
211
|
+ } else {
|
|
212
|
+ return [];
|
|
213
|
+ }
|
203
|
214
|
}
|
204
|
|
- }
|
205
|
215
|
|
206
|
|
- /**
|
207
|
|
- * Get all forums that the current user does not have access to ("Restricted forums" in the profile)
|
208
|
|
- * @return array Array of ForumIDs
|
209
|
|
- */
|
210
|
|
- public static function get_restricted_forums() {
|
211
|
|
- if (isset(G::$LoggedUser['CustomForums'])) {
|
212
|
|
- return (array)array_keys(G::$LoggedUser['CustomForums'], 0);
|
213
|
|
- } else {
|
214
|
|
- return [];
|
|
216
|
+ /**
|
|
217
|
+ * Get all forums that the current user does not have access to ("Restricted forums" in the profile)
|
|
218
|
+ * @return array Array of ForumIDs
|
|
219
|
+ */
|
|
220
|
+ public static function get_restricted_forums()
|
|
221
|
+ {
|
|
222
|
+ if (isset(G::$LoggedUser['CustomForums'])) {
|
|
223
|
+ return (array)array_keys(G::$LoggedUser['CustomForums'], 0);
|
|
224
|
+ } else {
|
|
225
|
+ return [];
|
|
226
|
+ }
|
215
|
227
|
}
|
216
|
|
- }
|
217
|
228
|
|
218
|
|
- /**
|
219
|
|
- * Get the last read posts for the current user
|
220
|
|
- * @param array $Forums Array of forums as returned by self::get_forums()
|
221
|
|
- * @return array TopicID => array(TopicID, PostID, Page) where PostID is the ID of the last read post and Page is the page on which that post is
|
222
|
|
- */
|
223
|
|
- public static function get_last_read($Forums) {
|
224
|
|
- if (isset(G::$LoggedUser['PostsPerPage'])) {
|
225
|
|
- $PerPage = G::$LoggedUser['PostsPerPage'];
|
226
|
|
- } else {
|
227
|
|
- $PerPage = POSTS_PER_PAGE;
|
228
|
|
- }
|
229
|
|
- $TopicIDs = [];
|
230
|
|
- foreach ($Forums as $Forum) {
|
231
|
|
- if (!empty($Forum['LastPostTopicID'])) {
|
232
|
|
- $TopicIDs[] = $Forum['LastPostTopicID'];
|
233
|
|
- }
|
234
|
|
- }
|
235
|
|
- if (!empty($TopicIDs)) {
|
236
|
|
- $QueryID = G::$DB->get_query_id();
|
237
|
|
- G::$DB->query("
|
|
229
|
+ /**
|
|
230
|
+ * Get the last read posts for the current user
|
|
231
|
+ * @param array $Forums Array of forums as returned by self::get_forums()
|
|
232
|
+ * @return array TopicID => array(TopicID, PostID, Page) where PostID is the ID of the last read post and Page is the page on which that post is
|
|
233
|
+ */
|
|
234
|
+ public static function get_last_read($Forums)
|
|
235
|
+ {
|
|
236
|
+ if (isset(G::$LoggedUser['PostsPerPage'])) {
|
|
237
|
+ $PerPage = G::$LoggedUser['PostsPerPage'];
|
|
238
|
+ } else {
|
|
239
|
+ $PerPage = POSTS_PER_PAGE;
|
|
240
|
+ }
|
|
241
|
+ $TopicIDs = [];
|
|
242
|
+ foreach ($Forums as $Forum) {
|
|
243
|
+ if (!empty($Forum['LastPostTopicID'])) {
|
|
244
|
+ $TopicIDs[] = $Forum['LastPostTopicID'];
|
|
245
|
+ }
|
|
246
|
+ }
|
|
247
|
+ if (!empty($TopicIDs)) {
|
|
248
|
+ $QueryID = G::$DB->get_query_id();
|
|
249
|
+ G::$DB->query("
|
238
|
250
|
SELECT
|
239
|
251
|
l.TopicID,
|
240
|
252
|
l.PostID,
|
|
@@ -250,70 +262,73 @@ class Forums {
|
250
|
262
|
FROM forums_last_read_topics AS l
|
251
|
263
|
WHERE l.TopicID IN(" . implode(',', $TopicIDs) . ") AND
|
252
|
264
|
l.UserID = ?", $PerPage, G::$LoggedUser['ID']);
|
253
|
|
- $LastRead = G::$DB->to_array('TopicID', MYSQLI_ASSOC);
|
254
|
|
- G::$DB->set_query_id($QueryID);
|
255
|
|
- } else {
|
256
|
|
- $LastRead = [];
|
|
265
|
+ $LastRead = G::$DB->to_array('TopicID', MYSQLI_ASSOC);
|
|
266
|
+ G::$DB->set_query_id($QueryID);
|
|
267
|
+ } else {
|
|
268
|
+ $LastRead = [];
|
|
269
|
+ }
|
|
270
|
+ return $LastRead;
|
257
|
271
|
}
|
258
|
|
- return $LastRead;
|
259
|
|
- }
|
260
|
272
|
|
261
|
|
- /**
|
262
|
|
- * Add a note to a topic.
|
263
|
|
- * @param int $TopicID
|
264
|
|
- * @param string $Note
|
265
|
|
- * @param int|null $UserID
|
266
|
|
- * @return boolean
|
267
|
|
- */
|
268
|
|
- public static function add_topic_note($TopicID, $Note, $UserID = null) {
|
269
|
|
- if ($UserID === null) {
|
270
|
|
- $UserID = G::$LoggedUser['ID'];
|
271
|
|
- }
|
272
|
|
- $QueryID = G::$DB->get_query_id();
|
273
|
|
- G::$DB->query("
|
|
273
|
+ /**
|
|
274
|
+ * Add a note to a topic.
|
|
275
|
+ * @param int $TopicID
|
|
276
|
+ * @param string $Note
|
|
277
|
+ * @param int|null $UserID
|
|
278
|
+ * @return boolean
|
|
279
|
+ */
|
|
280
|
+ public static function add_topic_note($TopicID, $Note, $UserID = null)
|
|
281
|
+ {
|
|
282
|
+ if ($UserID === null) {
|
|
283
|
+ $UserID = G::$LoggedUser['ID'];
|
|
284
|
+ }
|
|
285
|
+ $QueryID = G::$DB->get_query_id();
|
|
286
|
+ G::$DB->query("
|
274
|
287
|
INSERT INTO forums_topic_notes
|
275
|
288
|
(TopicID, AuthorID, AddedTime, Body)
|
276
|
289
|
VALUES
|
277
|
290
|
(?, ?, NOW(), ?)", $TopicID, $UserID, $Note);
|
278
|
|
- G::$DB->set_query_id($QueryID);
|
279
|
|
- return (bool)G::$DB->affected_rows();
|
280
|
|
- }
|
281
|
|
-
|
282
|
|
- /**
|
283
|
|
- * Determine if a thread is unread
|
284
|
|
- * @param bool $Locked
|
285
|
|
- * @param bool $Sticky
|
286
|
|
- * @param int $LastPostID
|
287
|
|
- * @param array $LastRead An array as returned by self::get_last_read
|
288
|
|
- * @param int $LastTopicID TopicID of the thread where the most recent post was made
|
289
|
|
- * @param string $LastTime Datetime of the last post
|
290
|
|
- * @return bool
|
291
|
|
- */
|
292
|
|
- public static function is_unread($Locked, $Sticky, $LastPostID, $LastRead, $LastTopicID, $LastTime) {
|
293
|
|
- return (!$Locked || $Sticky) && $LastPostID != 0 && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID) && strtotime($LastTime) > G::$LoggedUser['CatchupTime']);
|
294
|
|
- }
|
295
|
|
-
|
296
|
|
- /**
|
297
|
|
- * Create the part of WHERE in the sql queries used to filter forums for a
|
298
|
|
- * specific user (MinClassRead, restricted and permitted forums).
|
299
|
|
- * @return string
|
300
|
|
- */
|
301
|
|
- public static function user_forums_sql() {
|
302
|
|
- // I couldn't come up with a good name, please rename this if you can. -- Y
|
303
|
|
- $RestrictedForums = self::get_restricted_forums();
|
304
|
|
- $PermittedForums = self::get_permitted_forums();
|
305
|
|
- if (Donations::has_donor_forum(G::$LoggedUser['ID']) && !in_array(DONOR_FORUM, $PermittedForums)) {
|
306
|
|
- $PermittedForums[] = DONOR_FORUM;
|
|
291
|
+ G::$DB->set_query_id($QueryID);
|
|
292
|
+ return (bool)G::$DB->affected_rows();
|
307
|
293
|
}
|
308
|
|
- $SQL = "((f.MinClassRead <= '" . G::$LoggedUser['Class'] . "'";
|
309
|
|
- if (count($RestrictedForums)) {
|
310
|
|
- $SQL .= " AND f.ID NOT IN ('" . implode("', '", $RestrictedForums) . "')";
|
|
294
|
+
|
|
295
|
+ /**
|
|
296
|
+ * Determine if a thread is unread
|
|
297
|
+ * @param bool $Locked
|
|
298
|
+ * @param bool $Sticky
|
|
299
|
+ * @param int $LastPostID
|
|
300
|
+ * @param array $LastRead An array as returned by self::get_last_read
|
|
301
|
+ * @param int $LastTopicID TopicID of the thread where the most recent post was made
|
|
302
|
+ * @param string $LastTime Datetime of the last post
|
|
303
|
+ * @return bool
|
|
304
|
+ */
|
|
305
|
+ public static function is_unread($Locked, $Sticky, $LastPostID, $LastRead, $LastTopicID, $LastTime)
|
|
306
|
+ {
|
|
307
|
+ return (!$Locked || $Sticky) && $LastPostID != 0 && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID) && strtotime($LastTime) > G::$LoggedUser['CatchupTime']);
|
311
|
308
|
}
|
312
|
|
- $SQL .= ')';
|
313
|
|
- if (count($PermittedForums)) {
|
314
|
|
- $SQL .= " OR f.ID IN ('" . implode("', '", $PermittedForums) . "')";
|
|
309
|
+
|
|
310
|
+ /**
|
|
311
|
+ * Create the part of WHERE in the sql queries used to filter forums for a
|
|
312
|
+ * specific user (MinClassRead, restricted and permitted forums).
|
|
313
|
+ * @return string
|
|
314
|
+ */
|
|
315
|
+ public static function user_forums_sql()
|
|
316
|
+ {
|
|
317
|
+ // I couldn't come up with a good name, please rename this if you can. -- Y
|
|
318
|
+ $RestrictedForums = self::get_restricted_forums();
|
|
319
|
+ $PermittedForums = self::get_permitted_forums();
|
|
320
|
+ if (Donations::has_donor_forum(G::$LoggedUser['ID']) && !in_array(DONOR_FORUM, $PermittedForums)) {
|
|
321
|
+ $PermittedForums[] = DONOR_FORUM;
|
|
322
|
+ }
|
|
323
|
+ $SQL = "((f.MinClassRead <= '" . G::$LoggedUser['Class'] . "'";
|
|
324
|
+ if (count($RestrictedForums)) {
|
|
325
|
+ $SQL .= " AND f.ID NOT IN ('" . implode("', '", $RestrictedForums) . "')";
|
|
326
|
+ }
|
|
327
|
+ $SQL .= ')';
|
|
328
|
+ if (count($PermittedForums)) {
|
|
329
|
+ $SQL .= " OR f.ID IN ('" . implode("', '", $PermittedForums) . "')";
|
|
330
|
+ }
|
|
331
|
+ $SQL .= ')';
|
|
332
|
+ return $SQL;
|
315
|
333
|
}
|
316
|
|
- $SQL .= ')';
|
317
|
|
- return $SQL;
|
318
|
|
- }
|
319
|
334
|
}
|