From b7ece5cdadd2bebb357f166b2b1efe8ab0d2f173 Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Thu, 16 Aug 2018 12:53:07 +0200 Subject: [PATCH] General improvements. + Add a way to configure the db handler (default DB : BerkeleyDB 4); + Add a way to launch a database optimization on delete; * Designed Multiple votes checkbox; * Others minor improvements. --- config/app.default.php | 2 ++ index.php | 17 ++++++----------- models/Poll.php | 20 ++++++++++++++++---- static/css/common.css | 17 +++++++++++++++-- static/css/poll.css | 2 ++ views/home.php | 18 ++++++++++++------ 6 files changed, 53 insertions(+), 23 deletions(-) diff --git a/config/app.default.php b/config/app.default.php index 722647b..81c8f5a 100644 --- a/config/app.default.php +++ b/config/app.default.php @@ -11,4 +11,6 @@ $VERLAINE = [ "#FFAFEC", // Pink. "#82FFE8", // Light blue. ], + "optimize_on_delete" => false, + "db_handler" => "db4", // See available handlers by using `php -r "var_dump(dba_handlers());"` ]; \ No newline at end of file diff --git a/index.php b/index.php index 4c7aad4..5efeb78 100644 --- a/index.php +++ b/index.php @@ -125,23 +125,18 @@ Flight::route("GET|DELETE /polls/@id:[a-fA-F0-9]+/@token:[a-fA-F0-9]+", function $poll = Poll::load_poll($id); if ($poll) { - if (Flight::request()->type === "application/json") + if ($poll->delete_token === $token) { - if ($poll->delete_token === $token) - { - $poll->delete(); + $poll->delete(); + if (Flight::request()->type === "application/json") Flight::json(format_poll($poll), 204); - } else - Flight::halt(401, "

401 Unauthorized

Invalid token.

"); + Flight::redirect('/', 308); } else { - if ($poll->delete_token === $token) - { - $poll->delete(); - Flight::redirect('/', 204); - } + if (Flight::request()->type === "application/json") + Flight::halt(401, "

401 Unauthorized

Invalid token.

"); else Flight::redirect('/', 401); } diff --git a/models/Poll.php b/models/Poll.php index b69ca5b..1edc25a 100644 --- a/models/Poll.php +++ b/models/Poll.php @@ -1,5 +1,7 @@ id, $db) ? "dba_replace" : "dba_insert"); $func($this->id, json_encode([ "title" => $this->title, @@ -124,8 +132,12 @@ class Poll public function delete() { - $db = dba_open(SAVE_PATH . "/polls.db", "wd"); + global $VERLAINE; + + $db = dba_open(SAVE_PATH . "/polls.db", "wd", $VERLAINE["db_handler"]); dba_delete($this->id, $db); + if ($VERLAINE["optimize_on_delete"]) + dba_optimize($db); dba_close($db); } } diff --git a/static/css/common.css b/static/css/common.css index 5ca9e69..049441e 100644 --- a/static/css/common.css +++ b/static/css/common.css @@ -29,12 +29,16 @@ main margin: 0 5%; } -main p +main p, +main label { + display: block; + margin: 0.5em; font-size: 1.5em; text-align: center; } -main p strong +main p strong, +main label strong { font-family: "PT Serif", serif; font-size: 1.2em; @@ -50,6 +54,7 @@ main a.button margin: auto; padding: 1em; width: 25rem; + border-radius: 0; box-sizing: border-box; background: #141414; @@ -76,6 +81,12 @@ main button:hover, main a.button:hover { background: #1D1D1D; } +main hr +{ + border: solid #343434 thin; + width: 25rem; +} + footer { display: block; @@ -99,4 +110,6 @@ footer width: 100%; font-size: 1.2em; } + main hr + { width: 100%; } } \ No newline at end of file diff --git a/static/css/poll.css b/static/css/poll.css index 9716065..287feb6 100644 --- a/static/css/poll.css +++ b/static/css/poll.css @@ -52,10 +52,12 @@ h1.poll { flex: 1; display: block; + margin: 0; padding: 1em; font-family: "PT Serif", serif; font-size: 1.2em; cursor: pointer; + text-align: left; } @media screen and (max-width: 640px) diff --git a/views/home.php b/views/home.php index 76fab23..f4b952b 100644 --- a/views/home.php +++ b/views/home.php @@ -5,24 +5,30 @@

Poll Verlaine

- +
- - +
+
+ + + +