#####################################################
#  LEO SuperCool BBS / LeoBBS X / 雷傲極酷超級論壇  #
#####################################################
# 基於山鷹(糊)、花無缺製作的 LB5000 XP 2.30 免費版  #
#   新版程式製作 & 版權所有: 雷傲科技 (C)(R)2004    #
#####################################################
#      主頁地址： http://www.LeoBBS.com/            #
#      論壇地址： http://bbs.LeoBBS.com/            #
#####################################################

    $addme = qq~<a href=attachment.cgi?forum=$inforum&topic=$intopic&postno=$editpostnumber&type=.$up_ext><img src=$imagesurl/icon/$filetype.gif border=0 width=16><a> <a href=attachment.cgi?forum=$inforum&topic=$intopic&postno=$editpostnumber&type=.$up_ext>該主題有$div_one個 BitTorrent 格式的檔案，按此下載</a> (共 $fileinfo[7] 位元組)<br>~;

    open(FILE, "${imagesdir}$usrdir/$inforum/$up_name.$up_ext.btfile");
    sysread(FILE, $btinfo,(stat(FILE))[7]);
    close(FILE);
    $btinfo =~ s/\r//isg;

    chomp($btinfo);

    if (length($btinfo) <= 50) {
	eval("use BTINFO;");
	if ($@ eq "") {
		$/ = "";
		open(FILE, "${imagesdir}$usrdir/$inforum/$up_name.$up_ext");
		binmode(FILE);
		my $bufferall = <FILE>;
		close(FILE);
		$/ = "\n";
		my $btfileinfo = process_file($bufferall);
		my (undef, $hash, $announce) = split(/\n/, $btfileinfo);
		open(FILE, ">${imagesdir}$usrdir/$inforum/$up_name.$up_ext.btfile");
		print FILE "$btfileinfo\|$seedinfo";
		close(FILE);
		$btinfo = "$btfileinfo\|$seedinfo";
	}
    }
    
    my ($btfileinfo, $hash, $seedinfo) = split(/\n/, $btinfo);
    ($announce, $seeds, $leeches, $downloaded) = split (/\|/, $seedinfo);
    if ($seeds eq "") {
	$seeds = "不明";
	$leeches = "不明";
	$downloaded = "不明";
    }

my @btfileinfo = split (/\t/, $btfileinfo);
$addme .= qq~
<script>
function ShowMore(){
for (var i = 0; i < AFILE.length; i++){var e = AFILE[i];e.style.display = "";}
var _S = BFILE;
_S.style.display = "none";
}
</script>
<ul><table cellSpacing=1 cellPadding=4 bgColor=$tablebordercolor width=280><tr bgColor=$titlecolor><td align=middle nowrap><font color=$titlefontcolor>檔案名</td><td align=middle nowrap><font color=$titlefontcolor>檔案大小</td></tr>~;

my $allfilelength = 0;
my $counters = 0;
foreach (@btfileinfo) {
    next if ($_ eq "");
    $counters++;
    if ($counters % 2 == 1) {
	$postbackcolor1 = $postcolorone;
	$postfontcolor1 = $postfontcolorone;
    } else {
	$postbackcolor1 = $postcolortwo;
	$postfontcolor1 = $postfontcolortwo;
    }
    my ($filename, $filelength) = split (/\|/, $_);
    $allfilelength += $filelength;

    $lbsd = 'Bytes';
    if ($filelength > 1024) {
	$filelength /= 1024;
	$lbsd = 'KB';
    }
    if($filelength > 1024) {
	$filelength /= 1024;
	$lbsd = 'MB';
    }
    if($filelength > 1024) {
	$filelength /= 1024;
	$lbsd = 'GB';
    }
    $filelength = sprintf("%6.2f",$filelength) . " $lbsd";

    if ($counters eq 8 ) { $addme1 .= qq~ id=AFILE style=display:none~; }

    $addme .= qq~<tr bgColor=$postbackcolor1 $addme1><td align=middle nowrap><font color=$postfontcolor1>$filename</td><td align=middle nowrap><font color=$postfontcolor1>$filelength</td></tr>~;
}
if ($counters >= 8 ) { $addme .= qq~<tr bgColor=$postbackcolor1 id=BFILE style=display:""><td align=right nowrap colspan=2><span style=CURSOR:hand onclick=ShowMore()><font color=$postfontcolor1 title=顯示所有檔案>更多...</font></span>&nbsp;</td></tr>~; }

($announce, $seeds, $leeches, $downloaded) = split (/\|/, $seedinfo);
if ($seeds eq "") {
    $seeds      = "不明";
    $leeches    = "不明";
    $downloaded = "不明";
}
$lbsd = 'Bytes';
if ($allfilelength > 1024) {
    $allfilelength /= 1024;
    $lbsd = 'KB';
}
if($allfilelength > 1024) {
    $allfilelength /= 1024;
    $lbsd = 'MB';
}
if($allfilelength > 1024) {
    $allfilelength /= 1024;
    $lbsd = 'GB';
}
$allfilelength = sprintf("%6.2f",$allfilelength) . " $lbsd";

$addme .= qq~<tr bgColor=$titlecolor><td align=right nowrap colspan=2>種子數：$seeds?&nbsp;連結數：$leeches?&nbsp;完成數：$downloaded&nbsp;<BR>[<a href=getbtinfo.cgi?forum=$inforum&filename=$up_name target=_blank title="按此可獲得即時的資料資料，如果顯示出現\n白屏，可能是對方伺服器無法連結。">本網頁資料並非即時，如需要即時信息請按這裡</a>]&nbsp;<br>總共有 $counters 個檔案，內容共有 $allfilelength&nbsp;<br>URL: $announce&nbsp;<br></td></tr></table></ul>~;
1;
