| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,68 @@ |
| 1 |
+<?php |
|
| 2 |
+//re-read config.php file after it has been written |
|
| 3 |
+include ("config.php");
|
|
| 4 |
+require_once ("funcsv2.php");
|
|
| 5 |
+ |
|
| 6 |
+//This script runs whenever: |
|
| 7 |
+//1) a torrent is added to the database |
|
| 8 |
+//2) a torrent is deleted from the database |
|
| 9 |
+//3) the config.php file is edited |
|
| 10 |
+//This is to ensure that the correct rss.xml file is available and generated |
|
| 11 |
+ |
|
| 12 |
+//connect to database |
|
| 13 |
+$db = mysql_connect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Cannot connect to database. Check your username and password in the config file.</p>"); |
|
| 14 |
+mysql_select_db($database) or die(errorMessage() . "Error selecting database.</p>"); |
|
| 15 |
+$query = "SELECT filename,url,size,pubDate FROM ".$prefix."namemap ORDER BY pubDate DESC"; |
|
| 16 |
+$results = mysql_query($query) or die(errorMessage() . "Can't do SQL query - " . mysql_error() . "</p>"); |
|
| 17 |
+ |
|
| 18 |
+//if there are no entries in database or RSS feed is disabled in config.php file, delete rss.xml file |
|
| 19 |
+if (mysql_num_rows($results) == 0 || $enablerss == false) |
|
| 20 |
+{
|
|
| 21 |
+ if (file_exists("rss/rss.xml")) //make sure file exists before trying to delete
|
|
| 22 |
+ unlink("rss/rss.xml") or die ("Can't delete rss.xml file using unlink(). Are you running the server under Windows?");
|
|
| 23 |
+} |
|
| 24 |
+else //otherwise, generate new rss.xml file |
|
| 25 |
+{
|
|
| 26 |
+ $fd = fopen("rss/rss.xml", "w") or die(errorMessage() . "Error: Unable to write to rss.xml file!</p>");
|
|
| 27 |
+ $start_text = |
|
| 28 |
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" . |
|
| 29 |
+ "<rss version=\"2.0\">\n" . |
|
| 30 |
+ "<channel>\n" . |
|
| 31 |
+ "<title>" . clean($rss_title) . "</title>\n" . |
|
| 32 |
+ "<link>" . $rss_link . "</link>\n" . |
|
| 33 |
+ "<description>" . clean($rss_description) . "</description>\n" . |
|
| 34 |
+ "<lastBuildDate>" . date('D, j M Y h:i:s') . " " . $timezone . "</lastBuildDate>\n";
|
|
| 35 |
+ |
|
| 36 |
+ $middle_text = ""; |
|
| 37 |
+ while ($row = mysql_fetch_row($results)) |
|
| 38 |
+ {
|
|
| 39 |
+ //figure out full torrent URL |
|
| 40 |
+ $url = $website_url . $_SERVER['REQUEST_URI']; |
|
| 41 |
+ $url = str_replace("newtorrents.php", "", $url);
|
|
| 42 |
+ $url = str_replace("editconfig.php", "", $url);
|
|
| 43 |
+ $url = str_replace("deleter.php", "", $url);
|
|
| 44 |
+ $url = $url . "torrents/" . $row[0] . ".torrent"; |
|
| 45 |
+ $url = str_replace(" ", "%20", $url);
|
|
| 46 |
+ |
|
| 47 |
+ //figure out file(s) size |
|
| 48 |
+ $file_size = bytesToString($row[2]); |
|
| 49 |
+ |
|
| 50 |
+ //go through each entry in database |
|
| 51 |
+ $middle_text = $middle_text . "<item>\n" . |
|
| 52 |
+ "<title>" . $row[0] . " (" . $file_size . ")</title>\n" .
|
|
| 53 |
+ "<description>" . $row[0] . " (" . $file_size . ") " . $row[1] . "</description>\n" .
|
|
| 54 |
+ "<pubDate>" . $row[3] . " " . $timezone . "</pubDate>\n" . |
|
| 55 |
+ "<guid>" . $url . "</guid>\n" . |
|
| 56 |
+ "<link>" . $url . "</link>\n" . |
|
| 57 |
+ "<enclosure url=\"" . $url . "\" length=\"" . filesize("torrents/" . $row[0] . ".torrent") . "\" type=\"application/x-bittorrent\" />\n" .
|
|
| 58 |
+ "</item>\n"; |
|
| 59 |
+ } |
|
| 60 |
+ |
|
| 61 |
+ $end_text = "</channel>\n</rss>"; |
|
| 62 |
+ |
|
| 63 |
+ fwrite($fd, $start_text . $middle_text . $end_text); |
|
| 64 |
+ fclose($fd); |
|
| 65 |
+ |
|
| 66 |
+} |
|
| 67 |
+ |
|
| 68 |
+?> |
|
| 0 | 69 |
\ No newline at end of file |