Gazelle/sections/upload/generate_extra_torrents.php

60 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];
$ExtraTor = new BEncTorrent($Name, true);
if (isset($ExtraTor->Dec['encrypted_files'])) {
2013-02-16 08:00:57 +00:00
$Err = "At least one of the torrents contain an encrypted file list which is not supported here";
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-02-25 08:00:45 +00:00
$ExtraDirName = isset($ExtraTor->Val['info']->Val['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;
check_file($ExtraType, $ExtraName);
// Make sure the filename is not too long
if (mb_strlen($ExtraName, 'UTF-8') + mb_strlen($ExtraDirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) {
$Err = 'The torrent contained one or more files with too long a name (' . $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');
$DB->query("SELECT ID FROM torrents WHERE info_hash='" . db_string($ThisInsert['InfoHash']) . "'");
2012-11-14 08:00:19 +00:00
if ($DB->record_count() > 0) {
list($ExtraID) = $DB->next_record();
$DB->query("SELECT TorrentID FROM torrents_files WHERE TorrentID = " . $ExtraID);
if ($DB->record_count() > 0) {
$Err = '<a href="torrents.php?torrentid=' . $ExtraID . '">The exact same torrent file already exists on the site!</a>';
} else {
//One of the lost torrents.
2013-02-25 21:16:55 +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);
?>