Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Pelican extends CI_Controller { |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 4 | private function is_valid_file($rel_path = '/', $file_html = 'index.html') |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 5 | { |
| 6 | $abs_path = APPPATH.$rel_path.$file_html; |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 7 | return file_exists($abs_path); |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 8 | } |
| 9 | |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 10 | public function public_author($file_name = 'index') |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 11 | { |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 12 | $file_html = $file_name.'.html'; |
| 13 | if ($this->is_valid_file('views/author/', $file_html)) |
| 14 | { |
| 15 | $this->load->view('author/'.$file_html); |
| 16 | } |
| 17 | else |
| 18 | { |
| 19 | header('Location: https://'.$_SERVER['HTTP_HOST']); |
| 20 | } |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 23 | public function public_blog($file_name = 'index') |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 24 | { |
| 25 | $file_html = $file_name.'.html'; |
| 26 | if ($this->is_valid_file('views/blog/', $file_html)) |
| 27 | { |
| 28 | $this->load->view('blog/'.$file_html); |
| 29 | } |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 30 | else |
| 31 | { |
| 32 | header('Location: https://'.$_SERVER['HTTP_HOST']); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public function public_category($file_name = 'index') |
| 37 | { |
| 38 | $file_html = $file_name.'.html'; |
| 39 | if ($this->is_valid_file('views/category/', $file_html)) |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 40 | { |
| 41 | $this->load->view('category/'.$file_html); |
| 42 | } |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 43 | else |
| 44 | { |
| 45 | header('Location: https://'.$_SERVER['HTTP_HOST']); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public function public_draft($file_name = 'index') |
| 50 | { |
| 51 | $file_html = $file_name.'.html'; |
luigi | 74fc693 | 2020-11-08 12:51:31 +0000 | [diff] [blame^] | 52 | if ($this->is_valid_file('views/blog/draft', $file_html)) |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 53 | { |
luigi | 74fc693 | 2020-11-08 12:51:31 +0000 | [diff] [blame^] | 54 | $this->load->view('blog/draft/'.$file_html); |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 55 | } |
| 56 | else |
| 57 | { |
| 58 | header('Location: https://'.$_SERVER['HTTP_HOST']); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | public function public_gitles() |
| 63 | { |
| 64 | $gerrit_gitles = '/gerrit/plugins/gitiles/'; |
| 65 | header('Location: https://'.$_SERVER['HTTP_HOST'].$gerrit_gitles); |
| 66 | } |
| 67 | |
| 68 | public function public_page($file_name = 'index') |
| 69 | { |
| 70 | $file_html = $file_name.'.html'; |
| 71 | if ($this->is_valid_file('views/page/', $file_html)) |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 72 | { |
| 73 | $this->load->view('page/'.$file_html); |
| 74 | } |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 75 | else |
| 76 | { |
| 77 | header('Location: https://'.$_SERVER['HTTP_HOST']); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public function public_root($file_name = 'index') |
| 82 | { |
| 83 | $file_html = $file_name.'.html'; |
| 84 | if ($this->is_valid_file('views/', $file_html)) |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 85 | { |
| 86 | $this->load->view($file_html); |
| 87 | } |
| 88 | else |
| 89 | { |
Luigi Santivetti | 57a98ca | 2020-10-13 22:55:51 +0100 | [diff] [blame] | 90 | header('Location: https://'.$_SERVER['HTTP_HOST']); |
Luigi Santivetti | 7bab494 | 2019-06-16 07:40:53 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | } |