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

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

@@ -15,51 +15,49 @@ class Validate
15 15
      * ];
16 16
      *
17 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 20
      * That way, you can have, e.g., 5 GiB FASTQ sequence data in one file,
21 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 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 28
         $UnNested = array_values($FileList[1]);
29 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 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,6 +22,7 @@ $Properties['Containers'] = [
22 22
 //--------------- Autofill format and archive ----------------------------------//
23 23
 
24 24
 if ($T['Container'] === 'Autofill') {
25
+
25 26
     # torrents.Container
26 27
     $Validate->ParseExtensions(
27 28
         # $FileList
@@ -36,7 +37,7 @@ if ($T['Container'] === 'Autofill') {
36 37
 }
37 38
 
38 39
 if ($T['Archive'] === 'Autofill') {
39
-    /*
40
+
40 41
     # torrents.Archive
41 42
     $Validate->ParseExtensions(
42 43
         # $FileList
@@ -48,6 +49,5 @@ if ($T['Archive'] === 'Autofill') {
48 49
         # $FileTypes
49 50
         $T['FileTypes'],
50 51
     );
51
-    */
52 52
 }
53 53
 # Line 452

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

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

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

@@ -180,36 +180,50 @@ class Validate
180 180
      * ];
181 181
      *
182 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 185
      * That way, you can have, e.g., 5 GiB FASTQ sequence data in one file,
186 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 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 193
         $UnNested = array_values($FileList[1]);
194 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 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 229
     public function GenerateJS($FormID)

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

@@ -1,4 +1,5 @@
1
-<?
1
+<?php
2
+
2 3
 //******************************************************************************//
3 4
 //--------------- Take edit ----------------------------------------------------//
4 5
 // This pages handles the backend of the 'edit torrent' function. It checks     //
@@ -10,7 +11,6 @@ enforce_login();
10 11
 authorize();
11 12
 
12 13
 require_once(SERVER_ROOT.'/classes/validate.class.php');
13
-
14 14
 $Validate = new Validate;
15 15
 
16 16
 //******************************************************************************//
@@ -24,21 +24,45 @@ $_POST['type'] = $_POST['type'] + 1;
24 24
 $TypeID = (int)$_POST['type'];
25 25
 $Type = $Categories[$TypeID-1];
26 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 49
 $Properties['Remastered'] = (isset($_POST['remaster']))? 1 : 0;
28 50
 if ($Properties['Remastered']) {
29
-  $Properties['UnknownRelease'] = (isset($_POST['unknown'])) ? 1 : 0;
51
+    $Properties['UnknownRelease'] = (isset($_POST['unknown'])) ? 1 : 0;
30 52
 }
31 53
 if (!$Properties['Remastered']) {
32
-  $Properties['UnknownRelease'] = 0;
54
+    $Properties['UnknownRelease'] = 0;
33 55
 }
56
+
34 57
 $Properties['BadTags'] = (isset($_POST['bad_tags']))? 1 : 0;
35 58
 $Properties['BadFolders'] = (isset($_POST['bad_folders']))? 1 : 0;
36 59
 $Properties['BadFiles'] = (isset($_POST['bad_files'])) ? 1 : 0;
60
+$Properties['Trumpable'] = (isset($_POST['make_trumpable'])) ? 1 : 0;
61
+
37 62
 $Properties['Format'] = $_POST['format'];
38 63
 $Properties['Media'] = $_POST['media'];
39 64
 $Properties['Bitrate'] = $_POST['bitrate'];
40 65
 $Properties['Encoding'] = $_POST['bitrate'];
41
-$Properties['Trumpable'] = (isset($_POST['make_trumpable'])) ? 1 : 0;
42 66
 $Properties['TorrentDescription'] = $_POST['release_desc'];
43 67
 $Properties['MediaInfo'] = $_POST['mediainfo'];
44 68
 $Properties['Name'] = $_POST['title'];
@@ -49,29 +73,31 @@ $Properties['AudioFormat'] = $_POST['audioformat'];
49 73
 $Properties['Subbing'] = $_POST['sub'];
50 74
 $Properties['Language'] = $_POST['lang'];
51 75
 $Properties['Subber']= $_POST['subber'];
76
+
52 77
 $Properties['Censored'] = (isset($_POST['censored'])) ? '1' : '0';
53 78
 $Properties['Anonymous'] = (isset($_POST['anonymous'])) ? '1' : '0';
54 79
 $Properties['Archive'] = (isset($_POST['archive']) && $_POST['archive'] != '---') ? $_POST['archive'] : '';
55 80
 
56 81
 if ($_POST['album_desc']) {
57
-  $Properties['GroupDescription'] = $_POST['album_desc'];
82
+    $Properties['GroupDescription'] = $_POST['album_desc'];
58 83
 }
84
+
59 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,162 +109,204 @@ $DB->query("
83 109
   FROM torrents
84 110
   WHERE ID = $TorrentID");
85 111
 */
112
+
86 113
 $DB->query("
87 114
   SELECT UserID, FreeTorrent
88 115
   FROM torrents
89 116
   WHERE ID = $TorrentID");
117
+
90 118
 if (!$DB->has_results()) {
91
-  error(404);
119
+    error(404);
92 120
 }
121
+
93 122
 // list($UserID, $Remastered, $RemasterYear, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
94 123
 list($UserID, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
95 124
 
96 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 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 152
 switch ($Type) {
116 153
   case 'Music':
117 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 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 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 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 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 268
     break;
203 269
 }
270
+*/
204 271
 
205 272
 $Err = $Validate->ValidateForm($_POST); // Validate the form
206 273
 
207 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 283
 // Strip out Amazon's padding
284
+/*
217 285
 $AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
218 286
 $Matches = [];
219 287
 if (preg_match($RegX, $Properties['Image'], $Matches)) {
220
-  $Properties['Image'] = $Matches[1].'.jpg';
288
+    $Properties['Image'] = $Matches[1].'.jpg';
221 289
 }
222 290
 ImageTools::blacklisted($Properties['Image']);
291
+*/
223 292
 
224 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 301
 //--------------- Make variables ready for database input ----------------------//
234 302
 
235 303
 // Shorten and escape $Properties for database input
236 304
 $T = [];
237 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 312
 $T['Censored'] = $Properties['Censored'];
@@ -257,20 +325,20 @@ $DBTorVals = $DB->to_array(false, MYSQLI_ASSOC);
257 325
 $DBTorVals = $DBTorVals[0];
258 326
 $LogDetails = '';
259 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 343
 $T['Censored'] = $Properties['Censored'];
276 344
 $T['Anonymous'] = $Properties['Anonymous'];
@@ -308,92 +376,92 @@ $SQL = "
308 376
     Anonymous = $T[Anonymous],";
309 377
 
310 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 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 395
     SELECT TorrentID
328 396
     FROM torrents_bad_tags
329 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 402
       INSERT INTO torrents_bad_tags
335 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 407
       DELETE FROM torrents_bad_tags
340 408
       WHERE TorrentID = '$TorrentID'");
341
-  }
409
+    }
342 410
 
343
-  $DB->query("
411
+    $DB->query("
344 412
     SELECT TorrentID
345 413
     FROM torrents_bad_folders
346 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 419
       INSERT INTO torrents_bad_folders
352 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 424
       DELETE FROM torrents_bad_folders
357 425
       WHERE TorrentID = '$TorrentID'");
358
-  }
426
+    }
359 427
 
360
-  $DB->query("
428
+    $DB->query("
361 429
     SELECT TorrentID
362 430
     FROM torrents_bad_files
363 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 436
       INSERT INTO torrents_bad_files
369 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 441
       DELETE FROM torrents_bad_files
374 442
       WHERE TorrentID = '$TorrentID'");
375
-  }
443
+    }
376 444
 
377
-  $DB->query("
445
+    $DB->query("
378 446
     SELECT TorrentID
379 447
     FROM library_contest
380 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 452
       SELECT UserID
385 453
       FROM torrents
386 454
       WHERE ID = $TorrentID");
387
-    list($UploaderID) = $DB->next_record();
388
-    $DB->query("
455
+        list($UploaderID) = $DB->next_record();
456
+        $DB->query("
389 457
       INSERT INTO library_contest
390 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 462
       DELETE FROM library_contest
395 463
       WHERE TorrentID = '$TorrentID'");
396
-  }
464
+    }
397 465
 }
398 466
 
399 467
 $SQL .= "
@@ -402,7 +470,7 @@ $SQL .= "
402 470
 $DB->query($SQL);
403 471
 
404 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 476
 $DB->query("
@@ -413,11 +481,11 @@ list($GroupID, $Time) = $DB->next_record();
413 481
 
414 482
 // Competition
415 483
 if (strtotime($Time) > 1241352173) {
416
-  if ($_POST['log_score'] == '100') {
417
-    $DB->query("
484
+    if ($_POST['log_score'] == '100') {
485
+        $DB->query("
418 486
       INSERT IGNORE into users_points (GroupID, UserID, Points)
419 487
       VALUES ('$GroupID', '$UserID', '1')");
420
-  }
488
+    }
421 489
 }
422 490
 // End competiton
423 491
 
@@ -442,4 +510,3 @@ Torrents::update_hash($GroupID);
442 510
 // All done!
443 511
 
444 512
 header("Location: torrents.php?id=$GroupID");
445
-?>

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

@@ -47,7 +47,6 @@ $Properties['CategoryName'] = $Type;
47 47
 #   'GazelleName' => [$Name, $Icon, $Description, $Containers],
48 48
 #    ...
49 49
 #  ];
50
-$Properties['ArchiveTypes'] = $Archives;
51 50
 $Properties['FileTypes'] = [
52 51
     'DNA'      => $Containers,
53 52
     'RNA'      => $Containers,
@@ -55,6 +54,13 @@ $Properties['FileTypes'] = [
55 54
     'Imaging'  => $ContainersGames,
56 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 65
 $Properties['Title'] = $_POST['title'];
60 66
 $Properties['TitleRJ'] = $_POST['title_rj'];
@@ -423,7 +429,8 @@ if (!empty($Err)) { // Show the upload form, with the data the user entered
423 429
 
424 430
 if ($T['Container'] === 'Autofill') {
425 431
     # torrents.Container
426
-    $Validate->ParseExtensions(
432
+    $T['Container'] = $Validate->ParseExtensions(
433
+
427 434
         # $FileList
428 435
         $Tor->file_list(),
429 436
 
@@ -436,9 +443,9 @@ if ($T['Container'] === 'Autofill') {
436 443
 }
437 444
 
438 445
 if ($T['Archive'] === 'Autofill') {
439
-    /*
440 446
     # torrents.Archive
441
-    $Validate->ParseExtensions(
447
+    $T['Archive'] = $Validate->ParseExtensions(
448
+
442 449
         # $FileList
443 450
         $Tor->file_list(),
444 451
 
@@ -446,9 +453,8 @@ if ($T['Archive'] === 'Autofill') {
446 453
         $T['CategoryName'],
447 454
 
448 455
         # $FileTypes
449
-        $T['FileTypes'],
456
+        $T['ArchiveTypes'],
450 457
     );
451
-    */
452 458
 }
453 459
 
454 460
 //******************************************************************************//

Loading…
Cancel
Save