From 468bc55ada06979e53b1d03b040b2dfe6beaf017 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Wed, 31 May 2023 20:58:43 -0500 Subject: initial commit --- index.php | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 index.php (limited to 'index.php') diff --git a/index.php b/index.php new file mode 100644 index 0000000..f5f7438 --- /dev/null +++ b/index.php @@ -0,0 +1,112 @@ + + * @param string $api_url The API endpoint to use for extraction + * @param string $inline_title The

title to use in the HTML + * @return string $html_output The formatted HTML result of stories from the API + */ +function get_stories($api_url, $inline_title) +{ + $response_raw = file_get_contents($api_url); + $response = json_decode($response_raw, true); + + $html_output = '

' . $inline_title . '

'; + + for ($i = 0; $i < count($response); $i++) { + $sub_url = 'https://hacker-news.firebaseio.com/v0/item/' . $response[$i] . '.json'; + $sub_response_raw = file_get_contents($sub_url); + $sub_response = json_decode($sub_response_raw, true); + + $html = '
' . $sub_response['title'] . ''; + $html .= '

by '; + $html .= $sub_response['by'] . ' | ' . $sub_response['score'] . ' points

'; + $html_output .= $html; + } + + return $html_output; +} + +/** + * Send formatted HTML results to the user via a template + * + * @access public + * @author cmc + * @param string $page_url Canoncial URL for HTML header + * @param string $page_description Page description for HTML header + * @param string $page_title Page title for HTML header + * @param string $page_content Page content to display in
+ */ +function echo_html(string $page_url, string $page_description, string $page_title, string $page_content) { + include_once '_classes/template.php'; + + $template = new HN\View\Template( + $page_url, + $page_description, + $page_title, + $page_content + ); + + $template->echo_template(); +} + +// EOF -- cgit v1.2.3-70-g09d2