Browse Source

Fix 500 errors on torrent group editing and missing CSS assets

biotorrents 4 years ago
parent
commit
f16b4bbfe2

+ 2
- 1
classes/mysql.class.php View File

@@ -118,7 +118,8 @@ if (!extension_loaded('mysqli')) {
118 118
 
119 119
 /**
120 120
  * db_string
121
- * Handles escaping
121
+ *
122
+ * Handles escaping.
122 123
  */
123 124
 function db_string($String, $DisableWildcards = false)
124 125
 {

+ 1
- 1
classes/security.class.php View File

@@ -17,7 +17,7 @@ class Security
17 17
      * Makes sure a number ID is valid,
18 18
      * e.g., a page ID requested by GET.
19 19
      */
20
-    public function checkInt(mixed $ID)
20
+    public function checkInt($ID)
21 21
     #public function checkInt(int|array $ID) # Union types need PHP 8 - unbelievable!
22 22
     {
23 23
         # Cast single ID to array

+ 29
- 28
classes/torrents.class.php View File

@@ -545,7 +545,7 @@ class Torrents
545 545
      *
546 546
      * @param int $GroupID
547 547
      */
548
-    public static function update_hash($GroupID)
548
+    public static function update_hash(int $GroupID)
549 549
     {
550 550
         $QueryID = G::$DB->get_query_id();
551 551
 
@@ -575,18 +575,19 @@ class Torrents
575 575
 
576 576
         // Fetch album artists
577 577
         G::$DB->query("
578
-        SELECT GROUP_CONCAT(ag.Name separator ' ')
579
-        FROM torrents_artists AS ta
580
-          JOIN artists_group AS ag ON ag.ArtistID = ta.ArtistID
581
-          WHERE ta.GroupID = ?
582
-        GROUP BY ta.GroupID", $GroupID);
578
+        SELECT GROUP_CONCAT(ag.`Name` separator ' ')
579
+        FROM `torrents_artists` AS `ta`
580
+          JOIN `artists_group` AS ag ON ag.`ArtistID` = ta.`ArtistID`
581
+          WHERE ta.`GroupID` = '$GroupID'
582
+        GROUP BY ta.`GroupID`
583
+        ");
583 584
         if (G::$DB->has_results()) {
584 585
             list($ArtistName) = G::$DB->next_record(MYSQLI_NUM, false);
585 586
         } else {
586 587
             $ArtistName = '';
587 588
         }
588 589
 
589
-        G::$DB->query("
590
+        G::$DB->prepare_query("
590 591
         REPLACE
591 592
         INTO sphinx_delta(
592 593
           `ID`,
@@ -619,28 +620,28 @@ class Torrents
619 620
         SELECT
620 621
           t.`ID`,
621 622
           g.`id`,
622
-          `Name`,
623
-          `Title2`,
624
-          `NameJP`,
625
-          `TagList`,
626
-          `Year`,
627
-          `CatalogueNumber`,
628
-          `CategoryID`,
623
+          g.`title`,
624
+          g.`subject`,
625
+          g.`object`,
626
+          g.`tag_list`,
627
+          g.`published`,
628
+          g.`identifier`,
629
+          g.`category_id`,
629 630
           UNIX_TIMESTAMP(t.`Time`),
630
-          `Size`,
631
-          `Snatched`,
632
-          `Seeders`,
633
-          `Leechers`,
634
-          `Censored`,
635
-          `Studio`,
636
-          `Series`,
631
+          t.`Size`,
632
+          t.`Snatched`,
633
+          t.`Seeders`,
634
+          t.`Leechers`,
635
+          t.`Censored`,
636
+          g.`workgroup`,
637
+          g.`location`,
637 638
           CAST(`FreeTorrent` AS CHAR),
638
-          `Media`,
639
-          `Container`,
640
-          `Codec`,
641
-          `Resolution`,
642
-          `Version`,
643
-          `Description`,
639
+          t.`Media`,
640
+          t.`Container`,
641
+          t.`Codec`,
642
+          t.`Resolution`,
643
+          t.`Version`,
644
+          t.`Description`,
644 645
         REPLACE
645 646
           (
646 647
         REPLACE
@@ -657,13 +658,13 @@ class Torrents
657 658
         WHERE
658 659
           g.`id` = '$GroupID'
659 660
         ");
661
+        G::$DB->exec_prepared_query();
660 662
 
661 663
         G::$Cache->delete_value("torrents_details_$GroupID");
662 664
         G::$Cache->delete_value("torrent_group_$GroupID");
663 665
         G::$Cache->delete_value("torrent_group_light_$GroupID");
664 666
 
665 667
         $ArtistInfo = Artists::get_artist($GroupID);
666
-
667 668
         G::$Cache->delete_value("groups_artists_$GroupID");
668 669
         G::$DB->set_query_id($QueryID);
669 670
     }

+ 59
- 18
feeds.php View File

@@ -1,42 +1,58 @@
1 1
 <?php
2 2
 declare(strict_types = 1);
3 3
 
4
-/*-- Feed Start Class ----------------------------------*/
5
-/*------------------------------------------------------*/
6
-/* Simplified version of script_start, used for the     */
7
-/* sitewide RSS system.                                 */
8
-/*------------------------------------------------------*/
9
-/********************************************************/
10
-
11
-// Let's prevent people from clearing feeds
4
+/**
5
+ * Feed start class
6
+ *
7
+ * Simplified version of script_start,
8
+ * used for the sitewide RSS system.
9
+ */
10
+
11
+# Let's prevent people from clearing feeds
12 12
 if (isset($_GET['clearcache'])) {
13 13
     unset($_GET['clearcache']);
14 14
 }
15 15
 
16 16
 require_once 'classes/config.php';
17
-require_once SERVER_ROOT.'/classes/misc.class.php';
18
-require_once SERVER_ROOT.'/classes/cache.class.php';
19
-require_once SERVER_ROOT.'/classes/feed.class.php';
20
-
21 17
 $ENV = ENV::go();
22
-$Cache = new Cache($ENV->getPriv('MEMCACHED_SERVERS')); // Load the caching class
23
-$Feed = new Feed; // Load the time class
24 18
 
19
+require_once "$ENV->SERVER_ROOT/classes/misc.class.php";
20
+require_once "$ENV->SERVER_ROOT/classes/cache.class.php";
21
+require_once "$ENV->SERVER_ROOT/classes/feed.class.php";
22
+
23
+# Load the caching class
24
+$Cache = new Cache($ENV->getPriv('MEMCACHED_SERVERS'));
25
+
26
+# Load the time class
27
+$Feed = new Feed;
28
+
29
+
30
+/**
31
+ * check_perms
32
+ */
25 33
 function check_perms()
26 34
 {
27 35
     return false;
28 36
 }
29 37
 
38
+
39
+/**
40
+ * is_number
41
+ */
30 42
 function is_number($Str)
31 43
 {
32 44
     if ($Str < 0) {
33 45
         return false;
34 46
     }
35 47
 
36
-    // We're converting input to an int, then string, and comparing to the original
48
+    # We're converting input to an int, then string, and comparing to the original
37 49
     return ($Str === strval(intval($Str)));
38 50
 }
39 51
 
52
+
53
+/**
54
+ * display_str
55
+ */
40 56
 function display_str($Str)
41 57
 {
42 58
     if ($Str !== '') {
@@ -62,21 +78,29 @@ function display_str($Str)
62 78
 
63 79
         $Str = str_replace($Replace, $With, $Str);
64 80
     }
81
+
65 82
     return $Str;
66 83
 }
67 84
 
85
+
86
+/**
87
+ * make_utf8
88
+ */
68 89
 function make_utf8($Str)
69 90
 {
70 91
     if ($Str !== '') {
71 92
         if (is_utf8($Str)) {
72 93
             $Encoding = 'UTF-8';
73 94
         }
95
+
74 96
         if (empty($Encoding)) {
75 97
             $Encoding = mb_detect_encoding($Str, 'UTF-8, ISO-8859-1');
76 98
         }
99
+
77 100
         if (empty($Encoding)) {
78 101
             $Encoding = 'ISO-8859-1';
79 102
         }
103
+
80 104
         if ($Encoding === 'UTF-8') {
81 105
             return $Str;
82 106
         } else {
@@ -85,6 +109,10 @@ function make_utf8($Str)
85 109
     }
86 110
 }
87 111
 
112
+
113
+/**
114
+ * is_utf8
115
+ */
88 116
 function is_utf8($Str)
89 117
 {
90 118
     return preg_match(
@@ -102,6 +130,10 @@ function is_utf8($Str)
102 130
     );
103 131
 }
104 132
 
133
+
134
+/**
135
+ * display_array
136
+ */
105 137
 function display_array($Array, $Escape = [])
106 138
 {
107 139
     foreach ($Array as $Key => $Val) {
@@ -109,20 +141,29 @@ function display_array($Array, $Escape = [])
109 141
             $Array[$Key] = display_str($Val);
110 142
         }
111 143
     }
144
+
112 145
     return $Array;
113 146
 }
114 147
 
148
+
115 149
 /**
116
- * Print the site's URL including the appropriate URI scheme, including the trailing slash
150
+ * site_url
151
+ *
152
+ * Print the site's URL and appropriate URI scheme,
153
+ * including the trailing slash.
117 154
  */
118 155
 function site_url()
119 156
 {
120
-    return 'https://' . SITE_DOMAIN . '/';
157
+    $ENV = ENV::go();
158
+    return "https://$ENV->SITE_DOMAIN/";
121 159
 }
122 160
 
161
+
162
+# Set the headers
123 163
 header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
124 164
 header('Pragma:');
125 165
 header('Expires: '.date('D, d M Y H:i:s', time() + (2 * 60 * 60)).' GMT');
126 166
 header('Last-Modified: '.date('D, d M Y H:i:s').' GMT');
127 167
 
128
-require_once SERVER_ROOT.'/sections/feeds/index.php';
168
+# Load the feeds section
169
+require_once "$ENV->SERVER_ROOT/sections/feeds/index.php";

+ 86
- 47
image.php View File

@@ -1,7 +1,7 @@
1 1
 <?php
2 2
 declare(strict_types=1);
3 3
 
4
-// Functions and headers needed by the image proxy
4
+# Functions and headers needed by the image proxy
5 5
 error_reporting(E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR);
6 6
 
7 7
 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
@@ -9,107 +9,146 @@ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
9 9
     error();
10 10
 }
11 11
 
12
-header('Expires: '.date('D, d-M-Y H:i:s \U\T\C', time() + 3600 * 24 * 120)); // 120 days
12
+header('Expires: '.date('D, d-M-Y H:i:s \U\T\C', time() + 3600 * 24 * 120)); # 120 days
13 13
 header('Last-Modified: '.date('D, d-M-Y H:i:s \U\T\C', time()));
14 14
 
15 15
 if (!extension_loaded('gd')) {
16
-    error('nogd');
16
+    error('Please install and enable the GD Graphics Library.');
17 17
 }
18 18
 
19
+
20
+/**
21
+ * img_error
22
+ */
19 23
 function img_error($Type)
20 24
 {
25
+    $ENV = ENV::go();
26
+
21 27
     header('Content-type: image/gif');
22
-    error(file_get_contents(SERVER_ROOT.'/sections/image/err_imgs/'.$Type.'.png'));
28
+    error(file_get_contents("$ENV->SERVER_ROOT/sections/image/err_imgs/$Type.png"));
23 29
 }
24 30
 
31
+
32
+/**
33
+ * invisible
34
+ */
25 35
 function invisible($Image)
26 36
 {
27 37
     $Count = imagecolorstotal($Image);
28 38
     if ($Count === 0) {
29 39
         return false;
30 40
     }
41
+
31 42
     $TotalAlpha = 0;
32 43
     for ($i = 0; $i < $Count; ++$i) {
33 44
         $Color = imagecolorsforindex($Image, $i);
34 45
         $TotalAlpha += $Color['alpha'];
35 46
     }
47
+
36 48
     return (($TotalAlpha / $Count) === 127);
37 49
 }
38 50
 
51
+
52
+/**
53
+ * verysmall
54
+ */
39 55
 function verysmall($Image)
40 56
 {
41 57
     return ((imagesx($Image) * imagesy($Image)) < 25);
42 58
 }
43 59
 
60
+
61
+/**
62
+ * image_type
63
+ */
44 64
 function image_type($Data)
45 65
 {
46 66
     if (!strncmp($Data, 'GIF', 3)) {
47 67
         return 'gif';
48 68
     }
69
+
49 70
     if (!strncmp($Data, pack('H*', '89504E47'), 4)) {
50 71
         return 'png';
51 72
     }
73
+
52 74
     if (!strncmp($Data, pack('H*', 'FFD8'), 2)) {
53 75
         return 'jpeg';
54 76
     }
77
+
55 78
     if (!strncmp($Data, 'BM', 2)) {
56 79
         return 'bmp';
57 80
     }
81
+
58 82
     if (!strncmp($Data, 'II', 2) || !strncmp($Data, 'MM', 2)) {
59 83
         return 'tiff';
60 84
     }
85
+
61 86
     if (!substr_compare($Data, 'webm', 31, 4)) {
62 87
         return 'webm';
63 88
     }
64 89
 }
65 90
 
91
+
92
+/**
93
+ * image_height
94
+ */
66 95
 function image_height($Type, $Data)
67 96
 {
68
-    $Length = strlen($Data);
69 97
     global $URL, $_GET;
98
+    $Length = strlen($Data);
70 99
 
71 100
     switch ($Type) {
72
-    case 'jpeg':
73
-      // See http://www.obrador.com/essentialjpeg/headerinfo.htm
74
-      $i = 4;
75
-      $Data = (substr($Data, $i));
76
-      $Block = unpack('nLength', $Data);
77
-      $Data = substr($Data, $Block['Length']);
78
-      $i += $Block['Length'];
79
-      $Str []= 'Started 4, + '.$Block['Length'];
80
-
81
-      while ($Data !== '') { // Iterate through the blocks until we find the start of frame marker (FFC0)
82
-        $Block = unpack('CBlock/CType/nLength', $Data); // Get info about the block
83
-        if ($Block['Block'] !== '255') { // We should be at the start of a new block
84
-          break;
85
-        }
86
-
87
-          if ($Block['Type'] !== '192') { // C0
88
-          $Data = substr($Data, $Block['Length'] + 2); // Next block
89
-          $Str []= 'Started $i, + '.($Block['Length'] + 2);
90
-              $i += ($Block['Length'] + 2);
91
-          } else { // We're at the FFC0 block
92
-          $Data = substr($Data, 5); // Skip FF C0 Length(2) precision(1)
93
-          $i += 5;
94
-              $Height = unpack('nHeight', $Data);
95
-              return $Height['Height'];
96
-          }
97
-      }
98
-      break;
99
-
100
-    case 'gif':
101
-      $Data = substr($Data, 8);
102
-      $Height = unpack('vHeight', $Data);
103
-      return $Height['Height'];
104
-
105
-    case 'png':
106
-      $Data = substr($Data, 20);
107
-      $Height = unpack('NHeight', $Data);
108
-      return $Height['Height'];
109
-      
110
-    default:
111
-      return 0;
112
-  }
101
+        case 'jpeg':
102
+            # https://www.geocities.ws/crestwoodsdd/JPEG.htm
103
+            $i = 4;
104
+            $Data = (substr($Data, $i));
105
+            $Block = unpack('nLength', $Data);
106
+            $Data = substr($Data, $Block['Length']);
107
+            $i += $Block['Length'];
108
+            $Str []= 'Started 4, + '.$Block['Length'];
109
+
110
+            # Iterate through the blocks until we find the start of frame marker (FFC0)
111
+            while ($Data !== '') {
112
+                # Get info about the block
113
+                $Block = unpack('CBlock/CType/nLength', $Data);
114
+
115
+                # We should be at the start of a new block
116
+                if ($Block['Block'] !== '255') {
117
+                    break;
118
+                }
119
+
120
+                if ($Block['Type'] !== '192') { # C0
121
+                    $Data = substr($Data, $Block['Length'] + 2); # Next block
122
+                    $Str []= 'Started $i, + '.($Block['Length'] + 2);
123
+                    $i += ($Block['Length'] + 2);
124
+                }
125
+                
126
+                # We're at the FFC0 block
127
+                else {
128
+                    # Skip FF C0 Length(2) precision(1)
129
+                    $Data = substr($Data, 5);
130
+                    $i += 5;
131
+                    $Height = unpack('nHeight', $Data);
132
+                    return $Height['Height'];
133
+                }
134
+            }
135
+            break;
136
+            
137
+        case 'gif':
138
+            $Data = substr($Data, 8);
139
+            $Height = unpack('vHeight', $Data);
140
+            return $Height['Height'];
141
+        
142
+        case 'png':
143
+            $Data = substr($Data, 20);
144
+            $Height = unpack('NHeight', $Data);
145
+            return $Height['Height'];
146
+            
147
+        default:
148
+            return 0;
149
+    }
113 150
 }
114 151
 
115
-require_once 'classes/script_start.php'; // script_start.php contains all we need and includes sections/image/index.php
152
+
153
+# script_start.php contains all we need and includes sections/image/index.php
154
+require_once 'classes/script_start.php';

+ 2
- 6
sections/collages/collage.php View File

@@ -1,13 +1,9 @@
1 1
 <?php
2 2
 #declare(strict_types=1);
3 3
 
4
-ini_set('max_execution_time', 600);
4
+$CollageID = (int) $_GET['id'];
5
+Security::checkInt($CollageID);
5 6
 
6
-if (empty($_GET['id']) || !is_number($_GET['id'])) {
7
-    error(0);
8
-}
9
-
10
-$CollageID = $_GET['id'];
11 7
 $CollageData = $Cache->get_value("collage_$CollageID");
12 8
 
13 9
 if ($CollageData) {

+ 18
- 18
sections/collages/index.php View File

@@ -1,71 +1,73 @@
1
-<?
1
+<?php
2
+declare(strict_types=1);
3
+
2 4
 define('ARTIST_COLLAGE', 'Artists');
3 5
 enforce_login();
4 6
 
5 7
 if (empty($_REQUEST['action'])) {
6
-  $_REQUEST['action'] = '';
8
+    $_REQUEST['action'] = '';
7 9
 }
8 10
 
9 11
 switch ($_REQUEST['action']) {
10 12
   case 'new':
11 13
     if (!check_perms('site_collages_create')) {
12
-      error(403);
14
+        error(403);
13 15
     }
14 16
     require(SERVER_ROOT.'/sections/collages/new.php');
15 17
     break;
16 18
   case 'new_handle':
17 19
     if (!check_perms('site_collages_create')) {
18
-      error(403);
20
+        error(403);
19 21
     }
20 22
     require(SERVER_ROOT.'/sections/collages/new_handle.php');
21 23
     break;
22 24
   case 'add_torrent':
23 25
   case 'add_torrent_batch':
24 26
     if (!check_perms('site_collages_manage')) {
25
-      error(403);
27
+        error(403);
26 28
     }
27 29
     require(SERVER_ROOT.'/sections/collages/add_torrent.php');
28 30
     break;
29 31
   case 'add_artist':
30 32
   case 'add_artist_batch':
31 33
     if (!check_perms('site_collages_manage')) {
32
-      error(403);
34
+        error(403);
33 35
     }
34 36
     require(SERVER_ROOT.'/sections/collages/add_artist.php');
35 37
     break;
36 38
   case 'manage':
37 39
     if (!check_perms('site_collages_manage')) {
38
-      error(403);
40
+        error(403);
39 41
     }
40 42
     require(SERVER_ROOT.'/sections/collages/manage.php');
41 43
     break;
42 44
   case 'manage_handle':
43 45
     if (!check_perms('site_collages_manage')) {
44
-      error(403);
46
+        error(403);
45 47
     }
46 48
     require(SERVER_ROOT.'/sections/collages/manage_handle.php');
47 49
     break;
48 50
   case 'manage_artists':
49 51
     if (!check_perms('site_collages_manage')) {
50
-      error(403);
52
+        error(403);
51 53
     }
52 54
     require(SERVER_ROOT.'/sections/collages/manage_artists.php');
53 55
     break;
54 56
   case 'manage_artists_handle':
55 57
     if (!check_perms('site_collages_manage')) {
56
-      error(403);
58
+        error(403);
57 59
     }
58 60
     require(SERVER_ROOT.'/sections/collages/manage_artists_handle.php');
59 61
     break;
60 62
   case 'edit':
61 63
     if (!check_perms('site_edit_wiki')) {
62
-      error(403);
64
+        error(403);
63 65
     }
64 66
     require(SERVER_ROOT.'/sections/collages/edit.php');
65 67
     break;
66 68
   case 'edit_handle':
67 69
     if (!check_perms('site_edit_wiki')) {
68
-      error(403);
70
+        error(403);
69 71
     }
70 72
     require(SERVER_ROOT.'/sections/collages/edit_handle.php');
71 73
     break;
@@ -90,19 +92,17 @@ switch ($_REQUEST['action']) {
90 92
     break;
91 93
   case 'create_personal':
92 94
     if (!check_perms('site_collages_personal')) {
93
-      error(403);
95
+        error(403);
94 96
     } else {
95
-      Collages::create_personal_collage();
97
+        Collages::create_personal_collage();
96 98
     }
97 99
     break;
98 100
 
99 101
   default:
100 102
     if (!empty($_GET['id'])) {
101
-      require(SERVER_ROOT.'/sections/collages/collage.php');
103
+        require(SERVER_ROOT.'/sections/collages/collage.php');
102 104
     } else {
103
-      require(SERVER_ROOT.'/sections/collages/browse.php');
105
+        require(SERVER_ROOT.'/sections/collages/browse.php');
104 106
     }
105 107
     break;
106 108
 }
107
-
108
-?>

+ 14
- 14
sections/collages/torrent_collage.php View File

@@ -46,7 +46,7 @@ foreach ($GroupIDs as $GroupID) {
46 46
     $Group = $TorrentList[$GroupID];
47 47
     extract(Torrents::array_group($Group));
48 48
     $UserID = $Contributors[$GroupID];
49
-    $TorrentTags = new Tags($TagList);
49
+    $TorrentTags = new Tags($tag_list);
50 50
 
51 51
     // Handle stats and stuff
52 52
     $Number++;
@@ -74,28 +74,28 @@ foreach ($GroupIDs as $GroupID) {
74 74
     $DisplayName .= "<a class='torrent_title' href='torrents.php?id=$GroupID' ";
75 75
 
76 76
     if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
77
-        $DisplayName .= 'data-cover="'.ImageTools::process($WikiImage, 'thumb').'" ';
77
+        $DisplayName .= 'data-cover="'.ImageTools::process($picture, 'thumb').'" ';
78 78
     }
79 79
 
80
-    $GroupName = empty($GroupName) ? (empty($GroupTitle2) ? $GroupNameJP : $GroupTitle2) : $GroupName;
81
-    $DisplayName .= "dir='ltr'>$GroupName</a>";
80
+    $title = empty($title) ? (empty($subject) ? $object : $subject) : $title;
81
+    $DisplayName .= "dir='ltr'>$title</a>";
82 82
 
83 83
     # Year
84
-    if ($GroupYear) {
84
+    if ($published) {
85 85
         $Label = '<br />📅&nbsp;';
86
-        $DisplayName .= $Label."<a href='torrents.php?action=search&year=$GroupYear'>$GroupYear</a>";
86
+        $DisplayName .= $Label."<a href='torrents.php?action=search&year=$published'>$published</a>";
87 87
     }
88 88
           
89 89
     # Studio
90
-    if ($GroupStudio) {
90
+    if ($workgroup) {
91 91
         $Label = '&ensp;📍&nbsp;';
92
-        $DisplayName .= $Label."<a href='torrents.php?action=search&location=$GroupStudio'>$GroupStudio</a>";
92
+        $DisplayName .= $Label."<a href='torrents.php?action=search&location=$workgroup'>$workgroup</a>";
93 93
     }
94 94
 
95 95
     # Catalogue Number
96
-    if ($GroupCatalogueNumber) {
96
+    if ($identifier) {
97 97
         $Label = '&ensp;🔑&nbsp;';
98
-        $DisplayName .= $Label."<a href='torrents.php?action=search&numbers=$GroupCatalogueNumber'>$GroupCatalogueNumber</a>";
98
+        $DisplayName .= $Label."<a href='torrents.php?action=search&numbers=$identifier'>$identifier</a>";
99 99
     }
100 100
 
101 101
     # Authors
@@ -284,7 +284,7 @@ foreach ($GroupIDs as $GroupID) {
284 284
     $DisplayName = '';
285 285
 
286 286
     #$DisplayName .= Artists::display_artists($Artists, false);
287
-    $DisplayName .= $GroupName;
287
+    $DisplayName .= $title;
288 288
 
289 289
     if ($GroupYear > 0) {
290 290
         $DisplayName = "$DisplayName [$GroupYear]";
@@ -295,11 +295,11 @@ foreach ($GroupIDs as $GroupID) {
295 295
 
296 296
 <div class="collage_image image_group_<?=$GroupID?>">
297 297
   <a href="torrents.php?id=<?=$GroupID?>">
298
-    <?php if (!$WikiImage) {
299
-        $WikiImage = STATIC_SERVER.'common/noartwork/music.png';
298
+    <?php if (!$picture) {
299
+        $picture = STATIC_SERVER.'common/noartwork/music.png';
300 300
     } ?>
301 301
     <img class="tooltip_interactive"
302
-      src="<?=ImageTools::process($WikiImage, 'thumb')?>"
302
+      src="<?=ImageTools::process($picture, 'thumb')?>"
303 303
       alt="<?=$DisplayName?>"
304 304
       title="<?=$DisplayName?>"
305 305
       data-title-plain="<?="$DisplayName ($PlainTags)"?>"

+ 49
- 28
sections/schedule/daily/disable_inactive_users.php View File

@@ -1,27 +1,38 @@
1 1
 <?php
2
-#declare(strict_types=1);
2
+declare(strict_types=1);
3 3
 
4
+/*
4 5
 $ENV = ENV::go();
5 6
 
6
-// The SQL query's lines below controls the notification clock
7
-//   AND um.LastAccess < (NOW() - INTERVAL 110 DAY)
8
-//   AND um.LastAccess > (NOW() - INTERVAL 111 DAY)
7
+# The SQL query's lines below controls the notification clock
8
+#   AND um.LastAccess < (NOW() - INTERVAL 110 DAY)
9
+#   AND um.LastAccess > (NOW() - INTERVAL 111 DAY)
9 10
 
10 11
 if (apcu_exists('DBKEY')) {
11
-    // Send email
12
+    # Send email
12 13
     $DB->query("
13
-      SELECT um.Username, um.Email
14
-      FROM users_info AS ui
15
-        JOIN users_main AS um ON um.ID = ui.UserID
16
-        LEFT JOIN users_levels AS ul ON ul.UserID = um.ID AND ul.PermissionID = '".CELEB."'
17
-      WHERE um.PermissionID IN ('".USER."', '".MEMBER ."')
18
-        AND um.LastAccess < (NOW() - INTERVAL 355 DAY)
19
-        AND um.LastAccess > (NOW() - INTERVAL 356 DAY)
20
-        AND um.LastAccess IS NOT NULL
21
-        AND ui.Donor = '0'
22
-        AND um.Enabled != '2'
23
-        AND ul.UserID IS NULL
24
-      GROUP BY um.ID");
14
+    SELECT
15
+      um.`Username`,
16
+      um.`Email`
17
+    FROM
18
+      `users_info` AS ui
19
+    JOIN `users_main` AS um
20
+    ON
21
+      um.`ID` = ui.`UserID`
22
+    LEFT JOIN `users_levels` AS ul
23
+    ON
24
+      ul.`UserID` = um.`ID` AND ul.`PermissionID` = '".CELEB."'
25
+    WHERE
26
+      um.`PermissionID` IN('".USER."', '".MEMBER ."')
27
+      AND um.`LastAccess` <(NOW() - INTERVAL 355 DAY)
28
+      AND um.`LastAccess` >(NOW() - INTERVAL 356 DAY)
29
+      AND um.`LastAccess` IS NOT NULL
30
+      AND ui.`Donor` = '0'
31
+      AND um.`Enabled` != '2'
32
+      AND ul.`UserID` IS NULL
33
+    GROUP BY
34
+      um.`ID`
35
+    ");
25 36
 
26 37
     while (list($Username, $Email) = $DB->next_record()) {
27 38
         $Email = Crypto::decrypt($Email);
@@ -32,19 +43,29 @@ if (apcu_exists('DBKEY')) {
32 43
     # The actual deletion clock
33 44
     #   AND um.LastAccess < (NOW() - INTERVAL 120 DAY)
34 45
     $DB->query("
35
-      SELECT um.ID
36
-      FROM users_info AS ui
37
-        JOIN users_main AS um ON um.ID = ui.UserID
38
-        LEFT JOIN users_levels AS ul ON ul.UserID = um.ID AND ul.PermissionID = '".CELEB."'
39
-      WHERE um.PermissionID IN ('".USER."', '".MEMBER ."')
40
-        AND um.LastAccess < (NOW() - INTERVAL 365 DAY)
41
-        AND um.LastAccess IS NOT NULL
42
-        AND ui.Donor = '0'
43
-        AND um.Enabled != '2'
44
-        AND ul.UserID IS NULL
45
-      GROUP BY um.ID");
46
+    SELECT
47
+      um.`ID`
48
+    FROM
49
+      `users_info` AS ui
50
+    JOIN `users_main` AS um
51
+    ON
52
+      um.`ID` = ui.`UserID`
53
+    LEFT JOIN `users_levels` AS ul
54
+    ON
55
+      ul.`UserID` = um.`ID` AND ul.`PermissionID` = '".CELEB."'
56
+    WHERE
57
+      um.`PermissionID` IN('".USER."', '".MEMBER ."')
58
+      AND um.`LastAccess` <(NOW() - INTERVAL 365 DAY)
59
+      AND um.`LastAccess` IS NOT NULL
60
+      AND ui.`Donor` = '0'
61
+      AND um.`Enabled` != '2'
62
+      AND ul.`UserID` IS NULL
63
+    GROUP BY
64
+      um.`ID`
65
+    ");
46 66
 
47 67
     if ($DB->has_results()) {
48 68
         Tools::disable_users($DB->collect('ID'), 'Disabled for inactivity.', 3);
49 69
     }
50 70
 }
71
+*/

+ 7
- 7
sections/torrents/editgroup.php View File

@@ -64,8 +64,8 @@ if ($DB->has_results()) {
64 64
 $Artists = Artists::get_artists(array($GroupID))[$GroupID];
65 65
 
66 66
 if (!$Body) {
67
-    $Body = $WikiBody;
68
-    $Image = $WikiImage;
67
+    $Body = $description;
68
+    $Image = $picture;
69 69
 }
70 70
 
71 71
 View::show_header(
@@ -76,7 +76,7 @@ View::show_header(
76 76
 
77 77
 <h2 class="header">
78 78
   Edit
79
-  <a href="torrents.php?id=<?=$GroupID?>"><?=($Name ? $Name : ($Title2 ? $Title2 : $NameJP))?></a>
79
+  <a href="torrents.php?id=<?=$GroupID?>"><?=($title ? $title : ($subject ? $subject : $object))?></a>
80 80
 </h2>
81 81
 
82 82
 <div class="box pad">
@@ -101,7 +101,7 @@ View::show_header(
101 101
 
102 102
     <?php
103 103
 new TEXTAREA_PREVIEW(
104
-    'body', # $Name breaks "Rename (will not merge)"
104
+    'body', # $title breaks "Rename (will not merge)"
105 105
     $ID = 'body',
106 106
     $Value = display_str($Body) ?? '',
107 107
 );
@@ -308,7 +308,7 @@ new TEXTAREA_PREVIEW(
308 308
 
309 309
         <td>
310 310
           <input type="text" name="name" size="70"
311
-            value="<?=$Name?>" />
311
+            value="<?=$title?>" />
312 312
         </td>
313 313
       </tr>
314 314
 
@@ -318,8 +318,8 @@ new TEXTAREA_PREVIEW(
318 318
         </td>
319 319
 
320 320
         <td>
321
-          <input type="text" name="Title2" size="70"
322
-            value="<?=$Title2?>" />
321
+          <input type="text" name="subject" size="70"
322
+            value="<?=$subject?>" />
323 323
         </td>
324 324
       </tr>
325 325
 

+ 289
- 252
sections/torrents/index.php View File

@@ -1,270 +1,307 @@
1 1
 <?php
2 2
 #declare(strict_types=1);
3 3
 
4
-//Function used for pagination of peer/snatch/download lists on details.php
5
-function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
6
-  $NumPages = ceil($NumResults / 100);
7
-  $PageLinks = [];
8
-  for ($i = 1; $i <= $NumPages; $i++) {
9
-    if ($i == $CurrentPage) {
10
-      $PageLinks[] = $i;
11
-    } else {
12
-      $PageLinks[] = "<a href=\"#\" onclick=\"$Action($TorrentID, $i)\">$i</a>";
4
+$ENV = ENV::go();
5
+
6
+// Function used for pagination of peer/snatch/download lists on details.php
7
+function js_pages($Action, $TorrentID, $NumResults, $CurrentPage)
8
+{
9
+    $NumPages = ceil($NumResults / 100);
10
+    $PageLinks = [];
11
+
12
+    for ($i = 1; $i <= $NumPages; $i++) {
13
+        if ($i === $CurrentPage) {
14
+            $PageLinks[] = $i;
15
+        } else {
16
+            $PageLinks[] = "<a href='#' onclick='$Action($TorrentID, $i)'>$i</a>";
17
+        }
13 18
     }
14
-  }
15
-  return implode(' | ', $PageLinks);
19
+  
20
+    return implode(' | ', $PageLinks);
16 21
 }
17 22
 
18
-// This gets used in a few places
19
-$ArtistTypes = array(1 => 'Main', 2 => 'Guest', 3 => 'Remixer', 4 => 'Composer', 5 => 'Conductor', 6 => 'DJ/Compiler', 7 => 'Producer');
20 23
 
24
+/**
25
+ * Main switchboard
26
+ */
21 27
 if (!empty($_REQUEST['action'])) {
22
-  switch ($_REQUEST['action']) {
23
-    case 'edit':
24
-      enforce_login();
25
-      include(SERVER_ROOT.'/sections/torrents/edit.php');
26
-      break;
27
-
28
-    case 'editgroup':
29
-      enforce_login();
30
-      include(SERVER_ROOT.'/sections/torrents/editgroup.php');
31
-      break;
32
-
33
-    case 'editgroupid':
34
-      enforce_login();
35
-      include(SERVER_ROOT.'/sections/torrents/editgroupid.php');
36
-      break;
37
-
38
-    case 'changecategory':
39
-      enforce_login();
40
-      include(SERVER_ROOT.'/sections/torrents/takechangecategory.php');
41
-      break;
42
-    case 'grouplog':
43
-      enforce_login();
44
-      include(SERVER_ROOT.'/sections/torrents/grouplog.php');
45
-      break;
46
-    case 'takeedit':
47
-      enforce_login();
48
-      include(SERVER_ROOT.'/sections/torrents/takeedit.php');
49
-      break;
50
-
51
-    case 'newgroup':
52
-      enforce_login();
53
-      include(SERVER_ROOT.'/sections/torrents/takenewgroup.php');
54
-      break;
55
-
56
-    case 'peerlist':
57
-      enforce_login();
58
-      include(SERVER_ROOT.'/sections/torrents/peerlist.php');
59
-      break;
60
-
61
-    case 'snatchlist':
62
-      enforce_login();
63
-      include(SERVER_ROOT.'/sections/torrents/snatchlist.php');
64
-      break;
65
-
66
-    case 'downloadlist':
67
-      enforce_login();
68
-      include(SERVER_ROOT.'/sections/torrents/downloadlist.php');
69
-      break;
70
-
71
-    case 'redownload':
72
-      enforce_login();
73
-      include(SERVER_ROOT.'/sections/torrents/redownload.php');
74
-      break;
75
-
76
-    case 'revert':
77
-    case 'takegroupedit':
78
-      enforce_login();
79
-      include(SERVER_ROOT.'/sections/torrents/takegroupedit.php');
80
-      break;
81
-
82
-    case 'screenshotedit':
83
-      enforce_login();
84
-      include(SERVER_ROOT.'/sections/torrents/screenshotedit.php');
85
-      break;
86
-
87
-    case 'nonwikiedit':
88
-      enforce_login();
89
-      include(SERVER_ROOT.'/sections/torrents/nonwikiedit.php');
90
-      break;
91
-
92
-    case 'rename':
93
-      enforce_login();
94
-      include(SERVER_ROOT.'/sections/torrents/rename.php');
95
-      break;
96
-
97
-    case 'merge':
98
-      enforce_login();
99
-      include(SERVER_ROOT.'/sections/torrents/merge.php');
100
-      break;
101
-
102
-    case 'add_alias':
103
-      enforce_login();
104
-      include(SERVER_ROOT.'/sections/torrents/add_alias.php');
105
-      break;
106
-
107
-    case 'delete_alias':
108
-      enforce_login();
109
-      authorize();
110
-      include(SERVER_ROOT.'/sections/torrents/delete_alias.php');
111
-      break;
112
-
113
-    case 'history':
114
-      enforce_login();
115
-      include(SERVER_ROOT.'/sections/torrents/history.php');
116
-      break;
117
-
118
-    case 'delete':
119
-      enforce_login();
120
-      include(SERVER_ROOT.'/sections/torrents/delete.php');
121
-      break;
122
-
123
-    case 'takedelete':
124
-      enforce_login();
125
-      include(SERVER_ROOT.'/sections/torrents/takedelete.php');
126
-      break;
127
-
128
-    case 'masspm':
129
-      enforce_login();
130
-      include(SERVER_ROOT.'/sections/torrents/masspm.php');
131
-      break;
132
-
133
-    case 'reseed':
134
-      enforce_login();
135
-      include(SERVER_ROOT.'/sections/torrents/reseed.php');
136
-      break;
137
-
138
-    case 'takemasspm':
139
-      enforce_login();
140
-      include(SERVER_ROOT.'/sections/torrents/takemasspm.php');
141
-      break;
142
-
143
-    case 'add_tag':
144
-      enforce_login();
145
-      include(SERVER_ROOT.'/sections/torrents/add_tag.php');
146
-      break;
147
-
148
-    case 'delete_tag':
149
-      enforce_login();
150
-      authorize();
151
-      include(SERVER_ROOT.'/sections/torrents/delete_tag.php');
152
-      break;
153
-
154
-    case 'notify':
155
-      enforce_login();
156
-      include(SERVER_ROOT.'/sections/torrents/notify.php');
157
-      break;
158
-
159
-    case 'manage_artists':
160
-      enforce_login();
161
-      require(SERVER_ROOT.'/sections/torrents/manage_artists.php');
162
-      break;
163
-
164
-    case 'notify_clear':
165
-    case 'notify_clear_item':
166
-    case 'notify_clear_items':
167
-    case 'notify_clearitem':
168
-    case 'notify_clear_filter':
169
-    case 'notify_cleargroup':
170
-    case 'notify_catchup':
171
-    case 'notify_catchup_filter':
172
-      authorize();
173
-      enforce_login();
174
-      require(SERVER_ROOT.'/sections/torrents/notify_actions.php');
175
-      break;
28
+    switch ($_REQUEST['action']) {
29
+        case 'edit':
30
+            enforce_login();
31
+            require_once "$ENV->SERVER_ROOT/sections/torrents/edit.php";
32
+            break;
33
+        
34
+        case 'editgroup':
35
+            enforce_login();
36
+            require_once "$ENV->SERVER_ROOT/sections/torrents/editgroup.php";
37
+            break;
38
+            
39
+        case 'editgroupid':
40
+            enforce_login();
41
+            require_once "$ENV->SERVER_ROOT/sections/torrents/editgroupid.php";
42
+            break;
43
+            
44
+        case 'changecategory':
45
+            enforce_login();
46
+            require_once "$ENV->SERVER_ROOT/sections/torrents/takechangecategory.php";
47
+            break;
48
+            
49
+        case 'grouplog':
50
+            enforce_login();
51
+            require_once "$ENV->SERVER_ROOT/sections/torrents/grouplog.php";
52
+            break;
53
+            
54
+        case 'takeedit':
55
+            enforce_login();
56
+            require_once "$ENV->SERVER_ROOT/sections/torrents/takeedit.php";
57
+            break;
58
+            
59
+        case 'newgroup':
60
+            enforce_login();
61
+            require_once "$ENV->SERVER_ROOT/sections/torrents/takenewgroup.php";
62
+            break;
63
+            
64
+        case 'peerlist':
65
+            enforce_login();
66
+            require_once "$ENV->SERVER_ROOT/sections/torrents/peerlist.php";
67
+            break;
68
+            
69
+        case 'snatchlist':
70
+            enforce_login();
71
+            require_once "$ENV->SERVER_ROOT/sections/torrents/snatchlist.php";
72
+            break;
73
+            
74
+        case 'downloadlist':
75
+            enforce_login();
76
+            require_once "$ENV->SERVER_ROOT/sections/torrents/downloadlist.php";
77
+            break;
78
+            
79
+        case 'redownload':
80
+            enforce_login();
81
+            require_once "$ENV->SERVER_ROOT/sections/torrents/redownload.php";
82
+            break;
83
+            
84
+        case 'revert':
85
+        case 'takegroupedit':
86
+            enforce_login();
87
+            require_once "$ENV->SERVER_ROOT/sections/torrents/takegroupedit.php";
88
+            break;
89
+            
90
+        case 'screenshotedit':
91
+            enforce_login();
92
+            require_once "$ENV->SERVER_ROOT/sections/torrents/screenshotedit.php";
93
+            break;
94
+            
95
+        case 'nonwikiedit':
96
+            enforce_login();
97
+            require_once "$ENV->SERVER_ROOT/sections/torrents/nonwikiedit.php";
98
+            break;
99
+            
100
+        case 'rename':
101
+            enforce_login();
102
+            require_once "$ENV->SERVER_ROOT/sections/torrents/rename.php";
103
+            break;
104
+            
105
+        case 'merge':
106
+            enforce_login();
107
+            require_once "$ENV->SERVER_ROOT/sections/torrents/merge.php";
108
+            break;
109
+            
110
+        case 'add_alias':
111
+            enforce_login();
112
+            require_once "$ENV->SERVER_ROOT/sections/torrents/add_alias.php";
113
+            break;
114
+            
115
+        case 'delete_alias':
116
+            enforce_login();
117
+            authorize();
118
+            require_once "$ENV->SERVER_ROOT/sections/torrents/delete_alias.php";
119
+            break;
120
+            
121
+        case 'history':
122
+            enforce_login();
123
+            require_once "$ENV->SERVER_ROOT/sections/torrents/history.php";
124
+            break;
125
+            
126
+        case 'delete':
127
+            enforce_login();
128
+            require_once "$ENV->SERVER_ROOT/sections/torrents/delete.php";
129
+            break;
130
+            
131
+        case 'takedelete':
132
+            enforce_login();
133
+            require_once "$ENV->SERVER_ROOT/sections/torrents/takedelete.php";
134
+            break;
135
+            
136
+        case 'masspm':
137
+            enforce_login();
138
+            require_once "$ENV->SERVER_ROOT/sections/torrents/masspm.php";
139
+            break;
140
+            
141
+        case 'reseed':
142
+            enforce_login();
143
+            require_once "$ENV->SERVER_ROOT/sections/torrents/reseed.php";
144
+            break;
145
+            
146
+        case 'takemasspm':
147
+            enforce_login();
148
+            require_once "$ENV->SERVER_ROOT/sections/torrents/takemasspm.php";
149
+            break;
150
+            
151
+        case 'add_tag':
152
+            enforce_login();
153
+            require_once "$ENV->SERVER_ROOT/sections/torrents/add_tag.php";
154
+            break;
155
+            
156
+        case 'delete_tag':
157
+            enforce_login();
158
+            authorize();
159
+            require_once "$ENV->SERVER_ROOT/sections/torrents/delete_tag.php";
160
+            break;
161
+            
162
+        case 'notify':
163
+            enforce_login();
164
+            require_once "$ENV->SERVER_ROOT/sections/torrents/notify.php";
165
+            break;
166
+            
167
+        case 'manage_artists':
168
+            enforce_login();
169
+            require_once "$ENV->SERVER_ROOT/sections/torrents/manage_artists.php";
170
+            break;
171
+            
172
+        case 'notify_clear':
173
+        case 'notify_clear_item':
174
+        case 'notify_clear_items':
175
+        case 'notify_clearitem':
176
+        case 'notify_clear_filter':
177
+        case 'notify_cleargroup':
178
+        case 'notify_catchup':
179
+        case 'notify_catchup_filter':
180
+            enforce_login();
181
+            authorize();
182
+            require_once "$ENV->SERVER_ROOT/sections/torrents/notify_actions.php";
183
+            break;
184
+            
185
+        case 'download':
186
+            require_once "$ENV->SERVER_ROOT/sections/torrents/download.php";
187
+            break;
188
+            
189
+        case 'regen_filelist':
190
+            if (check_perms('users_mod') && !empty($_GET['torrentid']) && is_number($_GET['torrentid'])) {
191
+                Torrents::regenerate_filelist($_GET['torrentid']);
192
+                header('Location: torrents.php?torrentid='.$_GET['torrentid']);
193
+                error();
194
+            } else {
195
+                error(403);
196
+            }
197
+            break;
198
+            
199
+        case 'fix_group':
200
+            if ((check_perms('users_mod') || check_perms('torrents_fix_ghosts')) && authorize() && !empty($_GET['groupid']) && is_number($_GET['groupid'])) {
201
+                $DB->prepare_query("
202
+                SELECT
203
+                  COUNT(`ID`)
204
+                FROM
205
+                  `torrents`
206
+                WHERE
207
+                  `GroupID` = '$_GET[groupid]'
208
+                ");
209
+                $DB->exec_prepared_query();
210
+                list($Count) = $DB->next_record();
211
+                
212
+                if ($Count === 0) {
213
+                    Torrents::delete_group($_GET['groupid']);
214
+                }
215
+                
216
+                if (!empty($_GET['artistid']) && is_number($_GET['artistid'])) {
217
+                    header('Location: artist.php?id='.$_GET['artistid']);
218
+                } else {
219
+                    header('Location: torrents.php?id='.$_GET['groupid']);
220
+                }
221
+            } else {
222
+                error(403);
223
+            }
224
+            break;
225
+            
226
+        case 'add_cover_art':
227
+            require_once "$ENV->SERVER_ROOT/sections/torrents/add_cover_art.php";
228
+            break;
229
+            
230
+        case 'remove_cover_art':
231
+            require_once "$ENV->SERVER_ROOT/sections/torrents/remove_cover_art.php";
232
+            break;
233
+            
234
+        case 'autocomplete_tags':
235
+            require_once "$ENV->SERVER_ROOT/sections/torrents/autocomplete_tags.php";
236
+            break;
237
+            
238
+        default:
239
+            enforce_login();
240
+            
241
+            if (!empty($_GET['id'])) {
242
+                require_once "$ENV->SERVER_ROOT/sections/torrents/details.php";
243
+            } elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
244
+                $DB->query("
245
+                SELECT
246
+                  `GroupID`
247
+                FROM
248
+                  `torrents`
249
+                WHERE
250
+                  `ID` = '$_GET[torrentid]'
251
+                ");
252
+                list($GroupID) = $DB->next_record();
253
+                
254
+                if ($GroupID) {
255
+                    header("Location: torrents.php?id=$GroupID&torrentid=".$_GET['torrentid']);
256
+                }
257
+            } else {
258
+                require_once "$ENV->SERVER_ROOT/sections/torrents/browse.php";
259
+            }
260
+            break;
261
+    } # switch
262
+}
176 263
 
177
-    case 'download':
178
-      require(SERVER_ROOT.'/sections/torrents/download.php');
179
-      break;
264
+# If $_REQUEST['action'] is empty
265
+else {
266
+    enforce_login();
267
+
268
+    if (!empty($_GET['id'])) {
269
+        require_once "$ENV->SERVER_ROOT/sections/torrents/details.php";
270
+    } elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
271
+        $DB->query("
272
+        SELECT
273
+          `GroupID`
274
+        FROM
275
+          `torrents`
276
+        WHERE
277
+          `ID` = '$_GET[torrentid]'
278
+        ");
279
+        list($GroupID) = $DB->next_record();
180 280
 
181
-    case 'regen_filelist':
182
-      if (check_perms('users_mod') && !empty($_GET['torrentid']) && is_number($_GET['torrentid'])) {
183
-        Torrents::regenerate_filelist($_GET['torrentid']);
184
-        header('Location: torrents.php?torrentid='.$_GET['torrentid']);
185
-        error();
186
-      } else {
187
-        error(403);
188
-      }
189
-      break;
190
-    case 'fix_group':
191
-      if ((check_perms('users_mod') || check_perms('torrents_fix_ghosts')) && authorize() && !empty($_GET['groupid']) && is_number($_GET['groupid'])) {
192
-        $DB->query('
193
-          SELECT COUNT(ID)
194
-          FROM torrents
195
-          WHERE GroupID = '.$_GET['groupid']);
196
-        list($Count) = $DB->next_record();
197
-        if ($Count == 0) {
198
-          Torrents::delete_group($_GET['groupid']);
199
-        }
200
-        if (!empty($_GET['artistid']) && is_number($_GET['artistid'])) {
201
-          header('Location: artist.php?id='.$_GET['artistid']);
281
+        if ($GroupID) {
282
+            header("Location: torrents.php?id=$GroupID&torrentid=".$_GET['torrentid'].'#torrent'.$_GET['torrentid']);
202 283
         } else {
203
-          header('Location: torrents.php?id='.$_GET['groupid']);
284
+            header("Location: log.php?search=Torrent+$_GET[torrentid]");
204 285
         }
205
-      } else {
206
-        error(403);
207
-      }
208
-      break;
209
-    case 'add_cover_art':
210
-      include(SERVER_ROOT.'/sections/torrents/add_cover_art.php');
211
-      break;
212
-    case 'remove_cover_art':
213
-      include(SERVER_ROOT.'/sections/torrents/remove_cover_art.php');
214
-      break;
215
-    case 'autocomplete_tags':
216
-      include(SERVER_ROOT.'/sections/torrents/autocomplete_tags.php');
217
-      break;
218
-    default:
219
-      enforce_login();
220
-
221
-      if (!empty($_GET['id'])) {
222
-        include(SERVER_ROOT.'/sections/torrents/details.php');
223
-      } elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
224
-        $DB->query('
225
-          SELECT GroupID
226
-          FROM torrents
227
-          WHERE ID = '.$_GET['torrentid']);
286
+    } elseif (!empty($_GET['type'])) {
287
+        require_once "$ENV->SERVER_ROOT/sections/torrents/user.php";
288
+    } elseif (!empty($_GET['groupname']) && !empty($_GET['forward'])) {
289
+        $DB->prepare_query("
290
+        SELECT
291
+          `id`
292
+        FROM
293
+          `torrents_group`
294
+        WHERE
295
+          `title` LIKE '$_GET[groupname]'
296
+        ");
228 297
         list($GroupID) = $DB->next_record();
298
+
229 299
         if ($GroupID) {
230
-          header("Location: torrents.php?id=$GroupID&torrentid=".$_GET['torrentid']);
300
+            header("Location: torrents.php?id=$GroupID");
301
+        } else {
302
+            require_once "$ENV->SERVER_ROOT/sections/torrents/browse.php";
231 303
         }
232
-      } else {
233
-        include(SERVER_ROOT.'/sections/torrents/browse.php');
234
-      }
235
-      break;
236
-  }
237
-} else {
238
-  enforce_login();
239
-
240
-  if (!empty($_GET['id'])) {
241
-    include(SERVER_ROOT.'/sections/torrents/details.php');
242
-  } elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
243
-    $DB->query("
244
-      SELECT GroupID
245
-      FROM torrents
246
-      WHERE ID = ".$_GET['torrentid']);
247
-    list($GroupID) = $DB->next_record();
248
-    if ($GroupID) {
249
-      header("Location: torrents.php?id=$GroupID&torrentid=".$_GET['torrentid'].'#torrent'.$_GET['torrentid']);
250
-    } else {
251
-      header("Location: log.php?search=Torrent+$_GET[torrentid]");
252
-    }
253
-  } elseif (!empty($_GET['type'])) {
254
-    include(SERVER_ROOT.'/sections/torrents/user.php');
255
-  } elseif (!empty($_GET['groupname']) && !empty($_GET['forward'])) {
256
-    $DB->query("
257
-      SELECT ID
258
-      FROM torrents_group
259
-      WHERE Name LIKE '".db_string($_GET['groupname'])."'");
260
-    list($GroupID) = $DB->next_record();
261
-    if ($GroupID) {
262
-      header("Location: torrents.php?id=$GroupID");
263 304
     } else {
264
-      include(SERVER_ROOT.'/sections/torrents/browse.php');
305
+        require_once "$ENV->SERVER_ROOT/sections/torrents/browse.php";
265 306
     }
266
-  } else {
267
-    include(SERVER_ROOT.'/sections/torrents/browse.php');
268
-  }
269 307
 }
270
-?>

+ 35
- 34
sections/torrents/manage_artists.php View File

@@ -1,9 +1,11 @@
1
-<?
1
+<?php
2
+#declare(strict_types = 1);
3
+
2 4
 if (empty($_POST['importance']) || empty($_POST['artists']) || empty($_POST['groupid']) || !is_number($_POST['importance']) || !is_number($_POST['groupid'])) {
3
-  error(0);
5
+    error(0);
4 6
 }
5 7
 if (!check_perms('torrents_edit')) {
6
-  error(403);
8
+    error(403);
7 9
 }
8 10
 authorize();
9 11
 
@@ -14,38 +16,38 @@ $ArtistIDs = [];
14 16
 $ArtistsString = '0';
15 17
 
16 18
 foreach ($Artists as $i => $Artist) {
17
-  list($Importance, $ArtistID) = explode(';', $Artist);
18
-  if (is_number($ArtistID) && is_number($Importance)) {
19
-    $CleanArtists[] = array($Importance, $ArtistID);
20
-    $ArtistIDs[] = $ArtistID;
21
-  }
19
+    list($Importance, $ArtistID) = explode(';', $Artist);
20
+    if (is_number($ArtistID) && is_number($Importance)) {
21
+        $CleanArtists[] = array($Importance, $ArtistID);
22
+        $ArtistIDs[] = $ArtistID;
23
+    }
22 24
 }
23 25
 
24 26
 if (count($CleanArtists) > 0) {
25
-  $ArtistsString = implode(',', $ArtistIDs);
26
-  if ($_POST['manager_action'] == 'delete') {
27
-    $DB->query("
27
+    $ArtistsString = implode(',', $ArtistIDs);
28
+    if ($_POST['manager_action'] == 'delete') {
29
+        $DB->query("
28 30
       SELECT Name
29 31
       FROM torrents_group
30 32
       WHERE ID = '".$_POST['groupid']."'");
31
-    list($GroupName) = $DB->next_record();
32
-    $DB->query("
33
+        list($GroupName) = $DB->next_record();
34
+        $DB->query("
33 35
       SELECT ArtistID, Name
34 36
       FROM artists_group
35 37
       WHERE ArtistID IN ($ArtistsString)");
36
-    $ArtistNames = $DB->to_array('ArtistID', MYSQLI_ASSOC, false);
37
-    foreach ($CleanArtists as $Artist) {
38
-      list($Importance, $ArtistID) = $Artist;
39
-      Misc::write_log('Artist ('.$ArtistTypes[$Importance].") $ArtistID (".$ArtistNames[$ArtistID]['Name'].") was removed from the group ".$_POST['groupid']." ($GroupName) by user ".$LoggedUser['ID'].' ('.$LoggedUser['Username'].')');
40
-      Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "Removed artist ".$ArtistNames[$ArtistID]['Name']." (".$ArtistTypes[$Importance].")", 0);
41
-      $DB->query("
38
+        $ArtistNames = $DB->to_array('ArtistID', MYSQLI_ASSOC, false);
39
+        foreach ($CleanArtists as $Artist) {
40
+            list($Importance, $ArtistID) = $Artist;
41
+            Misc::write_log("Artist $ArtistID (".$ArtistNames[$ArtistID]['Name'].") was removed from the group ".$_POST['groupid']." ($GroupName) by user ".$LoggedUser['ID'].' ('.$LoggedUser['Username'].')');
42
+            Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "Removed artist ".$ArtistNames[$ArtistID]['Name'], 0);
43
+            $DB->query("
42 44
         DELETE FROM torrents_artists
43 45
         WHERE GroupID = '$GroupID'
44 46
           AND ArtistID = '$ArtistID'
45 47
           AND Importance = '$Importance'");
46
-      $Cache->delete_value("artist_groups_$ArtistID");
47
-    }
48
-    $DB->query("
48
+            $Cache->delete_value("artist_groups_$ArtistID");
49
+        }
50
+        $DB->query("
49 51
       SELECT ArtistID
50 52
         FROM requests_artists
51 53
         WHERE ArtistID IN ($ArtistsString)
@@ -53,20 +55,19 @@ if (count($CleanArtists) > 0) {
53 55
       SELECT ArtistID
54 56
         FROM torrents_artists
55 57
         WHERE ArtistID IN ($ArtistsString)");
56
-    $Items = $DB->collect('ArtistID');
57
-    $EmptyArtists = array_diff($ArtistIDs, $Items);
58
-    foreach ($EmptyArtists as $ArtistID) {
59
-      Artists::delete_artist($ArtistID);
60
-    }
61
-  } else {
62
-    $DB->query("
58
+        $Items = $DB->collect('ArtistID');
59
+        $EmptyArtists = array_diff($ArtistIDs, $Items);
60
+        foreach ($EmptyArtists as $ArtistID) {
61
+            Artists::delete_artist($ArtistID);
62
+        }
63
+    } else {
64
+        $DB->query("
63 65
       UPDATE IGNORE torrents_artists
64 66
       SET Importance = '".$_POST['importance']."'
65 67
       WHERE GroupID = '$GroupID'
66 68
         AND ArtistID IN ($ArtistsString)");
67
-  }
68
-  $Cache->delete_value("groups_artists_$GroupID");
69
-  Torrents::update_hash($GroupID);
70
-  header("Location: torrents.php?id=$GroupID");
69
+    }
70
+    $Cache->delete_value("groups_artists_$GroupID");
71
+    Torrents::update_hash($GroupID);
72
+    header("Location: torrents.php?id=$GroupID");
71 73
 }
72
-?>

+ 30
- 31
sections/torrents/nonwikiedit.php View File

@@ -12,7 +12,7 @@ if (!check_perms('torrents_edit')) {
12 12
     FROM
13 13
       `torrents`
14 14
     WHERE
15
-      `GroupID` = '$GroupID'
15
+      `GroupID` = '$group_id'
16 16
     ");
17 17
 
18 18
     if (!in_array($LoggedUser['ID'], $DB->collect('UserID'))) {
@@ -38,25 +38,25 @@ if (check_perms('torrents_freeleech')
38 38
         error(404);
39 39
     }
40 40
 
41
-    Torrents::freeleech_groups($GroupID, $Free, $FreeType);
41
+    Torrents::freeleech_groups($group_id, $Free, $FreeType);
42 42
 }
43 43
 
44 44
 $Artists = $_POST['idols'];
45 45
 
46 46
 // Escape fields
47
-$Studio = db_string($_POST['studio']);
48
-$Series = db_string($_POST['series']);
49
-$Year = db_string((int)$_POST['year']);
50
-$CatalogueNumber = db_string($_POST['catalogue']);
47
+$workgroup = db_string($_POST['studio']);
48
+$location = db_string($_POST['series']);
49
+$published = db_string((int)$_POST['year']);
50
+$identifier = db_string($_POST['catalogue']);
51 51
 
52 52
 // Get some info for the group log
53 53
 $DB->query("
54 54
 SELECT
55
-  `Year`
55
+  `published`
56 56
 FROM
57 57
   `torrents_group`
58 58
 WHERE
59
-  `ID` = '$GroupID'
59
+  `id` = '$group_id'
60 60
 ");
61 61
 list($OldYear) = $DB->next_record();
62 62
 
@@ -64,22 +64,22 @@ $DB->query("
64 64
 UPDATE
65 65
   `torrents_group`
66 66
 SET
67
-  `Year` = '$Year',
68
-  `CatalogueNumber` = '$CatalogueNumber',
69
-  `Studio` = '$Studio',
70
-  `Series` = '$Series'
67
+  `published` = '$published',
68
+  `identifier` = '$identifier',
69
+  `workgroup` = '$workgroup',
70
+  `location` = '$location'
71 71
 WHERE
72
-  `ID` = '$GroupID'
72
+  `id` = '$group_id'
73 73
 ");
74 74
 
75
-if ($OldYear !== $Year) {
76
-    $Message = db_string("Year changed from $OldYear to $Year");
75
+if ($OldYear !== $published) {
76
+    $Message = db_string("Year changed from $OldYear to $published");
77
+
77 78
     $DB->query("
78
-    INSERT INTO `group_log`
79
-      (`GroupID`, `UserID`, `Time`, `Info`)
79
+    INSERT INTO `group_log`(`GroupID`, `UserID`, `Time`, `Info`)
80 80
     VALUES(
81
-      '$GroupID',
82
-      ".$LoggedUser['ID'].",
81
+      '$group_id',
82
+      '$LoggedUser[ID]',
83 83
       NOW(),
84 84
       '$Message')
85 85
     ");
@@ -94,7 +94,7 @@ JOIN `torrents_artists` AS ta
94 94
 ON
95 95
   ag.`ArtistID` = ta.`ArtistID`
96 96
 WHERE
97
-  ta.`GroupID` = '$GroupID'
97
+  ta.`GroupID` = '$group_id'
98 98
 ");
99 99
 
100 100
 while ($r = $DB->next_record(MYSQLI_ASSOC, true)) {
@@ -123,18 +123,17 @@ foreach ($Artists as $Artist) {
123 123
             $ArtistID = $DB->inserted_id();
124 124
         }
125 125
 
126
-        $DB->query(
127
-            "
126
+        $DB->query("
128 127
         INSERT INTO `torrents_artists`(`GroupID`, `ArtistID`, `UserID`)
129 128
         VALUES(
130
-          '$GroupID',
129
+          '$group_id',
131 130
           '$ArtistID',
132
-          ".$LoggedUser['ID']."
131
+          '$LoggedUser[ID]'
133 132
         )
134 133
         ON DUPLICATE KEY
135 134
         UPDATE
136
-          `UserID` = ".$LoggedUser['ID']
137
-        ); // Why does this even happen
135
+          `UserID` = '$LoggedUser[ID]'
136
+        "); // Why does this even happen
138 137
         $Cache->delete_value('artist_groups_'.$ArtistID);
139 138
     }
140 139
 }
@@ -161,7 +160,7 @@ foreach ($CurrArtists as $CurrArtist) {
161 160
               `torrents_artists`
162 161
             WHERE
163 162
               `ArtistID` = '$ArtistID'
164
-              AND `GroupID` = '$GroupID'
163
+              AND `GroupID` = '$group_id'
165 164
             ");
166 165
 
167 166
             $DB->query("
@@ -200,13 +199,13 @@ SELECT
200 199
 FROM
201 200
   `torrents`
202 201
 WHERE
203
-  `GroupID` = '$GroupID'
202
+  `GroupID` = '$group_id'
204 203
 ");
205 204
 
206 205
 while (list($TorrentID) = $DB->next_record()) {
207 206
     $Cache->delete_value("torrent_download_$TorrentID");
208 207
 }
209 208
 
210
-Torrents::update_hash($GroupID);
211
-$Cache->delete_value("torrents_details_$GroupID");
212
-header("Location: torrents.php?id=$GroupID");
209
+Torrents::update_hash($group_id);
210
+$Cache->delete_value("torrents_details_$group_id");
211
+header("Location: torrents.php?id=$group_id");

+ 44
- 37
sections/torrents/rename.php View File

@@ -1,58 +1,65 @@
1 1
 <?php
2 2
 #declare(strict_types=1);
3 3
 
4
+/**
5
+ * Input validation
6
+ */
7
+
4 8
 authorize();
5 9
 
6
-$GroupID = $_POST['groupid'];
7
-$NewTitle1 = $_POST['name'];
8
-$NewTitle2 = $_POST['Title2'];
9
-$NewTitle3 = $_POST['namejp'];
10
+$group_id = (int) $_POST['groupid'];
11
+Security::checkInt($group_id);
12
+
13
+$NewTitle = $_POST['name'];
14
+$NewSubject = $_POST['Title2'];
15
+$NewObject = $_POST['namejp'];
10 16
 
11
-$DB->query(
12
-    "
17
+$DB->prepare_query("
13 18
 SELECT
14 19
   `ID`
15 20
 FROM
16 21
   `torrents`
17 22
 WHERE
18
-  `GroupID` = ".db_string($GroupID)."
19
-  AND `UserID` = ".$LoggedUser['ID']
20
-);
21
-$Contributed = $DB->has_results();
22
-
23
-if (!$GroupID || !is_number($GroupID)) {
24
-    error(404);
25
-}
23
+  `GroupID` = '$group_id' AND `UserID` = '$LoggedUser[ID]'
24
+");
25
+$DB->exec_prepared_query();
26 26
 
27
+$Contributed = $DB->has_results();
27 28
 if (!($Contributed || check_perms('torrents_edit'))) {
28 29
     error(403);
29 30
 }
30 31
 
31
-#if (empty($NewName) && empty($NewRJ) && empty($NewJP)) {
32
-if (empty($NewTitle1)) { # Title2, Title3 optional
32
+# NewSubject, NewObject optional
33
+if (empty($NewTitle)) {
33 34
     error('Torrent groups must have a name');
34 35
 }
35 36
 
36
-$DB->query("
37
+$DB->prepare_query("
37 38
 UPDATE
38 39
   `torrents_group`
39 40
 SET
40
-  `Name` = '".db_string($NewTitle1)."',
41
-  `Title2` = '".db_string($NewTitle2)."',
42
-  `NameJP` = '".db_string($NewTitle3)."'
41
+  `title` = '$NewTitle',
42
+  `subject` = '$NewSubject',
43
+  `object` = '$NewObject'
43 44
 WHERE
44
-  `ID` = '$GroupID'
45
+  `id` = '$group_id'
45 46
 ");
46
-$Cache->delete_value("torrents_details_$GroupID");
47
+$DB->exec_prepared_query();
47 48
 
48
-Torrents::update_hash($GroupID);
49
+$Cache->delete_value("torrents_details_$group_id");
50
+Torrents::update_hash($group_id);
49 51
 
50 52
 $DB->query("
51
-  SELECT `Name`, `Title2`, `NameJP`
52
-  FROM `torrents_group`
53
-  WHERE `ID` = '$GroupID'
53
+SELECT
54
+  `title`,
55
+  `subject`,
56
+  `object`
57
+FROM
58
+  `torrents_group`
59
+WHERE
60
+  `id` = '$group_id'
54 61
 ");
55
-list($OldName, $OldRJ, $OldJP) = $DB->next_record(MYSQLI_NUM, false);
62
+list($OldTitle, $OldSubject, $OldObject) = $DB->next_record(MYSQLI_NUM, false);
56 63
 
57 64
 # Map metadata over generic database fields
58 65
 # todo: Work into $ENV in classes/config.php
@@ -60,19 +67,19 @@ $Title1 = 'Title';
60 67
 $Title2 = 'Organism';
61 68
 $Title3 = 'Strain/Variety';
62 69
 
63
-if ($OldName !== $NewTitle1) {
64
-    Misc::write_log("Torrent Group $GroupID ($OldName)'s $Title1 was changed to '$NewTitle1' from '$OldName' by ".$LoggedUser['Username']);
65
-    Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "$Title1 changed to '$NewTitle1' from '$OldName'", 0);
70
+if ($OldTitle !== $NewTitle) {
71
+    Misc::write_log("Torrent Group $group_id ($OldTitle)'s $Title1 was changed to '$NewTitle' from '$OldTitle' by ".$LoggedUser['Username']);
72
+    Torrents::write_group_log($group_id, 0, $LoggedUser['ID'], "$Title1 changed to '$NewTitle' from '$OldTitle'", 0);
66 73
 }
67 74
 
68
-if ($OldRJ !== $NewTitle2) {
69
-    Misc::write_log("Torrent Group $GroupID ($OldRJ)'s $Title2 was changed to '$NewTitle2' from '$OldRJ' by ".$LoggedUser['Username']);
70
-    Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "$Title2 changed to '$NewTitle2' from '$OldRJ'", 0);
75
+if ($OldSubject !== $NewSubject) {
76
+    Misc::write_log("Torrent Group $group_id ($OldSubject)'s $Title2 was changed to '$NewSubject' from '$OldSubject' by ".$LoggedUser['Username']);
77
+    Torrents::write_group_log($group_id, 0, $LoggedUser['ID'], "$Title2 changed to '$NewSubject' from '$OldSubject'", 0);
71 78
 }
72 79
 
73
-if ($OldJP !== $NewTitle3) {
74
-    Misc::write_log("Torrent Group $GroupID ($OldJP)'s $Title3 was changed to '$NewTitle3' from '$OldJP' by ".$LoggedUser['Username']);
75
-    Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "$Title3 changed to '$NewTitle3' from '$OldJP'", 0);
80
+if ($OldObject !== $NewObject) {
81
+    Misc::write_log("Torrent Group $group_id ($OldObject)'s $Title3 was changed to '$NewObject' from '$OldObject' by ".$LoggedUser['Username']);
82
+    Torrents::write_group_log($group_id, 0, $LoggedUser['ID'], "$Title3 changed to '$NewObject' from '$OldObject'", 0);
76 83
 }
77 84
 
78
-header("Location: torrents.php?id=$GroupID");
85
+header("Location: torrents.php?id=$group_id");

+ 154
- 82
sections/torrents/takegroupedit.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-#declare(strict_types = 1);
2
+declare(strict_types = 1);
3 3
 
4 4
 /**
5 5
  * Input validation
@@ -13,139 +13,200 @@ if (!check_perms('site_edit_wiki')) {
13 13
 }
14 14
 
15 15
 # Variables for database input
16
-$UserID = (int) $LoggedUser['ID'];
17
-$GroupID = (int) $_REQUEST['groupid'];
18
-
19
-Security::checkInt([$UserID, $GroupID]);
16
+$user_id = (int) $LoggedUser['ID'];
17
+$group_id = (int) $_REQUEST['groupid'];
18
+Security::checkInt([$user_id, $group_id]);
20 19
 
21 20
 # If we're reverting to a previous revision
22 21
 if (!empty($_GET['action']) && $_GET['action'] === 'revert') {
23
-    $RevisionID = (int) $_GET['revisionid'];
24
-    Security::checkInt($RevisionID);
22
+    $revision_id = (int) $_GET['revisionid'];
23
+    Security::checkInt($revision_id);
25 24
 
26 25
     # To cite from merge: "Everything is legit, let's just confim they're not retarded"
27 26
     if (empty($_GET['confirm'])) {
28 27
         View::show_header();
29 28
     } ?>
30 29
 
31
-<!-- Start HTML -->
32 30
 <div class="center">
33 31
   <div class="header">
34
-    <h2>Revert Confirm!</h2>
32
+    <h2>
33
+      Revert Confirm!
34
+    </h2>
35 35
   </div>
36
-  <div class="box pad">
36
+
37
+  <div class="box">
37 38
     <form class="confirm_form" name="torrent_group" action="torrents.php" method="get">
38 39
       <input type="hidden" name="action" value="revert" />
39 40
       <input type="hidden" name="auth"
40 41
         value="<?=$LoggedUser['AuthKey']?>" />
41 42
       <input type="hidden" name="confirm" value="true" />
42
-      <input type="hidden" name="groupid" value="<?=$GroupID?>" />
43
+      <input type="hidden" name="groupid" value="<?=$group_id?>" />
43 44
       <input type="hidden" name="revisionid"
44
-        value="<?=$RevisionID?>" />
45
-      <h3>You are attempting to revert to the revision <a
46
-          href="torrents.php?id=<?=$GroupID?>&amp;revisionid=<?=$RevisionID?>"><?=$RevisionID?></a>.</h3>
45
+        value="<?=$revision_id?>" />
46
+
47
+      <h3>
48
+        You are attempting to revert to the revision
49
+        <a
50
+          href="torrents.php?id=<?=$group_id?>&amp;revisionid=<?=$revision_id?>"><?=$revision_id?></a>.
51
+      </h3>
47 52
       <input type="submit" value="Confirm" />
48 53
     </form>
49 54
   </div>
50 55
 </div>
56
+
51 57
 <?php
52 58
     View::show_footer();
53
-        error();
54
-    }
55
-} else { // with edit, the variables are passed with POST
56
-    $Body = $_POST['body'];
57
-    $Image = $_POST['image'];
59
+    error();
60
+}
58 61
 
59
-    if (($GroupInfo = $Cache->get_value('torrents_details_'.$GroupID)) && !isset($GroupInfo[0][0])) {
60
-        $GroupCategoryID = $GroupInfo[0]['CategoryID'];
62
+
63
+# With edit, the variables are passed with POST
64
+else {
65
+    $description = $_POST['body'];
66
+    $picture = $_POST['image'];
67
+
68
+    if (($GroupInfo = $Cache->get_value('torrents_details_'.$group_id)) && !isset($GroupInfo[0][0])) {
69
+        $GroupCategoryID = $GroupInfo[0]['category_id'];
61 70
     } else {
62 71
         $DB->query("
63
-      SELECT CategoryID
64
-      FROM torrents_group
65
-      WHERE ID = '$GroupID'");
72
+        SELECT
73
+          `category_id`
74
+        FROM
75
+          `torrents_group`
76
+        WHERE
77
+          `id` = '$group_id'
78
+        ");
66 79
         list($GroupCategoryID) = $DB->next_record();
67 80
     }
68 81
 
69 82
     // Trickery
70
-    if (!preg_match("/^".IMAGE_REGEX."$/i", $Image)) {
71
-        $Image = '';
83
+    if (!preg_match("/^".IMAGE_REGEX."$/i", $picture)) {
84
+        $picture = '';
72 85
     }
73
-    ImageTools::blacklisted($Image);
86
+
87
+    ImageTools::blacklisted($picture);
74 88
     $Summary = db_string($_POST['summary']);
75 89
 }
76 90
 
77 91
 // Insert revision
78
-if (empty($RevisionID)) { // edit
79
-  $DB->query("
80
-    INSERT INTO wiki_torrents
81
-      (PageID, Body, Image, UserID, Summary, Time)
82
-    VALUES
83
-      ('$GroupID', '".db_string($Body)."', '".db_string($Image)."', '$UserID', '$Summary', NOW())");
92
+if (empty($revision_id)) { // edit
93
+  $DB->prepare_query("
94
+  INSERT INTO `wiki_torrents`(
95
+    `PageID`,
96
+    `Body`,
97
+    `Image`,
98
+    `UserID`,
99
+    `Summary`,
100
+    `Time`
101
+  )
102
+  VALUES(
103
+    '$group_id',
104
+    '$description',
105
+    '$picture',
106
+    '$user_id',
107
+    '$Summary',
108
+    NOW()
109
+  )
110
+  ");
111
+    $DB->exec_prepared_query();
84 112
 } else { // revert
85 113
     $DB->query("
86
-    SELECT PageID, Body, Image
87
-    FROM wiki_torrents
88
-    WHERE RevisionID = '$RevisionID'");
114
+    SELECT
115
+      `PageID`,
116
+      `Body`,
117
+      `Image`
118
+    FROM
119
+      `wiki_torrents`
120
+    WHERE
121
+      `RevisionID` = '$revision_id'
122
+    ");
89 123
     list($PossibleGroupID, $Body, $Image) = $DB->next_record();
90
-    if ($PossibleGroupID != $GroupID) {
124
+
125
+    if ($PossibleGroupID !== $group_id) {
91 126
         error(404);
92 127
     }
93 128
 
94 129
     $DB->query("
95
-    INSERT INTO wiki_torrents
96
-      (PageID, Body, Image, UserID, Summary, Time)
97
-    SELECT '$GroupID', Body, Image, '$UserID', 'Reverted to revision $RevisionID', NOW()
98
-    FROM wiki_artists
99
-    WHERE RevisionID = '$RevisionID'");
130
+    INSERT INTO `wiki_torrents`(
131
+      `PageID`,
132
+      `Body`,
133
+      `Image`,
134
+      `UserID`,
135
+      `Summary`,
136
+      `Time`
137
+    )
138
+    SELECT
139
+      '$group_id',
140
+      `Body`,
141
+      `Image`,
142
+      '$user_id',
143
+      'Reverted to revision $revision_id',
144
+      NOW()
145
+    FROM
146
+      `wiki_artists`
147
+    WHERE
148
+      `RevisionID` = '$revision_id'
149
+    ");
100 150
 }
101 151
 
102
-$RevisionID = $DB->inserted_id();
103
-
104
-$Body = db_string($Body);
105
-$Image = db_string($Image);
152
+$revision_id = $DB->inserted_id();
153
+$description = db_string($description);
154
+$picture = db_string($picture);
106 155
 
107
-// Update torrents table (technically, we don't need the RevisionID column, but we can use it for a join which is nice and fast)
156
+// Update torrents table (technically, we don't need the revision_id column, but we can use it for a join which is nice and fast)
108 157
 $DB->query("
109 158
 UPDATE
110 159
   `torrents_group`
111 160
 SET
112
-  `revision_id` = '$RevisionID',
113
-  `description` = '$Body',
114
-  `picture` = '$Image'
161
+  `revision_id` = '$revision_id',
162
+  `description` = '$description',
163
+  `picture` = '$picture'
115 164
 WHERE
116
-  `id` = '$GroupID'
165
+  `id` = '$group_id'
117 166
 ");
118 167
 
119 168
 // There we go, all done!
169
+$Cache->delete_value('torrents_details_'.$group_id);
170
+$Cache->delete_value('torrent_group_'.$group_id);
120 171
 
121
-$Cache->delete_value('torrents_details_'.$GroupID);
122
-$Cache->delete_value('torrent_group_'.$GroupID);
123 172
 $DB->query("
124
-  SELECT CollageID
125
-  FROM collages_torrents
126
-  WHERE GroupID = '$GroupID'");
173
+SELECT
174
+  `CollageID`
175
+FROM
176
+  `collages_torrents`
177
+WHERE
178
+  `GroupID` = '$group_id'
179
+");
180
+
127 181
 if ($DB->has_results()) {
128 182
     while (list($CollageID) = $DB->next_record()) {
129 183
         $Cache->delete_value('collage_'.$CollageID);
130 184
     }
131 185
 }
132 186
 
133
-//Fix Recent Uploads/Downloads for image change
187
+// Fix Recent Uploads/Downloads for image change
134 188
 $DB->query("
135
-  SELECT DISTINCT UserID
136
-  FROM torrents AS t
137
-    LEFT JOIN torrents_group AS tg ON t.GroupID=tg.ID
138
-  WHERE tg.ID = $GroupID");
139
-
140
-$UserIDs = $DB->collect('UserID');
141
-foreach ($UserIDs as $UserID) {
142
-    $RecentUploads = $Cache->get_value('recent_uploads_'.$UserID);
189
+SELECT DISTINCT
190
+  `UserID`
191
+FROM
192
+  `torrents` AS t
193
+LEFT JOIN `torrents_group` AS tg
194
+ON
195
+  t.`GroupID` = tg.`id`
196
+WHERE
197
+  tg.`id` = '$group_id'
198
+");
199
+
200
+$user_ids = $DB->collect('UserID');
201
+foreach ($user_ids as $user_id) {
202
+    $RecentUploads = $Cache->get_value('recent_uploads_'.$user_id);
203
+
143 204
     if (is_array($RecentUploads)) {
144 205
         foreach ($RecentUploads as $Key => $Recent) {
145
-            if ($Recent['ID'] == $GroupID) {
146
-                if ($Recent['WikiImage'] != $Image) {
147
-                    $Recent['WikiImage'] = $Image;
148
-                    $Cache->begin_transaction('recent_uploads_'.$UserID);
206
+            if ($Recent['id'] === $group_id) {
207
+                if ($Recent['picture'] !== $picture) {
208
+                    $Recent['picture'] = $picture;
209
+                    $Cache->begin_transaction('recent_uploads_'.$user_id);
149 210
                     $Cache->update_row($Key, $Recent);
150 211
                     $Cache->commit_transaction(0);
151 212
                 }
@@ -155,24 +216,35 @@ foreach ($UserIDs as $UserID) {
155 216
 }
156 217
 
157 218
 $DB->query("
158
-  SELECT ID
159
-  FROM torrents
160
-  WHERE GroupID = $GroupID");
219
+SELECT
220
+  `ID`
221
+FROM
222
+  `torrents`
223
+WHERE
224
+  `GroupID` = '$group_id'
225
+");
226
+
161 227
 if ($DB->has_results()) {
162 228
     $TorrentIDs = implode(',', $DB->collect('ID'));
163 229
     $DB->query("
164
-    SELECT DISTINCT uid
165
-    FROM xbt_snatched
166
-    WHERE fid IN ($TorrentIDs)");
230
+    SELECT DISTINCT
231
+      `uid`
232
+    FROM
233
+      `xbt_snatched`
234
+    WHERE
235
+      `fid` IN($TorrentIDs)
236
+    ");
237
+
167 238
     $Snatchers = $DB->collect('uid');
168
-    foreach ($Snatchers as $UserID) {
169
-        $RecentSnatches = $Cache->get_value('recent_snatches_'.$UserID);
239
+    foreach ($Snatchers as $user_id) {
240
+        $RecentSnatches = $Cache->get_value('recent_snatches_'.$user_id);
241
+
170 242
         if (is_array($RecentSnatches)) {
171 243
             foreach ($RecentSnatches as $Key => $Recent) {
172
-                if ($Recent['ID'] == $GroupID) {
173
-                    if ($Recent['WikiImage'] != $Image) {
174
-                        $Recent['WikiImage'] = $Image;
175
-                        $Cache->begin_transaction('recent_snatches_'.$UserID);
244
+                if ($Recent['id'] == $group_id) {
245
+                    if ($Recent['picture'] !== $picture) {
246
+                        $Recent['picture'] = $picture;
247
+                        $Cache->begin_transaction('recent_snatches_'.$user_id);
176 248
                         $Cache->update_row($Key, $Recent);
177 249
                         $Cache->commit_transaction(0);
178 250
                     }
@@ -182,4 +254,4 @@ if ($DB->has_results()) {
182 254
     }
183 255
 }
184 256
 
185
-header("Location: torrents.php?id=$GroupID");
257
+header("Location: torrents.php?id=$group_id");

+ 1
- 0
static/styles/beluga/beluga.scss View File

@@ -1 +1,2 @@
1
+@import "../assets/go";
1 2
 @import "scss/beluga";

+ 1
- 0
static/styles/bookish/bookish.scss View File

@@ -1,3 +1,4 @@
1
+@import "../assets/go";
1 2
 @import "scss/bookish";
2 3
 
3 4
 @import "scss/colors";

+ 1
- 0
static/styles/development/development.scss View File

@@ -1 +1,2 @@
1
+@import "../assets/go";
1 2
 @import "scss/development";

+ 1
- 0
static/styles/genaviv/genaviv.scss View File

@@ -1 +1,2 @@
1
+@import "../assets/go";
1 2
 @import "scss/genaviv";

+ 1
- 0
static/styles/matcha/matcha.scss View File

@@ -1 +1,2 @@
1
+@import "../assets/go";
1 2
 @import "scss/matcha";

+ 1
- 0
static/styles/oppai/oppai.scss View File

@@ -1 +1,2 @@
1
+@import "../assets/go";
1 2
 @import "scss/oppai";

+ 1
- 0
static/styles/postmod/postmod.scss View File

@@ -1,3 +1,4 @@
1
+@import "../assets/go";
1 2
 @import "scss/postmod";
2 3
 
3 4
 @import "scss/colors";

+ 1
- 0
static/styles/public/public.scss View File

@@ -1 +1,2 @@
1
+@import "../assets/go";
1 2
 @import "scss/public";

Loading…
Cancel
Save