formatting, fixed query string encoding

This commit is contained in:
sose 2021-04-02 21:08:42 +00:00
parent bd76b325a9
commit 077a9f4664
1 changed files with 67 additions and 14 deletions

View File

@ -5,17 +5,32 @@ $abs_path = "gemini://" . getenv("SERVER_NAME") . getenv("SCRIPT_NAME");
$READER_LINK = dirname($abs_path) . "/reader";
# ^^^^^^^ 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");
$topics = array("WORLD", "BUSINESS", "TECHNOLOGY", "ENTERTAINMENT", "SPORTS", "SCIENCE", "HEALTH");
$abs_path = "gemini://"
. getenv("SERVER_NAME")
. getenv("SCRIPT_NAME");
$topics = array("WORLD",
"BUSINESS",
"TECHNOLOGY",
"ENTERTAINMENT",
"SPORTS",
"SCIENCE",
"HEALTH");
$feed_title = "";
$feed = new XMLReader;
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 {
$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();
@ -31,7 +46,13 @@ echo " \"Yeah it's news\" \n";
echo "====================================================\n";
echo "```\n";
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()) {
if ($feed->name === "title" && $feed_title === "") {
@ -48,12 +69,17 @@ while ($feed->read()) {
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 = @DOMDocument::loadHTML($sources_html);
$sources = $sources->getElementsByTagName("ol");
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");
$multi_source = false;
}
@ -65,11 +91,20 @@ while ($feed->read()) {
$source_publication = "";
$source_link = "";
$source_title = "";
$anchor_tag = $source_node->getElementsByTagName("a")->item(0);
$font_tag = $source_node->getElementsByTagName("font")->item(0);
$anchor_tag = $source_node
->getElementsByTagName("a")
->item(0);
$font_tag = $source_node
->getElementsByTagName("font")
->item(0);
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 = utf8_decode($source_title);
}
@ -77,7 +112,15 @@ while ($feed->read()) {
$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 {
$source_publication = "";
@ -87,14 +130,24 @@ while ($feed->read()) {
$font_tag = $sources->item(1);
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;
}
if ($font_tag !== null ) {
$source_publication = $font_tag->nodeValue;
}
echo "=> " . $source_link . " " . $source_title . " - " . $source_publication . "\n";
echo "=> "
. $source_link
. " "
. $source_title
. " - "
. $source_publication
. "\n";
}