Browse Source

Clean up a bunch of uploading logic

spaghetti 7 years ago
parent
commit
42768e3a4c

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

29
  */
29
  */
30
 class Bencode {
30
 class Bencode {
31
   private $DefaultKeys = array( // Get rid of everything except these keys to save some space
31
   private $DefaultKeys = array( // Get rid of everything except these keys to save some space
32
-      'created by', 'creation date', 'encoding', 'info');
32
+      'created by', 'creation date', 'encoding', 'info', 'comment');
33
   private $Data;
33
   private $Data;
34
   public $Enc;
34
   public $Enc;
35
 
35
 

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

61
     G::$DB->query("
61
     G::$DB->query("
62
       SELECT COUNT(ID)
62
       SELECT COUNT(ID)
63
       FROM torrents
63
       FROM torrents
64
-      WHERE UserID = ".G::$LoggedUser['ID']);
64
+      WHERE UserID = ?", G::$LoggedUser['ID']);
65
     list($Uploads) = G::$DB->next_record();
65
     list($Uploads) = G::$DB->next_record();
66
 ?>
66
 ?>
67
 
67
 

+ 0
- 61
sections/upload/generate_extra_torrents.php View File

1
-<?
2
-$ExtraTorrentsInsert = [];
3
-foreach ($ExtraTorrents as $ExtraTorrent) {
4
-  $Name = $ExtraTorrent['Name'];
5
-  $ExtraTorrentsInsert[$Name] = $ExtraTorrent;
6
-  $ThisInsert =& $ExtraTorrentsInsert[$Name];
7
-  $ExtraTor = new BencodeTorrent($Name, true);
8
-  if (isset($ExtraTor->Dec['encrypted_files'])) {
9
-    $Err = 'At least one of the torrents contain an encrypted file list which is not supported here';
10
-    break;
11
-  }
12
-  if (!$ExtraTor->is_private()) {
13
-    $ExtraTor->make_private(); // The torrent is now private.
14
-    $PublicTorrent = true;
15
-  }
16
-
17
-  // File list and size
18
-  list($ExtraTotalSize, $ExtraFileList) = $ExtraTor->file_list();
19
-  $ExtraDirName = isset($ExtraTor->Dec['info']['files']) ? Format::make_utf8($ExtraTor->get_name()) : '';
20
-
21
-  $ExtraTmpFileList = [];
22
-  foreach ($ExtraFileList as $ExtraFile) {
23
-    list($ExtraSize, $ExtraName) = $ExtraFile;
24
-
25
-    check_file($Type, $ExtraName);
26
-
27
-    // Make sure the file name is not too long
28
-    if (mb_strlen($ExtraName, 'UTF-8') + mb_strlen($ExtraDirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) {
29
-      $Err = "The torrent contained one or more files with too long of a name: <br />$ExtraDirName/$ExtraName";
30
-      break;
31
-    }
32
-    // Add file and size to array
33
-    $ExtraTmpFileList[] = Torrents::filelist_format_file($ExtraFile);
34
-  }
35
-
36
-  // To be stored in the database
37
-  $ThisInsert['FilePath'] = db_string($ExtraDirName);
38
-  $ThisInsert['FileString'] = db_string(implode("\n", $ExtraTmpFileList));
39
-  $ThisInsert['InfoHash'] = pack('H*', $ExtraTor->info_hash());
40
-  $ThisInsert['NumFiles'] = count($ExtraFileList);
41
-  $ThisInsert['TorEnc'] = db_string($ExtraTor->encode());
42
-  $ThisInsert['TotalSize'] = $ExtraTotalSize;
43
-
44
-  $Debug->set_flag('upload: torrent decoded');
45
-  $DB->query("
46
-    SELECT ID
47
-    FROM torrents
48
-    WHERE info_hash = '" . db_string($ThisInsert['InfoHash']) . "'");
49
-  if ($DB->has_results()) {
50
-    list($ExtraID) = $DB->next_record();
51
-    if (file_exists(TORRENT_STORE.$ExtraID.'.torrent')) {
52
-      $Err = "<a href=\"torrents.php?torrentid=$ExtraID\">The exact same torrent file already exists on the site!</a>";
53
-    } else {
54
-      //One of the lost torrents.
55
-      file_put_contents(TORRENT_STORE.$ExtraID.'.torrent', $ThisInsert['TorEnc']);
56
-      $Err = "<a href=\"torrents.php?torrentid=$ExtraID\">Thank you for fixing this torrent.</a>";
57
-    }
58
-  }
59
-}
60
-unset($ThisInsert);
61
-?>

+ 0
- 60
sections/upload/insert_extra_torrents.php View File

1
-<?
2
-foreach ($ExtraTorrentsInsert as $ExtraTorrent) {
3
-  $ExtraHasLog = 0;
4
-  $ExtraHasCue = 0;
5
-  $LogScore = ($HasLog == 1 ? $LogScoreAverage : 0);
6
-  // Torrent
7
-  $DB->query("
8
-  INSERT INTO torrents
9
-    (GroupID, UserID, Media, Format, Encoding,
10
-    Remastered, RemasterYear, RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber,
11
-    HasLog, HasCue, info_hash, FileCount, FileList, FilePath, Size, Time,
12
-    Description, LogScore, FreeTorrent, FreeLeechType)
13
-  VALUES
14
-    ($GroupID, $LoggedUser[ID], $T[Media], '$ExtraTorrent[Format]', '$ExtraTorrent[Encoding]',
15
-    $T[Remastered], $T[RemasterYear], $T[RemasterTitle], $T[RemasterRecordLabel], $T[RemasterCatalogueNumber],
16
-    $ExtraHasLog, $ExtraHasCue, '".db_string($ExtraTorrent['InfoHash'])."', $ExtraTorrent[NumFiles],
17
-    '$ExtraTorrent[FileString]', '$ExtraTorrent[FilePath]', $ExtraTorrent[TotalSize], NOW(),
18
-    '$ExtraTorrent[TorrentDescription]', $LogScore, '$T[FreeLeech]', '$T[FreeLeechType]')");
19
-
20
-  $Cache->increment('stats_torrent_count');
21
-  $ExtraTorrentID = $DB->inserted_id();
22
-
23
-  Tracker::update_tracker('add_torrent', array('id' => $ExtraTorrentID, 'info_hash' => rawurlencode($ExtraTorrent['InfoHash']), 'freetorrent' => $T['FreeLeech']));
24
-
25
-
26
-
27
-  //******************************************************************************//
28
-  //--------------- Write torrent file -------------------------------------------//
29
-
30
-  file_put_contents(TORRENT_STORE.$ExtraTorrentID.'torrent', $ExtraTorrent['TorEnc']);
31
-
32
-  Misc::write_log("Torrent $ExtraTorrentID ($LogName) (" . number_format($ExtraTorrent['TotalSize'] / (1024 * 1024), 2) . ' MB) was uploaded by ' . $LoggedUser['Username']);
33
-  Torrents::write_group_log($GroupID, $ExtraTorrentID, $LoggedUser['ID'], 'uploaded (' . number_format($ExtraTorrent['TotalSize'] / (1024 * 1024), 2) . ' MB)', 0);
34
-
35
-  Torrents::update_hash($GroupID);
36
-
37
-  // IRC
38
-  $Announce = '';
39
-  $Announce .= Artists::display_artists($ArtistForm, false);
40
-  $Announce .= trim($Properties['Title']) . ' ';
41
-  $Announce .= '[' . trim($Properties['Year']) . ']';
42
-  if (($Properties['ReleaseType'] > 0)) {
43
-    $Announce .= ' [' . $ReleaseTypes[$Properties['ReleaseType']] . ']';
44
-  }
45
-  $Announce .= ' - ';
46
-  $Announce .= trim(str_replace("'", '', $ExtraTorrent['Format'])) . ' / ' . trim(str_replace("'", '', $ExtraTorrent['Encoding']));
47
-  $Announce .= ' / ' . trim($Properties['Media']);
48
-  if ($T['FreeLeech'] == '1') {
49
-    $Announce .= ' / Freeleech!';
50
-  }
51
-
52
-  $Announce .= ' - https://' . SITE_DOMAIN . "/torrents.php?id=$GroupID / https://" . SITE_DOMAIN . "/torrents.php?action=download&id=$ExtraTorrentID";
53
-
54
-  $Announce .= ' - ' . trim($Properties['TagList']);
55
-
56
-  // ENT_QUOTES is needed to decode single quotes/apostrophes
57
-  send_irc('PRIVMSG ' . BOT_ANNOUNCE_CHAN . ' :' . html_entity_decode($Announce, ENT_QUOTES));
58
-
59
-}
60
-?>

+ 96
- 157
sections/upload/upload_handle.php View File

172
     $Validate->SetFields('groupid', '0', 'number', 'Group ID was not numeric');
172
     $Validate->SetFields('groupid', '0', 'number', 'Group ID was not numeric');
173
 }
173
 }
174
 
174
 
175
-
176
-$Validate->SetFields('rules',
177
-  '1','require','Your torrent must abide by the rules.');
178
-
179
 $Err = $Validate->ValidateForm($_POST); // Validate the form
175
 $Err = $Validate->ValidateForm($_POST); // Validate the form
180
 
176
 
181
 if (count(explode(',', $Properties['TagList'])) < 5) {
177
 if (count(explode(',', $Properties['TagList'])) < 5) {
232
   die();
228
   die();
233
 }
229
 }
234
 
230
 
235
-// Strip out Amazon's padding
236
-$AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
237
-$Matches = [];
238
-//What the fuck is $RegX what.cd devs?
239
-//if (preg_match($RegX, $Properties['Image'], $Matches)) {
240
-if (preg_match($AmazonReg, $Properties['Image'], $Matches)) {
241
-  $Properties['Image'] = $Matches[1].'.jpg';
242
-}
243
 ImageTools::blacklisted($Properties['Image']);
231
 ImageTools::blacklisted($Properties['Image']);
244
 
232
 
245
 //******************************************************************************//
233
 //******************************************************************************//
246
 //--------------- Make variables ready for database input ----------------------//
234
 //--------------- Make variables ready for database input ----------------------//
247
 
235
 
248
-// Shorten and escape $Properties for database input
249
-$T = [];
250
-foreach ($Properties as $Key => $Value) {
251
-  $T[$Key] = "'".db_string(trim($Value))."'";
252
-  if (!$T[$Key]) {
253
-    $T[$Key] = null;
254
-  }
255
-}
256
-
257
-$T['Censored'] = $Properties['Censored'];
258
-$T['Anonymous'] = $Properties['Anonymous'];
259
-
236
+// Prepared SQL statements do this for us, so there is nothing to do here anymore
237
+$T = $Properties;
260
 
238
 
261
 //******************************************************************************//
239
 //******************************************************************************//
262
 //--------------- Generate torrent file ----------------------------------------//
240
 //--------------- Generate torrent file ----------------------------------------//
264
 $Tor = new BencodeTorrent($TorrentName, true);
242
 $Tor = new BencodeTorrent($TorrentName, true);
265
 $PublicTorrent = $Tor->make_private(); // The torrent is now private.
243
 $PublicTorrent = $Tor->make_private(); // The torrent is now private.
266
 $UnsourcedTorrent = $Tor->make_sourced(); // The torrent now has the source field set.
244
 $UnsourcedTorrent = $Tor->make_sourced(); // The torrent now has the source field set.
267
-$TorEnc = $Tor->encode();
268
 $InfoHash = pack('H*', $Tor->info_hash());
245
 $InfoHash = pack('H*', $Tor->info_hash());
269
 
246
 
270
 if (isset($Tor->Dec['encrypted_files'])) {
247
 if (isset($Tor->Dec['encrypted_files'])) {
297
 $FileString = db_string(implode("\n", $TmpFileList));
274
 $FileString = db_string(implode("\n", $TmpFileList));
298
 $Debug->set_flag('upload: torrent decoded');
275
 $Debug->set_flag('upload: torrent decoded');
299
 
276
 
300
-/*if ($Type == 'Music') {
301
-  include(SERVER_ROOT.'/sections/upload/generate_extra_torrents.php');
302
-}*/
303
-
304
 if (!empty($Err)) { // Show the upload form, with the data the user entered
277
 if (!empty($Err)) { // Show the upload form, with the data the user entered
305
   $UploadForm = $Type;
278
   $UploadForm = $Type;
306
   include(SERVER_ROOT.'/sections/upload/upload.php');
279
   include(SERVER_ROOT.'/sections/upload/upload.php');
310
 //******************************************************************************//
283
 //******************************************************************************//
311
 //--------------- Start database stuff -----------------------------------------//
284
 //--------------- Start database stuff -----------------------------------------//
312
 
285
 
313
-$Body = $Properties['GroupDescription'];
286
+$Body = $T['GroupDescription'];
314
 
287
 
315
 // Trickery
288
 // Trickery
316
-if (!preg_match('/^'.IMAGE_REGEX.'$/i', $Properties['Image'])) {
317
-  $Properties['Image'] = '';
318
-  $T['Image'] = "''";
289
+if (!preg_match('/^'.IMAGE_REGEX.'$/i', $T['Image'])) {
290
+  $T['Image'] = '';
319
 }
291
 }
320
 
292
 
321
 // Does it belong in a group?
293
 // Does it belong in a group?
322
-if ($Properties['GroupID']) {
294
+if ($T['GroupID']) {
323
   $DB->query("
295
   $DB->query("
324
     SELECT
296
     SELECT
325
       ID,
297
       ID,
330
       Year,
302
       Year,
331
       TagList
303
       TagList
332
     FROM torrents_group
304
     FROM torrents_group
333
-    WHERE id = ".$Properties['GroupID']);
305
+    WHERE id = ?", $T['GroupID']);
334
   if ($DB->has_results()) {
306
   if ($DB->has_results()) {
335
     // Don't escape tg.Name. It's written directly to the log table
307
     // Don't escape tg.Name. It's written directly to the log table
336
-    list($GroupID, $WikiImage, $WikiBody, $RevisionID, $Properties['Title'], $Properties['Year'], $Properties['TagList']) = $DB->next_record(MYSQLI_NUM, array(4));
337
-    $Properties['TagList'] = str_replace(array(' ', '.', '_'), array(', ', '.', '.'), $Properties['TagList']);
338
-    if (!$Properties['Image'] && $WikiImage) {
339
-      $Properties['Image'] = $WikiImage;
340
-      $T['Image'] = "'".db_string($WikiImage)."'";
308
+    list($GroupID, $WikiImage, $WikiBody, $RevisionID, $T['Title'], $T['Year'], $T['TagList']) = $DB->next_record(MYSQLI_NUM, array(4));
309
+    $T['TagList'] = str_replace(array(' ', '.', '_'), array(', ', '.', '.'), $T['TagList']);
310
+    if (!$T['Image'] && $WikiImage) {
311
+      $T['Image'] = $WikiImage;
341
     }
312
     }
342
     if (strlen($WikiBody) > strlen($Body)) {
313
     if (strlen($WikiBody) > strlen($Body)) {
343
       $Body = $WikiBody;
314
       $Body = $WikiBody;
344
-      if (!$Properties['Image'] || $Properties['Image'] == $WikiImage) {
315
+      if (!$T['Image'] || $T['Image'] == $WikiImage) {
345
         $NoRevision = true;
316
         $NoRevision = true;
346
       }
317
       }
347
     }
318
     }
348
-    $Properties['Artist'] = Artists::display_artists(Artists::get_artist($GroupID), false, false);
319
+    $T['Artist'] = Artists::display_artists(Artists::get_artist($GroupID), false, false);
349
   }
320
   }
350
 }
321
 }
351
 if (!isset($GroupID) || !$GroupID) {
322
 if (!isset($GroupID) || !$GroupID) {
352
   foreach ($ArtistForm as $Num => $Artist) {
323
   foreach ($ArtistForm as $Num => $Artist) {
353
-    /*$DB->query("
324
+    // The album hasn't been uploaded. Try to get the artist IDs
325
+    $DB->query("
354
       SELECT
326
       SELECT
355
-        tg.id,
356
-        tg.WikiImage,
357
-        tg.WikiBody,
358
-        tg.RevisionID
359
-      FROM torrents_group AS tg
360
-        LEFT JOIN torrents_artists AS ta ON ta.GroupID = tg.ID
361
-        LEFT JOIN artists_group AS ag ON ta.ArtistID = ag.ArtistID
362
-      WHERE ag.Name = '".db_string($Artist['name'])."'
363
-        AND tg.Name = ".$T['Title']."
364
-        AND tg.Year = ".$T['Year']);
365
-
327
+        ArtistID,
328
+        Name
329
+      FROM artists_group
330
+      WHERE Name = ?", $Artist['name']);
366
     if ($DB->has_results()) {
331
     if ($DB->has_results()) {
367
-      list($GroupID, $WikiImage, $WikiBody, $RevisionID) = $DB->next_record();
368
-      if (!$Properties['Image'] && $WikiImage) {
369
-        $Properties['Image'] = $WikiImage;
370
-        $T['Image'] = "'".db_string($WikiImage)."'";
371
-      }
372
-      if (strlen($WikiBody) > strlen($Body)) {
373
-        $Body = $WikiBody;
374
-        if (!$Properties['Image'] || $Properties['Image'] == $WikiImage) {
375
-          $NoRevision = true;
376
-        }
377
-      }
378
-      $ArtistForm = Artists::get_artist($GroupID);
379
-      //This torrent belongs in a group
380
-      break;
381
-
382
-    } else {*/
383
-      // The album hasn't been uploaded. Try to get the artist IDs
384
-      $DB->query("
385
-        SELECT
386
-          ArtistID,
387
-          Name
388
-        FROM artists_group
389
-        WHERE Name = '".db_string($Artist['name'])."'");
390
-      if ($DB->has_results()) {
391
-        while (list($ArtistID, $Name) = $DB->next_record(MYSQLI_NUM, false)) {
392
-          if (!strcasecmp($Artist['name'], $Name)) {
393
-            $ArtistForm[$Num] = array('id' => $ArtistID, 'name' => $Name);
394
-            break;
395
-          }
332
+      while (list($ArtistID, $Name) = $DB->next_record(MYSQLI_NUM, false)) {
333
+        if (!strcasecmp($Artist['name'], $Name)) {
334
+          $ArtistForm[$Num] = ['id' => $ArtistID, 'name' => $Name];
335
+          break;
396
         }
336
         }
397
       }
337
       }
398
-    //}
338
+    }
399
   }
339
   }
400
 }
340
 }
401
 
341
 
402
 //Needs to be here as it isn't set for add format until now
342
 //Needs to be here as it isn't set for add format until now
403
-$LogName .= $Properties['Title'];
343
+$LogName .= $T['Title'];
404
 
344
 
405
 //For notifications--take note now whether it's a new group
345
 //For notifications--take note now whether it's a new group
406
 $IsNewGroup = !isset($GroupID) || !$GroupID;
346
 $IsNewGroup = !isset($GroupID) || !$GroupID;
417
         // Create artist
357
         // Create artist
418
         $DB->query("
358
         $DB->query("
419
           INSERT INTO artists_group (Name)
359
           INSERT INTO artists_group (Name)
420
-          VALUES ('".db_string($Artist['name'])."')");
360
+          VALUES ( ? )", $Artist['name']);
421
         $ArtistID = $DB->inserted_id();
361
         $ArtistID = $DB->inserted_id();
422
 
362
 
423
         $Cache->increment('stats_artist_count');
363
         $Cache->increment('stats_artist_count');
424
 
364
 
425
-        /*$DB->query("
426
-          INSERT INTO artists_alias (ArtistID, Name)
427
-          VALUES ($ArtistID, '".db_string($Artist['name'])."')");
428
-        $AliasID = $DB->inserted_id();*/
429
-
430
         $ArtistForm[$Num] = array('id' => $ArtistID, 'name' => $Artist['name']);
365
         $ArtistForm[$Num] = array('id' => $ArtistID, 'name' => $Artist['name']);
431
         $ArtistsAdded[strtolower($Artist['name'])] = $ArtistForm[$Num];
366
         $ArtistsAdded[strtolower($Artist['name'])] = $ArtistForm[$Num];
432
       }
367
       }
439
   // Create torrent group
374
   // Create torrent group
440
   $DB->query("
375
   $DB->query("
441
     INSERT INTO torrents_group
376
     INSERT INTO torrents_group
442
-      (CategoryID, Name, NameRJ, NameJP, Year, Series, Studio, CatalogueNumber, Pages, Time, WikiBody, WikiImage, DLsiteID)
377
+      (CategoryID, Name, NameRJ, NameJP, Year,
378
+      Series, Studio, CatalogueNumber, Pages, Time,
379
+      WikiBody, WikiImage, DLsiteID)
443
     VALUES
380
     VALUES
444
-      ($TypeID, ".$T['Title'].", ".$T['TitleRJ'].", ".$T['TitleJP'].", ".$T['Year'].", ".$T['Series'].", ".$T['Studio'].", ".$T['CatalogueNumber'].", " . $T['Pages'] . ", NOW(), '".db_string($Body)."', ".$T['Image'].", ".$T['DLsiteID'].")");
381
+      ( ?, ?, ?, ?, ?,
382
+        ?, ?, ?, ?, NOW(),
383
+        ?, ?, ? )",
384
+    $TypeID, $T['Title'], $T['TitleRJ'], $T['TitleJP'], $T['Year'],
385
+    $T['Series'], $T['Studio'], $T['CatalogueNumber'], $T['Pages'],
386
+    $Body, $T['Image'], $T['DLsiteID']);
445
   $GroupID = $DB->inserted_id();
387
   $GroupID = $DB->inserted_id();
446
   foreach ($ArtistForm as $Num => $Artist) {
388
   foreach ($ArtistForm as $Num => $Artist) {
447
     $DB->query("
389
     $DB->query("
448
       INSERT IGNORE INTO torrents_artists (GroupID, ArtistID, UserID)
390
       INSERT IGNORE INTO torrents_artists (GroupID, ArtistID, UserID)
449
-      VALUES ($GroupID, ".$Artist['id'].', '.$LoggedUser['ID'].")");
391
+      VALUES ( ?, ?, ? )", $GroupID, $Artist['id'], $LoggedUser['ID']);
450
     $Cache->increment('stats_album_count');
392
     $Cache->increment('stats_album_count');
451
     $Cache->delete_value('artist_groups_'.$Artist['id']);
393
     $Cache->delete_value('artist_groups_'.$Artist['id']);
452
   }
394
   }
453
   $Cache->increment('stats_group_count');
395
   $Cache->increment('stats_group_count');
454
 
396
 
455
   // Add screenshots
397
   // Add screenshots
456
-  $Screenshots = array_slice(array_filter(array_map("db_string", array_map("trim", array_unique(explode("\n", $Properties['Screenshots'])))), function ($s) { return preg_match('/^'.IMAGE_REGEX.'$/i', $s); }), 0, 10);
398
+  $Screenshots = array_slice(array_filter(array_map("db_string", array_map("trim", array_unique(explode("\n", $T['Screenshots'])))), function ($s) { return preg_match('/^'.IMAGE_REGEX.'$/i', $s); }), 0, 10);
457
 
399
 
458
   $values = [];
400
   $values = [];
459
   foreach ($Screenshots as $s) {
401
   foreach ($Screenshots as $s) {
471
   $DB->query("
413
   $DB->query("
472
     UPDATE torrents_group
414
     UPDATE torrents_group
473
     SET Time = NOW()
415
     SET Time = NOW()
474
-    WHERE ID = $GroupID");
416
+    WHERE ID = ?", $GroupID);
475
   $Cache->delete_value("torrent_group_$GroupID");
417
   $Cache->delete_value("torrent_group_$GroupID");
476
   $Cache->delete_value("torrents_details_$GroupID");
418
   $Cache->delete_value("torrents_details_$GroupID");
477
   $Cache->delete_value("detail_files_$GroupID");
419
   $Cache->delete_value("detail_files_$GroupID");
483
     INSERT INTO wiki_torrents
425
     INSERT INTO wiki_torrents
484
       (PageID, Body, UserID, Summary, Time, Image)
426
       (PageID, Body, UserID, Summary, Time, Image)
485
     VALUES
427
     VALUES
486
-      ($GroupID, $T[GroupDescription], $LoggedUser[ID], 'Uploaded new torrent', NOW(), $T[Image])");
428
+      ( ?, ?, ?, 'Uploaded new torrent', NOW(), ? )", $GroupID, $T['GroupDescription'], $LoggedUser['ID'], $T['Image']);
487
   $RevisionID = $DB->inserted_id();
429
   $RevisionID = $DB->inserted_id();
488
 
430
 
489
   // Revision ID
431
   // Revision ID
490
   $DB->query("
432
   $DB->query("
491
     UPDATE torrents_group
433
     UPDATE torrents_group
492
-    SET RevisionID = '$RevisionID'
493
-    WHERE ID = $GroupID");
434
+    SET RevisionID = ?
435
+    WHERE ID = ?", $RevisionID, $GroupID);
494
 }
436
 }
495
 
437
 
496
 // Tags
438
 // Tags
497
-$Tags = explode(',', $Properties['TagList']);
498
-if (!$Properties['GroupID']) {
439
+$Tags = explode(',', $T['TagList']);
440
+if (!$T['GroupID']) {
499
   foreach ($Tags as $Tag) {
441
   foreach ($Tags as $Tag) {
500
     $Tag = Misc::sanitize_tag($Tag);
442
     $Tag = Misc::sanitize_tag($Tag);
501
     if (!empty($Tag)) {
443
     if (!empty($Tag)) {
504
         INSERT INTO tags
446
         INSERT INTO tags
505
           (Name, UserID)
447
           (Name, UserID)
506
         VALUES
448
         VALUES
507
-          ('$Tag', $LoggedUser[ID])
449
+          ( ?, ? )
508
         ON DUPLICATE KEY UPDATE
450
         ON DUPLICATE KEY UPDATE
509
-          Uses = Uses + 1;
510
-      ");
451
+          Uses = Uses + 1;", $Tag, $LoggedUser['ID']);
511
       $TagID = $DB->inserted_id();
452
       $TagID = $DB->inserted_id();
512
 
453
 
513
       $DB->query("
454
       $DB->query("
514
         INSERT INTO torrents_tags
455
         INSERT INTO torrents_tags
515
           (TagID, GroupID, UserID)
456
           (TagID, GroupID, UserID)
516
         VALUES
457
         VALUES
517
-          ($TagID, $GroupID, $LoggedUser[ID])
518
-        ON DUPLICATE KEY UPDATE TagID=TagID
519
-      ");
458
+          ( ?, ?, ? )
459
+        ON DUPLICATE KEY UPDATE TagID=TagID", $TagID, $GroupID, $LoggedUser['ID']);
520
     }
460
     }
521
   }
461
   }
522
 }
462
 }
542
 }
482
 }
543
 
483
 
544
 // movie and anime ISOs are neutral leech, and receive a BP bounty
484
 // movie and anime ISOs are neutral leech, and receive a BP bounty
545
-if (($Type == "Movies" || $Type == "Anime") && ($T['Container'] == "'ISO'" || $T['Container'] == "'M2TS'" || $T['Container'] == "'VOB IFO'")) {
485
+if (($Type == 'Movies' || $Type == 'Anime') && ($T['Container'] == 'ISO' || $T['Container'] == 'M2TS' || $T['Container'] == 'VOB IFO')) {
546
   $T['FreeTorrent'] = 2;
486
   $T['FreeTorrent'] = 2;
547
   $T['FreeLeechType'] = 2;
487
   $T['FreeLeechType'] = 2;
548
 }
488
 }
550
 // Torrent
490
 // Torrent
551
 $DB->query("
491
 $DB->query("
552
   INSERT INTO torrents
492
   INSERT INTO torrents
553
-    (GroupID, UserID, Media, Container, Codec, Resolution, AudioFormat,
554
-    Subbing, Language, Subber, Censored, Anonymous, Archive, info_hash, FileCount, FileList,
555
-    FilePath, Size, Time, Description, MediaInfo, FreeTorrent, FreeLeechType)
493
+    (GroupID, UserID, Media, Container, Codec, Resolution,
494
+    AudioFormat, Subbing, Language, Subber, Censored,
495
+    Anonymous, Archive, info_hash, FileCount, FileList, FilePath, Size, Time,
496
+    Description, MediaInfo, FreeTorrent, FreeLeechType)
556
   VALUES
497
   VALUES
557
-    ($GroupID, $LoggedUser[ID], $T[Media], $T[Container], $T[Codec], $T[Resolution], $T[AudioFormat],
558
-    $T[Subbing], $T[Language], $T[Subber], $T[Censored], $T[Anonymous], $T[Archive],'".db_string($InfoHash)."', $NumFiles, '$FileString',
559
-    '$FilePath', $TotalSize, NOW(), $T[TorrentDescription], $T[MediaInfo], '$T[FreeTorrent]', '$T[FreeLeechType]')");
498
+    ( ?, ?, ?, ?, ?, ?,
499
+      ?, ?, ?, ?, ?,
500
+      ?, ?, ?, ?, ?, ?, ?, NOW(),
501
+      ?, ?, ?, ? )",
502
+  $GroupID, $LoggedUser['ID'], $T['Media'], $T['Container'], $T['Codec'], $T['Resolution'],
503
+  $T['AudioFormat'], $T['Subbing'], $T['Language'], $T['Subber'], $T['Censored'],
504
+  $T['Anonymous'], $T['Archive'], $InfoHash, $NumFiles, $FileString, $FilePath, $TotalSize,
505
+  $T['TorrentDescription'], $T['MediaInfo'], $T['FreeTorrent'], $T['FreeLeechType']);
560
 
506
 
561
 $Cache->increment('stats_torrent_count');
507
 $Cache->increment('stats_torrent_count');
562
 $TorrentID = $DB->inserted_id();
508
 $TorrentID = $DB->inserted_id();
509
+$Tor->Dec['comment'] = 'https://'.SITE_DOMAIN.'/torrents.php?torrentid='.$TorrentID;
563
 
510
 
564
-Tracker::update_tracker('add_torrent', array('id' => $TorrentID, 'info_hash' => rawurlencode($InfoHash), 'freetorrent' => $T['FreeTorrent']));
511
+Tracker::update_tracker('add_torrent', [
512
+  'id'          => $TorrentID,
513
+  'info_hash'   => rawurlencode($InfoHash),
514
+  'freetorrent' => $T['FreeTorrent']
515
+]);
565
 $Debug->set_flag('upload: ocelot updated');
516
 $Debug->set_flag('upload: ocelot updated');
566
 
517
 
567
 // Prevent deletion of this torrent until the rest of the upload process is done
518
 // Prevent deletion of this torrent until the rest of the upload process is done
574
 
525
 
575
   $DB->query("
526
   $DB->query("
576
     UPDATE users_main
527
     UPDATE users_main
577
-    SET BonusPoints = BonusPoints + $BPAmt
578
-    WHERE ID = $LoggedUser[ID]");
528
+    SET BonusPoints = BonusPoints + ?
529
+    WHERE ID = ?", $BPAmt, $LoggedUser['ID']);
579
 
530
 
580
    $DB->query("
531
    $DB->query("
581
     UPDATE users_info
532
     UPDATE users_info
582
-    SET AdminComment = CONCAT('".sqltime()." - Received $BPAmt ".BONUS_POINTS." for uploading a torrent $TorrentID\n\n', AdminComment)
583
-    WHERE UserID = $LoggedUser[ID]");
533
+    SET AdminComment = CONCAT(NOW(), ' - Received $BPAmt ".BONUS_POINTS." for uploading a torrent $TorrentID\n\n', AdminComment)
534
+    WHERE UserID = ?", $LoggedUser['ID']);
584
     $Cache->delete_value('user_info_heavy_'.$LoggedUser['ID']);
535
     $Cache->delete_value('user_info_heavy_'.$LoggedUser['ID']);
585
     $Cache->delete_value('user_stats_'.$LoggedUser['ID']);
536
     $Cache->delete_value('user_stats_'.$LoggedUser['ID']);
586
 }
537
 }
611
 //******************************************************************************//
562
 //******************************************************************************//
612
 //--------------- Write torrent file -------------------------------------------//
563
 //--------------- Write torrent file -------------------------------------------//
613
 
564
 
614
-file_put_contents(TORRENT_STORE.$TorrentID.'.torrent', $TorEnc);
565
+file_put_contents(TORRENT_STORE.$TorrentID.'.torrent', $Tor->encode());
615
 Misc::write_log("Torrent $TorrentID ($LogName) (".number_format($TotalSize / (1024 * 1024), 2).' MB) was uploaded by ' . $LoggedUser['Username']);
566
 Misc::write_log("Torrent $TorrentID ($LogName) (".number_format($TotalSize / (1024 * 1024), 2).' MB) was uploaded by ' . $LoggedUser['Username']);
616
 Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], 'uploaded ('.number_format($TotalSize / (1024 * 1024), 2).' MB)', 0);
567
 Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], 'uploaded ('.number_format($TotalSize / (1024 * 1024), 2).' MB)', 0);
617
 
568
 
618
 Torrents::update_hash($GroupID);
569
 Torrents::update_hash($GroupID);
619
 $Debug->set_flag('upload: sphinx updated');
570
 $Debug->set_flag('upload: sphinx updated');
620
 
571
 
621
-/*if ($Type == 'Music') {
622
-  include(SERVER_ROOT.'/sections/upload/insert_extra_torrents.php');
623
-}*/
624
-
625
 //******************************************************************************//
572
 //******************************************************************************//
626
 //---------------------- Recent Uploads ----------------------------------------//
573
 //---------------------- Recent Uploads ----------------------------------------//
627
 
574
 
628
-if (trim($Properties['Image']) != '') {
575
+if (trim($T['Image']) != '') {
629
   $RecentUploads = $Cache->get_value("recent_uploads_$UserID");
576
   $RecentUploads = $Cache->get_value("recent_uploads_$UserID");
630
   if (is_array($RecentUploads)) {
577
   if (is_array($RecentUploads)) {
631
     do {
578
     do {
641
       }
588
       }
642
       array_unshift($RecentUploads, array(
589
       array_unshift($RecentUploads, array(
643
             'ID' => $GroupID,
590
             'ID' => $GroupID,
644
-            'Name' => trim($Properties['Title']),
591
+            'Name' => trim($T['Title']),
645
             'Artist' => Artists::display_artists($ArtistForm, false, true),
592
             'Artist' => Artists::display_artists($ArtistForm, false, true),
646
-            'WikiImage' => trim($Properties['Image'])));
593
+            'WikiImage' => trim($T['Image'])));
647
       $Cache->cache_value("recent_uploads_$UserID", $RecentUploads, 0);
594
       $Cache->cache_value("recent_uploads_$UserID", $RecentUploads, 0);
648
     } while (0);
595
     } while (0);
649
   }
596
   }
660
   View::show_header('Warning');
607
   View::show_header('Warning');
661
 ?>
608
 ?>
662
   <h1>Warning</h1>
609
   <h1>Warning</h1>
663
-  <p><strong>Your torrent has been uploaded; however, you must download your torrent from <a href="torrents.php?id=<?=$GroupID?>">here</a> because you didn't make your torrent using the "private" option.</strong></p>
610
+  <p><strong>Your torrent has been uploaded - but you must re-download your torrent file from <a href="torrents.php?id=<?=$GroupID?>&torrentid=<?=$TorrentID?>">here</a> because the site modified it to make it private.</strong></p>
611
+<?
612
+  View::show_footer();
613
+} elseif ($UnsourcedTorrent) {
614
+  View::show_header('Warning');
615
+?>
616
+  <h1>Warning</h1>
617
+  <p><strong>Your torrent has been uploaded - but you must re-download your torrent file from <a href="torrents.php?id=<?=$GroupID?>&torrentid=<?=$TorrentID?>">here</a> because the site modified it to add a source flag.</strong></p>
664
 <?
618
 <?
665
   View::show_footer();
619
   View::show_footer();
666
 } elseif ($RequestID) {
620
 } elseif ($RequestID) {
667
   header("Location: requests.php?action=takefill&requestid=$RequestID&torrentid=$TorrentID&auth=".$LoggedUser['AuthKey']);
621
   header("Location: requests.php?action=takefill&requestid=$RequestID&torrentid=$TorrentID&auth=".$LoggedUser['AuthKey']);
668
 } else {
622
 } else {
669
-  header("Location: torrents.php?id=$GroupID");
623
+  header("Location: torrents.php?id=$GroupID&torrentid=$TorrentID");
670
 }
624
 }
671
 if (function_exists('fastcgi_finish_request')) {
625
 if (function_exists('fastcgi_finish_request')) {
672
   fastcgi_finish_request();
626
   fastcgi_finish_request();
683
 
637
 
684
 $Announce .= Artists::display_artists($ArtistForm, false);
638
 $Announce .= Artists::display_artists($ArtistForm, false);
685
 
639
 
686
-$Announce .= substr(trim(empty($Properties['Title']) ? (empty($Properties['TitleRJ']) ? $Properties['TitleJP'] : $Properties['TitleRJ']) : $Properties['Title']), 0, 100);
640
+$Announce .= substr(trim(empty($T['Title']) ? (empty($T['TitleRJ']) ? $T['TitleJP'] : $T['TitleRJ']) : $T['Title']), 0, 100);
687
 $Announce .= ' ';
641
 $Announce .= ' ';
688
 if ($Type != 'Other') {
642
 if ($Type != 'Other') {
689
-  $Announce .= '['.Torrents::torrent_info($Properties, false, false, false).']';
643
+  $Announce .= '['.Torrents::torrent_info($T, false, false, false).']';
690
 }
644
 }
691
-$Title = '['.$Properties['CategoryName'].'] '.$Announce;
645
+$Title = '['.$T['CategoryName'].'] '.$Announce;
692
 
646
 
693
 $Announce = "$Title - ".site_url()."torrents.php?id=$GroupID / ".site_url()."torrents.php?action=download&id=$TorrentID";
647
 $Announce = "$Title - ".site_url()."torrents.php?id=$GroupID / ".site_url()."torrents.php?action=download&id=$TorrentID";
694
 
648
 
695
-$Announce .= ' - '.trim($Properties['TagList']);
649
+$Announce .= ' - '.trim($T['TagList']);
696
 
650
 
697
 // ENT_QUOTES is needed to decode single quotes/apostrophes
651
 // ENT_QUOTES is needed to decode single quotes/apostrophes
698
 send_irc('PRIVMSG '.BOT_ANNOUNCE_CHAN.' '.html_entity_decode($Announce, ENT_QUOTES));
652
 send_irc('PRIVMSG '.BOT_ANNOUNCE_CHAN.' '.html_entity_decode($Announce, ENT_QUOTES));
701
 // Manage notifications
655
 // Manage notifications
702
 
656
 
703
 // For RSS
657
 // For RSS
704
-$Item = $Feed->item($Title, Text::strip_bbcode($Body), 'torrents.php?action=download&amp;authkey=[[AUTHKEY]]&amp;torrent_pass=[[PASSKEY]]&amp;id='.$TorrentID, $LoggedUser['Username'], 'torrents.php?id='.$GroupID, trim($Properties['TagList']));
658
+$Item = $Feed->item($Title, Text::strip_bbcode($Body), 'torrents.php?action=download&amp;authkey=[[AUTHKEY]]&amp;torrent_pass=[[PASSKEY]]&amp;id='.$TorrentID, $LoggedUser['Username'], 'torrents.php?id='.$GroupID, trim($T['TagList']));
705
 
659
 
706
 
660
 
707
 //Notifications
661
 //Notifications
761
 
715
 
762
 $SQL .= " AND (Categories LIKE '%|".db_string(trim($Type))."|%' OR Categories = '') ";
716
 $SQL .= " AND (Categories LIKE '%|".db_string(trim($Type))."|%' OR Categories = '') ";
763
 
717
 
764
-if ($Properties['ReleaseType']) {
765
-  $SQL .= " AND (ReleaseTypes LIKE '%|".db_string(trim($ReleaseTypes[$Properties['ReleaseType']]))."|%' OR ReleaseTypes = '') ";
718
+if ($T['ReleaseType']) {
719
+  $SQL .= " AND (ReleaseTypes LIKE '%|".db_string(trim($ReleaseTypes[$T['ReleaseType']]))."|%' OR ReleaseTypes = '') ";
766
 } else {
720
 } else {
767
   $SQL .= " AND (ReleaseTypes = '') ";
721
   $SQL .= " AND (ReleaseTypes = '') ";
768
 }
722
 }
773
     2. If they set NewGroupsOnly to 1, it must also be the first torrent in the group to match the formatbitrate filter on the notification
727
     2. If they set NewGroupsOnly to 1, it must also be the first torrent in the group to match the formatbitrate filter on the notification
774
 */
728
 */
775
 
729
 
776
-
777
-if ($Properties['Format']) {
778
-  $SQL .= " AND (Formats LIKE '%|".db_string(trim($Properties['Format']))."|%' OR Formats = '') ";
730
+if ($T['Format']) {
731
+  $SQL .= " AND (Formats LIKE '%|".db_string(trim($T['Format']))."|%' OR Formats = '') ";
779
 } else {
732
 } else {
780
   $SQL .= " AND (Formats = '') ";
733
   $SQL .= " AND (Formats = '') ";
781
 }
734
 }
786
   $SQL .= " AND (Encodings = '') ";
739
   $SQL .= " AND (Encodings = '') ";
787
 }
740
 }
788
 
741
 
789
-if ($Properties['Media']) {
790
-  $SQL .= " AND (Media LIKE '%|".db_string(trim($Properties['Media']))."|%' OR Media = '') ";
742
+if ($T['Media']) {
743
+  $SQL .= " AND (Media LIKE '%|".db_string(trim($T['Media']))."|%' OR Media = '') ";
791
 } else {
744
 } else {
792
   $SQL .= " AND (Media = '') ";
745
   $SQL .= " AND (Media = '') ";
793
 }
746
 }
796
 $SQL .= "AND ((NewGroupsOnly = '0' ";
749
 $SQL .= "AND ((NewGroupsOnly = '0' ";
797
 // Or this is the first torrent in the group to match the formatbitrate filter
750
 // Or this is the first torrent in the group to match the formatbitrate filter
798
 $SQL .= ") OR ( NewGroupsOnly = '1' ";
751
 $SQL .= ") OR ( NewGroupsOnly = '1' ";
799
-// Test the filter doesn't match any previous formatbitrate in the group
800
-/*
801
-foreach ($UsedFormatBitrates as $UsedFormatBitrate) {
802
-  $FormatReq = "(Formats LIKE '%|".db_string($UsedFormatBitrate['format'])."|%' OR Formats = '') ";
803
-  $BitrateReq = "(Encodings LIKE '%|".db_string($UsedFormatBitrate['bitrate'])."|%' OR Encodings = '') ";
804
-  $SQL .= "AND (NOT($FormatReq AND $BitrateReq)) ";
805
-}
806
-*/
807
 $SQL .= '))';
752
 $SQL .= '))';
808
 
753
 
809
 
754
 
810
-/*if ($Properties['Year'] && $Properties['RemasterYear']) {
811
-  $SQL .= " AND (('".db_string(trim($Properties['Year']))."' BETWEEN FromYear AND ToYear)
812
-      OR ('".db_string(trim($Properties['RemasterYear']))."' BETWEEN FromYear AND ToYear)
813
-      OR (FromYear = 0 AND ToYear = 0)) ";
814
-} else*/
815
-if ($Properties['Year'] || $Properties['RemasterYear']) {
816
-  //$SQL .= " AND (('".db_string(trim(Max($Properties['Year'],$Properties['RemasterYear'])))."' BETWEEN FromYear AND ToYear)
817
-  $SQL .= " AND (('".db_string(trim($Properties['Year']))."' BETWEEN FromYear AND ToYear)
755
+if ($T['Year']) {
756
+  $SQL .= " AND (('".db_string(trim($T['Year']))."' BETWEEN FromYear AND ToYear)
818
       OR (FromYear = 0 AND ToYear = 0)) ";
757
       OR (FromYear = 0 AND ToYear = 0)) ";
819
 } else {
758
 } else {
820
   $SQL .= " AND (FromYear = 0 AND ToYear = 0) ";
759
   $SQL .= " AND (FromYear = 0 AND ToYear = 0) ";

+ 3
- 0
static/functions/validate_upload.js View File

15
     if (!$('#file').raw().value) {
15
     if (!$('#file').raw().value) {
16
       hard_error('No torrent file is selected')
16
       hard_error('No torrent file is selected')
17
     }
17
     }
18
+    if ($('#release_desc').raw().value.length < 10) {
19
+      hard_error('The release description is too short')
20
+    }
18
     if ($('#file').raw().value.slice(-8).toLowerCase() != '.torrent') {
21
     if ($('#file').raw().value.slice(-8).toLowerCase() != '.torrent') {
19
       soft_error('The file selected does not appear to be a .torrent file')
22
       soft_error('The file selected does not appear to be a .torrent file')
20
     }
23
     }

Loading…
Cancel
Save