Gazelle/sections/upload/generate_extra_torrents.php

68 lines
2.3 KiB
PHP
Raw Normal View History

2012-11-14 08:00:19 +00:00
<?
$ExtraTorrentsInsert = array();
foreach ($ExtraTorrents as $ExtraTorrent) {
$Name = $ExtraTorrent['Name'];
$ExtraTorrentsInsert[$Name] = $ExtraTorrent;
2013-02-25 21:16:55 +00:00
$ThisInsert =& $ExtraTorrentsInsert[$Name];
2013-03-17 08:00:17 +00:00
$ExtraTor = new BencodeTorrent($Name, true);
2013-02-25 21:16:55 +00:00
if (isset($ExtraTor->Dec['encrypted_files'])) {
2013-04-24 08:00:23 +00:00
$Err = 'At least one of the torrents contain an encrypted file list which is not supported here';
2013-02-16 08:00:57 +00:00
break;
}
2013-02-25 21:16:55 +00:00
if (!$ExtraTor->is_private()) {
$ExtraTor->make_private(); // The torrent is now private.
$PublicTorrent = true;
}
2012-11-14 08:00:19 +00:00
// File list and size
list($ExtraTotalSize, $ExtraFileList) = $ExtraTor->file_list();
2013-04-24 08:00:23 +00:00
$ExtraDirName = isset($ExtraTor->Dec['info']['files']) ? Format::make_utf8($ExtraTor->get_name()) : '';
2012-11-14 08:00:19 +00:00
$ExtraTmpFileList = array();
foreach ($ExtraFileList as $ExtraFile) {
list($ExtraSize, $ExtraName) = $ExtraFile;
2013-08-22 08:00:54 +00:00
check_file($Type, $ExtraName);
2012-11-14 08:00:19 +00:00
2013-04-24 08:00:23 +00:00
// Make sure the file name is not too long
2012-11-14 08:00:19 +00:00
if (mb_strlen($ExtraName, 'UTF-8') + mb_strlen($ExtraDirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) {
2013-04-24 08:00:23 +00:00
$Err = "The torrent contained one or more files with too long of a name: <br />$ExtraDirName/$ExtraName";
2013-02-25 21:16:55 +00:00
break;
2012-11-14 08:00:19 +00:00
}
// Add file and size to array
2013-02-16 08:00:57 +00:00
$ExtraTmpFileList[] = Torrents::filelist_format_file($ExtraFile);
2012-11-14 08:00:19 +00:00
}
// To be stored in the database
2013-02-25 21:16:55 +00:00
$ThisInsert['FilePath'] = db_string($ExtraDirName);
$ThisInsert['FileString'] = db_string(implode("\n", $ExtraTmpFileList));
$ThisInsert['InfoHash'] = pack('H*', $ExtraTor->info_hash());
$ThisInsert['NumFiles'] = count($ExtraFileList);
$ThisInsert['TorEnc'] = db_string($ExtraTor->encode());
$ThisInsert['TotalSize'] = $ExtraTotalSize;
$Debug->set_flag('upload: torrent decoded');
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT ID
FROM torrents
WHERE info_hash = '" . db_string($ThisInsert['InfoHash']) . "'");
2013-07-10 00:08:53 +00:00
if ($DB->has_results()) {
2012-11-14 08:00:19 +00:00
list($ExtraID) = $DB->next_record();
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT TorrentID
FROM torrents_files
WHERE TorrentID = $ExtraID");
2013-07-10 00:08:53 +00:00
if ($DB->has_results()) {
2013-07-04 08:00:56 +00:00
$Err = "<a href=\"torrents.php?torrentid=$ExtraID\">The exact same torrent file already exists on the site!</a>";
2012-11-14 08:00:19 +00:00
} else {
//One of the lost torrents.
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT INTO torrents_files (TorrentID, File)
VALUES ($ExtraID, '$ThisInsert[TorEnc]')");
$Err = "<a href=\"torrents.php?torrentid=$ExtraID\">Thank you for fixing this torrent.</a>";
2012-11-14 08:00:19 +00:00
}
}
}
2013-02-25 21:16:55 +00:00
unset($ThisInsert);
?>