Commit e530c99eb5
Unsigned
Layout: unified · split
index.php +53 −10
| @@ -11,7 +11,7 @@ if (empty($elements[0])) { | |||
| 11 | ); | 11 | ); |
| 12 | echo_html( | 12 | echo_html( |
| 13 | $GLOBALS['full_domain'] . '/best/', | 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 | 'hn', | 15 | 'hn', |
| 16 | $html_output | 16 | $html_output |
| 17 | ); | 17 | ); |
| @@ -23,31 +23,75 @@ if (empty($elements[0])) { | |||
| 23 | 'Top' | 23 | 'Top' |
| 24 | ); | 24 | ); |
| 25 | echo_html( | 25 | echo_html( |
| 26 | $GLOBALS['full_domain'] . '/best/', | 26 | $GLOBALS['full_domain'] . '/top/', |
| 27 | 'The top 30 stories from Hacker News. Proxied by hn.', | ||
| 28 | 'hn', | 27 | 'hn', |
| 29 | $html_output | 28 | $html_output |
| 30 | ); | 29 | ); |
| 31 | break; | 30 | break; |
| 32 | 31 | ||
| 33 | case 'best': | 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 | break; | 43 | break; |
| 36 | 44 | ||
| 37 | case 'new': | 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 | break; | 56 | break; |
| 40 | 57 | ||
| 41 | case 'ask': | 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 | break; | 69 | break; |
| 44 | 70 | ||
| 45 | case 'show': | 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 | break; | 82 | break; |
| 48 | 83 | ||
| 49 | case 'job': | 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 | break; | 95 | break; |
| 52 | 96 | ||
| 53 | default: | 97 | default: |
| @@ -64,8 +108,7 @@ if (empty($elements[0])) { | |||
| 64 | * @param string $inline_title The <h1> title to use in the HTML | 108 | * @param string $inline_title The <h1> title to use in the HTML |
| 65 | * @return string $html_output The formatted HTML result of stories from the API | 109 | * @return string $html_output The formatted HTML result of stories from the API |
| 66 | */ | 110 | */ |
| 67 | function get_stories($api_url, $inline_title) | 111 | function get_stories($api_url, $inline_title) { |
| 68 | { | ||
| 69 | $response_raw = file_get_contents($api_url); | 112 | $response_raw = file_get_contents($api_url); |
| 70 | $response = json_decode($response_raw, true); | 113 | $response = json_decode($response_raw, true); |
| 71 | 114 | ||