├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md └── scwCookie ├── .htaccess ├── ajax.php ├── config.example.ini ├── install-check.txt ├── output ├── assets │ ├── icons.png │ ├── js-cookie.js │ ├── scwCookie.css │ ├── scwCookie.js │ ├── scwCookie.min.css │ └── scwCookie.min.js ├── cookies │ ├── Google_Analytics │ │ ├── cookies.php │ │ └── output.php │ ├── Hotjar │ │ ├── cookies.php │ │ └── output.php │ ├── Smartsupp │ │ ├── cookies.php │ │ └── output.php │ └── Tawk.to │ │ ├── cookies.php │ │ └── output.php ├── popup.php └── scwCookie.php └── scwCookie.class.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `gdpr-cookie` will be documented in this file. 4 | 5 | ## 2.3 6 | - Add functionality to remove cookies on toggle of switch and at page load 7 | - Usage of plugin [JS Cookie](https://github.com/js-cookie/js-cookie) to remove cookies effectively 8 | - Restructure of output directory to allow easier additions and modifications 9 | - More detailed comments added to README.md 10 | 11 | ## 2.2 12 | - Add Tawk.to embed code 13 | - Add tooltips to icons 14 | - Expand on label for cookies 15 | - Bug fixes 16 | 17 | ## 2.1 18 | - Fix for sites when headers are sent before close of body tag e.g. Wordpress 19 | - Add ability to set default value (allowed | blocked) 20 | - Add Hotjar and Smartsupp embed codes 21 | - Add ability to specify location of panel toggle (left | center | right) 22 | - Bug fixes 23 | 24 | 25 | ## 2.0 26 | - Full rewrite 27 | - Add ability to toggle which cookie is allowed 28 | -------------------------------------------------------------------------------- /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 contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at support@southcoastweb.co.uk. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/SouthCoastWebDesign/gdpr-cookie). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[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](http://pear.php.net/package/PHP_CodeSniffer). 11 | 12 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 13 | 14 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 15 | 16 | - **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](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 17 | 18 | **Happy coding**! 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 South Coast Web Design Ltd 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DSM Cookie 2.3 2 | 3 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 4 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/southcoastweb/gdpr-cookie/badges/quality-score.png)](https://scrutinizer-ci.com/g/southcoastweb/gdpr-cookie/?branch=2.2) 5 | [![Build Status](https://scrutinizer-ci.com/g/southcoastweb/gdpr-cookie/badges/build.png?b=2.2)](https://scrutinizer-ci.com/g/southcoastweb/gdpr-cookie/build-status/2.3) 6 | 7 | PHP cookie checker for Google Analytics, Tawk.To, Smartsupp and HotJar (GDPR Compliance) 8 | 9 | This small class will add a cookie toggle window to any website. 10 | 11 | To add this functionality within a site simply follow the below steps : 12 | 13 | 1. Upload the entire dsmCookie folder into the public_html (or similar) root folder of your website. 14 | 15 | 2. If done correctly you will then be able to visit [domain]/dsmCookie/install-check.txt and see the "Installed correctly" message. 16 | 17 | 3. Then add the following code at the very end / just before the closing body tag of each page: 18 | ``` 19 | 20 | ``` 21 | 22 | 4. Rename config.example.ini to config.ini 23 | 24 | 5. Then open config.ini in your chosen editor and set the values to match your site configuration 25 | 26 | Thats it, a window will now display in the footer of your site allowing people to manage the cookies you use. 27 | 28 | #### Remember to remove any previous cookie code, this will handle that from now on 29 | 30 | ## Demo 31 | A live example is available here: [https://dsmdesign.co.uk](https://dsmdesign.co.uk) 32 | 33 | ## Changelog 34 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 35 | 36 | ## Contributing 37 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 38 | 39 | ## License 40 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 41 | -------------------------------------------------------------------------------- /scwCookie/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | RewriteEngine On 3 | 4 | -------------------------------------------------------------------------------- /scwCookie/ajax.php: -------------------------------------------------------------------------------- 1 | true])); 15 | break; 16 | 17 | case 'toggle': 18 | $scwCookie = new ScwCookie\ScwCookie(); 19 | $return = []; 20 | 21 | // Update if cookie allowed or not 22 | $choices = $scwCookie->getCookie('scwCookie'); 23 | if ($choices == false) { 24 | $choices = []; 25 | $enabledCookies = $scwCookie->enabledCookies(); 26 | foreach ($enabledCookies as $name => $label) { 27 | $choices[$name] = $scwCookie->config['unsetDefault']; 28 | } 29 | $scwCookie->setCookie('scwCookie', $scwCookie->encrypt($choices), 52, 'weeks'); 30 | } else { 31 | $choices = $scwCookie->decrypt($choices); 32 | } 33 | $choices[$_POST['name']] = $_POST['value'] == 'true' ? 'allowed' : 'blocked'; 34 | 35 | // Remove cookies if now disabled 36 | if ($choices[$_POST['name']] == 'blocked') { 37 | $removeCookies = $scwCookie->clearCookieGroup($_POST['name']); 38 | $return['removeCookies'] = $removeCookies; 39 | } 40 | 41 | $choices = $scwCookie->encrypt($choices); 42 | $scwCookie->setCookie('scwCookie', $choices, 52, 'weeks'); 43 | 44 | header('Content-Type: application/json'); 45 | die(json_encode($return)); 46 | break; 47 | 48 | case 'load': 49 | $scwCookie = new ScwCookie\ScwCookie(); 50 | $return = []; 51 | 52 | $removeCookies = []; 53 | 54 | foreach ($scwCookie->disabledCookies() as $cookie => $label) { 55 | $removeCookies = array_merge($removeCookies, $scwCookie->clearCookieGroup($cookie)); 56 | } 57 | $return['removeCookies'] = $removeCookies; 58 | 59 | header('Content-Type: application/json'); 60 | die(json_encode($return)); 61 | break; 62 | 63 | default: 64 | header('HTTP/1.0 403 Forbidden'); 65 | throw new Exception("Action not recognised"); 66 | break; 67 | } 68 | -------------------------------------------------------------------------------- /scwCookie/config.example.ini: -------------------------------------------------------------------------------- 1 | ; This is the configuration file for DSM Cookie 2 | ; ############################################### 3 | 4 | ; URL for the cookie policy link to go to 5 | cookiePolicyURL = "/cookie-policy" 6 | 7 | ; If you use live chat cookies, set this to true and the ", provide live chat" message will appear in the popup 8 | ; Options: true, false 9 | showLiveChatMessage = false 10 | 11 | ; Location for the toggle button to display on the bottom of the window 12 | ; Options: left, center, right 13 | panelTogglePosition = left 14 | 15 | ; On page load will cookies be allowed or blocked 16 | ; Options: allowed, blocked 17 | unsetDefault = allowed 18 | 19 | ; Inividual cookie code configs 20 | ; ############################################### 21 | 22 | ; Google Analytics - https://analytics.google.com 23 | [Google_Analytics] 24 | 25 | ; Is this cookie to be used on your site? 26 | ; Options: true, false 27 | enabled = false 28 | 29 | ; Label for this cookie within the popup -> cookie settings area 30 | label = "Google Analytics" 31 | 32 | ; Google tracking ID: e.g. UA-1234567-8 33 | code = "" 34 | 35 | ; --------------------- 36 | 37 | ; Tawk.to - https://www.tawk.to 38 | [Tawk.to] 39 | 40 | ; Is this cookie to be used on your site? 41 | ; Options: true, false 42 | enabled = false 43 | 44 | ; Label for this cookie within the popup -> cookie settings area 45 | label = "Tawk.to - Live chat" 46 | 47 | ; Site code: e.g. 12345a6b789cdef01g234567 48 | code = "" 49 | 50 | ; --------------------- 51 | 52 | ; Smartsupp - https://www.smartsupp.com 53 | [Smartsupp] 54 | 55 | ; Is this cookie to be used on your site? 56 | ; Options: true, false 57 | enabled = false 58 | 59 | ; Label for this cookie within the popup -> cookie settings area 60 | label = "Smartsupp - Live chat" 61 | 62 | ; Site code: e.g. ab12c34defghi5j6k789l0m1234n567890o12345 63 | code = "" 64 | 65 | ; --------------------- 66 | 67 | ; Hotjar - https://www.hotjar.com 68 | [Hotjar] 69 | 70 | ; Is this cookie to be used on your site? 71 | ; Options: true, false 72 | enabled = false 73 | 74 | ; Label for this cookie within the popup -> cookie settings area 75 | label = "Hotjar - Website heatmaps" 76 | 77 | ; Site code: e.g. 123456 78 | code = "" 79 | -------------------------------------------------------------------------------- /scwCookie/install-check.txt: -------------------------------------------------------------------------------- 1 | Installed correctly 2 | -------------------------------------------------------------------------------- /scwCookie/output/assets/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSMDesign/gdpr-cookie/5dcc352f7979ce203301a87bd2ec2b61f76ea3e5/scwCookie/output/assets/icons.png -------------------------------------------------------------------------------- /scwCookie/output/assets/js-cookie.js: -------------------------------------------------------------------------------- 1 | !function(e){var n=!1;if("function"==typeof define&&define.amd&&(define(e),n=!0),"object"==typeof exports&&(module.exports=e(),n=!0),!n){var o=window.Cookies,t=window.Cookies=e();t.noConflict=function(){return window.Cookies=o,t}}}(function(){function e(){for(var e=0,n={};e1){if("number"==typeof(i=e({path:"/"},t.defaults,i)).expires){var a=new Date;a.setMilliseconds(a.getMilliseconds()+864e5*i.expires),i.expires=a}i.expires=i.expires?i.expires.toUTCString():"";try{c=JSON.stringify(r),/^[\{\[]/.test(c)&&(r=c)}catch(e){}r=o.write?o.write(r,n):encodeURIComponent(String(r)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),n=(n=(n=encodeURIComponent(String(n))).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent)).replace(/[\(\)]/g,escape);var s="";for(var f in i)i[f]&&(s+="; "+f,!0!==i[f]&&(s+="="+i[f]));return document.cookie=n+"="+r+s}n||(c={});for(var p=document.cookie?document.cookie.split("; "):[],d=/(%[0-9A-Z]{2})+/g,u=0;u'+label+''); 81 | }, function(){ 82 | $(this).find('.scw-cookie-tooltip').remove(); 83 | }); 84 | }); 85 | 86 | jQuery(document).ready(function($){ 87 | jQuery.post( 88 | '/scwCookie/ajax.php', 89 | { 90 | action : 'load', 91 | } 92 | ).done(function(data){ 93 | if (data.hasOwnProperty('removeCookies')) { 94 | jQuery.each(data.removeCookies, function(key, cookie){ 95 | Cookies.remove(cookie.name); 96 | Cookies.remove(cookie.name, { domain: cookie.domain }); 97 | Cookies.remove(cookie.name, { path: cookie.path }); 98 | Cookies.remove(cookie.name, { domain: cookie.domain, path: cookie.path }); 99 | }); 100 | } 101 | }); 102 | }); 103 | -------------------------------------------------------------------------------- /scwCookie/output/assets/scwCookie.min.css: -------------------------------------------------------------------------------- 1 | body.scw-cookie-in{margin-bottom:70px!important}.scw-cookie-btn,.scw-cookie-panel-toggle,.scw-cookie-policy,.scw-cookie-settings,.scw-cookie-settings .scwc-icon,.scw-cookie-switch{transition:all .3s ease}.scwc-icon{background-image:url(icons.png);background-repeat:no-repeat;background-size:auto 100%;height:25px;width:25px;display:inline-block}.scwc-icon.scwc-icon-cookie{background-position:0 0}.scwc-icon.scwc-icon-policy{background-position:-25px 0}.scwc-icon.scwc-icon-settings{background-position:-50px 0}.scw-cookie-panel-toggle{background:inherit;border-top:solid 3px #fff;cursor:pointer;padding:10px;position:absolute;transform:translateY(-100%)}.scw-cookie-panel-toggle::before{background:#2d3436;content:'Turn cookies on / off';float:left;height:20px;line-height:25px;margin-right:0;opacity:0;overflow:hidden;position:relative;text-align:center;transition:all .3s ease;visibility:hidden;width:0}.scw-cookie-panel-toggle:hover::before{opacity:1;visibility:visible;margin-right:10px;width:140px}.scw-cookie-panel-toggle-left{left:10px}.scw-cookie-panel-toggle-center{left:calc(50% - 22.5px)}.scw-cookie-panel-toggle-right{right:10px}.scw-cookie-panel-toggle:hover{border-top-color:#20bf6b}.scw-cookie{background:#2d3436;bottom:0;color:#fff;font-family:Arial;font-size:14px;left:0;position:fixed;width:100%;z-index:9999999999}.scw-cookie:not(.scw-cookie-out){animation:slideIn .5s ease-in-out}.scw-cookie.scw-cookie-out{transform:translateY(100%)}.scw-cookie.scw-cookie-slide-out{animation:slideOut .5s ease-in-out;transform:translateY(100%)}.scw-cookie-content{margin:0 auto;max-width:90%;padding:20px;width:1170px}.scw-cookie-content::after{clear:both;content:'';display:block}.scw-cookie-message{float:left;line-height:30px;width:70%}.scw-cookie-decision{text-align:right;float:left;width:30%}.scw-cookie-btn{background:#20bf6b;cursor:pointer;display:inline-block;line-height:30px;text-align:center;width:40px}.scw-cookie-btn:hover{background:#169853}.scw-cookie-policy,.scw-cookie-settings{display:inline-block;line-height:30px;margin-left:13px;text-align:center;width:20px}.scw-cookie-policy .scwc-icon,.scw-cookie-settings .scwc-icon{margin-top:-5px;opacity:.7;position:relative;top:7px}.scw-cookie-policy:hover .scwc-icon,.scw-cookie-settings:hover .scwc-icon{opacity:1}.scw-cookie-settings{cursor:pointer}.scw-cookie-details{clear:both;display:none;padding-top:15px}.scw-cookie-details::after{clear:both;content:'';display:block}.scw-cookie-details-title{font-weight:700}.scw-cookie-toggle{border:solid 1px;box-sizing:border-box;float:left;margin-top:10px;padding:5px;width:calc(50% - 5px)}.scw-cookie-toggle:nth-child(even){margin-right:5px}.scw-cookie-toggle:nth-child(odd){margin-left:5px}.scw-cookie-name{cursor:pointer;float:left;line-height:23px;padding-left:15px;width:80%}.scw-cookie-toggle input[type=checkbox]{cursor:pointer;float:left;height:25px;margin:0;width:20%}.scw-cookie-tooltip-trigger{position:relative}.scw-cookie-tooltip{animation:fadeIn .5s ease-in-out;background:#fff;border:solid 1px #000;color:#000;font-size:11px;left:50%;line-height:23px;padding:0 10px;position:absolute;top:0;transform:translate(-50%,-100%);width:100px}@-webkit-keyframes fadeIn{from{opacity:0;visibility:hidden}to{opacity:1;visibility:visible}}@keyframes fadeIn{from{opacity:0;visibility:hidden}to{opacity:1;visibility:visible}}@-webkit-keyframes slideIn{from{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes slideIn{from{transform:translateY(100%)}to{transform:translateY(0)}}@-webkit-keyframes slideOut{from{transform:translateY(0)}to{transform:translateY(100%)}}@keyframes slideOut{from{transform:translateY(0)}to{transform:translateY(100%)}}.scw-cookie-switch{background:#bdb9a6;border-radius:1em;cursor:pointer;display:inline-block;font-size:20px;height:.8em;margin:0;position:relative;top:4px;width:2em}.scw-cookie-switch.checked{background:#20bf6b}.scw-cookie-switch.disabled{cursor:not-allowed;opacity:.5}.scw-cookie-switch input{position:absolute;opacity:0}.scw-cookie-switch div{background:#fff;border-radius:.8em;box-shadow:0 .1em .3em rgba(0,0,0,.3);height:.8em;width:1em;-webkit-transition:all .3s;-moz-transition:all .3s;transition:all .3s}.scw-cookie-switch input:checked+div{-webkit-transform:translate3d(100%,0,0);-moz-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)} 2 | -------------------------------------------------------------------------------- /scwCookie/output/assets/scwCookie.min.js: -------------------------------------------------------------------------------- 1 | function scwCookieHide(){jQuery.post("/scwCookie/ajax.php",{action:"hide"}).done(function(o){o.hasOwnProperty("success")&&o.success&&(jQuery(".scw-cookie").addClass("scw-cookie-slide-out"),jQuery(document).find("body").removeClass("scw-cookie-in")),jQuery(".scw-cookie").hasClass("changed")&&location.reload()})}function scwCookieDetails(){jQuery(".scw-cookie-details").slideToggle()}function scwCookieToggle(o){jQuery(o).closest(".scw-cookie-toggle").find('input[type="checkbox"]').click()}function scwCookiePanelToggle(){jQuery(".scw-cookie").removeClass("scw-cookie-out"),jQuery(document).find("body").hasClass("scw-cookie-in")?(jQuery(".scw-cookie").addClass("scw-cookie-slide-out"),jQuery(document).find("body").removeClass("scw-cookie-in")):(jQuery(".scw-cookie").removeClass("scw-cookie-slide-out"),jQuery(document).find("body").addClass("scw-cookie-in"))}jQuery(".scw-cookie").hasClass("scw-cookie-out")||jQuery(document).find("body").addClass("scw-cookie-in"),jQuery(document).ready(function(o){o(".scw-cookie-switch input").each(function(){o(this).prop("checked")?o(this).closest(".scw-cookie-switch").addClass("checked"):o(this).closest(".scw-cookie-switch").removeClass("checked")})}),jQuery(document).on("change",'.scw-cookie-toggle input[type="checkbox"]',function(){jQuery(this).closest(".scw-cookie").addClass("changed"),jQuery(this).closest(".scw-cookie-switch").toggleClass("checked"),jQuery.post("/scwCookie/ajax.php",{action:"toggle",name:jQuery(this).attr("name"),value:jQuery(this).prop("checked")}).done(function(o){o.hasOwnProperty("removeCookies")&&jQuery.each(o.removeCookies,function(o,e){Cookies.remove(e.name),Cookies.remove(e.name,{domain:e.domain}),Cookies.remove(e.name,{path:e.path}),Cookies.remove(e.name,{domain:e.domain,path:e.path})})})}),jQuery(document).ready(function(o){o(".scw-cookie-tooltip-trigger").hover(function(){var e=o(this).attr("data-label");o(this).append(''+e+"")},function(){o(this).find(".scw-cookie-tooltip").remove()})}),jQuery(document).ready(function(o){jQuery.post("/scwCookie/ajax.php",{action:"load"}).done(function(o){o.hasOwnProperty("removeCookies")&&jQuery.each(o.removeCookies,function(o,e){Cookies.remove(e.name),Cookies.remove(e.name,{domain:e.domain}),Cookies.remove(e.name,{path:e.path}),Cookies.remove(e.name,{domain:e.domain,path:e.path})})})}); 2 | -------------------------------------------------------------------------------- /scwCookie/output/cookies/Google_Analytics/cookies.php: -------------------------------------------------------------------------------- 1 | [ 4 | 'path' => '/', 5 | 'domain' => '.'.str_replace('www.', '', $_SERVER['HTTP_HOST']), 6 | ], 7 | ['name' => '_ga'], 8 | ['name' => '_gid'], 9 | ['name' => '_gat'], 10 | ['name' => '_gat_gtag_'.str_replace('-', '_', $this->getConfig('Google_Analytics', 'code'))], 11 | ['name' => '__utma'], 12 | ['name' => '__utmt'], 13 | ['name' => '__utmb'], 14 | ['name' => '__utmc'], 15 | ['name' => '__utmz'], 16 | ['name' => '__utmv'], 17 | ['name' => '__utmx'], 18 | ['name' => '__utmxx'], 19 | ['name' => '_gaexp'], 20 | ['name' => '_utm.gif'], 21 | ]; 22 | -------------------------------------------------------------------------------- /scwCookie/output/cookies/Google_Analytics/output.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /scwCookie/output/cookies/Hotjar/cookies.php: -------------------------------------------------------------------------------- 1 | '_hjClosedSurveyInvites'], 4 | ['name' => '_hjDonePolls'], 5 | ['name' => '_hjMinimizedPolls'], 6 | ['name' => '_hjDoneTestersWidgets'], 7 | ['name' => '_hjMinimizedTestersWidgets'], 8 | ['name' => '_hjIncludedInSample'], 9 | ]; 10 | -------------------------------------------------------------------------------- /scwCookie/output/cookies/Hotjar/output.php: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /scwCookie/output/cookies/Smartsupp/cookies.php: -------------------------------------------------------------------------------- 1 | 'Smartlookcookie'], 4 | ['name' => 'ssupp.chatid'], 5 | ['name' => 'ssupp.vid'], 6 | ]; 7 | -------------------------------------------------------------------------------- /scwCookie/output/cookies/Smartsupp/output.php: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /scwCookie/output/cookies/Tawk.to/cookies.php: -------------------------------------------------------------------------------- 1 | '__tawkuuid', 5 | 'domain' => '.'.str_replace('www.', '', $_SERVER['HTTP_HOST']) 6 | ], 7 | ['name' => 'TawkConnectionTime'], 8 | ['name' => 'Tawk_'.$this->getConfig('Tawk.to', 'code')], 9 | ]; 10 | -------------------------------------------------------------------------------- /scwCookie/output/cookies/Tawk.to/output.php: -------------------------------------------------------------------------------- 1 | 2 | 13 | -------------------------------------------------------------------------------- /scwCookie/output/popup.php: -------------------------------------------------------------------------------- 1 | 2 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /scwCookie/output/scwCookie.php: -------------------------------------------------------------------------------- 1 | output(); 5 | -------------------------------------------------------------------------------- /scwCookie/scwCookie.class.php: -------------------------------------------------------------------------------- 1 | config = parse_ini_file("config.ini", true); 14 | 15 | $this->decisionMade = self::getCookie('scwCookieHidden') == 'true'; 16 | $this->choices = $this->getChoices(); 17 | } 18 | 19 | public function getChoices() 20 | { 21 | if (self::getCookie('scwCookie') !== false) { 22 | $cookie = self::getCookie('scwCookie'); 23 | $cookie = self::decrypt($cookie); 24 | return $cookie; 25 | } 26 | 27 | $return = []; 28 | foreach ($this->enabledCookies() as $name => $label) { 29 | $return[$name] = $this->config['unsetDefault']; 30 | } 31 | return $return; 32 | } 33 | 34 | public static function encrypt($value) 35 | { 36 | $value = json_encode($value); 37 | $return = base64_encode($value); 38 | return $return; 39 | } 40 | 41 | public static function decrypt($value) 42 | { 43 | $value = base64_decode($value); 44 | $value = str_replace('\"', '"', $value); 45 | $return = json_decode($value, true); 46 | return $return; 47 | } 48 | 49 | public function isAllowed($name) 50 | { 51 | $choices = $this->getChoices(); 52 | return isset($choices[$name]) && $choices[$name] == 'allowed'; 53 | } 54 | 55 | public function isEnabled($name) 56 | { 57 | $check = $this->config[$name]; 58 | return is_array($check) && isset($check['enabled']) && $check['enabled']; 59 | } 60 | 61 | public function getConfig($name, $attribute) 62 | { 63 | return isset($this->config[$name]) && isset($this->config[$name][$attribute]) 64 | ? $this->config[$name][$attribute] 65 | : false; 66 | } 67 | 68 | public function output() 69 | { 70 | echo $this->getOutput(); 71 | } 72 | 73 | public function getOutput() 74 | { 75 | $return = []; 76 | 77 | // Get popup output 78 | $return[] = $this->getOutputHTML('popup'); 79 | 80 | // Get embed codes 81 | foreach ($this->config as $configKey => $configValue) { 82 | if (!is_array($configValue) || !$configValue['enabled'] || !$this->isAllowed($configKey)) { 83 | continue; 84 | } 85 | $return[] = $this->getOutputHTML('/cookies/'.$configKey.'/output'); 86 | } 87 | 88 | return implode("\n", $return); 89 | } 90 | 91 | public function getOutputHTML($filename) 92 | { 93 | if (!file_exists(__DIR__.'/output/'.$filename.'.php')) { 94 | return false; 95 | } 96 | 97 | ob_start(); 98 | include __DIR__.'/output/'.$filename.'.php'; 99 | return trim(ob_get_clean()); 100 | } 101 | 102 | public function enabledCookies() 103 | { 104 | $return = []; 105 | foreach ($this->config as $name => $value) { 106 | if (!$this->isEnabled($name)) { 107 | continue; 108 | } 109 | $return[$name] = $value['label']; 110 | } 111 | return $return; 112 | } 113 | 114 | public function disabledCookies() 115 | { 116 | $return = []; 117 | foreach ($this->config as $name => $value) { 118 | if (!$this->isEnabled($name) || !is_array($value) || $this->isAllowed($name)) { 119 | continue; 120 | } 121 | $return[$name] = $value['label']; 122 | } 123 | return $return; 124 | } 125 | 126 | public static function setCookie( 127 | $name, 128 | $value, 129 | $lifetime = 30, 130 | $lifetimePeriod = 'days', 131 | $domain = '/', 132 | $secure = false 133 | ) { 134 | // Validate parameters 135 | self::validateSetCookieParams($name, $value, $lifetime, $domain, $secure); 136 | 137 | // Calculate expiry 138 | $expiry = strtotime('+'.$lifetime.' '.$lifetimePeriod); 139 | 140 | // Set cookie 141 | return setcookie($name, $value, $expiry, $domain, $secure); 142 | } 143 | 144 | public static function validateSetCookieParams($name, $value, $lifetime, $domain, $secure) 145 | { 146 | // Types of parameters to check 147 | $paramTypes = [ 148 | // Type => Array of variables 149 | 'string' => [$name, $value, $domain], 150 | 'int' => [$lifetime], 151 | 'bool' => [$secure], 152 | ]; 153 | 154 | // Validate basic parameters 155 | $validParams = self::basicValidationChecks($paramTypes); 156 | 157 | // Ensure parameters are still valid 158 | if (!$validParams) { 159 | // Failed parameter check 160 | header('HTTP/1.0 403 Forbidden'); 161 | throw new \Exception("Incorrect parameter passed to Cookie::set"); 162 | } 163 | 164 | return true; 165 | } 166 | 167 | public static function basicValidationChecks($paramTypes) 168 | { 169 | foreach ($paramTypes as $type => $variables) { 170 | $functionName = 'is_'.$type; 171 | foreach ($variables as $variable) { 172 | if (!$functionName($variable)) { 173 | return false; 174 | } 175 | } 176 | } 177 | return true; 178 | } 179 | 180 | public function clearCookieGroup($groupName) 181 | { 182 | if (!file_exists(__DIR__.'/output/cookies/'.$groupName.'/cookies.php')) { 183 | return false; 184 | } 185 | $clearCookies = include __DIR__.'/output/cookies/'.$groupName.'/cookies.php'; 186 | 187 | $defaults = [ 188 | 'path' => '/', 189 | 'domain' => $_SERVER['HTTP_HOST'], 190 | ]; 191 | 192 | if (isset($clearCookies['defaults'])) { 193 | $defaults = array_merge($defaults, $clearCookies['defaults']); 194 | unset($clearCookies['defaults']); 195 | } 196 | 197 | $return = []; 198 | 199 | foreach ($clearCookies as $cookie) { 200 | $cookie['path'] = isset($cookie['path']) ? $cookie['path'] : $defaults['path']; 201 | $cookie['domain'] = isset($cookie['domain']) ? $cookie['domain'] : $defaults['domain']; 202 | self::destroyCookie($cookie['name'], $cookie['path'], $cookie['domain']); 203 | $return[] = $cookie; 204 | } 205 | 206 | return $return; 207 | } 208 | 209 | public static function getCookie($name) 210 | { 211 | // If cookie exists - return it, otherwise return false 212 | return isset($_COOKIE[$name]) ? $_COOKIE[$name] : false; 213 | } 214 | 215 | public static function destroyCookie($name, $path = '', $domain = '') 216 | { 217 | // Set cookie expiration to 1 hour ago 218 | return setcookie($name, '', time() - 3600, $path, $domain); 219 | } 220 | } 221 | --------------------------------------------------------------------------------