*/ function GetApiResults(string $api_url): mixed { $response = file_get_contents($api_url); return json_decode($response, true); } /** * Formats a given set of API results into an HTML section * * @access public * @param mixed $api_results The decoded API results * @param string $inline_title The
ERROR: Stories not found. API returned `null`.
'; } else { $html_output = 'ERROR: User not found.
'; } else { // TODO: Create function to format $about using the following guidelines // : https://news.ycombinator.com/formatdoc // : hint: nl2br() will solve the first formatting requirement $about = $api_results['about']; $karma = $api_results['karma']; $created = date('Y-m-d h:m:s', $api_results['created']); $html_output = <<About: $about
Karma: $karma
Created:
User has no submissions.
'; } return $html_output; } } /** * Formats one specific item requested by the user * * @access public * @param mixed $api_results The decoded API results * @param string $inline_title TheERROR: User not found.
'; } else { $html_output = ''; if (in_array($api_results['type'], array("job", "story", "poll", "pollopt"))) { $html_output .= ConstructStoryDiscussion($api_results); } else { if (array_key_exists('parent', $api_results)) { $parent_api_results = GetApiResults('https://hacker-news.firebaseio.com/v0/item/' . $api_results['parent'] . '.json'); $html_output .= GetItem($parent_api_results); $html_output .= 'by $by | $score points | $descendants comments
EOT; } /** * Creates a story discussion page with comments * * @access public * @param mixed $api_results The decoded API results * @return string The formatted HTML result of stories from the API or the error message * @author cmcby $by | $score points | $descendants comments
$text
EOT; // TODO: Add support for more than just top-level kids (i.e., recursive). if ($api_results['descendants'] != 0) { $html_output .= <<$text
Submitted in response to: $parent
by $by
EOT; } /** * Creates a poll HTML element * * @access public * @param mixed $api_results The decoded API results * @return string The formatted HTML result of stories from the API or the error message * @author cmc