tvup / eu-cookie-consent
为了让您的网站符合欧盟GDPR法律,您可以使用此软件包并根据您的需求进行定制。
Requires
- php: ^8.2
- ext-dom: *
- ext-mbstring: *
- illuminate/support: *
Requires (Dev)
- orchestra/testbench: ^9.1.1
- phpunit/phpunit: ^10.5.17
This package is auto-updated.
Last update: 2024-09-02 02:27:22 UTC
README
所有属于欧盟公民或针对欧盟公民的网站都必须遵守一项疯狂的欧盟法律。这项法律要求显示一个对话框,告知用户您的网站如何使用cookie。您可以在欧洲委员会的网站上了解更多关于该法规的信息:欧洲委员会网站。
此软件包提供了一种易于配置的视图来显示消息。还包括JavaScript代码,用于在用户同意cookie政策时设置cookie。当设置了此cookie时,软件包将不会显示对话框。
安装
您可以通过composer安装此软件包
composer require the42coders/eu-cookie-consent
可选地,您可以发布以下文件
配置
推荐使用,因为您可以从访问者那里配置所有希望获得的同意。
php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="config"
视图
如果您想自定义软件包的外观和感觉
php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="views"
语言文件
此软件包自带多语言支持。您可以将其翻译成您想要的任何语言。或者只需更改默认文本。
php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="lang"
配置
这是软件包的核心,您可以定义您想要从用户那里获取的所有cookie/权限。
return [ /* * Use this setting to enable the cookie consent dialog. */ 'enabled' => env('COOKIE_CONSENT_ENABLED', true), /* * The name of the cookie in which we store if the user * has agreed to accept the conditions. */ 'cookie_name' => 'laravel_eu_cookie_consent', /* * Set the cookie duration in minutes. Default is 365 * 24 * 60 = 1 Year. */ 'cookie_lifetime' => 365 * 24 * 60, /* * Multilanguage support * * If enabled the title, description, the category keys and the cookie keys are defining the key from the translation files. */ 'multilanguage_support' => true, /* * Save Cookies Route */ 'route' => '/saveTheCookie', /* * Define the style of the Popup */ 'popup_style' => '', /* * Define classes the popup should use. */ 'popup_classes' => 'eu-popup', /* * If you want to have an Accept all Button for the users */ 'acceptAllButton' => 'true', /* * Cookies */ 'cookies' => [ //Defines the translation Key for the saveButton 'saveButton' => 'Save', //Optional: Defines the translation Key for the PopupTitle 'title' => 'PopupTitle', //Optional: Defines the translation Key for the PopupDescription 'description' => 'PopupDescription', //To make the popup easier to consume for the user you can organize your Cookies in categories. 'categories' => [ //The key defines the translation key in the translations for this category. 'essential' => [ //Optional: The description defines the key in the translations for the category description 'description' => 'essential_description', //In this array you can define all the Cookies you want to request form the User 'cookies' => [ //The key defines the key in the translations and is used to access the Cookie specific information 'session' => [ //Optional: you can set forced to make it impossible for the user to not accept this cookie. 'forced' => 'true', //Optional: The description defines the key in the translations //'description' => 'key in translation File' ], 'xsrf-token' => [ 'forced' => 'true', ], ], ], ], ], ];
使用方法
弹出窗口
要启用弹出窗口,您可以在blade文件中使用以下代码(它返回HTML代码)。
{!! EuCookieConsent::getPopup() !!}
如果您想给用户更改权限的选项,请添加另一行
{!! EuCookieConsent::getUpdatePopup() !!}
这使您有机会通过javascript调用带有给定用户设置的对话框。
只需调用以下js函数,弹出窗口就会出现。
update_popup()
权限
如果您想检查用户是否给出了您定义的特定权限,只需传递在配置文件中定义的cookie的关键字即可。
EuCookieConsent::canIUse('key from the cookies config')
脚本/导入...
我们经常只想在用户允许的情况下播放特定的Script Tag ... 您可以在cookie的配置中定义脚本。例如,如果您使用关键字header,您可以从所有cookie中渲染它们。
{!! EuCookieConsent::getHtml('header') !!}
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献。
安全
如果您发现任何与安全相关的问题,请通过电子邮件max@42coders.com报告,而不是使用问题跟踪器。
鸣谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。
Laravel软件包模板
此软件包是用Laravel软件包模板生成的。