index.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  42. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  43. <link rel="stylesheet" type="text/css" href="/main.css">
  44. <html>
  45. <head>
  46. <title>NewsFeed.FYI</title>
  47. </head>
  48. <body>
  49. <center><h1><font color="#9400d3"><i>NewsFeed.FYI</i></font></h1></center>
  50. <hr>
  51. <center><small>Basic HTML Google News Feed. Based on <a href="https://github.com/ActionRetro/68k-news" target="_blank"><b>source</b></a> for <a href="http://68k.news" target="_blank"><b>68k.news</b></a>, originally built by <a href="https://youtube.com/ActionRetro" target="_blank"><b>Action Retro</b></a>.</small></center>
  52. <?php
  53. if($section) {
  54. $section_title = explode(" - ", strtoupper($feed->get_title()));
  55. echo "<center><h2>" . $section_title[0] . " NEWS</h2></center>";
  56. }
  57. ?>
  58. <small>
  59. <p>
  60. <center><a href="index.php?loc=<?php echo $loc ?>">TOP</a> <a href="index.php?section=world&loc=<?php echo strtoupper($loc) ?>">WORLD</a> <a href="index.php?section=nation&loc=<?php echo strtoupper($loc) ?>">NATION</a> <a href="index.php?section=business&loc=<?php echo strtoupper($loc) ?>">BUSINESS</a> <a href="index.php?section=technology&loc=<?php echo strtoupper($loc) ?>">TECHNOLOGY</a> <a href="index.php?section=entertainment&loc=<?php echo strtoupper($loc) ?>">ENTERTAINMENT</a> <a href="index.php?section=science&loc=<?php echo strtoupper($loc) ?>">SCIENCE</a> <a href="index.php?section=health&loc=<?php echo strtoupper($loc) ?>">HEALTH</a><br>
  61. <font size="1">-=-=-=-=-=-=-=-=-=-=-=-=-=-</font>
  62. <br><?php echo strtoupper($loc) ?> Edition <a href="choose_edition.php">(Change)</a></center>
  63. </p>
  64. </small>
  65. <?php
  66. /*
  67. Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
  68. */
  69. foreach ($feed->get_items() as $item):
  70. ?>
  71. <h3><font size="5"><a href="<?php echo 'article.php?loc=' . $loc . '&a=' . $item->get_permalink(); ?>"><?php echo clean_str($item->get_title()); ?></a></font></h3>
  72. <p><font size="4"><?php
  73. $subheadlines = clean_str($item->get_description());
  74. $remove_google_link = explode("<li><strong>", $subheadlines);
  75. $no_blank = str_replace('target="_blank"', "", $remove_google_link[0]) . "</li></ol></font></p>";
  76. $cleaned_links = str_replace('<a href="', '<a href="article.php?loc=' . $loc . '&a=', $no_blank);
  77. $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>');
  78. $cleaned_links = str_replace( 'strong>', 'b>', $cleaned_links); //change <strong> to <b>
  79. $cleaned_links = str_replace( 'em>', 'i>', $cleaned_links); //change <em> to <i>
  80. $cleaned_links = str_replace( "View Full Coverage on Google News", "", $cleaned_links);
  81. echo $cleaned_links;
  82. ?></p>
  83. <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
  84. <?php endforeach; ?>
  85. <p><center><small>v1.0 Powered by Mozilla Readability (Andres Rey PHP Port) and SimplePie</small><center></p>
  86. </body>
  87. </html>