readrss.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /* $Id: readrss.php 3134 2007-06-27 00:07:58Z danez $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // prevent direct invocation
  16. if ((!isset($cfg['user'])) || (isset($_REQUEST['cfg']))) {
  17. @ob_end_clean();
  18. @header("location: ../../index.php");
  19. exit();
  20. }
  21. /******************************************************************************/
  22. // readrss functions
  23. require_once('inc/functions/functions.readrss.php');
  24. // require
  25. require_once("inc/classes/lastRSS.php");
  26. // Just to be safe ;o)
  27. if (!defined("ENT_COMPAT")) define("ENT_COMPAT", 2);
  28. if (!defined("ENT_NOQUOTES")) define("ENT_NOQUOTES", 0);
  29. if (!defined("ENT_QUOTES")) define("ENT_QUOTES", 3);
  30. // Get RSS feeds from Database
  31. $arURL = GetRSSLinks();
  32. // create lastRSS object
  33. $rss = new lastRSS();
  34. // setup transparent cache
  35. $cacheDir = $cfg['path'].".rsscache";
  36. if (!checkDirectory($cacheDir, 0777))
  37. @error("Error with rss-cache-dir", "index.php?iid=index", "", array($cacheDir));
  38. $rss->cache_dir = $cacheDir;
  39. $rss->cache_time = $cfg["rss_cache_min"] * 60; // 1200 = 20 min. 3600 = 1 hour
  40. $rss->strip_html = false; // don't remove HTML from the description
  41. // init template-instance
  42. tmplInitializeInstance($cfg["theme"], "page.readrss.tmpl");
  43. // set vars
  44. // Loop through each RSS feed
  45. $rss_list = array();
  46. foreach ($arURL as $rid => $url) {
  47. if (isset($_REQUEST["debug"]))
  48. $rss->cache_time=0;
  49. $rs = $rss->Get($url);
  50. if ($rs !== false) {
  51. if (!empty( $rs["items"])) {
  52. // Check this feed has a title tag:
  53. if (!isset($rs["title"]) || empty($rs["title"]))
  54. $rs["title"] = "Feed URL ".htmlentities($url, ENT_QUOTES)." Note: this feed does not have a valid 'title' tag";
  55. // Check each item in this feed has link, title and publication date:
  56. for ($i=0; $i < count($rs["items"]); $i++) {
  57. // Don't include feed items without a link:
  58. if (!isset($rs["items"][$i]["link"]) || empty($rs["items"][$i]["link"])){
  59. array_splice ($rs["items"], $i, 1);
  60. // Continue to next feed item:
  61. continue;
  62. }
  63. // Set the label for the link title (<a href="foo" title="$label">)
  64. $rs["items"][$i]["label"] = $rs["items"][$i]["title"];
  65. // Check item's pub date:
  66. if (!isset($rs["items"][$i]["pubDate"]) || empty($rs["items"][$i]["pubDate"]))
  67. $rs["items"][$i]["pubDate"] = "Unknown publication date";
  68. // Check item's title:
  69. if (!isset($rs["items"][$i]["title"]) || empty($rs["items"][$i]["title"])) {
  70. // No title found for this item, create one from the link:
  71. $link = html_entity_decode($rs["items"][$i]["link"]);
  72. if (strlen($link) >= 45)
  73. $link = substr($link, 0, 42)."...";
  74. $rs["items"][$i]["title"] = "Unknown feed item title: $link";
  75. } elseif(strlen($rs["items"][$i]["title"]) >= 67){
  76. // if title string is longer than 70, truncate it:
  77. // Note this is a quick hack, link titles will also be truncated as well
  78. // as the feed's display title in the table.
  79. $rs["items"][$i]["title"] = substr($rs["items"][$i]["title"], 0, 64)."...";
  80. }
  81. // decode html entities like &amp; -> & , and then uri_encode them them & -> %26
  82. // This is needed to get Urls with more than one GET Parameter working
  83. $rs["items"][$i]["link"] = rawurlencode(html_entity_decode($rs["items"][$i]["link"]));
  84. }
  85. $stat = 1;
  86. } else {
  87. // feed URL is valid and active, but no feed items were found:
  88. $stat = 2;
  89. }
  90. } else {
  91. // Unable to grab RSS feed, must of timed out
  92. $stat = 3;
  93. }
  94. array_push($rss_list, array(
  95. 'stat' => $stat,
  96. 'rid' => $rid,
  97. 'title' => (isset($rs["title"]) ? $rs["title"] : ""),
  98. 'url' => $url,
  99. 'feedItems' => $rs['items']
  100. )
  101. );
  102. }
  103. $tmpl->setloop('rss_list', $rss_list);
  104. //
  105. $tmpl->setvar('_TRANSFERFILE',$cfg['_TRANSFERFILE']);
  106. $tmpl->setvar('_TIMESTAMP', $cfg['_TIMESTAMP']);
  107. $tmpl->setvar('_ID_IMAGES', $cfg['_ID_IMAGES']);
  108. $tmpl->setvar('_MULTIPLE_UPLOAD', $cfg['_MULTIPLE_UPLOAD']);
  109. //
  110. $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
  111. //
  112. $tmpl->setvar('enable_multiupload', $cfg["enable_multiupload"]);
  113. tmplSetTitleBar($cfg["pagetitle"].' - RSS Torrents');
  114. tmplSetFoot();
  115. tmplSetIidVars();
  116. // parse template
  117. $tmpl->pparse();
  118. ?>