Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
8e4a4f745d
4 changed files with 958 additions and 936 deletions
  1. 244
    235
      classes/torrent.class.php
  2. 228
    219
      classes/torrent_32bit.class.php
  3. 258
    266
      classes/torrent_form.class.php
  4. 228
    216
      classes/torrentsdl.class.php

+ 244
- 235
classes/torrent.class.php View File

1
-<?
1
+<?php
2
 /*******************************************************************************
2
 /*******************************************************************************
3
 |~~~~ Gazelle bencode parser                         ~~~~|
3
 |~~~~ Gazelle bencode parser                         ~~~~|
4
 --------------------------------------------------------------------------------
4
 --------------------------------------------------------------------------------
63
 
63
 
64
 
64
 
65
 *******************************************************************************/
65
 *******************************************************************************/
66
-class BENCODE2 {
67
-  var $Val; // Decoded array
68
-  var $Pos = 1; // Pointer that indicates our position in the string
69
-  var $Str = ''; // Torrent string
70
-
71
-  function __construct($Val, $IsParsed = false) {
72
-    if (!$IsParsed) {
73
-      $this->Str = $Val;
74
-      $this->dec();
75
-    } else {
76
-      $this->Val = $Val;
66
+class BENCODE2
67
+{
68
+    public $Val; // Decoded array
69
+    public $Pos = 1; // Pointer that indicates our position in the string
70
+    public $Str = ''; // Torrent string
71
+
72
+    public function __construct($Val, $IsParsed = false)
73
+    {
74
+        if (!$IsParsed) {
75
+            $this->Str = $Val;
76
+            $this->dec();
77
+        } else {
78
+            $this->Val = $Val;
79
+        }
77
     }
80
     }
78
-  }
79
-
80
-  // Decode an element based on the type. The type is really just an indicator.
81
-  function decode($Type, $Key) {
82
-    if (is_number($Type)) { // Element is a string
83
-      // Get length of string
84
-      $StrLen = $Type;
85
-      while ($this->Str[$this->Pos + 1] != ':') {
86
-        $this->Pos++;
87
-        $StrLen.=$this->Str[$this->Pos];
88
-      }
89
-      $this->Val[$Key] = substr($this->Str, $this->Pos + 2, $StrLen);
90
-
91
-      $this->Pos += $StrLen;
92
-      $this->Pos += 2;
93
-
94
-    } elseif ($Type == 'i') { // Element is an int
95
-      $this->Pos++;
96
-
97
-      // Find end of integer (first occurance of 'e' after position)
98
-      $End = strpos($this->Str, 'e', $this->Pos);
99
-
100
-      // Get the integer, and - IMPORTANT - cast it as an int, so we know later that it's an int and not a string
101
-      $this->Val[$Key] = (int)substr($this->Str, $this->Pos, $End-$this->Pos);
102
-      $this->Pos = $End + 1;
103
-
104
-    } elseif ($Type == 'l') { // Element is a list
105
-      $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos));
106
-      $this->Pos += $this->Val[$Key]->Pos;
107
-
108
-    } elseif ($Type == 'd') { // Element is a dictionary
109
-      $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos));
110
-      $this->Pos += $this->Val[$Key]->Pos;
111
-      // Sort by key to respect spec
112
-      if (!empty($this->Val[$Key]->Val)) {
113
-        ksort($this->Val[$Key]->Val);
114
-      }
115
-
116
-    } else {
117
-      die('Invalid torrent file');
81
+
82
+    // Decode an element based on the type. The type is really just an indicator.
83
+    public function decode($Type, $Key)
84
+    {
85
+        if (is_number($Type)) { // Element is a string
86
+            // Get length of string
87
+            $StrLen = $Type;
88
+            while ($this->Str[$this->Pos + 1] != ':') {
89
+                $this->Pos++;
90
+                $StrLen.=$this->Str[$this->Pos];
91
+            }
92
+            $this->Val[$Key] = substr($this->Str, $this->Pos + 2, $StrLen);
93
+
94
+            $this->Pos += $StrLen;
95
+            $this->Pos += 2;
96
+        } elseif ($Type == 'i') { // Element is an int
97
+            $this->Pos++;
98
+
99
+            // Find end of integer (first occurance of 'e' after position)
100
+            $End = strpos($this->Str, 'e', $this->Pos);
101
+
102
+            // Get the integer, and - IMPORTANT - cast it as an int, so we know later that it's an int and not a string
103
+            $this->Val[$Key] = (int)substr($this->Str, $this->Pos, $End-$this->Pos);
104
+            $this->Pos = $End + 1;
105
+        } elseif ($Type == 'l') { // Element is a list
106
+            $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos));
107
+            $this->Pos += $this->Val[$Key]->Pos;
108
+        } elseif ($Type == 'd') { // Element is a dictionary
109
+            $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos));
110
+            $this->Pos += $this->Val[$Key]->Pos;
111
+            // Sort by key to respect spec
112
+            if (!empty($this->Val[$Key]->Val)) {
113
+                ksort($this->Val[$Key]->Val);
114
+            }
115
+        } else {
116
+            die('Invalid torrent file');
117
+        }
118
     }
118
     }
119
-  }
120
-
121
-  function encode($Val) {
122
-    if (is_int($Val)) { // Integer
123
-      return 'i'.$Val.'e';
124
-    } elseif (is_string($Val)) {
125
-      return strlen($Val).':'.$Val;
126
-    } elseif (is_object($Val)) {
127
-      return $Val->enc();
128
-    } else {
129
-      return 'fail';
119
+
120
+    public function encode($Val)
121
+    {
122
+        if (is_int($Val)) { // Integer
123
+            return 'i'.$Val.'e';
124
+        } elseif (is_string($Val)) {
125
+            return strlen($Val).':'.$Val;
126
+        } elseif (is_object($Val)) {
127
+            return $Val->enc();
128
+        } else {
129
+            return 'fail';
130
+        }
130
     }
131
     }
131
-  }
132
 }
132
 }
133
 
133
 
134
-class BENCODE_LIST extends BENCODE2 {
135
-  function enc() {
136
-    if (empty($this->Val)) {
137
-      return 'le';
134
+class BENCODE_LIST extends BENCODE2
135
+{
136
+    public function enc()
137
+    {
138
+        if (empty($this->Val)) {
139
+            return 'le';
140
+        }
141
+        $Str = 'l';
142
+        reset($this->Val);
143
+        foreach ($this->Val as $Value) {
144
+            $Str.=$this->encode($Value);
145
+        }
146
+        return $Str.'e';
138
     }
147
     }
139
-    $Str = 'l';
140
-    reset($this->Val);
141
-    foreach ($this->Val as $Value) {
142
-      $Str.=$this->encode($Value);
143
-    }
144
-    return $Str.'e';
145
-  }
146
-
147
-  // Decode a list
148
-  function dec() {
149
-    $Key = 0; // Array index
150
-    $Length = strlen($this->Str);
151
-    while ($this->Pos < $Length) {
152
-      $Type = $this->Str[$this->Pos];
153
-      // $Type now indicates what type of element we're dealing with
154
-      // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
155
-
156
-      if ($Type == 'e') { // End of list
157
-        $this->Pos += 1;
158
-        unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
159
-        return;
160
-      }
161
-
162
-      // Decode the bencoded element.
163
-      // This function changes $this->Pos and $this->Val, so you don't have to.
164
-      $this->decode($Type, $Key);
165
-      ++$Key;
148
+
149
+    // Decode a list
150
+    public function dec()
151
+    {
152
+        $Key = 0; // Array index
153
+        $Length = strlen($this->Str);
154
+        while ($this->Pos < $Length) {
155
+            $Type = $this->Str[$this->Pos];
156
+            // $Type now indicates what type of element we're dealing with
157
+            // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
158
+
159
+            if ($Type == 'e') { // End of list
160
+                $this->Pos += 1;
161
+                unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
162
+                return;
163
+            }
164
+
165
+            // Decode the bencoded element.
166
+            // This function changes $this->Pos and $this->Val, so you don't have to.
167
+            $this->decode($Type, $Key);
168
+            ++$Key;
169
+        }
170
+        return true;
166
     }
171
     }
167
-    return true;
168
-  }
169
 }
172
 }
170
 
173
 
171
-class BENCODE_DICT extends BENCODE2 {
172
-  function enc() {
173
-    if (empty($this->Val)) {
174
-      return 'de';
174
+class BENCODE_DICT extends BENCODE2
175
+{
176
+    public function enc()
177
+    {
178
+        if (empty($this->Val)) {
179
+            return 'de';
180
+        }
181
+        $Str = 'd';
182
+        reset($this->Val);
183
+        foreach ($this->Val as $Key => $Value) {
184
+            $Str.=strlen($Key).':'.$Key.$this->encode($Value);
185
+        }
186
+        return $Str.'e';
175
     }
187
     }
176
-    $Str = 'd';
177
-    reset($this->Val);
178
-    foreach ($this->Val as $Key => $Value) {
179
-      $Str.=strlen($Key).':'.$Key.$this->encode($Value);
180
-    }
181
-    return $Str.'e';
182
-  }
183
-
184
-  // Decode a dictionary
185
-  function dec() {
186
-    $Length = strlen($this->Str);
187
-    while ($this->Pos<$Length) {
188
-
189
-      if ($this->Str[$this->Pos] == 'e') { // End of dictionary
190
-        $this->Pos += 1;
191
-        unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
192
-        return;
193
-      }
194
-
195
-      // Get the dictionary key
196
-      // Length of the key, in bytes
197
-      $KeyLen = $this->Str[$this->Pos];
198
-
199
-      // Allow for multi-digit lengths
200
-      while ($this->Str[$this->Pos + 1] != ':' && $this->Pos + 1 < $Length) {
201
-        $this->Pos++;
202
-        $KeyLen.=$this->Str[$this->Pos];
203
-      }
204
-      // $this->Pos is now on the last letter of the key length
205
-      // Adding 2 brings it past that character and the ':' to the beginning of the string
206
-      $this->Pos += 2;
207
-
208
-      // Get the name of the key
209
-      $Key = substr($this->Str, $this->Pos, $KeyLen);
210
-
211
-      // Move the position past the key to the beginning of the element
212
-      $this->Pos += $KeyLen;
213
-      $Type = $this->Str[$this->Pos];
214
-      // $Type now indicates what type of element we're dealing with
215
-      // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
216
-
217
-      // Decode the bencoded element.
218
-      // This function changes $this->Pos and $this->Val, so you don't have to.
219
-      $this->decode($Type, $Key);
220
-
221
 
188
 
189
+    // Decode a dictionary
190
+    public function dec()
191
+    {
192
+        $Length = strlen($this->Str);
193
+        while ($this->Pos<$Length) {
194
+            if ($this->Str[$this->Pos] == 'e') { // End of dictionary
195
+                $this->Pos += 1;
196
+                unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
197
+                return;
198
+            }
199
+
200
+            // Get the dictionary key
201
+            // Length of the key, in bytes
202
+            $KeyLen = $this->Str[$this->Pos];
203
+
204
+            // Allow for multi-digit lengths
205
+            while ($this->Str[$this->Pos + 1] != ':' && $this->Pos + 1 < $Length) {
206
+                $this->Pos++;
207
+                $KeyLen.=$this->Str[$this->Pos];
208
+            }
209
+            // $this->Pos is now on the last letter of the key length
210
+            // Adding 2 brings it past that character and the ':' to the beginning of the string
211
+            $this->Pos += 2;
212
+
213
+            // Get the name of the key
214
+            $Key = substr($this->Str, $this->Pos, $KeyLen);
215
+
216
+            // Move the position past the key to the beginning of the element
217
+            $this->Pos += $KeyLen;
218
+            $Type = $this->Str[$this->Pos];
219
+            // $Type now indicates what type of element we're dealing with
220
+            // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
221
+
222
+            // Decode the bencoded element.
223
+            // This function changes $this->Pos and $this->Val, so you don't have to.
224
+            $this->decode($Type, $Key);
225
+        }
226
+        return true;
222
     }
227
     }
223
-    return true;
224
-  }
225
 }
228
 }
226
 
229
 
227
 
230
 
228
-class TORRENT extends BENCODE_DICT {
229
-  function dump() {
230
-    // Convenience function used for testing and figuring out how we store the data
231
-    print_r($this->Val);
232
-  }
231
+class TORRENT extends BENCODE_DICT
232
+{
233
+    public function dump()
234
+    {
235
+        // Convenience function used for testing and figuring out how we store the data
236
+        print_r($this->Val);
237
+    }
233
 
238
 
234
-  function dump_data() {
235
-    // Function which serializes $this->Val for storage
236
-    return base64_encode(serialize($this->Val));
237
-  }
239
+    public function dump_data()
240
+    {
241
+        // Function which serializes $this->Val for storage
242
+        return base64_encode(serialize($this->Val));
243
+    }
244
+
245
+    public function set_announce_list($UrlsList)
246
+    {
247
+        $AnnounceList = new BENCODE_LIST([], true);
248
+        foreach ($UrlsList as $Urls) {
249
+            $SubList = new BENCODE_LIST($Urls, true);
250
+            unset($SubList->Str);
251
+            $AnnounceList->Val[] = $SubList;
252
+        }
253
+        $this->Val['announce-list'] = $AnnounceList;
254
+    }
238
 
255
 
239
-  function set_announce_list($UrlsList) {
240
-    $AnnounceList = new BENCODE_LIST([], true);
241
-    foreach ($UrlsList as $Urls) {
242
-      $SubList = new BENCODE_LIST($Urls, true);
243
-      unset($SubList->Str);
244
-      $AnnounceList->Val[] = $SubList;
256
+    public function set_announce_url($Announce)
257
+    {
258
+        $this->Val['announce'] = $Announce;
259
+        ksort($this->Val);
245
     }
260
     }
246
-    $this->Val['announce-list'] = $AnnounceList;
247
-  }
248
-
249
-  function set_announce_url($Announce) {
250
-    $this->Val['announce'] = $Announce;
251
-    ksort($this->Val);
252
-  }
253
-
254
-  // Returns an array of:
255
-  //  * the files in the torrent
256
-  //  * the total size of files described therein
257
-  function file_list() {
258
-    $FileList = [];
259
-    if (!isset($this->Val['info']->Val['files'])) { // Single file mode
260
-      $TotalSize = $this->Val['info']->Val['length'];
261
-      $FileList[] = array($TotalSize, $this->get_name());
262
-    } else { // Multiple file mode
263
-      $FileNames = [];
264
-      $FileSizes = [];
265
-      $TotalSize = 0;
266
-      $Files = $this->Val['info']->Val['files']->Val;
267
-      if (isset($Files[0]->Val['path.utf-8'])) {
268
-        $PathKey = 'path.utf-8';
269
-      } else {
270
-        $PathKey = 'path';
271
-      }
272
-      foreach ($Files as $File) {
273
-        $FileSize = $File->Val['length'];
274
-        $TotalSize += $FileSize;
275
-
276
-        $FileName = ltrim(implode('/', $File->Val[$PathKey]->Val), '/');
277
-        $FileSizes[] = $FileSize;
278
-        $FileNames[] = $FileName;
279
-      }
280
-      natcasesort($FileNames);
281
-      foreach ($FileNames as $Index => $FileName) {
282
-        $FileList[] = array($FileSizes[$Index], $FileName);
283
-      }
261
+
262
+    // Returns an array of:
263
+    //  * the files in the torrent
264
+    //  * the total size of files described therein
265
+    public function file_list()
266
+    {
267
+        $FileList = [];
268
+        if (!isset($this->Val['info']->Val['files'])) { // Single file mode
269
+            $TotalSize = $this->Val['info']->Val['length'];
270
+            $FileList[] = array($TotalSize, $this->get_name());
271
+        } else { // Multiple file mode
272
+            $FileNames = [];
273
+            $FileSizes = [];
274
+            $TotalSize = 0;
275
+            $Files = $this->Val['info']->Val['files']->Val;
276
+            if (isset($Files[0]->Val['path.utf-8'])) {
277
+                $PathKey = 'path.utf-8';
278
+            } else {
279
+                $PathKey = 'path';
280
+            }
281
+            foreach ($Files as $File) {
282
+                $FileSize = $File->Val['length'];
283
+                $TotalSize += $FileSize;
284
+
285
+                $FileName = ltrim(implode('/', $File->Val[$PathKey]->Val), '/');
286
+                $FileSizes[] = $FileSize;
287
+                $FileNames[] = $FileName;
288
+            }
289
+            natcasesort($FileNames);
290
+            foreach ($FileNames as $Index => $FileName) {
291
+                $FileList[] = array($FileSizes[$Index], $FileName);
292
+            }
293
+        }
294
+        return array($TotalSize, $FileList);
284
     }
295
     }
285
-    return array($TotalSize, $FileList);
286
-  }
287
-
288
-  function get_name() {
289
-    if (isset($this->Val['info']->Val['name.utf-8'])) {
290
-      return $this->Val['info']->Val['name.utf-8'];
291
-    } else {
292
-      return $this->Val['info']->Val['name'];
296
+
297
+    public function get_name()
298
+    {
299
+        if (isset($this->Val['info']->Val['name.utf-8'])) {
300
+            return $this->Val['info']->Val['name.utf-8'];
301
+        } else {
302
+            return $this->Val['info']->Val['name'];
303
+        }
293
     }
304
     }
294
-  }
295
 
305
 
296
-  function make_private() {
297
-    //----- The following properties do not affect the infohash:
306
+    public function make_private()
307
+    {
308
+        //----- The following properties do not affect the infohash:
298
 
309
 
299
-    // anounce-list is an unofficial extension to the protocol
300
-    // that allows for multiple trackers per torrent
301
-    unset($this->Val['announce-list']);
310
+        // anounce-list is an unofficial extension to the protocol
311
+        // that allows for multiple trackers per torrent
312
+        unset($this->Val['announce-list']);
302
 
313
 
303
-    // Bitcomet & Azureus cache peers in here
304
-    unset($this->Val['nodes']);
314
+        // Bitcomet & Azureus cache peers in here
315
+        unset($this->Val['nodes']);
305
 
316
 
306
-    // Azureus stores the dht_backup_enable flag here
307
-    unset($this->Val['azureus_properties']);
317
+        // Azureus stores the dht_backup_enable flag here
318
+        unset($this->Val['azureus_properties']);
308
 
319
 
309
-    // Remove web-seeds
310
-    unset($this->Val['url-list']);
320
+        // Remove web-seeds
321
+        unset($this->Val['url-list']);
311
 
322
 
312
-    // Remove libtorrent resume info
313
-    unset($this->Val['libtorrent_resume']);
323
+        // Remove libtorrent resume info
324
+        unset($this->Val['libtorrent_resume']);
314
 
325
 
315
-    //----- End properties that do not affect the infohash
316
-    if ($this->Val['info']->Val['private']) {
317
-      return true; // Torrent is private
318
-    } else {
319
-      // Torrent is not private!
320
-      // add private tracker flag and sort info dictionary
321
-      $this->Val['info']->Val['private'] = 1;
322
-      ksort($this->Val['info']->Val);
323
-      return false;
326
+        //----- End properties that do not affect the infohash
327
+        if ($this->Val['info']->Val['private']) {
328
+            return true; // Torrent is private
329
+        } else {
330
+            // Torrent is not private!
331
+            // add private tracker flag and sort info dictionary
332
+            $this->Val['info']->Val['private'] = 1;
333
+            ksort($this->Val['info']->Val);
334
+            return false;
335
+        }
324
     }
336
     }
325
-  }
326
 }
337
 }
327
-
328
-?>

+ 228
- 219
classes/torrent_32bit.class.php View File

1
-<?
1
+<?php
2
 /*******************************************************************************
2
 /*******************************************************************************
3
 |~~~~ Gazelle bencode parser                                               ~~~~|
3
 |~~~~ Gazelle bencode parser                                               ~~~~|
4
 --------------------------------------------------------------------------------
4
 --------------------------------------------------------------------------------
72
 discovered that floats aren't accurate enough to use. :(
72
 discovered that floats aren't accurate enough to use. :(
73
 
73
 
74
 *******************************************************************************/
74
 *******************************************************************************/
75
-class BENCODE2 {
76
-  var $Val; // Decoded array
77
-  var $Pos = 1; // Pointer that indicates our position in the string
78
-  var $Str = ''; // Torrent string
79
-
80
-  function __construct($Val, $IsParsed = false) {
81
-    if (!$IsParsed) {
82
-      $this->Str = $Val;
83
-      $this->dec();
84
-    } else {
85
-      $this->Val = $Val;
75
+class BENCODE2
76
+{
77
+    public $Val; // Decoded array
78
+    public $Pos = 1; // Pointer that indicates our position in the string
79
+    public $Str = ''; // Torrent string
80
+
81
+    public function __construct($Val, $IsParsed = false)
82
+    {
83
+        if (!$IsParsed) {
84
+            $this->Str = $Val;
85
+            $this->dec();
86
+        } else {
87
+            $this->Val = $Val;
88
+        }
86
     }
89
     }
87
-  }
88
-
89
-  // Decode an element based on the type
90
-  function decode($Type, $Key) {
91
-    if (ctype_digit($Type)) { // Element is a string
92
-      // Get length of string
93
-      $StrLen = $Type;
94
-      while ($this->Str[$this->Pos + 1] != ':') {
95
-        $this->Pos++;
96
-        $StrLen.=$this->Str[$this->Pos];
97
-      }
98
-      $this->Val[$Key] = substr($this->Str, $this->Pos + 2, $StrLen);
99
-
100
-      $this->Pos += $StrLen;
101
-      $this->Pos += 2;
102
-
103
-    } elseif ($Type == 'i') { // Element is an int
104
-      $this->Pos++;
105
-
106
-      // Find end of integer (first occurance of 'e' after position)
107
-      $End = strpos($this->Str, 'e', $this->Pos);
108
-
109
-      // Get the integer, and mark it as an int (on our version 64 bit box, we cast it to an int)
110
-      $this->Val[$Key] = '[*INT*]'.substr($this->Str, $this->Pos, $End-$this->Pos);
111
-      $this->Pos = $End + 1;
112
-
113
-    } elseif ($Type == 'l') { // Element is a list
114
-      $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos));
115
-      $this->Pos += $this->Val[$Key]->Pos;
116
-
117
-    } elseif ($Type == 'd') { // Element is a dictionary
118
-      $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos));
119
-      $this->Pos += $this->Val[$Key]->Pos;
120
-      // Sort by key to respect spec
121
-      ksort($this->Val[$Key]->Val);
122
-
123
-    } else {
124
-      die('Invalid torrent file');
90
+
91
+    // Decode an element based on the type
92
+    public function decode($Type, $Key)
93
+    {
94
+        if (ctype_digit($Type)) { // Element is a string
95
+            // Get length of string
96
+            $StrLen = $Type;
97
+            while ($this->Str[$this->Pos + 1] != ':') {
98
+                $this->Pos++;
99
+                $StrLen.=$this->Str[$this->Pos];
100
+            }
101
+            $this->Val[$Key] = substr($this->Str, $this->Pos + 2, $StrLen);
102
+
103
+            $this->Pos += $StrLen;
104
+            $this->Pos += 2;
105
+        } elseif ($Type == 'i') { // Element is an int
106
+            $this->Pos++;
107
+
108
+            // Find end of integer (first occurance of 'e' after position)
109
+            $End = strpos($this->Str, 'e', $this->Pos);
110
+
111
+            // Get the integer, and mark it as an int (on our version 64 bit box, we cast it to an int)
112
+            $this->Val[$Key] = '[*INT*]'.substr($this->Str, $this->Pos, $End-$this->Pos);
113
+            $this->Pos = $End + 1;
114
+        } elseif ($Type == 'l') { // Element is a list
115
+            $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos));
116
+            $this->Pos += $this->Val[$Key]->Pos;
117
+        } elseif ($Type == 'd') { // Element is a dictionary
118
+            $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos));
119
+            $this->Pos += $this->Val[$Key]->Pos;
120
+            // Sort by key to respect spec
121
+            ksort($this->Val[$Key]->Val);
122
+        } else {
123
+            die('Invalid torrent file');
124
+        }
125
     }
125
     }
126
-  }
127
-
128
-  function encode($Val) {
129
-    if (is_string($Val)) {
130
-      if (substr($Val, 0, 7) == '[*INT*]') {
131
-        return 'i'.substr($Val,7).'e';
132
-      } else {
133
-        return strlen($Val).':'.$Val;
134
-      }
135
-    } elseif (is_object($Val)) {
136
-      return $Val->enc();
137
-    } else {
138
-      return 'fail';
126
+
127
+    public function encode($Val)
128
+    {
129
+        if (is_string($Val)) {
130
+            if (substr($Val, 0, 7) == '[*INT*]') {
131
+                return 'i'.substr($Val, 7).'e';
132
+            } else {
133
+                return strlen($Val).':'.$Val;
134
+            }
135
+        } elseif (is_object($Val)) {
136
+            return $Val->enc();
137
+        } else {
138
+            return 'fail';
139
+        }
139
     }
140
     }
140
-  }
141
 }
141
 }
142
 
142
 
143
-class BENCODE_LIST extends BENCODE2 {
144
-  function enc() {
145
-    $Str = 'l';
146
-    foreach ($this->Val as $Value) {
147
-      $Str.=$this->encode($Value);
143
+class BENCODE_LIST extends BENCODE2
144
+{
145
+    public function enc()
146
+    {
147
+        $Str = 'l';
148
+        foreach ($this->Val as $Value) {
149
+            $Str.=$this->encode($Value);
150
+        }
151
+        return $Str.'e';
148
     }
152
     }
149
-    return $Str.'e';
150
-  }
151
-
152
-  // Decode a list
153
-  function dec() {
154
-    $Key = 0; // Array index
155
-    $Length = strlen($this->Str);
156
-    while ($this->Pos<$Length) {
157
-      $Type = $this->Str[$this->Pos];
158
-      // $Type now indicates what type of element we're dealing with
159
-      // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
160
-
161
-      if ($Type == 'e') { // End of list
162
-        $this->Pos += 1;
163
-        unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
164
-        return;
165
-      }
166
-
167
-      // Decode the bencoded element.
168
-      // This function changes $this->Pos and $this->Val, so you don't have to.
169
-      $this->decode($Type, $Key);
170
-      ++ $Key;
153
+
154
+    // Decode a list
155
+    public function dec()
156
+    {
157
+        $Key = 0; // Array index
158
+        $Length = strlen($this->Str);
159
+        while ($this->Pos<$Length) {
160
+            $Type = $this->Str[$this->Pos];
161
+            // $Type now indicates what type of element we're dealing with
162
+            // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
163
+
164
+            if ($Type == 'e') { // End of list
165
+                $this->Pos += 1;
166
+                unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
167
+                return;
168
+            }
169
+
170
+            // Decode the bencoded element.
171
+            // This function changes $this->Pos and $this->Val, so you don't have to.
172
+            $this->decode($Type, $Key);
173
+            ++ $Key;
174
+        }
175
+        return true;
171
     }
176
     }
172
-    return true;
173
-  }
174
 }
177
 }
175
 
178
 
176
-class BENCODE_DICT extends BENCODE2 {
177
-  function enc() {
178
-    $Str = 'd';
179
-    foreach ($this->Val as $Key => $Value) {
180
-      $Str.=strlen($Key).':'.$Key.$this->encode($Value);
179
+class BENCODE_DICT extends BENCODE2
180
+{
181
+    public function enc()
182
+    {
183
+        $Str = 'd';
184
+        foreach ($this->Val as $Key => $Value) {
185
+            $Str.=strlen($Key).':'.$Key.$this->encode($Value);
186
+        }
187
+        return $Str.'e';
181
     }
188
     }
182
-    return $Str.'e';
183
-  }
184
-
185
-  // Decode a dictionary
186
-  function dec() {
187
-    $Length = strlen($this->Str);
188
-    while ($this->Pos < $Length) {
189
-
190
-      if ($this->Str[$this->Pos] == 'e') { // End of dictionary
191
-        $this->Pos += 1;
192
-        unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
193
-        return;
194
-      }
195
-
196
-      // Get the dictionary key
197
-      // Length of the key, in bytes
198
-      $KeyLen = $this->Str[$this->Pos];
199
-
200
-      // Allow for multi-digit lengths
201
-      while ($this->Str[$this->Pos + 1] != ':' && $this->Pos + 1 < $Length) {
202
-        $this->Pos++;
203
-        $KeyLen.=$this->Str[$this->Pos];
204
-      }
205
-      // $this->Pos is now on the last letter of the key length
206
-      // Adding 2 brings it past that character and the ':' to the beginning of the string
207
-      $this->Pos+=2;
208
-
209
-      // Get the name of the key
210
-      $Key = substr($this->Str, $this->Pos, $KeyLen);
211
-
212
-      // Move the position past the key to the beginning of the element
213
-      $this->Pos += $KeyLen;
214
-      $Type = $this->Str[$this->Pos];
215
-      // $Type now indicates what type of element we're dealing with
216
-      // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
217
-
218
-      // Decode the bencoded element.
219
-      // This function changes $this->Pos and $this->Val, so you don't have to.
220
-      $this->decode($Type, $Key);
221
-
222
 
189
 
190
+    // Decode a dictionary
191
+    public function dec()
192
+    {
193
+        $Length = strlen($this->Str);
194
+        while ($this->Pos < $Length) {
195
+            if ($this->Str[$this->Pos] == 'e') { // End of dictionary
196
+                $this->Pos += 1;
197
+                unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
198
+                return;
199
+            }
200
+
201
+            // Get the dictionary key
202
+            // Length of the key, in bytes
203
+            $KeyLen = $this->Str[$this->Pos];
204
+
205
+            // Allow for multi-digit lengths
206
+            while ($this->Str[$this->Pos + 1] != ':' && $this->Pos + 1 < $Length) {
207
+                $this->Pos++;
208
+                $KeyLen.=$this->Str[$this->Pos];
209
+            }
210
+            // $this->Pos is now on the last letter of the key length
211
+            // Adding 2 brings it past that character and the ':' to the beginning of the string
212
+            $this->Pos+=2;
213
+
214
+            // Get the name of the key
215
+            $Key = substr($this->Str, $this->Pos, $KeyLen);
216
+
217
+            // Move the position past the key to the beginning of the element
218
+            $this->Pos += $KeyLen;
219
+            $Type = $this->Str[$this->Pos];
220
+            // $Type now indicates what type of element we're dealing with
221
+            // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
222
+
223
+            // Decode the bencoded element.
224
+            // This function changes $this->Pos and $this->Val, so you don't have to.
225
+            $this->decode($Type, $Key);
226
+        }
227
+        return true;
223
     }
228
     }
224
-    return true;
225
-  }
226
 }
229
 }
227
 
230
 
228
 
231
 
229
-class TORRENT extends BENCODE_DICT {
230
-  function dump() {
231
-    // Convenience function used for testing and figuring out how we store the data
232
-    print_r($this->Val);
233
-  }
234
-
235
-  function dump_data() {
236
-    // Function which serializes $this->Val for storage
237
-    return base64_encode(serialize($this->Val));
238
-  }
239
-
240
-  function set_announce_url($Announce) {
241
-    $this->Val['announce'] = $Announce;
242
-    ksort($this->Val);
243
-  }
244
-
245
-  // Returns an array of:
246
-  //  * the files in the torrent
247
-  //  * the total size of files described therein
248
-  function file_list() {
249
-    $FileList = [];
250
-    if (!isset($this->Val['info']->Val['files'])) { // Single file mode
251
-      $TotalSize = substr($this->Val['info']->Val['length'],7);
252
-      $FileList[] = array($TotalSize, $this->get_name());
253
-    } else { // Multiple file mode
254
-      $FileNames = [];
255
-      $FileSizes = [];
256
-      $TotalSize = 0;
257
-      $Files = $this->Val['info']->Val['files']->Val;
258
-      if (isset($Files[0]->Val['path.utf-8'])) {
259
-        $PathKey = 'path.utf-8';
260
-      } else {
261
-        $PathKey = 'path';
262
-      }
263
-      foreach ($Files as $File) {
264
-        $FileSize = substr($File->Val['length'], 7);
265
-        $TotalSize += $FileSize;
266
-
267
-        $FileName = ltrim(implode('/', $File->Val[$PathKey]->Val), '/');
268
-        $FileSizes[] = $FileSize;
269
-        $FileNames[] = $FileName;
270
-      }
271
-      natcasesort($FileNames);
272
-      foreach ($FileNames as $Index => $FileName) {
273
-        $FileList[] = array($FileSizes[$Index], $FileName);
274
-      }
232
+class TORRENT extends BENCODE_DICT
233
+{
234
+    public function dump()
235
+    {
236
+        // Convenience function used for testing and figuring out how we store the data
237
+        print_r($this->Val);
238
+    }
239
+
240
+    public function dump_data()
241
+    {
242
+        // Function which serializes $this->Val for storage
243
+        return base64_encode(serialize($this->Val));
275
     }
244
     }
276
-    return array($TotalSize, $FileList);
277
-  }
278
-
279
-  function get_name() {
280
-    if (isset($this->Val['info']->Val['name.utf-8'])) {
281
-      return $this->Val['info']->Val['name.utf-8'];
282
-    } else {
283
-      return $this->Val['info']->Val['name'];
245
+
246
+    public function set_announce_url($Announce)
247
+    {
248
+        $this->Val['announce'] = $Announce;
249
+        ksort($this->Val);
250
+    }
251
+
252
+    // Returns an array of:
253
+    //  * the files in the torrent
254
+    //  * the total size of files described therein
255
+    public function file_list()
256
+    {
257
+        $FileList = [];
258
+        if (!isset($this->Val['info']->Val['files'])) { // Single file mode
259
+            $TotalSize = substr($this->Val['info']->Val['length'], 7);
260
+            $FileList[] = array($TotalSize, $this->get_name());
261
+        } else { // Multiple file mode
262
+            $FileNames = [];
263
+            $FileSizes = [];
264
+            $TotalSize = 0;
265
+            $Files = $this->Val['info']->Val['files']->Val;
266
+            if (isset($Files[0]->Val['path.utf-8'])) {
267
+                $PathKey = 'path.utf-8';
268
+            } else {
269
+                $PathKey = 'path';
270
+            }
271
+            foreach ($Files as $File) {
272
+                $FileSize = substr($File->Val['length'], 7);
273
+                $TotalSize += $FileSize;
274
+
275
+                $FileName = ltrim(implode('/', $File->Val[$PathKey]->Val), '/');
276
+                $FileSizes[] = $FileSize;
277
+                $FileNames[] = $FileName;
278
+            }
279
+            natcasesort($FileNames);
280
+            foreach ($FileNames as $Index => $FileName) {
281
+                $FileList[] = array($FileSizes[$Index], $FileName);
282
+            }
283
+        }
284
+        return array($TotalSize, $FileList);
285
+    }
286
+
287
+    public function get_name()
288
+    {
289
+        if (isset($this->Val['info']->Val['name.utf-8'])) {
290
+            return $this->Val['info']->Val['name.utf-8'];
291
+        } else {
292
+            return $this->Val['info']->Val['name'];
293
+        }
284
     }
294
     }
285
-  }
286
 
295
 
287
-  function make_private() {
288
-    //----- The following properties do not affect the infohash:
296
+    public function make_private()
297
+    {
298
+        //----- The following properties do not affect the infohash:
289
 
299
 
290
-    // anounce-list is an unofficial extension to the protocol
291
-    // that allows for multiple trackers per torrent
292
-    unset($this->Val['announce-list']);
300
+        // anounce-list is an unofficial extension to the protocol
301
+        // that allows for multiple trackers per torrent
302
+        unset($this->Val['announce-list']);
293
 
303
 
294
-    // Bitcomet & Azureus cache peers in here
295
-    unset($this->Val['nodes']);
304
+        // Bitcomet & Azureus cache peers in here
305
+        unset($this->Val['nodes']);
296
 
306
 
297
-    // Azureus stores the dht_backup_enable flag here
298
-    unset($this->Val['azureus_properties']);
307
+        // Azureus stores the dht_backup_enable flag here
308
+        unset($this->Val['azureus_properties']);
299
 
309
 
300
-    // Remove web-seeds
301
-    unset($this->Val['url-list']);
310
+        // Remove web-seeds
311
+        unset($this->Val['url-list']);
302
 
312
 
303
-    // Remove libtorrent resume info
304
-    unset($this->Val['libtorrent_resume']);
313
+        // Remove libtorrent resume info
314
+        unset($this->Val['libtorrent_resume']);
305
 
315
 
306
-    //----- End properties that do not affect the infohash
316
+        //----- End properties that do not affect the infohash
307
 
317
 
308
-    if (!empty($this->Val['info']->Val['private']) && $this->Val['info']->Val['private'] == '[*INT*]1') {
309
-      return true;
310
-    } else {
311
-      // Torrent is not private!
312
-      // add private tracker flag and sort info dictionary
313
-      $this->Val['info']->Val['private'] = '[*INT*]1';
314
-      ksort($this->Val['info']->Val);
315
-      return false;
318
+        if (!empty($this->Val['info']->Val['private']) && $this->Val['info']->Val['private'] == '[*INT*]1') {
319
+            return true;
320
+        } else {
321
+            // Torrent is not private!
322
+            // add private tracker flag and sort info dictionary
323
+            $this->Val['info']->Val['private'] = '[*INT*]1';
324
+            ksort($this->Val['info']->Val);
325
+            return false;
326
+        }
316
     }
327
     }
317
-  }
318
 }
328
 }
319
-?>

+ 258
- 266
classes/torrent_form.class.php View File

1
-<?
1
+<?php
2
 
2
 
3
 // This class is used in upload.php to display the upload form, and the edit
3
 // This class is used in upload.php to display the upload form, and the edit
4
 // section of torrents.php to display a shortened version of the same form
4
 // section of torrents.php to display a shortened version of the same form
5
 
5
 
6
-class TorrentForm {
7
-  var $UploadForm = '';
8
-  var $Categories = [];
9
-  var $Formats = [];
10
-  var $Bitrates = [];
11
-  var $Media = [];
12
-  var $MediaManaga = [];
13
-  var $Containers = [];
14
-  var $ContainersGames = [];
15
-  var $Codecs = [];
16
-  var $Resolutions = [];
17
-  var $AudioFormats = [];
18
-  var $Subbing = [];
19
-  var $Languages = [];
20
-  var $Platform = [];
21
-  var $NewTorrent = false;
22
-  var $Torrent = [];
23
-  var $Error = false;
24
-  var $TorrentID = false;
25
-  var $Disabled = '';
26
-  var $DisabledFlag = false;
6
+class TorrentForm
7
+{
8
+    public $UploadForm = '';
9
+    public $Categories = [];
10
+    public $Formats = [];
11
+    public $Bitrates = [];
12
+    public $Media = [];
13
+    public $MediaManaga = [];
14
+    public $Containers = [];
15
+    public $ContainersGames = [];
16
+    public $Codecs = [];
17
+    public $Resolutions = [];
18
+    public $AudioFormats = [];
19
+    public $Subbing = [];
20
+    public $Languages = [];
21
+    public $Platform = [];
22
+    public $NewTorrent = false;
23
+    public $Torrent = [];
24
+    public $Error = false;
25
+    public $TorrentID = false;
26
+    public $Disabled = '';
27
+    public $DisabledFlag = false;
27
 
28
 
28
-  function __construct($Torrent = false, $Error = false, $NewTorrent = true) {
29
+    public function __construct($Torrent = false, $Error = false, $NewTorrent = true)
30
+    {
31
+        $this->NewTorrent = $NewTorrent;
32
+        $this->Torrent = $Torrent;
33
+        $this->Error = $Error;
29
 
34
 
30
-    $this->NewTorrent = $NewTorrent;
31
-    $this->Torrent = $Torrent;
32
-    $this->Error = $Error;
35
+        global $UploadForm, $Categories, $Formats, $Bitrates, $Media, $MediaManga, $TorrentID, $Containers, $ContainersGames, $Codecs, $Resolutions, $AudioFormats, $Subbing, $Languages, $Platform, $Archives, $ArchivesManga;
33
 
36
 
34
-    global $UploadForm, $Categories, $Formats, $Bitrates, $Media, $MediaManga, $TorrentID, $Containers, $ContainersGames, $Codecs, $Resolutions, $AudioFormats, $Subbing, $Languages, $Platform, $Archives, $ArchivesManga;
37
+        $this->UploadForm = $UploadForm;
38
+        $this->Categories = $Categories;
39
+        $this->Formats = $Formats;
40
+        $this->Bitrates = $Bitrates;
41
+        $this->Media = $Media;
42
+        $this->MediaManga = $MediaManga;
43
+        $this->Containers = $Containers;
44
+        $this->ContainersGames = $ContainersGames;
45
+        $this->Codecs = $Codecs;
46
+        $this->Resolutions = $Resolutions;
47
+        $this->AudioFormats = $AudioFormats;
48
+        $this->Subbing = $Subbing;
49
+        $this->Languages = $Languages;
50
+        $this->TorrentID = $TorrentID;
51
+        $this->Platform = $Platform;
52
+        $this->Archives = $Archives;
53
+        $this->ArchivesManga = $ArchivesManga;
35
 
54
 
36
-    $this->UploadForm = $UploadForm;
37
-    $this->Categories = $Categories;
38
-    $this->Formats = $Formats;
39
-    $this->Bitrates = $Bitrates;
40
-    $this->Media = $Media;
41
-    $this->MediaManga = $MediaManga;
42
-    $this->Containers = $Containers;
43
-    $this->ContainersGames = $ContainersGames;
44
-    $this->Codecs = $Codecs;
45
-    $this->Resolutions = $Resolutions;
46
-    $this->AudioFormats = $AudioFormats;
47
-    $this->Subbing = $Subbing;
48
-    $this->Languages = $Languages;
49
-    $this->TorrentID = $TorrentID;
50
-    $this->Platform = $Platform;
51
-    $this->Archives = $Archives;
52
-    $this->ArchivesManga = $ArchivesManga;
53
-
54
-    if ($this->Torrent && $this->Torrent['GroupID']) {
55
-      $this->Disabled = ' readonly="readonly"';
56
-      $this->DisabledFlag = true;
55
+        if ($this->Torrent && $this->Torrent['GroupID']) {
56
+            $this->Disabled = ' readonly="readonly"';
57
+            $this->DisabledFlag = true;
58
+        }
57
     }
59
     }
58
-  }
59
 
60
 
60
-  function head() {
61
-    G::$DB->query("
61
+    public function head()
62
+    {
63
+        G::$DB->query("
62
       SELECT COUNT(ID)
64
       SELECT COUNT(ID)
63
       FROM torrents
65
       FROM torrents
64
       WHERE UserID = ?", G::$LoggedUser['ID']);
66
       WHERE UserID = ?", G::$LoggedUser['ID']);
65
-    list($Uploads) = G::$DB->next_record();
66
-?>
67
+        list($Uploads) = G::$DB->next_record(); ?>
67
 
68
 
68
 <div class="thin">
69
 <div class="thin">
69
-<?    if ($this->NewTorrent) { ?>
70
+        <?php    if ($this->NewTorrent) { ?>
70
   <p style="text-align: center;">
71
   <p style="text-align: center;">
71
     If you would like to use your own torrent file, add the following to it:<br />
72
     If you would like to use your own torrent file, add the following to it:<br />
72
-<?      $Announces = call_user_func_array('array_merge', ANNOUNCE_URLS);
73
-        foreach ($Announces as $Announce) {
74
-?>
73
+            <?php      $Announces = call_user_func_array('array_merge', ANNOUNCE_URLS);
74
+            foreach ($Announces as $Announce) {
75
+                ?>
75
     Announce: <input type="text" value="<?=$Announce . '/' . G::$LoggedUser['torrent_pass'] . '/announce'?>" size="74" onclick="this.select();" readonly="readonly" /> <br />
76
     Announce: <input type="text" value="<?=$Announce . '/' . G::$LoggedUser['torrent_pass'] . '/announce'?>" size="74" onclick="this.select();" readonly="readonly" /> <br />
76
-<?      } ?>
77
+                <?php
78
+            } ?>
77
 Source: <input type="text" value="<?=Users::get_upload_sources()[0]?>" size="20" onclick="this.select();" readonly="readonly" />
79
 Source: <input type="text" value="<?=Users::get_upload_sources()[0]?>" size="20" onclick="this.select();" readonly="readonly" />
78
     <p style="text-align: center;">
80
     <p style="text-align: center;">
79
         Otherwise, add none of it and simply redownload the torrent file after uploading it. All of the above data will be added to it by the site.<br /><br />
81
         Otherwise, add none of it and simply redownload the torrent file after uploading it. All of the above data will be added to it by the site.<br /><br />
82
       </strong>
84
       </strong>
83
     </p>
85
     </p>
84
   </p>
86
   </p>
85
-<?    }
86
-    if ($this->Error) {
87
-      echo "\t".'<p style="color: red; text-align: center;">'.$this->Error."</p>\n";
88
-    }
89
-?>
87
+        <?php    }
88
+        if ($this->Error) {
89
+            echo "\t".'<p style="color: red; text-align: center;">'.$this->Error."</p>\n";
90
+        } ?>
90
   <form class="create_form box pad" name="torrent" action="" enctype="multipart/form-data" method="post" onsubmit="$('#post').raw().disabled = 'disabled';">
91
   <form class="create_form box pad" name="torrent" action="" enctype="multipart/form-data" method="post" onsubmit="$('#post').raw().disabled = 'disabled';">
91
     <div>
92
     <div>
92
       <input type="hidden" name="submit" value="true" />
93
       <input type="hidden" name="submit" value="true" />
93
       <input type="hidden" name="auth" value="<?=G::$LoggedUser['AuthKey']?>" />
94
       <input type="hidden" name="auth" value="<?=G::$LoggedUser['AuthKey']?>" />
94
-<?    if (!$this->NewTorrent) { ?>
95
+        <?php    if (!$this->NewTorrent) { ?>
95
       <input type="hidden" name="action" value="takeedit" />
96
       <input type="hidden" name="action" value="takeedit" />
96
       <input type="hidden" name="torrentid" value="<?=display_str($this->TorrentID)?>" />
97
       <input type="hidden" name="torrentid" value="<?=display_str($this->TorrentID)?>" />
97
       <input type="hidden" name="type" value="<?=display_str($this->Torrent['CategoryID']-1)?>" />
98
       <input type="hidden" name="type" value="<?=display_str($this->Torrent['CategoryID']-1)?>" />
98
-<?
99
-    } else {
100
-      if ($this->Torrent && $this->Torrent['GroupID']) {
101
-?>
99
+            <?php
100
+        } else {
101
+            if ($this->Torrent && $this->Torrent['GroupID']) {
102
+                ?>
102
       <input type="hidden" name="groupid" value="<?=display_str($this->Torrent['GroupID'])?>" />
103
       <input type="hidden" name="groupid" value="<?=display_str($this->Torrent['GroupID'])?>" />
103
       <input type="hidden" name="type" value="<?=display_str($this->Torrent['CategoryID']-1)?>" />
104
       <input type="hidden" name="type" value="<?=display_str($this->Torrent['CategoryID']-1)?>" />
104
-<?
105
-      }
106
-      if ($this->Torrent && ($this->Torrent['RequestID'] ?? false)) {
107
-?>
105
+                <?php
106
+            }
107
+            if ($this->Torrent && ($this->Torrent['RequestID'] ?? false)) {
108
+                ?>
108
       <input type="hidden" name="requestid" value="<?=display_str($this->Torrent['RequestID'])?>" />
109
       <input type="hidden" name="requestid" value="<?=display_str($this->Torrent['RequestID'])?>" />
109
-<?
110
-      }
111
-    }
112
-?>
110
+                <?php
111
+            }
112
+        } ?>
113
     </div>
113
     </div>
114
-<?    if ($this->NewTorrent) { ?>
114
+        <?php    if ($this->NewTorrent) { ?>
115
     <table cellpadding="3" cellspacing="1" border="0" class="layout" width="100%">
115
     <table cellpadding="3" cellspacing="1" border="0" class="layout" width="100%">
116
       <tr>
116
       <tr>
117
         <td class="label">Torrent file</td>
117
         <td class="label">Torrent file</td>
121
         <td class="label">Type</td>
121
         <td class="label">Type</td>
122
         <td>
122
         <td>
123
           <select id="categories" name="type" onchange="Categories()"<?=($this->DisabledFlag) ? ' disabled="disabled"' : ''?>>
123
           <select id="categories" name="type" onchange="Categories()"<?=($this->DisabledFlag) ? ' disabled="disabled"' : ''?>>
124
-<?
125
-      foreach (Misc::display_array($this->Categories) as $Index => $Cat) {
126
-        echo "\t\t\t\t\t\t<option value=\"$Index\"";
127
-        if ($Cat == $this->Torrent['CategoryName']) {
128
-          echo ' selected="selected"';
129
-        }
130
-        echo ">$Cat</option>\n";
131
-      }
132
-?>
124
+            <?php
125
+            foreach (Misc::display_array($this->Categories) as $Index => $Cat) {
126
+                echo "\t\t\t\t\t\t<option value=\"$Index\"";
127
+                if ($Cat == $this->Torrent['CategoryName']) {
128
+                    echo ' selected="selected"';
129
+                }
130
+                echo ">$Cat</option>\n";
131
+            }
132
+            ?>
133
           </select>
133
           </select>
134
         </td>
134
         </td>
135
       </tr>
135
       </tr>
136
     </table>
136
     </table>
137
-<?    }//if ?>
137
+        <?php    }//if?>
138
     <div id="dynamic_form">
138
     <div id="dynamic_form">
139
-<?
140
-  }
139
+        <?php
140
+    }
141
 
141
 
142
 
142
 
143
-  function foot() {
144
-    $Torrent = $this->Torrent;
145
-?>
143
+    public function foot()
144
+    {
145
+        $Torrent = $this->Torrent; ?>
146
     </div>
146
     </div>
147
     <table cellpadding="3" cellspacing="1" border="0" class="layout slice" width="100%">
147
     <table cellpadding="3" cellspacing="1" border="0" class="layout slice" width="100%">
148
-<?
149
-    if (!$this->NewTorrent) {
150
-      if (check_perms('torrents_freeleech')) {
151
-?>
148
+        <?php
149
+        if (!$this->NewTorrent) {
150
+            if (check_perms('torrents_freeleech')) {
151
+                ?>
152
       <tr id="freetorrent">
152
       <tr id="freetorrent">
153
         <td class="label">Freeleech</td>
153
         <td class="label">Freeleech</td>
154
         <td>
154
         <td>
155
           <select name="freeleech">
155
           <select name="freeleech">
156
-<?
157
-        $FL = array("Normal", "Free", "Neutral");
158
-        foreach ($FL as $Key => $Name) {
159
-?>
156
+                <?php
157
+                $FL = array("Normal", "Free", "Neutral");
158
+                foreach ($FL as $Key => $Name) {
159
+                    ?>
160
             <option value="<?=$Key?>"<?=($Key == $Torrent['FreeTorrent'] ? ' selected="selected"' : '')?>><?=$Name?></option>
160
             <option value="<?=$Key?>"<?=($Key == $Torrent['FreeTorrent'] ? ' selected="selected"' : '')?>><?=$Name?></option>
161
-<?        } ?>
161
+                    <?php
162
+                } ?>
162
           </select>
163
           </select>
163
           because
164
           because
164
           <select name="freeleechtype">
165
           <select name="freeleechtype">
165
-<?
166
-        $FL = array("N/A", "Staff Pick", "Perma-FL", "Freeleechizer", "Site-Wide FL");
167
-        foreach ($FL as $Key => $Name) {
168
-?>
166
+                <?php
167
+                $FL = array("N/A", "Staff Pick", "Perma-FL", "Freeleechizer", "Site-Wide FL");
168
+                foreach ($FL as $Key => $Name) {
169
+                    ?>
169
             <option value="<?=$Key?>"<?=($Key == $Torrent['FreeLeechType'] ? ' selected="selected"' : '')?>><?=$Name?></option>
170
             <option value="<?=$Key?>"<?=($Key == $Torrent['FreeLeechType'] ? ' selected="selected"' : '')?>><?=$Name?></option>
170
-<?        } ?>
171
+                    <?php
172
+                } ?>
171
           </select>
173
           </select>
172
         </td>
174
         </td>
173
       </tr>
175
       </tr>
174
-<?
175
-      }
176
-    }
177
-?>
176
+                <?php
177
+            }
178
+        } ?>
178
       <tr>
179
       <tr>
179
         <td colspan="2" style="text-align: center;">
180
         <td colspan="2" style="text-align: center;">
180
           <p>Be sure that your torrent is approved by the <a href="rules.php?p=upload" target="_blank">rules</a>. Not doing this will result in a <strong class="important_text">warning</strong> or <strong class="important_text">worse</strong>.</p>
181
           <p>Be sure that your torrent is approved by the <a href="rules.php?p=upload" target="_blank">rules</a>. Not doing this will result in a <strong class="important_text">warning</strong> or <strong class="important_text">worse</strong>.</p>
181
-<?    if ($this->NewTorrent) { ?>
182
+        <?php    if ($this->NewTorrent) { ?>
182
           <p>After uploading the torrent, you will have a one hour grace period during which no one other than you can fill requests with this torrent. Make use of this time wisely, and <a href="requests.php">search the list of requests</a>.</p>
183
           <p>After uploading the torrent, you will have a one hour grace period during which no one other than you can fill requests with this torrent. Make use of this time wisely, and <a href="requests.php">search the list of requests</a>.</p>
183
-<?    } ?>
184
-        <input id="post" type="submit"<? if ($this->NewTorrent) { echo ' value="Upload torrent"'; } else { echo ' value="Edit torrent"';} ?> />
184
+        <?php    } ?>
185
+        <input id="post" type="submit"<?php if ($this->NewTorrent) {
186
+            echo ' value="Upload torrent"';
187
+                                      } else {
188
+                                          echo ' value="Edit torrent"';
189
+                                      } ?> />
185
         </td>
190
         </td>
186
       </tr>
191
       </tr>
187
     </table>
192
     </table>
188
   </form>
193
   </form>
189
 </div>
194
 </div>
190
-<?
191
-  }
195
+        <?php
196
+    }
192
 
197
 
193
 
198
 
194
-  function upload_form() {
195
-    $QueryID = G::$DB->get_query_id();
196
-    $this->head();
197
-    $Torrent = $this->Torrent;
198
-?>
199
+    public function upload_form()
200
+    {
201
+        $QueryID = G::$DB->get_query_id();
202
+        $this->head();
203
+        $Torrent = $this->Torrent; ?>
199
     <table cellpadding="3" cellspacing="1" border="0" class="layout slice" width="100%">
204
     <table cellpadding="3" cellspacing="1" border="0" class="layout slice" width="100%">
200
-<? if ($this->NewTorrent) { ?>
205
+        <?php if ($this->NewTorrent) { ?>
201
       <tr id="javdb_tr">
206
       <tr id="javdb_tr">
202
         <td class="label tooltip" title='Enter a JAV catalogue number, e.g., "CND-060"'>Catalogue Number</td>
207
         <td class="label tooltip" title='Enter a JAV catalogue number, e.g., "CND-060"'>Catalogue Number</td>
203
         <td>
208
         <td>
204
           <input type="text" id="catalogue" name="catalogue" size="10" value="<?=display_str($Torrent['CatalogueNumber']) ?>" <?=$this->Disabled?>/>
209
           <input type="text" id="catalogue" name="catalogue" size="10" value="<?=display_str($Torrent['CatalogueNumber']) ?>" <?=$this->Disabled?>/>
205
-<? if (!$this->DisabledFlag) { ?>
210
+            <?php if (!$this->DisabledFlag) { ?>
206
           <input type="button" autofill="jav" value="Autofill"></input>
211
           <input type="button" autofill="jav" value="Autofill"></input>
207
-<? } ?>
212
+            <?php } ?>
208
         </td>
213
         </td>
209
       </tr>
214
       </tr>
210
       <tr id="anidb_tr" class="hidden">
215
       <tr id="anidb_tr" class="hidden">
211
         <td class="label">AniDB Autofill (optional)</td>
216
         <td class="label">AniDB Autofill (optional)</td>
212
         <td>
217
         <td>
213
           <input type="text" id="anidb" size="10" <?=$this->Disabled?>/>
218
           <input type="text" id="anidb" size="10" <?=$this->Disabled?>/>
214
-<? if (!$this->DisabledFlag) { ?>
219
+            <?php if (!$this->DisabledFlag) { ?>
215
           <input type="button" autofill="anime" value="Autofill"/>
220
           <input type="button" autofill="anime" value="Autofill"/>
216
-<? } ?>
221
+            <?php } ?>
217
         </td>
222
         </td>
218
       </tr>
223
       </tr>
219
       <tr id="ehentai_tr" class="hidden">
224
       <tr id="ehentai_tr" class="hidden">
220
         <td class="label">e-hentai URL (optional)</td>
225
         <td class="label">e-hentai URL (optional)</td>
221
         <td>
226
         <td>
222
           <input type="text" id="catalogue" size="50" <?=$this->Disabled?> />
227
           <input type="text" id="catalogue" size="50" <?=$this->Disabled?> />
223
-<? if (!$this->DisabledFlag) { ?>
228
+            <?php if (!$this->DisabledFlag) { ?>
224
           <input type="button" autofill="douj" value="Autofill"/>
229
           <input type="button" autofill="douj" value="Autofill"/>
225
-<? } ?>
230
+            <?php } ?>
226
         </td>
231
         </td>
227
       </tr>
232
       </tr>
228
       <tr id="title_tr">
233
       <tr id="title_tr">
240
       <tr id="idols_tr">
245
       <tr id="idols_tr">
241
         <td class="label">Idol(s)</td>
246
         <td class="label">Idol(s)</td>
242
         <td id="idolfields">
247
         <td id="idolfields">
243
-<?      if (!empty($Torrent['Artists'])) {
244
-          foreach ($Torrent['Artists'] as $Num => $Artist) { ?>
248
+            <?php      if (!empty($Torrent['Artists'])) {
249
+                foreach ($Torrent['Artists'] as $Num => $Artist) { ?>
245
             <input type="text" id="idols_<?=$Num?>" name="idols[]" size="45" value="<?=display_str($Artist['name'])?>" <?=$this->Disabled?>/>
250
             <input type="text" id="idols_<?=$Num?>" name="idols[]" size="45" value="<?=display_str($Artist['name'])?>" <?=$this->Disabled?>/>
246
-            <? if ($Num == 0) { ?>
251
+                        <?php if ($Num == 0) { ?>
247
               <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
252
               <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
248
-            <? }
249
-            }
250
-          } else { ?>
253
+                        <?php }
254
+                }
255
+            } else { ?>
251
             <input type="text" id="idols_0" name="idols[]" size="45" value="" <?=$this->Disabled?> />
256
             <input type="text" id="idols_0" name="idols[]" size="45" value="" <?=$this->Disabled?> />
252
             <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
257
             <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
253
-<?        } ?>
258
+            <?php        } ?>
254
         </td>
259
         </td>
255
       </tr>
260
       </tr>
256
       <tr id="studio_tr">
261
       <tr id="studio_tr">
273
         <td class="label">DLsite ID</td>
278
         <td class="label">DLsite ID</td>
274
         <td><input type="text" id="dlsiteid" name="dlsiteid" size="8" maxlength="8" value="<?=display_str($Torrent['DLsiteID']??'')?>" <?=$this->Disabled?>/></td>
279
         <td><input type="text" id="dlsiteid" name="dlsiteid" size="8" maxlength="8" value="<?=display_str($Torrent['DLsiteID']??'')?>" <?=$this->Disabled?>/></td>
275
       </tr>
280
       </tr>
276
-<? } ?>
281
+        <?php } ?>
277
       <tr id="media_tr">
282
       <tr id="media_tr">
278
         <td class="label">Media</td>
283
         <td class="label">Media</td>
279
         <td>
284
         <td>
280
           <select name="media">
285
           <select name="media">
281
             <option>---</option>
286
             <option>---</option>
282
-<?
283
-    foreach($this->Media as $Media) {
284
-      echo "\t\t\t\t\t\t<option value=\"$Media\"";
285
-      if ($Media == ($Torrent['Media'] ?? false)) {
286
-        echo " selected";
287
-      }
288
-      echo ">$Media</option>\n";
289
-    }
290
-?>
287
+        <?php
288
+        foreach ($this->Media as $Media) {
289
+            echo "\t\t\t\t\t\t<option value=\"$Media\"";
290
+            if ($Media == ($Torrent['Media'] ?? false)) {
291
+                echo " selected";
292
+            }
293
+            echo ">$Media</option>\n";
294
+        } ?>
291
           </select>
295
           </select>
292
         </td>
296
         </td>
293
       </tr>
297
       </tr>
296
         <td>
300
         <td>
297
           <select name="media">
301
           <select name="media">
298
             <option>---</option>
302
             <option>---</option>
299
-<?
300
-    foreach($this->MediaManga as $Media) {
301
-      echo "\t\t\t\t\t\t<option value=\"$Media\"";
302
-      if ($Media == ($Torrent['Media'] ?? false)) {
303
-        echo " selected";
304
-      }
305
-      echo ">$Media</option>\n";
306
-    }
307
-?>
303
+        <?php
304
+        foreach ($this->MediaManga as $Media) {
305
+            echo "\t\t\t\t\t\t<option value=\"$Media\"";
306
+            if ($Media == ($Torrent['Media'] ?? false)) {
307
+                echo " selected";
308
+            }
309
+            echo ">$Media</option>\n";
310
+        } ?>
308
           </select>
311
           </select>
309
         </td>
312
         </td>
310
       </tr>
313
       </tr>
313
         <td>
316
         <td>
314
           <select id="platform" name="media">
317
           <select id="platform" name="media">
315
             <option>---</option>
318
             <option>---</option>
316
-<?
317
-    foreach($this->Platform as $Platform) {
318
-      echo "\t\t\t\t\t\t<option value=\"$Platform\"";
319
-      if ($Platform == ($Torrent['Media'] ?? false)) {
320
-        echo " selected";
321
-      }
322
-      echo ">$Platform</option>\n";
323
-    }
324
-?>
319
+        <?php
320
+        foreach ($this->Platform as $Platform) {
321
+            echo "\t\t\t\t\t\t<option value=\"$Platform\"";
322
+            if ($Platform == ($Torrent['Media'] ?? false)) {
323
+                echo " selected";
324
+            }
325
+            echo ">$Platform</option>\n";
326
+        } ?>
325
           </select>
327
           </select>
326
         </td>
328
         </td>
327
       </tr>
329
       </tr>
330
         <td>
332
         <td>
331
           <select name='archive'>
333
           <select name='archive'>
332
             <option>---</option>
334
             <option>---</option>
333
-<?
334
-    foreach($this->Archives as $Archive) {
335
-      echo "\t\t\t\t\t\t<option value=\"$Archive\"";
336
-      if ($Archive == ($Torrent['Archive'] ?? false)) {
337
-        echo ' selected';
338
-      }
339
-      echo ">$Archive</option>\n";
340
-    }
341
-?>
335
+        <?php
336
+        foreach ($this->Archives as $Archive) {
337
+            echo "\t\t\t\t\t\t<option value=\"$Archive\"";
338
+            if ($Archive == ($Torrent['Archive'] ?? false)) {
339
+                echo ' selected';
340
+            }
341
+            echo ">$Archive</option>\n";
342
+        } ?>
342
           </select>
343
           </select>
343
         </td>
344
         </td>
344
       </tr>
345
       </tr>
347
         <td>
348
         <td>
348
           <select name='archive'>
349
           <select name='archive'>
349
             <option>---</option>
350
             <option>---</option>
350
-<?
351
-    foreach(array_merge($this->Archives, $this->ArchivesManga) as $Archive) {
352
-      echo "\t\t\t\t\t\t<option value=\"$Archive\"";
353
-      if ($Archive == ($Torrent['Archive'] ?? false)) {
354
-        echo ' selected';
355
-      }
356
-      echo ">$Archive</option>\n";
357
-    }
358
-?>
351
+        <?php
352
+        foreach (array_merge($this->Archives, $this->ArchivesManga) as $Archive) {
353
+            echo "\t\t\t\t\t\t<option value=\"$Archive\"";
354
+            if ($Archive == ($Torrent['Archive'] ?? false)) {
355
+                echo ' selected';
356
+            }
357
+            echo ">$Archive</option>\n";
358
+        } ?>
359
           </select>
359
           </select>
360
         </td>
360
         </td>
361
       </tr>
361
       </tr>
364
         <td>
364
         <td>
365
           <select name="container">
365
           <select name="container">
366
             <option>---</option>
366
             <option>---</option>
367
-<?
368
-    foreach($this->Containers as $Cont) {
369
-      echo "\t\t\t\t\t\t<option value=\"$Cont\"";
370
-      if ($Cont == ($Torrent['Container'] ?? false)) {
371
-        echo " selected";
372
-      }
373
-      echo ">$Cont</option>\n";
374
-    }
375
-?>
367
+        <?php
368
+        foreach ($this->Containers as $Cont) {
369
+            echo "\t\t\t\t\t\t<option value=\"$Cont\"";
370
+            if ($Cont == ($Torrent['Container'] ?? false)) {
371
+                echo " selected";
372
+            }
373
+            echo ">$Cont</option>\n";
374
+        } ?>
376
           </select>
375
           </select>
377
         </td>
376
         </td>
378
       </tr>
377
       </tr>
381
         <td>
380
         <td>
382
           <select id="container" name="container">
381
           <select id="container" name="container">
383
             <option>---</option>
382
             <option>---</option>
384
-<?
385
-    foreach($this->ContainersGames as $Container) {
386
-      echo "\t\t\t\t\t\t<option value=\"$Container\"";
387
-      if ($Container == ($Torrent['Container'] ?? false)) {
388
-        echo " selected";
389
-      }
390
-      echo ">$Container</option>\n";
391
-    }
392
-?>
383
+        <?php
384
+        foreach ($this->ContainersGames as $Container) {
385
+            echo "\t\t\t\t\t\t<option value=\"$Container\"";
386
+            if ($Container == ($Torrent['Container'] ?? false)) {
387
+                echo " selected";
388
+            }
389
+            echo ">$Container</option>\n";
390
+        } ?>
393
           </select>
391
           </select>
394
         </td>
392
         </td>
395
       </tr>
393
       </tr>
398
         <td>
396
         <td>
399
           <select name="codec">
397
           <select name="codec">
400
             <option>---</option>
398
             <option>---</option>
401
-<?
402
-    foreach($this->Codecs as $Codec) {
403
-      echo "\t\t\t\t\t\t<option value=\"$Codec\"";
404
-      if ($Codec == ($Torrent['Codec'] ?? false)) {
405
-        echo " selected";
406
-      }
407
-      echo ">$Codec</option>\n";
408
-    }
409
-?>
399
+        <?php
400
+        foreach ($this->Codecs as $Codec) {
401
+            echo "\t\t\t\t\t\t<option value=\"$Codec\"";
402
+            if ($Codec == ($Torrent['Codec'] ?? false)) {
403
+                echo " selected";
404
+            }
405
+            echo ">$Codec</option>\n";
406
+        } ?>
410
           </select>
407
           </select>
411
         </td>
408
         </td>
412
       </tr>
409
       </tr>
415
         <td>
412
         <td>
416
           <select id="ressel" name="ressel" onchange="SetResolution()">
413
           <select id="ressel" name="ressel" onchange="SetResolution()">
417
             <option value="">---</option>
414
             <option value="">---</option>
418
-<?
419
-    foreach($this->Resolutions as $Res) {
420
-      echo "\t\t\t\t\t\t<option value=\"$Res\"";
421
-      if ($Res == ($Torrent['Resolution'] ?? false) || (!isset($FoundRes) && ($Torrent['Resolution'] ?? false) && $Res == "Other")) {
422
-        echo " selected";
423
-        $FoundRes = true;
424
-      }
425
-      echo ">$Res</option>\n";
426
-    }
427
-?>
415
+        <?php
416
+        foreach ($this->Resolutions as $Res) {
417
+            echo "\t\t\t\t\t\t<option value=\"$Res\"";
418
+            if ($Res == ($Torrent['Resolution'] ?? false) || (!isset($FoundRes) && ($Torrent['Resolution'] ?? false) && $Res == "Other")) {
419
+                echo " selected";
420
+                $FoundRes = true;
421
+            }
422
+            echo ">$Res</option>\n";
423
+        } ?>
428
           </select>
424
           </select>
429
           <input type="text" id="resolution" name="resolution" size="10" class="hidden tooltip" pattern="[0-9]+x[0-9]+" title='Enter "Other" resolutions in the form ###x###' value="<?=($Torrent['Resolution']??'')?>" readonly></input>
425
           <input type="text" id="resolution" name="resolution" size="10" class="hidden tooltip" pattern="[0-9]+x[0-9]+" title='Enter "Other" resolutions in the form ###x###' value="<?=($Torrent['Resolution']??'')?>" readonly></input>
430
           <script>
426
           <script>
440
         <td>
436
         <td>
441
           <select name="audioformat">
437
           <select name="audioformat">
442
             <option>---</option>
438
             <option>---</option>
443
-<?
444
-    foreach($this->AudioFormats as $AudioFormat) {
445
-      echo "\t\t\t\t\t\t<option value=\"$AudioFormat\"";
446
-      if  ($AudioFormat == ($Torrent['AudioFormat'] ?? false)) {
447
-        echo " selected";
448
-      }
449
-      echo ">$AudioFormat</option>\n";
450
-    }
451
-?>
439
+        <?php
440
+        foreach ($this->AudioFormats as $AudioFormat) {
441
+            echo "\t\t\t\t\t\t<option value=\"$AudioFormat\"";
442
+            if ($AudioFormat == ($Torrent['AudioFormat'] ?? false)) {
443
+                echo " selected";
444
+            }
445
+            echo ">$AudioFormat</option>\n";
446
+        } ?>
452
           </select>
447
           </select>
453
         </td>
448
         </td>
454
       </tr>
449
       </tr>
457
         <td>
452
         <td>
458
           <select name="lang">
453
           <select name="lang">
459
             <option>---</option>
454
             <option>---</option>
460
-<?
461
-    foreach($this->Languages as $Language) {
462
-      echo "\t\t\t\t\t\t<option value=\"$Language\"";
463
-      if ($Language == ($Torrent['Language'] ?? false)) {
464
-        echo " selected";
465
-      }
466
-      echo ">$Language</option>\n";
467
-    }
468
-?>
455
+        <?php
456
+        foreach ($this->Languages as $Language) {
457
+            echo "\t\t\t\t\t\t<option value=\"$Language\"";
458
+            if ($Language == ($Torrent['Language'] ?? false)) {
459
+                echo " selected";
460
+            }
461
+            echo ">$Language</option>\n";
462
+        } ?>
469
           </select>
463
           </select>
470
         </td>
464
         </td>
471
       </tr>
465
       </tr>
474
         <td>
468
         <td>
475
           <select name="sub">
469
           <select name="sub">
476
             <option>---</option>
470
             <option>---</option>
477
-<?
478
-    foreach($this->Subbing as $Subbing) {
479
-      echo "\t\t\t\t\t\t<option value=\"$Subbing\"";
480
-      if ($Subbing == ($Torrent['Subbing'] ?? false)) {
481
-        echo " selected";
482
-      }
483
-      echo ">$Subbing</option>\n";
484
-    }
485
-?>
471
+        <?php
472
+        foreach ($this->Subbing as $Subbing) {
473
+            echo "\t\t\t\t\t\t<option value=\"$Subbing\"";
474
+            if ($Subbing == ($Torrent['Subbing'] ?? false)) {
475
+                echo " selected";
476
+            }
477
+            echo ">$Subbing</option>\n";
478
+        } ?>
486
           </select>
479
           </select>
487
         </td>
480
         </td>
488
       </tr>
481
       </tr>
502
           <textarea name="mediainfo" id="mediainfo" onchange="MediaInfoExtract()"  rows="8" cols="60"><?=display_str($Torrent['MediaInfo']??'')?></textarea>
495
           <textarea name="mediainfo" id="mediainfo" onchange="MediaInfoExtract()"  rows="8" cols="60"><?=display_str($Torrent['MediaInfo']??'')?></textarea>
503
         </td>
496
         </td>
504
       </tr>
497
       </tr>
505
-<?    if ($this->NewTorrent) { ?>
498
+        <?php    if ($this->NewTorrent) { ?>
506
       <tr id="tags_tr">
499
       <tr id="tags_tr">
507
         <td class="label tooltip" title="Comma seperated list of tags">Tags</td>
500
         <td class="label tooltip" title="Comma seperated list of tags">Tags</td>
508
         <td>
501
         <td>
509
-<?
510
-  $GenreTags = G::$Cache->get_value('genre_tags');
511
-  if (!$GenreTags) {
512
-    $DB->query("
502
+            <?php
503
+            $GenreTags = G::$Cache->get_value('genre_tags');
504
+            if (!$GenreTags) {
505
+                $DB->query("
513
       SELECT Name
506
       SELECT Name
514
       FROM tags
507
       FROM tags
515
       WHERE TagType = 'genre'
508
       WHERE TagType = 'genre'
516
       ORDER BY Name");
509
       ORDER BY Name");
517
-    $GenreTags = $DB->collect('Name');
518
-    G::$Cache->cache_value('genre_tags', $GenreTags, 3600*6);
519
-  }
520
-?>
510
+                $GenreTags = $DB->collect('Name');
511
+                G::$Cache->cache_value('genre_tags', $GenreTags, 3600*6);
512
+            }
513
+            ?>
521
           <select id="genre_tags" name="genre_tags" onchange="add_tag(); return false;" <?=($this->DisabledFlag) ? ' disabled="disabled"' : ''?>>
514
           <select id="genre_tags" name="genre_tags" onchange="add_tag(); return false;" <?=($this->DisabledFlag) ? ' disabled="disabled"' : ''?>>
522
             <option>---</option>
515
             <option>---</option>
523
-<? foreach (Misc::display_array($GenreTags) as $Genre) { ?>
516
+            <?php foreach (Misc::display_array($GenreTags) as $Genre) { ?>
524
             <option value="<?=$Genre?>"><?=$Genre?></option>
517
             <option value="<?=$Genre?>"><?=$Genre?></option>
525
-<? } ?>
518
+            <?php } ?>
526
           </select>
519
           </select>
527
-          <input type="text" id="tags" name="tags" size="60" value="<?=display_str(implode(', ', explode(',', $Torrent['TagList']))) ?>"<? Users::has_autocomplete_enabled('other'); ?> />
520
+          <input type="text" id="tags" name="tags" size="60" value="<?=display_str(implode(', ', explode(',', $Torrent['TagList']))) ?>"<?php Users::has_autocomplete_enabled('other'); ?> />
528
           <p class="min_padding notes"></p>
521
           <p class="min_padding notes"></p>
529
         </td>
522
         </td>
530
       </tr>
523
       </tr>
532
         <td class="label">Cover Image</td>
525
         <td class="label">Cover Image</td>
533
         <td><input type="text" id="image" name="image" size="60" value="<?=display_str($Torrent['Image']) ?>"<?=$this->Disabled?> /></td>
526
         <td><input type="text" id="image" name="image" size="60" value="<?=display_str($Torrent['Image']) ?>"<?=$this->Disabled?> /></td>
534
       </tr>
527
       </tr>
535
-<? if (!$this->DisabledFlag && $this->NewTorrent) { ?>
528
+            <?php if (!$this->DisabledFlag && $this->NewTorrent) { ?>
536
       <tr id="screenshots_tr">
529
       <tr id="screenshots_tr">
537
         <td class="label">Screenshots</td>
530
         <td class="label">Screenshots</td>
538
         <td>
531
         <td>
540
           <p>Enter up to 10 links to samples for the torrent, one per line. The system will automatically remove malformed or invalid links, as well as any links after the 10th. Remember to consult the <a href="/rules.php?p=upload#h1.4">rules for adding screenshots</a>.</p>
533
           <p>Enter up to 10 links to samples for the torrent, one per line. The system will automatically remove malformed or invalid links, as well as any links after the 10th. Remember to consult the <a href="/rules.php?p=upload#h1.4">rules for adding screenshots</a>.</p>
541
           <p class="min_padding notes"></p>
534
           <p class="min_padding notes"></p>
542
       </tr>
535
       </tr>
543
-<? } ?>
536
+            <?php } ?>
544
       <tr id="group_desc_tr">
537
       <tr id="group_desc_tr">
545
         <td class="label">Torrent Group Description</td>
538
         <td class="label">Torrent Group Description</td>
546
         <td>
539
         <td>
547
           <p class="min_padding notes"></p>
540
           <p class="min_padding notes"></p>
548
-<?php new TEXTAREA_PREVIEW('album_desc', 'album_desc', display_str($Torrent['GroupDescription']), 60, 8, !$this->DisabledFlag, !$this->DisabledFlag, false, array($this->Disabled)); ?>
541
+            <?php new TEXTAREA_PREVIEW('album_desc', 'album_desc', display_str($Torrent['GroupDescription']), 60, 8, !$this->DisabledFlag, !$this->DisabledFlag, false, array($this->Disabled)); ?>
549
         </td>
542
         </td>
550
       </tr>
543
       </tr>
551
-<?    } ?>
544
+        <?php    } ?>
552
       <tr id="release_desc_tr">
545
       <tr id="release_desc_tr">
553
         <td class="label">Torrent Description (optional)</td>
546
         <td class="label">Torrent Description (optional)</td>
554
         <td>
547
         <td>
555
           <p class="min_padding notes"></p>
548
           <p class="min_padding notes"></p>
556
-<?php new TEXTAREA_PREVIEW('release_desc', 'release_desc', display_str($Torrent['TorrentDescription']??''), 60, 8); ?>
549
+        <?php new TEXTAREA_PREVIEW('release_desc', 'release_desc', display_str($Torrent['TorrentDescription']??''), 60, 8); ?>
557
         </td>
550
         </td>
558
       </tr>
551
       </tr>
559
       <tr id="anon_tr">
552
       <tr id="anon_tr">
562
       </tr>
555
       </tr>
563
     </table>
556
     </table>
564
 
557
 
565
-<?
566
-    $this->foot();
567
-    G::$DB->set_query_id($QueryID);
568
-  }
569
-
558
+        <?php
559
+        $this->foot();
560
+        G::$DB->set_query_id($QueryID);
561
+    }
570
 }
562
 }
571
 ?>
563
 ?>

+ 228
- 216
classes/torrentsdl.class.php View File

1
-<?
1
+<?php
2
 /**
2
 /**
3
  * Class for functions related to the features involving torrent downloads
3
  * Class for functions related to the features involving torrent downloads
4
  */
4
  */
5
-class TorrentsDL {
6
-  const ChunkSize = 100;
7
-  const MaxPathLength = 200;
8
-  private $QueryResult;
9
-  private $QueryRowNum = 0;
10
-  private $Zip;
11
-  private $IDBoundaries;
12
-  private $FailedFiles = [];
13
-  private $NumAdded = 0;
14
-  private $NumFound = 0;
15
-  private $Size = 0;
16
-  private $Title;
17
-  private $User;
18
-  private $AnnounceURL;
19
-  private $AnnounceList;
5
+class TorrentsDL
6
+{
7
+    const ChunkSize = 100;
8
+    const MaxPathLength = 200;
9
+    private $QueryResult;
10
+    private $QueryRowNum = 0;
11
+    private $Zip;
12
+    private $IDBoundaries;
13
+    private $FailedFiles = [];
14
+    private $NumAdded = 0;
15
+    private $NumFound = 0;
16
+    private $Size = 0;
17
+    private $Title;
18
+    private $User;
19
+    private $AnnounceURL;
20
+    private $AnnounceList;
20
 
21
 
21
-  /**
22
-   * Create a Zip object and store the query results
23
-   *
24
-   * @param mysqli_result $QueryResult results from a query on the collector pages
25
-   * @param string $Title name of the collection that will be created
26
-   * @param string $AnnounceURL URL to add to the created torrents
27
-   */
28
-  public function __construct(&$QueryResult, $Title) {
29
-    G::$Cache->InternalCache = false; // The internal cache is almost completely useless for this
30
-    Zip::unlimit(); // Need more memory and longer timeout
31
-    $this->QueryResult = $QueryResult;
32
-    $this->Title = $Title;
33
-    $this->User = G::$LoggedUser;
34
-    $this->AnnounceURL = ANNOUNCE_URLS[0][0]."/".G::$LoggedUser['torrent_pass']."/announce";
35
-    function add_passkey($Ann) {
36
-      return (is_array($Ann)) ? array_map('add_passkey', $Ann) : $Ann."/".G::$LoggedUser['torrent_pass']."/announce";
22
+    /**
23
+     * Create a Zip object and store the query results
24
+     *
25
+     * @param mysqli_result $QueryResult results from a query on the collector pages
26
+     * @param string $Title name of the collection that will be created
27
+     * @param string $AnnounceURL URL to add to the created torrents
28
+     */
29
+    public function __construct(&$QueryResult, $Title)
30
+    {
31
+        G::$Cache->InternalCache = false; // The internal cache is almost completely useless for this
32
+        Zip::unlimit(); // Need more memory and longer timeout
33
+        $this->QueryResult = $QueryResult;
34
+        $this->Title = $Title;
35
+        $this->User = G::$LoggedUser;
36
+        $this->AnnounceURL = ANNOUNCE_URLS[0][0]."/".G::$LoggedUser['torrent_pass']."/announce";
37
+        function add_passkey($Ann)
38
+        {
39
+            return (is_array($Ann)) ? array_map('add_passkey', $Ann) : $Ann."/".G::$LoggedUser['torrent_pass']."/announce";
40
+        }
41
+        $this->AnnounceList = (sizeof(ANNOUNCE_URLS) == 1 && sizeof(ANNOUNCE_URLS[0]) == 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS);
42
+        $this->Zip = new Zip(Misc::file_string($Title));
37
     }
43
     }
38
-    $this->AnnounceList = (sizeof(ANNOUNCE_URLS) == 1 && sizeof(ANNOUNCE_URLS[0]) == 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS);
39
-    $this->Zip = new Zip(Misc::file_string($Title));
40
-  }
41
 
44
 
42
-  /**
43
-   * Store the results from a DB query in smaller chunks to save memory
44
-   *
45
-   * @param string $Key the key to use in the result hash map
46
-   * @return array with results and torrent group IDs or false if there are no results left
47
-   */
48
-  public function get_downloads($Key) {
49
-    $GroupIDs = $Downloads = [];
50
-    $OldQuery = G::$DB->get_query_id();
51
-    G::$DB->set_query_id($this->QueryResult);
52
-    if (!isset($this->IDBoundaries)) {
53
-      if ($Key == 'TorrentID') {
54
-        $this->IDBoundaries = false;
55
-      } else {
56
-        $this->IDBoundaries = G::$DB->to_pair($Key, 'TorrentID', false);
57
-      }
58
-    }
59
-    $Found = 0;
60
-    while ($Download = G::$DB->next_record(MYSQLI_ASSOC, false)) {
61
-      if (!$this->IDBoundaries || $Download['TorrentID'] == $this->IDBoundaries[$Download[$Key]]) {
62
-        $Found++;
63
-        $Downloads[$Download[$Key]] = $Download;
64
-        $GroupIDs[$Download['TorrentID']] = $Download['GroupID'];
65
-        if ($Found >= self::ChunkSize) {
66
-          break;
45
+    /**
46
+     * Store the results from a DB query in smaller chunks to save memory
47
+     *
48
+     * @param string $Key the key to use in the result hash map
49
+     * @return array with results and torrent group IDs or false if there are no results left
50
+     */
51
+    public function get_downloads($Key)
52
+    {
53
+        $GroupIDs = $Downloads = [];
54
+        $OldQuery = G::$DB->get_query_id();
55
+        G::$DB->set_query_id($this->QueryResult);
56
+        if (!isset($this->IDBoundaries)) {
57
+            if ($Key == 'TorrentID') {
58
+                $this->IDBoundaries = false;
59
+            } else {
60
+                $this->IDBoundaries = G::$DB->to_pair($Key, 'TorrentID', false);
61
+            }
67
         }
62
         }
68
-      }
69
-    }
70
-    $this->NumFound += $Found;
71
-    G::$DB->set_query_id($OldQuery);
72
-    if (empty($Downloads)) {
73
-      return false;
63
+        $Found = 0;
64
+        while ($Download = G::$DB->next_record(MYSQLI_ASSOC, false)) {
65
+            if (!$this->IDBoundaries || $Download['TorrentID'] == $this->IDBoundaries[$Download[$Key]]) {
66
+                $Found++;
67
+                $Downloads[$Download[$Key]] = $Download;
68
+                $GroupIDs[$Download['TorrentID']] = $Download['GroupID'];
69
+                if ($Found >= self::ChunkSize) {
70
+                    break;
71
+                }
72
+            }
73
+        }
74
+        $this->NumFound += $Found;
75
+        G::$DB->set_query_id($OldQuery);
76
+        if (empty($Downloads)) {
77
+            return false;
78
+        }
79
+        return array($Downloads, $GroupIDs);
74
     }
80
     }
75
-    return array($Downloads, $GroupIDs);
76
-  }
77
 
81
 
78
-  /**
79
-   * Add a file to the zip archive
80
-   *
81
-   * @param string $TorrentData bencoded torrent without announce url (new format) or TORRENT object (old format)
82
-   * @param array $Info file info stored as an array with at least the keys
83
-   *  Artist, Name, Year, Media, Format, Encoding and TorrentID
84
-   * @param string $FolderName folder name
85
-   */
86
-  public function add_file(&$TorrentData, $Info, $FolderName = '') {
87
-    $FolderName = Misc::file_string($FolderName);
88
-    $MaxPathLength = $FolderName ? (self::MaxPathLength - strlen($FolderName) - 1) : self::MaxPathLength;
89
-    $FileName = self::construct_file_name($Info['Artist'], $Info['Name'], $Info['Year'], $Info['Media'], $Info['Format'], $Info['Encoding'], $Info['TorrentID'], $MaxPathLength);
90
-    $this->Size += $Info['Size'];
91
-    $this->NumAdded++;
92
-    $this->Zip->add_file(self::get_file($TorrentData, $this->AnnounceURL, $this->AnnounceList), ($FolderName ? "$FolderName/" : "") . $FileName);
93
-    usleep(25000); // We don't want to send much faster than the client can receive
94
-  }
82
+    /**
83
+     * Add a file to the zip archive
84
+     *
85
+     * @param string $TorrentData bencoded torrent without announce url (new format) or TORRENT object (old format)
86
+     * @param array $Info file info stored as an array with at least the keys
87
+     *  Artist, Name, Year, Media, Format, Encoding and TorrentID
88
+     * @param string $FolderName folder name
89
+     */
90
+    public function add_file(&$TorrentData, $Info, $FolderName = '')
91
+    {
92
+        $FolderName = Misc::file_string($FolderName);
93
+        $MaxPathLength = $FolderName ? (self::MaxPathLength - strlen($FolderName) - 1) : self::MaxPathLength;
94
+        $FileName = self::construct_file_name($Info['Artist'], $Info['Name'], $Info['Year'], $Info['Media'], $Info['Format'], $Info['Encoding'], $Info['TorrentID'], $MaxPathLength);
95
+        $this->Size += $Info['Size'];
96
+        $this->NumAdded++;
97
+        $this->Zip->add_file(self::get_file($TorrentData, $this->AnnounceURL, $this->AnnounceList), ($FolderName ? "$FolderName/" : "") . $FileName);
98
+        usleep(25000); // We don't want to send much faster than the client can receive
99
+    }
95
 
100
 
96
-  /**
97
-   * Add a file to the list of files that could not be downloaded
98
-   *
99
-   * @param array $Info file info stored as an array with at least the keys Artist, Name and Year
100
-   */
101
-  public function fail_file($Info) {
102
-    $this->FailedFiles[] = $Info['Artist'] . $Info['Name'] . " $Info[Year]";
103
-  }
101
+    /**
102
+     * Add a file to the list of files that could not be downloaded
103
+     *
104
+     * @param array $Info file info stored as an array with at least the keys Artist, Name and Year
105
+     */
106
+    public function fail_file($Info)
107
+    {
108
+        $this->FailedFiles[] = $Info['Artist'] . $Info['Name'] . " $Info[Year]";
109
+    }
104
 
110
 
105
-  /**
106
-   * Add a file to the list of files that did not match the user's format or quality requirements
107
-   *
108
-   * @param array $Info file info stored as an array with at least the keys Artist, Name and Year
109
-   */
110
-  public function skip_file($Info) {
111
-    $this->SkippedFiles[] = $Info['Artist'] . $Info['Name'] . " $Info[Year]";
112
-  }
111
+    /**
112
+     * Add a file to the list of files that did not match the user's format or quality requirements
113
+     *
114
+     * @param array $Info file info stored as an array with at least the keys Artist, Name and Year
115
+     */
116
+    public function skip_file($Info)
117
+    {
118
+        $this->SkippedFiles[] = $Info['Artist'] . $Info['Name'] . " $Info[Year]";
119
+    }
113
 
120
 
114
-  /**
115
-   * Add a summary to the archive and include a list of files that could not be added. Close the zip archive
116
-   *
117
-   * @param bool $FilterStats whether to include filter stats in the report
118
-   */
119
-  public function finalize($FilterStats = true) {
120
-    $this->Zip->add_file($this->summary($FilterStats), "Summary.txt");
121
-    if (!empty($this->FailedFiles)) {
122
-      $this->Zip->add_file($this->errors(), "Errors.txt");
121
+    /**
122
+     * Add a summary to the archive and include a list of files that could not be added. Close the zip archive
123
+     *
124
+     * @param bool $FilterStats whether to include filter stats in the report
125
+     */
126
+    public function finalize($FilterStats = true)
127
+    {
128
+        $this->Zip->add_file($this->summary($FilterStats), "Summary.txt");
129
+        if (!empty($this->FailedFiles)) {
130
+            $this->Zip->add_file($this->errors(), "Errors.txt");
131
+        }
132
+        $this->Zip->close_stream();
123
     }
133
     }
124
-    $this->Zip->close_stream();
125
-  }
126
 
134
 
127
-  /**
128
-   * Produce a summary text over the collector results
129
-   *
130
-   * @param bool $FilterStats whether to include filter stats in the report
131
-   * @return summary text
132
-   */
133
-  public function summary($FilterStats) {
134
-    global $ScriptStartTime;
135
-    $Time = number_format(1000 * (microtime(true) - $ScriptStartTime), 2)." ms";
136
-    $Used = Format::get_size(memory_get_usage(true));
137
-    $Date = date("M d Y, H:i");
138
-    $NumSkipped = count($this->SkippedFiles);
139
-    return "Collector Download Summary for $this->Title - " . SITE_NAME . "\r\n"
140
-      . "\r\n"
141
-      . "User:    {$this->User[Username]}\r\n"
142
-      . "Passkey: {$this->User[torrent_pass]}\r\n"
143
-      . "\r\n"
144
-      . "Time:    $Time\r\n"
145
-      . "Used:    $Used\r\n"
146
-      . "Date:    $Date\r\n"
147
-      . "\r\n"
148
-      . ($FilterStats !== false
135
+    /**
136
+     * Produce a summary text over the collector results
137
+     *
138
+     * @param bool $FilterStats whether to include filter stats in the report
139
+     * @return summary text
140
+     */
141
+    public function summary($FilterStats)
142
+    {
143
+        global $ScriptStartTime;
144
+        $Time = number_format(1000 * (microtime(true) - $ScriptStartTime), 2)." ms";
145
+        $Used = Format::get_size(memory_get_usage(true));
146
+        $Date = date("M d Y, H:i");
147
+        $NumSkipped = count($this->SkippedFiles);
148
+        return "Collector Download Summary for $this->Title - " . SITE_NAME . "\r\n"
149
+        . "\r\n"
150
+        . "User:    {$this->User[Username]}\r\n"
151
+        . "Passkey: {$this->User[torrent_pass]}\r\n"
152
+        . "\r\n"
153
+        . "Time:    $Time\r\n"
154
+        . "Used:    $Used\r\n"
155
+        . "Date:    $Date\r\n"
156
+        . "\r\n"
157
+        . ($FilterStats !== false
149
         ? "Torrent groups analyzed: $this->NumFound\r\n"
158
         ? "Torrent groups analyzed: $this->NumFound\r\n"
150
           . "Torrent groups filtered: $NumSkipped\r\n"
159
           . "Torrent groups filtered: $NumSkipped\r\n"
151
         : "")
160
         : "")
152
-      . "Torrents downloaded:   $this->NumAdded\r\n"
153
-      . "\r\n"
154
-      . "Total size of torrents (ratio hit): ".Format::get_size($this->Size)."\r\n"
155
-      . ($NumSkipped
161
+        . "Torrents downloaded:   $this->NumAdded\r\n"
162
+        . "\r\n"
163
+        . "Total size of torrents (ratio hit): ".Format::get_size($this->Size)."\r\n"
164
+        . ($NumSkipped
156
         ? "\r\n"
165
         ? "\r\n"
157
           . "Albums unavailable within your criteria (consider making a request for your desired format):\r\n"
166
           . "Albums unavailable within your criteria (consider making a request for your desired format):\r\n"
158
           . implode("\r\n", $this->SkippedFiles) . "\r\n"
167
           . implode("\r\n", $this->SkippedFiles) . "\r\n"
159
         : "");
168
         : "");
160
-  }
161
-
162
-  /**
163
-   * Compile a list of files that could not be added to the archive
164
-   *
165
-   * @return list of files
166
-   */
167
-  public function errors() {
168
-    return "A server error occurred. Please try again at a later time.\r\n"
169
-      . "\r\n"
170
-      . "The following torrents could not be downloaded:\r\n"
171
-      . implode("\r\n", $this->FailedFiles) . "\r\n";
172
-  }
173
-
174
-  /**
175
-   * Combine a bunch of torrent info into a standardized file name
176
-   *
177
-   * @params most input variables are self-explanatory
178
-   * @param int $TorrentID if given, append "-TorrentID" to torrent name
179
-   * @param int $MaxLength maximum file name length
180
-   * @return file name with at most $MaxLength characters
181
-   */
182
-  public static function construct_file_name($Artist, $Album, $Year, $Media, $Format, $Encoding, $TorrentID = false, $MaxLength = self::MaxPathLength) {
183
-    $MaxLength -= 8; // ".torrent"
184
-    if ($TorrentID !== false) {
185
-      $MaxLength -= (strlen($TorrentID) + 1);
186
-    }
187
-    $TorrentArtist = Misc::file_string($Artist);
188
-    $TorrentName = Misc::file_string($Album);
189
-    if ($Year > 0) {
190
-      $TorrentName .= " - $Year";
191
-    }
192
-    $TorrentInfo = [];
193
-    if ($Media != '') {
194
-      $TorrentInfo[] = $Media;
195
-    }
196
-    if ($Format != '') {
197
-      $TorrentInfo[] = $Format;
198
-    }
199
-    if ($Encoding != '') {
200
-      $TorrentInfo[] = $Encoding;
201
-    }
202
-    if (!empty($TorrentInfo)) {
203
-      $TorrentInfo = ' (' . Misc::file_string(implode(' - ', $TorrentInfo)) . ')';
204
-    } else {
205
-      $TorrentInfo = '';
206
     }
169
     }
207
 
170
 
208
-    if (!$TorrentName) {
209
-      $TorrentName = 'No Name';
210
-    } elseif (mb_strlen($TorrentArtist . $TorrentName . $TorrentInfo, 'UTF-8') <= $MaxLength) {
211
-      $TorrentName = $TorrentArtist . $TorrentName;
171
+    /**
172
+     * Compile a list of files that could not be added to the archive
173
+     *
174
+     * @return list of files
175
+     */
176
+    public function errors()
177
+    {
178
+        return "A server error occurred. Please try again at a later time.\r\n"
179
+        . "\r\n"
180
+        . "The following torrents could not be downloaded:\r\n"
181
+        . implode("\r\n", $this->FailedFiles) . "\r\n";
212
     }
182
     }
213
 
183
 
214
-    $TorrentName = Format::cut_string($TorrentName . $TorrentInfo, $MaxLength, true, false);
215
-    if ($TorrentID !== false) {
216
-      $TorrentName .= "-$TorrentID";
217
-    }
218
-    return "$TorrentName.torrent";
219
-  }
184
+    /**
185
+     * Combine a bunch of torrent info into a standardized file name
186
+     *
187
+     * @params most input variables are self-explanatory
188
+     * @param int $TorrentID if given, append "-TorrentID" to torrent name
189
+     * @param int $MaxLength maximum file name length
190
+     * @return file name with at most $MaxLength characters
191
+     */
192
+    public static function construct_file_name($Artist, $Album, $Year, $Media, $Format, $Encoding, $TorrentID = false, $MaxLength = self::MaxPathLength)
193
+    {
194
+        $MaxLength -= 8; // ".torrent"
195
+        if ($TorrentID !== false) {
196
+            $MaxLength -= (strlen($TorrentID) + 1);
197
+        }
198
+        $TorrentArtist = Misc::file_string($Artist);
199
+        $TorrentName = Misc::file_string($Album);
200
+        if ($Year > 0) {
201
+            $TorrentName .= " - $Year";
202
+        }
203
+        $TorrentInfo = [];
204
+        if ($Media != '') {
205
+            $TorrentInfo[] = $Media;
206
+        }
207
+        if ($Format != '') {
208
+            $TorrentInfo[] = $Format;
209
+        }
210
+        if ($Encoding != '') {
211
+            $TorrentInfo[] = $Encoding;
212
+        }
213
+        if (!empty($TorrentInfo)) {
214
+            $TorrentInfo = ' (' . Misc::file_string(implode(' - ', $TorrentInfo)) . ')';
215
+        } else {
216
+            $TorrentInfo = '';
217
+        }
218
+
219
+        if (!$TorrentName) {
220
+            $TorrentName = 'No Name';
221
+        } elseif (mb_strlen($TorrentArtist . $TorrentName . $TorrentInfo, 'UTF-8') <= $MaxLength) {
222
+            $TorrentName = $TorrentArtist . $TorrentName;
223
+        }
220
 
224
 
221
-  /**
222
-   * Convert a stored torrent into a binary file that can be loaded in a torrent client
223
-   *
224
-   * @param mixed $TorrentData bencoded torrent without announce URL (new format) or TORRENT object (old format)
225
-   * @return bencoded string
226
-   */
227
-  public static function get_file(&$TorrentData, $AnnounceURL, $AnnounceList = []) {
228
-    if (Misc::is_new_torrent($TorrentData)) {
229
-      $Bencode = BencodeTorrent::add_announce_url($TorrentData, $AnnounceURL);
230
-      if (!empty($AnnounceList)) {
231
-        $Bencode = BencodeTorrent::add_announce_list($Bencode, $AnnounceList);
232
-      }
233
-      return $Bencode;
225
+        $TorrentName = Format::cut_string($TorrentName . $TorrentInfo, $MaxLength, true, false);
226
+        if ($TorrentID !== false) {
227
+            $TorrentName .= "-$TorrentID";
228
+        }
229
+        return "$TorrentName.torrent";
234
     }
230
     }
235
-    $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
236
-    $Tor->set_announce_url($AnnounceURL);
237
-    unset($Tor->Val['announce-list']);
238
-    if (!empty($AnnounceList)) {
239
-      $Tor->set_announce_list($AnnounceList);
231
+
232
+    /**
233
+     * Convert a stored torrent into a binary file that can be loaded in a torrent client
234
+     *
235
+     * @param mixed $TorrentData bencoded torrent without announce URL (new format) or TORRENT object (old format)
236
+     * @return bencoded string
237
+     */
238
+    public static function get_file(&$TorrentData, $AnnounceURL, $AnnounceList = [])
239
+    {
240
+        if (Misc::is_new_torrent($TorrentData)) {
241
+            $Bencode = BencodeTorrent::add_announce_url($TorrentData, $AnnounceURL);
242
+            if (!empty($AnnounceList)) {
243
+                $Bencode = BencodeTorrent::add_announce_list($Bencode, $AnnounceList);
244
+            }
245
+            return $Bencode;
246
+        }
247
+        $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
248
+        $Tor->set_announce_url($AnnounceURL);
249
+        unset($Tor->Val['announce-list']);
250
+        if (!empty($AnnounceList)) {
251
+            $Tor->set_announce_list($AnnounceList);
252
+        }
253
+        unset($Tor->Val['url-list']);
254
+        unset($Tor->Val['libtorrent_resume']);
255
+        return $Tor->enc();
240
     }
256
     }
241
-    unset($Tor->Val['url-list']);
242
-    unset($Tor->Val['libtorrent_resume']);
243
-    return $Tor->enc();
244
-  }
245
 }
257
 }

Loading…
Cancel
Save