formatting, fixed query string encoding
This commit is contained in:
parent
bd76b325a9
commit
077a9f4664
81
news.php
81
news.php
|
@ -5,17 +5,32 @@ $abs_path = "gemini://" . getenv("SERVER_NAME") . getenv("SCRIPT_NAME");
|
||||||
|
|
||||||
$READER_LINK = dirname($abs_path) . "/reader";
|
$READER_LINK = dirname($abs_path) . "/reader";
|
||||||
# ^^^^^^^ uri path to an instance of reader.php
|
# ^^^^^^^ uri path to an instance of reader.php
|
||||||
# the default is relative, and assumes you have one in the same directory as this script
|
# the default is relative, and assumes you have one in the same directory as
|
||||||
|
# this script
|
||||||
|
|
||||||
|
|
||||||
$abs_path = "gemini://" . getenv("SERVER_NAME") . getenv("SCRIPT_NAME");
|
$abs_path = "gemini://"
|
||||||
$topics = array("WORLD", "BUSINESS", "TECHNOLOGY", "ENTERTAINMENT", "SPORTS", "SCIENCE", "HEALTH");
|
. getenv("SERVER_NAME")
|
||||||
|
. getenv("SCRIPT_NAME");
|
||||||
|
|
||||||
|
$topics = array("WORLD",
|
||||||
|
"BUSINESS",
|
||||||
|
"TECHNOLOGY",
|
||||||
|
"ENTERTAINMENT",
|
||||||
|
"SPORTS",
|
||||||
|
"SCIENCE",
|
||||||
|
"HEALTH");
|
||||||
|
|
||||||
$feed_title = "";
|
$feed_title = "";
|
||||||
$feed = new XMLReader;
|
$feed = new XMLReader;
|
||||||
if ( getenv("PATH_INFO") !== null ) {
|
if ( getenv("PATH_INFO") !== null ) {
|
||||||
$feed->open("https://news.google.com/atom" . getenv("PATH_INFO") . "?" . getenv("QUERY_STRING"), "utf-8");
|
$feed->open("https://news.google.com/atom"
|
||||||
|
. getenv("PATH_INFO")
|
||||||
|
. "?"
|
||||||
|
. getenv("QUERY_STRING"), "utf-8");
|
||||||
} else {
|
} else {
|
||||||
$feed->open("https://news.google.com/atom?" . getenv("QUERY_STRING"), "utf-8");
|
$feed->open("https://news.google.com/atom?"
|
||||||
|
. getenv("QUERY_STRING"), "utf-8");
|
||||||
}
|
}
|
||||||
$feed->read();
|
$feed->read();
|
||||||
|
|
||||||
|
@ -31,7 +46,13 @@ echo " \"Yeah it's news\" \n";
|
||||||
echo "====================================================\n";
|
echo "====================================================\n";
|
||||||
echo "```\n";
|
echo "```\n";
|
||||||
foreach ($topics as $topic) {
|
foreach ($topics as $topic) {
|
||||||
echo "=> " . getenv("SCRIPT_NAME") . "/headlines/section/topic/" . $topic . " " . $topic . "\n";
|
echo "=> "
|
||||||
|
. getenv("SCRIPT_NAME")
|
||||||
|
. "/headlines/section/topic/"
|
||||||
|
. $topic
|
||||||
|
. " "
|
||||||
|
. $topic
|
||||||
|
. "\n";
|
||||||
}
|
}
|
||||||
while ($feed->read()) {
|
while ($feed->read()) {
|
||||||
if ($feed->name === "title" && $feed_title === "") {
|
if ($feed->name === "title" && $feed_title === "") {
|
||||||
|
@ -48,12 +69,17 @@ while ($feed->read()) {
|
||||||
echo "\n## " . $entry_node->nodeValue . "\n";
|
echo "\n## " . $entry_node->nodeValue . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($entry_node->tagName === "content" && $entry_node->childNodes->length === 1) {
|
if ($entry_node->tagName === "content" &&
|
||||||
|
$entry_node->childNodes->length === 1) {
|
||||||
$sources_html = $entry_node->childNodes->item(0)->data;
|
$sources_html = $entry_node->childNodes->item(0)->data;
|
||||||
$sources = @DOMDocument::loadHTML($sources_html);
|
$sources = @DOMDocument::loadHTML($sources_html);
|
||||||
$sources = $sources->getElementsByTagName("ol");
|
$sources = $sources->getElementsByTagName("ol");
|
||||||
if ($sources->length === 0) {
|
if ($sources->length === 0) {
|
||||||
$sources = DOMDocument::loadHTML($entry_node->childNodes->item(0)->data);
|
$sources = DOMDocument::loadHTML($entry_node
|
||||||
|
->childNodes
|
||||||
|
->item(0)
|
||||||
|
->data);
|
||||||
|
|
||||||
$sources = $sources->getElementsByTagName("a");
|
$sources = $sources->getElementsByTagName("a");
|
||||||
$multi_source = false;
|
$multi_source = false;
|
||||||
}
|
}
|
||||||
|
@ -65,11 +91,20 @@ while ($feed->read()) {
|
||||||
$source_publication = "";
|
$source_publication = "";
|
||||||
$source_link = "";
|
$source_link = "";
|
||||||
$source_title = "";
|
$source_title = "";
|
||||||
$anchor_tag = $source_node->getElementsByTagName("a")->item(0);
|
$anchor_tag = $source_node
|
||||||
$font_tag = $source_node->getElementsByTagName("font")->item(0);
|
->getElementsByTagName("a")
|
||||||
|
->item(0);
|
||||||
|
|
||||||
|
$font_tag = $source_node
|
||||||
|
->getElementsByTagName("font")
|
||||||
|
->item(0);
|
||||||
|
|
||||||
if ($anchor_tag !== null) {
|
if ($anchor_tag !== null) {
|
||||||
$source_link = $anchor_tag->attributes->getNamedItem("href")->value;
|
$source_link = $anchor_tag
|
||||||
|
->attributes
|
||||||
|
->getNamedItem("href")
|
||||||
|
->value;
|
||||||
|
|
||||||
$source_title = $anchor_tag->nodeValue;
|
$source_title = $anchor_tag->nodeValue;
|
||||||
$source_title = utf8_decode($source_title);
|
$source_title = utf8_decode($source_title);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +112,15 @@ while ($feed->read()) {
|
||||||
$source_publication = $font_tag->nodeValue;
|
$source_publication = $font_tag->nodeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "=> " . $READER_LINK . "?" . $source_link . " " . $source_title . " - " . $source_publication . "\n\n";
|
echo "=> "
|
||||||
|
. $READER_LINK
|
||||||
|
. "?"
|
||||||
|
. urlencode($source_link)
|
||||||
|
. " "
|
||||||
|
. $source_title
|
||||||
|
. " - "
|
||||||
|
. $source_publication
|
||||||
|
. "\n\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$source_publication = "";
|
$source_publication = "";
|
||||||
|
@ -87,14 +130,24 @@ while ($feed->read()) {
|
||||||
$font_tag = $sources->item(1);
|
$font_tag = $sources->item(1);
|
||||||
|
|
||||||
if ($anchor_tag !== null) {
|
if ($anchor_tag !== null) {
|
||||||
$source_link = $anchor_tag->attributes->getNamedItem("href")->value;
|
$source_link = $anchor_tag
|
||||||
|
->attributes
|
||||||
|
->getNamedItem("href")
|
||||||
|
->value;
|
||||||
|
|
||||||
$source_title = $anchor_tag->nodeValue;
|
$source_title = $anchor_tag->nodeValue;
|
||||||
}
|
}
|
||||||
if ($font_tag !== null ) {
|
if ($font_tag !== null ) {
|
||||||
$source_publication = $font_tag->nodeValue;
|
$source_publication = $font_tag->nodeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "=> " . $source_link . " " . $source_title . " - " . $source_publication . "\n";
|
echo "=> "
|
||||||
|
. $source_link
|
||||||
|
. " "
|
||||||
|
. $source_title
|
||||||
|
. " - "
|
||||||
|
. $source_publication
|
||||||
|
. "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue