diff options
author | Christian Cleberg <hello@cleberg.net> | 2023-06-01 08:55:45 -0500 |
---|---|---|
committer | Christian Cleberg <hello@cleberg.net> | 2023-06-01 08:55:45 -0500 |
commit | 6cc6e8cd5dc0ecc637c4bcc8bee06a9525a525d3 (patch) | |
tree | 464ed3cb505434fd2eb924de62614e4245a6ea57 | |
parent | a066660764583d754d3f91e4e095cc78d69b0075 (diff) | |
download | hn-6cc6e8cd5dc0ecc637c4bcc8bee06a9525a525d3.tar.gz hn-6cc6e8cd5dc0ecc637c4bcc8bee06a9525a525d3.tar.bz2 hn-6cc6e8cd5dc0ecc637c4bcc8bee06a9525a525d3.zip |
add user functionality
-rw-r--r-- | index.php | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -95,6 +95,19 @@ if (empty($elements[0])) { ); break; + case 'user': + $html_output = get_user( + 'https://hacker-news.firebaseio.com/v0/user/' . $elements[0] . '.json', + 'User Profile: ' . $elements[0] + ); + echo_html( + $GLOBALS['full_domain'] . '/user/' . $elements[0], + 'The Hacker News profile for ' . $elements[0] . ', proxied by hn.', + 'hn', + $html_output + ); + break; + default: header('HTTP/1.1 404 Not Found'); } @@ -111,7 +124,12 @@ if (empty($elements[0])) { */ function get_stories($api_url, $inline_title) { $response_raw = file_get_contents($api_url); - $response = json_decode($response_raw, true); + if (is_null($response_raw) || $response_raw == "null") { + $html_output .= '<p>ERROR: Stories not found. API returned `null`.</p>'; + return $html_output; + } else { + $response = json_decode($response_raw, true); + } $html_output = '<h1>' . $inline_title . '</h1>'; |