├── .phpunit.result.cache ├── .styleci.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── config.php ├── resources ├── img │ └── cookie_gdpr.png ├── lang │ └── en │ │ └── cookies.php └── views │ ├── category.blade.php │ ├── cookie.blade.php │ ├── popup.blade.php │ └── update_popup.blade.php └── src ├── EuCookieConsent.php ├── EuCookieConsentFacade.php ├── EuCookieConsentServiceProvider.php ├── Http └── Controllers │ └── EuCookieConsentController.php └── routes.php /.phpunit.result.cache: -------------------------------------------------------------------------------- 1 | C:37:"PHPUnit\Runner\DefaultTestResultCache":1574:{a:2:{s:7:"defects";a:6:{s:67:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::true_is_true";i:4;s:75:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::eu_cookie_is_not_set";i:3;s:71:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::eu_cookie_is_set";i:3;s:76:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::show_eu_cookie_config";i:3;s:97:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::can_I_Use_for_not_set_cookie_returns_false";i:4;s:93:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::getPopup_returns_html_if_cookie_is_not";i:3;}s:5:"times";a:10:{s:67:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::true_is_true";d:0.437;s:75:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::eu_cookie_is_not_set";d:0.003;s:71:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::eu_cookie_is_set";d:0.003;s:76:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::show_eu_cookie_config";d:0.003;s:64:"the42coders\EuCookieConsent\Tests\BaseTest::testIfThePhpUnitRuns";d:0.177;s:73:"the42coders\EuCookieConsent\Tests\BaseTest::testIfTheServiceProviderBoots";d:0.049;s:97:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::can_I_Use_for_not_set_cookie_returns_false";d:0.043;s:97:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::getPopup_returns_html_if_cookie_is_not_set";d:0.07;s:93:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::getPopup_returns_html_if_cookie_is_not";d:0.044;s:105:"the42coders\EuCookieConsent\Tests\EuCookieConsentTest::getPopup_returns_empty_string_if_cookie_is_not_set";d:0.071;}}} -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `eu-cookie-consent` will be documented in this file 4 | 5 | ## 1.0.0 - 201X-XX-XX 6 | 7 | - initial release 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at support@42coders. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Max Hutschenreiter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eu-cookie-consent helps you to stay conform with the EU cookie law 2 | 3 | [](https://packagist.org/packages/the42coders/eu-cookie-consent) 4 | [](https://travis-ci.org/42coders/eu-cookie-consent) 5 | [](https://packagist.org/packages/the42coders/eu-cookie-consent) 6 | 7 | All sites owned by EU citizens or targeted towards EU citizens must comply with a crazy EU law. This law requires a dialog to be displayed to inform the users of your websites how cookies are being used. You can read more info on the legislation on [the site of the European Commission](http://ec.europa.eu/ipg/basics/legal/cookies/index_en.htm#section_2). 8 | 9 | This package provides an easily configurable view to display the message. Also included is JavaScript code to set a cookie when a user agrees with the cookie policy. The package will not display the dialog when that cookie has been set. 10 | 11 |  12 | 13 | ## Installation 14 | 15 | You can install the package via composer: 16 | 17 | ```bash 18 | composer require the42coders/eu-cookie-consent 19 | ``` 20 | 21 | Optionally you can publish the following Files 22 | 23 | ##### Config 24 | This is recommended since you can configure all the consents you want to get from the visitor. 25 | ``` bash 26 | php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="config" 27 | ``` 28 | ##### Views 29 | If you want to customize the look and feel of the Package 30 | ``` bash 31 | php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="views" 32 | ``` 33 | ##### Language files 34 | This package comes with multilanguage support out of the box. You can translate it to the Languages you want. Or just change the default Text. 35 | ``` bash 36 | php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="lang" 37 | ``` 38 | ## Config 39 | This is the heart of the Package you can define all the Cookies/Permissions you want to get form the User. 40 | ``` php 41 | return [ 42 | 43 | /* 44 | * Use this setting to enable the cookie consent dialog. 45 | */ 46 | 'enabled' => env('COOKIE_CONSENT_ENABLED', true), 47 | 48 | /* 49 | * The name of the cookie in which we store if the user 50 | * has agreed to accept the conditions. 51 | */ 52 | 'cookie_name' => 'laravel_eu_cookie_consent', 53 | 54 | /* 55 | * Set the cookie duration in minutes. Default is 365 * 24 * 60 = 1 Year. 56 | */ 57 | 'cookie_lifetime' => 365 * 24 * 60, 58 | 59 | /* 60 | * Multilanguage support 61 | * 62 | * If enabled the title, description, the category keys and the cookie keys are defining the key from the translation files. 63 | */ 64 | 'multilanguage_support' => true, 65 | 66 | /* 67 | * Save Cookies Route 68 | */ 69 | 'route' => '/saveTheCookie', 70 | 71 | /* 72 | * Define the style of the Popup 73 | */ 74 | 'popup_style' => '', 75 | 76 | /* 77 | * Define classes the popup should use. 78 | */ 79 | 'popup_classes' => 'eu-popup', 80 | 81 | /* 82 | * If you want to have an Accept all Button for the users 83 | */ 84 | 'acceptAllButton' => 'true', 85 | 86 | /* 87 | * Cookies 88 | */ 89 | 'cookies' => [ 90 | //Defines the translation Key for the saveButton 91 | 'saveButton' => 'Save', 92 | //Optional: Defines the translation Key for the PopupTitle 93 | 'title' => 'PopupTitle', 94 | //Optional: Defines the translation Key for the PopupDescription 95 | 'description' => 'PopupDescription', 96 | //To make the popup easier to consume for the user you can organize your Cookies in categories. 97 | 'categories' => [ 98 | //The key defines the translation key in the translations for this category. 99 | 'essential' => [ 100 | //Optional: The description defines the key in the translations for the category description 101 | 'description' => 'essential_description', 102 | //In this array you can define all the Cookies you want to request form the User 103 | 'cookies' => [ 104 | //The key defines the key in the translations and is used to access the Cookie specific information 105 | 'session' => [ 106 | //Optional: you can set forced to make it impossible for the user to not accept this cookie. 107 | 'forced' => 'true', 108 | //Optional: The description defines the key in the translations 109 | //'description' => 'key in translation File' 110 | ], 111 | 'xsrf-token' => [ 112 | 'forced' => 'true', 113 | ], 114 | ], 115 | ], 116 | ], 117 | ], 118 | 119 | ]; 120 | ``` 121 | 122 | ## Usage 123 | 124 | ##### Popup 125 | To enable the Popup you can use the following Code in your blade Files (it returns html code). 126 | ``` php 127 | {!! EuCookieConsent::getPopup() !!} 128 | ``` 129 | 130 | If you want to give the users the option to change the permissions just add another line 131 | ``` php 132 | {!! EuCookieConsent::getUpdatePopup() !!} 133 | ``` 134 | This gives you the possibility to call the dialog with the given user settings by javascript. 135 | 136 | Just call the following js function and the popup will appear. 137 | ``` js 138 | update_popup() 139 | ``` 140 | 141 | ##### Permission 142 | If you want to check if the user gave you a specific permission. You can just pass the key of the Cookie you defined in the config file. 143 | ``` php 144 | EuCookieConsent::canIUse('key from the cookies config') 145 | ``` 146 | ##### Scripts/Imports ... 147 | Very often we want to play out a specific Script Tag ... only if the user allowed us. You can define 148 | the Scripts in the config of the cookie. If you use the key header for example you can render them from all of the cookies. 149 | ``` php 150 | {!! EuCookieConsent::getHtml('header') !!} 151 | ``` 152 | 153 | ### Testing 154 | 155 | ``` bash 156 | composer test 157 | ``` 158 | 159 | ### Changelog 160 | 161 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 162 | 163 | ## Contributing 164 | 165 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 166 | 167 | ### Security 168 | 169 | If you discover any security related issues, please email max@42coders.com instead of using the issue tracker. 170 | 171 | ## Credits 172 | 173 | - [Max Hutschenreiter](https://github.com/42coders) 174 | - [All Contributors](../../contributors) 175 | 176 | ## License 177 | 178 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 179 | 180 | ## Laravel Package Boilerplate 181 | 182 | This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com). 183 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "the42coders/eu-cookie-consent", 3 | "description": "To make your site compliant to the EU GDPR law you can use this package and customize it to your needs.", 4 | "keywords": [ 5 | "42coders", 6 | "eu-cookie-consent" 7 | ], 8 | "homepage": "https://github.com/42coders/eu-cookie-consent", 9 | "license": "MIT", 10 | "type": "library", 11 | "authors": [ 12 | { 13 | "name": "Max Hutschenreiter", 14 | "email": "max@42coders.com", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": ">7.1", 20 | "illuminate/support": "*" 21 | }, 22 | "require-dev": { 23 | "orchestra/testbench": "^5.2", 24 | "phpunit/phpunit": "^8.0" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "the42coders\\EuCookieConsent\\": "src" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "the42coders\\EuCookieConsent\\Tests\\": "tests" 34 | } 35 | }, 36 | "scripts": { 37 | "test": "vendor/bin/phpunit", 38 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 39 | 40 | }, 41 | "config": { 42 | "sort-packages": true 43 | }, 44 | "extra": { 45 | "laravel": { 46 | "providers": [ 47 | "the42coders\\EuCookieConsent\\EuCookieConsentServiceProvider" 48 | ], 49 | "aliases": { 50 | "EuCookieConsent": "the42coders\\EuCookieConsent\\EuCookieConsentFacade" 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | env('COOKIE_CONSENT_ENABLED', true), 9 | 10 | /* 11 | * The name of the cookie in which we store if the user 12 | * has agreed to accept the conditions. 13 | */ 14 | 'cookie_name' => 'laravel_eu_cookie_consent', 15 | 16 | /* 17 | * Set the cookie duration in minutes. Default is 365 * 24 * 60 = 1 Year. 18 | */ 19 | 'cookie_lifetime' => 365 * 24 * 60, 20 | 21 | /* 22 | * Multilanguage support 23 | * 24 | * If enabled the title, description, the category keys and the cookie keys are defining the key from the translation files. 25 | */ 26 | 'multilanguage_support' => true, 27 | 28 | /* 29 | * Save Cookies Route 30 | */ 31 | 'route' => '/saveTheCookie', 32 | 33 | /* 34 | * Define the style of the Popup 35 | */ 36 | 'popup_style' => '', 37 | 38 | /* 39 | * Define classes the popup should use. 40 | */ 41 | 'popup_classes' => 'eu-popup', 42 | 43 | /* 44 | * If you want to have an Accept all Button for the users 45 | */ 46 | 'acceptAllButton' => 'true', 47 | 48 | /* 49 | * Cookies 50 | */ 51 | 'cookies' => [ 52 | //Defines the translation Key for the saveButton 53 | 'saveButton' => 'Save', 54 | //Optional: Defines the translation Key for the PopupTitle 55 | 'title' => 'PopupTitle', 56 | //Optional: Defines the translation Key for the PopupDescription 57 | 'description' => 'PopupDescription', 58 | //To make the popup easier to consume for the user you can organize your Cookies in categories. 59 | 'categories' => [ 60 | //The key defines the translation key in the translations for this category. 61 | 'essential' => [ 62 | //Optional: The description defines the key in the translations for the category description 63 | 'description' => 'essential_description', 64 | //In this array you can define all the Cookies you want to request form the User 65 | 'cookies' => [ 66 | //The key defines the key in the translations and is used to access the Cookie specific information 67 | 'session' => [ 68 | //Optional: you can set forced to make it impossible for the user to not accept this cookie. 69 | 'forced' => 'true', 70 | //Optional: The description defines the key in the translations 71 | //'description' => 'key in translation File' 72 | ], 73 | 'xsrf-token' => [ 74 | 'forced' => 'true', 75 | ], 76 | ], 77 | ], 78 | ], 79 | ], 80 | 81 | ]; 82 | -------------------------------------------------------------------------------- /resources/img/cookie_gdpr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42coders/eu-cookie-consent/50c10d1d8dbabd2056601b31af705016fc97fec6/resources/img/cookie_gdpr.png -------------------------------------------------------------------------------- /resources/lang/en/cookies.php: -------------------------------------------------------------------------------- 1 | 'Accept all', 5 | 'save' => 'Save', 6 | 'PopupTitle' => 'EU Cookie Consent', 7 | 'PopupDescription' => 'To use this Website we are using Cookies and collecting some Data. To be compliant with the EU GDPR we give you to choose if you allow us to use certain Cookies and to collect some Data.', 8 | 9 | 'essential' => 'Essential Data', 10 | 'essential_description' => 'The Essential Data is needed to run the Site you are visiting technically. You can not deactivate them.', 11 | 12 | 'session' => 'Session Cookie: PHP uses a Cookie to identify user sessions. Without this Cookie the Website is not working.', 13 | 'xsrf-token' => 'XSRF-Token Cookie: Laravel automatically generates a CSRF "token" for each active user session managed by the application. This token is used to verify that the authenticated user is the one actually making the requests to the application.', 14 | ]; 15 | -------------------------------------------------------------------------------- /resources/views/category.blade.php: -------------------------------------------------------------------------------- 1 | {{-- Popup Category --}} 2 |
7 | 8 | @if($multiLanguageSupport) 9 | {{ __('eu-cookie-consent::cookies.'.$categoryName) }} 10 | @else 11 | {{ $category['title'] }} 12 | @endif 13 | 14 |
15 |16 | {{-- Popup Category description only if its set in the config --}} 17 | @if(isset($category['description'])) 18 | @if($multiLanguageSupport) 19 | {{ __('eu-cookie-consent::cookies.'.$category['description']) }} 20 | @else 21 | {{ $category['description'] }} 22 | @endif 23 | @endif 24 |
25 | {{-- Popup Category iteration through the single cookies defined in the config --}} 26 | @foreach($category['cookies'] as $cookieName => $cookie) 27 | @include('eu-cookie-consent::cookie') 28 | @endforeach 29 | @endif 30 |5 | @if($multiLanguageSupport) 6 | {{ __('eu-cookie-consent::cookies.'.$cookie['description']) }} 7 | @else 8 | {{ $cookie['description'] }} 9 | @endif 10 |
11 | @endif 12 | {{-- Popup Cookie checkbox with Label --}} 13 | 14 | {{-- For the foreced cookies we need this workaround with hidden input because we set the original input disabled --}} 15 | @if(isset($cookie['forced'])) 16 | 17 | @endif 18 | 25 |