From 7f2c7edf761896ff056230dd38af3a04296a210d Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 11 Jan 2024 16:54:37 +0100 Subject: [PATCH] feat: :sparkles: add age-gating check --- www/router.php | 2 ++ www/static/age_gate_check.js | 12 +++++++++++ www/static/dergstyle.css | 39 ++++++++++++++++++++++++++++++++++++ www/templates/root.html | 17 +++++++++++++++- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 www/static/age_gate_check.js diff --git a/www/router.php b/www/router.php index 03ef15c..6e29a1d 100644 --- a/www/router.php +++ b/www/router.php @@ -107,6 +107,8 @@ function render_twig($template, $args = []) { $args['site_config'] = $SITE_CONFIG; + $args['age_gate'] = (!isset($_COOKIE['AgeConfirmed'])) && isset($SITE_CONFIG['age_gate']); + echo $twig->render($template, $args); } diff --git a/www/static/age_gate_check.js b/www/static/age_gate_check.js new file mode 100644 index 0000000..716ba3c --- /dev/null +++ b/www/static/age_gate_check.js @@ -0,0 +1,12 @@ + + +function confirmAge() { + let ageGate = document.getElementById("age_gate_block"); + ageGate.style.opacity = 0; + + setTimeout(() => { + ageGate.parentElement.removeChild(ageGate); + }, 1000); + + document.cookie += "AgeConfirmed=true; path=/; max-age=31536000" +} \ No newline at end of file diff --git a/www/static/dergstyle.css b/www/static/dergstyle.css index 6051215..b0798fe 100644 --- a/www/static/dergstyle.css +++ b/www/static/dergstyle.css @@ -52,6 +52,45 @@ a:hover { color: var(--highlight_2); } +#age_gate_block { + position: fixed; + top: 0; + left: 0; + z-index: 1040; + width: 100vw; + height: 100vh; + background-color: rgba(0, 0, 0, 0.4); + backdrop-filter: blur(20px); + + transition: opacity 0.8s linear; +} + +#age_gate_block div { + background-color: var(--bg_3); + border-radius: 1em; + + padding: 1em; + + width: 12em; + + margin:0 auto; + display: table; + position: absolute; + + left: 0; + right:0; + top: 50%; + -webkit-transform:translateY(-50%); + -moz-transform:translateY(-50%); + -ms-transform:translateY(-50%); + -o-transform:translateY(-50%); + transform:translateY(-50%); +} + +#age_gate_block p { + min-height: 5em; +} + #main_header { overflow: hidden; position: relative; diff --git a/www/templates/root.html b/www/templates/root.html index e451443..5950c0b 100644 --- a/www/templates/root.html +++ b/www/templates/root.html @@ -35,13 +35,28 @@ + {%if age_gate %} + +
+
+

+ This website may contain content meant for an 18+ audience. +

+ + +
+
+ + + {% endif %} +
full picture -

{% block big_title %}The dergsite{%endblock%}

+

{% block big_title %}{{og.site_name}}{%endblock%}

{% block second_title %}{% endblock %}