Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions app/Http/Controllers/CookieConsentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Blumilk\Website\Http\Controllers;

use Blumilk\Website\Http\Requests\CookieConsentRequest;
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class CookieConsentController extends Controller
{
public const string COOKIE_NAME = "cookie_consent";
public const int COOKIE_MINUTES = 60 * 24 * 90;

public function __invoke(CookieConsentRequest $request, CookieFactory $cookie): Response
{
return response()->noContent()->withCookie(
$cookie->make(self::COOKIE_NAME, $request->validated("consent"), self::COOKIE_MINUTES),
);
}

public static function current(Request $request): string
{
$consent = $request->cookie(self::COOKIE_NAME);

return in_array($consent, CookieConsentRequest::CONSENTS, true) ? $consent : "unknown";
}
}
19 changes: 19 additions & 0 deletions app/Http/Requests/CookieConsentRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Blumilk\Website\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CookieConsentRequest extends FormRequest
{
public const array CONSENTS = ["accepted", "declined"];

public function rules(): array
{
return [
"consent" => ["required", "string", "in:" . implode(",", self::CONSENTS)],
];
}
}
1 change: 1 addition & 0 deletions lang/en/buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"apply_now" => "Apply now!",
"back_to_portfolio" => "Back to portfolio",
"accept_all" => "Accept all",
"decline_all" => "Decline all",
"download" => "Download",
"see_how_we_can_help" => "How can we help you",
"schedule_free_consultation" => "Schedule a free consultation",
Expand Down
2 changes: 1 addition & 1 deletion lang/en/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@
"subtitle_3" => "or use the menu to find what you need.",
],
"cookies" => [
"text_1" => "We use cookies on our website to ensure the best possible quality of services and to adapt the website to your needs. By clicking „Accept all”, you agree to our use of cookies. To learn more, check out our",
"text_1" => "We use cookies on our website to ensure the best possible quality of services and to adapt the website to your needs. By clicking „Accept all”, you agree to our use of cookies. You can also decline them and change your choice at any time in the page footer. To learn more, check out our",
"text_2" => "privacy policy.",
],
"at" => "at",
Expand Down
1 change: 1 addition & 0 deletions lang/en/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
"code" => "Source code",
"policy" => "Privacy policy",
"data" => " Company data",
"cookies" => "Cookie settings",
];
1 change: 1 addition & 0 deletions lang/pl/buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"apply_now" => "Aplikuj teraz!",
"back_to_portfolio" => "Wróć do portfolio",
"accept_all" => "Akceptuj wszystkie",
"decline_all" => "Odrzuć wszystkie",
"download" => "Pobierz",
"see_how_we_can_help" => "Sprawdź, jak możemy Ci pomóc",
"schedule_free_consultation" => "Umów się na bezpłatną konsultację",
Expand Down
2 changes: 1 addition & 1 deletion lang/pl/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@
"subtitle_3" => "lub skorzystaj z menu, aby znaleźć to, czego potrzebujesz.",
],
"cookies" => [
"text_1" => "Na naszej stronie używamy plików cookies („ciasteczek”), aby zapewnić jak najlepszą jakość usług i dostosować stronę do Twoich potrzeb. Klikając „Akceptuj wszystkie”, wyrażasz zgodę na używanie przez nas plików cookie. Aby dowiedzieć się więcej, sprawdź naszą",
"text_1" => "Na naszej stronie używamy plików cookies („ciasteczek”), aby zapewnić jak najlepszą jakość usług i dostosować stronę do Twoich potrzeb. Klikając „Akceptuj wszystkie”, wyrażasz zgodę na używanie przez nas plików cookie. Możesz też je odrzucić, a swój wybór zmienić w każdej chwili w stopce strony. Aby dowiedzieć się więcej, sprawdź naszą",
"text_2" => "politykę prywatności.",
],
"at" => "w",
Expand Down
1 change: 1 addition & 0 deletions lang/pl/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
"code" => "Kod źródłowy",
"policy" => "Polityka prywatności",
"data" => " Dane firmy",
"cookies" => "Ustawienia cookies",
];
80 changes: 71 additions & 9 deletions resources/views/components/cookies.blade.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,80 @@
@php
$cookieConsent = \Blumilk\Website\Http\Controllers\CookieConsentController::current(request());
@endphp

<script>
document.addEventListener("alpine:init", function () {
Alpine.data('cookieConsent', () => ({
state: Alpine.$persist('unknown').as('cookieConsent'),
state: @js($cookieConsent),
open: false,
init() {
this.migrateLocalStorageConsent()

this.open = this.state === 'unknown'

this.applyConsent()
this.dispatchEvent()
},
dialogue: {
['x-show']() {
return this.state === 'unknown'
return this.open
},
['@cookie-consent-open.window']() {
this.open = true
}
},
accept: {
['@click']() {
this.state = 'accepted'
this.choose('accepted')
}
},
decline: {
['@click']() {
this.choose('declined')
}
},
choose(state) {
this.state = state
this.open = false

this.dispatchEvent()
this.saveConsent()
this.applyConsent()
this.dispatchEvent()
},
saveConsent() {
fetch(@js(route("cookie-consent")), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-CSRF-TOKEN': @js(csrf_token()),
},
body: JSON.stringify({ consent: this.state }),
})
},
migrateLocalStorageConsent() {
const key = 'cookieConsent'
let previous = null

try {
previous = JSON.parse(localStorage.getItem(key))
localStorage.removeItem(key)
} catch {}

if (this.state === 'unknown' && ['accepted', 'declined'].includes(previous)) {
this.state = previous
this.saveConsent()
}
},
applyConsent() {
try {
if (this.state === 'declined') {
localStorage.setItem('umami.disabled', '1')
} else {
localStorage.removeItem('umami.disabled')
}
} catch {}
},
dispatchEvent() {
document.dispatchEvent(new CustomEvent('cookieConsent', {
detail: this.state
Expand All @@ -26,17 +84,21 @@
})
</script>

<section class="z-10 fixed max-w-3xl p-4 bg-white border border-gray-200 sm:gap-x-4 mx-12 bottom-16 dark:bg-gray-900 sm:flex sm:items-center dark:border-gray-700 rounded-2xl" x-data="cookieConsent" x-bind="dialogue" x-cloak>
<div class="flex items-center gap-x-4">
<span class="inline-flex p-2 text-website-normal rounded-lg shrink-0 dark:bg-gray-800 bg-website-light/30 show">
<section class="z-10 fixed max-w-3xl p-4 bg-white border border-gray-200 sm:gap-x-4 mx-12 bottom-16 dark:bg-gray-900 sm:flex sm:items-center dark:border-gray-700 rounded-2xl" x-data="cookieConsent" x-bind="dialogue" x-cloak @if ($cookieConsent !== "unknown") style="display: none" @endif>
<div class="flex items-center gap-4">
<span class="hidden sm:inline-flex p-2 text-website-normal rounded-lg shrink-0 dark:bg-gray-800 bg-website-light/30 show">
<i class="ti ti-cookie text-4xl"></i>
</span>
<p class="text-xs text-gray-600 dark:text-gray-300">{{ __("content.cookies.text_1") }}<a href="{{ route("privacy-policy") }}" class="text-blue-500 hover:underline"> {{ __("content.cookies.text_2") }}</a>
</p>
</div>
<div class="flex items-center shrink-0 mt-6 sm:mt-0">
<div class="flex flex-col md:flex-row items-stretch gap-2 shrink-0 mt-6 sm:mt-0">
<button x-bind="decline" type="button"
class="text-xs w-full sm:w-auto font-medium border border-gray-300 rounded-lg hover:bg-gray-100 text-gray-700 px-4 py-2.5 duration-300 transition-colors focus:outline-hidden">
{{ __("buttons.decline_all") }}
</button>
<button x-bind="accept" type="button"
class=" text-xs w-full sm:w-auto max-w-80 ml-auto sm:mx-auto font-medium bg-blue-normal rounded-lg hover:bg-gray-700 text-white px-4 py-2.5 duration-300 transition-colors focus:outline-hidden">
class="text-xs w-full sm:w-auto font-medium bg-blue-normal rounded-lg hover:bg-gray-700 text-white px-4 py-2.5 duration-300 transition-colors focus:outline-hidden">
{{ __("buttons.accept_all") }}
</button>
</div>
Expand Down
4 changes: 3 additions & 1 deletion resources/views/layout/footer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
<span class="hidden md:inline">|</span>
<a href="{{ route('privacy-policy') }}" class="block md:inline font-normal whitespace-normal px-1">{{ __('footer.policy') }}</a>
<span class="hidden md:inline">|</span>
<a href="{{ route('data') }}" class="block md:inline pl-1">{{ __('footer.data') }}</a></p>
<a href="{{ route('data') }}" class="block md:inline px-1">{{ __('footer.data') }}</a>
<span class="hidden md:inline">|</span>
<button type="button" x-data x-on:click="$dispatch('cookie-consent-open')" class="block md:inline mx-auto md:mx-0 pl-1 cursor-pointer">{{ __('footer.cookies') }}</button></p>
</div>
</div>
</footer>
Expand Down
12 changes: 7 additions & 5 deletions resources/views/layout/public.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

<script src='https://api.mapbox.com/mapbox-gl-js/v3.4.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v3.4.0/mapbox-gl.css' rel='stylesheet'/>
<script
defer src="https://analytics.blumilk.pl/script.js"
data-website-id="a60fb021-70a4-4829-9209-a690f6fcb79f"
data-domains="blumilk.pl">
</script>
@if (\Blumilk\Website\Http\Controllers\CookieConsentController::current(request()) !== "declined")
<script
defer src="https://analytics.blumilk.pl/script.js"
data-website-id="a60fb021-70a4-4829-9209-a690f6fcb79f"
data-domains="blumilk.pl">
</script>
@endif
{!! RecaptchaV3::initJs() !!}
</head>

Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Blumilk\Website\Http\Controllers\CareerController;
use Blumilk\Website\Http\Controllers\CompanyDataController;
use Blumilk\Website\Http\Controllers\ContactController;
use Blumilk\Website\Http\Controllers\CookieConsentController;
use Blumilk\Website\Http\Controllers\HomeController;
use Blumilk\Website\Http\Controllers\LogoController;
use Blumilk\Website\Http\Controllers\NewsController;
Expand Down Expand Up @@ -38,4 +39,6 @@

$router->get($uri->translate("offer"), OfferController::class)->name("offer");

$router->post("cookie-consent", CookieConsentController::class)->name("cookie-consent");

$router->fallback(FallbackController::class);
Loading