- commit
- ffabb9653fb532c284eff3d943d2c3843d3118f1
- parent
- 97e9d7e79aa6a5d0fd95aeebf0c38f270f266ce1
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2018-10-12 17:22
refactor server code
Diffstat
| M | index.php | 20 | +++++++------------- |
1 files changed, 7 insertions, 13 deletions
diff --git a/index.php b/index.php
@@ -116,21 +116,19 @@ if (isset($_SERVER['REQUEST_METHOD'])) {
116 116 $loader = new Twig_Loader_Filesystem('templates');
117 117 $twig = new Twig_Environment($loader);
118 118
119 -1 if ($_SERVER['REQUEST_METHOD'] == 'GET') {
120 -1 if (empty($_GET['path'])) {
121 -1 header("Location: ?path=/", true, 302);
122 -1 } else {
123 -1 $path = validatePath($_GET['path']);
-1 119 if (empty($_GET['path'])) {
-1 120 header("Location: ?path=/", true, 302);
-1 121 } else {
-1 122 $path = validatePath($_GET['path']);
-1 123
-1 124 if ($_SERVER['REQUEST_METHOD'] == 'GET') {
124 125 $data = getData($path);
125 126 echo $twig->render('form.html', array(
126 127 'data' => $data,
127 128 'subpages' => getSubpages($path),
128 129 'path' => $path,
129 130 ));
130 -1 }
131 -1 } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
132 -1 if ($_POST['delete']) {
133 -1 $path = validatePath($_GET['path']);
-1 131 } elseif ($_POST['delete']) {
134 132 if ($path === '/') {
135 133 http_response_code(400);
136 134 die();
@@ -139,16 +137,12 @@ if (isset($_SERVER['REQUEST_METHOD'])) {
139 137 rrmdir("..$path/");
140 138 header("Location: ?path=/", true, 302);
141 139 } else {
142 -1 $path = validatePath($_GET['path']);
143 -1
144 140 // TODO validate form
145 141 setData($path, $_POST);
146 142 render($path);
147 143
148 144 header("Location: ", true, 302);
149 145 }
150 -1 } else {
151 -1 http_response_code(405);
152 146 }
153 147 } else {
154 148 renderAll('/', true);