-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
97 lines (76 loc) · 3.55 KB
/
index.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
<?php
include_once('config.php');
if (POORMANSCRON) {
include_once('cron.php');
}
$filmsFound = $database->getFoundFilmsOrderByFoundDate();
header('Content-Type: application/xml; charset=utf-8', true);
$xml = new DOMDocument("1.0", "UTF-8");
// RSS element
$rss = $xml->createElement("rss");
$rss->setAttribute("version","2.0"); //set RSS version
$rss->setAttribute( "xmlns:torrent", "http://xmlns.ezrss.it/0.1/" );
// Channel element
$channel = $xml->createElement( "channel" );
$channelTitle = $xml->createElement( "title", "letterboxd watchlist rss torrent" );
$channelDescription = $xml->createElement( "description", "letterboxd watchlist rss torrent" );
$channelLanguage = $xml->createElement( "language", "en-us" );
$feedURL = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$channelLink = $xml->createElement( "link", $feedURL );
$channel->appendChild( $channelTitle );
$channel->appendChild( $channelDescription );
$channel->appendChild( $channelLanguage );
$channel->appendChild( $channelLink );
// Items
foreach ($filmsFound as $film) {
$item = $xml->createElement( "item" );
$filmTitle = $film->title . ($film->year ? ' (' . $film->year . ')' : '');
$filmPubDate = (new DateTime($film->foundDate))->format(DATETIME::RSS);
// Item subelements
$title = $xml->createElement( "title", htmlspecialchars($film->torrentTitle) );
$description = $xml->createElement( "description", $filmTitle );
$pubDate = $xml->createElement( "pubDate", $filmPubDate );
$guid = $xml->createElement( "guid" );
$guid->appendChild( new DOMText( $film->torrentInfo ) );
$item->appendChild( $title );
$item->appendChild( $description );
$item->appendChild( $pubDate );
$item->appendChild( $guid );
if ($film->torrentInfoHash) {
$torrentInfoHash = $xml->createElement( "torrent:infoHash", $film->torrentInfoHash );
$item->appendChild( $torrentInfoHash );
}
if ($film->torrentSize) {
$torrentContentLength = $xml->createElement( "torrent:contentLength", $film->torrentSize );
$item->appendChild( $torrentContentLength );
}
if ((!$film->torrentFile && !$film->torrentMagnet) ||
(FEED_DOWNLOAD_LINK === 'torrent' && !$film->torrentFile) ||
(FEED_DOWNLOAD_LINK === 'magnet' && !$film->torrentMagnet) ) {
continue;
}
$enclosure = $xml->createElement( "enclosure" );
if ($film->torrentSize) $enclosure->setAttribute( "length", $film->torrentSize );
$enclosure->setAttribute( "type", "application/x-bittorrent" );
$link = $xml->createElement( "link" );
if ((FEED_DOWNLOAD_LINK === 'both' || FEED_DOWNLOAD_LINK === 'torrent') && $film->torrentFile) {
$enclosure->setAttribute( "url", $film->torrentFile );
$link->appendChild( new DOMText( $film->torrentFile ) );
} else if (FEED_DOWNLOAD_LINK === 'magnet' && $film->torrentMagnet) {
$enclosure->setAttribute( "url", $film->torrentMagnet );
$link->appendChild( new DOMText( $film->torrentMagnet ) );
}
$item->appendChild( $enclosure );
$item->appendChild( $link );
if ((FEED_DOWNLOAD_LINK === 'both' || FEED_DOWNLOAD_LINK === 'magnet') && $film->torrentMagnet) {
$torrentMagnetURI = $xml->createElement( "torrent:magnetURI" );
$torrentMagnetURI->appendChild( new DOMText( $film->torrentMagnet ) );
$item->appendChild( $torrentMagnetURI );
}
// Item complete
$channel->appendChild( $item );
}
$rss->appendChild( $channel );
$xml->appendChild( $rss );
// Parse the XML
echo $xml->saveXML();