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 2434d1d commit d42322d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cookiebot/CookiebotPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getName(): string
*/
public function getVersion(): string
{
return '1.0.0';
return '1.1.0';
}

/**
Expand Down
34 changes: 34 additions & 0 deletions cookiebot/services/CookiebotService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ class CookiebotService extends BaseApplicationComponent
*/
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 @@ -31,6 +43,10 @@ public function hasConsent(): bool
*/
public function hasPreferencesConsent(): bool
{
if (!$this->requiresConsent()) {
return true;
}

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

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

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

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

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

Expand Down Expand Up @@ -106,6 +130,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 @@ -160,6 +190,10 @@ private function createConsentObject(bool $preferences = false, bool $statistics
*/
private function renderScript(string $type, string $culture = null): string
{
if (!$this->requiresConsent()) {
return '';
}

$settings = craft()->plugins->getPlugin('cookiebot')->getSettings();
$vars['domainGroupID'] = $settings->domainGroupID;
$vars['culture'] = $culture;
Expand Down
10 changes: 9 additions & 1 deletion releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
"notes": [
"[Added] Initial release"
]
},
{
"version": "1.1.0",
"downloadUrl": "https://github.com/balazscsaba2006/craft-cookiebot/archive/master.zip",
"date": "2010-04-20T11:49:22.152Z",
"notes": [
"[Fixed] Upgraded cookiebot support for version 2 of the cookie, that handles cookies that don't require consent"
]
}
]
]

0 comments on commit d42322d

Please sign in to comment.