Browse Source

Bring the Extension Parser package up to speed

pjc 5 years ago
parent
commit
d73c18dcda

+ 8
- 5
_packages/extension-parser/classes/config.php View File

@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3
-# Line 224
3
+# Line 222
4 4
 # Sequencing Formats
5 5
 #
6 6
 # https://www.ncbi.nlm.nih.gov/sra/docs/submitformats/
@@ -25,6 +25,7 @@ $Containers = [
25 25
   'SwissProt'  => ['dat'],
26 26
   'VCF'        => ['vcf'],
27 27
   'Plain'      => ['csv', 'txt'],
28
+  'Other'      => [],
28 29
 ];
29 30
 
30 31
 # Imaging Formats
@@ -41,7 +42,7 @@ $ContainersGames = [
41 42
   'PNG'       => ['png'],
42 43
   'TIFF'      => ['tif', 'tiff'],
43 44
   'WebP'      => ['webp'],
44
-  'Other'     => [''],
45
+  'Other'     => [],
45 46
 ];
46 47
 
47 48
 # Protein Formats
@@ -75,6 +76,7 @@ $ContainersProt = [
75 76
   'TraML'          => ['traml'],
76 77
   'ULVAC-PHI'      => ['tdc'],
77 78
   'Plain'          => ['csv', 'txt'],
79
+  'Other'          => [],
78 80
 ];
79 81
 
80 82
 # Extra Formats
@@ -96,7 +98,8 @@ $ContainersExtra = [
96 98
   'Excel'            => ['xls', 'xlt', 'xlm', 'xlsx', 'xlsm', 'xltx', 'xltm', 'xlsb', 'xla', 'xlam', 'xll', 'xlw'],
97 99
   'PowerPoint'       => ['ppt', 'pot', 'pps', 'pptx', 'pptm', 'potx', 'potm', 'ppam', 'ppsx', 'ppsm', 'sldx', 'sldm'],
98 100
   'PDF'              => ['pdf', 'fdf', 'xfdf'],
99
-  'Other'            => [''],
101
+  'Plain'            => ['csv', 'txt'],
102
+  'Other'            => [],
100 103
 ];
101 104
 
102 105
 $Archives = [
@@ -106,6 +109,6 @@ $Archives = [
106 109
   'Pickle'   => ['pickle', 'pkl'],
107 110
   'RAR'      => ['rar', 'rev'],
108 111
   'ZIP'      => ['zip', 'zipx'],
109
-  'None'     => [''],
112
+  'None'     => [],
110 113
 ];
111
-# Line 330
114
+# Line 331

+ 78
- 12
_packages/extension-parser/classes/torrent_form.class.php View File

@@ -1,6 +1,26 @@
1
-<?php ?>
1
+<?php
2 2
 
3
-<!-- Three container fields -->
3
+class TorrentForm
4
+{
5
+    # Line 13
6
+    public $Containers = [];
7
+    public $ContainersGames = [];
8
+    public $ContainersProt = [];
9
+    public $ContainersExtra = [];
10
+    # Line 16
11
+
12
+    public function __construct($Torrent = false, $Error = false, $NewTorrent = true)
13
+    {
14
+        # Line 45
15
+        $this->Containers = $Containers;
16
+        $this->ContainersGames = $ContainersGames;
17
+        $this->ContainersProt = $ContainersProt;
18
+        $this->ContainersExtra = $ContainersExtra;
19
+        # Line 48
20
+?>
21
+
22
+<!-- Line 510 -->
23
+<!-- Multiple container fields -->
4 24
 <tr id="container_tr">
5 25
   <td class="label">
6 26
     Format
@@ -8,11 +28,12 @@
8 28
   </td>
9 29
   <td>
10 30
     <select name="container">
31
+      <option value="">---</option>
11 32
       <option value="Autofill">Autofill</option>
12 33
       <?php
13
-          foreach ($this->Containers as $Name => $Container) {
14
-              echo "<option value='$Name'>$Name</option>\n";
15
-          } ?>
34
+        foreach ($this->Containers as $Name => $Container) {
35
+            echo "<option value='$Name'>$Name</option>\n";
36
+        } ?>
16 37
     </select><br />
17 38
     Data file format, or detect from file list
18 39
   </td>
@@ -26,11 +47,12 @@
26 47
   </td>
27 48
   <td>
28 49
     <select id="container" name="container">
50
+      <option value="">---</option>
29 51
       <option value="Autofill">Autofill</option>
30 52
       <?php
31
-          foreach ($this->ContainersGames as $Name => $Container) {
32
-              echo "<option value='$Name'>$Name</option>\n";
33
-          } ?>
53
+        foreach ($this->ContainersGames as $Name => $Container) {
54
+            echo "<option value='$Name'>$Name</option>\n";
55
+        } ?>
34 56
     </select><br />
35 57
     Data file format, or detect from file list
36 58
   </td>
@@ -44,12 +66,56 @@
44 66
   </td>
45 67
   <td>
46 68
     <select id="container" name="container">
69
+      <option value="">---</option>
70
+      <option value="Autofill">Autofill</option>
71
+      <?php
72
+        foreach ($this->ContainersProt as $Name => $Container) {
73
+            echo "<option value='$Name'>$Name</option>\n";
74
+        } ?>
75
+    </select><br />
76
+    Data file format, or detect from file list
77
+  </td>
78
+</tr>
79
+
80
+<!-- 4 -->
81
+<tr id="container_extra_tr">
82
+  <td class="label">
83
+    Format
84
+    <strong class="important_text">*</strong>
85
+  </td>
86
+  <td>
87
+    <select id="container" name="container">
88
+      <option value="">---</option>
47 89
       <option value="Autofill">Autofill</option>
48 90
       <?php
49
-          foreach ($this->ContainersProt as $Name => $Container) {
50
-              echo "<option value='$Name'>$Name</option>\n";
51
-          } ?>
91
+        foreach ($this->ContainersExtra as $Name => $Container) {
92
+            echo "<option value='$Name'>$Name</option>\n";
93
+        } ?>
52 94
     </select><br />
53 95
     Data file format, or detect from file list
54 96
   </td>
55
-</tr>
97
+</tr>
98
+
99
+<!-- Compression -->
100
+<tr id="archive_tr">
101
+  <td class="label">
102
+    Archive
103
+    <strong class="important_text">*</strong>
104
+  </td>
105
+  <td>
106
+    <select name='archive'>
107
+      <option value="">---</option>
108
+      <option value="Autofill">Autofill</option>
109
+      <?php
110
+        foreach ($this->Archives as $Name => $Archive) {
111
+            echo "\t\t\t\t\t\t<option value=\"$Name\"";
112
+            if ($Archive === ($Torrent['Archive'] ?? false)) {
113
+                echo ' selected';
114
+            }
115
+            echo ">$Name</option>\n";
116
+        } ?>
117
+    </select><br />
118
+    Compression algorithm, or detect from file list
119
+  </td>
120
+</tr>
121
+<!-- Line 607 -->

+ 65
- 0
_packages/extension-parser/classes/validate.class.php View File

@@ -0,0 +1,65 @@
1
+<?php
2
+
3
+class Validate
4
+{
5
+    # Line 171
6
+    /**
7
+     * Extension Parser
8
+     *
9
+     * Takes an associative array of file types and extension, e.g.,
10
+     * $Archives = [
11
+     *   '7z'     => ['7z'],
12
+     *   'bzip2'  => ['bz2', 'bzip2'],
13
+     *   'gzip'   => ['gz', 'gzip', 'tgz', 'tpz'],
14
+     *   ...
15
+     * ];
16
+     *
17
+     * Then it finds all the extensions in a torrent file list,
18
+     * organizes them by file size, and returns the "heaviest" match.
19
+     *
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.
22
+     *
23
+     * todo: Incorporate into the main function (remove if statements first)
24
+     */
25
+    public function ParseExtensions($FileList, $Category, $FileTypes)
26
+    {
27
+        # Make $Tor->file_list() output manageable
28
+        $UnNested = array_values($FileList[1]);
29
+        $Sorted = (usort($UnNested, function ($a, $b) {
30
+            return $b <=> $a; # Workaround because ↑ returns true
31
+        }) === true) ? array_values($UnNested) : null;
32
+        
33
+        # Harvest the wheat
34
+        $TopTen = array_slice($Sorted, 0, 10);
35
+        $Result = [];
36
+
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>');
44
+
45
+            $Result = array_filter($Extensions, function ($a) {
46
+                foreach ($FileTypes as $FileType) {
47
+                    in_array($a, $FileType);
48
+                }
49
+            });
50
+
51
+            /*
52
+            foreach ($FileTypes as $k => $FileType) {
53
+                var_dump(array_intersect($Extensions, $FileTypes));
54
+            }
55
+            */
56
+        }
57
+
58
+        print_r('<pre>');
59
+        print_r('===== RESULTS =====');
60
+        print_r($Result);
61
+        print_r('</pre>');
62
+
63
+        # To be continued
64
+    }
65
+    # Line 229

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

@@ -0,0 +1,53 @@
1
+<?php
2
+
3
+# Line 44
4
+# todo: Associate containers with categories beforehand
5
+# It may have to happen structurally in config.php, e.g.,
6
+# $Categories = [
7
+#   'GazelleName' => [$Name, $Icon, $Description, $Containers],
8
+#    ...
9
+#  ];
10
+$Properties['Archives'] = $Archives;
11
+$Properties['Containers'] = [
12
+    'DNA'      => $Containers,
13
+    'RNA'      => $Containers,
14
+    'Proteins' => $ContainersProt,
15
+    'Imaging'  => $ContainersGames,
16
+    'Extras'   => $ContainersExtra
17
+];
18
+# Line 57
19
+
20
+# Line 421
21
+//******************************************************************************//
22
+//--------------- Autofill format and archive ----------------------------------//
23
+
24
+if ($T['Container'] === 'Autofill') {
25
+    # torrents.Container
26
+    $Validate->ParseExtensions(
27
+        # $FileList
28
+        $Tor->file_list(),
29
+
30
+        # $Category
31
+        $T['CategoryName'],
32
+
33
+        # $FileTypes
34
+        $T['FileTypes'],
35
+    );
36
+}
37
+
38
+if ($T['Archive'] === 'Autofill') {
39
+    /*
40
+    # torrents.Archive
41
+    $Validate->ParseExtensions(
42
+        # $FileList
43
+        $Tor->file_list(),
44
+
45
+        # $Category
46
+        $T['CategoryName'],
47
+
48
+        # $FileTypes
49
+        $T['FileTypes'],
50
+    );
51
+    */
52
+}
53
+# Line 452

+ 57
- 57
_packages/extension-parser/static/functions/upload.js View File

@@ -1,51 +1,51 @@
1 1
 // Line 11
2 2
 function Categories() {
3 3
     let def = [
4
-        'javdb', // Accession Number
5
-        'audio', // Version
6
-        'title', // Torrent Title
7
-        'title_rj', // Organism
8
-        'title_jp', // Strain/Variety
9
-        'idols', // Authors(s)
10
-        'studio', // Department/Lab
11
-        'series', // Location
12
-        'year', // Year
13
-        'codec', // License
14
-        // Platform changes below
15
-        'resolution', // Assembly Level
16
-        // Format changes below
17
-        'archive', // Archive
18
-        'tags', // Tags
19
-        'cover', // Picture
20
-        'mirrors', // Mirrors
21
-        'screenshots', // Publications
22
-        'group_desc', // Torrent Group Description
23
-        'release_desc', // Torrent Description
24
-        'censored', // Aligned/Annotated
25
-        'anon', // Upload Anonymously
4
+      'javdb', // Accession Number
5
+      'audio', // Version
6
+      'title', // Torrent Title
7
+      'title_rj', // Organism
8
+      'title_jp', // Strain/Variety
9
+      'idols', // Authors(s)
10
+      'studio', // Department/Lab
11
+      'series', // Location
12
+      'year', // Year
13
+      'codec', // License
14
+      // Platform changes below
15
+      'resolution', // Assembly Level
16
+      // Format changes below
17
+      'archive', // Archive
18
+      'tags', // Tags
19
+      'cover', // Picture
20
+      'mirrors', // Mirrors
21
+      'screenshots', // Publications
22
+      'group_desc', // Torrent Group Description
23
+      'release_desc', // Torrent Description
24
+      'censored', // Aligned/Annotated
25
+      'anon', // Upload Anonymously
26 26
     ]
27 27
   
28 28
     let cats = [
29
-        { // DNA
30
-            'media': {}, // Platform
31
-            'container': {}, // Format
32
-        },
33
-        { // RNA
34
-            'media': {}, // Platform
35
-            'container': {}, // Format
36
-        },
37
-        { // Proteins
38
-            'media': {}, // Platform
39
-            'container_prot': {}, // Format
40
-        },
41
-        { // Imaging
42
-            'media_manga': {}, // Platform
43
-            'container_games': {}, // Format
44
-        },
45
-        { // Extras
46
-            'media': {}, // Platform
47
-            'container_extra': {}, // Format
48
-        }
29
+      { // DNA
30
+        'media': {}, // Platform
31
+        'container': {}, // Format
32
+      },
33
+      { // RNA
34
+        'media': {}, // Platform
35
+        'container': {}, // Format
36
+      },
37
+      { // Proteins
38
+        'media': {}, // Platform
39
+        'container_prot': {}, // Format
40
+      },
41
+      { // Imaging
42
+        'media_manga': {}, // Platform
43
+        'container_games': {}, // Format
44
+      },
45
+      { // Extras
46
+        'media': {}, // Platform
47
+        'container_extra': {}, // Format
48
+      }
49 49
     ]
50 50
   
51 51
     let active = {}
@@ -56,28 +56,28 @@ function Categories() {
56 56
     active = Object.assign(active, cats[category])
57 57
   
58 58
     let hide = el => {
59
-        Array.from($(`#${el.id} input, #${el.id} select, #${el.id} textarea`)).forEach(inp => inp.disabled = true)
60
-        $(el).ghide()
59
+      Array.from($(`#${el.id} input, #${el.id} select, #${el.id} textarea`)).forEach(inp => inp.disabled = true)
60
+      $(el).ghide()
61 61
     }
62 62
   
63 63
     let show = el => {
64
-        Array.from($(`#${el.id} input, #${el.id} select, #${el.id} textarea`)).forEach(inp => inp.disabled = false)
65
-        $(el).gshow()
64
+      Array.from($(`#${el.id} input, #${el.id} select, #${el.id} textarea`)).forEach(inp => inp.disabled = false)
65
+      $(el).gshow()
66 66
     }
67 67
   
68 68
     let trs = $('#dynamic_form tr')
69 69
     for (let tr of trs) {
70
-        let field = tr.id.slice(0, -3)
71
-        if (active[field]) {
72
-            if (active[field].name) {
73
-                tr.children[0].innerHTML = active[field].name
74
-            }
75
-            let notes = $(`#${tr.id} p.notes`).raw()
76
-            if (notes) notes.innerHTML = active[field].notes || ''
77
-            show(tr)
78
-        } else {
79
-            hide(tr)
70
+      let field = tr.id.slice(0, -3)
71
+      if (active[field]) {
72
+        if (active[field].name) {
73
+          tr.children[0].innerHTML = active[field].name
80 74
         }
75
+        let notes = $(`#${tr.id} p.notes`).raw()
76
+        if (notes) notes.innerHTML = active[field].notes || ''
77
+        show(tr)
78
+      } else {
79
+        hide(tr)
80
+      }
81 81
     }
82
-}
82
+  }
83 83
 // Line 91

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

@@ -81,7 +81,7 @@ class TorrentForm
81 81
     Otherwise, add none of it and redownload the torrent file after uploading it.
82 82
     All of the above data will be added to it by the site.
83 83
     <strong>If you never have before, be sure to read this list of
84
-      <a href="wiki.php?action=article&name=uploadingpitfalls">uploading pitfalls</a></strong>.
84
+      <a href="wiki.php?action=article&name=uploadingpitfalls">uploading pitfalls</a>.</strong>
85 85
   </p>
86 86
 
87 87
   <!--

+ 21
- 83
classes/validate.class.php View File

@@ -186,108 +186,46 @@ class Validate
186 186
      * and 100 other small files, and get the format of the actual data.
187 187
      *
188 188
      * todo: Incorporate into the main function (remove if statements first)
189
-     * todo: Make this work with a more robust object than $Tor->file_list()
190 189
      */
191
-    public function ParseExtensions($FileList, $FileTypes)
190
+    public function ParseExtensions($FileList, $Category, $FileTypes)
192 191
     {
193 192
         # Make $Tor->file_list() output manageable
194 193
         $UnNested = array_values($FileList[1]);
195
-        $Sorted = usort($UnNested, function ($a, $b) {
196
-            return $b[0] > $a[0];
197
-        });
198
-        $TopTen = array_slice($Sorted, 0, 10); # Good
194
+        $Sorted = (usort($UnNested, function ($a, $b) {
195
+            return $b <=> $a; # Workaround because ↑ returns true
196
+        }) === true) ? array_values($UnNested) : null;
197
+        
198
+        # Harvest the wheat
199
+        $TopTen = array_slice($Sorted, 0, 10);
199 200
         $Result = [];
200 201
 
201
-        print_r('<pre>');
202
-        var_dump($Sorted);
203
-        print_r('</pre>');
204
-
205
-
206 202
         foreach ($TopTen as $TopTen) {
207
-            $Extensions = explode('.', strtolower($TopTen[1]));
203
+            # How many extensions to keep
204
+            $Extensions = array_slice(explode('.', strtolower($TopTen[1])), -2, 2);
205
+    
206
+            print_r('<pre>');
207
+            var_dump($FileTypes);
208
+            print_r('</pre>');
209
+
208 210
             $Result = array_filter($Extensions, function ($a) {
209 211
                 foreach ($FileTypes as $FileType) {
210 212
                     in_array($a, $FileType);
211 213
                 }
212 214
             });
213
-            /*
214
-            foreach ($FileTypes as $Key => $FileTypes) {
215
-                print_r('<pre>');
216 215
 
217
-            var_dump($UnNested);
218
-            var_dump( $FileTypes[$Key]);
219
-            print_r('</pre>');
220
-
221
-        }
222
-        */
223
-        }
224
-        /*
225
-        foreach ($TopTen as $TopTen) {
226
-            $Extensions = explode('.', strtolower($TopTen[1]));
227
-            #foreach ($FileTypes as $Key => $FileTypes) {
228
-                print_r('<pre>');
229
-                #$Result = (in_array($Extensions, $FileTypes)) ? $FileTypes[$Key] : false;
230
-                var_dump($Extensions);
216
+            /*
217
+            foreach ($FileTypes as $k => $FileType) {
231 218
                 var_dump(array_intersect($Extensions, $FileTypes));
232
-                print_r('</pre>');
233
-
234
-            #}
235
-            print_r('<pre>');
236
-            //var_dump(array_intersect($Extensions, $FileTypes));
237
-            //var_dump($Extensions);
238
-            print_r('</pre>');
239
-
219
+            }
220
+            */
240 221
         }
241
-        */
222
+
242 223
         print_r('<pre>');
243
-        #var_dump(array_intersect($UnNested, $FileTypes));
244
-        #print_r($Sorted);
224
+        print_r('===== RESULTS =====');
245 225
         print_r($Result);
246 226
         print_r('</pre>');
247
- 
248
-        /*
249
-        while ($Result === false) {
250
-           foreach ($UnNested as $Key => $UnNested) {
251
-               $Exploded = explode('.', strtolower($UnNested[1]));
252
-               foreach ($Needles as $Key => $Needle) {
253
-                   $ID = array_search($Exploded, $Needle);
254
-                   var_dump($Needle[$ID]);
255
-               }
256
-               $dump = array_filter($Exploded, function($s){
257
-                   foreach ($Needles as $Type => $Extension) {
258
-                       return array_search($s, $Extension);
259
-                   }
260
-               });
261
-               #var_dump($dump);
262
-               /*
263
-               if (array_search($Needle, $Exploded, true)) {
264
-                   $Result = $Needles;
265
-               #break;
266
-               }
267
-           }
268
-
269
-         }
270
-        */
271
-#var_dump($Result);
272
-        /*
273
-#do {
274
-    foreach ($UnNested as $UnNested) {
275
-        $Exploded = explode('.', strtolower($UnNested[1]));
276
-            #var_dump(in_array(vals($names), $Explode));
277
-
278
-        }
279
-/*
280
-        if (array_intersect($names, $Exploded)) {
281
-            $result = array_search($Exploded, $names);
282
-
283
-        }
284
-        *
285
-    }
286
-#} while ($result !== false);
287
-print_r($result);
288
-
289 227
 
290
-*/
228
+        # To be continued
291 229
     }
292 230
 
293 231
     public function GenerateJS($FormID)

+ 35
- 3
sections/upload/upload_handle.php View File

@@ -40,9 +40,26 @@ $TypeID = $_POST['type'] + 1;
40 40
 
41 41
 $Properties['CategoryID'] = $TypeID;
42 42
 $Properties['CategoryName'] = $Type;
43
+
44
+# todo: Associate containers with categories beforehand
45
+# It may have to happen structurally in config.php, e.g.,
46
+# $Categories = [
47
+#   'GazelleName' => [$Name, $Icon, $Description, $Containers],
48
+#    ...
49
+#  ];
50
+$Properties['ArchiveTypes'] = $Archives;
51
+$Properties['FileTypes'] = [
52
+    'DNA'      => $Containers,
53
+    'RNA'      => $Containers,
54
+    'Proteins' => $ContainersProt,
55
+    'Imaging'  => $ContainersGames,
56
+    'Extras'   => $ContainersExtra
57
+];
58
+
43 59
 $Properties['Title'] = $_POST['title'];
44 60
 $Properties['TitleRJ'] = $_POST['title_rj'];
45 61
 $Properties['TitleJP'] = $_POST['title_jp'];
62
+
46 63
 $Properties['Year'] = $_POST['year'];
47 64
 $Properties['Studio'] = isset($_POST['studio']) ? $_POST['studio'] : '';
48 65
 $Properties['Series'] = isset($_POST['series']) ? $_POST['series'] : '';
@@ -404,17 +421,32 @@ if (!empty($Err)) { // Show the upload form, with the data the user entered
404 421
 //******************************************************************************//
405 422
 //--------------- Autofill format and archive ----------------------------------//
406 423
 
407
-if ($T['Container'] === 'Autofill' || $T['Archive'] === 'Autofill') {
424
+if ($T['Container'] === 'Autofill') {
408 425
     # torrents.Container
409 426
     $Validate->ParseExtensions(
427
+        # $FileList
410 428
         $Tor->file_list(),
411
-        array_merge($Containers, $ContainersGames, $ContainersProt)
429
+
430
+        # $Category
431
+        $T['CategoryName'],
432
+
433
+        # $FileTypes
434
+        $T['FileTypes'],
412 435
     );
436
+}
437
+
438
+if ($T['Archive'] === 'Autofill') {
413 439
     /*
414 440
     # torrents.Archive
415 441
     $Validate->ParseExtensions(
442
+        # $FileList
416 443
         $Tor->file_list(),
417
-        array_merge($Containers, $ContainersGames, $ContainersProt)
444
+
445
+        # $Category
446
+        $T['CategoryName'],
447
+
448
+        # $FileTypes
449
+        $T['FileTypes'],
418 450
     );
419 451
     */
420 452
 }

Loading…
Cancel
Save