-
Notifications
You must be signed in to change notification settings - Fork 26
/
torrent.php
219 lines (167 loc) · 6.05 KB
/
torrent.php
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
require_once('includes/config.php');
require_once('includes/rivr.php');
require_once('includes/functions.php');
if($_GET['dl']){
$hash = $_GET['hash'];
}else{
$hash = explode('/',$_SERVER['REQUEST_URI']);
$hash = $hash[count($hash)-1];
}
$hash = strtoupper(trim(htmlspecialchars(urldecode($hash))));
$query = $sdb->query("SELECT id, source_id, date, category FROM rtindex0,rtindex1,rtindex2,rtindex3 WHERE hash = '$hash';");
if(!$query->num_rows){
header("Location: error");
die();
}
while($data = $query->fetch_assoc()){
$tquery = $db->query("SELECT title, url FROM rtindex WHERE id = '{$data['id']}';");
$tdata = $tquery->fetch_assoc();
$data['title'] = $tdata['title'];
$data['url'] = $tdata['url'];
$cdata[] = $data;
}
$count = count($cdata);
$title = $cdata[0]['title'];
if($_GET['dl']){
$tt = '[rivr.eu]'.str_replace(' ','.',$title);
$data = Rivr::getTorrent($hash);
header("Content-type: application/x-download");
header("Content-Length: ".strlen($data));
header("Content-Disposition: attachment; filename=$tt.torrent");
header("Content-Transfer-Encoding: binary");
echo $data;
die();
}
$query = $db->query("SELECT id, url FROM sources;");
if($query->num_rows){
while($data = $query->fetch_assoc()){
$sources[$data['id']] = $data['url'];
}
}
$torrent = Rivr::getTorrentInfo($hash);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="images/favicon.png">
<title><?php echo $title .' ~ '. ENGINE_NAME; ?></title>
<link rel="stylesheet" type="text/css" href="css/main.css"/>
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="css/popup.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/search.js"></script>
<script src="js/popup.js"></script>
</head>
<body>
<img src="images/loading.png" id="loading"/>
<div id="container">
<div id="top">
<form action="search" method="GET" id="search">
<a href="index"><img src="images/logo_sm.png" id="logo_top"/></a> <input type="search" name="q" id="q" class="qs" value="<?php echo $q; ?>" required/><span id="sbt"></span>
</form>
</div>
<div id="ad_top">
<script type="text/javascript">
var ad_idzone = "1751578",
ad_width = "728",
ad_height = "90";
</script>
<script type="text/javascript" src="https://ads.exoclick.com/ads.js"></script>
<noscript><a href="http://main.exoclick.com/img-click.php?idzone=1751578" target="_blank"><img src="https://syndication.exoclick.com/ads-iframe-display.php?idzone=1751578&output=img&type=728x90" width="728" height="90"></a></noscript>
</div>
<script>
function cdir(nfid){
$('.'+nfid).slideToggle();
}
</script>
<div id="results">
<p align="center">
<?php
$magnet = "magnet:?xt=urn:btih:$hash&dn=".urlencode($title).'&tr='.implode('&tr=',array('udp://tracker.openbittorrent.com:80/announce','udp://tracker.publicbt.com:80/announce','udp://open.demonii.com:1337/announce','udp://tracker.leechers-paradise.org:6969/announce','udp://coppersurfer.tk:6969/announce'));
if($torrent){
echo "<a href=\"torrent?hash=$hash&dl=1\" class=\"ptag\">Download torrent</a> ";
foreach($torrent['announce-list'] as $tracker){
$trackers[] = $tracker[0];
}
$magnet = "magnet:?xt=urn:btih:$hash&dn=".urlencode($title).'&tr='.implode('&tr=',$trackers);
}
echo "<a href=\"$magnet\" class=\"ptag\">Magnet</a>";
?>
</p>
<?php
echo "<table class=\"rtable\">";
echo "<tr><td class=\"top_row\" width=\"800px\">$title ~ $count sources</td></tr>";
foreach($cdata as $data){
echo "<tr class=\"row\"><td><img src=\"https://plus.google.com/_/favicon?domain={$sources[$data['source_id']]}\" class=\"icon\"> ".$sources[$data['source_id']];
if($data['url']){
echo " · <a href=\"{$data['url']}\" target=\"blank\">{$data['title']}</a>";
}
echo " · ".Rivr::getTypeInt($data['category'])."</td></tr>";
}
echo "</table><br/>";
if($torrent){
echo "<table class=\"table\"><tr><td width=\"405px\" align=\"left\" valign=\"top\">";
//trackers info
echo "<td width=\"405px\" align=\"right\" valign=\"top\"><table class=\"rtable_sm\">";
echo "<tr><td class=\"top_row\" width=\"390px\">Trackers</td></tr>";
foreach($trackers as $tracker){
echo "<tr class=\"row small\"><td>$tracker</td></tr>";
}
echo "</table></td></tr></table><br/>";
//torrent contents
function &getArrayPath($path, &$array){
$path = explode('/',$path);
$folder = array_shift($path);
$path = implode('/',$path);
if($folder=='') return $array;
return getArrayPath($path, $array[$folder]);
}
foreach($torrent['info']['files'] as $file){
$lfile = $file['path'][count($file['path'])-1];
unset($file['path'][count($file['path'])-1]);
$size = bytesToStr($file['length']);
$file['path'] = array_reverse($file['path']);
$path = &getArrayPath(implode('/',$file['path']), $paths);
$path[] = array($lfile,$size);
$total_size += $file['length'];
}
if(!$paths){
$paths[] = array($torrent['info']['name'],bytesToStr($torrent['info']['length']));
$total_size = $torrent['info']['length'];
}
function printFiles($files, $level, $fid){
foreach($files as $folder => $file){
echo "<div class=\"$fid $cf";
if($fid) echo ' hidden';
echo "\">";
if(!is_numeric($folder)){
$nfid = md5($folder.$level);
echo "<div class=\"row\" onclick=\"cdir('$nfid')\">";
echo str_repeat(' ',$level);
echo "<img src=\"images/ext/folder.png\" class=\"icon\"> $folder</div>";
printFiles($file, $level+1, $nfid);
}else{
$ext = explode('.',$file[0]);
$ext = $ext[count($ext)-1];
echo "<div class=\"row\">";
echo str_repeat(' ',$level);
echo "<img src=\"images/ext/file_extension_$ext.png\" class=\"icon\"> {$file[0]} - {$file[1]}</div>";
}
echo "</div>";
}
}
echo "<table class=\"rtable\">";
echo "<tr><td class=\"top_row\" width=\"800px\">Torrent contents ~ ".bytesToStr($total_size)."</td></tr>";
echo "<tr><td>";
printFiles($paths, 0, '', '');
echo "</td></tr></table>";
}
?>
</div>
<?php include("includes/footer.php"); ?>
</div>
</body>
</html>