Browse Source

Nothing broken in testing

pjc 5 years ago
parent
commit
3fb7eb7c9b

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

@@ -43,7 +43,6 @@ class Comments
43 43
         Subscriptions::quote_notify($Body, $PostID, $Page, $PageID);
44 44
 
45 45
         G::$DB->set_query_id($QueryID);
46
-
47 46
         return $PostID;
48 47
     }
49 48
 
@@ -136,7 +135,8 @@ class Comments
136 135
             return false;
137 136
         }
138 137
         list($Page, $PageID) = G::$DB->next_record();
139
-        // get number of pages
138
+
139
+        // Get number of pages
140 140
         G::$DB->query("
141 141
         SELECT
142 142
           CEIL(COUNT(ID) / " . TORRENT_COMMENTS_PER_PAGE . ") AS Pages,
@@ -145,8 +145,9 @@ class Comments
145 145
           WHERE Page = '$Page'
146 146
           AND PageID = $PageID
147 147
         GROUP BY PageID");
148
+
148 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 151
             G::$DB->set_query_id($QueryID);
151 152
             return false;
152 153
         }
@@ -159,6 +160,7 @@ class Comments
159 160
         G::$DB->query("
160 161
         DELETE FROM comments
161 162
           WHERE ID = $PostID");
163
+
162 164
         G::$DB->query("
163 165
         DELETE FROM comments_edits
164 166
           WHERE Page = '$Page'
@@ -180,14 +182,12 @@ class Comments
180 182
         }
181 183
 
182 184
         G::$Cache->delete_value($Page . '_comments_' . $PageID);
183
-
184 185
         if ($Page === 'collages') {
185 186
             // On collages, we also need to clear the collage key (collage_$CollageID), because it has the comments in it... (why??)
186 187
             G::$Cache->delete_value("collage_$PageID");
187 188
         }
188 189
 
189 190
         G::$DB->set_query_id($QueryID);
190
-
191 191
         return true;
192 192
     }
193 193
 
@@ -223,7 +223,6 @@ class Comments
223 223
     public static function get_url_query($PostID)
224 224
     {
225 225
         $QueryID = G::$DB->get_query_id();
226
-
227 226
         G::$DB->query("
228 227
         SELECT Page, PageID
229 228
         FROM comments
@@ -272,11 +271,12 @@ class Comments
272 271
         // Format::page_limit handles a potential $_GET['page']
273 272
         if (isset($_GET['postid']) && is_number($_GET['postid']) && $NumComments > TORRENT_COMMENTS_PER_PAGE) {
274 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 280
             list($PostNum) = G::$DB->next_record();
281 281
             list($CommPage, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $PostNum);
282 282
         } else {
@@ -291,20 +291,21 @@ class Comments
291 291
         if ($Catalogue === false) {
292 292
             $CatalogueLimit = $CatalogueID * THREAD_CATALOGUE . ', ' . THREAD_CATALOGUE;
293 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 309
             $Catalogue = G::$DB->to_array(false, MYSQLI_ASSOC);
309 310
             G::$Cache->cache_value($Page.'_comments_'.$PageID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
310 311
         }
@@ -318,34 +319,37 @@ class Comments
318 319
             $LastPost = $LastPost['ID'];
319 320
             $FirstPost = reset($Thread);
320 321
             $FirstPost = $FirstPost['ID'];
322
+
321 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 332
             if (G::$DB->affected_rows()) {
330 333
                 G::$Cache->delete_value('notify_quoted_' . G::$LoggedUser['ID']);
331 334
             }
332 335
 
333 336
             // Last read
334 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 344
             list($LastRead) = G::$DB->next_record();
341 345
             if ($LastRead < $LastPost) {
342 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 353
                 G::$Cache->delete_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
350 354
             }
351 355
         } else {
@@ -353,7 +357,6 @@ class Comments
353 357
         }
354 358
 
355 359
         G::$DB->set_query_id($QueryID);
356
-
357 360
         return array($NumComments, $CommPage, $Thread, $LastRead);
358 361
     }
359 362
 

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

@@ -32,19 +32,22 @@ class DEBUG
32 32
         if ($Errors > MAX_ERRORS && !defined('ERROR_EXCEPTION')) {
33 33
             $Reason[] = $Errors.' PHP errors';
34 34
         }
35
+
35 36
         /*
36 37
         $Queries = count($this->get_queries());
37 38
         if ($Queries > MAX_QUERIES && !defined('QUERY_EXCEPTION')) {
38 39
           $Reason[] = $Queries.' Queries';
39 40
         }
40 41
         */
42
+
41 43
         $Ram = memory_get_usage(true);
42 44
         if ($Ram > MAX_MEMORY && !defined('MEMORY_EXCEPTION')) {
43 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 51
         $DBWarningCount = 0;
49 52
         foreach ($Queries as $Query) {
50 53
           if (!empty($Query[2])) {
@@ -53,7 +56,8 @@ class DEBUG
53 56
         }
54 57
         if ($DBWarningCount) {
55 58
           $Reason[] = $DBWarningCount . ' DB warning(s)';
56
-        }*/
59
+        }
60
+        */
57 61
 
58 62
         $CacheStatus = G::$Cache->server_status();
59 63
         if (in_array(0, $CacheStatus) && !G::$Cache->get_value('cache_fail_reported')) {
@@ -75,7 +79,6 @@ class DEBUG
75 79
             $this->analysis(implode(', ', $Reason));
76 80
             return true;
77 81
         }
78
-
79 82
         return false;
80 83
     }
81 84
 
@@ -87,21 +90,22 @@ class DEBUG
87 90
         }
88 91
         $Identifier = Users::make_secret(5);
89 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 109
         $RequestURI = !empty($_SERVER['REQUEST_URI']) ? substr($_SERVER['REQUEST_URI'], 1) : '';
106 110
         send_irc('PRIVMSG '.LAB_CHAN." :{$Message} $Document ".site_url()."tools.php?action=analysis&case=$Identifier ".site_url().$RequestURI);
107 111
     }
@@ -121,9 +125,11 @@ class DEBUG
121 125
     {
122 126
         $BackTrace = debug_backtrace();
123 127
         $ID = Users::make_secret(5);
128
+
124 129
         if (!$VarName) {
125 130
             $VarName = $ID;
126 131
         }
132
+
127 133
         $File = array('path' => substr($BackTrace[0]['file'], strlen(SERVER_ROOT)), 'line' => $BackTrace[0]['line']);
128 134
         $this->LoggedVars[$ID] = array($VarName => array('bt' => $File, 'data' => $Var));
129 135
     }
@@ -134,7 +140,7 @@ class DEBUG
134 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 144
     public function handle_errors()
139 145
     {
140 146
         //error_reporting(E_ALL ^ E_STRICT | E_WARNING | E_DEPRECATED | E_ERROR | E_PARSE); //E_STRICT disabled
@@ -151,6 +157,7 @@ class DEBUG
151 157
             if (!is_int($Key) || !is_int($LastKey) || $Key != $LastKey + 1) {
152 158
                 $Return[$Key] .= "'$Key' => ";
153 159
             }
160
+
154 161
             if ($Val === true) {
155 162
                 $Return[$Key] .= 'true';
156 163
             } elseif ($Val === false) {
@@ -164,6 +171,7 @@ class DEBUG
164 171
             } elseif (is_array($Val)) {
165 172
                 $Return[$Key] .= 'array('.$this->format_args($Val).')';
166 173
             }
174
+
167 175
             $LastKey = $Key;
168 176
         }
169 177
         return implode(', ', $Return);
@@ -171,47 +179,47 @@ class DEBUG
171 179
 
172 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 183
         if (stripos('Undefined index', $Error) !== false) {
176 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 188
         $Call = '';
181 189
         $Args = '';
182 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 193
         if (isset($Tracer[$Steps]['function'], $Tracer[$Steps]['class']) && $Tracer[$Steps]['function'] == 'php_error_handler' && $Tracer[$Steps]['class'] == 'DEBUG') {
186 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 198
         if (isset($Tracer[$Steps]['function']) && $Tracer[$Steps]['function'] == 'trigger_error') {
191 199
             $Steps++;
192 200
             $File = $Tracer[$Steps]['file'];
193 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 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 207
             $Error = 'Type hinting failed on arg '.$Matches[1]. ', expected '.$Matches[2].' but found '.$Matches[3];
200 208
             $File = $Matches[4];
201 209
             $Line = $Matches[5];
202 210
         }
203 211
 
204
-        //Lets not be repetative
212
+        // Let's not be repetative
205 213
         if (($Tracer[$Steps]['function'] == 'include' || $Tracer[$Steps]['function'] == 'require') && isset($Tracer[$Steps]['args'][0]) && $Tracer[$Steps]['args'][0] == $File) {
206 214
             unset($Tracer[$Steps]['args']);
207 215
         }
208 216
 
209
-        //Class
217
+        // Class
210 218
         if (isset($Tracer[$Steps]['class'])) {
211 219
             $Call .= $Tracer[$Steps]['class'].'::';
212 220
         }
213 221
 
214
-        //Function & args
222
+        // Function & args
215 223
         if (isset($Tracer[$Steps]['function'])) {
216 224
             $Call .= $Tracer[$Steps]['function'];
217 225
             if (isset($Tracer[$Steps]['args'][0])) {
@@ -219,7 +227,7 @@ class DEBUG
219 227
             }
220 228
         }
221 229
 
222
-        //Shorten the path & we're done
230
+        // Shorten the path & we're done
223 231
         $File = str_replace(SERVER_ROOT, '', $File);
224 232
         $Error = str_replace(SERVER_ROOT, '', $Error);
225 233
 
@@ -238,8 +246,9 @@ class DEBUG
238 246
             $PageTime = (microtime(true) - $ScriptStartTime);
239 247
             $CPUTime = $this->get_cpu_time();
240 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 252
             if ($CPUTime) {
244 253
                 $Perf['CPU time'] = number_format($CPUTime / 1000000, 3).' s';
245 254
             }
@@ -255,7 +264,7 @@ class DEBUG
255 264
 
256 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 268
         if ($Light) {
260 269
             foreach ($this->Errors as $Key => $Value) {
261 270
                 $this->Errors[$Key][3] = '';
@@ -347,6 +356,7 @@ class DEBUG
347 356
         if (empty($Perf)) {
348 357
             return;
349 358
         } ?>
359
+
350 360
 <table class="layout">
351 361
   <tr>
352 362
     <td><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_perf').gtoggle(); return false;"
@@ -374,12 +384,20 @@ class DEBUG
374 384
         if (!is_array($Includes)) {
375 385
             $Includes = $this->get_includes();
376 386
         } ?>
387
+
377 388
 <table class="layout">
378 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 398
   </tr>
382 399
 </table>
400
+
383 401
 <table id="debug_include" class="debug_table hidden">
384 402
   <?php
385 403
     foreach ($Includes as $File) {
@@ -401,15 +419,22 @@ class DEBUG
401 419
         } ?>
402 420
 <table class="layout">
403 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 429
   </tr>
407 430
 </table>
431
+
408 432
 <table id="debug_classes" class="debug_table hidden">
409 433
   <tr>
410 434
     <td>
411 435
       <pre>
412
-<?php          print_r($Classes);
436
+<?php
437
+print_r($Classes);
413 438
         echo "\n"; ?>
414 439
         </pre>
415 440
     </td>
@@ -423,15 +448,21 @@ class DEBUG
423 448
         ?>
424 449
 <table class="layout">
425 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 458
   </tr>
429 459
 </table>
430 460
 <table id="debug_extensions" class="debug_table hidden">
431 461
   <tr>
432 462
     <td>
433 463
       <pre>
434
-<?php          print_r($this->get_extensions());
464
+<?php
465
+print_r($this->get_extensions());
435 466
         echo "\n"; ?>
436 467
         </pre>
437 468
     </td>
@@ -445,24 +476,33 @@ class DEBUG
445 476
         if (!is_array($Flags)) {
446 477
             $Flags = $this->get_flags();
447 478
         }
479
+
448 480
         if (empty($Flags)) {
449 481
             return;
450 482
         } ?>
483
+
451 484
 <table class="layout">
452 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 493
   </tr>
456 494
 </table>
495
+
457 496
 <table id="debug_flags" class="debug_table hidden">
458 497
   <tr class="valign_top">
459 498
     <td class="debug_flags_event"><strong>Event</strong></td>
460 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 501
     <td class="debug_flags_time"><strong>CPU time</strong></td>
463
-    <?php    } ?>
502
+    <?php } ?>
464 503
     <td class="debug_flags_memory"><strong>Memory</strong></td>
465 504
   </tr>
505
+
466 506
   <?php
467 507
     foreach ($Flags as $Flag) {
468 508
         list($Event, $MicroTime, $Memory, $CPUTime) = $Flag; ?>
@@ -470,9 +510,9 @@ class DEBUG
470 510
     <td><?=$Event?>
471 511
     </td>
472 512
     <td><?=number_format($MicroTime, 3)?> ms</td>
473
-    <?php      if ($CPUTime !== false) { ?>
513
+    <?php if ($CPUTime !== false) { ?>
474 514
     <td><?=number_format($CPUTime / 1000, 3)?> ms</td>
475
-    <?php      } ?>
515
+    <?php } ?>
476 516
     <td><?=Format::get_size($Memory)?>
477 517
     </td>
478 518
   </tr>
@@ -487,17 +527,24 @@ class DEBUG
487 527
         if (!is_array($Constants)) {
488 528
             $Constants = $this->get_constants();
489 529
         } ?>
530
+
490 531
 <table class="layout">
491 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 540
   </tr>
495 541
 </table>
542
+
496 543
 <table id="debug_constants" class="debug_table hidden">
497 544
   <tr>
498 545
     <td class="debug_data debug_constants_data">
499 546
       <pre>
500
-<?=         display_str(print_r($Constants, true))?>
547
+<?=display_str(print_r($Constants, true))?>
501 548
         </pre>
502 549
     </td>
503 550
   </tr>
@@ -510,23 +557,32 @@ class DEBUG
510 557
         if (!is_array($OcelotRequests)) {
511 558
             $OcelotRequests = $this->get_ocelot_requests();
512 559
         }
560
+
513 561
         if (empty($OcelotRequests)) {
514 562
             return;
515 563
         } ?>
564
+
516 565
 <table class="layout">
517 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 573
     </td>
520 574
   </tr>
521 575
 </table>
576
+
522 577
 <table id="debug_ocelot" class="debug_table hidden">
523
-  <?php    foreach ($OcelotRequests as $i => $Request) { ?>
578
+  <?php foreach ($OcelotRequests as $i => $Request) { ?>
524 579
   <tr>
525 580
     <td class="debug_data debug_ocelot_data">
526 581
       <a data-toggle-target="#debug_ocelot_<?=$i?>"><?=display_str($Request['path'])?></a>
527 582
       <pre id="debug_ocelot_<?=$i?>"
528 583
         class="hidden"><?=display_str($Request['response'])?></pre>
529 584
     </td>
585
+
530 586
     <td class="debug_info" style="width: 100px;">
531 587
       <?=display_str($Request['status'])?>
532 588
     </td>
@@ -534,7 +590,7 @@ class DEBUG
534 590
       <?=number_format($Request['time'], 5)?> ms
535 591
     </td>
536 592
   </tr>
537
-  <?php    } ?>
593
+  <?php } ?>
538 594
 </table>
539 595
 <?php
540 596
     }
@@ -546,18 +602,26 @@ class DEBUG
546 602
             $CacheKeys = $this->get_cache_keys();
547 603
             $Header .= ' ('.number_format($this->get_cache_time(), 5).' ms)';
548 604
         }
605
+
549 606
         if (empty($CacheKeys)) {
550 607
             return;
551 608
         }
552 609
         $Header = ' '.number_format(count($CacheKeys))." $Header:"; ?>
610
+
553 611
 <table class="layout">
554 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 620
   </tr>
558 621
 </table>
622
+
559 623
 <table id="debug_cache" class="debug_table hidden">
560
-  <?php    foreach ($CacheKeys as $Key) { ?>
624
+  <?php foreach ($CacheKeys as $Key) { ?>
561 625
   <tr>
562 626
     <td class="label nobr debug_info debug_cache_key">
563 627
       <a href="#"
@@ -567,11 +631,11 @@ class DEBUG
567 631
     </td>
568 632
     <td class="debug_data debug_cache_data">
569 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 635
         </pre>
572 636
     </td>
573 637
   </tr>
574
-  <?php    } ?>
638
+  <?php } ?>
575 639
 </table>
576 640
 <?php
577 641
     }
@@ -581,13 +645,21 @@ class DEBUG
581 645
         if (!is_array($Errors)) {
582 646
             $Errors = $this->get_errors();
583 647
         }
648
+
584 649
         if (empty($Errors)) {
585 650
             return;
586 651
         } ?>
652
+
587 653
 <table class="layout">
588 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 663
   </tr>
592 664
 </table>
593 665
 <table id="debug_error" class="debug_table hidden">
@@ -618,30 +690,41 @@ class DEBUG
618 690
             $Queries = $this->get_queries();
619 691
             $Header .= ' ('.number_format($this->get_query_time(), 5).' ms)';
620 692
         }
693
+
621 694
         if (empty($Queries)) {
622 695
             return;
623 696
         }
624 697
         $Header = ' '.number_format(count($Queries))." $Header:"; ?>
698
+
625 699
 <table class="layout">
626 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 708
   </tr>
630 709
 </table>
710
+
631 711
 <table id="debug_database" class="debug_table hidden">
632 712
   <?php
633 713
     foreach ($Queries as $Query) {
634 714
         $SQL = $Query[0] ?? null;
635 715
         $Time = $Query[1] ?? null;
636 716
         $Warnings = $Query[2] ?? null;
717
+
637 718
         if ($Warnings !== null) {
638 719
             $Warnings = implode('<br />', $Warnings);
639 720
         } ?>
721
+
640 722
   <tr class="valign_top">
641 723
     <td class="debug_data debug_query_data">
642 724
       <div><?=str_replace("\t", '&nbsp;&nbsp;', nl2br(display_str(trim($SQL))))?>
643 725
       </div>
644 726
     </td>
727
+
645 728
     <td class="debug_info debug_query_time" style="width: 130px;"><?=number_format($Time, 5)?> ms</td>
646 729
     <td class="debug_info debug_query_warnings"><?=$Warnings?>
647 730
     </td>
@@ -659,14 +742,21 @@ class DEBUG
659 742
             $Queries = $this->get_sphinxql_queries();
660 743
             $Header .= ' ('.number_format($this->get_sphinxql_time(), 5).' ms)';
661 744
         }
745
+
662 746
         if (empty($Queries)) {
663 747
             return;
664 748
         }
665 749
         $Header = ' '.number_format(count($Queries))." $Header:"; ?>
750
+
666 751
 <table class="layout">
667 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 760
   </tr>
671 761
 </table>
672 762
 <table id="debug_sphinx" class="debug_table hidden">
@@ -695,12 +785,19 @@ class DEBUG
695 785
             $Vars = $this->LoggedVars;
696 786
         }
697 787
         $Header = ' '.number_format(count($Vars))." $Header:"; ?>
788
+
698 789
 <table class="layout">
699 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 798
   </tr>
703 799
 </table>
800
+
704 801
 <table id="debug_loggedvars" class="debug_table hidden">
705 802
   <?php
706 803
     foreach ($Vars as $ID => $Var) {
@@ -710,13 +807,15 @@ class DEBUG
710 807
   <tr>
711 808
     <td class="debug_info debug_loggedvars_name">
712 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 814
       </div>
716 815
     </td>
717 816
     <td class="debug_data debug_loggedvars_data">
718 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 819
         </pre>
721 820
     </td>
722 821
   </tr>

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

@@ -15,52 +15,57 @@ class Forums
15 15
         if ((!$ThreadInfo = G::$Cache->get_value('thread_' . $ThreadID . '_info')) || !isset($ThreadInfo['Ranking'])) {
16 16
             $QueryID = G::$DB->get_query_id();
17 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 35
             if (!G::$DB->has_results()) {
35 36
                 G::$DB->set_query_id($QueryID);
36 37
                 return null;
37 38
             }
39
+
38 40
             $ThreadInfo = G::$DB->next_record(MYSQLI_ASSOC, false);
39 41
             if ($ThreadInfo['StickyPostID']) {
40 42
                 $ThreadInfo['Posts']--;
41 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 60
                 list($ThreadInfo['StickyPost']) = G::$DB->to_array(false, MYSQLI_ASSOC);
58 61
             }
62
+
59 63
             G::$DB->set_query_id($QueryID);
60 64
             if (!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
61 65
                 G::$Cache->cache_value('thread_' . $ThreadID . '_info', $ThreadInfo, 0);
62 66
             }
63 67
         }
68
+        
64 69
         if ($Return) {
65 70
             return $ThreadInfo;
66 71
         }
@@ -79,12 +84,15 @@ class Forums
79 84
         if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 1) {
80 85
             return true;
81 86
         }
87
+
82 88
         if ($ForumID == DONOR_FORUM && Donations::has_donor_forum(G::$LoggedUser['ID'])) {
83 89
             return true;
84 90
         }
91
+
85 92
         if ($Forums[$ForumID]['MinClass' . $Perm] > G::$LoggedUser['Class'] && (!isset(G::$LoggedUser['CustomForums'][$ForumID]) || G::$LoggedUser['CustomForums'][$ForumID] == 0)) {
86 93
             return false;
87 94
         }
95
+        
88 96
         if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 0) {
89 97
             return false;
90 98
         }
@@ -102,24 +110,25 @@ class Forums
102 110
         if (!$Forum) {
103 111
             $QueryID = G::$DB->get_query_id();
104 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 124
             if (!G::$DB->has_results()) {
116 125
                 return false;
117 126
             }
127
+
118 128
             // Makes an array, with $Forum['Name'], etc.
119 129
             $Forum = G::$DB->next_record(MYSQLI_ASSOC);
120 130
 
121 131
             G::$DB->set_query_id($QueryID);
122
-
123 132
             G::$Cache->cache_value("ForumInfo_$ForumID", $Forum, 86400);
124 133
         }
125 134
         return $Forum;
@@ -135,12 +144,14 @@ class Forums
135 144
         if ($ForumCats === false) {
136 145
             $QueryID = G::$DB->get_query_id();
137 146
             G::$DB->query("
138
-        SELECT ID, Name
139
-        FROM forums_categories");
147
+            SELECT ID, Name
148
+            FROM forums_categories");
149
+
140 150
             $ForumCats = [];
141 151
             while (list($ID, $Name) = G::$DB->next_record()) {
142 152
                 $ForumCats[$ID] = $Name;
143 153
             }
154
+
144 155
             G::$DB->set_query_id($QueryID);
145 156
             G::$Cache->cache_value('forums_categories', $ForumCats, 0);
146 157
         }
@@ -156,38 +167,40 @@ class Forums
156 167
         if (!$Forums = G::$Cache->get_value('forums_list')) {
157 168
             $QueryID = G::$DB->get_query_id();
158 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 193
             $Forums = G::$DB->to_array('ID', MYSQLI_ASSOC, false);
183 194
 
184 195
             G::$DB->query("
185
-        SELECT ForumID, ThreadID
186
-        FROM forums_specific_rules");
196
+            SELECT ForumID, ThreadID
197
+            FROM forums_specific_rules");
198
+
187 199
             $SpecificRules = [];
188 200
             while (list($ForumID, $ThreadID) = G::$DB->next_record(MYSQLI_NUM, false)) {
189 201
                 $SpecificRules[$ForumID][] = $ThreadID;
190 202
             }
203
+
191 204
             G::$DB->set_query_id($QueryID);
192 205
             foreach ($Forums as $ForumID => &$Forum) {
193 206
                 if (isset($SpecificRules[$ForumID])) {
@@ -239,30 +252,33 @@ class Forums
239 252
         } else {
240 253
             $PerPage = POSTS_PER_PAGE;
241 254
         }
255
+
242 256
         $TopicIDs = [];
243 257
         foreach ($Forums as $Forum) {
244 258
             if (!empty($Forum['LastPostTopicID'])) {
245 259
                 $TopicIDs[] = $Forum['LastPostTopicID'];
246 260
             }
247 261
         }
262
+
248 263
         if (!empty($TopicIDs)) {
249 264
             $QueryID = G::$DB->get_query_id();
250 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 282
             $LastRead = G::$DB->to_array('TopicID', MYSQLI_ASSOC);
267 283
             G::$DB->set_query_id($QueryID);
268 284
         } else {
@@ -283,12 +299,14 @@ class Forums
283 299
         if ($UserID === null) {
284 300
             $UserID = G::$LoggedUser['ID'];
285 301
         }
302
+
286 303
         $QueryID = G::$DB->get_query_id();
287 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 310
         G::$DB->set_query_id($QueryID);
293 311
         return (bool)G::$DB->affected_rows();
294 312
     }
@@ -318,17 +336,21 @@ class Forums
318 336
         // I couldn't come up with a good name, please rename this if you can. -- Y
319 337
         $RestrictedForums = self::get_restricted_forums();
320 338
         $PermittedForums = self::get_permitted_forums();
339
+
321 340
         if (Donations::has_donor_forum(G::$LoggedUser['ID']) && !in_array(DONOR_FORUM, $PermittedForums)) {
322 341
             $PermittedForums[] = DONOR_FORUM;
323 342
         }
343
+
324 344
         $SQL = "((f.MinClassRead <= '" . G::$LoggedUser['Class'] . "'";
325 345
         if (count($RestrictedForums)) {
326 346
             $SQL .= " AND f.ID NOT IN ('" . implode("', '", $RestrictedForums) . "')";
327 347
         }
348
+
328 349
         $SQL .= ')';
329 350
         if (count($PermittedForums)) {
330 351
             $SQL .= " OR f.ID IN ('" . implode("', '", $PermittedForums) . "')";
331 352
         }
353
+        
332 354
         $SQL .= ')';
333 355
         return $SQL;
334 356
     }

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

@@ -10,118 +10,126 @@
10 10
  *
11 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 107
 <div class="thin">
104 108
   <div class="header">
105
-    <h2><?=display_str($this->Heading)?></h2>
109
+    <h2><?=display_str($this->Heading)?>
110
+    </h2>
106 111
   </div>
107 112
 
108 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 118
     <tr>
111 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 126
       </td>
119 127
     </tr>
120 128
   </table>
121 129
 
122 130
   <form action="bookmarks.php" method="post" id="drag_drop_collage_form">
123 131
 
124
-<?      $this->buttons(); ?>
132
+    <?php $this->buttons(); ?>
125 133
 
126 134
     <table id="manage_collage_table" class="box">
127 135
       <thead>
@@ -136,131 +144,155 @@ class MASS_USER_TORRENTS_TABLE_VIEW {
136 144
         </tr>
137 145
       </thead>
138 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 158
       </tbody>
151 159
     </table>
152 160
 
153
-<?      $this->buttons(); ?>
161
+    <?php $this->buttons(); ?>
154 162
 
155 163
     <div>
156 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 169
     </div>
160 170
   </form>
161 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,7 +253,7 @@ class SectionParser
253 253
     }
254 254
 
255 255
     public static function strip_path($string)
256
-    { // remove filepath
256
+    { // Remove filepath
257 257
         $string = str_replace("\\", "/", $string);
258 258
         $path_parts = pathinfo($string);
259 259
         return $path_parts['basename'];
@@ -502,7 +502,7 @@ class GeneralSectionParser extends SectionParser
502 502
             case 'mpeg-ts':
503 503
                 $this->form_codec = 'MPEG-TS';
504 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 506
             case 'mpeg-ps':
507 507
                 $this->form_codec = '---';
508 508
                 break;
@@ -760,8 +760,7 @@ class VideoSectionParser extends SectionParser
760 760
         switch (strtolower($codec)) {
761 761
             case 'x264':
762 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 764
             case 'h265':
766 765
                 return 'h265';
767 766
             case 'xvid':

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

@@ -1,7 +1,7 @@
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 6
 // The following are used throughout the site:
7 7
 // uploaded, ratio, downloaded: stats
@@ -37,67 +37,79 @@
37 37
  * @param $Paranoia The paranoia level to check against.
38 38
  * @param $UserClass The user class to check against (Staff can see through paranoia of lower classed staff)
39 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 44
 define("PARANOIA_ALLOWED", 1);
46 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,7 +124,7 @@ function permissions_form()
124 124
       <tr>
125 125
         <td>
126 126
           <?php
127
-          display_perm('site_leech', 'Can leech.');
127
+    display_perm('site_leech', 'Can leech.');
128 128
     display_perm('site_upload', 'Can upload.');
129 129
     display_perm('site_vote', 'Can vote on requests.');
130 130
     display_perm('site_submit_requests', 'Can submit requests.');
@@ -168,6 +168,7 @@ function permissions_form()
168 168
       </tr>
169 169
     </table>
170 170
   </div>
171
+
171 172
   <div class="permission_container">
172 173
     <table>
173 174
       <tr class="colhead">
@@ -176,7 +177,7 @@ function permissions_form()
176 177
       <tr>
177 178
         <td>
178 179
           <?php
179
-          display_perm('users_edit_usernames', 'Can edit usernames.');
180
+    display_perm('users_edit_usernames', 'Can edit usernames.');
180 181
     display_perm('users_edit_ratio', 'Can edit anyone\'s upload/download amounts.');
181 182
     display_perm('users_edit_own_ratio', 'Can edit own upload/download amounts.');
182 183
     display_perm('users_edit_titles', 'Can edit titles.');
@@ -208,11 +209,12 @@ function permissions_form()
208 209
     display_perm('users_make_invisible', 'Can make users invisible');
209 210
     display_perm('users_logout', 'Can log users out');
210 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 213
         </td>
213 214
       </tr>
214 215
     </table>
215 216
   </div>
217
+
216 218
   <div class="permission_container">
217 219
     <table>
218 220
       <tr class="colhead">
@@ -221,7 +223,7 @@ function permissions_form()
221 223
       <tr>
222 224
         <td>
223 225
           <?php
224
-          display_perm('torrents_edit', 'Can edit any torrent');
226
+    display_perm('torrents_edit', 'Can edit any torrent');
225 227
     display_perm('torrents_delete', 'Can delete torrents');
226 228
     display_perm('torrents_delete_fast', 'Can delete more than 3 torrents at a time.');
227 229
     display_perm('torrents_freeleech', 'Can make torrents freeleech');
@@ -238,6 +240,7 @@ function permissions_form()
238 240
       </tr>
239 241
     </table>
240 242
   </div>
243
+
241 244
   <div class="permission_container">
242 245
     <table>
243 246
       <tr class="colhead">
@@ -246,7 +249,7 @@ function permissions_form()
246 249
       <tr>
247 250
         <td>
248 251
           <?php
249
-          display_perm('admin_manage_news', 'Can manage site news');
252
+    display_perm('admin_manage_news', 'Can manage site news');
250 253
     display_perm('admin_manage_blog', 'Can manage the site blog');
251 254
     display_perm('admin_manage_polls', 'Can manage polls');
252 255
     display_perm('admin_manage_forums', 'Can manage forums (add/edit/delete)');
@@ -268,6 +271,7 @@ function permissions_form()
268 271
       </tr>
269 272
     </table>
270 273
   </div>
274
+
271 275
   <div class="submit_container"><input type="submit" name="submit" value="Save Permission Class" /></div>
272 276
 </div>
273 277
 <?php

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

@@ -10,42 +10,43 @@ class Requests
10 10
     public static function update_sphinx_requests($RequestID)
11 11
     {
12 12
         $QueryID = G::$DB->get_query_id();
13
-
14 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 19
         $TagList = G::$DB->collect(0, false);
20 20
         $TagList = db_string(implode(' ', $TagList));
21 21
 
22 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 38
         G::$DB->query("
38
-      UPDATE sphinx_requests_delta
39
-      SET ArtistList = (
39
+        UPDATE sphinx_requests_delta
40
+        SET ArtistList = (
40 41
           SELECT GROUP_CONCAT(ag.Name SEPARATOR ' ')
41 42
           FROM requests_artists AS ra
42 43
             JOIN artists_group AS ag ON ag.ArtistID = ra.ArtistID
43 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 50
         G::$Cache->delete_value("request_$RequestID");
50 51
     }
51 52
 
@@ -68,12 +69,14 @@ class Requests
68 69
                 unset($RequestIDs[$i], $Found[$GroupID], $NotFound[$GroupID]);
69 70
                 continue;
70 71
             }
72
+
71 73
             $Data = G::$Cache->get_value("request_$RequestID");
72 74
             if (!empty($Data)) {
73 75
                 unset($NotFound[$RequestID]);
74 76
                 $Found[$RequestID] = $Data;
75 77
             }
76 78
         }
79
+
77 80
         // Make sure there's something in $RequestIDs, otherwise the SQL will break
78 81
         if (count($RequestIDs) === 0) {
79 82
             return [];
@@ -81,47 +84,50 @@ class Requests
81 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 90
         if (count($NotFound) > 0) {
88 91
             $QueryID = G::$DB->get_query_id();
89
-
90 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 114
             $Requests = G::$DB->to_array(false, MYSQLI_ASSOC, true);
112 115
             $Tags = self::get_tags(G::$DB->collect('ID', false));
116
+
113 117
             foreach ($Requests as $Request) {
114 118
                 $Request['AnonymousFill'] = false;
115 119
                 if ($Request['FillerID']) {
116 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 125
                     list($Anonymous) = G::$DB->next_record();
121 126
                     if ($Anonymous) {
122 127
                         $Request['AnonymousFill'] = true;
123 128
                     }
124 129
                 }
130
+
125 131
                 unset($NotFound[$Request['ID']]);
126 132
                 $Request['Tags'] = isset($Tags[$Request['ID']]) ? $Tags[$Request['ID']] : [];
127 133
                 $Found[$Request['ID']] = $Request;
@@ -166,15 +172,17 @@ class Requests
166 172
             $Results = [];
167 173
             $QueryID = G::$DB->get_query_id();
168 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 183
             $ArtistRaw = G::$DB->to_array();
177 184
             G::$DB->set_query_id($QueryID);
185
+
178 186
             foreach ($ArtistRaw as $ArtistRow) {
179 187
                 list($ArtistID, $ArtistName) = $ArtistRow;
180 188
                 $Results[] = array('id' => $ArtistID, 'name' => $ArtistName);
@@ -189,21 +197,25 @@ class Requests
189 197
         if (empty($RequestIDs)) {
190 198
             return [];
191 199
         }
200
+
192 201
         if (is_array($RequestIDs)) {
193 202
             $RequestIDs = implode(',', $RequestIDs);
194 203
         }
204
+
195 205
         $QueryID = G::$DB->get_query_id();
196 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 216
         $Tags = G::$DB->to_array(false, MYSQLI_NUM, false);
206 217
         G::$DB->set_query_id($QueryID);
218
+
207 219
         $Results = [];
208 220
         foreach ($Tags as $TagsRow) {
209 221
             list($RequestID, $TagID, $TagName) = $TagsRow;
@@ -218,18 +230,19 @@ class Requests
218 230
         if (!is_array($RequestVotes)) {
219 231
             $QueryID = G::$DB->get_query_id();
220 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 242
             if (!G::$DB->has_results()) {
230 243
                 return array(
231
-          'TotalBounty' => 0,
232
-          'Voters' => []);
244
+                    'TotalBounty' => 0,
245
+                    'Voters' => []);
233 246
             }
234 247
             $Votes = G::$DB->to_array();
235 248
 

+ 92
- 79
classes/script_start.php View File

@@ -10,12 +10,14 @@
10 10
 /* generates the page are at the bottom.        */
11 11
 /*------------------------------------------------------*/
12 12
 /********************************************************/
13
+
13 14
 require 'config.php'; // The config contains all site wide configuration information
14 15
 
15 16
 // Check for common setup pitfalls
16 17
 if (!ini_get('short_open_tag')) {
17 18
     die('short_open_tag must be On in php.ini');
18 19
 }
20
+
19 21
 if (!extension_loaded('apcu')) {
20 22
     die('APCu extension not loaded');
21 23
 }
@@ -32,6 +34,7 @@ require(SERVER_ROOT.'/classes/proxies.class.php');
32 34
 if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
33 35
     $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
34 36
 }
37
+
35 38
 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])
36 39
     && proxyCheck($_SERVER['REMOTE_ADDR'])
37 40
     && filter_var(
@@ -52,23 +55,20 @@ if (!isset($argv) && !empty($_SERVER['HTTP_HOST'])) {
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 59
 if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
59 60
     $RUsage = getrusage();
60 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 73
 $Debug = new DEBUG;
74 74
 $Debug->handle_errors();
@@ -86,7 +86,6 @@ require(SERVER_ROOT.'/classes/classloader.php');
86 86
 G::initialize();
87 87
 
88 88
 //Begin browser identification
89
-
90 89
 $Browser = UserAgent::browser($_SERVER['HTTP_USER_AGENT']);
91 90
 $OperatingSystem = UserAgent::operating_system($_SERVER['HTTP_USER_AGENT']);
92 91
 
@@ -118,17 +117,19 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
118 117
     $UserSessions = $Cache->get_value("users_sessions_$UserID");
119 118
     if (!is_array($UserSessions)) {
120 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 133
         $UserSessions = $DB->to_array('SessionID', MYSQLI_ASSOC);
133 134
         $Cache->cache_value("users_sessions_$UserID", $UserSessions, 0);
134 135
     }
@@ -141,12 +142,15 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
141 142
     $Enabled = $Cache->get_value('enabled_'.$LoggedUser['ID']);
142 143
     if ($Enabled === false) {
143 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 149
         list($Enabled) = $DB->next_record();
148 150
         $Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
149 151
     }
152
+
153
+    # todo: Check strict equality
150 154
     if ($Enabled == 2) {
151 155
         logout();
152 156
     }
@@ -155,9 +159,10 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
155 159
     $UserStats = $Cache->get_value('user_stats_'.$LoggedUser['ID']);
156 160
     if (!is_array($UserStats)) {
157 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 166
         $UserStats = $DB->next_record(MYSQLI_ASSOC);
162 167
         $Cache->cache_value('user_stats_'.$LoggedUser['ID'], $UserStats, 3600);
163 168
     }
@@ -168,15 +173,14 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
168 173
 
169 174
     // Create LoggedUser array
170 175
     $LoggedUser = array_merge($HeavyInfo, $LightInfo, $UserStats);
171
-
172 176
     $LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']);
173 177
 
174 178
     // $LoggedUser['RatioWatch'] as a bool to disable things for users on Ratio Watch
175 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 185
     // Load in the permissions
182 186
     $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
@@ -193,31 +197,37 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
193 197
     // Update LastUpdate every 10 minutes
194 198
     if (strtotime($UserSessions[$SessionID]['LastUpdate']) + 600 < time()) {
195 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 204
         $SessionQuery =
200
-     "UPDATE users_sessions
201
-      SET ";
205
+       "UPDATE users_sessions
206
+          SET ";
207
+
202 208
         // Only update IP if we have an encryption key in memory
203 209
         if (apcu_exists('DBKEY')) {
204 210
             $SessionQuery .= "IP = '".Crypto::encrypt($_SERVER['REMOTE_ADDR'])."', ";
205 211
         }
212
+
206 213
         $SessionQuery .=
207 214
        "Browser = '$Browser',
208 215
         OperatingSystem = '$OperatingSystem',
209 216
         LastUpdate = NOW()
210
-      WHERE UserID = '$LoggedUser[ID]'
217
+        WHERE UserID = '$LoggedUser[ID]'
211 218
         AND SessionID = '".db_string($SessionID)."'";
219
+
212 220
         $DB->query($SessionQuery);
213 221
         $Cache->begin_transaction("users_sessions_$UserID");
214 222
         $Cache->delete_row($SessionID);
223
+
215 224
         $UsersSessionCache = array(
216 225
         'SessionID' => $SessionID,
217 226
         'Browser' => $Browser,
218 227
         'OperatingSystem' => $OperatingSystem,
219 228
         'IP' => (apcu_exists('DBKEY') ? Crypto::encrypt($_SERVER['REMOTE_ADDR']) : $UserSessions[$SessionID]['IP']),
220 229
         'LastUpdate' => sqltime() );
230
+
221 231
         $Cache->insert_front($SessionID, $UsersSessionCache);
222 232
         $Cache->commit_transaction(0);
223 233
     }
@@ -227,9 +237,10 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
227 237
         $LoggedUser['Notify'] = $Cache->get_value('notify_filters_'.$LoggedUser['ID']);
228 238
         if (!is_array($LoggedUser['Notify'])) {
229 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 244
             $LoggedUser['Notify'] = $DB->to_array('ID');
234 245
             $Cache->cache_value('notify_filters_'.$LoggedUser['ID'], $LoggedUser['Notify'], 2592000);
235 246
         }
@@ -241,7 +252,6 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
241 252
     }
242 253
 
243 254
     // IP changed
244
-
245 255
     if (apcu_exists('DBKEY') && Crypto::decrypt($LoggedUser['IP']) != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
246 256
         if (Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
247 257
             error('Your IP address has been banned.');
@@ -250,10 +260,11 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
250 260
         $CurIP = db_string($LoggedUser['IP']);
251 261
         $NewIP = db_string($_SERVER['REMOTE_ADDR']);
252 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 268
         while (list($EncIP) = $DB->next_record()) {
258 269
             if (Crypto::decrypt($EncIP) == $CurIP) {
259 270
                 $CurIP = $EncIP;
@@ -261,54 +272,56 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
261 272
                 break;
262 273
             }
263 274
         }
275
+
264 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 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 289
         $ipcc = Tools::geoip($NewIP);
277 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 295
         $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
282 296
         $Cache->update_row(false, array('IP' => Crypto::encrypt($_SERVER['REMOTE_ADDR'])));
283 297
         $Cache->commit_transaction(0);
284 298
     }
285 299
 
286
-
287 300
     // Get stylesheets
288 301
     $Stylesheets = $Cache->get_value('stylesheets');
289 302
     if (!is_array($Stylesheets)) {
290 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 312
         $Stylesheets = $DB->to_array('ID', MYSQLI_BOTH);
299 313
         $Cache->cache_value('stylesheets', $Stylesheets, 0);
300 314
     }
301 315
 
302 316
     // todo: Clean up this messy solution
303 317
     $LoggedUser['StyleName'] = $Stylesheets[$LoggedUser['StyleID']]['Name'];
304
-
305 318
     if (empty($LoggedUser['Username'])) {
306 319
         logout(); // Ghost
307 320
     }
308 321
 }
322
+
309 323
 G::initialize();
310 324
 $Debug->set_flag('end user handling');
311
-
312 325
 $Debug->set_flag('start function definitions');
313 326
 
314 327
 /**
@@ -320,22 +333,23 @@ function logout()
320 333
     setcookie('session', '', time() - 60 * 60 * 24 * 365, '/', '', false);
321 334
     setcookie('userid', '', time() - 60 * 60 * 24 * 365, '/', '', false);
322 335
     setcookie('keeplogged', '', time() - 60 * 60 * 24 * 365, '/', '', false);
336
+
323 337
     if ($SessionID) {
324 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 343
         G::$Cache->begin_transaction('users_sessions_' . G::$LoggedUser['ID']);
330 344
         G::$Cache->delete_row($SessionID);
331 345
         G::$Cache->commit_transaction(0);
332 346
     }
347
+
333 348
     G::$Cache->delete_value('user_info_' . G::$LoggedUser['ID']);
334 349
     G::$Cache->delete_value('user_stats_' . G::$LoggedUser['ID']);
335 350
     G::$Cache->delete_value('user_info_heavy_' . G::$LoggedUser['ID']);
336 351
 
337 352
     header('Location: login.php');
338
-
339 353
     die();
340 354
 }
341 355
 
@@ -345,7 +359,7 @@ function logout_all_sessions()
345 359
 
346 360
     G::$DB->query("
347 361
     DELETE FROM users_sessions
348
-    WHERE UserID = '$UserID'");
362
+      WHERE UserID = '$UserID'");
349 363
 
350 364
     G::$Cache->delete_value('users_sessions_' . $UserID);
351 365
     logout();
@@ -396,7 +410,6 @@ $Cache->cache_value('php_' . getmypid(), array(
396 410
 define('STAFF_LOCKED', 1);
397 411
 
398 412
 $AllowedPages = ['staffpm', 'ajax', 'locked', 'logout', 'login'];
399
-
400 413
 if (isset(G::$LoggedUser['LockedAccount']) && !in_array($Document, $AllowedPages)) {
401 414
     require(SERVER_ROOT . '/sections/locked/index.php');
402 415
 } else {
@@ -415,10 +428,10 @@ if (!defined('SKIP_NO_CACHE_HEADERS')) {
415 428
     header('Pragma: no-cache');
416 429
 }
417 430
 
418
-//Flush to user
431
+// Flush to user
419 432
 ob_end_flush();
420 433
 
421 434
 $Debug->set_flag('set headers and send to user');
422 435
 
423
-//Attribute profiling
436
+// Attribute profiling
424 437
 $Debug->profile();

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

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

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

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

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

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

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

@@ -15,20 +15,20 @@ class Users
15 15
         if (!$Classes || !$ClassLevels) {
16 16
             $QueryID = G::$DB->get_query_id();
17 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 22
             $Classes = G::$DB->to_array('ID');
22 23
             $ClassLevels = G::$DB->to_array('Level');
23 24
             G::$DB->set_query_id($QueryID);
24 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 29
         return [$Classes, $ClassLevels];
29 30
     }
30 31
 
31
-
32 32
     /**
33 33
      * Get user info, is used for the current user and usernames all over the site.
34 34
      *
@@ -59,60 +59,62 @@ class Users
59 59
             $OldQueryID = G::$DB->get_query_id();
60 60
 
61 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 84
             if (!G::$DB->has_results()) { // Deleted user, maybe?
85 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 101
             } else {
102 102
                 $UserInfo = G::$DB->next_record(MYSQLI_ASSOC, ['Paranoia', 'Title']);
103 103
                 $UserInfo['CatchupTime'] = strtotime($UserInfo['CatchupTime']);
104
+
104 105
                 if (!is_array($UserInfo['Paranoia'])) {
105 106
                     $UserInfo['Paranoia'] = json_decode($UserInfo['Paranoia'], true);
106 107
                 }
108
+
107 109
                 if (!$UserInfo['Paranoia']) {
108 110
                     $UserInfo['Paranoia'] = [];
109 111
                 }
110 112
                 $UserInfo['Class'] = $Classes[$UserInfo['PermissionID']]['Level'];
111 113
 
112 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 119
                 $Badges = [];
118 120
                 if (G::$DB->has_results()) {
@@ -132,6 +134,7 @@ class Users
132 134
             } else {
133 135
                 $UserInfo['ExtraClasses'] = [];
134 136
             }
137
+
135 138
             unset($UserInfo['Levels']);
136 139
             $EffectiveClass = $UserInfo['Class'];
137 140
             foreach ($UserInfo['ExtraClasses'] as $Class => $Val) {
@@ -142,11 +145,11 @@ class Users
142 145
             G::$Cache->cache_value("user_info_$UserID", $UserInfo, 2592000);
143 146
             G::$DB->set_query_id($OldQueryID);
144 147
         }
148
+
145 149
         if (strtotime($UserInfo['Warned']) < time()) {
146 150
             $UserInfo['Warned'] = null;
147 151
             G::$Cache->cache_value("user_info_$UserID", $UserInfo, 2592000);
148 152
         }
149
-
150 153
         return $UserInfo;
151 154
     }
152 155
 
@@ -164,43 +167,44 @@ class Users
164 167
         if (empty($HeavyInfo)) {
165 168
             $QueryID = G::$DB->get_query_id();
166 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 206
             $HeavyInfo['CustomPermissions'] = [];
207
+
204 208
             if (!empty($HeavyInfo['CustomPermissions'])) {
205 209
                 $HeavyInfo['CustomPermissions'] = json_decode($HeavyInfo['CustomPermissions'], true);
206 210
             }
@@ -218,9 +222,10 @@ class Users
218 222
             unset($HeavyInfo['PermittedForums']);
219 223
 
220 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 229
             $PermIDs = G::$DB->collect('PermissionID');
225 230
             foreach ($PermIDs as $PermID) {
226 231
                 $Perms = Permissions::get_permissions($PermID);
@@ -228,6 +233,7 @@ class Users
228 233
                     $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',', $Perms['PermittedForums'])));
229 234
                 }
230 235
             }
236
+
231 237
             $Perms = Permissions::get_permissions($HeavyInfo['PermissionID']);
232 238
             unset($HeavyInfo['PermissionID']);
233 239
             if (!empty($Perms['PermittedForums'])) {
@@ -240,10 +246,12 @@ class Users
240 246
                 foreach ($RestrictedForums as $ForumID) {
241 247
                     $HeavyInfo['CustomForums'][$ForumID] = 0;
242 248
                 }
249
+
243 250
                 foreach ($PermittedForums as $ForumID) {
244 251
                     $HeavyInfo['CustomForums'][$ForumID] = 1;
245 252
                 }
246 253
             }
254
+
247 255
             if (isset($HeavyInfo['CustomForums'][''])) {
248 256
                 unset($HeavyInfo['CustomForums']['']);
249 257
             }
@@ -255,7 +263,6 @@ class Users
255 263
             unset($HeavyInfo['SiteOptions']);
256 264
 
257 265
             G::$DB->set_query_id($QueryID);
258
-
259 266
             G::$Cache->cache_value("user_info_heavy_$UserID", $HeavyInfo, 0);
260 267
         }
261 268
         return $HeavyInfo;
@@ -273,6 +280,7 @@ class Users
273 280
         if (!is_number($UserID)) {
274 281
             error(0);
275 282
         }
283
+
276 284
         if (empty($NewOptions)) {
277 285
             return false;
278 286
         }
@@ -281,9 +289,10 @@ class Users
281 289
 
282 290
         // Get SiteOptions
283 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 296
         list($SiteOptions) = G::$DB->next_record(MYSQLI_NUM, false);
288 297
         $SiteOptions = json_decode($SiteOptions, true);
289 298
 
@@ -296,9 +305,9 @@ class Users
296 305
 
297 306
         // Update DB
298 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 311
         G::$DB->set_query_id($QueryID);
303 312
 
304 313
         // Update cache
@@ -370,12 +379,12 @@ class Users
370 379
     {
371 380
         global $Classes;
372 381
 
373
-        if ($UserID == 0) {
382
+        if ($UserID === 0) {
374 383
             return 'System';
375 384
         }
376 385
 
377 386
         $UserInfo = self::user_info($UserID);
378
-        if ($UserInfo['Username'] == '') {
387
+        if ($UserInfo['Username'] === '') {
379 388
             return "Unknown [$UserID]";
380 389
         }
381 390
 
@@ -404,9 +413,10 @@ class Users
404 413
         }
405 414
         if ($Badges) {
406 415
             $DonorRank = Donations::get_rank($UserID);
407
-            if ($DonorRank == 0 && $UserInfo['Donor'] == 1) {
416
+            if ($DonorRank == 0 && $UserInfo['Donor'] === 1) {
408 417
                 $DonorRank = 1;
409 418
             }
419
+
410 420
             if ($ShowDonorIcon && $DonorRank > 0) {
411 421
                 $IconLink = 'donate.php';
412 422
                 $IconImage = 'donor.png';
@@ -415,12 +425,15 @@ class Users
415 425
                 $SpecialRank = Donations::get_special_rank($UserID);
416 426
                 $EnabledRewards = Donations::get_enabled_rewards($UserID);
417 427
                 $DonorRewards = Donations::get_rewards($UserID);
428
+
418 429
                 if ($EnabledRewards['HasDonorIconMouseOverText'] && !empty($DonorRewards['IconMouseOverText'])) {
419 430
                     $IconText = display_str($DonorRewards['IconMouseOverText']);
420 431
                 }
432
+
421 433
                 if ($EnabledRewards['HasDonorIconLink'] && !empty($DonorRewards['CustomIconLink'])) {
422 434
                     $IconLink = display_str($DonorRewards['CustomIconLink']);
423 435
                 }
436
+
424 437
                 if ($EnabledRewards['HasCustomDonorIcon'] && !empty($DonorRewards['CustomIcon'])) {
425 438
                     $IconImage = ImageTools::process($DonorRewards['CustomIcon']);
426 439
                 } else {
@@ -431,6 +444,7 @@ class Users
431 444
                     } elseif ($DonorRank >= MAX_RANK) {
432 445
                         $DonorHeart = 5;
433 446
                     }
447
+
434 448
                     if ($DonorHeart === 1) {
435 449
                         $IconImage = STATIC_SERVER . 'common/symbols/donor.png';
436 450
                     } else {
@@ -442,16 +456,20 @@ class Users
442 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 468
         if ($Class) {
452 469
             foreach (array_keys($UserInfo['ExtraClasses']) as $ExtraClass) {
453 470
                 $Str .= ' ['.Users::make_class_abbrev_string($ExtraClass).']';
454 471
             }
472
+
455 473
             if ($Title) {
456 474
                 $Str .= ' <strong>('.Users::make_class_string($UserInfo['PermissionID']).')</strong>';
457 475
             } else {
@@ -463,12 +481,12 @@ class Users
463 481
             // Image proxy CTs
464 482
             if (check_perms('site_proxy_images') && !empty($UserInfo['Title'])) {
465 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 492
             if ($UserInfo['Title']) {
@@ -510,10 +528,11 @@ class Users
510 528
         } else {
511 529
             $QueryID = G::$DB->get_query_id();
512 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 536
             $GroupIDs = G::$DB->collect('GroupID');
518 537
             $BookmarkData = G::$DB->to_array('GroupID', MYSQLI_ASSOC);
519 538
             G::$DB->set_query_id($QueryID);
@@ -521,7 +540,6 @@ class Users
521 540
         }
522 541
 
523 542
         $TorrentList = Torrents::get_groups($GroupIDs);
524
-
525 543
         return [$GroupIDs, $BookmarkData, $TorrentList];
526 544
     }
527 545
 
@@ -548,29 +566,34 @@ class Users
548 566
             $Rewards = Donations::get_rewards($UserID);
549 567
             $AvatarMouseOverText = $Rewards['AvatarMouseOverText'];
550 568
         }
569
+
551 570
         if (!empty($AvatarMouseOverText)) {
552 571
             $AvatarMouseOverText =  "title=\"$AvatarMouseOverText\" alt=\"$AvatarMouseOverText\"";
553 572
         } else {
554 573
             $AvatarMouseOverText = "alt=\"$Username's avatar\"";
555 574
         }
575
+
556 576
         if ($EnabledRewards['HasSecondAvatar'] && !empty($Rewards['SecondAvatar'])) {
557 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 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 597
           case 0:
575 598
             $Type = 'identicon';
576 599
             break;
@@ -598,29 +621,32 @@ class Users
598 621
           default:
599 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 643
         return $ToReturn;
618 644
     }
619 645
 
620 646
     public static function has_avatars_enabled()
621 647
     {
622 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,23 +665,26 @@ class Users
639 665
             $Enabled = true;
640 666
         } elseif (G::$LoggedUser['AutoComplete'] !== 1) {
641 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 682
         if ($Enabled && $Output) {
655 683
             echo ' data-gazelle-autocomplete="true"';
656 684
         }
685
+
657 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 688
             return $Enabled;
660 689
         }
661 690
     }
@@ -671,12 +700,13 @@ class Users
671 700
     {
672 701
         $ResetKey = Users::make_secret();
673 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 710
         $TPL = new TEMPLATE;
681 711
         $TPL->open(SERVER_ROOT . '/templates/password_reset.tpl'); // Password reset template
682 712
         $TPL->set('Username', $Username);
@@ -688,7 +718,6 @@ class Users
688 718
         Misc::send_email($Email, 'Password reset information for ' . SITE_NAME, $TPL->get(), 'noreply');
689 719
     }
690 720
 
691
-
692 721
     /*
693 722
      * Authorize a new location
694 723
      *
@@ -701,7 +730,8 @@ class Users
701 730
     {
702 731
         $AuthKey = Users::make_secret();
703 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 735
         $TPL = new TEMPLATE;
706 736
         $TPL->open(SERVER_ROOT . '/templates/new_location.tpl');
707 737
         $TPL->set('Username', $Username);
@@ -720,16 +750,19 @@ class Users
720 750
         if (!($SourceKey = G::$Cache->get_value('source_key_new'))) {
721 751
             G::$Cache->cache_value('source_key_new', $SourceKey = [Users::make_secret(), time()]);
722 752
         }
753
+
723 754
         $SourceKeyOld = G::$Cache->get_value('source_key_old');
724 755
         if ($SourceKey[1]-time() > 3600) {
725 756
             G::$Cache->cache_value('source_key_old', $SourceKeyOld = $SourceKey);
726 757
             G::$Cache->cache_value('source_key_new', $SourceKey = [Users::make_secret(), time()]);
727 758
         }
759
+
728 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 766
         list($Uploads) = G::$DB->next_record();
734 767
         $Source[0] = SITE_NAME.'-'.substr(hash('sha256', $SourceKey[0].G::$LoggedUser['ID'].$Uploads), 0, 10);
735 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,21 +18,27 @@ class Validate
18 18
         if (!empty($Options['maxlength'])) {
19 19
             $this->Fields[$FieldName]['MaxLength'] = $Options['maxlength'];
20 20
         }
21
+
21 22
         if (!empty($Options['minlength'])) {
22 23
             $this->Fields[$FieldName]['MinLength'] = $Options['minlength'];
23 24
         }
25
+
24 26
         if (!empty($Options['comparefield'])) {
25 27
             $this->Fields[$FieldName]['CompareField'] = $Options['comparefield'];
26 28
         }
29
+
27 30
         if (!empty($Options['allowperiod'])) {
28 31
             $this->Fields[$FieldName]['AllowPeriod'] = $Options['allowperiod'];
29 32
         }
33
+
30 34
         if (!empty($Options['allowcomma'])) {
31 35
             $this->Fields[$FieldName]['AllowComma'] = $Options['allowcomma'];
32 36
         }
37
+
33 38
         if (!empty($Options['inarray'])) {
34 39
             $this->Fields[$FieldName]['InArray'] = $Options['inarray'];
35 40
         }
41
+
36 42
         if (!empty($Options['regex'])) {
37 43
             $this->Fields[$FieldName]['Regex'] = $Options['regex'];
38 44
         }
@@ -52,6 +58,7 @@ class Validate
52 58
                     } else {
53 59
                         $MaxLength = 255;
54 60
                     }
61
+
55 62
                     if (isset($Field['MinLength'])) {
56 63
                         $MinLength = $Field['MinLength'];
57 64
                     } else {
@@ -69,6 +76,7 @@ class Validate
69 76
                     } else {
70 77
                         $MaxLength = '';
71 78
                     }
79
+
72 80
                     if (isset($Field['MinLength'])) {
73 81
                         $MinLength = $Field['MinLength'];
74 82
                     } else {
@@ -79,6 +87,7 @@ class Validate
79 87
                     if (isset($Field['AllowPeriod'])) {
80 88
                         $Match .= '.';
81 89
                     }
90
+
82 91
                     if (isset($Field['AllowComma'])) {
83 92
                         $Match .= ',';
84 93
                     }
@@ -115,6 +124,7 @@ class Validate
115 124
                     } else {
116 125
                         $MaxLength = 255;
117 126
                     }
127
+
118 128
                     if (isset($Field['MinLength'])) {
119 129
                         $MinLength = $Field['MinLength'];
120 130
                     } else {
@@ -134,6 +144,7 @@ class Validate
134 144
                     } else {
135 145
                         $MaxLength = 20;
136 146
                     }
147
+                    
137 148
                     if (isset($Field['MinLength'])) {
138 149
                         $MinLength = $Field['MinLength'];
139 150
                     } else {

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

@@ -278,12 +278,17 @@ if (count($Forum) === 0) {
278 278
         }
279 279
     } ?>
280 280
   </table>
281
+
281 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 286
   </div>
287
+
284 288
   <div class="linkbox pager">
285 289
     <?=$Pages?>
286 290
   </div>
291
+
287 292
   <div class="linkbox"><a
288 293
       href="forums.php?action=catchup&amp;forumid=<?=$ForumID?>&amp;auth=<?=$LoggedUser['AuthKey']?>"
289 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