-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtable.php
More file actions
90 lines (77 loc) · 3.24 KB
/
table.php
File metadata and controls
90 lines (77 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
include_once ('inc/func.php');
?>
<table width="75%" border="1">
<colgroup>
<col span="1" style="width:auto; text-align:left;">
<col span="1" style="width:8%">
<col span="1" style="width:8%">
<col span="1" style="width:8%">
<col span="1" style="width:8%">
<col span="1" style="width:10%">
<col span="1" style="width:8%">
</colgroup>
<?php # Print the table headers ?>
<tr>
<th class='alignleft'><?=$LANG['name']?></th>
<th title="<?=$LANG['seeders']?>"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span></th>
<th title="<?=$LANG['leechers']?>"><span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span></th>
<th title="<?=$LANG['size']?>"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span></th>
<th title="<?=$LANG['complete']?>"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></th>
<th title="<?=$LANG['shared']?>"><img src="//assets.johncave.co.nz/bootstrap/glyphs/share-alt.png" height="19px" alt="" ></th>
<th title="<?=$LANG['get']?>"> <span class="glyphicon glyphicon-download" aria-hidden="true"></span> </th>
</tr>
<?php
#First off, see if the table is cached in Redis
$table = $redis -> get('pltt');
#$age = time()-($redis -> get('plttage'));
if($table){
#print "Served from Redis.";
print $table;
} else{
#print "Creating new table";
# Now start building rows for each Torrent file in the torrent directory. #
$files = array_diff(scandir($CONFIG['tordir']), array('..', '.'));
$table = "";
#var_dump($files);
foreach ($files as $file){
$torrent = new Torrent($CONFIG['tordir'].$file);
$scrape = scrapeTorrent($torrent -> announce(), $torrent->hash_info());
#print json_encode($scrape);
if($scrape[$torrent->hash_info()]['completed'] == 0){
$completed = "?";
} else {
$completed = $scrape[$torrent->hash_info()]['completed'];
}
$table .= "<tr>";
$table .= "<td class='alignleft'><a href='".$CONFIG['torwebdir'].$file."'>".$torrent->name()."</a>";
$table .= "<td>".$scrape[$torrent->hash_info()]['seeders']."</td>";
$table .= "<td>".$scrape[$torrent->hash_info()]['leechers']."</td>";
$table .= "<td> ".bytesToSize($torrent->size())." </td>";
$table .= "<td> ".$completed." </td>";
$shared = $torrent->size()*$scrape[$torrent->hash_info()]['completed'];
$table .= "<td> ".bytesToSize($shared)."</td>";
$table .= "<td> <span style='font-size:20px'><a href='".$CONFIG['torwebdir'].$file."'><span class='glyphicon glyphicon-download-alt' title='".$LANG['getFile']."' aria-hidden='true'></span></a> <a href='".$torrent->magnet()."'> <span class='glyphicon glyphicon-magnet' title='".$LANG['getMagnet']."' aria-hidden='true'></span></a></span></td>";
$table .= "</tr>\n";
}
$table .= "</table>";
#Store the table in Redis then print it.
#print "Generated table";
$redis -> set('pltt', $table);
$redis -> expire('pltt', $CONFIG['tableCache']);
$redis -> set('pltgt', gmdate("H:i:s"));
#$redis -> set('plttage', time());
print $table;
}
/*
foreach ($files as $file){
print "<tr>";
$torrent = new BDecode($CONFIG['tordir'].$file);
print " <td>".$torrent->result['info']['name']."</td>";
print "<td> </td> <td> </td>";
print "<td> ".bytesToSize($torrent->result['info']['length'])."</td>";
#print "<br /><br /><br />";
print "</tr>";
}
*/
?>