- commit
- 2b72173c390538f9f47c79938c51f8e5688a6799
- parent
- 7b5d214bd2ca653a33c440d41ebb5c1e93642df7
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2018-10-12 18:09
change path structure
Diffstat
| M | index.php | 20 | +++++++++----------- |
1 files changed, 9 insertions, 11 deletions
diff --git a/index.php b/index.php
@@ -57,9 +57,8 @@ function getSubpages($path) 57 57 function validatePath($path) 58 58 { 59 59 if (60 -1 strlen($path) === 0 ||61 -1 $path[0] !== '/' ||62 -1 (strlen($path) > 1 && substr($path, -1) === '/') ||-1 60 (strlen($path) > 1 && $path[0] !== '/') || -1 61 substr($path, -1) === '/' || 63 62 strpos($path, '.') !== false 64 63 ) { 65 64 http_response_code(400); @@ -95,11 +94,10 @@ function render($path, $verbose=false) 95 94 file_put_contents("..$path/index.html", $html); 96 95 } 97 9698 -1 function renderAll($path='/', $verbose=false)-1 97 function renderAll($path='', $verbose=false) 99 98 { 100 99 render($path, $verbose);101 -1 $trimmed = rtrim($path, '/');102 -1 $dir = "../_content$trimmed";-1 100 $dir = "../_content$path"; 103 101 foreach (scandir($dir) as $name) { 104 102 if ($name !== '.' && $name !== '..' && is_dir("$dir/$name")) { 105 103 renderAll("$trimmed/$name", $verbose); @@ -111,8 +109,8 @@ if (isset($_SERVER['REQUEST_METHOD'])) { 111 109 $loader = new Twig_Loader_Filesystem('templates'); 112 110 $twig = new Twig_Environment($loader); 113 111114 -1 if (empty($_GET['path'])) {115 -1 header("Location: ?path=/", true, 302);-1 112 if (empty($_GET['path']) && $_GET['path'] !== '') { -1 113 header("Location: ?path=", true, 302); 116 114 } elseif ($_GET['path'] === '_site') { 117 115 if ($_SERVER['REQUEST_METHOD'] == 'GET') { 118 116 echo $twig->render('site.html', array( @@ -134,13 +132,13 @@ if (isset($_SERVER['REQUEST_METHOD'])) { 134 132 'path' => $path, 135 133 )); 136 134 } elseif ($_POST['delete']) {137 -1 if ($path === '/') {-1 135 if ($path === '') { 138 136 http_response_code(400); 139 137 die(); 140 138 } 141 139 rrmdir("../_content$path");142 -1 rrmdir("..$path/");143 -1 header("Location: ?path=/", true, 302);-1 140 rrmdir("..$path"); -1 141 header("Location: ?path=", true, 302); 144 142 } else { 145 143 // TODO validate form 146 144 setData($path, $_POST);