Commit 6cc6e8cd5d

6cc6e8cd5dc0ecc637c4bcc8bee06a9525a525d3

parent: a066660764

Unsigned

cmc <hello@cleberg.net> · 2023-06-01 13:55 UTC

add user functionality

Layout: unified · split

index.php +19 −1
@@ -95,6 +95,19 @@ if (empty($elements[0])) {
9595 );
9696 break;
9797
98 case 'user':
99 $html_output = get_user(
100 'https://hacker-news.firebaseio.com/v0/user/' . $elements[0] . '.json',
101 'User Profile: ' . $elements[0]
102 );
103 echo_html(
104 $GLOBALS['full_domain'] . '/user/' . $elements[0],
105 'The Hacker News profile for ' . $elements[0] . ', proxied by hn.',
106 'hn',
107 $html_output
108 );
109 break;
110
98111 default:
99112 header('HTTP/1.1 404 Not Found');
100113 }
@@ -111,7 +124,12 @@ if (empty($elements[0])) {
111124*/
112125function get_stories($api_url, $inline_title) {
113126 $response_raw = file_get_contents($api_url);
114 $response = json_decode($response_raw, true);
127 if (is_null($response_raw) || $response_raw == "null") {
128 $html_output .= '<p>ERROR: Stories not found. API returned `null`.</p>';
129 return $html_output;
130 } else {
131 $response = json_decode($response_raw, true);
132 }
115133
116134 $html_output = '<h1>' . $inline_title . '</h1>';
117135