Skip to content

Commit

Permalink
Upgraded cookiebot support for version 2 of the cookie, that handles …
Browse files Browse the repository at this point in the history
…cookies that don't require consent
  • Loading branch information
balazscsaba2006 committed Apr 20, 2019
1 parent f7c5edc commit d0a5db5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -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"}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@

## 1.0.6 - 2018-07-06
### Fixed
- Downgraded to PHP 7.0 support
- 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
34 changes: 34 additions & 0 deletions src/services/CookiebotService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -35,6 +47,10 @@ public function hasConsent(): bool
*/
public function hasPreferencesConsent(): bool
{
if (!$this->requiresConsent()) {
return true;
}

return $this->decodeCookie()->preferences;
}

Expand All @@ -43,6 +59,10 @@ public function hasPreferencesConsent(): bool
*/
public function hasStatisticsConsent(): bool
{
if (!$this->requiresConsent()) {
return true;
}

return $this->decodeCookie()->statistics;
}

Expand All @@ -51,6 +71,10 @@ public function hasStatisticsConsent(): bool
*/
public function hasMarketingConsent(): bool
{
if (!$this->requiresConsent()) {
return true;
}

return $this->decodeCookie()->marketing;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d0a5db5

Please sign in to comment.