Browse Source

todo: Use extension parser in torrent edit handler

pjc 5 years ago
parent
commit
81251e5ba7

+ 0
- 5
_packages/extension-parser/classes/torrent_form.class.php View File

28
   </td>
28
   </td>
29
   <td>
29
   <td>
30
     <select name="container">
30
     <select name="container">
31
-      <option value="">---</option>
32
       <option value="Autofill">Autofill</option>
31
       <option value="Autofill">Autofill</option>
33
       <?php
32
       <?php
34
         foreach ($this->Containers as $Name => $Container) {
33
         foreach ($this->Containers as $Name => $Container) {
47
   </td>
46
   </td>
48
   <td>
47
   <td>
49
     <select id="container" name="container">
48
     <select id="container" name="container">
50
-      <option value="">---</option>
51
       <option value="Autofill">Autofill</option>
49
       <option value="Autofill">Autofill</option>
52
       <?php
50
       <?php
53
         foreach ($this->ContainersGames as $Name => $Container) {
51
         foreach ($this->ContainersGames as $Name => $Container) {
66
   </td>
64
   </td>
67
   <td>
65
   <td>
68
     <select id="container" name="container">
66
     <select id="container" name="container">
69
-      <option value="">---</option>
70
       <option value="Autofill">Autofill</option>
67
       <option value="Autofill">Autofill</option>
71
       <?php
68
       <?php
72
         foreach ($this->ContainersProt as $Name => $Container) {
69
         foreach ($this->ContainersProt as $Name => $Container) {
85
   </td>
82
   </td>
86
   <td>
83
   <td>
87
     <select id="container" name="container">
84
     <select id="container" name="container">
88
-      <option value="">---</option>
89
       <option value="Autofill">Autofill</option>
85
       <option value="Autofill">Autofill</option>
90
       <?php
86
       <?php
91
         foreach ($this->ContainersExtra as $Name => $Container) {
87
         foreach ($this->ContainersExtra as $Name => $Container) {
104
   </td>
100
   </td>
105
   <td>
101
   <td>
106
     <select name='archive'>
102
     <select name='archive'>
107
-      <option value="">---</option>
108
       <option value="Autofill">Autofill</option>
103
       <option value="Autofill">Autofill</option>
109
       <?php
104
       <?php
110
         foreach ($this->Archives as $Name => $Archive) {
105
         foreach ($this->Archives as $Name => $Archive) {

+ 29
- 31
_packages/extension-parser/classes/validate.class.php View File

15
      * ];
15
      * ];
16
      *
16
      *
17
      * Then it finds all the extensions in a torrent file list,
17
      * Then it finds all the extensions in a torrent file list,
18
-     * organizes them by file size, and returns the "heaviest" match.
18
+     * organizes them by file size, and returns the heaviest match.
19
      *
19
      *
20
      * That way, you can have, e.g., 5 GiB FASTQ sequence data in one file,
20
      * That way, you can have, e.g., 5 GiB FASTQ sequence data in one file,
21
      * and 100 other small files, and get the format of the actual data.
21
      * and 100 other small files, and get the format of the actual data.
22
      *
22
      *
23
-     * todo: Incorporate into the main function (remove if statements first)
23
+     * todo: Incorporate into $this->ValidateForm (remove if statements first)
24
      */
24
      */
25
     public function ParseExtensions($FileList, $Category, $FileTypes)
25
     public function ParseExtensions($FileList, $Category, $FileTypes)
26
     {
26
     {
27
-        # Make $Tor->file_list() output manageable
27
+        # Sort $Tor->file_list() output by size
28
         $UnNested = array_values($FileList[1]);
28
         $UnNested = array_values($FileList[1]);
29
         $Sorted = (usort($UnNested, function ($a, $b) {
29
         $Sorted = (usort($UnNested, function ($a, $b) {
30
-            return $b <=> $a; # Workaround because ↑ returns true
31
-        }) === true) ? array_values($UnNested) : null;
30
+            return $b <=> $a;
31
+        })) ? $UnNested : null;  # Ternary wrap because ↑ returns true
32
         
32
         
33
         # Harvest the wheat
33
         # Harvest the wheat
34
-        $TopTen = array_slice($Sorted, 0, 10);
35
-        $Result = [];
34
+        # todo: Entries seem duplicated here
35
+        $Heaviest = array_slice($Sorted, 0, 20);
36
+        $Matches = [];
36
 
37
 
37
-        foreach ($TopTen as $TopTen) {
38
-            # How many extensions to keep
39
-            $Extensions = array_slice(explode('.', strtolower($TopTen[1])), -2, 2);
40
-    
41
-            print_r('<pre>');
42
-            var_dump($FileTypes);
43
-            print_r('</pre>');
38
+        foreach ($Heaviest as $Heaviest) {
39
+            # Collect the last 2 period-separated tokens
40
+            $Extensions = array_slice(explode('.', strtolower($Heaviest[1])), -2, 2);
41
+            $Matches = array_merge($Extensions);
44
 
42
 
45
-            $Result = array_filter($Extensions, function ($a) {
46
-                foreach ($FileTypes as $FileType) {
47
-                    in_array($a, $FileType);
48
-                }
49
-            });
43
+            # Distill the file format
44
+            $FileTypes = $FileTypes[$Category];
45
+            $FileTypeNames = array_keys($FileTypes);
50
 
46
 
51
-            /*
52
-            foreach ($FileTypes as $k => $FileType) {
53
-                var_dump(array_intersect($Extensions, $FileTypes));
47
+            # todo: Find the smallest possible number of iterations
48
+            # todo: Reduce nesting by one level
49
+            foreach ($Matches as $Match) {
50
+                $Match = strtolower($Match);
51
+        
52
+                foreach ($FileTypeNames as $FileTypeName) {
53
+                    $SearchMe = [ $FileTypeName, $FileTypes[$FileTypeName] ];
54
+        
55
+                    if (in_array($Match, $SearchMe[1])) {
56
+                        return $SearchMe[0];
57
+                        break;
58
+                    }
59
+                }
54
             }
60
             }
55
-            */
56
         }
61
         }
57
-
58
-        print_r('<pre>');
59
-        print_r('===== RESULTS =====');
60
-        print_r($Result);
61
-        print_r('</pre>');
62
-
63
-        # To be continued
64
     }
62
     }
65
-    # Line 229
63
+    # Line 227

+ 2
- 2
_packages/extension-parser/sections/upload/upload_handle.php View File

22
 //--------------- Autofill format and archive ----------------------------------//
22
 //--------------- Autofill format and archive ----------------------------------//
23
 
23
 
24
 if ($T['Container'] === 'Autofill') {
24
 if ($T['Container'] === 'Autofill') {
25
+
25
     # torrents.Container
26
     # torrents.Container
26
     $Validate->ParseExtensions(
27
     $Validate->ParseExtensions(
27
         # $FileList
28
         # $FileList
36
 }
37
 }
37
 
38
 
38
 if ($T['Archive'] === 'Autofill') {
39
 if ($T['Archive'] === 'Autofill') {
39
-    /*
40
+
40
     # torrents.Archive
41
     # torrents.Archive
41
     $Validate->ParseExtensions(
42
     $Validate->ParseExtensions(
42
         # $FileList
43
         # $FileList
48
         # $FileTypes
49
         # $FileTypes
49
         $T['FileTypes'],
50
         $T['FileTypes'],
50
     );
51
     );
51
-    */
52
 }
52
 }
53
 # Line 452
53
 # Line 452

+ 0
- 5
classes/torrent_form.class.php View File

515
     </td>
515
     </td>
516
     <td>
516
     <td>
517
       <select name="container">
517
       <select name="container">
518
-        <option value="">---</option>
519
         <option value="Autofill">Autofill</option>
518
         <option value="Autofill">Autofill</option>
520
         <?php
519
         <?php
521
           foreach ($this->Containers as $Name => $Container) {
520
           foreach ($this->Containers as $Name => $Container) {
534
     </td>
533
     </td>
535
     <td>
534
     <td>
536
       <select id="container" name="container">
535
       <select id="container" name="container">
537
-        <option value="">---</option>
538
         <option value="Autofill">Autofill</option>
536
         <option value="Autofill">Autofill</option>
539
         <?php
537
         <?php
540
           foreach ($this->ContainersGames as $Name => $Container) {
538
           foreach ($this->ContainersGames as $Name => $Container) {
553
     </td>
551
     </td>
554
     <td>
552
     <td>
555
       <select id="container" name="container">
553
       <select id="container" name="container">
556
-        <option value="">---</option>
557
         <option value="Autofill">Autofill</option>
554
         <option value="Autofill">Autofill</option>
558
         <?php
555
         <?php
559
           foreach ($this->ContainersProt as $Name => $Container) {
556
           foreach ($this->ContainersProt as $Name => $Container) {
572
     </td>
569
     </td>
573
     <td>
570
     <td>
574
       <select id="container" name="container">
571
       <select id="container" name="container">
575
-        <option value="">---</option>
576
         <option value="Autofill">Autofill</option>
572
         <option value="Autofill">Autofill</option>
577
         <?php
573
         <?php
578
           foreach ($this->ContainersExtra as $Name => $Container) {
574
           foreach ($this->ContainersExtra as $Name => $Container) {
591
     </td>
587
     </td>
592
     <td>
588
     <td>
593
       <select name='archive'>
589
       <select name='archive'>
594
-        <option value="">---</option>
595
         <option value="Autofill">Autofill</option>
590
         <option value="Autofill">Autofill</option>
596
         <?php
591
         <?php
597
           foreach ($this->Archives as $Name => $Archive) {
592
           foreach ($this->Archives as $Name => $Archive) {

+ 30
- 16
classes/validate.class.php View File

180
      * ];
180
      * ];
181
      *
181
      *
182
      * Then it finds all the extensions in a torrent file list,
182
      * Then it finds all the extensions in a torrent file list,
183
-     * organizes them by file size, and returns the "heaviest" match.
183
+     * organizes them by file size, and returns the heaviest match.
184
      *
184
      *
185
      * That way, you can have, e.g., 5 GiB FASTQ sequence data in one file,
185
      * That way, you can have, e.g., 5 GiB FASTQ sequence data in one file,
186
      * and 100 other small files, and get the format of the actual data.
186
      * and 100 other small files, and get the format of the actual data.
187
      *
187
      *
188
-     * todo: Incorporate into the main function (remove if statements first)
188
+     * todo: Incorporate into $this->ValidateForm (remove if statements first)
189
      */
189
      */
190
     public function ParseExtensions($FileList, $Category, $FileTypes)
190
     public function ParseExtensions($FileList, $Category, $FileTypes)
191
     {
191
     {
192
-        # Make $Tor->file_list() output manageable
192
+        # Sort $Tor->file_list() output by size
193
         $UnNested = array_values($FileList[1]);
193
         $UnNested = array_values($FileList[1]);
194
         $Sorted = (usort($UnNested, function ($a, $b) {
194
         $Sorted = (usort($UnNested, function ($a, $b) {
195
-            return $b <=> $a; # Workaround because ↑ returns true
196
-        }) === true) ? $UnNested : null;
195
+            return $b <=> $a;
196
+        })) ? $UnNested : null;  # Ternary wrap because ↑ returns true
197
         
197
         
198
         # Harvest the wheat
198
         # Harvest the wheat
199
-        $TopTen = array_slice($Sorted, 0, 10);
200
-        $Match = null;
199
+        # todo: Entries seem duplicated here
200
+        $Heaviest = array_slice($Sorted, 0, 20);
201
+        $Matches = [];
201
 
202
 
202
-        do {
203
-            $Extensions = array_slice(explode('.', strtolower($TopTen[1])), -2, 2);
204
-            #array_shift(something)
205
-        } while ($i > 0);
203
+        foreach ($Heaviest as $Heaviest) {
204
+            # Collect the last 2 period-separated tokens
205
+            $Extensions = array_slice(explode('.', strtolower($Heaviest[1])), -2, 2);
206
+            $Matches = array_merge($Extensions);
206
 
207
 
207
-        print_r('<pre>');
208
-        print_r('===== RESULTS =====');
209
-        print_r($Matches);
210
-        print_r('</pre>');
208
+            # Distill the file format
209
+            $FileTypes = $FileTypes[$Category];
210
+            $FileTypeNames = array_keys($FileTypes);
211
 
211
 
212
-        # To be continued
212
+            # todo: Find the smallest possible number of iterations
213
+            # todo: Reduce nesting by one level
214
+            foreach ($Matches as $Match) {
215
+                $Match = strtolower($Match);
216
+        
217
+                foreach ($FileTypeNames as $FileTypeName) {
218
+                    $SearchMe = [ $FileTypeName, $FileTypes[$FileTypeName] ];
219
+        
220
+                    if (in_array($Match, $SearchMe[1])) {
221
+                        return $SearchMe[0];
222
+                        break;
223
+                    }
224
+                }
225
+            }
226
+        }
213
     }
227
     }
214
 
228
 
215
     public function GenerateJS($FormID)
229
     public function GenerateJS($FormID)

+ 247
- 180
sections/torrents/takeedit.php View File

1
-<?
1
+<?php
2
+
2
 //******************************************************************************//
3
 //******************************************************************************//
3
 //--------------- Take edit ----------------------------------------------------//
4
 //--------------- Take edit ----------------------------------------------------//
4
 // This pages handles the backend of the 'edit torrent' function. It checks     //
5
 // This pages handles the backend of the 'edit torrent' function. It checks     //
10
 authorize();
11
 authorize();
11
 
12
 
12
 require_once(SERVER_ROOT.'/classes/validate.class.php');
13
 require_once(SERVER_ROOT.'/classes/validate.class.php');
13
-
14
 $Validate = new Validate;
14
 $Validate = new Validate;
15
 
15
 
16
 //******************************************************************************//
16
 //******************************************************************************//
24
 $TypeID = (int)$_POST['type'];
24
 $TypeID = (int)$_POST['type'];
25
 $Type = $Categories[$TypeID-1];
25
 $Type = $Categories[$TypeID-1];
26
 $TorrentID = (int)$_POST['torrentid'];
26
 $TorrentID = (int)$_POST['torrentid'];
27
+
28
+# todo: Associate containers with categories beforehand
29
+# It may have to happen structurally in config.php, e.g.,
30
+# $Categories = [
31
+#   'GazelleName' => [$Name, $Icon, $Description, $Containers],
32
+#    ...
33
+#  ];
34
+$Properties['FileTypes'] = [
35
+  'DNA'      => $Containers,
36
+  'RNA'      => $Containers,
37
+  'Proteins' => $ContainersProt,
38
+  'Imaging'  => $ContainersGames,
39
+  'Extras'   => $ContainersExtra
40
+];
41
+$Properties['ArchiveTypes'] = [
42
+  'DNA'      => $Archives,
43
+  'RNA'      => $Archives,
44
+  'Proteins' => $Archives,
45
+  'Imaging'  => $Archives,
46
+  'Extras'   => $Archives
47
+];
48
+
27
 $Properties['Remastered'] = (isset($_POST['remaster']))? 1 : 0;
49
 $Properties['Remastered'] = (isset($_POST['remaster']))? 1 : 0;
28
 if ($Properties['Remastered']) {
50
 if ($Properties['Remastered']) {
29
-  $Properties['UnknownRelease'] = (isset($_POST['unknown'])) ? 1 : 0;
51
+    $Properties['UnknownRelease'] = (isset($_POST['unknown'])) ? 1 : 0;
30
 }
52
 }
31
 if (!$Properties['Remastered']) {
53
 if (!$Properties['Remastered']) {
32
-  $Properties['UnknownRelease'] = 0;
54
+    $Properties['UnknownRelease'] = 0;
33
 }
55
 }
56
+
34
 $Properties['BadTags'] = (isset($_POST['bad_tags']))? 1 : 0;
57
 $Properties['BadTags'] = (isset($_POST['bad_tags']))? 1 : 0;
35
 $Properties['BadFolders'] = (isset($_POST['bad_folders']))? 1 : 0;
58
 $Properties['BadFolders'] = (isset($_POST['bad_folders']))? 1 : 0;
36
 $Properties['BadFiles'] = (isset($_POST['bad_files'])) ? 1 : 0;
59
 $Properties['BadFiles'] = (isset($_POST['bad_files'])) ? 1 : 0;
60
+$Properties['Trumpable'] = (isset($_POST['make_trumpable'])) ? 1 : 0;
61
+
37
 $Properties['Format'] = $_POST['format'];
62
 $Properties['Format'] = $_POST['format'];
38
 $Properties['Media'] = $_POST['media'];
63
 $Properties['Media'] = $_POST['media'];
39
 $Properties['Bitrate'] = $_POST['bitrate'];
64
 $Properties['Bitrate'] = $_POST['bitrate'];
40
 $Properties['Encoding'] = $_POST['bitrate'];
65
 $Properties['Encoding'] = $_POST['bitrate'];
41
-$Properties['Trumpable'] = (isset($_POST['make_trumpable'])) ? 1 : 0;
42
 $Properties['TorrentDescription'] = $_POST['release_desc'];
66
 $Properties['TorrentDescription'] = $_POST['release_desc'];
43
 $Properties['MediaInfo'] = $_POST['mediainfo'];
67
 $Properties['MediaInfo'] = $_POST['mediainfo'];
44
 $Properties['Name'] = $_POST['title'];
68
 $Properties['Name'] = $_POST['title'];
49
 $Properties['Subbing'] = $_POST['sub'];
73
 $Properties['Subbing'] = $_POST['sub'];
50
 $Properties['Language'] = $_POST['lang'];
74
 $Properties['Language'] = $_POST['lang'];
51
 $Properties['Subber']= $_POST['subber'];
75
 $Properties['Subber']= $_POST['subber'];
76
+
52
 $Properties['Censored'] = (isset($_POST['censored'])) ? '1' : '0';
77
 $Properties['Censored'] = (isset($_POST['censored'])) ? '1' : '0';
53
 $Properties['Anonymous'] = (isset($_POST['anonymous'])) ? '1' : '0';
78
 $Properties['Anonymous'] = (isset($_POST['anonymous'])) ? '1' : '0';
54
 $Properties['Archive'] = (isset($_POST['archive']) && $_POST['archive'] != '---') ? $_POST['archive'] : '';
79
 $Properties['Archive'] = (isset($_POST['archive']) && $_POST['archive'] != '---') ? $_POST['archive'] : '';
55
 
80
 
56
 if ($_POST['album_desc']) {
81
 if ($_POST['album_desc']) {
57
-  $Properties['GroupDescription'] = $_POST['album_desc'];
82
+    $Properties['GroupDescription'] = $_POST['album_desc'];
58
 }
83
 }
84
+
59
 if (check_perms('torrents_freeleech')) {
85
 if (check_perms('torrents_freeleech')) {
60
-  $Free = (int)$_POST['freeleech'];
61
-  if (!in_array($Free, array(0, 1, 2))) {
62
-    error(404);
63
-  }
64
-  $Properties['FreeLeech'] = $Free;
65
-
66
-  if ($Free == 0) {
67
-    $FreeType = 0;
68
-  } else {
69
-    $FreeType = (int)$_POST['freeleechtype'];
70
-    if (!in_array($Free, array(0, 1, 2, 3))) {
71
-      error(404);
86
+    $Free = (int)$_POST['freeleech'];
87
+    if (!in_array($Free, array(0, 1, 2))) {
88
+        error(404);
72
     }
89
     }
73
-  }
74
-  $Properties['FreeLeechType'] = $FreeType;
90
+    $Properties['FreeLeech'] = $Free;
91
+
92
+    if ($Free === 0) {
93
+        $FreeType = 0;
94
+    } else {
95
+        $FreeType = (int)$_POST['freeleechtype'];
96
+        if (!in_array($Free, array(0, 1, 2, 3))) {
97
+            error(404);
98
+        }
99
+    }
100
+    $Properties['FreeLeechType'] = $FreeType;
75
 }
101
 }
76
 
102
 
77
 //******************************************************************************//
103
 //******************************************************************************//
83
   FROM torrents
109
   FROM torrents
84
   WHERE ID = $TorrentID");
110
   WHERE ID = $TorrentID");
85
 */
111
 */
112
+
86
 $DB->query("
113
 $DB->query("
87
   SELECT UserID, FreeTorrent
114
   SELECT UserID, FreeTorrent
88
   FROM torrents
115
   FROM torrents
89
   WHERE ID = $TorrentID");
116
   WHERE ID = $TorrentID");
117
+
90
 if (!$DB->has_results()) {
118
 if (!$DB->has_results()) {
91
-  error(404);
119
+    error(404);
92
 }
120
 }
121
+
93
 // list($UserID, $Remastered, $RemasterYear, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
122
 // list($UserID, $Remastered, $RemasterYear, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
94
 list($UserID, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
123
 list($UserID, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
95
 
124
 
96
 if ($LoggedUser['ID'] != $UserID && !check_perms('torrents_edit')) {
125
 if ($LoggedUser['ID'] != $UserID && !check_perms('torrents_edit')) {
97
-  error(403);
126
+    error(403);
98
 }
127
 }
99
 
128
 
100
-/*
101
-if ($Remastered == '1' && !$RemasterYear && !check_perms('edit_unknowns')) {
129
+/* todo: Check strict equality and untangle features
130
+if ($Remastered === '1' && !$RemasterYear && !check_perms('edit_unknowns')) {
102
   error(403);
131
   error(403);
103
 }
132
 }
104
 */
133
 */
105
 
134
 
106
-if ($Properties['UnknownRelease'] && !($Remastered == '1' && !$RemasterYear) && !check_perms('edit_unknowns')) {
107
-  //It's Unknown now, and it wasn't before
108
-  if ($LoggedUser['ID'] != $UserID) {
109
-    //Hax
110
-    die();
111
-  }
135
+if ($Properties['UnknownRelease'] && !($Remastered === '1' && !$RemasterYear) && !check_perms('edit_unknowns')) {
136
+    // It's Unknown now, and it wasn't before
137
+    if ($LoggedUser['ID'] !== $UserID) {
138
+        // Hax
139
+        die();
140
+    }
112
 }
141
 }
113
 
142
 
114
-$Validate->SetFields('type', '1', 'number', 'Not a valid type.', array('maxlength' => count($Categories), 'minlength' => 1));
143
+$Validate->SetFields(
144
+    'type',
145
+    '1',
146
+    'number',
147
+    'Not a valid type',
148
+    array('maxlength' => count($Categories), 'minlength' => 1)
149
+);
150
+
151
+/* Ugh
115
 switch ($Type) {
152
 switch ($Type) {
116
   case 'Music':
153
   case 'Music':
117
     if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease']) {
154
     if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease']) {
118
-      $Validate->SetFields('remaster_year', '1', 'number', 'Year of remaster/re-issue must be entered.');
155
+        $Validate->SetFields(
156
+            'remaster_year',
157
+            '1',
158
+            'number',
159
+            'Year of remaster/re-issue must be entered'
160
+        );
119
     } else {
161
     } else {
120
-      $Validate->SetFields('remaster_year', '0','number', 'Invalid remaster year.');
162
+        $Validate->SetFields(
163
+            'remaster_year',
164
+            '0',
165
+            'number',
166
+            'Invalid remaster year'
167
+        );
121
     }
168
     }
122
 
169
 
123
-    if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease'] && $Properties['RemasterYear'] < 1982 && $Properties['Media'] == 'CD') {
124
-      error('You have selected a year for an album that predates the medium you say it was created on.');
125
-      header("Location: torrents.php?action=edit&id=$TorrentID");
126
-      die();
127
-    }
128
-
129
-    $Validate->SetFields('remaster_title', '0', 'string', 'Remaster title must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
130
-
131
-    if ($Properties['RemasterTitle'] == 'Original Release') {
132
-      error('"Original Release" is not a valid remaster title.');
133
-      header("Location: torrents.php?action=edit&id=$TorrentID");
134
-      die();
170
+    if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease'] && $Properties['RemasterYear'] < 1982 && $Properties['Media'] === 'CD') {
171
+        error('You have selected a year for an album that predates the medium you say it was created on');
172
+        header("Location: torrents.php?action=edit&id=$TorrentID");
173
+        die();
135
     }
174
     }
136
 
175
 
137
-    $Validate->SetFields('remaster_record_label', '0', 'string', 'Remaster record label must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
138
-
139
-    $Validate->SetFields('remaster_catalogue_number', '0', 'string', 'Remaster catalogue number must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
140
-
141
-
142
-    $Validate->SetFields('format', '1', 'inarray', 'Not a valid format.', array('inarray' => $Formats));
143
-
144
-    $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
145
-
146
-
147
-    // Handle 'other' bitrates
148
-    if ($Properties['Encoding'] == 'Other') {
149
-      $Validate->SetFields('other_bitrate', '1', 'text', 'You must enter the other bitrate (max length: 9 characters).', array('maxlength' => 9));
150
-      $enc = trim($_POST['other_bitrate']);
151
-      if (isset($_POST['vbr'])) {
152
-        $enc .= ' (VBR)';
153
-      }
154
-
155
-      $Properties['Encoding'] = $enc;
156
-      $Properties['Bitrate'] = $enc;
157
-    } else {
158
-      $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
176
+    $Validate->SetFields(
177
+        'remaster_title',
178
+        '0',
179
+        'string',
180
+        'Remaster title must be between 2 and 80 characters',
181
+        array('maxlength' => 80, 'minlength' => 2)
182
+    );
183
+
184
+    if ($Properties['RemasterTitle'] === 'Original Release') {
185
+        error('"Original Release" is not a valid remaster title');
186
+        header("Location: torrents.php?action=edit&id=$TorrentID");
187
+        die();
159
     }
188
     }
160
 
189
 
161
-    $Validate->SetFields('media', '1', 'inarray', 'Not a valid media.', array('inarray' => $Media));
162
-
163
-    $Validate->SetFields('release_desc', '0', 'string', 'Invalid release description.', array('maxlength' => 1000000, 'minlength' => 0));
164
-
165
-    break;
166
-
167
-  case 'Audiobooks':
168
-  case 'Comedy':
169
-    /*$Validate->SetFields('title', '1', 'string', 'Title must be between 2 and 300 characters.', array('maxlength' => 300, 'minlength' => 2));
170
-    ^ this is commented out because there is no title field on these pages*/
171
-    $Validate->SetFields('year', '1', 'number', 'The year of the release must be entered.');
172
-
173
-    $Validate->SetFields('format', '1', 'inarray', 'Not a valid format.', array('inarray' => $Formats));
174
-
175
-    $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
190
+    $Validate->SetFields(
191
+        'remaster_record_label',
192
+        '0',
193
+        'string',
194
+        'Remaster record label must be between 2 and 80 characters',
195
+        array('maxlength' => 80, 'minlength' => 2)
196
+    );
197
+
198
+    $Validate->SetFields(
199
+        'remaster_catalogue_number',
200
+        '0',
201
+        'string',
202
+        'Remaster catalogue number must be between 2 and 80 characters',
203
+        array('maxlength' => 80, 'minlength' => 2)
204
+    );
205
+
206
+    $Validate->SetFields(
207
+        'format',
208
+        '1',
209
+        'inarray',
210
+        'Not a valid format',
211
+        array('inarray' => $Formats)
212
+    );
213
+
214
+    $Validate->SetFields(
215
+        'bitrate',
216
+        '1',
217
+        'inarray',
218
+        'You must choose a bitrate',
219
+        array('inarray' => $Bitrates)
220
+    );
176
 
221
 
177
 
222
 
178
     // Handle 'other' bitrates
223
     // Handle 'other' bitrates
179
-    if ($Properties['Encoding'] == 'Other') {
180
-      $Validate->SetFields('other_bitrate', '1', 'text', 'You must enter the other bitrate (max length: 9 characters).', array('maxlength' => 9));
181
-      $enc = trim($_POST['other_bitrate']);
182
-      if (isset($_POST['vbr'])) {
183
-        $enc .= ' (VBR)';
184
-      }
185
-
186
-      $Properties['Encoding'] = $enc;
187
-      $Properties['Bitrate'] = $enc;
224
+    if ($Properties['Encoding'] === 'Other') {
225
+        $Validate->SetFields(
226
+            'other_bitrate',
227
+            '1',
228
+            'text',
229
+            'You must enter the other bitrate (max length: 9 characters)',
230
+            array('maxlength' => 9)
231
+        );
232
+
233
+        $enc = trim($_POST['other_bitrate']);
234
+        if (isset($_POST['vbr'])) {
235
+            $enc .= ' (VBR)';
236
+        }
237
+
238
+        $Properties['Encoding'] = $enc;
239
+        $Properties['Bitrate'] = $enc;
188
     } else {
240
     } else {
189
-      $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
241
+        $Validate->SetFields(
242
+            'bitrate',
243
+            '1',
244
+            'inarray',
245
+            'You must choose a bitrate',
246
+            array('inarray' => $Bitrates)
247
+        );
190
     }
248
     }
191
 
249
 
192
-    $Validate->SetFields('release_desc', '0', 'string', 'The release description has a minimum length of 10 characters.', array('maxlength' => 1000000, 'minlength' => 10));
193
-
250
+    $Validate->SetFields(
251
+        'media',
252
+        '1',
253
+        'inarray',
254
+        'Not a valid media',
255
+        array('inarray' => $Media)
256
+    );
257
+
258
+    $Validate->SetFields(
259
+        'release_desc',
260
+        '0',
261
+        'string',
262
+        'Invalid release description',
263
+        array('maxlength' => 1000000, 'minlength' => 0)
264
+    );
194
     break;
265
     break;
195
 
266
 
196
-  case 'Applications':
197
-  case 'Comics':
198
-  case 'E-Books':
199
-  case 'E-Learning Videos':
200
-    /*$Validate->SetFields('title', '1', 'string', 'Title must be between 2 and 300 characters.', array('maxlength' => 300, 'minlength' => 2));
201
-      ^ this is commented out because there is no title field on these pages*/
267
+  default:
202
     break;
268
     break;
203
 }
269
 }
270
+*/
204
 
271
 
205
 $Err = $Validate->ValidateForm($_POST); // Validate the form
272
 $Err = $Validate->ValidateForm($_POST); // Validate the form
206
 
273
 
207
 if ($Properties['Remastered'] && !$Properties['RemasterYear']) {
274
 if ($Properties['Remastered'] && !$Properties['RemasterYear']) {
208
-  //Unknown Edit!
209
-  if ($LoggedUser['ID'] == $UserID || check_perms('edit_unknowns')) {
210
-    //Fine!
211
-  } else {
212
-    $Err = "You may not edit someone else's upload to unknown release.";
213
-  }
275
+    // Unknown Edit!
276
+    if ($LoggedUser['ID'] === $UserID || check_perms('edit_unknowns')) {
277
+        // Fine!
278
+    } else {
279
+        $Err = "You may not edit someone else's upload to unknown release";
280
+    }
214
 }
281
 }
215
 
282
 
216
 // Strip out Amazon's padding
283
 // Strip out Amazon's padding
284
+/*
217
 $AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
285
 $AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
218
 $Matches = [];
286
 $Matches = [];
219
 if (preg_match($RegX, $Properties['Image'], $Matches)) {
287
 if (preg_match($RegX, $Properties['Image'], $Matches)) {
220
-  $Properties['Image'] = $Matches[1].'.jpg';
288
+    $Properties['Image'] = $Matches[1].'.jpg';
221
 }
289
 }
222
 ImageTools::blacklisted($Properties['Image']);
290
 ImageTools::blacklisted($Properties['Image']);
291
+*/
223
 
292
 
224
 if ($Err) { // Show the upload form, with the data the user entered
293
 if ($Err) { // Show the upload form, with the data the user entered
225
-  if (check_perms('site_debug')) {
226
-    die($Err);
227
-  }
228
-  error($Err);
294
+    if (check_perms('site_debug')) {
295
+        die($Err);
296
+    }
297
+    error($Err);
229
 }
298
 }
230
 
299
 
231
-
232
 //******************************************************************************//
300
 //******************************************************************************//
233
 //--------------- Make variables ready for database input ----------------------//
301
 //--------------- Make variables ready for database input ----------------------//
234
 
302
 
235
 // Shorten and escape $Properties for database input
303
 // Shorten and escape $Properties for database input
236
 $T = [];
304
 $T = [];
237
 foreach ($Properties as $Key => $Value) {
305
 foreach ($Properties as $Key => $Value) {
238
-  $T[$Key] = "'".db_string(trim($Value))."'";
239
-  if (!$T[$Key]) {
240
-    $T[$Key] = null;
241
-  }
306
+    $T[$Key] = "'".db_string(trim($Value))."'";
307
+    if (!$T[$Key]) {
308
+        $T[$Key] = null;
309
+    }
242
 }
310
 }
243
 
311
 
244
 $T['Censored'] = $Properties['Censored'];
312
 $T['Censored'] = $Properties['Censored'];
257
 $DBTorVals = $DBTorVals[0];
325
 $DBTorVals = $DBTorVals[0];
258
 $LogDetails = '';
326
 $LogDetails = '';
259
 foreach ($DBTorVals as $Key => $Value) {
327
 foreach ($DBTorVals as $Key => $Value) {
260
-  $Value = "'$Value'";
261
-  if ($Value != $T[$Key]) {
262
-    if (!isset($T[$Key])) {
263
-      continue;
264
-    }
265
-    if ((empty($Value) && empty($T[$Key])) || ($Value == "'0'" && $T[$Key] == "''")) {
266
-      continue;
267
-    }
268
-    if ($LogDetails == '') {
269
-      $LogDetails = "$Key: $Value -> ".$T[$Key];
270
-    } else {
271
-      $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
328
+    $Value = "'$Value'";
329
+    if ($Value != $T[$Key]) {
330
+        if (!isset($T[$Key])) {
331
+            continue;
332
+        }
333
+        if ((empty($Value) && empty($T[$Key])) || ($Value == "'0'" && $T[$Key] == "''")) {
334
+            continue;
335
+        }
336
+        if ($LogDetails == '') {
337
+            $LogDetails = "$Key: $Value -> ".$T[$Key];
338
+        } else {
339
+            $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
340
+        }
272
     }
341
     }
273
-  }
274
 }
342
 }
275
 $T['Censored'] = $Properties['Censored'];
343
 $T['Censored'] = $Properties['Censored'];
276
 $T['Anonymous'] = $Properties['Anonymous'];
344
 $T['Anonymous'] = $Properties['Anonymous'];
308
     Anonymous = $T[Anonymous],";
376
     Anonymous = $T[Anonymous],";
309
 
377
 
310
 if (check_perms('torrents_freeleech')) {
378
 if (check_perms('torrents_freeleech')) {
311
-  $SQL .= "FreeTorrent = $T[FreeLeech],";
312
-  $SQL .= "FreeLeechType = $T[FreeLeechType],";
379
+    $SQL .= "FreeTorrent = $T[FreeLeech],";
380
+    $SQL .= "FreeLeechType = $T[FreeLeechType],";
313
 }
381
 }
314
 
382
 
315
 if (check_perms('users_mod')) {
383
 if (check_perms('users_mod')) {
316
-/*  if ($T[Format] != "'FLAC'") {
317
-    $SQL .= "
318
-      HasLog = '0',
319
-      HasCue = '0',";
320
-  } else {
321
-    $SQL .= "
322
-      HasLog = $T[HasLog],
323
-      HasCue = $T[HasCue],";
324
-  }
325
-*/
326
-  $DB->query("
384
+    /*  if ($T[Format] != "'FLAC'") {
385
+        $SQL .= "
386
+          HasLog = '0',
387
+          HasCue = '0',";
388
+      } else {
389
+        $SQL .= "
390
+          HasLog = $T[HasLog],
391
+          HasCue = $T[HasCue],";
392
+      }
393
+    */
394
+    $DB->query("
327
     SELECT TorrentID
395
     SELECT TorrentID
328
     FROM torrents_bad_tags
396
     FROM torrents_bad_tags
329
     WHERE TorrentID = '$TorrentID'");
397
     WHERE TorrentID = '$TorrentID'");
330
-  list($btID) = $DB->next_record();
398
+    list($btID) = $DB->next_record();
331
 
399
 
332
-  if (!$btID && $Properties['BadTags']) {
333
-    $DB->query("
400
+    if (!$btID && $Properties['BadTags']) {
401
+        $DB->query("
334
       INSERT INTO torrents_bad_tags
402
       INSERT INTO torrents_bad_tags
335
       VALUES ($TorrentID, $LoggedUser[ID], NOW())");
403
       VALUES ($TorrentID, $LoggedUser[ID], NOW())");
336
-  }
337
-  if ($btID && !$Properties['BadTags']) {
338
-    $DB->query("
404
+    }
405
+    if ($btID && !$Properties['BadTags']) {
406
+        $DB->query("
339
       DELETE FROM torrents_bad_tags
407
       DELETE FROM torrents_bad_tags
340
       WHERE TorrentID = '$TorrentID'");
408
       WHERE TorrentID = '$TorrentID'");
341
-  }
409
+    }
342
 
410
 
343
-  $DB->query("
411
+    $DB->query("
344
     SELECT TorrentID
412
     SELECT TorrentID
345
     FROM torrents_bad_folders
413
     FROM torrents_bad_folders
346
     WHERE TorrentID = '$TorrentID'");
414
     WHERE TorrentID = '$TorrentID'");
347
-  list($bfID) = $DB->next_record();
415
+    list($bfID) = $DB->next_record();
348
 
416
 
349
-  if (!$bfID && $Properties['BadFolders']) {
350
-    $DB->query("
417
+    if (!$bfID && $Properties['BadFolders']) {
418
+        $DB->query("
351
       INSERT INTO torrents_bad_folders
419
       INSERT INTO torrents_bad_folders
352
       VALUES ($TorrentID, $LoggedUser[ID], NOW())");
420
       VALUES ($TorrentID, $LoggedUser[ID], NOW())");
353
-  }
354
-  if ($bfID && !$Properties['BadFolders']) {
355
-    $DB->query("
421
+    }
422
+    if ($bfID && !$Properties['BadFolders']) {
423
+        $DB->query("
356
       DELETE FROM torrents_bad_folders
424
       DELETE FROM torrents_bad_folders
357
       WHERE TorrentID = '$TorrentID'");
425
       WHERE TorrentID = '$TorrentID'");
358
-  }
426
+    }
359
 
427
 
360
-  $DB->query("
428
+    $DB->query("
361
     SELECT TorrentID
429
     SELECT TorrentID
362
     FROM torrents_bad_files
430
     FROM torrents_bad_files
363
     WHERE TorrentID = '$TorrentID'");
431
     WHERE TorrentID = '$TorrentID'");
364
-  list($bfiID) = $DB->next_record();
432
+    list($bfiID) = $DB->next_record();
365
 
433
 
366
-  if (!$bfiID && $Properties['BadFiles']) {
367
-    $DB->query("
434
+    if (!$bfiID && $Properties['BadFiles']) {
435
+        $DB->query("
368
       INSERT INTO torrents_bad_files
436
       INSERT INTO torrents_bad_files
369
       VALUES ($TorrentID, $LoggedUser[ID], NOW())");
437
       VALUES ($TorrentID, $LoggedUser[ID], NOW())");
370
-  }
371
-  if ($bfiID && !$Properties['BadFiles']) {
372
-    $DB->query("
438
+    }
439
+    if ($bfiID && !$Properties['BadFiles']) {
440
+        $DB->query("
373
       DELETE FROM torrents_bad_files
441
       DELETE FROM torrents_bad_files
374
       WHERE TorrentID = '$TorrentID'");
442
       WHERE TorrentID = '$TorrentID'");
375
-  }
443
+    }
376
 
444
 
377
-  $DB->query("
445
+    $DB->query("
378
     SELECT TorrentID
446
     SELECT TorrentID
379
     FROM library_contest
447
     FROM library_contest
380
     WHERE TorrentID = '$TorrentID'");
448
     WHERE TorrentID = '$TorrentID'");
381
-  list($lbID) = $DB->next_record();
382
-  if (!$lbID && $Properties['LibraryUpload'] && $Properties['LibraryPoints'] > 0) {
383
-    $DB->query("
449
+    list($lbID) = $DB->next_record();
450
+    if (!$lbID && $Properties['LibraryUpload'] && $Properties['LibraryPoints'] > 0) {
451
+        $DB->query("
384
       SELECT UserID
452
       SELECT UserID
385
       FROM torrents
453
       FROM torrents
386
       WHERE ID = $TorrentID");
454
       WHERE ID = $TorrentID");
387
-    list($UploaderID) = $DB->next_record();
388
-    $DB->query("
455
+        list($UploaderID) = $DB->next_record();
456
+        $DB->query("
389
       INSERT INTO library_contest
457
       INSERT INTO library_contest
390
       VALUES ($UploaderID, $TorrentID, $Properties[LibraryPoints])");
458
       VALUES ($UploaderID, $TorrentID, $Properties[LibraryPoints])");
391
-  }
392
-  if ($lbID && !$Properties['LibraryUpload']) {
393
-    $DB->query("
459
+    }
460
+    if ($lbID && !$Properties['LibraryUpload']) {
461
+        $DB->query("
394
       DELETE FROM library_contest
462
       DELETE FROM library_contest
395
       WHERE TorrentID = '$TorrentID'");
463
       WHERE TorrentID = '$TorrentID'");
396
-  }
464
+    }
397
 }
465
 }
398
 
466
 
399
 $SQL .= "
467
 $SQL .= "
402
 $DB->query($SQL);
470
 $DB->query($SQL);
403
 
471
 
404
 if (check_perms('torrents_freeleech') && $Properties['FreeLeech'] != $CurFreeLeech) {
472
 if (check_perms('torrents_freeleech') && $Properties['FreeLeech'] != $CurFreeLeech) {
405
-  Torrents::freeleech_torrents($TorrentID, $Properties['FreeLeech'], $Properties['FreeLeechType']);
473
+    Torrents::freeleech_torrents($TorrentID, $Properties['FreeLeech'], $Properties['FreeLeechType']);
406
 }
474
 }
407
 
475
 
408
 $DB->query("
476
 $DB->query("
413
 
481
 
414
 // Competition
482
 // Competition
415
 if (strtotime($Time) > 1241352173) {
483
 if (strtotime($Time) > 1241352173) {
416
-  if ($_POST['log_score'] == '100') {
417
-    $DB->query("
484
+    if ($_POST['log_score'] == '100') {
485
+        $DB->query("
418
       INSERT IGNORE into users_points (GroupID, UserID, Points)
486
       INSERT IGNORE into users_points (GroupID, UserID, Points)
419
       VALUES ('$GroupID', '$UserID', '1')");
487
       VALUES ('$GroupID', '$UserID', '1')");
420
-  }
488
+    }
421
 }
489
 }
422
 // End competiton
490
 // End competiton
423
 
491
 
442
 // All done!
510
 // All done!
443
 
511
 
444
 header("Location: torrents.php?id=$GroupID");
512
 header("Location: torrents.php?id=$GroupID");
445
-?>

+ 12
- 6
sections/upload/upload_handle.php View File

47
 #   'GazelleName' => [$Name, $Icon, $Description, $Containers],
47
 #   'GazelleName' => [$Name, $Icon, $Description, $Containers],
48
 #    ...
48
 #    ...
49
 #  ];
49
 #  ];
50
-$Properties['ArchiveTypes'] = $Archives;
51
 $Properties['FileTypes'] = [
50
 $Properties['FileTypes'] = [
52
     'DNA'      => $Containers,
51
     'DNA'      => $Containers,
53
     'RNA'      => $Containers,
52
     'RNA'      => $Containers,
55
     'Imaging'  => $ContainersGames,
54
     'Imaging'  => $ContainersGames,
56
     'Extras'   => $ContainersExtra
55
     'Extras'   => $ContainersExtra
57
 ];
56
 ];
57
+$Properties['ArchiveTypes'] = [
58
+    'DNA'      => $Archives,
59
+    'RNA'      => $Archives,
60
+    'Proteins' => $Archives,
61
+    'Imaging'  => $Archives,
62
+    'Extras'   => $Archives
63
+];
58
 
64
 
59
 $Properties['Title'] = $_POST['title'];
65
 $Properties['Title'] = $_POST['title'];
60
 $Properties['TitleRJ'] = $_POST['title_rj'];
66
 $Properties['TitleRJ'] = $_POST['title_rj'];
423
 
429
 
424
 if ($T['Container'] === 'Autofill') {
430
 if ($T['Container'] === 'Autofill') {
425
     # torrents.Container
431
     # torrents.Container
426
-    $Validate->ParseExtensions(
432
+    $T['Container'] = $Validate->ParseExtensions(
433
+
427
         # $FileList
434
         # $FileList
428
         $Tor->file_list(),
435
         $Tor->file_list(),
429
 
436
 
436
 }
443
 }
437
 
444
 
438
 if ($T['Archive'] === 'Autofill') {
445
 if ($T['Archive'] === 'Autofill') {
439
-    /*
440
     # torrents.Archive
446
     # torrents.Archive
441
-    $Validate->ParseExtensions(
447
+    $T['Archive'] = $Validate->ParseExtensions(
448
+
442
         # $FileList
449
         # $FileList
443
         $Tor->file_list(),
450
         $Tor->file_list(),
444
 
451
 
446
         $T['CategoryName'],
453
         $T['CategoryName'],
447
 
454
 
448
         # $FileTypes
455
         # $FileTypes
449
-        $T['FileTypes'],
456
+        $T['ArchiveTypes'],
450
     );
457
     );
451
-    */
452
 }
458
 }
453
 
459
 
454
 //******************************************************************************//
460
 //******************************************************************************//

Loading…
Cancel
Save