prepare('SELECT * FROM blog_members WHERE username = :username');
$stmt->execute(array(':username' => html($_SESSION['username'])));
$row = $stmt->fetch();
$uid = $row['memberID'];
}
else {
// s'il n'y a pas de session, c'est donc un visiteur avec l'id 32
$uid = 32;
}
/*
//on recherche le hash dans la base xbt_files
$stmt1 = $db->prepare('SELECT * FROM xbt_files WHERE fid = :fid');
$stmt1->execute(array(':fid' => $fid));
$row1 = $stmt1->fetch();
*/
//on recherche le torrent dans la base blog_posts_seo
$stmt2 = $db->prepare('SELECT * FROM blog_posts_seo WHERE postID = :postID');
$stmt2->execute(array(':postID' => $fid));
$row2 = $stmt2->fetch();
if($row2['postID'] == '') {
header('Location: '.SITEURL.'/torrents.php?action=noexist');
}
$torrent = $row2['postTorrent'];
$torrentfile = $REP_TORRENTS.'/'.$torrent;
// On décode le fichier torrent
$fd = fopen($torrentfile, "rb");
$alltorrent = fread($fd, filesize($torrentfile));
$array = BDecode($alltorrent);
fclose($fd);
//On cherche le pid
$stmt3 = $db->prepare('SELECT * FROM blog_members WHERE memberID = :uid');
$stmt3->execute(array(':uid' => $uid));
$row3 = $stmt3->fetch();
// Il n'y a que les membres + les visiteurs qui peuvent télécharger
// pas de userid = 0
if ($row3['pid'] == '') {
header('Location: '.SITEURL);
}
if ($row3['pid'] == '00000000000000000000000000000000') {
$pid = '00000000000000000000000000000000';
}
else {
$pid = $row3['pid'];
}
$tracker_announce_urls = SITEURL.':'.ANNOUNCEPORT.'/announce';
// On construit la nouvelle announce avec le pid (passkey ...)
$array["announce"] = SITEURL.":".ANNOUNCEPORT."/".$pid."/announce";
$alltorrent=BEncode($array);
// On construit le header
header("Content-Type: application/x-bittorrent");
header('Content-Disposition: attachment; filename="['.SITENAMELONG.']'.$torrent.'"');
print($alltorrent);
if(isset($_SESSION['username'])) {
write_log('Download torrent : '.html($row2['postTitle']).' par '.html($_SESSION['username']), $db);
}
else {
write_log('Download torrent : '.html($row2['postTitle']).' par Visiteur', $db);
}
?>