feedbrowser.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. function make_feed_browser($search, $limit, $mode = 1) {
  3. if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
  4. $rv = '';
  5. $pdo = Db::pdo();
  6. if ($search) {
  7. $search = $pdo->quote($search);
  8. $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
  9. UPPER(title) LIKE UPPER('%$search%'))";
  10. } else {
  11. $search_qpart = "";
  12. }
  13. if ($mode == 1) {
  14. $sth = $pdo->prepare("SELECT feed_url, site_url, title, SUM(subscribers) AS subscribers FROM
  15. (SELECT feed_url, site_url, title, subscribers FROM ttrss_feedbrowser_cache UNION ALL
  16. SELECT feed_url, site_url, title, subscribers FROM ttrss_linked_feeds) AS qqq
  17. WHERE
  18. (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
  19. WHERE tf.feed_url = qqq.feed_url
  20. AND owner_uid = ?) $search_qpart
  21. GROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT " . (int)$limit);
  22. $sth->execute([$_SESSION['uid']]);
  23. } else if ($mode == 2) {
  24. $sth = $pdo->prepare("SELECT *,
  25. (SELECT COUNT(*) FROM ttrss_user_entries WHERE
  26. orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
  27. FROM
  28. ttrss_archived_feeds
  29. WHERE
  30. (SELECT COUNT(*) FROM ttrss_feeds
  31. WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
  32. owner_uid = :uid) = 0 AND
  33. owner_uid = :uid $search_qpart
  34. ORDER BY id DESC LIMIT " . (int)$limit);
  35. $sth->execute([":uid" => $_SESSION['uid']]);
  36. }
  37. $feedctr = 0;
  38. while ($line = $sth->fetch()) {
  39. if ($mode == 1) {
  40. $feed_url = htmlspecialchars($line["feed_url"]);
  41. $site_url = htmlspecialchars($line["site_url"]);
  42. $subscribers = $line["subscribers"];
  43. $check_box = "<input onclick='Lists.onRowChecked(this)'
  44. dojoType=\"dijit.form.CheckBox\"
  45. type=\"checkbox\" \">";
  46. $site_url = "<a target=\"_blank\" rel=\"noopener noreferrer\"
  47. href=\"$site_url\">
  48. <span class=\"fb_feedTitle\">".
  49. htmlspecialchars($line["title"])."</span></a>";
  50. $feed_url = "<a target=\"_blank\" rel=\"noopener noreferrer\" class=\"fb_feedUrl\"
  51. href=\"$feed_url\"><i class='icon-syndicate material-icons'>rss_feed</i></a>";
  52. $rv .= "<li>$check_box $feed_url $site_url".
  53. "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
  54. } else if ($mode == 2) {
  55. $feed_url = htmlspecialchars($line["feed_url"]);
  56. $site_url = htmlspecialchars($line["site_url"]);
  57. $check_box = "<input onclick='Lists.onRowChecked(this)' dojoType=\"dijit.form.CheckBox\"
  58. type=\"checkbox\">";
  59. if ($line['articles_archived'] > 0) {
  60. $archived = sprintf(_ngettext("%d archived article", "%d archived articles", (int) $line['articles_archived']), $line['articles_archived']);
  61. $archived = "&nbsp;<span class='subscribers'>($archived)</span>";
  62. } else {
  63. $archived = '';
  64. }
  65. $site_url = "<a target=\"_blank\" rel=\"noopener noreferrer\"
  66. href=\"$site_url\">
  67. <span class=\"fb_feedTitle\">".
  68. htmlspecialchars($line["title"])."</span></a>";
  69. $feed_url = "<a target=\"_blank\" rel=\"noopener noreferrer\" class=\"fb_feedUrl\"
  70. href=\"$feed_url\"><i class='icon-syndicate material-icons'>rss_feed</i></a>";
  71. $rv .= "<li id=\"FBROW-".$line["id"]."\">".
  72. "$check_box $feed_url $site_url $archived</li>";
  73. }
  74. ++$feedctr;
  75. }
  76. if ($feedctr == 0) {
  77. $rv .= "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
  78. }
  79. return $rv;
  80. }