From 6cc6e8cd5dc0ecc637c4bcc8bee06a9525a525d3 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Thu, 1 Jun 2023 08:55:45 -0500 Subject: add user functionality --- index.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index bca506d..89eab4d 100644 --- a/index.php +++ b/index.php @@ -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 .= '

ERROR: Stories not found. API returned `null`.

'; + return $html_output; + } else { + $response = json_decode($response_raw, true); + } $html_output = '

' . $inline_title . '

'; -- cgit v1.2.3-70-g09d2