index.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 style="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. // A list of all the keyworks to trigger Sports-style
  93. $title_filters = array(
  94. "NFL",
  95. "APFL",
  96. "AAFL",
  97. "AFL",
  98. "AIFA",
  99. "CFL",
  100. "CIFL",
  101. "IFL",
  102. "IWFL",
  103. "NFLE",
  104. "NIFL",
  105. "XFL",
  106. "NBA",
  107. "MLB",
  108. "NHL",
  109. "MMA",
  110. "ESPN",
  111. "SPORTS",
  112. "Fox Sports",
  113. "Yahoo Sports",
  114. "NBC Sports",
  115. "CBS Sports",
  116. "KSL Sports",
  117. "Big Ten Network",
  118. "The Athletic",
  119. "Sports Illustrated",
  120. "Sporting News",
  121. "Bleacher Report",
  122. "Dowgnation",
  123. "247Sports",
  124. "FOOTBALL",
  125. "Football",
  126. "BASKETBALL",
  127. "Basketball",
  128. "HOCKEY",
  129. "Hockey"
  130. );
  131. // A list of all the title keywords. If any
  132. $description_filters = array(
  133. );
  134. /*
  135. Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
  136. */
  137. foreach ($feed->get_items() as $item):
  138. $item_title = clean_str($item->get_title());
  139. $item_link = "article.php?loc=" . $loc . '&a=' . $item->get_permalink();
  140. $subheadlines = clean_str($item->get_description());
  141. $up_title = $item_title; // strtoupper($item_title);
  142. $up_description = $subheadlines; // strtoupper($subheadlines);
  143. for ($i = 0; $i < count($title_filters); $i++)
  144. {
  145. if (str_contains($up_title, $title_filters[$i]) == true ||
  146. str_contains($up_description, $title_filters[$i]) == true)
  147. {
  148. // 🧒 👦 👨‍👦‍👦
  149. echo '<p class="sports" style="font-size: 4px;">
  150. ⚽ 🏀 🏈 ⚾️ 🎾 🏐 🏉 🎱 🏆 🏟 ⛹️
  151. <a href="' . $item_link . '">happened</a>
  152. </p>';
  153. // Break out of 2nd-level loop.
  154. continue 2;
  155. }
  156. }
  157. $subheadlines = clean_str($item->get_description());
  158. $remove_google_link = explode("<li><strong>", $subheadlines);
  159. $no_blank = str_replace('target="_blank"', "", $remove_google_link[0]) . "</li></ol></font></p>";
  160. $cleaned_links = str_replace('<a href="', '<a href="article.php?loc=' . $loc . '&a=', $no_blank);
  161. $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>');
  162. $cleaned_links = str_replace( 'strong>', 'b>', $cleaned_links); //change <strong> to <b>
  163. $cleaned_links = str_replace( 'em>', 'i>', $cleaned_links); //change <em> to <i>
  164. $cleaned_links = str_replace( "View Full Coverage on Google News", "", $cleaned_links);
  165. ?>
  166. <h3 style="font-size: 5;">
  167. <a href="<?php echo $item_link; ?>">
  168. <?php echo clean_str($item->get_title()); ?>
  169. </a>
  170. </h3>
  171. <p style="font-size: 4;">
  172. <?php echo $cleaned_links; ?>
  173. </p>
  174. <p style="font-size: small;">Posted on
  175. <?php echo $item->get_date('j F Y | g:i a'); ?>
  176. </p>
  177. <?php endforeach; ?>
  178. <p style="text-align: center; font-size: small;">v1.0 Powered by Mozilla Readability (Andres Rey PHP Port) and SimplePie</p>
  179. </body>
  180. </html>