Browse Source

Nothing broken in testing

pjc 5 years ago
parent
commit
3fb7eb7c9b

+ 47
- 44
classes/comments.class.php View File

43
         Subscriptions::quote_notify($Body, $PostID, $Page, $PageID);
43
         Subscriptions::quote_notify($Body, $PostID, $Page, $PageID);
44
 
44
 
45
         G::$DB->set_query_id($QueryID);
45
         G::$DB->set_query_id($QueryID);
46
-
47
         return $PostID;
46
         return $PostID;
48
     }
47
     }
49
 
48
 
136
             return false;
135
             return false;
137
         }
136
         }
138
         list($Page, $PageID) = G::$DB->next_record();
137
         list($Page, $PageID) = G::$DB->next_record();
139
-        // get number of pages
138
+
139
+        // Get number of pages
140
         G::$DB->query("
140
         G::$DB->query("
141
         SELECT
141
         SELECT
142
           CEIL(COUNT(ID) / " . TORRENT_COMMENTS_PER_PAGE . ") AS Pages,
142
           CEIL(COUNT(ID) / " . TORRENT_COMMENTS_PER_PAGE . ") AS Pages,
145
           WHERE Page = '$Page'
145
           WHERE Page = '$Page'
146
           AND PageID = $PageID
146
           AND PageID = $PageID
147
         GROUP BY PageID");
147
         GROUP BY PageID");
148
+
148
         if (!G::$DB->has_results()) {
149
         if (!G::$DB->has_results()) {
149
-            // the comment $PostID was probably not posted on $Page
150
+            // The comment $PostID was probably not posted on $Page
150
             G::$DB->set_query_id($QueryID);
151
             G::$DB->set_query_id($QueryID);
151
             return false;
152
             return false;
152
         }
153
         }
159
         G::$DB->query("
160
         G::$DB->query("
160
         DELETE FROM comments
161
         DELETE FROM comments
161
           WHERE ID = $PostID");
162
           WHERE ID = $PostID");
163
+
162
         G::$DB->query("
164
         G::$DB->query("
163
         DELETE FROM comments_edits
165
         DELETE FROM comments_edits
164
           WHERE Page = '$Page'
166
           WHERE Page = '$Page'
180
         }
182
         }
181
 
183
 
182
         G::$Cache->delete_value($Page . '_comments_' . $PageID);
184
         G::$Cache->delete_value($Page . '_comments_' . $PageID);
183
-
184
         if ($Page === 'collages') {
185
         if ($Page === 'collages') {
185
             // On collages, we also need to clear the collage key (collage_$CollageID), because it has the comments in it... (why??)
186
             // On collages, we also need to clear the collage key (collage_$CollageID), because it has the comments in it... (why??)
186
             G::$Cache->delete_value("collage_$PageID");
187
             G::$Cache->delete_value("collage_$PageID");
187
         }
188
         }
188
 
189
 
189
         G::$DB->set_query_id($QueryID);
190
         G::$DB->set_query_id($QueryID);
190
-
191
         return true;
191
         return true;
192
     }
192
     }
193
 
193
 
223
     public static function get_url_query($PostID)
223
     public static function get_url_query($PostID)
224
     {
224
     {
225
         $QueryID = G::$DB->get_query_id();
225
         $QueryID = G::$DB->get_query_id();
226
-
227
         G::$DB->query("
226
         G::$DB->query("
228
         SELECT Page, PageID
227
         SELECT Page, PageID
229
         FROM comments
228
         FROM comments
272
         // Format::page_limit handles a potential $_GET['page']
271
         // Format::page_limit handles a potential $_GET['page']
273
         if (isset($_GET['postid']) && is_number($_GET['postid']) && $NumComments > TORRENT_COMMENTS_PER_PAGE) {
272
         if (isset($_GET['postid']) && is_number($_GET['postid']) && $NumComments > TORRENT_COMMENTS_PER_PAGE) {
274
             G::$DB->query("
273
             G::$DB->query("
275
-        SELECT COUNT(ID)
276
-        FROM comments
277
-        WHERE Page = '$Page'
278
-          AND PageID = $PageID
279
-          AND ID <= $_GET[postid]");
274
+            SELECT COUNT(ID)
275
+            FROM comments
276
+              WHERE Page = '$Page'
277
+              AND PageID = $PageID
278
+              AND ID <= $_GET[postid]");
279
+
280
             list($PostNum) = G::$DB->next_record();
280
             list($PostNum) = G::$DB->next_record();
281
             list($CommPage, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $PostNum);
281
             list($CommPage, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $PostNum);
282
         } else {
282
         } else {
291
         if ($Catalogue === false) {
291
         if ($Catalogue === false) {
292
             $CatalogueLimit = $CatalogueID * THREAD_CATALOGUE . ', ' . THREAD_CATALOGUE;
292
             $CatalogueLimit = $CatalogueID * THREAD_CATALOGUE . ', ' . THREAD_CATALOGUE;
293
             G::$DB->query("
293
             G::$DB->query("
294
-                SELECT
295
-                  c.ID,
296
-                  c.AuthorID,
297
-                  c.AddedTime,
298
-                  c.Body,
299
-                  c.EditedUserID,
300
-                  c.EditedTime,
301
-                  u.Username
302
-                FROM comments AS c
303
-                  LEFT JOIN users_main AS u ON u.ID = c.EditedUserID
304
-                  WHERE c.Page = '$Page'
305
-                  AND c.PageID = $PageID
306
-                ORDER BY c.ID
307
-                LIMIT $CatalogueLimit");
294
+            SELECT
295
+              c.ID,
296
+              c.AuthorID,
297
+              c.AddedTime,
298
+              c.Body,
299
+              c.EditedUserID,
300
+              c.EditedTime,
301
+              u.Username
302
+            FROM comments AS c
303
+              LEFT JOIN users_main AS u ON u.ID = c.EditedUserID
304
+              WHERE c.Page = '$Page'
305
+              AND c.PageID = $PageID
306
+            ORDER BY c.ID
307
+              LIMIT $CatalogueLimit");
308
+
308
             $Catalogue = G::$DB->to_array(false, MYSQLI_ASSOC);
309
             $Catalogue = G::$DB->to_array(false, MYSQLI_ASSOC);
309
             G::$Cache->cache_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
310
             G::$Cache->cache_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
310
         }
311
         }
318
             $LastPost = $LastPost['ID'];
319
             $LastPost = $LastPost['ID'];
319
             $FirstPost = reset($Thread);
320
             $FirstPost = reset($Thread);
320
             $FirstPost = $FirstPost['ID'];
321
             $FirstPost = $FirstPost['ID'];
322
+
321
             G::$DB->query("
323
             G::$DB->query("
322
-                UPDATE users_notify_quoted
323
-                SET UnRead = false
324
-                  WHERE UserID = " . G::$LoggedUser['ID'] . "
325
-                  AND Page = '$Page'
326
-                  AND PageID = $PageID
327
-                  AND PostID >= $FirstPost
328
-                  AND PostID <= $LastPost");
324
+            UPDATE users_notify_quoted
325
+            SET UnRead = false
326
+              WHERE UserID = " . G::$LoggedUser['ID'] . "
327
+              AND Page = '$Page'
328
+              AND PageID = $PageID
329
+              AND PostID >= $FirstPost
330
+              AND PostID <= $LastPost");
331
+
329
             if (G::$DB->affected_rows()) {
332
             if (G::$DB->affected_rows()) {
330
                 G::$Cache->delete_value('notify_quoted_' . G::$LoggedUser['ID']);
333
                 G::$Cache->delete_value('notify_quoted_' . G::$LoggedUser['ID']);
331
             }
334
             }
332
 
335
 
333
             // Last read
336
             // Last read
334
             G::$DB->query("
337
             G::$DB->query("
335
-        SELECT PostID
336
-        FROM users_comments_last_read
337
-          WHERE UserID = " . G::$LoggedUser['ID'] . "
338
-          AND Page = '$Page'
339
-          AND PageID = $PageID");
338
+            SELECT PostID
339
+            FROM users_comments_last_read
340
+              WHERE UserID = " . G::$LoggedUser['ID'] . "
341
+              AND Page = '$Page'
342
+              AND PageID = $PageID");
343
+
340
             list($LastRead) = G::$DB->next_record();
344
             list($LastRead) = G::$DB->next_record();
341
             if ($LastRead < $LastPost) {
345
             if ($LastRead < $LastPost) {
342
                 G::$DB->query("
346
                 G::$DB->query("
343
-          INSERT INTO users_comments_last_read
344
-            (UserID, Page, PageID, PostID)
345
-          VALUES
346
-            (" . G::$LoggedUser['ID'] . ", '$Page', $PageID, $LastPost)
347
-          ON DUPLICATE KEY UPDATE
348
-            PostID = $LastPost");
347
+                INSERT INTO users_comments_last_read
348
+                  (UserID, Page, PageID, PostID)
349
+                VALUES
350
+                  (" . G::$LoggedUser['ID'] . ", '$Page', $PageID, $LastPost)
351
+                ON DUPLICATE KEY UPDATE
352
+                  PostID = $LastPost");
349
                 G::$Cache->delete_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
353
                 G::$Cache->delete_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
350
             }
354
             }
351
         } else {
355
         } else {
353
         }
357
         }
354
 
358
 
355
         G::$DB->set_query_id($QueryID);
359
         G::$DB->set_query_id($QueryID);
356
-
357
         return array($NumComments, $CommPage, $Thread, $LastRead);
360
         return array($NumComments, $CommPage, $Thread, $LastRead);
358
     }
361
     }
359
 
362
 

+ 168
- 69
classes/debug.class.php View File

32
         if ($Errors > MAX_ERRORS && !defined('ERROR_EXCEPTION')) {
32
         if ($Errors > MAX_ERRORS && !defined('ERROR_EXCEPTION')) {
33
             $Reason[] = $Errors.' PHP errors';
33
             $Reason[] = $Errors.' PHP errors';
34
         }
34
         }
35
+
35
         /*
36
         /*
36
         $Queries = count($this->get_queries());
37
         $Queries = count($this->get_queries());
37
         if ($Queries > MAX_QUERIES && !defined('QUERY_EXCEPTION')) {
38
         if ($Queries > MAX_QUERIES && !defined('QUERY_EXCEPTION')) {
38
           $Reason[] = $Queries.' Queries';
39
           $Reason[] = $Queries.' Queries';
39
         }
40
         }
40
         */
41
         */
42
+
41
         $Ram = memory_get_usage(true);
43
         $Ram = memory_get_usage(true);
42
         if ($Ram > MAX_MEMORY && !defined('MEMORY_EXCEPTION')) {
44
         if ($Ram > MAX_MEMORY && !defined('MEMORY_EXCEPTION')) {
43
             $Reason[] = Format::get_size($Ram).' RAM used';
45
             $Reason[] = Format::get_size($Ram).' RAM used';
44
         }
46
         }
45
 
47
 
46
-        G::$DB->warnings(); // see comment in MYSQL::query
47
-        /*$Queries = $this->get_queries();
48
+        G::$DB->warnings(); // See comment in MYSQL::query
49
+        /*
50
+        $Queries = $this->get_queries();
48
         $DBWarningCount = 0;
51
         $DBWarningCount = 0;
49
         foreach ($Queries as $Query) {
52
         foreach ($Queries as $Query) {
50
           if (!empty($Query[2])) {
53
           if (!empty($Query[2])) {
53
         }
56
         }
54
         if ($DBWarningCount) {
57
         if ($DBWarningCount) {
55
           $Reason[] = $DBWarningCount . ' DB warning(s)';
58
           $Reason[] = $DBWarningCount . ' DB warning(s)';
56
-        }*/
59
+        }
60
+        */
57
 
61
 
58
         $CacheStatus = G::$Cache->server_status();
62
         $CacheStatus = G::$Cache->server_status();
59
         if (in_array(0, $CacheStatus) && !G::$Cache->get_value('cache_fail_reported')) {
63
         if (in_array(0, $CacheStatus) && !G::$Cache->get_value('cache_fail_reported')) {
75
             $this->analysis(implode(', ', $Reason));
79
             $this->analysis(implode(', ', $Reason));
76
             return true;
80
             return true;
77
         }
81
         }
78
-
79
         return false;
82
         return false;
80
     }
83
     }
81
 
84
 
87
         }
90
         }
88
         $Identifier = Users::make_secret(5);
91
         $Identifier = Users::make_secret(5);
89
         G::$Cache->cache_value(
92
         G::$Cache->cache_value(
90
-        'analysis_'.$Identifier,
91
-        array(
92
-        'url' => $_SERVER['REQUEST_URI'],
93
-        'message' => $Report,
94
-        'errors' => $this->get_errors(true),
95
-        'queries' => $this->get_queries(),
96
-        'flags' => $this->get_flags(),
97
-        'includes' => $this->get_includes(),
98
-        'cache' => $this->get_cache_keys(),
99
-        'vars' => $this->get_logged_vars(),
100
-        'perf' => $this->get_perf(),
101
-        'ocelot' => $this->get_ocelot_requests()
102
-      ),
103
-        $Time
104
-    );
93
+            'analysis_'.$Identifier,
94
+            array(
95
+                'url' => $_SERVER['REQUEST_URI'],
96
+                'message' => $Report,
97
+                'errors' => $this->get_errors(true),
98
+                'queries' => $this->get_queries(),
99
+                'flags' => $this->get_flags(),
100
+                'includes' => $this->get_includes(),
101
+                'cache' => $this->get_cache_keys(),
102
+                'vars' => $this->get_logged_vars(),
103
+                'perf' => $this->get_perf(),
104
+                'ocelot' => $this->get_ocelot_requests()
105
+            ),
106
+            $Time
107
+        );
108
+
105
         $RequestURI = !empty($_SERVER['REQUEST_URI']) ? substr($_SERVER['REQUEST_URI'], 1) : '';
109
         $RequestURI = !empty($_SERVER['REQUEST_URI']) ? substr($_SERVER['REQUEST_URI'], 1) : '';
106
         send_irc('PRIVMSG '.LAB_CHAN." :{$Message} $Document ".site_url()."tools.php?action=analysis&case=$Identifier ".site_url().$RequestURI);
110
         send_irc('PRIVMSG '.LAB_CHAN." :{$Message} $Document ".site_url()."tools.php?action=analysis&case=$Identifier ".site_url().$RequestURI);
107
     }
111
     }
121
     {
125
     {
122
         $BackTrace = debug_backtrace();
126
         $BackTrace = debug_backtrace();
123
         $ID = Users::make_secret(5);
127
         $ID = Users::make_secret(5);
128
+
124
         if (!$VarName) {
129
         if (!$VarName) {
125
             $VarName = $ID;
130
             $VarName = $ID;
126
         }
131
         }
132
+
127
         $File = array('path' => substr($BackTrace[0]['file'], strlen(SERVER_ROOT)), 'line' => $BackTrace[0]['line']);
133
         $File = array('path' => substr($BackTrace[0]['file'], strlen(SERVER_ROOT)), 'line' => $BackTrace[0]['line']);
128
         $this->LoggedVars[$ID] = array($VarName => array('bt' => $File, 'data' => $Var));
134
         $this->LoggedVars[$ID] = array($VarName => array('bt' => $File, 'data' => $Var));
129
     }
135
     }
134
         $this->Flags[] = array($Event, (microtime(true) - $ScriptStartTime) * 1000, memory_get_usage(true), $this->get_cpu_time());
140
         $this->Flags[] = array($Event, (microtime(true) - $ScriptStartTime) * 1000, memory_get_usage(true), $this->get_cpu_time());
135
     }
141
     }
136
 
142
 
137
-    //This isn't in the constructor because $this is not available, and the function cannot be made static
143
+    // This isn't in the constructor because $this is not available, and the function cannot be made static
138
     public function handle_errors()
144
     public function handle_errors()
139
     {
145
     {
140
         //error_reporting(E_ALL ^ E_STRICT | E_WARNING | E_DEPRECATED | E_ERROR | E_PARSE); //E_STRICT disabled
146
         //error_reporting(E_ALL ^ E_STRICT | E_WARNING | E_DEPRECATED | E_ERROR | E_PARSE); //E_STRICT disabled
151
             if (!is_int($Key) || !is_int($LastKey) || $Key != $LastKey + 1) {
157
             if (!is_int($Key) || !is_int($LastKey) || $Key != $LastKey + 1) {
152
                 $Return[$Key] .= "'$Key' => ";
158
                 $Return[$Key] .= "'$Key' => ";
153
             }
159
             }
160
+
154
             if ($Val === true) {
161
             if ($Val === true) {
155
                 $Return[$Key] .= 'true';
162
                 $Return[$Key] .= 'true';
156
             } elseif ($Val === false) {
163
             } elseif ($Val === false) {
164
             } elseif (is_array($Val)) {
171
             } elseif (is_array($Val)) {
165
                 $Return[$Key] .= 'array('.$this->format_args($Val).')';
172
                 $Return[$Key] .= 'array('.$this->format_args($Val).')';
166
             }
173
             }
174
+
167
             $LastKey = $Key;
175
             $LastKey = $Key;
168
         }
176
         }
169
         return implode(', ', $Return);
177
         return implode(', ', $Return);
171
 
179
 
172
     public function php_error_handler($Level, $Error, $File, $Line)
180
     public function php_error_handler($Level, $Error, $File, $Line)
173
     {
181
     {
174
-        //Who added this, it's still something to pay attention to...
182
+        // Who added this, it's still something to pay attention to...
175
         if (stripos('Undefined index', $Error) !== false) {
183
         if (stripos('Undefined index', $Error) !== false) {
176
             //return true;
184
             //return true;
177
         }
185
         }
178
 
186
 
179
-        $Steps = 1; //Steps to go up in backtrace, default one
187
+        $Steps = 1; // Steps to go up in backtrace, default one
180
         $Call = '';
188
         $Call = '';
181
         $Args = '';
189
         $Args = '';
182
         $Tracer = debug_backtrace();
190
         $Tracer = debug_backtrace();
183
 
191
 
184
-        //This is in case something in this function goes wrong and we get stuck with an infinite loop
192
+        // This is in case something in this function goes wrong and we get stuck with an infinite loop
185
         if (isset($Tracer[$Steps]['function'], $Tracer[$Steps]['class']) && $Tracer[$Steps]['function'] == 'php_error_handler' && $Tracer[$Steps]['class'] == 'DEBUG') {
193
         if (isset($Tracer[$Steps]['function'], $Tracer[$Steps]['class']) && $Tracer[$Steps]['function'] == 'php_error_handler' && $Tracer[$Steps]['class'] == 'DEBUG') {
186
             return true;
194
             return true;
187
         }
195
         }
188
 
196
 
189
-        //If this error was thrown, we return the function which threw it
197
+        // If this error was thrown, we return the function which threw it
190
         if (isset($Tracer[$Steps]['function']) && $Tracer[$Steps]['function'] == 'trigger_error') {
198
         if (isset($Tracer[$Steps]['function']) && $Tracer[$Steps]['function'] == 'trigger_error') {
191
             $Steps++;
199
             $Steps++;
192
             $File = $Tracer[$Steps]['file'];
200
             $File = $Tracer[$Steps]['file'];
193
             $Line = $Tracer[$Steps]['line'];
201
             $Line = $Tracer[$Steps]['line'];
194
         }
202
         }
195
 
203
 
196
-        //At this time ONLY Array strict typing is fully supported.
197
-        //Allow us to abuse strict typing (IE: function test(Array))
204
+        // At this time ONLY Array strict typing is fully supported.
205
+        // Allow us to abuse strict typing (IE: function test(Array))
198
         if (preg_match('/^Argument (\d+) passed to \S+ must be an (array), (array|string|integer|double|object) given, called in (\S+) on line (\d+) and defined$/', $Error, $Matches)) {
206
         if (preg_match('/^Argument (\d+) passed to \S+ must be an (array), (array|string|integer|double|object) given, called in (\S+) on line (\d+) and defined$/', $Error, $Matches)) {
199
             $Error = 'Type hinting failed on arg '.$Matches[1]. ', expected '.$Matches[2].' but found '.$Matches[3];
207
             $Error = 'Type hinting failed on arg '.$Matches[1]. ', expected '.$Matches[2].' but found '.$Matches[3];
200
             $File = $Matches[4];
208
             $File = $Matches[4];
201
             $Line = $Matches[5];
209
             $Line = $Matches[5];
202
         }
210
         }
203
 
211
 
204
-        //Lets not be repetative
212
+        // Let's not be repetative
205
         if (($Tracer[$Steps]['function'] == 'include' || $Tracer[$Steps]['function'] == 'require') && isset($Tracer[$Steps]['args'][0]) && $Tracer[$Steps]['args'][0] == $File) {
213
         if (($Tracer[$Steps]['function'] == 'include' || $Tracer[$Steps]['function'] == 'require') && isset($Tracer[$Steps]['args'][0]) && $Tracer[$Steps]['args'][0] == $File) {
206
             unset($Tracer[$Steps]['args']);
214
             unset($Tracer[$Steps]['args']);
207
         }
215
         }
208
 
216
 
209
-        //Class
217
+        // Class
210
         if (isset($Tracer[$Steps]['class'])) {
218
         if (isset($Tracer[$Steps]['class'])) {
211
             $Call .= $Tracer[$Steps]['class'].'::';
219
             $Call .= $Tracer[$Steps]['class'].'::';
212
         }
220
         }
213
 
221
 
214
-        //Function & args
222
+        // Function & args
215
         if (isset($Tracer[$Steps]['function'])) {
223
         if (isset($Tracer[$Steps]['function'])) {
216
             $Call .= $Tracer[$Steps]['function'];
224
             $Call .= $Tracer[$Steps]['function'];
217
             if (isset($Tracer[$Steps]['args'][0])) {
225
             if (isset($Tracer[$Steps]['args'][0])) {
219
             }
227
             }
220
         }
228
         }
221
 
229
 
222
-        //Shorten the path & we're done
230
+        // Shorten the path & we're done
223
         $File = str_replace(SERVER_ROOT, '', $File);
231
         $File = str_replace(SERVER_ROOT, '', $File);
224
         $Error = str_replace(SERVER_ROOT, '', $Error);
232
         $Error = str_replace(SERVER_ROOT, '', $Error);
225
 
233
 
238
             $PageTime = (microtime(true) - $ScriptStartTime);
246
             $PageTime = (microtime(true) - $ScriptStartTime);
239
             $CPUTime = $this->get_cpu_time();
247
             $CPUTime = $this->get_cpu_time();
240
             $Perf = array(
248
             $Perf = array(
241
-        'Memory usage' => Format::get_size(memory_get_usage(true)),
242
-        'Page process time' => number_format($PageTime, 3).' s');
249
+                'Memory usage' => Format::get_size(memory_get_usage(true)),
250
+                'Page process time' => number_format($PageTime, 3).' s');
251
+
243
             if ($CPUTime) {
252
             if ($CPUTime) {
244
                 $Perf['CPU time'] = number_format($CPUTime / 1000000, 3).' s';
253
                 $Perf['CPU time'] = number_format($CPUTime / 1000000, 3).' s';
245
             }
254
             }
255
 
264
 
256
     public function get_errors($Light = false)
265
     public function get_errors($Light = false)
257
     {
266
     {
258
-        //Because the cache can't take some of these variables
267
+        // Because the cache can't take some of these variables
259
         if ($Light) {
268
         if ($Light) {
260
             foreach ($this->Errors as $Key => $Value) {
269
             foreach ($this->Errors as $Key => $Value) {
261
                 $this->Errors[$Key][3] = '';
270
                 $this->Errors[$Key][3] = '';
347
         if (empty($Perf)) {
356
         if (empty($Perf)) {
348
             return;
357
             return;
349
         } ?>
358
         } ?>
359
+
350
 <table class="layout">
360
 <table class="layout">
351
   <tr>
361
   <tr>
352
     <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_perf').gtoggle(); return false;"
362
     <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_perf').gtoggle(); return false;"
374
         if (!is_array($Includes)) {
384
         if (!is_array($Includes)) {
375
             $Includes = $this->get_includes();
385
             $Includes = $this->get_includes();
376
         } ?>
386
         } ?>
387
+
377
 <table class="layout">
388
 <table class="layout">
378
   <tr>
389
   <tr>
379
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_include').gtoggle(); return false;"
380
-          class="brackets">View</a> <?=number_format(count($Includes))?> Includes:</strong></td>
390
+    <td>
391
+      <strong>
392
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_include').gtoggle(); return false;"
393
+          class="brackets">View</a>
394
+        <?=number_format(count($Includes))?>
395
+        Includes:
396
+      </strong>
397
+    </td>
381
   </tr>
398
   </tr>
382
 </table>
399
 </table>
400
+
383
 <table id="debug_include" class="debug_table hidden">
401
 <table id="debug_include" class="debug_table hidden">
384
   <?php
402
   <?php
385
     foreach ($Includes as $File) {
403
     foreach ($Includes as $File) {
401
         } ?>
419
         } ?>
402
 <table class="layout">
420
 <table class="layout">
403
   <tr>
421
   <tr>
404
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_classes').gtoggle(); return false;"
405
-          class="brackets">View</a> Classes:</strong></td>
422
+    <td>
423
+      <strong>
424
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_classes').gtoggle(); return false;"
425
+          class="brackets">View</a>
426
+        Classes:
427
+      </strong>
428
+    </td>
406
   </tr>
429
   </tr>
407
 </table>
430
 </table>
431
+
408
 <table id="debug_classes" class="debug_table hidden">
432
 <table id="debug_classes" class="debug_table hidden">
409
   <tr>
433
   <tr>
410
     <td>
434
     <td>
411
       <pre>
435
       <pre>
412
-<?php          print_r($Classes);
436
+<?php
437
+print_r($Classes);
413
         echo "\n"; ?>
438
         echo "\n"; ?>
414
         </pre>
439
         </pre>
415
     </td>
440
     </td>
423
         ?>
448
         ?>
424
 <table class="layout">
449
 <table class="layout">
425
   <tr>
450
   <tr>
426
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_extensions').gtoggle(); return false;"
427
-          class="brackets">View</a> Extensions:</strong></td>
451
+    <td>
452
+      <strong>
453
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_extensions').gtoggle(); return false;"
454
+          class="brackets">View</a>
455
+        Extensions:
456
+      </strong>
457
+    </td>
428
   </tr>
458
   </tr>
429
 </table>
459
 </table>
430
 <table id="debug_extensions" class="debug_table hidden">
460
 <table id="debug_extensions" class="debug_table hidden">
431
   <tr>
461
   <tr>
432
     <td>
462
     <td>
433
       <pre>
463
       <pre>
434
-<?php          print_r($this->get_extensions());
464
+<?php
465
+print_r($this->get_extensions());
435
         echo "\n"; ?>
466
         echo "\n"; ?>
436
         </pre>
467
         </pre>
437
     </td>
468
     </td>
445
         if (!is_array($Flags)) {
476
         if (!is_array($Flags)) {
446
             $Flags = $this->get_flags();
477
             $Flags = $this->get_flags();
447
         }
478
         }
479
+
448
         if (empty($Flags)) {
480
         if (empty($Flags)) {
449
             return;
481
             return;
450
         } ?>
482
         } ?>
483
+
451
 <table class="layout">
484
 <table class="layout">
452
   <tr>
485
   <tr>
453
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_flags').gtoggle(); return false;"
454
-          class="brackets">View</a> Flags:</strong></td>
486
+    <td>
487
+      <strong>
488
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_flags').gtoggle(); return false;"
489
+          class="brackets">View</a>
490
+        Flags:
491
+      </strong>
492
+    </td>
455
   </tr>
493
   </tr>
456
 </table>
494
 </table>
495
+
457
 <table id="debug_flags" class="debug_table hidden">
496
 <table id="debug_flags" class="debug_table hidden">
458
   <tr class="valign_top">
497
   <tr class="valign_top">
459
     <td class="debug_flags_event"><strong>Event</strong></td>
498
     <td class="debug_flags_event"><strong>Event</strong></td>
460
     <td class="debug_flags_time"><strong>Page time</strong></td>
499
     <td class="debug_flags_time"><strong>Page time</strong></td>
461
-    <?php    if ($Flags[0][3] !== false) { ?>
500
+    <?php if ($Flags[0][3] !== false) { ?>
462
     <td class="debug_flags_time"><strong>CPU time</strong></td>
501
     <td class="debug_flags_time"><strong>CPU time</strong></td>
463
-    <?php    } ?>
502
+    <?php } ?>
464
     <td class="debug_flags_memory"><strong>Memory</strong></td>
503
     <td class="debug_flags_memory"><strong>Memory</strong></td>
465
   </tr>
504
   </tr>
505
+
466
   <?php
506
   <?php
467
     foreach ($Flags as $Flag) {
507
     foreach ($Flags as $Flag) {
468
         list($Event, $MicroTime, $Memory, $CPUTime) = $Flag; ?>
508
         list($Event, $MicroTime, $Memory, $CPUTime) = $Flag; ?>
470
     <td><?=$Event?>
510
     <td><?=$Event?>
471
     </td>
511
     </td>
472
     <td><?=number_format($MicroTime, 3)?> ms</td>
512
     <td><?=number_format($MicroTime, 3)?> ms</td>
473
-    <?php      if ($CPUTime !== false) { ?>
513
+    <?php if ($CPUTime !== false) { ?>
474
     <td><?=number_format($CPUTime / 1000, 3)?> ms</td>
514
     <td><?=number_format($CPUTime / 1000, 3)?> ms</td>
475
-    <?php      } ?>
515
+    <?php } ?>
476
     <td><?=Format::get_size($Memory)?>
516
     <td><?=Format::get_size($Memory)?>
477
     </td>
517
     </td>
478
   </tr>
518
   </tr>
487
         if (!is_array($Constants)) {
527
         if (!is_array($Constants)) {
488
             $Constants = $this->get_constants();
528
             $Constants = $this->get_constants();
489
         } ?>
529
         } ?>
530
+
490
 <table class="layout">
531
 <table class="layout">
491
   <tr>
532
   <tr>
492
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_constants').gtoggle(); return false;"
493
-          class="brackets">View</a> Constants:</strong></td>
533
+    <td>
534
+      <strong>
535
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_constants').gtoggle(); return false;"
536
+          class="brackets">View</a>
537
+        Constants:
538
+      </strong>
539
+    </td>
494
   </tr>
540
   </tr>
495
 </table>
541
 </table>
542
+
496
 <table id="debug_constants" class="debug_table hidden">
543
 <table id="debug_constants" class="debug_table hidden">
497
   <tr>
544
   <tr>
498
     <td class="debug_data debug_constants_data">
545
     <td class="debug_data debug_constants_data">
499
       <pre>
546
       <pre>
500
-<?=         display_str(print_r($Constants, true))?>
547
+<?=display_str(print_r($Constants, true))?>
501
         </pre>
548
         </pre>
502
     </td>
549
     </td>
503
   </tr>
550
   </tr>
510
         if (!is_array($OcelotRequests)) {
557
         if (!is_array($OcelotRequests)) {
511
             $OcelotRequests = $this->get_ocelot_requests();
558
             $OcelotRequests = $this->get_ocelot_requests();
512
         }
559
         }
560
+
513
         if (empty($OcelotRequests)) {
561
         if (empty($OcelotRequests)) {
514
             return;
562
             return;
515
         } ?>
563
         } ?>
564
+
516
 <table class="layout">
565
 <table class="layout">
517
   <tr>
566
   <tr>
518
-    <td><strong><a data-toggle-target="#debug_ocelot" class="brackets">View</a> <?=number_format(count($OcelotRequests))?> Ocelot requests:</strong>
567
+    <td>
568
+      <strong>
569
+        <a data-toggle-target="#debug_ocelot" class="brackets">View</a>
570
+        <?=number_format(count($OcelotRequests))?>
571
+        Ocelot requests:
572
+      </strong>
519
     </td>
573
     </td>
520
   </tr>
574
   </tr>
521
 </table>
575
 </table>
576
+
522
 <table id="debug_ocelot" class="debug_table hidden">
577
 <table id="debug_ocelot" class="debug_table hidden">
523
-  <?php    foreach ($OcelotRequests as $i => $Request) { ?>
578
+  <?php foreach ($OcelotRequests as $i => $Request) { ?>
524
   <tr>
579
   <tr>
525
     <td class="debug_data debug_ocelot_data">
580
     <td class="debug_data debug_ocelot_data">
526
       <a data-toggle-target="#debug_ocelot_<?=$i?>"><?=display_str($Request['path'])?></a>
581
       <a data-toggle-target="#debug_ocelot_<?=$i?>"><?=display_str($Request['path'])?></a>
527
       <pre id="debug_ocelot_<?=$i?>"
582
       <pre id="debug_ocelot_<?=$i?>"
528
         class="hidden"><?=display_str($Request['response'])?></pre>
583
         class="hidden"><?=display_str($Request['response'])?></pre>
529
     </td>
584
     </td>
585
+
530
     <td class="debug_info" style="width: 100px;">
586
     <td class="debug_info" style="width: 100px;">
531
       <?=display_str($Request['status'])?>
587
       <?=display_str($Request['status'])?>
532
     </td>
588
     </td>
534
       <?=number_format($Request['time'], 5)?> ms
590
       <?=number_format($Request['time'], 5)?> ms
535
     </td>
591
     </td>
536
   </tr>
592
   </tr>
537
-  <?php    } ?>
593
+  <?php } ?>
538
 </table>
594
 </table>
539
 <?php
595
 <?php
540
     }
596
     }
546
             $CacheKeys = $this->get_cache_keys();
602
             $CacheKeys = $this->get_cache_keys();
547
             $Header .= ' ('.number_format($this->get_cache_time(), 5).' ms)';
603
             $Header .= ' ('.number_format($this->get_cache_time(), 5).' ms)';
548
         }
604
         }
605
+
549
         if (empty($CacheKeys)) {
606
         if (empty($CacheKeys)) {
550
             return;
607
             return;
551
         }
608
         }
552
         $Header = ' '.number_format(count($CacheKeys))." $Header:"; ?>
609
         $Header = ' '.number_format(count($CacheKeys))." $Header:"; ?>
610
+
553
 <table class="layout">
611
 <table class="layout">
554
   <tr>
612
   <tr>
555
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_cache').gtoggle(); return false;"
556
-          class="brackets">View</a><?=$Header?></strong></td>
613
+    <td>
614
+      <strong>
615
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_cache').gtoggle(); return false;"
616
+          class="brackets">View</a>
617
+        <?=$Header?>
618
+      </strong>
619
+    </td>
557
   </tr>
620
   </tr>
558
 </table>
621
 </table>
622
+
559
 <table id="debug_cache" class="debug_table hidden">
623
 <table id="debug_cache" class="debug_table hidden">
560
-  <?php    foreach ($CacheKeys as $Key) { ?>
624
+  <?php foreach ($CacheKeys as $Key) { ?>
561
   <tr>
625
   <tr>
562
     <td class="label nobr debug_info debug_cache_key">
626
     <td class="label nobr debug_info debug_cache_key">
563
       <a href="#"
627
       <a href="#"
567
     </td>
631
     </td>
568
     <td class="debug_data debug_cache_data">
632
     <td class="debug_data debug_cache_data">
569
       <pre id="debug_cache_<?=$Key?>" class="hidden">
633
       <pre id="debug_cache_<?=$Key?>" class="hidden">
570
-<?=         display_str(print_r(G::$Cache->get_value($Key, true), true))?>
634
+<?=display_str(print_r(G::$Cache->get_value($Key, true), true))?>
571
         </pre>
635
         </pre>
572
     </td>
636
     </td>
573
   </tr>
637
   </tr>
574
-  <?php    } ?>
638
+  <?php } ?>
575
 </table>
639
 </table>
576
 <?php
640
 <?php
577
     }
641
     }
581
         if (!is_array($Errors)) {
645
         if (!is_array($Errors)) {
582
             $Errors = $this->get_errors();
646
             $Errors = $this->get_errors();
583
         }
647
         }
648
+
584
         if (empty($Errors)) {
649
         if (empty($Errors)) {
585
             return;
650
             return;
586
         } ?>
651
         } ?>
652
+
587
 <table class="layout">
653
 <table class="layout">
588
   <tr>
654
   <tr>
589
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_error').gtoggle(); return false;"
590
-          class="brackets">View</a> <?=number_format(count($Errors))?> Errors:</strong></td>
655
+    <td>
656
+      <strong>
657
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_error').gtoggle(); return false;"
658
+          class="brackets">View</a>
659
+        <?=number_format(count($Errors))?>
660
+        Errors:
661
+      </strong>
662
+    </td>
591
   </tr>
663
   </tr>
592
 </table>
664
 </table>
593
 <table id="debug_error" class="debug_table hidden">
665
 <table id="debug_error" class="debug_table hidden">
618
             $Queries = $this->get_queries();
690
             $Queries = $this->get_queries();
619
             $Header .= ' ('.number_format($this->get_query_time(), 5).' ms)';
691
             $Header .= ' ('.number_format($this->get_query_time(), 5).' ms)';
620
         }
692
         }
693
+
621
         if (empty($Queries)) {
694
         if (empty($Queries)) {
622
             return;
695
             return;
623
         }
696
         }
624
         $Header = ' '.number_format(count($Queries))." $Header:"; ?>
697
         $Header = ' '.number_format(count($Queries))." $Header:"; ?>
698
+
625
 <table class="layout">
699
 <table class="layout">
626
   <tr>
700
   <tr>
627
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_database').gtoggle(); return false;"
628
-          class="brackets">View</a><?=$Header?></strong></td>
701
+    <td>
702
+      <strong>
703
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_database').gtoggle(); return false;"
704
+          class="brackets">View</a>
705
+        <?=$Header?>
706
+      </strong>
707
+    </td>
629
   </tr>
708
   </tr>
630
 </table>
709
 </table>
710
+
631
 <table id="debug_database" class="debug_table hidden">
711
 <table id="debug_database" class="debug_table hidden">
632
   <?php
712
   <?php
633
     foreach ($Queries as $Query) {
713
     foreach ($Queries as $Query) {
634
         $SQL = $Query[0] ?? null;
714
         $SQL = $Query[0] ?? null;
635
         $Time = $Query[1] ?? null;
715
         $Time = $Query[1] ?? null;
636
         $Warnings = $Query[2] ?? null;
716
         $Warnings = $Query[2] ?? null;
717
+
637
         if ($Warnings !== null) {
718
         if ($Warnings !== null) {
638
             $Warnings = implode('<br />', $Warnings);
719
             $Warnings = implode('<br />', $Warnings);
639
         } ?>
720
         } ?>
721
+
640
   <tr class="valign_top">
722
   <tr class="valign_top">
641
     <td class="debug_data debug_query_data">
723
     <td class="debug_data debug_query_data">
642
       <div><?=str_replace("\t", '&nbsp;&nbsp;', nl2br(display_str(trim($SQL))))?>
724
       <div><?=str_replace("\t", '&nbsp;&nbsp;', nl2br(display_str(trim($SQL))))?>
643
       </div>
725
       </div>
644
     </td>
726
     </td>
727
+
645
     <td class="debug_info debug_query_time" style="width: 130px;"><?=number_format($Time, 5)?> ms</td>
728
     <td class="debug_info debug_query_time" style="width: 130px;"><?=number_format($Time, 5)?> ms</td>
646
     <td class="debug_info debug_query_warnings"><?=$Warnings?>
729
     <td class="debug_info debug_query_warnings"><?=$Warnings?>
647
     </td>
730
     </td>
659
             $Queries = $this->get_sphinxql_queries();
742
             $Queries = $this->get_sphinxql_queries();
660
             $Header .= ' ('.number_format($this->get_sphinxql_time(), 5).' ms)';
743
             $Header .= ' ('.number_format($this->get_sphinxql_time(), 5).' ms)';
661
         }
744
         }
745
+
662
         if (empty($Queries)) {
746
         if (empty($Queries)) {
663
             return;
747
             return;
664
         }
748
         }
665
         $Header = ' '.number_format(count($Queries))." $Header:"; ?>
749
         $Header = ' '.number_format(count($Queries))." $Header:"; ?>
750
+
666
 <table class="layout">
751
 <table class="layout">
667
   <tr>
752
   <tr>
668
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_sphinx').gtoggle(); return false;"
669
-          class="brackets">View</a><?=$Header?></strong></td>
753
+    <td>
754
+      <strong>
755
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_sphinx').gtoggle(); return false;"
756
+          class="brackets">View</a>
757
+        <?=$Header?>
758
+      </strong>
759
+    </td>
670
   </tr>
760
   </tr>
671
 </table>
761
 </table>
672
 <table id="debug_sphinx" class="debug_table hidden">
762
 <table id="debug_sphinx" class="debug_table hidden">
695
             $Vars = $this->LoggedVars;
785
             $Vars = $this->LoggedVars;
696
         }
786
         }
697
         $Header = ' '.number_format(count($Vars))." $Header:"; ?>
787
         $Header = ' '.number_format(count($Vars))." $Header:"; ?>
788
+
698
 <table class="layout">
789
 <table class="layout">
699
   <tr>
790
   <tr>
700
-    <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_loggedvars').gtoggle(); return false;"
701
-          class="brackets">View</a><?=$Header?></strong></td>
791
+    <td>
792
+      <strong>
793
+        <a href="#" onclick="$(this).parents('.layout').next('#debug_loggedvars').gtoggle(); return false;"
794
+          class="brackets">View</a>
795
+        <?=$Header?>
796
+      </strong>
797
+    </td>
702
   </tr>
798
   </tr>
703
 </table>
799
 </table>
800
+
704
 <table id="debug_loggedvars" class="debug_table hidden">
801
 <table id="debug_loggedvars" class="debug_table hidden">
705
   <?php
802
   <?php
706
     foreach ($Vars as $ID => $Var) {
803
     foreach ($Vars as $ID => $Var) {
710
   <tr>
807
   <tr>
711
     <td class="debug_info debug_loggedvars_name">
808
     <td class="debug_info debug_loggedvars_name">
712
       <a href="#"
809
       <a href="#"
713
-        onclick="$('#debug_loggedvars_<?=$ID?>').gtoggle(); return false;"><?=display_str($Key)?></a> (<?=$Size . ($Size == 1 ? ' element' : ' elements')?>)
714
-      <div><?=$Data['bt']['path'].':'.$Data['bt']['line']; ?>
810
+        onclick="$('#debug_loggedvars_<?=$ID?>').gtoggle(); return false;"><?=display_str($Key)?></a>
811
+      (<?=$Size . ($Size == 1 ? ' element' : ' elements')?>)
812
+      <div>
813
+        <?=$Data['bt']['path'].':'.$Data['bt']['line']; ?>
715
       </div>
814
       </div>
716
     </td>
815
     </td>
717
     <td class="debug_data debug_loggedvars_data">
816
     <td class="debug_data debug_loggedvars_data">
718
       <pre id="debug_loggedvars_<?=$ID?>" class="hidden">
817
       <pre id="debug_loggedvars_<?=$ID?>" class="hidden">
719
-<?=         display_str(print_r($Data['data'], true))?>
818
+<?=display_str(print_r($Data['data'], true))?>
720
         </pre>
819
         </pre>
721
     </td>
820
     </td>
722
   </tr>
821
   </tr>

+ 110
- 88
classes/forums.class.php View File

15
         if ((!$ThreadInfo = G::$Cache->get_value('thread_' . $ThreadID . '_info')) || !isset($ThreadInfo['Ranking'])) {
15
         if ((!$ThreadInfo = G::$Cache->get_value('thread_' . $ThreadID . '_info')) || !isset($ThreadInfo['Ranking'])) {
16
             $QueryID = G::$DB->get_query_id();
16
             $QueryID = G::$DB->get_query_id();
17
             G::$DB->query("
17
             G::$DB->query("
18
-        SELECT
19
-          t.Title,
20
-          t.ForumID,
21
-          t.IsLocked,
22
-          t.IsSticky,
23
-          COUNT(fp.id) AS Posts,
24
-          t.LastPostAuthorID,
25
-          ISNULL(p.TopicID) AS NoPoll,
26
-          t.StickyPostID,
27
-          t.AuthorID as OP,
28
-          t.Ranking
29
-        FROM forums_topics AS t
30
-          JOIN forums_posts AS fp ON fp.TopicID = t.ID
31
-          LEFT JOIN forums_polls AS p ON p.TopicID = t.ID
32
-        WHERE t.ID = ?
33
-        GROUP BY fp.TopicID", $ThreadID);
18
+            SELECT
19
+              t.Title,
20
+              t.ForumID,
21
+              t.IsLocked,
22
+              t.IsSticky,
23
+              COUNT(fp.id) AS Posts,
24
+              t.LastPostAuthorID,
25
+              ISNULL(p.TopicID) AS NoPoll,
26
+              t.StickyPostID,
27
+              t.AuthorID as OP,
28
+              t.Ranking
29
+            FROM forums_topics AS t
30
+              JOIN forums_posts AS fp ON fp.TopicID = t.ID
31
+              LEFT JOIN forums_polls AS p ON p.TopicID = t.ID
32
+            WHERE t.ID = ?
33
+            GROUP BY fp.TopicID", $ThreadID);
34
+
34
             if (!G::$DB->has_results()) {
35
             if (!G::$DB->has_results()) {
35
                 G::$DB->set_query_id($QueryID);
36
                 G::$DB->set_query_id($QueryID);
36
                 return null;
37
                 return null;
37
             }
38
             }
39
+
38
             $ThreadInfo = G::$DB->next_record(MYSQLI_ASSOC, false);
40
             $ThreadInfo = G::$DB->next_record(MYSQLI_ASSOC, false);
39
             if ($ThreadInfo['StickyPostID']) {
41
             if ($ThreadInfo['StickyPostID']) {
40
                 $ThreadInfo['Posts']--;
42
                 $ThreadInfo['Posts']--;
41
                 G::$DB->query(
43
                 G::$DB->query(
42
-            "SELECT
43
-            p.ID,
44
-            p.AuthorID,
45
-            p.AddedTime,
46
-            p.Body,
47
-            p.EditedUserID,
48
-            p.EditedTime,
49
-            ed.Username
50
-            FROM forums_posts AS p
51
-              LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
52
-            WHERE p.TopicID = ?
53
-              AND p.ID = ?",
54
-            $ThreadID,
55
-            $ThreadInfo['StickyPostID']
56
-        );
44
+                    "
45
+                SELECT
46
+                  p.ID,
47
+                  p.AuthorID,
48
+                  p.AddedTime,
49
+                  p.Body,
50
+                  p.EditedUserID,
51
+                  p.EditedTime,
52
+                  ed.Username
53
+                FROM forums_posts AS p
54
+                  LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
55
+                WHERE p.TopicID = ?
56
+                  AND p.ID = ?",
57
+                    $ThreadID,
58
+                    $ThreadInfo['StickyPostID']
59
+                );
57
                 list($ThreadInfo['StickyPost']) = G::$DB->to_array(false, MYSQLI_ASSOC);
60
                 list($ThreadInfo['StickyPost']) = G::$DB->to_array(false, MYSQLI_ASSOC);
58
             }
61
             }
62
+
59
             G::$DB->set_query_id($QueryID);
63
             G::$DB->set_query_id($QueryID);
60
             if (!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
64
             if (!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
61
                 G::$Cache->cache_value('thread_' . $ThreadID . '_info', $ThreadInfo, 0);
65
                 G::$Cache->cache_value('thread_' . $ThreadID . '_info', $ThreadInfo, 0);
62
             }
66
             }
63
         }
67
         }
68
+        
64
         if ($Return) {
69
         if ($Return) {
65
             return $ThreadInfo;
70
             return $ThreadInfo;
66
         }
71
         }
79
         if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 1) {
84
         if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 1) {
80
             return true;
85
             return true;
81
         }
86
         }
87
+
82
         if ($ForumID == DONOR_FORUM && Donations::has_donor_forum(G::$LoggedUser['ID'])) {
88
         if ($ForumID == DONOR_FORUM && Donations::has_donor_forum(G::$LoggedUser['ID'])) {
83
             return true;
89
             return true;
84
         }
90
         }
91
+
85
         if ($Forums[$ForumID]['MinClass' . $Perm] > G::$LoggedUser['Class'] && (!isset(G::$LoggedUser['CustomForums'][$ForumID]) || G::$LoggedUser['CustomForums'][$ForumID] == 0)) {
92
         if ($Forums[$ForumID]['MinClass' . $Perm] > G::$LoggedUser['Class'] && (!isset(G::$LoggedUser['CustomForums'][$ForumID]) || G::$LoggedUser['CustomForums'][$ForumID] == 0)) {
86
             return false;
93
             return false;
87
         }
94
         }
95
+        
88
         if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 0) {
96
         if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 0) {
89
             return false;
97
             return false;
90
         }
98
         }
102
         if (!$Forum) {
110
         if (!$Forum) {
103
             $QueryID = G::$DB->get_query_id();
111
             $QueryID = G::$DB->get_query_id();
104
             G::$DB->query("
112
             G::$DB->query("
105
-        SELECT
106
-          Name,
107
-          MinClassRead,
108
-          MinClassWrite,
109
-          MinClassCreate,
110
-          COUNT(forums_topics.ID) AS Topics
111
-        FROM forums
112
-          LEFT JOIN forums_topics ON forums_topics.ForumID = forums.ID
113
-        WHERE forums.ID = ?
114
-        GROUP BY ForumID", $ForumID);
113
+            SELECT
114
+              Name,
115
+              MinClassRead,
116
+              MinClassWrite,
117
+              MinClassCreate,
118
+              COUNT(forums_topics.ID) AS Topics
119
+            FROM forums
120
+              LEFT JOIN forums_topics ON forums_topics.ForumID = forums.ID
121
+            WHERE forums.ID = ?
122
+              GROUP BY ForumID", $ForumID);
123
+
115
             if (!G::$DB->has_results()) {
124
             if (!G::$DB->has_results()) {
116
                 return false;
125
                 return false;
117
             }
126
             }
127
+
118
             // Makes an array, with $Forum['Name'], etc.
128
             // Makes an array, with $Forum['Name'], etc.
119
             $Forum = G::$DB->next_record(MYSQLI_ASSOC);
129
             $Forum = G::$DB->next_record(MYSQLI_ASSOC);
120
 
130
 
121
             G::$DB->set_query_id($QueryID);
131
             G::$DB->set_query_id($QueryID);
122
-
123
             G::$Cache->cache_value("ForumInfo_$ForumID", $Forum, 86400);
132
             G::$Cache->cache_value("ForumInfo_$ForumID", $Forum, 86400);
124
         }
133
         }
125
         return $Forum;
134
         return $Forum;
135
         if ($ForumCats === false) {
144
         if ($ForumCats === false) {
136
             $QueryID = G::$DB->get_query_id();
145
             $QueryID = G::$DB->get_query_id();
137
             G::$DB->query("
146
             G::$DB->query("
138
-        SELECT ID, Name
139
-        FROM forums_categories");
147
+            SELECT ID, Name
148
+            FROM forums_categories");
149
+
140
             $ForumCats = [];
150
             $ForumCats = [];
141
             while (list($ID, $Name) = G::$DB->next_record()) {
151
             while (list($ID, $Name) = G::$DB->next_record()) {
142
                 $ForumCats[$ID] = $Name;
152
                 $ForumCats[$ID] = $Name;
143
             }
153
             }
154
+
144
             G::$DB->set_query_id($QueryID);
155
             G::$DB->set_query_id($QueryID);
145
             G::$Cache->cache_value('forums_categories', $ForumCats, 0);
156
             G::$Cache->cache_value('forums_categories', $ForumCats, 0);
146
         }
157
         }
156
         if (!$Forums = G::$Cache->get_value('forums_list')) {
167
         if (!$Forums = G::$Cache->get_value('forums_list')) {
157
             $QueryID = G::$DB->get_query_id();
168
             $QueryID = G::$DB->get_query_id();
158
             G::$DB->query("
169
             G::$DB->query("
159
-        SELECT
160
-          f.ID,
161
-          f.CategoryID,
162
-          f.Name,
163
-          f.Description,
164
-          f.MinClassRead AS MinClassRead,
165
-          f.MinClassWrite AS MinClassWrite,
166
-          f.MinClassCreate AS MinClassCreate,
167
-          f.NumTopics,
168
-          f.NumPosts,
169
-          f.LastPostID,
170
-          f.LastPostAuthorID,
171
-          f.LastPostTopicID,
172
-          f.LastPostTime,
173
-          0 AS SpecificRules,
174
-          t.Title,
175
-          t.IsLocked AS Locked,
176
-          t.IsSticky AS Sticky
177
-        FROM forums AS f
178
-          JOIN forums_categories AS fc ON fc.ID = f.CategoryID
179
-          LEFT JOIN forums_topics AS t ON t.ID = f.LastPostTopicID
180
-        GROUP BY f.ID
181
-        ORDER BY fc.Sort, fc.Name, f.CategoryID, f.Sort");
170
+            SELECT
171
+              f.ID,
172
+              f.CategoryID,
173
+              f.Name,
174
+              f.Description,
175
+              f.MinClassRead AS MinClassRead,
176
+              f.MinClassWrite AS MinClassWrite,
177
+              f.MinClassCreate AS MinClassCreate,
178
+              f.NumTopics,
179
+              f.NumPosts,
180
+              f.LastPostID,
181
+              f.LastPostAuthorID,
182
+              f.LastPostTopicID,
183
+              f.LastPostTime,
184
+              0 AS SpecificRules,
185
+              t.Title,
186
+              t.IsLocked AS Locked,
187
+              t.IsSticky AS Sticky
188
+            FROM forums AS f
189
+              JOIN forums_categories AS fc ON fc.ID = f.CategoryID
190
+              LEFT JOIN forums_topics AS t ON t.ID = f.LastPostTopicID
191
+            GROUP BY f.ID
192
+              ORDER BY fc.Sort, fc.Name, f.CategoryID, f.Sort");
182
             $Forums = G::$DB->to_array('ID', MYSQLI_ASSOC, false);
193
             $Forums = G::$DB->to_array('ID', MYSQLI_ASSOC, false);
183
 
194
 
184
             G::$DB->query("
195
             G::$DB->query("
185
-        SELECT ForumID, ThreadID
186
-        FROM forums_specific_rules");
196
+            SELECT ForumID, ThreadID
197
+            FROM forums_specific_rules");
198
+
187
             $SpecificRules = [];
199
             $SpecificRules = [];
188
             while (list($ForumID, $ThreadID) = G::$DB->next_record(MYSQLI_NUM, false)) {
200
             while (list($ForumID, $ThreadID) = G::$DB->next_record(MYSQLI_NUM, false)) {
189
                 $SpecificRules[$ForumID][] = $ThreadID;
201
                 $SpecificRules[$ForumID][] = $ThreadID;
190
             }
202
             }
203
+
191
             G::$DB->set_query_id($QueryID);
204
             G::$DB->set_query_id($QueryID);
192
             foreach ($Forums as $ForumID => &$Forum) {
205
             foreach ($Forums as $ForumID => &$Forum) {
193
                 if (isset($SpecificRules[$ForumID])) {
206
                 if (isset($SpecificRules[$ForumID])) {
239
         } else {
252
         } else {
240
             $PerPage = POSTS_PER_PAGE;
253
             $PerPage = POSTS_PER_PAGE;
241
         }
254
         }
255
+
242
         $TopicIDs = [];
256
         $TopicIDs = [];
243
         foreach ($Forums as $Forum) {
257
         foreach ($Forums as $Forum) {
244
             if (!empty($Forum['LastPostTopicID'])) {
258
             if (!empty($Forum['LastPostTopicID'])) {
245
                 $TopicIDs[] = $Forum['LastPostTopicID'];
259
                 $TopicIDs[] = $Forum['LastPostTopicID'];
246
             }
260
             }
247
         }
261
         }
262
+
248
         if (!empty($TopicIDs)) {
263
         if (!empty($TopicIDs)) {
249
             $QueryID = G::$DB->get_query_id();
264
             $QueryID = G::$DB->get_query_id();
250
             G::$DB->query("
265
             G::$DB->query("
251
-        SELECT
252
-          l.TopicID,
253
-          l.PostID,
254
-          CEIL(
255
-            (
256
-              SELECT
257
-                COUNT(p.ID)
258
-              FROM forums_posts AS p
259
-              WHERE p.TopicID = l.TopicID
260
-                AND p.ID <= l.PostID
261
-            ) / ?
262
-          ) AS Page
263
-        FROM forums_last_read_topics AS l
264
-        WHERE l.TopicID IN(" . implode(',', $TopicIDs) . ") AND
265
-          l.UserID = ?", $PerPage, G::$LoggedUser['ID']);
266
+            SELECT
267
+              l.TopicID,
268
+              l.PostID,
269
+              CEIL(
270
+                (
271
+                  SELECT
272
+                  COUNT(p.ID)
273
+                  FROM forums_posts AS p
274
+                    WHERE p.TopicID = l.TopicID
275
+                    AND p.ID <= l.PostID
276
+                ) / ?
277
+              ) AS Page
278
+            FROM forums_last_read_topics AS l
279
+              WHERE l.TopicID IN(" . implode(',', $TopicIDs) . ") AND
280
+              l.UserID = ?", $PerPage, G::$LoggedUser['ID']);
281
+
266
             $LastRead = G::$DB->to_array('TopicID', MYSQLI_ASSOC);
282
             $LastRead = G::$DB->to_array('TopicID', MYSQLI_ASSOC);
267
             G::$DB->set_query_id($QueryID);
283
             G::$DB->set_query_id($QueryID);
268
         } else {
284
         } else {
283
         if ($UserID === null) {
299
         if ($UserID === null) {
284
             $UserID = G::$LoggedUser['ID'];
300
             $UserID = G::$LoggedUser['ID'];
285
         }
301
         }
302
+
286
         $QueryID = G::$DB->get_query_id();
303
         $QueryID = G::$DB->get_query_id();
287
         G::$DB->query("
304
         G::$DB->query("
288
-      INSERT INTO forums_topic_notes
289
-        (TopicID, AuthorID, AddedTime, Body)
290
-      VALUES
291
-        (?, ?, NOW(), ?)", $TopicID, $UserID, $Note);
305
+        INSERT INTO forums_topic_notes
306
+          (TopicID, AuthorID, AddedTime, Body)
307
+        VALUES
308
+          (?, ?, NOW(), ?)", $TopicID, $UserID, $Note);
309
+
292
         G::$DB->set_query_id($QueryID);
310
         G::$DB->set_query_id($QueryID);
293
         return (bool)G::$DB->affected_rows();
311
         return (bool)G::$DB->affected_rows();
294
     }
312
     }
318
         // I couldn't come up with a good name, please rename this if you can. -- Y
336
         // I couldn't come up with a good name, please rename this if you can. -- Y
319
         $RestrictedForums = self::get_restricted_forums();
337
         $RestrictedForums = self::get_restricted_forums();
320
         $PermittedForums = self::get_permitted_forums();
338
         $PermittedForums = self::get_permitted_forums();
339
+
321
         if (Donations::has_donor_forum(G::$LoggedUser['ID']) && !in_array(DONOR_FORUM, $PermittedForums)) {
340
         if (Donations::has_donor_forum(G::$LoggedUser['ID']) && !in_array(DONOR_FORUM, $PermittedForums)) {
322
             $PermittedForums[] = DONOR_FORUM;
341
             $PermittedForums[] = DONOR_FORUM;
323
         }
342
         }
343
+
324
         $SQL = "((f.MinClassRead <= '" . G::$LoggedUser['Class'] . "'";
344
         $SQL = "((f.MinClassRead <= '" . G::$LoggedUser['Class'] . "'";
325
         if (count($RestrictedForums)) {
345
         if (count($RestrictedForums)) {
326
             $SQL .= " AND f.ID NOT IN ('" . implode("', '", $RestrictedForums) . "')";
346
             $SQL .= " AND f.ID NOT IN ('" . implode("', '", $RestrictedForums) . "')";
327
         }
347
         }
348
+
328
         $SQL .= ')';
349
         $SQL .= ')';
329
         if (count($PermittedForums)) {
350
         if (count($PermittedForums)) {
330
             $SQL .= " OR f.ID IN ('" . implode("', '", $PermittedForums) . "')";
351
             $SQL .= " OR f.ID IN ('" . implode("', '", $PermittedForums) . "')";
331
         }
352
         }
353
+        
332
         $SQL .= ')';
354
         $SQL .= ')';
333
         return $SQL;
355
         return $SQL;
334
     }
356
     }

+ 241
- 209
classes/mass_user_torrents_table_view.class.php View File

10
  *
10
  *
11
  * It can be used for Bookmarks, Collages, or anywhere where torrents are managed.
11
  * It can be used for Bookmarks, Collages, or anywhere where torrents are managed.
12
  */
12
  */
13
-class MASS_USER_TORRENTS_TABLE_VIEW {
14
-  /**
15
-   * Used to set text the page heading (h2 tag)
16
-   * @var string $Heading
17
-   */
18
-  private $Heading = 'Manage Torrents';
19
-
20
-  /**
21
-   * Sets the value of the input name="type"
22
-   * Later to be used as $_POST['type'] in a form processor
23
-   * @var string $EditType
24
-   */
25
-  private $EditType;
26
-
27
-  /**
28
-   * Flag for empty $TorrentList
29
-   * @var bool $HasTorrentList
30
-   */
31
-  private $HasTorrents;
32
-
33
-  /**
34
-   * Internal reference to the TorrentList
35
-   * @var array $TorrentList
36
-   */
37
-  private $TorrentList;
38
-
39
-  /**
40
-   * Ref. to $CollageDataList
41
-   * @var array $CollageDataList
42
-   */
43
-  private $CollageDataList;
44
-
45
-  /**
46
-   * Counter for number of groups
47
-   * @var in $NumGroups
48
-   */
49
-  private $NumGroups = 0;
50
-
51
-  /**
52
-   * When creating a new instance of this class, TorrentList and
53
-   * CollageDataList must be passed. Additionally, a heading can be added.
54
-   *
55
-   * @param array $TorrentList
56
-   * @param array $CollageDataList
57
-   * @param string $EditType
58
-   * @param string $Heading
59
-   */
60
-  public function __construct (array &$TorrentList, array &$CollageDataList, $EditType, $Heading = null) {
61
-    $this->set_heading($Heading);
62
-    $this->set_edit_type($EditType);
63
-
64
-    $this->TorrentList = $TorrentList;
65
-    $this->CollageDataList = $CollageDataList;
66
-
67
-    $this->HasTorrents = !empty($TorrentList);
68
-    if (!$this->HasTorrents) {
69
-      $this->no_torrents();
13
+class MASS_USER_TORRENTS_TABLE_VIEW
14
+{
15
+    /**
16
+     * Used to set text the page heading (h2 tag)
17
+     * @var string $Heading
18
+     */
19
+    private $Heading = 'Manage Torrents';
20
+
21
+    /**
22
+     * Sets the value of the input name="type"
23
+     * Later to be used as $_POST['type'] in a form processor
24
+     * @var string $EditType
25
+     */
26
+    private $EditType;
27
+
28
+    /**
29
+     * Flag for empty $TorrentList
30
+     * @var bool $HasTorrentList
31
+     */
32
+    private $HasTorrents;
33
+
34
+    /**
35
+     * Internal reference to the TorrentList
36
+     * @var array $TorrentList
37
+     */
38
+    private $TorrentList;
39
+
40
+    /**
41
+     * Ref. to $CollageDataList
42
+     * @var array $CollageDataList
43
+     */
44
+    private $CollageDataList;
45
+
46
+    /**
47
+     * Counter for number of groups
48
+     * @var in $NumGroups
49
+     */
50
+    private $NumGroups = 0;
51
+
52
+    /**
53
+     * When creating a new instance of this class, TorrentList and
54
+     * CollageDataList must be passed. Additionally, a heading can be added.
55
+     *
56
+     * @param array $TorrentList
57
+     * @param array $CollageDataList
58
+     * @param string $EditType
59
+     * @param string $Heading
60
+     */
61
+    public function __construct(array &$TorrentList, array &$CollageDataList, $EditType, $Heading = null)
62
+    {
63
+        $this->set_heading($Heading);
64
+        $this->set_edit_type($EditType);
65
+
66
+        $this->TorrentList = $TorrentList;
67
+        $this->CollageDataList = $CollageDataList;
68
+
69
+        $this->HasTorrents = !empty($TorrentList);
70
+        if (!$this->HasTorrents) {
71
+            $this->no_torrents();
72
+        }
73
+    }
74
+
75
+    private function no_torrents()
76
+    {
77
+        ?>
78
+<div class="thin">
79
+  <div class="header">
80
+    <h2>No torrents found</h2>
81
+  </div>
82
+  <div class="box pad" align="center">
83
+    <p>Add some torrents and come back later</p>
84
+  </div>
85
+</div>
86
+<?php
87
+    }
88
+
89
+    /**
90
+     * Renders a complete page and table
91
+     */
92
+    public function render_all()
93
+    {
94
+        $this->header();
95
+        $this->body();
96
+        $this->footer();
70
     }
97
     }
71
-  }
72
-
73
-  private function no_torrents () {
74
-?>
75
-    <div class="thin">
76
-      <div class="header">
77
-        <h2>No torrents found.</h2>
78
-      </div>
79
-      <div class="box pad" align="center">
80
-        <p>Add some torrents and come back later.</p>
81
-      </div>
82
-    </div>
83
-<?
84
-  }
85
-
86
-  /**
87
-   * Renders a complete page and table
88
-   */
89
-  public function render_all () {
90
-    $this->header();
91
-    $this->body();
92
-    $this->footer();
93
-  }
94
-
95
-  /**
96
-   * Renders a comptele page/table header: div#thin, h2, scripts, notes,
97
-   * form, table, etc.
98
-   */
99
-  public function header () {
100
-    if ($this->HasTorrents) {
101
-?>
102
 
98
 
99
+    /**
100
+     * Renders a comptele page/table header: div#thin, h2, scripts, notes,
101
+     * form, table, etc.
102
+     */
103
+    public function header()
104
+    {
105
+        if ($this->HasTorrents) {
106
+            ?>
103
 <div class="thin">
107
 <div class="thin">
104
   <div class="header">
108
   <div class="header">
105
-    <h2><?=display_str($this->Heading)?></h2>
109
+    <h2><?=display_str($this->Heading)?>
110
+    </h2>
106
   </div>
111
   </div>
107
 
112
 
108
   <table width="100%" class="layout box">
113
   <table width="100%" class="layout box">
109
-    <tr class="colhead"><td id="sorting_head">Sorting</td></tr>
114
+    <tr class="colhead">
115
+      <td id="sorting_head">Sorting</td>
116
+    </tr>
117
+
110
     <tr>
118
     <tr>
111
       <td id="drag_drop_textnote">
119
       <td id="drag_drop_textnote">
112
-      <ul>
113
-        <li>Click on the headings to organize columns automatically.</li>
114
-        <li>Sort multiple columns simultaneously by holding down the shift key and clicking other column headers.</li>
115
-        <li>Click and drag any row to change its order.</li>
116
-        <li>Double-click on a row to check it.</li>
117
-      </ul>
120
+        <ul>
121
+          <li>Click on the headings to organize columns automatically.</li>
122
+          <li>Sort multiple columns simultaneously by holding down the shift key and clicking other column headers.</li>
123
+          <li>Click and drag any row to change its order.</li>
124
+          <li>Double-click on a row to check it.</li>
125
+        </ul>
118
       </td>
126
       </td>
119
     </tr>
127
     </tr>
120
   </table>
128
   </table>
121
 
129
 
122
   <form action="bookmarks.php" method="post" id="drag_drop_collage_form">
130
   <form action="bookmarks.php" method="post" id="drag_drop_collage_form">
123
 
131
 
124
-<?      $this->buttons(); ?>
132
+    <?php $this->buttons(); ?>
125
 
133
 
126
     <table id="manage_collage_table" class="box">
134
     <table id="manage_collage_table" class="box">
127
       <thead>
135
       <thead>
136
         </tr>
144
         </tr>
137
       </thead>
145
       </thead>
138
       <tbody>
146
       <tbody>
139
-<?
147
+        <?php
148
+        }
140
     }
149
     }
141
-  }
142
-
143
-  /**
144
-   * Closes header code
145
-   */
146
-  public function footer () {
147
-    if ($this->HasTorrents) {
148
-?>
149
 
150
 
151
+    /**
152
+     * Closes header code
153
+     */
154
+    public function footer()
155
+    {
156
+        if ($this->HasTorrents) {
157
+            ?>
150
       </tbody>
158
       </tbody>
151
     </table>
159
     </table>
152
 
160
 
153
-<?      $this->buttons(); ?>
161
+    <?php $this->buttons(); ?>
154
 
162
 
155
     <div>
163
     <div>
156
       <input type="hidden" name="action" value="mass_edit" />
164
       <input type="hidden" name="action" value="mass_edit" />
157
-      <input type="hidden" name="type" value="<?=display_str($this->EditType)?>" />
158
-      <input type="hidden" name="auth" value="<?=G::$LoggedUser['AuthKey']?>" />
165
+      <input type="hidden" name="type"
166
+        value="<?=display_str($this->EditType)?>" />
167
+      <input type="hidden" name="auth"
168
+        value="<?=G::$LoggedUser['AuthKey']?>" />
159
     </div>
169
     </div>
160
   </form>
170
   </form>
161
 </div>
171
 </div>
172
+<?php
173
+        }
174
+    }
162
 
175
 
163
-<?
176
+    /**
177
+     * Formats data for use in row
178
+     *
179
+     */
180
+    public function body()
181
+    {
182
+        if ($this->HasTorrents) {
183
+            foreach ($this->TorrentList as $GroupID => $Group) {
184
+                $Artists = [];
185
+
186
+                extract($Group);
187
+                extract($this->CollageDataList[$GroupID]);
188
+
189
+                $this->NumGroups++;
190
+
191
+                $DisplayName = self::display_name($ExtendedArtists, $Artists, $VanityHouse);
192
+                $TorrentLink = '<a href="torrents.php?id='.$GroupID.'" class="tooltip" title="View torrent">'.$Name.'</a>';
193
+                $Year = $Year > 0 ? $Year : '';
194
+                $DateAdded = date($Time);
195
+
196
+                $this->row($Sort, $GroupID, $Year, $DisplayName, $TorrentLink, $DateAdded);
197
+            }
198
+        }
164
     }
199
     }
165
-  }
166
-
167
-  /**
168
-   * Formats data for use in row
169
-   *
170
-   */
171
-  public function body () {
172
-    if ($this->HasTorrents)
173
-      foreach ($this->TorrentList as $GroupID => $Group) {
174
-        $Artists = [];
175
-
176
-        extract($Group);
177
-        extract($this->CollageDataList[$GroupID]);
178
-
179
-        $this->NumGroups++;
180
-
181
-        $DisplayName = self::display_name($ExtendedArtists, $Artists, $VanityHouse);
182
-        $TorrentLink = '<a href="torrents.php?id='.$GroupID.'" class="tooltip" title="View torrent">'.$Name.'</a>';
183
-        $Year = $Year > 0 ? $Year : '';
184
-        $DateAdded = date($Time);
185
-
186
-        $this->row($Sort, $GroupID, $Year, $DisplayName, $TorrentLink, $DateAdded);
187
-      }
188
-  }
189
-
190
-  /**
191
-   * Outputs a single row
192
-   *
193
-   * @param string|int $Sort
194
-   * @param string|int $GroupID
195
-   * @param string|int $GroupYear
196
-   * @param string $DisplayName
197
-   * @param string $TorrentLink
198
-   */
199
-  public function row ($Sort, $GroupID, $GroupYear, $DisplayName, $TorrentLink, $DateAdded) {
200
-?>
201
-
202
-          <tr class="drag row" id="li_<?=$GroupID?>">
203
-            <td>
204
-              <input class="sort_numbers" type="text" name="sort[<?=$GroupID?>]" value="<?=$Sort?>" id="sort_<?=$GroupID?>" size="4" />
205
-            </td>
206
-            <td><?=$this->NumGroups?></td>
207
-            <td><?=$GroupYear ? trim($GroupYear) : ' '?></td>
208
-            <td><?=$DisplayName ? trim($DisplayName) : ' '?></td>
209
-            <td><?=$TorrentLink ? trim($TorrentLink) : ' '?></td>
210
-            <td class="nobr tooltip" title="<?=$DateAdded?>"><?=$DateAdded ? time_diff($DateAdded) : ' '?></td>
211
-            <td class="center"><input type="checkbox" name="remove[<?=$GroupID?>]" value="" /></td>
212
-          </tr>
213
-<?
214
-  }
215
-
216
-  /**
217
-   * Parses a simple display name
218
-   *
219
-   * @param array $ExtendedArtists
220
-   * @param array $Artists
221
-   * @param string $VanityHouse
222
-   * @return string $DisplayName
223
-   */
224
-  public static function display_name (array &$ExtendedArtists, array &$Artists, $VanityHouse) {
225
-    $DisplayName = '';
226
-    if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4])
227
-        || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
228
-      unset($ExtendedArtists[2], $ExtendedArtists[3]);
229
-      $DisplayName = Artists::display_artists($ExtendedArtists, true, false);
230
-    } elseif (count($Artists) > 0) {
231
-      $DisplayName = Artists::display_artists(array('1'=>$Artists), true, false);
200
+
201
+    /**
202
+     * Outputs a single row
203
+     *
204
+     * @param string|int $Sort
205
+     * @param string|int $GroupID
206
+     * @param string|int $GroupYear
207
+     * @param string $DisplayName
208
+     * @param string $TorrentLink
209
+     */
210
+    public function row($Sort, $GroupID, $GroupYear, $DisplayName, $TorrentLink, $DateAdded)
211
+    {
212
+        ?>
213
+<tr class="drag row" id="li_<?=$GroupID?>">
214
+  <td>
215
+    <input class="sort_numbers" type="text"
216
+      name="sort[<?=$GroupID?>]"
217
+      value="<?=$Sort?>"
218
+      id="sort_<?=$GroupID?>" size="4" />
219
+  </td>
220
+
221
+  <td><?=$this->NumGroups?>
222
+  </td>
223
+
224
+  <td><?=$GroupYear ? trim($GroupYear) : ' '?>
225
+  </td>
226
+
227
+  <td><?=$DisplayName ? trim($DisplayName) : ' '?>
228
+  </td>
229
+
230
+  <td><?=$TorrentLink ? trim($TorrentLink) : ' '?>
231
+  </td>
232
+
233
+  <td class="nobr tooltip" title="<?=$DateAdded?>"><?=$DateAdded ? time_diff($DateAdded) : ' '?>
234
+  </td>
235
+
236
+  <td class="center"><input type="checkbox"
237
+      name="remove[<?=$GroupID?>]" value="" /></td>
238
+</tr>
239
+<?php
232
     }
240
     }
233
-    if ($VanityHouse) {
234
-      $DisplayName .= ' [<abbr class="tooltip" title="This is a Vanity House release">VH</abbr>]';
241
+
242
+    /**
243
+     * Parses a simple display name
244
+     *
245
+     * @param array $ExtendedArtists
246
+     * @param array $Artists
247
+     * @param string $VanityHouse
248
+     * @return string $DisplayName
249
+     */
250
+    public static function display_name(array &$ExtendedArtists, array &$Artists, $VanityHouse)
251
+    {
252
+        $DisplayName = '';
253
+        if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4])
254
+         || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
255
+            unset($ExtendedArtists[2], $ExtendedArtists[3]);
256
+            $DisplayName = Artists::display_artists($ExtendedArtists, true, false);
257
+        } elseif (count($Artists) > 0) {
258
+            $DisplayName = Artists::display_artists(array('1'=>$Artists), true, false);
259
+        }
260
+
261
+        if ($VanityHouse) {
262
+            $DisplayName .= ' [<abbr class="tooltip" title="This is a Vanity House release">VH</abbr>]';
263
+        }
264
+        return $DisplayName;
265
+    }
266
+
267
+    /**
268
+     * Renders buttons used at the top and bottom of the table
269
+     */
270
+    public function buttons()
271
+    {
272
+        ?>
273
+<div class="drag_drop_save">
274
+  <input type="submit" name="update" value="Update ranking" title="Save your rank"
275
+    class="tooltip save_sortable_collage" />
276
+  <input type="submit" name="delete" value="Delete checked" title="Remove items"
277
+    class="tooltip save_sortable_collage" />
278
+</div>
279
+<?php
280
+    }
281
+
282
+    /**
283
+     * @param string $EditType
284
+     */
285
+    public function set_edit_type($EditType)
286
+    {
287
+        $this->EditType = $EditType;
288
+    }
289
+
290
+    /**
291
+     * Set's the current page's heading
292
+     * @param string $Heading
293
+     */
294
+    public function set_heading($Heading)
295
+    {
296
+        $this->Heading = $Heading;
235
     }
297
     }
236
-    return $DisplayName;
237
-  }
238
-
239
-  /**
240
-   * Renders buttons used at the top and bottom of the table
241
-   */
242
-  public function buttons () {
243
-?>
244
-    <div class="drag_drop_save">
245
-      <input type="submit" name="update" value="Update ranking" title="Save your rank" class="tooltip save_sortable_collage" />
246
-      <input type="submit" name="delete" value="Delete checked" title="Remove items" class="tooltip save_sortable_collage" />
247
-    </div>
248
-<?
249
-  }
250
-
251
-
252
-  /**
253
-   * @param string $EditType
254
-   */
255
-  public function set_edit_type ($EditType) {
256
-    $this->EditType = $EditType;
257
-  }
258
-
259
-  /**
260
-   * Set's the current page's heading
261
-   * @param string $Heading
262
-   */
263
-  public function set_heading ($Heading) {
264
-    $this->Heading = $Heading;
265
-  }
266
 }
298
 }

+ 3
- 4
classes/mediainfo.class.php View File

253
     }
253
     }
254
 
254
 
255
     public static function strip_path($string)
255
     public static function strip_path($string)
256
-    { // remove filepath
256
+    { // Remove filepath
257
         $string = str_replace("\\", "/", $string);
257
         $string = str_replace("\\", "/", $string);
258
         $path_parts = pathinfo($string);
258
         $path_parts = pathinfo($string);
259
         return $path_parts['basename'];
259
         return $path_parts['basename'];
502
             case 'mpeg-ts':
502
             case 'mpeg-ts':
503
                 $this->form_codec = 'MPEG-TS';
503
                 $this->form_codec = 'MPEG-TS';
504
                 break;
504
                 break;
505
-            // We can't determine if it's DVD5 or DVD9, so don't guess.
505
+            // We can't determine if it's DVD5 or DVD9, so don't guess
506
             case 'mpeg-ps':
506
             case 'mpeg-ps':
507
                 $this->form_codec = '---';
507
                 $this->form_codec = '---';
508
                 break;
508
                 break;
760
         switch (strtolower($codec)) {
760
         switch (strtolower($codec)) {
761
             case 'x264':
761
             case 'x264':
762
             case 'h264':
762
             case 'h264':
763
-                return strtolower($this->bitdepth) == '10 bits' ?
764
-                    'h264 10-bit' : 'h264';
763
+                return strtolower($this->bitdepth) == '10 bits' ? 'h264 10-bit' : 'h264';
765
             case 'h265':
764
             case 'h265':
766
                 return 'h265';
765
                 return 'h265';
767
             case 'xvid':
766
             case 'xvid':

+ 69
- 57
classes/paranoia.class.php View File

1
-<?
1
+<?php
2
 
2
 
3
-// Note: at the time this file is loaded, check_perms is not defined. Don't
4
-// call check_paranoia in /classes/script_start.php without ensuring check_perms has been defined
3
+// Note: at the time this file is loaded, check_perms is not defined.
4
+// Don't call check_paranoia in /classes/script_start.php without ensuring check_perms has been defined
5
 
5
 
6
 // The following are used throughout the site:
6
 // The following are used throughout the site:
7
 // uploaded, ratio, downloaded: stats
7
 // uploaded, ratio, downloaded: stats
37
  * @param $Paranoia The paranoia level to check against.
37
  * @param $Paranoia The paranoia level to check against.
38
  * @param $UserClass The user class to check against (Staff can see through paranoia of lower classed staff)
38
  * @param $UserClass The user class to check against (Staff can see through paranoia of lower classed staff)
39
  * @param $UserID Optional. The user ID of the person being viewed
39
  * @param $UserID Optional. The user ID of the person being viewed
40
- * @return mixed   1 representing the user has normal access
41
-           2 representing that the paranoia was overridden,
42
-           false representing access denied.
40
+ * @return mixed 1 representing the user has normal access
41
+ *               2 representing that the paranoia was overridden,
42
+ *               false representing access denied.
43
  */
43
  */
44
-
45
 define("PARANOIA_ALLOWED", 1);
44
 define("PARANOIA_ALLOWED", 1);
46
 define("PARANOIA_OVERRIDDEN", 2);
45
 define("PARANOIA_OVERRIDDEN", 2);
47
 
46
 
48
-function check_paranoia($Property, $Paranoia = false, $UserClass = false, $UserID = false) {
49
-  global $Classes;
50
-  if ($Property == false) {
51
-    return false;
52
-  }
53
-  if (!is_array($Paranoia)) {
54
-    $Paranoia = json_decode($Paranoia, true);
55
-  }
56
-  if (!is_array($Paranoia)) {
57
-    $Paranoia = [];
58
-  }
59
-  if (is_array($Property)) {
60
-    $all = true;
61
-    foreach ($Property as $P) {
62
-      $all = $all && check_paranoia($P, $Paranoia, $UserClass, $UserID);
63
-    }
64
-    return $all;
65
-  } else {
66
-    if (($UserID !== false) && (G::$LoggedUser['ID'] == $UserID)) {
67
-      return PARANOIA_ALLOWED;
47
+function check_paranoia($Property, $Paranoia = false, $UserClass = false, $UserID = false)
48
+{
49
+    global $Classes;
50
+    if ($Property == false) {
51
+        return false;
68
     }
52
     }
69
 
53
 
70
-    $May = !in_array($Property, $Paranoia) && !in_array($Property . '+', $Paranoia);
71
-    if ($May)
72
-      return PARANOIA_ALLOWED;
54
+    if (!is_array($Paranoia)) {
55
+        $Paranoia = json_decode($Paranoia, true);
56
+    }
73
 
57
 
74
-    if (check_perms('users_override_paranoia', $UserClass)) {
75
-      return PARANOIA_OVERRIDDEN;
58
+    if (!is_array($Paranoia)) {
59
+        $Paranoia = [];
76
     }
60
     }
77
-    $Override=false;
78
-    switch ($Property) {
79
-      case 'downloaded':
80
-      case 'ratio':
81
-      case 'uploaded':
82
-      case 'lastseen':
83
-        if (check_perms('users_mod', $UserClass))
84
-          return PARANOIA_OVERRIDDEN;
85
-        break;
86
-      case 'snatched': case 'snatched+':
87
-        if (check_perms('users_view_torrents_snatchlist', $UserClass))
88
-          return PARANOIA_OVERRIDDEN;
89
-        break;
90
-      case 'uploads': case 'uploads+':
91
-      case 'seeding': case 'seeding+':
92
-      case 'leeching': case 'leeching+':
93
-        if (check_perms('users_view_seedleech', $UserClass))
94
-          return PARANOIA_OVERRIDDEN;
95
-        break;
96
-      case 'invitedcount':
97
-        if (check_perms('users_view_invites', $UserClass))
98
-          return PARANOIA_OVERRIDDEN;
99
-        break;
61
+
62
+    if (is_array($Property)) {
63
+        $all = true;
64
+        foreach ($Property as $P) {
65
+            $all = $all && check_paranoia($P, $Paranoia, $UserClass, $UserID);
66
+        }
67
+        return $all;
68
+    } else {
69
+        if (($UserID !== false) && (G::$LoggedUser['ID'] == $UserID)) {
70
+            return PARANOIA_ALLOWED;
71
+        }
72
+
73
+        $May = !in_array($Property, $Paranoia) && !in_array($Property . '+', $Paranoia);
74
+        if ($May) {
75
+            return PARANOIA_ALLOWED;
76
+        }
77
+
78
+        if (check_perms('users_override_paranoia', $UserClass)) {
79
+            return PARANOIA_OVERRIDDEN;
80
+        }
81
+
82
+        $Override=false;
83
+        switch ($Property) {
84
+          case 'downloaded':
85
+          case 'ratio':
86
+          case 'uploaded':
87
+          case 'lastseen':
88
+            if (check_perms('users_mod', $UserClass)) {
89
+                return PARANOIA_OVERRIDDEN;
90
+            }
91
+            break;
92
+
93
+          case 'snatched': case 'snatched+':
94
+            if (check_perms('users_view_torrents_snatchlist', $UserClass)) {
95
+                return PARANOIA_OVERRIDDEN;
96
+            }
97
+            break;
98
+
99
+          case 'uploads': case 'uploads+':
100
+          case 'seeding': case 'seeding+':
101
+          case 'leeching': case 'leeching+':
102
+            if (check_perms('users_view_seedleech', $UserClass)) {
103
+                return PARANOIA_OVERRIDDEN;
104
+            }
105
+            break;
106
+            
107
+          case 'invitedcount':
108
+            if (check_perms('users_view_invites', $UserClass)) {
109
+                return PARANOIA_OVERRIDDEN;
110
+            }
111
+            break;
112
+        }
113
+        return false;
100
     }
114
     }
101
-    return false;
102
-  }
103
 }
115
 }

+ 9
- 5
classes/permissions_form.php View File

124
       <tr>
124
       <tr>
125
         <td>
125
         <td>
126
           <?php
126
           <?php
127
-          display_perm('site_leech', 'Can leech.');
127
+    display_perm('site_leech', 'Can leech.');
128
     display_perm('site_upload', 'Can upload.');
128
     display_perm('site_upload', 'Can upload.');
129
     display_perm('site_vote', 'Can vote on requests.');
129
     display_perm('site_vote', 'Can vote on requests.');
130
     display_perm('site_submit_requests', 'Can submit requests.');
130
     display_perm('site_submit_requests', 'Can submit requests.');
168
       </tr>
168
       </tr>
169
     </table>
169
     </table>
170
   </div>
170
   </div>
171
+
171
   <div class="permission_container">
172
   <div class="permission_container">
172
     <table>
173
     <table>
173
       <tr class="colhead">
174
       <tr class="colhead">
176
       <tr>
177
       <tr>
177
         <td>
178
         <td>
178
           <?php
179
           <?php
179
-          display_perm('users_edit_usernames', 'Can edit usernames.');
180
+    display_perm('users_edit_usernames', 'Can edit usernames.');
180
     display_perm('users_edit_ratio', 'Can edit anyone\'s upload/download amounts.');
181
     display_perm('users_edit_ratio', 'Can edit anyone\'s upload/download amounts.');
181
     display_perm('users_edit_own_ratio', 'Can edit own upload/download amounts.');
182
     display_perm('users_edit_own_ratio', 'Can edit own upload/download amounts.');
182
     display_perm('users_edit_titles', 'Can edit titles.');
183
     display_perm('users_edit_titles', 'Can edit titles.');
208
     display_perm('users_make_invisible', 'Can make users invisible');
209
     display_perm('users_make_invisible', 'Can make users invisible');
209
     display_perm('users_logout', 'Can log users out');
210
     display_perm('users_logout', 'Can log users out');
210
     display_perm('users_mod', 'Can access basic moderator tools (Admin comment)'); ?>
211
     display_perm('users_mod', 'Can access basic moderator tools (Admin comment)'); ?>
211
-          *Everything is only applicable to users with the same or lower class level
212
+          * Everything is only applicable to users with the same or lower class level
212
         </td>
213
         </td>
213
       </tr>
214
       </tr>
214
     </table>
215
     </table>
215
   </div>
216
   </div>
217
+
216
   <div class="permission_container">
218
   <div class="permission_container">
217
     <table>
219
     <table>
218
       <tr class="colhead">
220
       <tr class="colhead">
221
       <tr>
223
       <tr>
222
         <td>
224
         <td>
223
           <?php
225
           <?php
224
-          display_perm('torrents_edit', 'Can edit any torrent');
226
+    display_perm('torrents_edit', 'Can edit any torrent');
225
     display_perm('torrents_delete', 'Can delete torrents');
227
     display_perm('torrents_delete', 'Can delete torrents');
226
     display_perm('torrents_delete_fast', 'Can delete more than 3 torrents at a time.');
228
     display_perm('torrents_delete_fast', 'Can delete more than 3 torrents at a time.');
227
     display_perm('torrents_freeleech', 'Can make torrents freeleech');
229
     display_perm('torrents_freeleech', 'Can make torrents freeleech');
238
       </tr>
240
       </tr>
239
     </table>
241
     </table>
240
   </div>
242
   </div>
243
+
241
   <div class="permission_container">
244
   <div class="permission_container">
242
     <table>
245
     <table>
243
       <tr class="colhead">
246
       <tr class="colhead">
246
       <tr>
249
       <tr>
247
         <td>
250
         <td>
248
           <?php
251
           <?php
249
-          display_perm('admin_manage_news', 'Can manage site news');
252
+    display_perm('admin_manage_news', 'Can manage site news');
250
     display_perm('admin_manage_blog', 'Can manage the site blog');
253
     display_perm('admin_manage_blog', 'Can manage the site blog');
251
     display_perm('admin_manage_polls', 'Can manage polls');
254
     display_perm('admin_manage_polls', 'Can manage polls');
252
     display_perm('admin_manage_forums', 'Can manage forums (add/edit/delete)');
255
     display_perm('admin_manage_forums', 'Can manage forums (add/edit/delete)');
268
       </tr>
271
       </tr>
269
     </table>
272
     </table>
270
   </div>
273
   </div>
274
+
271
   <div class="submit_container"><input type="submit" name="submit" value="Save Permission Class" /></div>
275
   <div class="submit_container"><input type="submit" name="submit" value="Save Permission Class" /></div>
272
 </div>
276
 </div>
273
 <?php
277
 <?php

+ 89
- 76
classes/requests.class.php View File

10
     public static function update_sphinx_requests($RequestID)
10
     public static function update_sphinx_requests($RequestID)
11
     {
11
     {
12
         $QueryID = G::$DB->get_query_id();
12
         $QueryID = G::$DB->get_query_id();
13
-
14
         G::$DB->query("
13
         G::$DB->query("
15
-      SELECT REPLACE(t.Name, '.', '_')
16
-      FROM tags AS t
17
-        JOIN requests_tags AS rt ON t.ID = rt.TagID
18
-      WHERE rt.RequestID = $RequestID");
14
+        SELECT REPLACE(t.Name, '.', '_')
15
+        FROM tags AS t
16
+          JOIN requests_tags AS rt ON t.ID = rt.TagID
17
+          WHERE rt.RequestID = $RequestID");
18
+
19
         $TagList = G::$DB->collect(0, false);
19
         $TagList = G::$DB->collect(0, false);
20
         $TagList = db_string(implode(' ', $TagList));
20
         $TagList = db_string(implode(' ', $TagList));
21
 
21
 
22
         G::$DB->query("
22
         G::$DB->query("
23
-      REPLACE INTO sphinx_requests_delta (
24
-        ID, UserID, TimeAdded, LastVote, CategoryID, Title, TagList,
25
-        CatalogueNumber, DLSiteID, FillerID, TorrentID,
26
-        TimeFilled, Visible, Votes, Bounty)
27
-      SELECT
28
-        ID, r.UserID, UNIX_TIMESTAMP(TimeAdded) AS TimeAdded,
29
-        UNIX_TIMESTAMP(LastVote) AS LastVote, CategoryID, Title, '$TagList',
30
-        CatalogueNumber, DLSiteID, FillerID, TorrentID,
31
-        UNIX_TIMESTAMP(TimeFilled) AS TimeFilled, Visible,
32
-        COUNT(rv.UserID) AS Votes, SUM(rv.Bounty) >> 10 AS Bounty
33
-      FROM requests AS r
34
-        LEFT JOIN requests_votes AS rv ON rv.RequestID = r.ID
35
-      WHERE ID = $RequestID
36
-      GROUP BY r.ID");
23
+        REPLACE INTO sphinx_requests_delta (
24
+          ID, UserID, TimeAdded, LastVote, CategoryID, Title, TagList,
25
+          CatalogueNumber, DLSiteID, FillerID, TorrentID,
26
+          TimeFilled, Visible, Votes, Bounty)
27
+        SELECT
28
+          ID, r.UserID, UNIX_TIMESTAMP(TimeAdded) AS TimeAdded,
29
+          UNIX_TIMESTAMP(LastVote) AS LastVote, CategoryID, Title, '$TagList',
30
+          CatalogueNumber, DLSiteID, FillerID, TorrentID,
31
+          UNIX_TIMESTAMP(TimeFilled) AS TimeFilled, Visible,
32
+          COUNT(rv.UserID) AS Votes, SUM(rv.Bounty) >> 10 AS Bounty
33
+        FROM requests AS r
34
+          LEFT JOIN requests_votes AS rv ON rv.RequestID = r.ID
35
+        WHERE ID = $RequestID
36
+          GROUP BY r.ID");
37
+
37
         G::$DB->query("
38
         G::$DB->query("
38
-      UPDATE sphinx_requests_delta
39
-      SET ArtistList = (
39
+        UPDATE sphinx_requests_delta
40
+        SET ArtistList = (
40
           SELECT GROUP_CONCAT(ag.Name SEPARATOR ' ')
41
           SELECT GROUP_CONCAT(ag.Name SEPARATOR ' ')
41
           FROM requests_artists AS ra
42
           FROM requests_artists AS ra
42
             JOIN artists_group AS ag ON ag.ArtistID = ra.ArtistID
43
             JOIN artists_group AS ag ON ag.ArtistID = ra.ArtistID
43
           WHERE ra.RequestID = $RequestID
44
           WHERE ra.RequestID = $RequestID
44
-          GROUP BY NULL
45
-          )
46
-      WHERE ID = $RequestID");
47
-        G::$DB->set_query_id($QueryID);
45
+            GROUP BY NULL
46
+        )
47
+          WHERE ID = $RequestID");
48
 
48
 
49
+        G::$DB->set_query_id($QueryID);
49
         G::$Cache->delete_value("request_$RequestID");
50
         G::$Cache->delete_value("request_$RequestID");
50
     }
51
     }
51
 
52
 
68
                 unset($RequestIDs[$i], $Found[$GroupID], $NotFound[$GroupID]);
69
                 unset($RequestIDs[$i], $Found[$GroupID], $NotFound[$GroupID]);
69
                 continue;
70
                 continue;
70
             }
71
             }
72
+
71
             $Data = G::$Cache->get_value("request_$RequestID");
73
             $Data = G::$Cache->get_value("request_$RequestID");
72
             if (!empty($Data)) {
74
             if (!empty($Data)) {
73
                 unset($NotFound[$RequestID]);
75
                 unset($NotFound[$RequestID]);
74
                 $Found[$RequestID] = $Data;
76
                 $Found[$RequestID] = $Data;
75
             }
77
             }
76
         }
78
         }
79
+
77
         // Make sure there's something in $RequestIDs, otherwise the SQL will break
80
         // Make sure there's something in $RequestIDs, otherwise the SQL will break
78
         if (count($RequestIDs) === 0) {
81
         if (count($RequestIDs) === 0) {
79
             return [];
82
             return [];
81
         $IDs = implode(',', array_keys($NotFound));
84
         $IDs = implode(',', array_keys($NotFound));
82
 
85
 
83
         /*
86
         /*
84
-          Don't change without ensuring you change everything else that uses get_requests()
85
-        */
87
+         * Don't change without ensuring you change everything else that uses get_requests()
88
+         */
86
 
89
 
87
         if (count($NotFound) > 0) {
90
         if (count($NotFound) > 0) {
88
             $QueryID = G::$DB->get_query_id();
91
             $QueryID = G::$DB->get_query_id();
89
-
90
             G::$DB->query("
92
             G::$DB->query("
91
-        SELECT
92
-          ID,
93
-          UserID,
94
-          TimeAdded,
95
-          LastVote,
96
-          CategoryID,
97
-          Title,
98
-          TitleRJ,
99
-          TitleJP,
100
-          Image,
101
-          Description,
102
-          CatalogueNumber,
103
-          DLsiteID,
104
-          FillerID,
105
-          TorrentID,
106
-          TimeFilled,
107
-          GroupID
108
-        FROM requests
109
-        WHERE ID IN ($IDs)
110
-        ORDER BY ID");
93
+            SELECT
94
+              ID,
95
+              UserID,
96
+              TimeAdded,
97
+              LastVote,
98
+              CategoryID,
99
+              Title,
100
+              TitleRJ,
101
+              TitleJP,
102
+              Image,
103
+              Description,
104
+              CatalogueNumber,
105
+              DLsiteID,
106
+              FillerID,
107
+              TorrentID,
108
+              TimeFilled,
109
+              GroupID
110
+            FROM requests
111
+              WHERE ID IN ($IDs)
112
+              ORDER BY ID");
113
+
111
             $Requests = G::$DB->to_array(false, MYSQLI_ASSOC, true);
114
             $Requests = G::$DB->to_array(false, MYSQLI_ASSOC, true);
112
             $Tags = self::get_tags(G::$DB->collect('ID', false));
115
             $Tags = self::get_tags(G::$DB->collect('ID', false));
116
+
113
             foreach ($Requests as $Request) {
117
             foreach ($Requests as $Request) {
114
                 $Request['AnonymousFill'] = false;
118
                 $Request['AnonymousFill'] = false;
115
                 if ($Request['FillerID']) {
119
                 if ($Request['FillerID']) {
116
                     G::$DB->query("
120
                     G::$DB->query("
117
-            SELECT Anonymous
118
-            FROM torrents
119
-            WHERE ID = ".$Request['TorrentID']);
121
+                    SELECT Anonymous
122
+                    FROM torrents
123
+                      WHERE ID = ".$Request['TorrentID']);
124
+
120
                     list($Anonymous) = G::$DB->next_record();
125
                     list($Anonymous) = G::$DB->next_record();
121
                     if ($Anonymous) {
126
                     if ($Anonymous) {
122
                         $Request['AnonymousFill'] = true;
127
                         $Request['AnonymousFill'] = true;
123
                     }
128
                     }
124
                 }
129
                 }
130
+
125
                 unset($NotFound[$Request['ID']]);
131
                 unset($NotFound[$Request['ID']]);
126
                 $Request['Tags'] = isset($Tags[$Request['ID']]) ? $Tags[$Request['ID']] : [];
132
                 $Request['Tags'] = isset($Tags[$Request['ID']]) ? $Tags[$Request['ID']] : [];
127
                 $Found[$Request['ID']] = $Request;
133
                 $Found[$Request['ID']] = $Request;
166
             $Results = [];
172
             $Results = [];
167
             $QueryID = G::$DB->get_query_id();
173
             $QueryID = G::$DB->get_query_id();
168
             G::$DB->query("
174
             G::$DB->query("
169
-        SELECT
170
-          ra.ArtistID,
171
-          ag.Name
172
-        FROM requests_artists AS ra
173
-          JOIN artists_group AS ag ON ra.ArtistID = ag.ArtistID
174
-        WHERE ra.RequestID = $RequestID
175
-        ORDER BY ag.Name ASC;");
175
+            SELECT
176
+              ra.ArtistID,
177
+              ag.Name
178
+            FROM requests_artists AS ra
179
+              JOIN artists_group AS ag ON ra.ArtistID = ag.ArtistID
180
+            WHERE ra.RequestID = $RequestID
181
+              ORDER BY ag.Name ASC;");
182
+
176
             $ArtistRaw = G::$DB->to_array();
183
             $ArtistRaw = G::$DB->to_array();
177
             G::$DB->set_query_id($QueryID);
184
             G::$DB->set_query_id($QueryID);
185
+
178
             foreach ($ArtistRaw as $ArtistRow) {
186
             foreach ($ArtistRaw as $ArtistRow) {
179
                 list($ArtistID, $ArtistName) = $ArtistRow;
187
                 list($ArtistID, $ArtistName) = $ArtistRow;
180
                 $Results[] = array('id' => $ArtistID, 'name' => $ArtistName);
188
                 $Results[] = array('id' => $ArtistID, 'name' => $ArtistName);
189
         if (empty($RequestIDs)) {
197
         if (empty($RequestIDs)) {
190
             return [];
198
             return [];
191
         }
199
         }
200
+
192
         if (is_array($RequestIDs)) {
201
         if (is_array($RequestIDs)) {
193
             $RequestIDs = implode(',', $RequestIDs);
202
             $RequestIDs = implode(',', $RequestIDs);
194
         }
203
         }
204
+
195
         $QueryID = G::$DB->get_query_id();
205
         $QueryID = G::$DB->get_query_id();
196
         G::$DB->query("
206
         G::$DB->query("
197
-      SELECT
198
-        rt.RequestID,
199
-        rt.TagID,
200
-        t.Name
201
-      FROM requests_tags AS rt
202
-        JOIN tags AS t ON rt.TagID = t.ID
203
-      WHERE rt.RequestID IN ($RequestIDs)
204
-      ORDER BY rt.TagID ASC");
207
+        SELECT
208
+          rt.RequestID,
209
+          rt.TagID,
210
+          t.Name
211
+        FROM requests_tags AS rt
212
+          JOIN tags AS t ON rt.TagID = t.ID
213
+        WHERE rt.RequestID IN ($RequestIDs)
214
+          ORDER BY rt.TagID ASC");
215
+
205
         $Tags = G::$DB->to_array(false, MYSQLI_NUM, false);
216
         $Tags = G::$DB->to_array(false, MYSQLI_NUM, false);
206
         G::$DB->set_query_id($QueryID);
217
         G::$DB->set_query_id($QueryID);
218
+
207
         $Results = [];
219
         $Results = [];
208
         foreach ($Tags as $TagsRow) {
220
         foreach ($Tags as $TagsRow) {
209
             list($RequestID, $TagID, $TagName) = $TagsRow;
221
             list($RequestID, $TagID, $TagName) = $TagsRow;
218
         if (!is_array($RequestVotes)) {
230
         if (!is_array($RequestVotes)) {
219
             $QueryID = G::$DB->get_query_id();
231
             $QueryID = G::$DB->get_query_id();
220
             G::$DB->query("
232
             G::$DB->query("
221
-        SELECT
222
-          rv.UserID,
223
-          rv.Bounty,
224
-          u.Username
225
-        FROM requests_votes AS rv
226
-          LEFT JOIN users_main AS u ON u.ID = rv.UserID
227
-        WHERE rv.RequestID = $RequestID
228
-        ORDER BY rv.Bounty DESC");
233
+            SELECT
234
+              rv.UserID,
235
+              rv.Bounty,
236
+              u.Username
237
+            FROM requests_votes AS rv
238
+              LEFT JOIN users_main AS u ON u.ID = rv.UserID
239
+            WHERE rv.RequestID = $RequestID
240
+              ORDER BY rv.Bounty DESC");
241
+
229
             if (!G::$DB->has_results()) {
242
             if (!G::$DB->has_results()) {
230
                 return array(
243
                 return array(
231
-          'TotalBounty' => 0,
232
-          'Voters' => []);
244
+                    'TotalBounty' => 0,
245
+                    'Voters' => []);
233
             }
246
             }
234
             $Votes = G::$DB->to_array();
247
             $Votes = G::$DB->to_array();
235
 
248
 

+ 92
- 79
classes/script_start.php View File

10
 /* generates the page are at the bottom.        */
10
 /* generates the page are at the bottom.        */
11
 /*------------------------------------------------------*/
11
 /*------------------------------------------------------*/
12
 /********************************************************/
12
 /********************************************************/
13
+
13
 require 'config.php'; // The config contains all site wide configuration information
14
 require 'config.php'; // The config contains all site wide configuration information
14
 
15
 
15
 // Check for common setup pitfalls
16
 // Check for common setup pitfalls
16
 if (!ini_get('short_open_tag')) {
17
 if (!ini_get('short_open_tag')) {
17
     die('short_open_tag must be On in php.ini');
18
     die('short_open_tag must be On in php.ini');
18
 }
19
 }
20
+
19
 if (!extension_loaded('apcu')) {
21
 if (!extension_loaded('apcu')) {
20
     die('APCu extension not loaded');
22
     die('APCu extension not loaded');
21
 }
23
 }
32
 if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
34
 if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
33
     $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
35
     $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
34
 }
36
 }
37
+
35
 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])
38
 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])
36
     && proxyCheck($_SERVER['REMOTE_ADDR'])
39
     && proxyCheck($_SERVER['REMOTE_ADDR'])
37
     && filter_var(
40
     && filter_var(
52
     }
55
     }
53
 }
56
 }
54
 
57
 
55
-
56
-
57
-$ScriptStartTime = microtime(true); //To track how long a page takes to create
58
+$ScriptStartTime = microtime(true); // To track how long a page takes to create
58
 if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
59
 if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
59
     $RUsage = getrusage();
60
     $RUsage = getrusage();
60
     $CPUTimeStart = $RUsage['ru_utime.tv_sec'] * 1000000 + $RUsage['ru_utime.tv_usec'];
61
     $CPUTimeStart = $RUsage['ru_utime.tv_sec'] * 1000000 + $RUsage['ru_utime.tv_usec'];
61
 }
62
 }
62
-ob_start(); //Start a buffer, mainly in case there is a mysql error
63
+ob_start(); // Start a buffer, mainly in case there is a mysql error
63
 
64
 
64
-
65
-require(SERVER_ROOT.'/classes/debug.class.php'); //Require the debug class
66
-require(SERVER_ROOT.'/classes/mysql.class.php'); //Require the database wrapper
67
-require(SERVER_ROOT.'/classes/cache.class.php'); //Require the caching class
68
-require(SERVER_ROOT.'/classes/time.class.php'); //Require the time class
69
-require(SERVER_ROOT.'/classes/paranoia.class.php'); //Require the paranoia check_paranoia function
70
-require(SERVER_ROOT.'/classes/regex.php');
71
-require(SERVER_ROOT.'/classes/util.php');
65
+require SERVER_ROOT.'/classes/debug.class.php'; // Require the debug class
66
+require SERVER_ROOT.'/classes/mysql.class.php'; // Require the database wrapper
67
+require SERVER_ROOT.'/classes/cache.class.php'; // Require the caching class
68
+require SERVER_ROOT.'/classes/time.class.php'; // Require the time class
69
+require SERVER_ROOT.'/classes/paranoia.class.php'; // Require the paranoia check_paranoia function
70
+require SERVER_ROOT.'/classes/regex.php';
71
+require SERVER_ROOT.'/classes/util.php';
72
 
72
 
73
 $Debug = new DEBUG;
73
 $Debug = new DEBUG;
74
 $Debug->handle_errors();
74
 $Debug->handle_errors();
86
 G::initialize();
86
 G::initialize();
87
 
87
 
88
 //Begin browser identification
88
 //Begin browser identification
89
-
90
 $Browser = UserAgent::browser($_SERVER['HTTP_USER_AGENT']);
89
 $Browser = UserAgent::browser($_SERVER['HTTP_USER_AGENT']);
91
 $OperatingSystem = UserAgent::operating_system($_SERVER['HTTP_USER_AGENT']);
90
 $OperatingSystem = UserAgent::operating_system($_SERVER['HTTP_USER_AGENT']);
92
 
91
 
118
     $UserSessions = $Cache->get_value("users_sessions_$UserID");
117
     $UserSessions = $Cache->get_value("users_sessions_$UserID");
119
     if (!is_array($UserSessions)) {
118
     if (!is_array($UserSessions)) {
120
         $DB->query(
119
         $DB->query(
121
-        "SELECT
122
-        SessionID,
123
-        Browser,
124
-        OperatingSystem,
125
-        IP,
126
-        LastUpdate
127
-      FROM users_sessions
128
-      WHERE UserID = '$UserID'
129
-        AND Active = 1
130
-      ORDER BY LastUpdate DESC"
131
-    );
120
+            "
121
+        SELECT
122
+          SessionID,
123
+          Browser,
124
+          OperatingSystem,
125
+          IP,
126
+          LastUpdate
127
+        FROM users_sessions
128
+          WHERE UserID = '$UserID'
129
+          AND Active = 1
130
+        ORDER BY LastUpdate DESC"
131
+        );
132
+
132
         $UserSessions = $DB->to_array('SessionID', MYSQLI_ASSOC);
133
         $UserSessions = $DB->to_array('SessionID', MYSQLI_ASSOC);
133
         $Cache->cache_value("users_sessions_$UserID", $UserSessions, 0);
134
         $Cache->cache_value("users_sessions_$UserID", $UserSessions, 0);
134
     }
135
     }
141
     $Enabled = $Cache->get_value('enabled_'.$LoggedUser['ID']);
142
     $Enabled = $Cache->get_value('enabled_'.$LoggedUser['ID']);
142
     if ($Enabled === false) {
143
     if ($Enabled === false) {
143
         $DB->query("
144
         $DB->query("
144
-      SELECT Enabled
145
-      FROM users_main
146
-      WHERE ID = '$LoggedUser[ID]'");
145
+        SELECT Enabled
146
+          FROM users_main
147
+          WHERE ID = '$LoggedUser[ID]'");
148
+
147
         list($Enabled) = $DB->next_record();
149
         list($Enabled) = $DB->next_record();
148
         $Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
150
         $Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
149
     }
151
     }
152
+
153
+    # todo: Check strict equality
150
     if ($Enabled == 2) {
154
     if ($Enabled == 2) {
151
         logout();
155
         logout();
152
     }
156
     }
155
     $UserStats = $Cache->get_value('user_stats_'.$LoggedUser['ID']);
159
     $UserStats = $Cache->get_value('user_stats_'.$LoggedUser['ID']);
156
     if (!is_array($UserStats)) {
160
     if (!is_array($UserStats)) {
157
         $DB->query("
161
         $DB->query("
158
-      SELECT Uploaded AS BytesUploaded, Downloaded AS BytesDownloaded, RequiredRatio
159
-      FROM users_main
160
-      WHERE ID = '$LoggedUser[ID]'");
162
+        SELECT Uploaded AS BytesUploaded, Downloaded AS BytesDownloaded, RequiredRatio
163
+        FROM users_main
164
+          WHERE ID = '$LoggedUser[ID]'");
165
+
161
         $UserStats = $DB->next_record(MYSQLI_ASSOC);
166
         $UserStats = $DB->next_record(MYSQLI_ASSOC);
162
         $Cache->cache_value('user_stats_'.$LoggedUser['ID'], $UserStats, 3600);
167
         $Cache->cache_value('user_stats_'.$LoggedUser['ID'], $UserStats, 3600);
163
     }
168
     }
168
 
173
 
169
     // Create LoggedUser array
174
     // Create LoggedUser array
170
     $LoggedUser = array_merge($HeavyInfo, $LightInfo, $UserStats);
175
     $LoggedUser = array_merge($HeavyInfo, $LightInfo, $UserStats);
171
-
172
     $LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']);
176
     $LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']);
173
 
177
 
174
     // $LoggedUser['RatioWatch'] as a bool to disable things for users on Ratio Watch
178
     // $LoggedUser['RatioWatch'] as a bool to disable things for users on Ratio Watch
175
     $LoggedUser['RatioWatch'] = (
179
     $LoggedUser['RatioWatch'] = (
176
-      $LoggedUser['RatioWatchEnds']
177
-    && time() < strtotime($LoggedUser['RatioWatchEnds'])
178
-    && ($LoggedUser['BytesDownloaded'] * $LoggedUser['RequiredRatio']) > $LoggedUser['BytesUploaded']
179
-  );
180
+        $LoggedUser['RatioWatchEnds']
181
+     && time() < strtotime($LoggedUser['RatioWatchEnds'])
182
+     && ($LoggedUser['BytesDownloaded'] * $LoggedUser['RequiredRatio']) > $LoggedUser['BytesUploaded']
183
+    );
180
 
184
 
181
     // Load in the permissions
185
     // Load in the permissions
182
     $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
186
     $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
193
     // Update LastUpdate every 10 minutes
197
     // Update LastUpdate every 10 minutes
194
     if (strtotime($UserSessions[$SessionID]['LastUpdate']) + 600 < time()) {
198
     if (strtotime($UserSessions[$SessionID]['LastUpdate']) + 600 < time()) {
195
         $DB->query("
199
         $DB->query("
196
-      UPDATE users_main
197
-      SET LastAccess = NOW()
198
-      WHERE ID = '$LoggedUser[ID]'");
200
+        UPDATE users_main
201
+        SET LastAccess = NOW()
202
+          WHERE ID = '$LoggedUser[ID]'");
203
+
199
         $SessionQuery =
204
         $SessionQuery =
200
-     "UPDATE users_sessions
201
-      SET ";
205
+       "UPDATE users_sessions
206
+          SET ";
207
+
202
         // Only update IP if we have an encryption key in memory
208
         // Only update IP if we have an encryption key in memory
203
         if (apcu_exists('DBKEY')) {
209
         if (apcu_exists('DBKEY')) {
204
             $SessionQuery .= "IP = '".Crypto::encrypt($_SERVER['REMOTE_ADDR'])."', ";
210
             $SessionQuery .= "IP = '".Crypto::encrypt($_SERVER['REMOTE_ADDR'])."', ";
205
         }
211
         }
212
+
206
         $SessionQuery .=
213
         $SessionQuery .=
207
        "Browser = '$Browser',
214
        "Browser = '$Browser',
208
         OperatingSystem = '$OperatingSystem',
215
         OperatingSystem = '$OperatingSystem',
209
         LastUpdate = NOW()
216
         LastUpdate = NOW()
210
-      WHERE UserID = '$LoggedUser[ID]'
217
+        WHERE UserID = '$LoggedUser[ID]'
211
         AND SessionID = '".db_string($SessionID)."'";
218
         AND SessionID = '".db_string($SessionID)."'";
219
+
212
         $DB->query($SessionQuery);
220
         $DB->query($SessionQuery);
213
         $Cache->begin_transaction("users_sessions_$UserID");
221
         $Cache->begin_transaction("users_sessions_$UserID");
214
         $Cache->delete_row($SessionID);
222
         $Cache->delete_row($SessionID);
223
+
215
         $UsersSessionCache = array(
224
         $UsersSessionCache = array(
216
         'SessionID' => $SessionID,
225
         'SessionID' => $SessionID,
217
         'Browser' => $Browser,
226
         'Browser' => $Browser,
218
         'OperatingSystem' => $OperatingSystem,
227
         'OperatingSystem' => $OperatingSystem,
219
         'IP' => (apcu_exists('DBKEY') ? Crypto::encrypt($_SERVER['REMOTE_ADDR']) : $UserSessions[$SessionID]['IP']),
228
         'IP' => (apcu_exists('DBKEY') ? Crypto::encrypt($_SERVER['REMOTE_ADDR']) : $UserSessions[$SessionID]['IP']),
220
         'LastUpdate' => sqltime() );
229
         'LastUpdate' => sqltime() );
230
+
221
         $Cache->insert_front($SessionID, $UsersSessionCache);
231
         $Cache->insert_front($SessionID, $UsersSessionCache);
222
         $Cache->commit_transaction(0);
232
         $Cache->commit_transaction(0);
223
     }
233
     }
227
         $LoggedUser['Notify'] = $Cache->get_value('notify_filters_'.$LoggedUser['ID']);
237
         $LoggedUser['Notify'] = $Cache->get_value('notify_filters_'.$LoggedUser['ID']);
228
         if (!is_array($LoggedUser['Notify'])) {
238
         if (!is_array($LoggedUser['Notify'])) {
229
             $DB->query("
239
             $DB->query("
230
-        SELECT ID, Label
231
-        FROM users_notify_filters
232
-        WHERE UserID = '$LoggedUser[ID]'");
240
+            SELECT ID, Label
241
+            FROM users_notify_filters
242
+              WHERE UserID = '$LoggedUser[ID]'");
243
+
233
             $LoggedUser['Notify'] = $DB->to_array('ID');
244
             $LoggedUser['Notify'] = $DB->to_array('ID');
234
             $Cache->cache_value('notify_filters_'.$LoggedUser['ID'], $LoggedUser['Notify'], 2592000);
245
             $Cache->cache_value('notify_filters_'.$LoggedUser['ID'], $LoggedUser['Notify'], 2592000);
235
         }
246
         }
241
     }
252
     }
242
 
253
 
243
     // IP changed
254
     // IP changed
244
-
245
     if (apcu_exists('DBKEY') && Crypto::decrypt($LoggedUser['IP']) != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
255
     if (apcu_exists('DBKEY') && Crypto::decrypt($LoggedUser['IP']) != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
246
         if (Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
256
         if (Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
247
             error('Your IP address has been banned.');
257
             error('Your IP address has been banned.');
250
         $CurIP = db_string($LoggedUser['IP']);
260
         $CurIP = db_string($LoggedUser['IP']);
251
         $NewIP = db_string($_SERVER['REMOTE_ADDR']);
261
         $NewIP = db_string($_SERVER['REMOTE_ADDR']);
252
         $DB->query("
262
         $DB->query("
253
-      SELECT IP
254
-      FROM users_history_ips
255
-      WHERE EndTime IS NULL
256
-        AND UserID = '$LoggedUser[ID]'");
263
+        SELECT IP
264
+        FROM users_history_ips
265
+          WHERE EndTime IS NULL
266
+          AND UserID = '$LoggedUser[ID]'");
267
+
257
         while (list($EncIP) = $DB->next_record()) {
268
         while (list($EncIP) = $DB->next_record()) {
258
             if (Crypto::decrypt($EncIP) == $CurIP) {
269
             if (Crypto::decrypt($EncIP) == $CurIP) {
259
                 $CurIP = $EncIP;
270
                 $CurIP = $EncIP;
261
                 break;
272
                 break;
262
             }
273
             }
263
         }
274
         }
275
+
264
         $DB->query("
276
         $DB->query("
265
-      UPDATE users_history_ips
266
-      SET EndTime = NOW()
267
-      WHERE EndTime IS NULL
268
-        AND UserID = '$LoggedUser[ID]'
269
-        AND IP = '$CurIP'");
277
+        UPDATE users_history_ips
278
+        SET EndTime = NOW()
279
+          WHERE EndTime IS NULL
280
+          AND UserID = '$LoggedUser[ID]'
281
+          AND IP = '$CurIP'");
282
+
270
         $DB->query("
283
         $DB->query("
271
-      INSERT IGNORE INTO users_history_ips
272
-        (UserID, IP, StartTime)
273
-      VALUES
274
-        ('$LoggedUser[ID]', '".Crypto::encrypt($NewIP)."', NOW())");
284
+        INSERT IGNORE INTO users_history_ips
285
+          (UserID, IP, StartTime)
286
+        VALUES
287
+          ('$LoggedUser[ID]', '".Crypto::encrypt($NewIP)."', NOW())");
275
 
288
 
276
         $ipcc = Tools::geoip($NewIP);
289
         $ipcc = Tools::geoip($NewIP);
277
         $DB->query("
290
         $DB->query("
278
-      UPDATE users_main
279
-      SET IP = '".Crypto::encrypt($NewIP)."', ipcc = '$ipcc'
280
-      WHERE ID = '$LoggedUser[ID]'");
291
+        UPDATE users_main
292
+        SET IP = '".Crypto::encrypt($NewIP)."', ipcc = '$ipcc'
293
+          WHERE ID = '$LoggedUser[ID]'");
294
+
281
         $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
295
         $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
282
         $Cache->update_row(false, array('IP' => Crypto::encrypt($_SERVER['REMOTE_ADDR'])));
296
         $Cache->update_row(false, array('IP' => Crypto::encrypt($_SERVER['REMOTE_ADDR'])));
283
         $Cache->commit_transaction(0);
297
         $Cache->commit_transaction(0);
284
     }
298
     }
285
 
299
 
286
-
287
     // Get stylesheets
300
     // Get stylesheets
288
     $Stylesheets = $Cache->get_value('stylesheets');
301
     $Stylesheets = $Cache->get_value('stylesheets');
289
     if (!is_array($Stylesheets)) {
302
     if (!is_array($Stylesheets)) {
290
         $DB->query('
303
         $DB->query('
291
-      SELECT
292
-        ID,
293
-        LOWER(REPLACE(Name, " ", "_")) AS Name,
294
-        Name AS ProperName,
295
-        LOWER(REPLACE(Additions, " ", "_")) AS Additions,
296
-        Additions AS ProperAdditions
297
-      FROM stylesheets');
304
+        SELECT
305
+          ID,
306
+          LOWER(REPLACE(Name, " ", "_")) AS Name,
307
+          Name AS ProperName,
308
+          LOWER(REPLACE(Additions, " ", "_")) AS Additions,
309
+          Additions AS ProperAdditions
310
+        FROM stylesheets');
311
+
298
         $Stylesheets = $DB->to_array('ID', MYSQLI_BOTH);
312
         $Stylesheets = $DB->to_array('ID', MYSQLI_BOTH);
299
         $Cache->cache_value('stylesheets', $Stylesheets, 0);
313
         $Cache->cache_value('stylesheets', $Stylesheets, 0);
300
     }
314
     }
301
 
315
 
302
     // todo: Clean up this messy solution
316
     // todo: Clean up this messy solution
303
     $LoggedUser['StyleName'] = $Stylesheets[$LoggedUser['StyleID']]['Name'];
317
     $LoggedUser['StyleName'] = $Stylesheets[$LoggedUser['StyleID']]['Name'];
304
-
305
     if (empty($LoggedUser['Username'])) {
318
     if (empty($LoggedUser['Username'])) {
306
         logout(); // Ghost
319
         logout(); // Ghost
307
     }
320
     }
308
 }
321
 }
322
+
309
 G::initialize();
323
 G::initialize();
310
 $Debug->set_flag('end user handling');
324
 $Debug->set_flag('end user handling');
311
-
312
 $Debug->set_flag('start function definitions');
325
 $Debug->set_flag('start function definitions');
313
 
326
 
314
 /**
327
 /**
320
     setcookie('session', '', time() - 60 * 60 * 24 * 365, '/', '', false);
333
     setcookie('session', '', time() - 60 * 60 * 24 * 365, '/', '', false);
321
     setcookie('userid', '', time() - 60 * 60 * 24 * 365, '/', '', false);
334
     setcookie('userid', '', time() - 60 * 60 * 24 * 365, '/', '', false);
322
     setcookie('keeplogged', '', time() - 60 * 60 * 24 * 365, '/', '', false);
335
     setcookie('keeplogged', '', time() - 60 * 60 * 24 * 365, '/', '', false);
336
+
323
     if ($SessionID) {
337
     if ($SessionID) {
324
         G::$DB->query("
338
         G::$DB->query("
325
-      DELETE FROM users_sessions
326
-      WHERE UserID = '" . G::$LoggedUser['ID'] . "'
327
-        AND SessionID = '".db_string($SessionID)."'");
339
+        DELETE FROM users_sessions
340
+          WHERE UserID = '" . G::$LoggedUser['ID'] . "'
341
+          AND SessionID = '".db_string($SessionID)."'");
328
 
342
 
329
         G::$Cache->begin_transaction('users_sessions_' . G::$LoggedUser['ID']);
343
         G::$Cache->begin_transaction('users_sessions_' . G::$LoggedUser['ID']);
330
         G::$Cache->delete_row($SessionID);
344
         G::$Cache->delete_row($SessionID);
331
         G::$Cache->commit_transaction(0);
345
         G::$Cache->commit_transaction(0);
332
     }
346
     }
347
+
333
     G::$Cache->delete_value('user_info_' . G::$LoggedUser['ID']);
348
     G::$Cache->delete_value('user_info_' . G::$LoggedUser['ID']);
334
     G::$Cache->delete_value('user_stats_' . G::$LoggedUser['ID']);
349
     G::$Cache->delete_value('user_stats_' . G::$LoggedUser['ID']);
335
     G::$Cache->delete_value('user_info_heavy_' . G::$LoggedUser['ID']);
350
     G::$Cache->delete_value('user_info_heavy_' . G::$LoggedUser['ID']);
336
 
351
 
337
     header('Location: login.php');
352
     header('Location: login.php');
338
-
339
     die();
353
     die();
340
 }
354
 }
341
 
355
 
345
 
359
 
346
     G::$DB->query("
360
     G::$DB->query("
347
     DELETE FROM users_sessions
361
     DELETE FROM users_sessions
348
-    WHERE UserID = '$UserID'");
362
+      WHERE UserID = '$UserID'");
349
 
363
 
350
     G::$Cache->delete_value('users_sessions_' . $UserID);
364
     G::$Cache->delete_value('users_sessions_' . $UserID);
351
     logout();
365
     logout();
396
 define('STAFF_LOCKED', 1);
410
 define('STAFF_LOCKED', 1);
397
 
411
 
398
 $AllowedPages = ['staffpm', 'ajax', 'locked', 'logout', 'login'];
412
 $AllowedPages = ['staffpm', 'ajax', 'locked', 'logout', 'login'];
399
-
400
 if (isset(G::$LoggedUser['LockedAccount']) && !in_array($Document, $AllowedPages)) {
413
 if (isset(G::$LoggedUser['LockedAccount']) && !in_array($Document, $AllowedPages)) {
401
     require(SERVER_ROOT . '/sections/locked/index.php');
414
     require(SERVER_ROOT . '/sections/locked/index.php');
402
 } else {
415
 } else {
415
     header('Pragma: no-cache');
428
     header('Pragma: no-cache');
416
 }
429
 }
417
 
430
 
418
-//Flush to user
431
+// Flush to user
419
 ob_end_flush();
432
 ob_end_flush();
420
 
433
 
421
 $Debug->set_flag('set headers and send to user');
434
 $Debug->set_flag('set headers and send to user');
422
 
435
 
423
-//Attribute profiling
436
+// Attribute profiling
424
 $Debug->profile();
437
 $Debug->profile();

+ 23
- 13
classes/torrent.class.php View File

1
 <?php
1
 <?php
2
 
2
 
3
+# todo: Rplace with https://github.com/OPSnet/bencode-torrent
4
+
3
 /*******************************************************************************
5
 /*******************************************************************************
4
 |~~~~ Gazelle bencode parser                         ~~~~|
6
 |~~~~ Gazelle bencode parser                         ~~~~|
5
 --------------------------------------------------------------------------------
7
 --------------------------------------------------------------------------------
67
 class BENCODE2
69
 class BENCODE2
68
 {
70
 {
69
     public $Val; // Decoded array
71
     public $Val; // Decoded array
70
-  public $Pos = 1; // Pointer that indicates our position in the string
71
-  public $Str = ''; // Torrent string
72
-
73
-  public function __construct($Val, $IsParsed = false)
74
-  {
75
-      if (!$IsParsed) {
76
-          $this->Str = $Val;
77
-          $this->dec();
78
-      } else {
79
-          $this->Val = $Val;
80
-      }
81
-  }
72
+    public $Pos = 1; // Pointer that indicates our position in the string
73
+    public $Str = ''; // Torrent string
74
+
75
+    public function __construct($Val, $IsParsed = false)
76
+    {
77
+        if (!$IsParsed) {
78
+            $this->Str = $Val;
79
+            $this->dec();
80
+        } else {
81
+            $this->Val = $Val;
82
+        }
83
+    }
82
 
84
 
83
     // Decode an element based on the type. The type is really just an indicator.
85
     // Decode an element based on the type. The type is really just an indicator.
84
     public function decode($Type, $Key)
86
     public function decode($Type, $Key)
139
         if (empty($this->Val)) {
141
         if (empty($this->Val)) {
140
             return 'le';
142
             return 'le';
141
         }
143
         }
144
+
142
         $Str = 'l';
145
         $Str = 'l';
143
         reset($this->Val);
146
         reset($this->Val);
147
+
144
         foreach ($this->Val as $Value) {
148
         foreach ($this->Val as $Value) {
145
             $Str.=$this->encode($Value);
149
             $Str.=$this->encode($Value);
146
         }
150
         }
152
     {
156
     {
153
         $Key = 0; // Array index
157
         $Key = 0; // Array index
154
         $Length = strlen($this->Str);
158
         $Length = strlen($this->Str);
159
+
155
         while ($this->Pos < $Length) {
160
         while ($this->Pos < $Length) {
156
             $Type = $this->Str[$this->Pos];
161
             $Type = $this->Str[$this->Pos];
157
             // $Type now indicates what type of element we're dealing with
162
             // $Type now indicates what type of element we're dealing with
179
         if (empty($this->Val)) {
184
         if (empty($this->Val)) {
180
             return 'de';
185
             return 'de';
181
         }
186
         }
187
+
182
         $Str = 'd';
188
         $Str = 'd';
183
         reset($this->Val);
189
         reset($this->Val);
190
+
184
         foreach ($this->Val as $Key => $Value) {
191
         foreach ($this->Val as $Key => $Value) {
185
             $Str.=strlen($Key).':'.$Key.$this->encode($Value);
192
             $Str.=strlen($Key).':'.$Key.$this->encode($Value);
186
         }
193
         }
273
             $FileSizes = [];
280
             $FileSizes = [];
274
             $TotalSize = 0;
281
             $TotalSize = 0;
275
             $Files = $this->Val['info']->Val['files']->Val;
282
             $Files = $this->Val['info']->Val['files']->Val;
283
+
276
             if (isset($Files[0]->Val['path.utf-8'])) {
284
             if (isset($Files[0]->Val['path.utf-8'])) {
277
                 $PathKey = 'path.utf-8';
285
                 $PathKey = 'path.utf-8';
278
             } else {
286
             } else {
279
                 $PathKey = 'path';
287
                 $PathKey = 'path';
280
             }
288
             }
289
+
281
             foreach ($Files as $File) {
290
             foreach ($Files as $File) {
282
                 $FileSize = $File->Val['length'];
291
                 $FileSize = $File->Val['length'];
283
                 $TotalSize += $FileSize;
292
                 $TotalSize += $FileSize;
286
                 $FileSizes[] = $FileSize;
295
                 $FileSizes[] = $FileSize;
287
                 $FileNames[] = $FileName;
296
                 $FileNames[] = $FileName;
288
             }
297
             }
298
+
289
             natcasesort($FileNames);
299
             natcasesort($FileNames);
290
             foreach ($FileNames as $Index => $FileName) {
300
             foreach ($FileNames as $Index => $FileName) {
291
                 $FileList[] = array($FileSizes[$Index], $FileName);
301
                 $FileList[] = array($FileSizes[$Index], $FileName);
318
         unset($this->Val['azureus_properties']);
328
         unset($this->Val['azureus_properties']);
319
 
329
 
320
         // Remove web-seeds
330
         // Remove web-seeds
321
-        #unset($this->Val['url-list']);
331
+        unset($this->Val['url-list']);
322
 
332
 
323
         // Remove libtorrent resume info
333
         // Remove libtorrent resume info
324
         unset($this->Val['libtorrent_resume']);
334
         unset($this->Val['libtorrent_resume']);

+ 22
- 5
classes/torrentsdl.class.php View File

1
 <?php
1
 <?php
2
+
2
 /**
3
 /**
3
  * Class for functions related to the features involving torrent downloads
4
  * Class for functions related to the features involving torrent downloads
4
  */
5
  */
29
     public function __construct(&$QueryResult, $Title)
30
     public function __construct(&$QueryResult, $Title)
30
     {
31
     {
31
         G::$Cache->InternalCache = false; // The internal cache is almost completely useless for this
32
         G::$Cache->InternalCache = false; // The internal cache is almost completely useless for this
32
-    Zip::unlimit(); // Need more memory and longer timeout
33
-    $this->QueryResult = $QueryResult;
33
+        Zip::unlimit(); // Need more memory and longer timeout
34
+        $this->QueryResult = $QueryResult;
34
         $this->Title = $Title;
35
         $this->Title = $Title;
35
         $this->User = G::$LoggedUser;
36
         $this->User = G::$LoggedUser;
36
         $this->AnnounceURL = ANNOUNCE_URLS[0][0]."/".G::$LoggedUser['torrent_pass']."/announce";
37
         $this->AnnounceURL = ANNOUNCE_URLS[0][0]."/".G::$LoggedUser['torrent_pass']."/announce";
38
+
37
         function add_passkey($Ann)
39
         function add_passkey($Ann)
38
         {
40
         {
39
             return (is_array($Ann)) ? array_map('add_passkey', $Ann) : $Ann."/".G::$LoggedUser['torrent_pass']."/announce";
41
             return (is_array($Ann)) ? array_map('add_passkey', $Ann) : $Ann."/".G::$LoggedUser['torrent_pass']."/announce";
40
         }
42
         }
43
+
41
         # todo: Probably not working, but no need yet
44
         # todo: Probably not working, but no need yet
42
         $this->AnnounceList = (sizeof(ANNOUNCE_URLS[0]) === 1 && sizeof(ANNOUNCE_URLS[0][0]) === 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS[0]);
45
         $this->AnnounceList = (sizeof(ANNOUNCE_URLS[0]) === 1 && sizeof(ANNOUNCE_URLS[0][0]) === 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS[0]);
46
+
43
         # Tracker tiers (pending)
47
         # Tracker tiers (pending)
44
         #$this->AnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array(array_map('add_passkey', ANNOUNCE_URLS[0]), ANNOUNCE_URLS[1]);
48
         #$this->AnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array(array_map('add_passkey', ANNOUNCE_URLS[0]), ANNOUNCE_URLS[1]);
49
+        
45
         # Original Oppaitime
50
         # Original Oppaitime
46
         #$this->AnnounceList = (sizeof(ANNOUNCE_URLS) == 1 && sizeof(ANNOUNCE_URLS[0]) == 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS);
51
         #$this->AnnounceList = (sizeof(ANNOUNCE_URLS) == 1 && sizeof(ANNOUNCE_URLS[0]) == 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS);
47
         $this->Zip = new Zip(Misc::file_string($Title));
52
         $this->Zip = new Zip(Misc::file_string($Title));
58
         $GroupIDs = $Downloads = [];
63
         $GroupIDs = $Downloads = [];
59
         $OldQuery = G::$DB->get_query_id();
64
         $OldQuery = G::$DB->get_query_id();
60
         G::$DB->set_query_id($this->QueryResult);
65
         G::$DB->set_query_id($this->QueryResult);
66
+
61
         if (!isset($this->IDBoundaries)) {
67
         if (!isset($this->IDBoundaries)) {
62
             if ($Key == 'TorrentID') {
68
             if ($Key == 'TorrentID') {
63
                 $this->IDBoundaries = false;
69
                 $this->IDBoundaries = false;
65
                 $this->IDBoundaries = G::$DB->to_pair($Key, 'TorrentID', false);
71
                 $this->IDBoundaries = G::$DB->to_pair($Key, 'TorrentID', false);
66
             }
72
             }
67
         }
73
         }
74
+
68
         $Found = 0;
75
         $Found = 0;
69
         while ($Download = G::$DB->next_record(MYSQLI_ASSOC, false)) {
76
         while ($Download = G::$DB->next_record(MYSQLI_ASSOC, false)) {
70
             if (!$this->IDBoundaries || $Download['TorrentID'] == $this->IDBoundaries[$Download[$Key]]) {
77
             if (!$this->IDBoundaries || $Download['TorrentID'] == $this->IDBoundaries[$Download[$Key]]) {
76
                 }
83
                 }
77
             }
84
             }
78
         }
85
         }
86
+
79
         $this->NumFound += $Found;
87
         $this->NumFound += $Found;
80
         G::$DB->set_query_id($OldQuery);
88
         G::$DB->set_query_id($OldQuery);
81
         if (empty($Downloads)) {
89
         if (empty($Downloads)) {
200
         if ($TorrentID !== false) {
208
         if ($TorrentID !== false) {
201
             $MaxLength -= (strlen($TorrentID) + 1);
209
             $MaxLength -= (strlen($TorrentID) + 1);
202
         }
210
         }
211
+
203
         $TorrentArtist = Misc::file_string($Artist);
212
         $TorrentArtist = Misc::file_string($Artist);
204
         $TorrentName = Misc::file_string($Album);
213
         $TorrentName = Misc::file_string($Album);
214
+
205
         if ($Year > 0) {
215
         if ($Year > 0) {
206
             $TorrentName .= " - $Year";
216
             $TorrentName .= " - $Year";
207
         }
217
         }
218
+
208
         $TorrentInfo = [];
219
         $TorrentInfo = [];
209
-        if ($Media != '') {
220
+        if ($Media !== '') {
210
             $TorrentInfo[] = $Media;
221
             $TorrentInfo[] = $Media;
211
         }
222
         }
212
-        if ($Format != '') {
223
+
224
+        if ($Format !== '') {
213
             $TorrentInfo[] = $Format;
225
             $TorrentInfo[] = $Format;
214
         }
226
         }
215
-        if ($Encoding != '') {
227
+
228
+        if ($Encoding !== '') {
216
             $TorrentInfo[] = $Encoding;
229
             $TorrentInfo[] = $Encoding;
217
         }
230
         }
231
+
218
         if (!empty($TorrentInfo)) {
232
         if (!empty($TorrentInfo)) {
219
             $TorrentInfo = ' (' . Misc::file_string(implode(' - ', $TorrentInfo)) . ')';
233
             $TorrentInfo = ' (' . Misc::file_string(implode(' - ', $TorrentInfo)) . ')';
220
         } else {
234
         } else {
249
             }
263
             }
250
             return $Bencode;
264
             return $Bencode;
251
         }
265
         }
266
+
252
         $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
267
         $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
253
         $Tor->set_announce_url($AnnounceURL);
268
         $Tor->set_announce_url($AnnounceURL);
269
+
254
         unset($Tor->Val['announce-list']);
270
         unset($Tor->Val['announce-list']);
255
         if (!empty($AnnounceList)) {
271
         if (!empty($AnnounceList)) {
256
             $Tor->set_announce_list($AnnounceList);
272
             $Tor->set_announce_list($AnnounceList);
257
         }
273
         }
274
+        
258
         unset($Tor->Val['url-list']);
275
         unset($Tor->Val['url-list']);
259
         unset($Tor->Val['libtorrent_resume']);
276
         unset($Tor->Val['libtorrent_resume']);
260
         return $Tor->enc();
277
         return $Tor->enc();

+ 43
- 35
classes/userrank.class.php View File

11
         $QueryID = G::$DB->get_query_id();
11
         $QueryID = G::$DB->get_query_id();
12
 
12
 
13
         G::$DB->query("
13
         G::$DB->query("
14
-      DROP TEMPORARY TABLE IF EXISTS temp_stats");
14
+        DROP TEMPORARY TABLE IF EXISTS temp_stats");
15
 
15
 
16
         G::$DB->query("
16
         G::$DB->query("
17
-      CREATE TEMPORARY TABLE temp_stats (
18
-        ID int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
19
-        Val bigint(20) NOT NULL
20
-      );");
17
+        CREATE TEMPORARY TABLE temp_stats (
18
+          ID int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
19
+          Val bigint(20) NOT NULL
20
+        );");
21
 
21
 
22
         G::$DB->query("
22
         G::$DB->query("
23
-      INSERT INTO temp_stats (Val) ".
24
-      $Query);
23
+        INSERT INTO temp_stats (Val) ".
24
+        $Query);
25
 
25
 
26
         G::$DB->query("
26
         G::$DB->query("
27
-      SELECT COUNT(ID)
28
-      FROM temp_stats");
27
+        SELECT COUNT(ID)
28
+        FROM temp_stats");
29
         list($UserCount) = G::$DB->next_record();
29
         list($UserCount) = G::$DB->next_record();
30
 
30
 
31
         G::$DB->query("
31
         G::$DB->query("
32
-      SELECT MIN(Val)
33
-      FROM temp_stats
34
-      GROUP BY CEIL(ID / (".(int)$UserCount." / 100));");
32
+        SELECT MIN(Val)
33
+        FROM temp_stats
34
+          GROUP BY CEIL(ID / (".(int)$UserCount." / 100));");
35
 
35
 
36
         $Table = G::$DB->to_array();
36
         $Table = G::$DB->to_array();
37
-
38
         G::$DB->set_query_id($QueryID);
37
         G::$DB->set_query_id($QueryID);
39
 
38
 
40
         // Give a little variation to the cache length, so all the tables don't expire at the same time
39
         // Give a little variation to the cache length, so all the tables don't expire at the same time
46
     private static function table_query($TableName)
45
     private static function table_query($TableName)
47
     {
46
     {
48
         switch ($TableName) {
47
         switch ($TableName) {
49
-      case 'uploaded':
50
-        $Query =  "
48
+        case 'uploaded':
49
+          $Query =  "
51
           SELECT Uploaded
50
           SELECT Uploaded
52
           FROM users_main
51
           FROM users_main
53
           WHERE Enabled = '1'
52
           WHERE Enabled = '1'
54
             AND Uploaded > 0
53
             AND Uploaded > 0
55
           ORDER BY Uploaded;";
54
           ORDER BY Uploaded;";
56
-        break;
57
-      case 'downloaded':
58
-        $Query =  "
55
+          break;
56
+
57
+        case 'downloaded':
58
+          $Query =  "
59
           SELECT Downloaded
59
           SELECT Downloaded
60
           FROM users_main
60
           FROM users_main
61
           WHERE Enabled = '1'
61
           WHERE Enabled = '1'
62
             AND Downloaded > 0
62
             AND Downloaded > 0
63
           ORDER BY Downloaded;";
63
           ORDER BY Downloaded;";
64
-        break;
65
-      case 'uploads':
66
-        $Query = "
64
+          break;
65
+
66
+        case 'uploads':
67
+          $Query = "
67
           SELECT COUNT(t.ID) AS Uploads
68
           SELECT COUNT(t.ID) AS Uploads
68
           FROM users_main AS um
69
           FROM users_main AS um
69
             JOIN torrents AS t ON t.UserID = um.ID
70
             JOIN torrents AS t ON t.UserID = um.ID
70
           WHERE um.Enabled = '1'
71
           WHERE um.Enabled = '1'
71
           GROUP BY um.ID
72
           GROUP BY um.ID
72
           ORDER BY Uploads;";
73
           ORDER BY Uploads;";
73
-        break;
74
-      case 'requests':
75
-        $Query = "
74
+          break;
75
+
76
+        case 'requests':
77
+          $Query = "
76
           SELECT COUNT(r.ID) AS Requests
78
           SELECT COUNT(r.ID) AS Requests
77
           FROM users_main AS um
79
           FROM users_main AS um
78
             JOIN requests AS r ON r.FillerID = um.ID
80
             JOIN requests AS r ON r.FillerID = um.ID
79
           WHERE um.Enabled = '1'
81
           WHERE um.Enabled = '1'
80
           GROUP BY um.ID
82
           GROUP BY um.ID
81
           ORDER BY Requests;";
83
           ORDER BY Requests;";
82
-        break;
83
-      case 'posts':
84
-        $Query = "
84
+          break;
85
+
86
+        case 'posts':
87
+          $Query = "
85
           SELECT COUNT(p.ID) AS Posts
88
           SELECT COUNT(p.ID) AS Posts
86
           FROM users_main AS um
89
           FROM users_main AS um
87
             JOIN forums_posts AS p ON p.AuthorID = um.ID
90
             JOIN forums_posts AS p ON p.AuthorID = um.ID
88
           WHERE um.Enabled = '1'
91
           WHERE um.Enabled = '1'
89
           GROUP BY um.ID
92
           GROUP BY um.ID
90
           ORDER BY Posts;";
93
           ORDER BY Posts;";
91
-        break;
92
-      case 'bounty':
93
-        $Query = "
94
+          break;
95
+
96
+        case 'bounty':
97
+          $Query = "
94
           SELECT SUM(rv.Bounty) AS Bounty
98
           SELECT SUM(rv.Bounty) AS Bounty
95
           FROM users_main AS um
99
           FROM users_main AS um
96
             JOIN requests_votes AS rv ON rv.UserID = um.ID
100
             JOIN requests_votes AS rv ON rv.UserID = um.ID
97
           WHERE um.Enabled = '1' " .
101
           WHERE um.Enabled = '1' " .
98
           "GROUP BY um.ID
102
           "GROUP BY um.ID
99
           ORDER BY Bounty;";
103
           ORDER BY Bounty;";
100
-        break;
101
-      case 'artists':
102
-        $Query = "
104
+          break;
105
+
106
+        case 'artists':
107
+          $Query = "
103
           SELECT COUNT(ta.ArtistID) AS Artists
108
           SELECT COUNT(ta.ArtistID) AS Artists
104
           FROM torrents_artists AS ta
109
           FROM torrents_artists AS ta
105
             JOIN torrents_group AS tg ON tg.ID = ta.GroupID
110
             JOIN torrents_group AS tg ON tg.ID = ta.GroupID
107
           WHERE t.UserID != ta.UserID
112
           WHERE t.UserID != ta.UserID
108
           GROUP BY tg.ID
113
           GROUP BY tg.ID
109
           ORDER BY Artists ASC";
114
           ORDER BY Artists ASC";
110
-        break;
111
-    }
115
+          break;
116
+        }
112
         return $Query;
117
         return $Query;
113
     }
118
     }
114
 
119
 
130
                 G::$Cache->delete_value(self::PREFIX.$TableName.'_lock');
135
                 G::$Cache->delete_value(self::PREFIX.$TableName.'_lock');
131
             }
136
             }
132
         }
137
         }
138
+
133
         $LastPercentile = 0;
139
         $LastPercentile = 0;
134
         foreach ($Table as $Row) {
140
         foreach ($Table as $Row) {
135
             list($CurValue) = $Row;
141
             list($CurValue) = $Row;
147
         if ($Ratio > 1) {
153
         if ($Ratio > 1) {
148
             $Ratio = 1;
154
             $Ratio = 1;
149
         }
155
         }
156
+
150
         $TotalScore = 0;
157
         $TotalScore = 0;
151
         if (in_array(false, func_get_args(), true)) {
158
         if (in_array(false, func_get_args(), true)) {
152
             return false;
159
             return false;
153
         }
160
         }
161
+        
154
         $TotalScore += $Uploaded * 15;
162
         $TotalScore += $Uploaded * 15;
155
         $TotalScore += $Downloaded * 8;
163
         $TotalScore += $Downloaded * 8;
156
         $TotalScore += $Uploads * 25;
164
         $TotalScore += $Uploads * 25;

+ 196
- 163
classes/users.class.php View File

15
         if (!$Classes || !$ClassLevels) {
15
         if (!$Classes || !$ClassLevels) {
16
             $QueryID = G::$DB->get_query_id();
16
             $QueryID = G::$DB->get_query_id();
17
             G::$DB->query('
17
             G::$DB->query('
18
-        SELECT ID, Name, Abbreviation, Level, Secondary
19
-        FROM permissions
20
-        ORDER BY Level');
18
+            SELECT ID, Name, Abbreviation, Level, Secondary
19
+            FROM permissions
20
+              ORDER BY Level');
21
+
21
             $Classes = G::$DB->to_array('ID');
22
             $Classes = G::$DB->to_array('ID');
22
             $ClassLevels = G::$DB->to_array('Level');
23
             $ClassLevels = G::$DB->to_array('Level');
23
             G::$DB->set_query_id($QueryID);
24
             G::$DB->set_query_id($QueryID);
24
             G::$Cache->cache_value('classes', [$Classes, $ClassLevels], 0);
25
             G::$Cache->cache_value('classes', [$Classes, $ClassLevels], 0);
25
         }
26
         }
26
-        $Debug->set_flag('Loaded permissions');
27
 
27
 
28
+        $Debug->set_flag('Loaded permissions');
28
         return [$Classes, $ClassLevels];
29
         return [$Classes, $ClassLevels];
29
     }
30
     }
30
 
31
 
31
-
32
     /**
32
     /**
33
      * Get user info, is used for the current user and usernames all over the site.
33
      * Get user info, is used for the current user and usernames all over the site.
34
      *
34
      *
59
             $OldQueryID = G::$DB->get_query_id();
59
             $OldQueryID = G::$DB->get_query_id();
60
 
60
 
61
             G::$DB->query("
61
             G::$DB->query("
62
-        SELECT
63
-          m.ID,
64
-          m.Username,
65
-          m.PermissionID,
66
-          m.Paranoia,
67
-          i.Artist,
68
-          i.Donor,
69
-          i.Warned,
70
-          i.Avatar,
71
-          m.Enabled,
72
-          m.Title,
73
-          i.CatchupTime,
74
-          m.Visible,
75
-          la.Type AS LockedAccount,
76
-          GROUP_CONCAT(ul.PermissionID SEPARATOR ',') AS Levels
77
-        FROM users_main AS m
78
-          INNER JOIN users_info AS i ON i.UserID = m.ID
79
-          LEFT JOIN locked_accounts AS la ON la.UserID = m.ID
80
-          LEFT JOIN users_levels AS ul ON ul.UserID = m.ID
81
-        WHERE m.ID = '$UserID'
82
-        GROUP BY m.ID");
62
+            SELECT
63
+              m.ID,
64
+              m.Username,
65
+              m.PermissionID,
66
+              m.Paranoia,
67
+              i.Artist,
68
+              i.Donor,
69
+              i.Warned,
70
+              i.Avatar,
71
+              m.Enabled,
72
+              m.Title,
73
+              i.CatchupTime,
74
+              m.Visible,
75
+              la.Type AS LockedAccount,
76
+            GROUP_CONCAT(ul.PermissionID SEPARATOR ',') AS Levels
77
+            FROM users_main AS m
78
+              INNER JOIN users_info AS i ON i.UserID = m.ID
79
+              LEFT JOIN locked_accounts AS la ON la.UserID = m.ID
80
+              LEFT JOIN users_levels AS ul ON ul.UserID = m.ID
81
+            WHERE m.ID = '$UserID'
82
+              GROUP BY m.ID");
83
 
83
 
84
             if (!G::$DB->has_results()) { // Deleted user, maybe?
84
             if (!G::$DB->has_results()) { // Deleted user, maybe?
85
                 $UserInfo = [
85
                 $UserInfo = [
86
-          'ID'           => $UserID,
87
-          'Username'     => '',
88
-          'PermissionID' => 0,
89
-          'Paranoia'     => [],
90
-          'Artist'       => false,
91
-          'Donor'        => false,
92
-          'Warned'       => null,
93
-          'Avatar'       => '',
94
-          'Enabled'      => 0,
95
-          'Title'        => '',
96
-          'CatchupTime'  => 0,
97
-          'Visible'      => '1',
98
-          'Levels'       => '',
99
-          'Class'        => 0
100
-        ];
86
+                    'ID'           => $UserID,
87
+                    'Username'     => '',
88
+                    'PermissionID' => 0,
89
+                    'Paranoia'     => [],
90
+                    'Artist'       => false,
91
+                    'Donor'        => false,
92
+                    'Warned'       => null,
93
+                    'Avatar'       => '',
94
+                    'Enabled'      => 0,
95
+                    'Title'        => '',
96
+                    'CatchupTime'  => 0,
97
+                    'Visible'      => '1',
98
+                    'Levels'       => '',
99
+                    'Class'        => 0
100
+                ];
101
             } else {
101
             } else {
102
                 $UserInfo = G::$DB->next_record(MYSQLI_ASSOC, ['Paranoia', 'Title']);
102
                 $UserInfo = G::$DB->next_record(MYSQLI_ASSOC, ['Paranoia', 'Title']);
103
                 $UserInfo['CatchupTime'] = strtotime($UserInfo['CatchupTime']);
103
                 $UserInfo['CatchupTime'] = strtotime($UserInfo['CatchupTime']);
104
+
104
                 if (!is_array($UserInfo['Paranoia'])) {
105
                 if (!is_array($UserInfo['Paranoia'])) {
105
                     $UserInfo['Paranoia'] = json_decode($UserInfo['Paranoia'], true);
106
                     $UserInfo['Paranoia'] = json_decode($UserInfo['Paranoia'], true);
106
                 }
107
                 }
108
+
107
                 if (!$UserInfo['Paranoia']) {
109
                 if (!$UserInfo['Paranoia']) {
108
                     $UserInfo['Paranoia'] = [];
110
                     $UserInfo['Paranoia'] = [];
109
                 }
111
                 }
110
                 $UserInfo['Class'] = $Classes[$UserInfo['PermissionID']]['Level'];
112
                 $UserInfo['Class'] = $Classes[$UserInfo['PermissionID']]['Level'];
111
 
113
 
112
                 G::$DB->query("
114
                 G::$DB->query("
113
-          SELECT BadgeID, Displayed
114
-          FROM users_badges
115
-          WHERE UserID = ".$UserID);
115
+                SELECT BadgeID, Displayed
116
+                FROM users_badges
117
+                  WHERE UserID = ".$UserID);
116
 
118
 
117
                 $Badges = [];
119
                 $Badges = [];
118
                 if (G::$DB->has_results()) {
120
                 if (G::$DB->has_results()) {
132
             } else {
134
             } else {
133
                 $UserInfo['ExtraClasses'] = [];
135
                 $UserInfo['ExtraClasses'] = [];
134
             }
136
             }
137
+
135
             unset($UserInfo['Levels']);
138
             unset($UserInfo['Levels']);
136
             $EffectiveClass = $UserInfo['Class'];
139
             $EffectiveClass = $UserInfo['Class'];
137
             foreach ($UserInfo['ExtraClasses'] as $Class => $Val) {
140
             foreach ($UserInfo['ExtraClasses'] as $Class => $Val) {
142
             G::$Cache->cache_value("user_info_$UserID", $UserInfo, 2592000);
145
             G::$Cache->cache_value("user_info_$UserID", $UserInfo, 2592000);
143
             G::$DB->set_query_id($OldQueryID);
146
             G::$DB->set_query_id($OldQueryID);
144
         }
147
         }
148
+
145
         if (strtotime($UserInfo['Warned']) < time()) {
149
         if (strtotime($UserInfo['Warned']) < time()) {
146
             $UserInfo['Warned'] = null;
150
             $UserInfo['Warned'] = null;
147
             G::$Cache->cache_value("user_info_$UserID", $UserInfo, 2592000);
151
             G::$Cache->cache_value("user_info_$UserID", $UserInfo, 2592000);
148
         }
152
         }
149
-
150
         return $UserInfo;
153
         return $UserInfo;
151
     }
154
     }
152
 
155
 
164
         if (empty($HeavyInfo)) {
167
         if (empty($HeavyInfo)) {
165
             $QueryID = G::$DB->get_query_id();
168
             $QueryID = G::$DB->get_query_id();
166
             G::$DB->query("
169
             G::$DB->query("
167
-        SELECT
168
-          m.Invites,
169
-          m.torrent_pass,
170
-          m.IP,
171
-          m.CustomPermissions,
172
-          m.can_leech AS CanLeech,
173
-          i.AuthKey,
174
-          i.RatioWatchEnds,
175
-          i.RatioWatchDownload,
176
-          i.StyleID,
177
-          i.StyleURL,
178
-          i.DisableInvites,
179
-          i.DisablePosting,
180
-          i.DisableUpload,
181
-          i.DisableWiki,
182
-          i.DisableAvatar,
183
-          i.DisablePM,
184
-          i.DisablePoints,
185
-          i.DisablePromotion,
186
-          i.DisableRequests,
187
-          i.DisableForums,
188
-          i.DisableTagging,
189
-          i.SiteOptions,
190
-          i.LastReadNews,
191
-          i.LastReadBlog,
192
-          i.RestrictedForums,
193
-          i.PermittedForums,
194
-          m.FLTokens,
195
-          m.BonusPoints,
196
-          m.HnR,
197
-          m.PermissionID
198
-        FROM users_main AS m
199
-          INNER JOIN users_info AS i ON i.UserID = m.ID
200
-        WHERE m.ID = '$UserID'");
201
-            $HeavyInfo = G::$DB->next_record(MYSQLI_ASSOC, ['CustomPermissions', 'SiteOptions']);
170
+            SELECT
171
+              m.Invites,
172
+              m.torrent_pass,
173
+              m.IP,
174
+              m.CustomPermissions,
175
+              m.can_leech AS CanLeech,
176
+              i.AuthKey,
177
+              i.RatioWatchEnds,
178
+              i.RatioWatchDownload,
179
+              i.StyleID,
180
+              i.StyleURL,
181
+              i.DisableInvites,
182
+              i.DisablePosting,
183
+              i.DisableUpload,
184
+              i.DisableWiki,
185
+              i.DisableAvatar,
186
+              i.DisablePM,
187
+              i.DisablePoints,
188
+              i.DisablePromotion,
189
+              i.DisableRequests,
190
+              i.DisableForums,
191
+              i.DisableTagging,
192
+              i.SiteOptions,
193
+              i.LastReadNews,
194
+              i.LastReadBlog,
195
+              i.RestrictedForums,
196
+              i.PermittedForums,
197
+              m.FLTokens,
198
+              m.BonusPoints,
199
+              m.HnR,
200
+              m.PermissionID
201
+            FROM users_main AS m
202
+              INNER JOIN users_info AS i ON i.UserID = m.ID
203
+              WHERE m.ID = '$UserID'");
202
 
204
 
205
+            $HeavyInfo = G::$DB->next_record(MYSQLI_ASSOC, ['CustomPermissions', 'SiteOptions']);
203
             $HeavyInfo['CustomPermissions'] = [];
206
             $HeavyInfo['CustomPermissions'] = [];
207
+
204
             if (!empty($HeavyInfo['CustomPermissions'])) {
208
             if (!empty($HeavyInfo['CustomPermissions'])) {
205
                 $HeavyInfo['CustomPermissions'] = json_decode($HeavyInfo['CustomPermissions'], true);
209
                 $HeavyInfo['CustomPermissions'] = json_decode($HeavyInfo['CustomPermissions'], true);
206
             }
210
             }
218
             unset($HeavyInfo['PermittedForums']);
222
             unset($HeavyInfo['PermittedForums']);
219
 
223
 
220
             G::$DB->query("
224
             G::$DB->query("
221
-        SELECT PermissionID
222
-        FROM users_levels
223
-        WHERE UserID = $UserID");
225
+            SELECT PermissionID
226
+            FROM users_levels
227
+              WHERE UserID = $UserID");
228
+
224
             $PermIDs = G::$DB->collect('PermissionID');
229
             $PermIDs = G::$DB->collect('PermissionID');
225
             foreach ($PermIDs as $PermID) {
230
             foreach ($PermIDs as $PermID) {
226
                 $Perms = Permissions::get_permissions($PermID);
231
                 $Perms = Permissions::get_permissions($PermID);
228
                     $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',', $Perms['PermittedForums'])));
233
                     $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',', $Perms['PermittedForums'])));
229
                 }
234
                 }
230
             }
235
             }
236
+
231
             $Perms = Permissions::get_permissions($HeavyInfo['PermissionID']);
237
             $Perms = Permissions::get_permissions($HeavyInfo['PermissionID']);
232
             unset($HeavyInfo['PermissionID']);
238
             unset($HeavyInfo['PermissionID']);
233
             if (!empty($Perms['PermittedForums'])) {
239
             if (!empty($Perms['PermittedForums'])) {
240
                 foreach ($RestrictedForums as $ForumID) {
246
                 foreach ($RestrictedForums as $ForumID) {
241
                     $HeavyInfo['CustomForums'][$ForumID] = 0;
247
                     $HeavyInfo['CustomForums'][$ForumID] = 0;
242
                 }
248
                 }
249
+
243
                 foreach ($PermittedForums as $ForumID) {
250
                 foreach ($PermittedForums as $ForumID) {
244
                     $HeavyInfo['CustomForums'][$ForumID] = 1;
251
                     $HeavyInfo['CustomForums'][$ForumID] = 1;
245
                 }
252
                 }
246
             }
253
             }
254
+
247
             if (isset($HeavyInfo['CustomForums'][''])) {
255
             if (isset($HeavyInfo['CustomForums'][''])) {
248
                 unset($HeavyInfo['CustomForums']['']);
256
                 unset($HeavyInfo['CustomForums']['']);
249
             }
257
             }
255
             unset($HeavyInfo['SiteOptions']);
263
             unset($HeavyInfo['SiteOptions']);
256
 
264
 
257
             G::$DB->set_query_id($QueryID);
265
             G::$DB->set_query_id($QueryID);
258
-
259
             G::$Cache->cache_value("user_info_heavy_$UserID", $HeavyInfo, 0);
266
             G::$Cache->cache_value("user_info_heavy_$UserID", $HeavyInfo, 0);
260
         }
267
         }
261
         return $HeavyInfo;
268
         return $HeavyInfo;
273
         if (!is_number($UserID)) {
280
         if (!is_number($UserID)) {
274
             error(0);
281
             error(0);
275
         }
282
         }
283
+
276
         if (empty($NewOptions)) {
284
         if (empty($NewOptions)) {
277
             return false;
285
             return false;
278
         }
286
         }
281
 
289
 
282
         // Get SiteOptions
290
         // Get SiteOptions
283
         G::$DB->query("
291
         G::$DB->query("
284
-      SELECT SiteOptions
285
-      FROM users_info
286
-      WHERE UserID = $UserID");
292
+        SELECT SiteOptions
293
+        FROM users_info
294
+          WHERE UserID = $UserID");
295
+
287
         list($SiteOptions) = G::$DB->next_record(MYSQLI_NUM, false);
296
         list($SiteOptions) = G::$DB->next_record(MYSQLI_NUM, false);
288
         $SiteOptions = json_decode($SiteOptions, true);
297
         $SiteOptions = json_decode($SiteOptions, true);
289
 
298
 
296
 
305
 
297
         // Update DB
306
         // Update DB
298
         G::$DB->query("
307
         G::$DB->query("
299
-      UPDATE users_info
300
-      SET SiteOptions = '".db_string(json_encode($SiteOptions, true))."'
301
-      WHERE UserID = $UserID");
308
+        UPDATE users_info
309
+        SET SiteOptions = '".db_string(json_encode($SiteOptions, true))."'
310
+          WHERE UserID = $UserID");
302
         G::$DB->set_query_id($QueryID);
311
         G::$DB->set_query_id($QueryID);
303
 
312
 
304
         // Update cache
313
         // Update cache
370
     {
379
     {
371
         global $Classes;
380
         global $Classes;
372
 
381
 
373
-        if ($UserID == 0) {
382
+        if ($UserID === 0) {
374
             return 'System';
383
             return 'System';
375
         }
384
         }
376
 
385
 
377
         $UserInfo = self::user_info($UserID);
386
         $UserInfo = self::user_info($UserID);
378
-        if ($UserInfo['Username'] == '') {
387
+        if ($UserInfo['Username'] === '') {
379
             return "Unknown [$UserID]";
388
             return "Unknown [$UserID]";
380
         }
389
         }
381
 
390
 
404
         }
413
         }
405
         if ($Badges) {
414
         if ($Badges) {
406
             $DonorRank = Donations::get_rank($UserID);
415
             $DonorRank = Donations::get_rank($UserID);
407
-            if ($DonorRank == 0 && $UserInfo['Donor'] == 1) {
416
+            if ($DonorRank == 0 && $UserInfo['Donor'] === 1) {
408
                 $DonorRank = 1;
417
                 $DonorRank = 1;
409
             }
418
             }
419
+
410
             if ($ShowDonorIcon && $DonorRank > 0) {
420
             if ($ShowDonorIcon && $DonorRank > 0) {
411
                 $IconLink = 'donate.php';
421
                 $IconLink = 'donate.php';
412
                 $IconImage = 'donor.png';
422
                 $IconImage = 'donor.png';
415
                 $SpecialRank = Donations::get_special_rank($UserID);
425
                 $SpecialRank = Donations::get_special_rank($UserID);
416
                 $EnabledRewards = Donations::get_enabled_rewards($UserID);
426
                 $EnabledRewards = Donations::get_enabled_rewards($UserID);
417
                 $DonorRewards = Donations::get_rewards($UserID);
427
                 $DonorRewards = Donations::get_rewards($UserID);
428
+
418
                 if ($EnabledRewards['HasDonorIconMouseOverText'] && !empty($DonorRewards['IconMouseOverText'])) {
429
                 if ($EnabledRewards['HasDonorIconMouseOverText'] && !empty($DonorRewards['IconMouseOverText'])) {
419
                     $IconText = display_str($DonorRewards['IconMouseOverText']);
430
                     $IconText = display_str($DonorRewards['IconMouseOverText']);
420
                 }
431
                 }
432
+
421
                 if ($EnabledRewards['HasDonorIconLink'] && !empty($DonorRewards['CustomIconLink'])) {
433
                 if ($EnabledRewards['HasDonorIconLink'] && !empty($DonorRewards['CustomIconLink'])) {
422
                     $IconLink = display_str($DonorRewards['CustomIconLink']);
434
                     $IconLink = display_str($DonorRewards['CustomIconLink']);
423
                 }
435
                 }
436
+
424
                 if ($EnabledRewards['HasCustomDonorIcon'] && !empty($DonorRewards['CustomIcon'])) {
437
                 if ($EnabledRewards['HasCustomDonorIcon'] && !empty($DonorRewards['CustomIcon'])) {
425
                     $IconImage = ImageTools::process($DonorRewards['CustomIcon']);
438
                     $IconImage = ImageTools::process($DonorRewards['CustomIcon']);
426
                 } else {
439
                 } else {
431
                     } elseif ($DonorRank >= MAX_RANK) {
444
                     } elseif ($DonorRank >= MAX_RANK) {
432
                         $DonorHeart = 5;
445
                         $DonorHeart = 5;
433
                     }
446
                     }
447
+
434
                     if ($DonorHeart === 1) {
448
                     if ($DonorHeart === 1) {
435
                         $IconImage = STATIC_SERVER . 'common/symbols/donor.png';
449
                         $IconImage = STATIC_SERVER . 'common/symbols/donor.png';
436
                     } else {
450
                     } else {
442
             $Str .= Badges::display_badges(Badges::get_displayed_badges($UserID), true);
456
             $Str .= Badges::display_badges(Badges::get_displayed_badges($UserID), true);
443
         }
457
         }
444
 
458
 
445
-        $Str .= ($IsWarned && $UserInfo['Warned']) ? '<a href="wiki.php?action=article&amp;name=warnings"'
446
-          . '><img src="'.STATIC_SERVER.'common/symbols/warned.png" alt="Warned" title="Warned'
447
-          . (G::$LoggedUser['ID'] === $UserID ? ' - Expires ' . date('Y-m-d H:i', strtotime($UserInfo['Warned'])) : '')
448
-          . '" class="tooltip" /></a>' : '';
449
-        $Str .= ($IsEnabled && $UserInfo['Enabled'] == 2) ? '<a href="rules.php"><img src="'.STATIC_SERVER.'common/symbols/disabled.png" alt="Banned" title="Disabled" class="tooltip" /></a>' : '';
459
+        $Str .= ($IsWarned && $UserInfo['Warned'])
460
+          ? '<a href="wiki.php?action=article&amp;name=warnings"'.'><img src="'.STATIC_SERVER.'common/symbols/warned.png" alt="Warned" title="Warned'.(G::$LoggedUser['ID'] === $UserID ? ' - Expires '.date('Y-m-d H:i', strtotime($UserInfo['Warned']))
461
+          : '').'" class="tooltip" /></a>'
462
+          : '';
463
+
464
+        $Str .= ($IsEnabled && $UserInfo['Enabled'] === 2)
465
+          ? '<a href="rules.php"><img src="'.STATIC_SERVER.'common/symbols/disabled.png" alt="Banned" title="Disabled" class="tooltip" /></a>'
466
+          : '';
450
 
467
 
451
         if ($Class) {
468
         if ($Class) {
452
             foreach (array_keys($UserInfo['ExtraClasses']) as $ExtraClass) {
469
             foreach (array_keys($UserInfo['ExtraClasses']) as $ExtraClass) {
453
                 $Str .= ' ['.Users::make_class_abbrev_string($ExtraClass).']';
470
                 $Str .= ' ['.Users::make_class_abbrev_string($ExtraClass).']';
454
             }
471
             }
472
+
455
             if ($Title) {
473
             if ($Title) {
456
                 $Str .= ' <strong>('.Users::make_class_string($UserInfo['PermissionID']).')</strong>';
474
                 $Str .= ' <strong>('.Users::make_class_string($UserInfo['PermissionID']).')</strong>';
457
             } else {
475
             } else {
463
             // Image proxy CTs
481
             // Image proxy CTs
464
             if (check_perms('site_proxy_images') && !empty($UserInfo['Title'])) {
482
             if (check_perms('site_proxy_images') && !empty($UserInfo['Title'])) {
465
                 $UserInfo['Title'] = preg_replace_callback(
483
                 $UserInfo['Title'] = preg_replace_callback(
466
-            '~src=("?)(http.+?)(["\s>])~',
467
-            function ($Matches) {
468
-                return 'src=' . $Matches[1] . ImageTools::process($Matches[2]) . $Matches[3];
469
-            },
470
-            $UserInfo['Title']
471
-        );
484
+                    '~src=("?)(http.+?)(["\s>])~',
485
+                    function ($Matches) {
486
+                        return 'src=' . $Matches[1] . ImageTools::process($Matches[2]) . $Matches[3];
487
+                    },
488
+                    $UserInfo['Title']
489
+                );
472
             }
490
             }
473
 
491
 
474
             if ($UserInfo['Title']) {
492
             if ($UserInfo['Title']) {
510
         } else {
528
         } else {
511
             $QueryID = G::$DB->get_query_id();
529
             $QueryID = G::$DB->get_query_id();
512
             G::$DB->query("
530
             G::$DB->query("
513
-        SELECT GroupID, Sort, `Time`
514
-        FROM bookmarks_torrents
515
-        WHERE UserID = $UserID
516
-        ORDER BY Sort, `Time` ASC");
531
+            SELECT GroupID, Sort, `Time`
532
+            FROM bookmarks_torrents
533
+              WHERE UserID = $UserID
534
+              ORDER BY Sort, `Time` ASC");
535
+
517
             $GroupIDs = G::$DB->collect('GroupID');
536
             $GroupIDs = G::$DB->collect('GroupID');
518
             $BookmarkData = G::$DB->to_array('GroupID', MYSQLI_ASSOC);
537
             $BookmarkData = G::$DB->to_array('GroupID', MYSQLI_ASSOC);
519
             G::$DB->set_query_id($QueryID);
538
             G::$DB->set_query_id($QueryID);
521
         }
540
         }
522
 
541
 
523
         $TorrentList = Torrents::get_groups($GroupIDs);
542
         $TorrentList = Torrents::get_groups($GroupIDs);
524
-
525
         return [$GroupIDs, $BookmarkData, $TorrentList];
543
         return [$GroupIDs, $BookmarkData, $TorrentList];
526
     }
544
     }
527
 
545
 
548
             $Rewards = Donations::get_rewards($UserID);
566
             $Rewards = Donations::get_rewards($UserID);
549
             $AvatarMouseOverText = $Rewards['AvatarMouseOverText'];
567
             $AvatarMouseOverText = $Rewards['AvatarMouseOverText'];
550
         }
568
         }
569
+
551
         if (!empty($AvatarMouseOverText)) {
570
         if (!empty($AvatarMouseOverText)) {
552
             $AvatarMouseOverText =  "title=\"$AvatarMouseOverText\" alt=\"$AvatarMouseOverText\"";
571
             $AvatarMouseOverText =  "title=\"$AvatarMouseOverText\" alt=\"$AvatarMouseOverText\"";
553
         } else {
572
         } else {
554
             $AvatarMouseOverText = "alt=\"$Username's avatar\"";
573
             $AvatarMouseOverText = "alt=\"$Username's avatar\"";
555
         }
574
         }
575
+
556
         if ($EnabledRewards['HasSecondAvatar'] && !empty($Rewards['SecondAvatar'])) {
576
         if ($EnabledRewards['HasSecondAvatar'] && !empty($Rewards['SecondAvatar'])) {
557
             $SecondAvatar = ' data-gazelle-second-avatar="' . ImageTools::process($Rewards['SecondAvatar'], 'avatar') . '"';
577
             $SecondAvatar = ' data-gazelle-second-avatar="' . ImageTools::process($Rewards['SecondAvatar'], 'avatar') . '"';
558
         }
578
         }
559
-        // case 1 is avatars disabled
579
+
580
+        // Case 1 is avatars disabled
560
         switch ($Setting) {
581
         switch ($Setting) {
561
-      case 0:
562
-        if (!empty($Avatar)) {
563
-            $ToReturn = ($ReturnHTML ? "<a href=\"user.php?id=$UserID\"><img src=\"$Avatar\" ".($Size?"width=\"$Size\" ":"")."$Style $AvatarMouseOverText$SecondAvatar $Class /></a>" : $Avatar);
564
-        } else {
565
-            $URL = STATIC_SERVER.'common/avatars/default.png';
566
-            $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar />" : $URL);
567
-        }
568
-        break;
569
-      case 2:
570
-        $ShowAvatar = true;
571
-        // no break
572
-      case 3:
573
-        switch (G::$LoggedUser['Identicons']) {
582
+        case 0:
583
+          if (!empty($Avatar)) {
584
+              $ToReturn = ($ReturnHTML ? "<a href=\"user.php?id=$UserID\"><img src=\"$Avatar\" ".($Size?"width=\"$Size\" ":"")."$Style $AvatarMouseOverText$SecondAvatar $Class /></a>" : $Avatar);
585
+          } else {
586
+              $URL = STATIC_SERVER.'common/avatars/default.png';
587
+              $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar />" : $URL);
588
+          }
589
+          break;
590
+
591
+        case 2:
592
+          $ShowAvatar = true;
593
+          // no break
594
+
595
+        case 3:
596
+          switch (G::$LoggedUser['Identicons']) {
574
           case 0:
597
           case 0:
575
             $Type = 'identicon';
598
             $Type = 'identicon';
576
             break;
599
             break;
598
           default:
621
           default:
599
             $Type = 'identicon';
622
             $Type = 'identicon';
600
         }
623
         }
601
-        $Rating = 'pg';
602
-        if (!isset($Robot) || !$Robot) {
603
-            $URL = 'https://secure.gravatar.com/avatar/'.md5(strtolower(trim($Username)))."?s=$Size&amp;d=$Type&amp;r=$Rating";
604
-        } else {
605
-            $URL = 'https://robohash.org/'.md5($Username)."?set=set$Type&amp;size={$Size}x$Size";
606
-        }
607
-        if ($ShowAvatar == true && !empty($Avatar)) {
608
-            $ToReturn = ($ReturnHTML ? "<img src=\"$Avatar\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar $Class />" : $Avatar);
609
-        } else {
610
-            $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText $Class />" : $URL);
624
+
625
+          $Rating = 'pg';
626
+          if (!isset($Robot) || !$Robot) {
627
+              $URL = 'https://secure.gravatar.com/avatar/'.md5(strtolower(trim($Username)))."?s=$Size&amp;d=$Type&amp;r=$Rating";
628
+          } else {
629
+              $URL = 'https://robohash.org/'.md5($Username)."?set=set$Type&amp;size={$Size}x$Size";
630
+          }
631
+
632
+          if ($ShowAvatar === true && !empty($Avatar)) {
633
+              $ToReturn = ($ReturnHTML ? "<img src=\"$Avatar\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar $Class />" : $Avatar);
634
+          } else {
635
+              $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText $Class />" : $URL);
636
+          }
637
+          break;
638
+
639
+        default:
640
+          $URL = STATIC_SERVER.'common/avatars/default.png';
641
+          $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar $Class/>" : $URL);
611
         }
642
         }
612
-        break;
613
-      default:
614
-        $URL = STATIC_SERVER.'common/avatars/default.png';
615
-        $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar $Class/>" : $URL);
616
-    }
617
         return $ToReturn;
643
         return $ToReturn;
618
     }
644
     }
619
 
645
 
620
     public static function has_avatars_enabled()
646
     public static function has_avatars_enabled()
621
     {
647
     {
622
         global $HeavyInfo;
648
         global $HeavyInfo;
623
-        return isset($HeavyInfo['DisableAvatars']) && ($HeavyInfo['DisableAvatars'] != 1);
649
+        return isset($HeavyInfo['DisableAvatars']) && ($HeavyInfo['DisableAvatars'] !== 1);
624
     }
650
     }
625
 
651
 
626
     /**
652
     /**
639
             $Enabled = true;
665
             $Enabled = true;
640
         } elseif (G::$LoggedUser['AutoComplete'] !== 1) {
666
         } elseif (G::$LoggedUser['AutoComplete'] !== 1) {
641
             switch ($Type) {
667
             switch ($Type) {
642
-        case 'search':
643
-          if (G::$LoggedUser['AutoComplete'] == 2) {
644
-              $Enabled = true;
645
-          }
646
-          break;
647
-        case 'other':
648
-          if (G::$LoggedUser['AutoComplete'] != 2) {
649
-              $Enabled = true;
650
-          }
651
-          break;
652
-      }
668
+            case 'search':
669
+              if (G::$LoggedUser['AutoComplete'] === 2) {
670
+                  $Enabled = true;
671
+              }
672
+              break;
673
+
674
+            case 'other':
675
+              if (G::$LoggedUser['AutoComplete'] !== 2) {
676
+                  $Enabled = true;
677
+              }
678
+              break;
679
+            }
653
         }
680
         }
681
+
654
         if ($Enabled && $Output) {
682
         if ($Enabled && $Output) {
655
             echo ' data-gazelle-autocomplete="true"';
683
             echo ' data-gazelle-autocomplete="true"';
656
         }
684
         }
685
+
657
         if (!$Output) {
686
         if (!$Output) {
658
-            // don't return a boolean if you're echoing HTML
687
+            // Don't return a boolean if you're echoing HTML
659
             return $Enabled;
688
             return $Enabled;
660
         }
689
         }
661
     }
690
     }
671
     {
700
     {
672
         $ResetKey = Users::make_secret();
701
         $ResetKey = Users::make_secret();
673
         G::$DB->query("
702
         G::$DB->query("
674
-      UPDATE users_info
675
-      SET
676
-        ResetKey = '" . db_string($ResetKey) . "',
677
-        ResetExpires = '" . time_plus(60 * 60) . "'
678
-      WHERE UserID = '$UserID'");
679
-        require_once(SERVER_ROOT . '/classes/templates.class.php');
703
+        UPDATE users_info
704
+        SET
705
+          ResetKey = '" . db_string($ResetKey) . "',
706
+          ResetExpires = '" . time_plus(60 * 60) . "'
707
+        WHERE UserID = '$UserID'");
708
+
709
+        require_once SERVER_ROOT . '/classes/templates.class.php';
680
         $TPL = new TEMPLATE;
710
         $TPL = new TEMPLATE;
681
         $TPL->open(SERVER_ROOT . '/templates/password_reset.tpl'); // Password reset template
711
         $TPL->open(SERVER_ROOT . '/templates/password_reset.tpl'); // Password reset template
682
         $TPL->set('Username', $Username);
712
         $TPL->set('Username', $Username);
688
         Misc::send_email($Email, 'Password reset information for ' . SITE_NAME, $TPL->get(), 'noreply');
718
         Misc::send_email($Email, 'Password reset information for ' . SITE_NAME, $TPL->get(), 'noreply');
689
     }
719
     }
690
 
720
 
691
-
692
     /*
721
     /*
693
      * Authorize a new location
722
      * Authorize a new location
694
      *
723
      *
701
     {
730
     {
702
         $AuthKey = Users::make_secret();
731
         $AuthKey = Users::make_secret();
703
         G::$Cache->cache_value('new_location_'.$AuthKey, ['UserID'=>$UserID, 'ASN'=>$ASN], 3600*2);
732
         G::$Cache->cache_value('new_location_'.$AuthKey, ['UserID'=>$UserID, 'ASN'=>$ASN], 3600*2);
704
-        require_once(SERVER_ROOT . '/classes/templates.class.php');
733
+
734
+        require_once SERVER_ROOT . '/classes/templates.class.php';
705
         $TPL = new TEMPLATE;
735
         $TPL = new TEMPLATE;
706
         $TPL->open(SERVER_ROOT . '/templates/new_location.tpl');
736
         $TPL->open(SERVER_ROOT . '/templates/new_location.tpl');
707
         $TPL->set('Username', $Username);
737
         $TPL->set('Username', $Username);
720
         if (!($SourceKey = G::$Cache->get_value('source_key_new'))) {
750
         if (!($SourceKey = G::$Cache->get_value('source_key_new'))) {
721
             G::$Cache->cache_value('source_key_new', $SourceKey = [Users::make_secret(), time()]);
751
             G::$Cache->cache_value('source_key_new', $SourceKey = [Users::make_secret(), time()]);
722
         }
752
         }
753
+
723
         $SourceKeyOld = G::$Cache->get_value('source_key_old');
754
         $SourceKeyOld = G::$Cache->get_value('source_key_old');
724
         if ($SourceKey[1]-time() > 3600) {
755
         if ($SourceKey[1]-time() > 3600) {
725
             G::$Cache->cache_value('source_key_old', $SourceKeyOld = $SourceKey);
756
             G::$Cache->cache_value('source_key_old', $SourceKeyOld = $SourceKey);
726
             G::$Cache->cache_value('source_key_new', $SourceKey = [Users::make_secret(), time()]);
757
             G::$Cache->cache_value('source_key_new', $SourceKey = [Users::make_secret(), time()]);
727
         }
758
         }
759
+
728
         G::$DB->query("
760
         G::$DB->query("
729
-      SELECT
730
-        COUNT(ID)
731
-      FROM torrents
732
-      WHERE UserID = ".G::$LoggedUser['ID']);
761
+        SELECT
762
+          COUNT(ID)
763
+        FROM torrents
764
+          WHERE UserID = ".G::$LoggedUser['ID']);
765
+          
733
         list($Uploads) = G::$DB->next_record();
766
         list($Uploads) = G::$DB->next_record();
734
         $Source[0] = SITE_NAME.'-'.substr(hash('sha256', $SourceKey[0].G::$LoggedUser['ID'].$Uploads), 0, 10);
767
         $Source[0] = SITE_NAME.'-'.substr(hash('sha256', $SourceKey[0].G::$LoggedUser['ID'].$Uploads), 0, 10);
735
         $Source[1] = $SourceKeyOld ? SITE_NAME.'-'.substr(hash('sha256', $SourceKeyOld[0].G::$LoggedUser['ID'].$Uploads), 0, 10) : $Source[0];
768
         $Source[1] = $SourceKeyOld ? SITE_NAME.'-'.substr(hash('sha256', $SourceKeyOld[0].G::$LoggedUser['ID'].$Uploads), 0, 10) : $Source[0];

+ 11
- 0
classes/validate.class.php View File

18
         if (!empty($Options['maxlength'])) {
18
         if (!empty($Options['maxlength'])) {
19
             $this->Fields[$FieldName]['MaxLength'] = $Options['maxlength'];
19
             $this->Fields[$FieldName]['MaxLength'] = $Options['maxlength'];
20
         }
20
         }
21
+
21
         if (!empty($Options['minlength'])) {
22
         if (!empty($Options['minlength'])) {
22
             $this->Fields[$FieldName]['MinLength'] = $Options['minlength'];
23
             $this->Fields[$FieldName]['MinLength'] = $Options['minlength'];
23
         }
24
         }
25
+
24
         if (!empty($Options['comparefield'])) {
26
         if (!empty($Options['comparefield'])) {
25
             $this->Fields[$FieldName]['CompareField'] = $Options['comparefield'];
27
             $this->Fields[$FieldName]['CompareField'] = $Options['comparefield'];
26
         }
28
         }
29
+
27
         if (!empty($Options['allowperiod'])) {
30
         if (!empty($Options['allowperiod'])) {
28
             $this->Fields[$FieldName]['AllowPeriod'] = $Options['allowperiod'];
31
             $this->Fields[$FieldName]['AllowPeriod'] = $Options['allowperiod'];
29
         }
32
         }
33
+
30
         if (!empty($Options['allowcomma'])) {
34
         if (!empty($Options['allowcomma'])) {
31
             $this->Fields[$FieldName]['AllowComma'] = $Options['allowcomma'];
35
             $this->Fields[$FieldName]['AllowComma'] = $Options['allowcomma'];
32
         }
36
         }
37
+
33
         if (!empty($Options['inarray'])) {
38
         if (!empty($Options['inarray'])) {
34
             $this->Fields[$FieldName]['InArray'] = $Options['inarray'];
39
             $this->Fields[$FieldName]['InArray'] = $Options['inarray'];
35
         }
40
         }
41
+
36
         if (!empty($Options['regex'])) {
42
         if (!empty($Options['regex'])) {
37
             $this->Fields[$FieldName]['Regex'] = $Options['regex'];
43
             $this->Fields[$FieldName]['Regex'] = $Options['regex'];
38
         }
44
         }
52
                     } else {
58
                     } else {
53
                         $MaxLength = 255;
59
                         $MaxLength = 255;
54
                     }
60
                     }
61
+
55
                     if (isset($Field['MinLength'])) {
62
                     if (isset($Field['MinLength'])) {
56
                         $MinLength = $Field['MinLength'];
63
                         $MinLength = $Field['MinLength'];
57
                     } else {
64
                     } else {
69
                     } else {
76
                     } else {
70
                         $MaxLength = '';
77
                         $MaxLength = '';
71
                     }
78
                     }
79
+
72
                     if (isset($Field['MinLength'])) {
80
                     if (isset($Field['MinLength'])) {
73
                         $MinLength = $Field['MinLength'];
81
                         $MinLength = $Field['MinLength'];
74
                     } else {
82
                     } else {
79
                     if (isset($Field['AllowPeriod'])) {
87
                     if (isset($Field['AllowPeriod'])) {
80
                         $Match .= '.';
88
                         $Match .= '.';
81
                     }
89
                     }
90
+
82
                     if (isset($Field['AllowComma'])) {
91
                     if (isset($Field['AllowComma'])) {
83
                         $Match .= ',';
92
                         $Match .= ',';
84
                     }
93
                     }
115
                     } else {
124
                     } else {
116
                         $MaxLength = 255;
125
                         $MaxLength = 255;
117
                     }
126
                     }
127
+
118
                     if (isset($Field['MinLength'])) {
128
                     if (isset($Field['MinLength'])) {
119
                         $MinLength = $Field['MinLength'];
129
                         $MinLength = $Field['MinLength'];
120
                     } else {
130
                     } else {
134
                     } else {
144
                     } else {
135
                         $MaxLength = 20;
145
                         $MaxLength = 20;
136
                     }
146
                     }
147
+                    
137
                     if (isset($Field['MinLength'])) {
148
                     if (isset($Field['MinLength'])) {
138
                         $MinLength = $Field['MinLength'];
149
                         $MinLength = $Field['MinLength'];
139
                     } else {
150
                     } else {

+ 6
- 1
sections/forums/forum.php View File

278
         }
278
         }
279
     } ?>
279
     } ?>
280
   </table>
280
   </table>
281
+
281
   <div class="breadcrumbs">
282
   <div class="breadcrumbs">
282
-    <a href="forums.php">Forums</a> › <?=$ForumName?>
283
+    <p>
284
+      <a href="forums.php">Forums</a> › <?=$ForumName?>
285
+    </p>
283
   </div>
286
   </div>
287
+
284
   <div class="linkbox pager">
288
   <div class="linkbox pager">
285
     <?=$Pages?>
289
     <?=$Pages?>
286
   </div>
290
   </div>
291
+
287
   <div class="linkbox"><a
292
   <div class="linkbox"><a
288
       href="forums.php?action=catchup&amp;forumid=<?=$ForumID?>&amp;auth=<?=$LoggedUser['AuthKey']?>"
293
       href="forums.php?action=catchup&amp;forumid=<?=$ForumID?>&amp;auth=<?=$LoggedUser['AuthKey']?>"
289
       class="brackets">Catch up</a></div>
294
       class="brackets">Catch up</a></div>

+ 399
- 313
sections/forums/thread.php
File diff suppressed because it is too large
View File


Loading…
Cancel
Save