index.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /*
  93. Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
  94. */
  95. foreach ($feed->get_items() as $item):
  96. ?>
  97. <h3 style="font-size: 5;"><a href="<?php echo 'article.php?loc=' . $loc . '&a=' . $item->get_permalink(); ?>"><?php echo clean_str($item->get_title()); ?></a></h3>
  98. <p style="font-size: 4;">
  99. <?php
  100. $source = clean_str($item->get_source());
  101. $subheadlines = clean_str($item->get_description());
  102. $remove_google_link = explode("<li><strong>", $subheadlines);
  103. $no_blank = str_replace('target="_blank"', "", $remove_google_link[0]) . "</li></ol></font></p>";
  104. $cleaned_links = str_replace('<a href="', '<a href="article.php?loc=' . $loc . '&a=', $no_blank);
  105. $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>');
  106. $cleaned_links = str_replace( 'strong>', 'b>', $cleaned_links); //change <strong> to <b>
  107. $cleaned_links = str_replace( 'em>', 'i>', $cleaned_links); //change <em> to <i>
  108. $cleaned_links = str_replace( "View Full Coverage on Google News", "", $cleaned_links);
  109. echo $cleaned_links . '<br>' . $source;
  110. ?>
  111. </p>
  112. <p style="font-size: small;">Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></p>
  113. <?php endforeach; ?>
  114. <p style="text-align: center; font-size: small;">v1.0 Powered by Mozilla Readability (Andres Rey PHP Port) and SimplePie</p>
  115. </body>
  116. </html>