From d0a5db53ed6148c8014350dba5896aa7176c8fca Mon Sep 17 00:00:00 2001 From: Balazs Csaba Date: Sat, 20 Apr 2019 11:43:34 +0300 Subject: [PATCH] Upgraded cookiebot support for version 2 of the cookie, that handles cookies that don't require consent --- .craftplugin | 2 +- CHANGELOG.md | 6 +++++- src/services/CookiebotService.php | 34 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.craftplugin b/.craftplugin index 1567490..a76604c 100644 --- a/.craftplugin +++ b/.craftplugin @@ -1 +1 @@ -{"pluginName":"Cookiebot","pluginDescription":"CookieBot integration into Craft CMS 3.","pluginVersion":"1.0.6","pluginAuthorName":"Human Direct","pluginVendorName":"humandirect","pluginAuthorUrl":"https://humandirect.eu","pluginAuthorGithub":"","codeComments":"yes","pluginComponents":["services","utilities","variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} +{"pluginName":"Cookiebot","pluginDescription":"CookieBot integration into Craft CMS 3.","pluginVersion":"1.0.7","pluginAuthorName":"Human Direct","pluginVendorName":"humandirect","pluginAuthorUrl":"https://humandirect.eu","pluginAuthorGithub":"","codeComments":"yes","pluginComponents":["services","utilities","variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} diff --git a/CHANGELOG.md b/CHANGELOG.md index ce384ee..25cd755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,4 +29,8 @@ ## 1.0.6 - 2018-07-06 ### Fixed -- Downgraded to PHP 7.0 support \ No newline at end of file +- Downgraded to PHP 7.0 support + +## 1.0.7 - 2019-04-20 +### Fixed +- Upgraded cookiebot support for version 2 of the cookie, that handles cookies that don't require consent diff --git a/src/services/CookiebotService.php b/src/services/CookiebotService.php index 9679a54..bdebec5 100644 --- a/src/services/CookiebotService.php +++ b/src/services/CookiebotService.php @@ -22,11 +22,23 @@ class CookiebotService extends Component */ private $cookieConsent; + /** + * @return bool + */ + public function requiresConsent(): bool + { + return $this->isCookieSet() && '-1' !== $_COOKIE[self::COOKIE_NAME]; + } + /** * @return bool */ public function hasConsent(): bool { + if (!$this->requiresConsent()) { + return true; + } + return $this->isCookieSet() && '0' !== $_COOKIE[self::COOKIE_NAME]; } @@ -35,6 +47,10 @@ public function hasConsent(): bool */ public function hasPreferencesConsent(): bool { + if (!$this->requiresConsent()) { + return true; + } + return $this->decodeCookie()->preferences; } @@ -43,6 +59,10 @@ public function hasPreferencesConsent(): bool */ public function hasStatisticsConsent(): bool { + if (!$this->requiresConsent()) { + return true; + } + return $this->decodeCookie()->statistics; } @@ -51,6 +71,10 @@ public function hasStatisticsConsent(): bool */ public function hasMarketingConsent(): bool { + if (!$this->requiresConsent()) { + return true; + } + return $this->decodeCookie()->marketing; } @@ -110,6 +134,12 @@ private function decodeCookie(): \stdClass return $this->cookieConsent; } + if (!$this->requiresConsent()) { + $this->cookieConsent = $this->createConsentObject(true, true, true); + + return $this->cookieConsent; + } + // the user has not accepted cookies if (!$this->hasConsent()) { $this->cookieConsent = $this->createConsentObject(); @@ -164,6 +194,10 @@ private function createConsentObject(bool $preferences = false, bool $statistics */ private function renderScript(string $type, string $culture = null): string { + if (!$this->requiresConsent()) { + return ''; + } + $settings = Cookiebot::$plugin->getSettings(); $vars['domainGroupID'] = $settings->domainGroupID; $vars['culture'] = $culture;