Commit e530c99eb5
Unsigned
Layout: unified · split
index.php +53 −10
| @@ -11,7 +11,7 @@ if (empty($elements[0])) { | ||
| 11 | 11 | ); |
| 12 | 12 | echo_html( |
| 13 | 13 | $GLOBALS['full_domain'] . '/best/', |
| 14 | 'The top 30 stories from Hacker News. Proxied by hn.', | |
| 14 | 'The top stories from Hacker News, proxied by hn.', | |
| 15 | 15 | 'hn', |
| 16 | 16 | $html_output |
| 17 | 17 | ); |
| @@ -23,31 +23,75 @@ if (empty($elements[0])) { | ||
| 23 | 23 | 'Top' |
| 24 | 24 | ); |
| 25 | 25 | echo_html( |
| 26 | $GLOBALS['full_domain'] . '/best/', | |
| 27 | 'The top 30 stories from Hacker News. Proxied by hn.', | |
| 26 | $GLOBALS['full_domain'] . '/top/', | |
| 28 | 27 | 'hn', |
| 29 | 28 | $html_output |
| 30 | 29 | ); |
| 31 | 30 | break; |
| 32 | 31 | |
| 33 | 32 | case 'best': |
| 34 | echo 'best'; | |
| 33 | $html_output = get_stories( | |
| 34 | 'https://hacker-news.firebaseio.com/v0/beststories.json?limitToFirst=30&orderBy="$key"', | |
| 35 | 'Best' | |
| 36 | ); | |
| 37 | echo_html( | |
| 38 | $GLOBALS['full_domain'] . '/best/', | |
| 39 | 'The best 30 stories from Hacker News, proxied by hn.', | |
| 40 | 'hn', | |
| 41 | $html_output | |
| 42 | ); | |
| 35 | 43 | break; |
| 36 | 44 | |
| 37 | 45 | case 'new': |
| 38 | echo 'new'; | |
| 46 | $html_output = get_stories( | |
| 47 | 'https://hacker-news.firebaseio.com/v0/newstories.json?limitToFirst=30&orderBy="$key"', | |
| 48 | 'New' | |
| 49 | ); | |
| 50 | echo_html( | |
| 51 | $GLOBALS['full_domain'] . '/new/', | |
| 52 | 'The newest 30 stories from Hacker News, proxied by hn.', | |
| 53 | 'hn', | |
| 54 | $html_output | |
| 55 | ); | |
| 39 | 56 | break; |
| 40 | 57 | |
| 41 | 58 | case 'ask': |
| 42 | echo 'ask'; | |
| 59 | $html_output = get_stories( | |
| 60 | 'https://hacker-news.firebaseio.com/v0/askstories.json?limitToFirst=30&orderBy="$key"', | |
| 61 | 'Ask' | |
| 62 | ); | |
| 63 | echo_html( | |
| 64 | $GLOBALS['full_domain'] . '/ask/', | |
| 65 | 'The latest 30 asks from Hacker News, proxied by hn.', | |
| 66 | 'hn', | |
| 67 | $html_output | |
| 68 | ); | |
| 43 | 69 | break; |
| 44 | 70 | |
| 45 | 71 | case 'show': |
| 46 | echo 'show'; | |
| 72 | $html_output = get_stories( | |
| 73 | 'https://hacker-news.firebaseio.com/v0/showstories.json?limitToFirst=30&orderBy="$key"', | |
| 74 | 'Show' | |
| 75 | ); | |
| 76 | echo_html( | |
| 77 | $GLOBALS['full_domain'] . '/show/', | |
| 78 | 'The latest 30 show stories from Hacker News, proxied by hn.', | |
| 79 | 'hn', | |
| 80 | $html_output | |
| 81 | ); | |
| 47 | 82 | break; |
| 48 | 83 | |
| 49 | 84 | case 'job': |
| 50 | echo 'job'; | |
| 85 | $html_output = get_stories( | |
| 86 | 'https://hacker-news.firebaseio.com/v0/jobstories.json?limitToFirst=30&orderBy="$key"', | |
| 87 | 'Job' | |
| 88 | ); | |
| 89 | echo_html( | |
| 90 | $GLOBALS['full_domain'] . '/job/', | |
| 91 | 'The latest 30 job posts from Hacker News, proxied by hn.', | |
| 92 | 'hn', | |
| 93 | $html_output | |
| 94 | ); | |
| 51 | 95 | break; |
| 52 | 96 | |
| 53 | 97 | default: |
| @@ -64,8 +108,7 @@ if (empty($elements[0])) { | ||
| 64 | 108 | * @param string $inline_title The <h1> title to use in the HTML |
| 65 | 109 | * @return string $html_output The formatted HTML result of stories from the API |
| 66 | 110 | */ |
| 67 | function get_stories($api_url, $inline_title) | |
| 68 | { | |
| 111 | function get_stories($api_url, $inline_title) { | |
| 69 | 112 | $response_raw = file_get_contents($api_url); |
| 70 | 113 | $response = json_decode($response_raw, true); |
| 71 | 114 | |