forked from swetorrentking/rartracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss.php
116 lines (93 loc) · 3.35 KB
/
rss.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
<?php
include('api/secrets.php');
include('api/Config.php');
$db = new PDO($database.':host='.$host.';dbname='.$dbname.';charset=utf8', $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
function mksize($bytes) {
if ($bytes < 1000 * 1024)
return number_format($bytes / 1024, 2) . " KiB";
elseif ($bytes < 1000 * 1048576)
return number_format($bytes / 1048576, 2) . " MiB";
elseif ($bytes < 1000 * 1073741824)
return number_format($bytes / 1073741824, 2) . " GiB";
else
return number_format($bytes / 1099511627776, 3) . " TiB";
}
$passkey = $_GET["passkey"];
if (!preg_match("/^[a-z0-9]{32}$/", $passkey)) {
echo "Invalid passkey";
exit;
}
$sth = $db->prepare("SELECT id FROM users WHERE passkey = ?");
$sth->bindParam(1, $passkey, PDO::PARAM_STR);
$sth->execute();
$user = $sth->fetch();
if (!$user) {
echo "User not found.";
exit();
}
$s = $_GET["s"];
if (!$s) {
$s = $_GET["vad"];
}
$category = array();
$category[1] = "DVDR PAL";
$category[2] = "DVDR CUSTOM";
$category[3] = "DVDR TV";
$category[4] = "720p Film";
$category[5] = "1080p Film";
$category[6] = "720p TV";
$category[7] = "1080p TV";
$category[8] = "Svensk TV";
$category[9] = "Audiobook";
$category[10] = "E-book";
$category[11] = "E-paper";
$category[12] = "Music";
$cats = $_GET["cat"];
if ($cats) {
if (!preg_match("/^[0-9,]+$/", $cats)) {
echo "Invalid categories";
exit;
}
$cats = explode(",", $cats);
}
$where = array();
$finalWhere = "";
if ($cats) {
$where[] = "category IN (".implode(", ", $cats).")";
}
if ($s == 1) {
$where[] = 'reqid = 0';
} else if($s == 2)
$where[] = 'reqid > 0';
else if ($s == 3) {
$bookmark = true;
}
if ($_GET['p2p'] != "1") {
$where[] = 'p2p = 0';
}
if (count($where) > 0) {
$finalWhere = "WHERE " . implode(" AND ", $where);
}
$SITENAME = Config::NAME;
$DESCR = "RSS Feeds";
$BASEURL = Config::SITE_URL;
$SITEMAIL = Config::SITE_MAIL;
header("Content-Type: application/xml");
print("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rss version=\"0.91\">\n<channel>\n" .
"<title>" . $SITENAME . "</title>\n<link>" . $BASEURL . "</link>\n<description>" . $DESCR . "</description>\n" .
"<language>en-usde</language>\n<copyright> Copyright " . $SITENAME . "</copyright>\n<webMaster>".$SITEMAIL."</webMaster>\n" .
"<image><title>" . $SITENAME . "</title>\n<url>" . $BASEURL . "/favicon.ico</url>\n<link>" . $BASEURL . "</link>\n" .
"<width>16</width>\n<height>16</height>\n<description>" . $DESCR . "</description>\n</image>\n");
if ($bookmark) {
$res = $db->query("SELECT torrents.id, name, descr, filename, size, category, seeders, leechers, added FROM bookmarks LEFT JOIN torrents ON bookmarks.torrentid = torrents.id WHERE bookmarks.userid = ".$user[0]." ORDER BY bookmarks.id DESC LIMIT 15");
} else {
$res = $db->query("SELECT id,name,descr,filename,size,category,seeders,leechers,added FROM torrents $finalWhere ORDER BY added DESC LIMIT 15");
}
while ($row = $res->fetch()){
list($id, $name, $descr, $filename, $size, $cat, $seeders, $leechers, $added, $catname) = $row;
$link = $BASEURL . "/download.php?id=$id&passkey=$passkey";
echo("<item><title>" . htmlspecialchars($name) . "</title>\n<link>" . $link . "</link>\n<description>Kategori: " . $category[$cat] . " \n Storlek: " . mksize($size) . "\n " . htmlspecialchars($descr) . "\n</description>\n<pubDate>".$added."</pubDate></item> \n");
}
echo("</channel>\n</rss>\n");
?>