index.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. require_once('php/autoloader.php');
  3. $section="";
  4. $loc = "US";
  5. $lang = "en";
  6. $feed_url="";
  7. if(isset( $_GET['section'])) {
  8. $section = $_GET["section"];
  9. }
  10. if(isset( $_GET['loc'])) {
  11. $loc = strtoupper($_GET["loc"]);
  12. }
  13. if(isset( $_GET['lang'])) {
  14. $lang = $_GET["lang"];
  15. }
  16. if($section) {
  17. $feed_url="https://news.google.com/news/rss/headlines/section/topic/".strtoupper($section)."?ned=".$loc."&hl=".$lang;
  18. } else {
  19. $feed_url="https://news.google.com/rss?gl=".$loc."&hl=".$lang."-".$loc."&ceid=".$loc.":".$lang;
  20. }
  21. //https://news.google.com/news/rss/headlines/section/topic/CATEGORYNAME?ned=in&hl=en
  22. $feed = new SimplePie();
  23. // Set the feed to process.
  24. $feed->set_feed_url($feed_url);
  25. // Run SimplePie.
  26. $feed->init();
  27. // This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
  28. $feed->handle_content_type();
  29. //replace chars that old machines probably can't handle
  30. function clean_str($str) {
  31. $str = str_replace( "‘", "'", $str );
  32. $str = str_replace( "’", "'", $str );
  33. $str = str_replace( "“", '"', $str );
  34. $str = str_replace( "”", '"', $str );
  35. $str = str_replace( "–", '-', $str );
  36. $str = str_replace( '&nbsp;', ' - ', $str );
  37. return $str;
  38. }
  39. ?>
  40. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 2.0//EN">
  41. <html>
  42. <head>
  43. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  44. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  45. <link rel="stylesheet" type="text/css" href="/main.css">
  46. <title>
  47. NewsFeed.FYI
  48. </title>
  49. </head>
  50. <body>
  51. <h1 class="newsfeed">
  52. <i>NewsFeed.FYI</i>
  53. </h1>
  54. <hr>
  55. <p style="text-align: center; font-size: small;">
  56. Basic HTML Google News Feed. Based on
  57. <a href="https://github.com/ActionRetro/68k-news" target="_blank">
  58. <b>source</b>
  59. </a>
  60. for
  61. <a href="http://68k.news" target="_blank">
  62. <b>68k.news</b>
  63. </a>
  64. , originally built by
  65. <a href="https://youtube.com/ActionRetro" target="_blank">
  66. <b>Action Retro</b>
  67. </a>
  68. .
  69. </p>
  70. <?php
  71. if($section) {
  72. $section_title = explode(" - ", strtoupper($feed->get_title()));
  73. echo "<h2 syle='text-align: center;'>" . $section_title[0] . " NEWS</h2>";
  74. }
  75. ?>
  76. <p style="text-align: center; font-size: small;">
  77. <a href="index.php?loc=<?php echo $loc ?>">TOP</a>
  78. <a href="index.php?section=world&loc=<?php echo strtoupper($loc) ?>">WORLD</a>
  79. <a href="index.php?section=nation&loc=<?php echo strtoupper($loc) ?>">NATION</a>
  80. <a href="index.php?section=business&loc=<?php echo strtoupper($loc) ?>">BUSINESS</a>
  81. <a href="index.php?section=technology&loc=<?php echo strtoupper($loc) ?>">TECHNOLOGY</a>
  82. <a href="index.php?section=entertainment&loc=<?php echo strtoupper($loc) ?>">ENTERTAINMENT</a>
  83. <a href="index.php?section=science&loc=<?php echo strtoupper($loc) ?>">SCIENCE</a>
  84. <a href="index.php?section=health&loc=<?php echo strtoupper($loc) ?>">HEALTH</a>
  85. <br>
  86. <span style="size: 1;">-=-=-=-=-=-=-=-=-=-=-=-=-=-</span>
  87. <br>
  88. <?php echo strtoupper($loc) ?> Edition
  89. <a href="choose_edition.php">(Change)</a>
  90. </p>
  91. <?php
  92. $title_filters = array(
  93. " SPORTS",
  94. " NFL",
  95. " NBA",
  96. " MLB",
  97. "ESPN"
  98. );
  99. /*
  100. Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
  101. */
  102. foreach ($feed->get_items() as $item):
  103. $item_title = clean_str($item->get_title());
  104. $item_link = "article.php?loc=" . $loc . '&a=' . $item->get_permalink();
  105. $up_title = strtoupper($item_title);
  106. // if (str_contains($up_title, "SPORTS") == true)
  107. // {
  108. // // 🧒 👦 👨‍👦‍👦
  109. // echo '<p class="sports" style="font-size: 4px;">
  110. // ⚽ 🏀 🏈 ⚾️ 🎾 🏐 🏉 🎱 🏆 🏟 ⛹️
  111. // <a href="$item_link">happened</a>
  112. // </p>';
  113. // // Break out of 2nd-level loop.
  114. // continue;
  115. // }
  116. for ($i = 0; $i < count($title_filters); $i++)
  117. {
  118. $testing = $title_filters[$i];
  119. if (str_contains($up_title, $testing) == true)
  120. {
  121. // 🧒 👦 👨‍👦‍👦
  122. echo '<p class="sports" style="font-size: 4px;">
  123. ⚽ 🏀 🏈 ⚾️ 🎾 🏐 🏉 🎱 🏆 🏟 ⛹️
  124. <a href="' . $item_link . '">happened</a>
  125. </p>';
  126. // Break out of 2nd-level loop.
  127. continue 2;
  128. }
  129. }
  130. $subheadlines = clean_str($item->get_description());
  131. $remove_google_link = explode("<li><strong>", $subheadlines);
  132. $no_blank = str_replace('target="_blank"', "", $remove_google_link[0]) . "</li></ol></font></p>";
  133. $cleaned_links = str_replace('<a href="', '<a href="article.php?loc=' . $loc . '&a=', $no_blank);
  134. $cleaned_links = strip_tags($cleaned_links, '<a><ol><ul><li><br><p><small><font><b><strong><i><em><blockquote><h1><h2><h3><h4><h5><h6>');
  135. $cleaned_links = str_replace( 'strong>', 'b>', $cleaned_links); //change <strong> to <b>
  136. $cleaned_links = str_replace( 'em>', 'i>', $cleaned_links); //change <em> to <i>
  137. $cleaned_links = str_replace( "View Full Coverage on Google News", "", $cleaned_links);
  138. ?>
  139. <h3 style="font-size: 5;">
  140. <a href="<?php echo $item_link; ?>">
  141. <?php echo clean_str($item->get_title()); ?>
  142. </a>
  143. </h3>
  144. <p style="font-size: 4;">
  145. <?php echo $cleaned_links; ?>
  146. </p>
  147. <p style="font-size: small;">Posted on
  148. <?php echo $item->get_date('j F Y | g:i a'); ?>
  149. </p>
  150. <?php endforeach; ?>
  151. <p style="text-align: center; font-size: small;">v1.0 Powered by Mozilla Readability (Andres Rey PHP Port) and SimplePie</p>
  152. </body>
  153. </html>