Răsfoiți Sursa

add newsfeed.fyi files

blaine 1 an în urmă
părinte
comite
7551788260
6 a modificat fișierele cu 351 adăugiri și 0 ștergeri
  1. 92 0
      www/article.php
  2. 55 0
      www/choose_edition.php
  3. 46 0
      www/image.php
  4. 43 0
      www/image_compressed.php
  5. 101 0
      www/index.php
  6. 14 0
      www/main.css

+ 92 - 0
www/article.php

@@ -0,0 +1,92 @@
+<?php
+require_once('vendor/autoload.php');
+
+$article_url = "";
+$article_html = "";
+$error_text = "";
+$loc = "US";
+
+if( isset( $_GET['loc'] ) ) {
+    $loc = strtoupper($_GET["loc"]);
+}
+
+if( isset( $_GET['a'] ) ) {
+    $article_url = $_GET["a"];
+} else {
+    echo "What do you think you're doing... >:(";
+    exit();
+}
+
+if (substr( $article_url, 0, 23 ) != "https://news.google.com") {
+    echo("That's not news :(");
+    die();
+}
+
+use andreskrey\Readability\Readability;
+use andreskrey\Readability\Configuration;
+use andreskrey\Readability\ParseException;
+
+$configuration = new Configuration();
+$configuration
+    ->setArticleByLine(false);
+
+$readability = new Readability($configuration);
+
+if(!$article_html = file_get_contents($article_url)) {
+    $error_text .=  "Failed to get the article :( <br>";
+}
+
+try {
+    $readability->parse($article_html);
+    $readable_article = strip_tags($readability->getContent(), '<ol><ul><li><br><p><small><font><b><strong><i><em><blockquote><h1><h2><h3><h4><h5><h6>');
+    $readable_article = str_replace( 'strong>', 'b>', $readable_article ); //change <strong> to <b>
+    $readable_article = str_replace( 'em>', 'i>', $readable_article ); //change <em> to <i>
+    
+    $readable_article = clean_str($readable_article);
+    
+} catch (ParseException $e) {
+    $error_text .= 'Sorry! ' . $e->getMessage() . '<br>';
+}
+
+//replace chars that old machines probably can't handle
+function clean_str($str) {
+    $str = str_replace( "‘", "'", $str );    
+    $str = str_replace( "’", "'", $str );  
+    $str = str_replace( "“", '"', $str ); 
+    $str = str_replace( "”", '"', $str );
+    $str = str_replace( "–", '-', $str );
+
+    return $str;
+}
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 2.0//EN">
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<link rel="stylesheet" type="text/css" href="/main.css">
+ 
+ <html>
+ <head>
+     <title><?php echo $readability->getTitle();?></title>
+ </head>
+ <body>
+    <small><a href="/index.php?loc=<?php echo $loc ?>">< Back to <font color="#9400d3">NewsFeed</font> <?php echo $loc ?> front page</a></small>
+    <h1><?php echo clean_str($readability->getTitle());?></h1>
+    <p><small><a href="<?php echo $article_url ?>" target="_blank">Original source</a> (on modern site) <?php
+        $img_num = 0;
+        $imgline_html = "| Article images:";
+        foreach ($readability->getImages() as $image_url):
+            //we can only do png and jpg
+            if (strpos($image_url, ".jpg") || strpos($image_url, ".jpeg") || strpos($image_url, ".png") === true) {
+                $img_num++;
+                $imgline_html .= " <a href='image.php?loc=" . $loc . "&i=" . $image_url . "'>[$img_num]</a> ";
+            }
+        endforeach;
+        if($img_num>0) {
+            echo  $imgline_html ;
+        }
+    ?></small></p>
+    <?php if($error_text) { echo "<p><font color='red'>" . $error_text . "</font></p>"; } ?>
+    <p><?php echo $readable_article;?></font></p>
+    <small><a href="/index.php?loc=<?php echo $loc ?>">< Back to <font color="#9400d3">NewsFeed</font> <?php echo $loc ?> front page</a></small>
+ </body>
+ </html>

+ 55 - 0
www/choose_edition.php

@@ -0,0 +1,55 @@
+<?php
+
+$loc = "US";
+
+if( isset( $_GET['loc'] ) ) {
+    $loc = $_GET["loc"];
+}
+
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 2.0//EN">
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+
+<html>
+<head>
+	<title>68k.news: Choose Your Edition</title>
+</head>
+<body>
+    <center><h1><b>68k.news:</b> <font color="#9400d3"><i>Headlines from the Future</i></font></h1></center>
+    <hr>
+    <center>
+    <small>Basic HTML Google News for vintage computers. Built by <a href="https://youtube.com/ActionRetro" target="_blank"><b>Action Retro</b></a> on YouTube. Tested on Netscape 1.1 through 4 on a Mac SE/30.</small>
+    <p><h2>CHOOSE YOUR EDITION:</h2></p>
+    <p><a href='/index.php?section=nation&loc=US'>United States</a></p>
+    <p><a href='/index.php?section=nation&loc=JP'>Japan</a></p>
+    <p><a href='/index.php?section=nation&loc=UK'>United Kingdom</a></p>
+    <p>Spain (RIP)</p>
+    <p><a href='/index.php?section=nation&loc=CA'>Canada</a></p>
+    <p><a href='/index.php?section=nation&loc=DE'>Deutschland</a></p>
+    <p><a href='/index.php?section=nation&loc=IT'>Italia</a></p>
+    <p><a href='/index.php?section=nation&loc=FR'>France</a></p>
+    <p><a href='/index.php?section=nation&loc=AU'>Australia</a></p>
+    <p><a href='/index.php?section=nation&loc=TW'>Taiwan</a></p>
+    <p><a href='/index.php?section=nation&loc=NL'>Nederland</a></p>
+    <p><a href='/index.php?section=nation&loc=BR'>Brasil</a></p>
+    <p><a href='/index.php?section=nation&loc=TR'>Turkey</a></p>
+    <p><a href='/index.php?section=nation&loc=BE'>Belgium</a></p>
+    <p><a href='/index.php?section=nation&loc=GR'>Greece</a></p>
+    <p><a href='/index.php?section=nation&loc=IN'>India</a></p>
+    <p><a href='/index.php?section=nation&loc=MX'>Mexico</a></p>
+    <p><a href='/index.php?section=nation&loc=DK'>Denmark</a></p>
+    <p><a href='/index.php?section=nation&loc=AR'>Argentina</a></p>
+    <p><a href='/index.php?section=nation&loc=CH'>Switzerland</a></p>
+    <p><a href='/index.php?section=nation&loc=CL'>Chile</a></p>
+    <p><a href='/index.php?section=nation&loc=AT'>Austria</a></p>
+    <p><a href='/index.php?section=nation&loc=KR'>Korea</a></p>
+    <p><a href='/index.php?section=nation&loc=IE'>Ireland</a></p>
+    <p><a href='/index.php?section=nation&loc=CO'>Colombia</a></p>
+    <p><a href='/index.php?section=nation&loc=PL'>Poland</a></p>
+    <p><a href='/index.php?section=nation&loc=PT'>Portugal</a></p>
+    <p><a href='/index.php?section=nation&loc=PK'>Pakistan</a></p>
+    </center>
+    <small><a href="/index.php?loc=<?php echo $loc ?>">< Back to <font color="#9400d3">68k.news</font> <?php echo $loc ?>front page</a></small>
+	<p><center><small>Powered by Mozilla Readability (Andres Rey PHP Port) and SimplePie</small></p>
+</body>
+</html>

+ 46 - 0
www/image.php

@@ -0,0 +1,46 @@
+<?php
+
+    $url = "";
+    $loc = "US";
+
+    if( isset( $_GET['loc'] ) ) {
+        $loc = strtoupper($_GET["loc"]);
+    }
+    
+    //get the image url
+    if (isset( $_GET['i'] ) ) {
+        $url = $_GET[ 'i' ];
+    } else {
+        exit();
+    }
+
+    //we can only do jpg and png here
+    if (strpos($url, ".jpg") && strpos($url, ".jpeg") && strpos($url, ".png") != true ) {
+        echo strpos($url, ".jpg");
+        echo "Unsupported file type :(";
+        exit();
+    }
+
+    //image needs to start with http
+    if (substr( $url, 0, 4 ) != "http") {
+        echo("Image failed :(");
+        exit();
+    }
+
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 2.0//EN">
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ 
+ 
+ <html>
+ <head>
+     <title>68k.news Image Viewer</title>
+ </head>
+ <body">
+    <small><a href="<?php echo $_SERVER['HTTP_REFERER'] . '?loc=' . strtoupper($loc) ?>">< Back to article</a> | <a href="/index.php"><font color="#9400d3">68k.news</font> front page</a></small>
+    <p><small><b>Viewing image:</b> <?php echo $url ?></small></p>
+    <img src="/image_compressed.php?i=<?php echo $url; ?>">
+    <br><br>
+    <small><a href="<?php echo $_SERVER['HTTP_REFERER'] . '?loc=' . strtoupper($loc) ?>">< Back to article</a> | <a href="/index.php"><font color="#9400d3">68k.news</font> front page</a></small>
+ </body>
+ </html>

+ 43 - 0
www/image_compressed.php

@@ -0,0 +1,43 @@
+<?php
+
+$url = "";
+$filetype = "";
+$raw_image = NULL;
+
+//get the image url
+if (isset( $_GET['i'] ) ) {
+    $url = $_GET[ 'i' ];
+} else {
+    exit();
+}
+
+//an image will start with http, anything else is sus
+if (substr( $url, 0, 4 ) != "http") {
+    exit();
+}
+
+//we can only do jpg and png here
+if (strpos($url, ".jpg") || strpos($url, ".jpeg") === true) {
+    $filetype = "jpg";
+    $raw_image = imagecreatefromjpeg($url);
+} elseif (strpos($url, ".png") === true) {
+    $filetype = "png";
+    $raw_image = imagecreatefrompng($url);
+} else {
+    exit();
+}
+
+$dest_imagex = 300;
+$dest_imagey = 200;
+$dest_image = imagecreatetruecolor($dest_imagex, $dest_imagey);
+
+imagecopyresized($dest_image, $raw_image, 0, 0, 0, 0, $dest_imagex, $dest_imagey, imagesx($raw_image), imagesy($raw_image));
+
+header('Content-type: image/' . $filetype); 
+if ($filetype = "jpg") {
+    imagejpeg($dest_image,NULL,80); //80% quality
+} elseif ($filetype = "png") {
+    imagepng($dest_image,NULL,8); //80% compression
+}
+
+?>

+ 101 - 0
www/index.php

@@ -0,0 +1,101 @@
+<?php
+
+require_once('php/autoloader.php');
+
+$section="";
+$loc = "US";
+$lang = "en";
+$feed_url="";
+
+if(isset( $_GET['section'])) {
+    $section = $_GET["section"];
+}
+if(isset( $_GET['loc'])) {
+    $loc = strtoupper($_GET["loc"]);
+}
+if(isset( $_GET['lang'])) {
+    $lang = $_GET["lang"];
+}
+
+if($section) {
+	$feed_url="https://news.google.com/news/rss/headlines/section/topic/".strtoupper($section)."?ned=".$loc."&hl=".$lang;
+} else {
+	$feed_url="https://news.google.com/rss?gl=".$loc."&hl=".$lang."-".$loc."&ceid=".$loc.":".$lang;
+}
+
+//https://news.google.com/news/rss/headlines/section/topic/CATEGORYNAME?ned=in&hl=en
+$feed = new SimplePie();
+ 
+// Set the feed to process.
+$feed->set_feed_url($feed_url);
+ 
+// Run SimplePie.
+$feed->init();
+ 
+// 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).
+$feed->handle_content_type();
+
+//replace chars that old machines probably can't handle
+function clean_str($str) {
+    $str = str_replace( "‘", "'", $str );    
+    $str = str_replace( "’", "'", $str );  
+    $str = str_replace( "“", '"', $str ); 
+    $str = str_replace( "”", '"', $str );
+    $str = str_replace( "–", '-', $str );
+	$str = str_replace( '&nbsp;', ' - ', $str );
+
+    return $str;
+}
+ 
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 2.0//EN">
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<link rel="stylesheet" type="text/css" href="/main.css">
+
+<html>
+<head>
+	<title>NewsFeed.FYI</title>
+</head>
+<body>
+	<center><h1><font color="#9400d3"><i>NewsFeed.FYI</i></font></h1></center>
+	<hr>
+	<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>
+	<?php
+	if($section) {
+		$section_title = explode(" - ", strtoupper($feed->get_title()));
+		echo "<center><h2>" . $section_title[0]  . " NEWS</h2></center>";
+	}
+	?>
+	<small>
+	<p>
+	<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>
+	<font size="1">-=-=-=-=-=-=-=-=-=-=-=-=-=-</font>
+	<br><?php echo strtoupper($loc) ?> Edition <a href="choose_edition.php">(Change)</a></center>
+	</p>
+	</small>
+	<?php
+	/*
+	Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
+	*/
+	foreach ($feed->get_items() as $item):
+	?>
+ 
+			<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>
+			<p><font size="4"><?php 
+            $subheadlines = clean_str($item->get_description());
+            $remove_google_link = explode("<li><strong>", $subheadlines);
+            $no_blank = str_replace('target="_blank"', "", $remove_google_link[0]) . "</li></ol></font></p>"; 
+            $cleaned_links = str_replace('<a href="', '<a href="article.php?loc=' . $loc . '&a=', $no_blank);
+			$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>');
+    		$cleaned_links = str_replace( 'strong>', 'b>', $cleaned_links); //change <strong> to <b>
+    		$cleaned_links = str_replace( 'em>', 'i>', $cleaned_links); //change <em> to <i>
+			$cleaned_links = str_replace( "View Full Coverage on Google News", "", $cleaned_links);
+            echo $cleaned_links;
+            ?></p>
+			<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
+ 
+	<?php endforeach; ?>
+	<p><center><small>v1.0 Powered by Mozilla Readability (Andres Rey PHP Port) and SimplePie</small><center></p>
+</body>
+</html>

+ 14 - 0
www/main.css

@@ -0,0 +1,14 @@
+body {
+  margin:40px auto;
+  max-width:800px;
+  line-height:1.6;
+  font-size:18px;
+  font-family: Sans-Serif;
+  color:#444;
+  padding: 1em;
+  padding: 0 10px;
+}
+
+h1,h2,h3 {
+  line-height:1.2;
+}