-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds compatibility, removes mandatory condition
- Loading branch information
1 parent
be19b9e
commit 5cb8b6d
Showing
28 changed files
with
219 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* This file is part of the TYPO3 CMS extension. | ||
* The extension name is: Cookie Consent Plus. | ||
* The extension key is: cookieconsent_plus. | ||
* Cookie Consent Plus extends dp_cookieconsent TYPO3 extension | ||
* The developer is Davide Alghi (Abbiategrasso - Italy). | ||
* Cookie Consent Plus Copyright (C) 2021 Davide Alghi. | ||
* All Rights Reserved. | ||
* Cookie Consent Plus is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* Cookie Consent Plus is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with Cookie Consent Plus. If not, see https://www.gnu.org/licenses/gpl-3.0.en.html. | ||
* See the file LICENSE.md for copying conditions. | ||
* Website: https://www.penguinable.it | ||
* | ||
* @category TYPO3 | ||
* @copyright 2021 Davide Alghi | ||
* @author Davide Alghi <[email protected]> | ||
* @license GPLv3 | ||
*/ | ||
|
||
namespace PAD\CookieconsentPlus\Compatibility; | ||
|
||
use \TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
|
||
class Version | ||
{ | ||
const DP_COOKIECONSENT_KEY = 'dp_cookieconsent'; | ||
|
||
/** | ||
* If dp_cookieconsent is the new version | ||
* returns true | ||
* else false | ||
* It is the new version, if it is eq to 11.2.1 or gte to 11.4.0 | ||
* | ||
* @param none | ||
* @return bool | ||
*/ | ||
public function isTheNewVersion(): bool | ||
{ | ||
$version = ExtensionManagementUtility::getExtensionVersion(self::DP_COOKIECONSENT_KEY); | ||
$result = false; | ||
if (\version_compare($version, '11.2.1', '==') || \version_compare($version, '11.4.0', '>=')) { | ||
$result = true; | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
* along with Cookie Consent Plus. If not, see https://www.gnu.org/licenses/gpl-3.0.en.html. | ||
* See the file LICENSE.md for copying conditions. | ||
* Website: https://www.penguinable.it | ||
* | ||
* | ||
* @category TYPO3 | ||
* @copyright 2021 Davide Alghi | ||
* @author Davide Alghi <[email protected]> | ||
|
@@ -31,41 +31,73 @@ | |
|
||
namespace PAD\CookieconsentPlus\Cookie; | ||
|
||
use \PAD\CookieconsentPlus\Compatibility\Version; | ||
use \TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class CookieManager | ||
{ | ||
const COOKIECONSENTSTATUS_NAME = 'cookieconsent_status'; | ||
const COOKIECONSENTSTATUS_OPTOUT_NAME = 'dp_cookieconsent_status'; | ||
const COOKIECONSENTSTATUS_DP_NAME = 'dp_cookieconsent_status'; | ||
const COOKIEDISMISSVALUE = 'dismiss'; | ||
const COOKIEALLOWVALUE = 'allow'; | ||
const COOKIEDENYVALUE = 'deny'; | ||
const COOKIEDIALOGSTATUSOPEN = 'open'; | ||
const COOKIEDIALOGSTATUSAPPROVED = 'approved'; | ||
|
||
protected $cookieValue = ''; | ||
protected $optoutCookieValue = ''; | ||
protected $dpCookieValue = []; | ||
protected $cookieStatus = false; | ||
protected $mandatoryCookieStatus = false; | ||
protected $dpCookieStatus = ''; | ||
protected $statisticsCookieStatus = false; | ||
protected $marketingCookieStatus = false; | ||
|
||
/** | ||
* Sets statuses from cookies value | ||
* | ||
* | ||
* @param void | ||
*/ | ||
public function __construct() | ||
{ | ||
if (isset($_COOKIE[self::COOKIECONSENTSTATUS_NAME])) { | ||
$this->cookieValue = $_COOKIE[self::COOKIECONSENTSTATUS_NAME]; | ||
if ($this->cookieValue) { | ||
$this->cookieStatus = $_COOKIE[self::COOKIECONSENTSTATUS_NAME] == self::COOKIEDENYVALUE ? false : true; | ||
if ($this->cookieStatus) { | ||
$this->mandatoryCookieStatus = true; | ||
if ($this->cookieValue != self::COOKIEDISMISSVALUE && isset($_COOKIE[self::COOKIECONSENTSTATUS_OPTOUT_NAME])) { | ||
$this->optoutCookieValue = $_COOKIE[self::COOKIECONSENTSTATUS_OPTOUT_NAME]; | ||
$optoutCookieValueArray = json_decode($_COOKIE[self::COOKIECONSENTSTATUS_OPTOUT_NAME], true); | ||
$this->statisticsCookieStatus = (boolean) $optoutCookieValueArray['dp--cookie-statistics']; | ||
$this->marketingCookieStatus = (boolean) $optoutCookieValueArray['dp--cookie-marketing']; | ||
} else { | ||
$this->statisticsCookieStatus = true; | ||
$this->marketingCookieStatus = true; | ||
$versionCompatibility = GeneralUtility::makeInstance(Version::class); | ||
if ($versionCompatibility->isTheNewVersion()) { // dp_cookieconsent new version | ||
if (isset($_COOKIE[self::COOKIECONSENTSTATUS_DP_NAME])) { | ||
$this->cookieValue = ''; | ||
$this->cookieStatus = false; | ||
$this->dpCookieValue = json_decode($_COOKIE[self::COOKIECONSENTSTATUS_DP_NAME], true); | ||
$this->dpCookieStatus = $this->dpCookieValue['status']; | ||
if ($this->dpCookieStatus == self::COOKIEDIALOGSTATUSAPPROVED) { | ||
if (is_array($this->dpCookieValue['checkboxes'])) { | ||
foreach ($this->dpCookieValue['checkboxes'] as $key => $value) { | ||
switch ($value['name']) { | ||
case 'statistics': | ||
$this->statisticsCookieStatus = (boolean) $value['checked']; | ||
break; | ||
|
||
case 'marketing': | ||
$this->marketingCookieStatus = (boolean) $value['checked']; | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
$this->statisticsCookieStatus = false; | ||
$this->marketingCookieStatus = false; | ||
} | ||
} | ||
} else { // dp_cookieconsent old version | ||
if (isset($_COOKIE[self::COOKIECONSENTSTATUS_NAME])) { | ||
$this->cookieValue = $_COOKIE[self::COOKIECONSENTSTATUS_NAME]; | ||
if ($this->cookieValue) { | ||
$this->cookieStatus = $_COOKIE[self::COOKIECONSENTSTATUS_NAME] == self::COOKIEDENYVALUE ? false : true; | ||
if ($this->cookieStatus) { | ||
if ($this->cookieValue != self::COOKIEDISMISSVALUE && isset($_COOKIE[self::COOKIECONSENTSTATUS_DP_NAME])) { | ||
$this->dpCookieValue = json_decode($_COOKIE[self::COOKIECONSENTSTATUS_DP_NAME], true); | ||
$this->statisticsCookieStatus = (boolean) $this->dpCookieValue['dp--cookie-statistics']; | ||
$this->marketingCookieStatus = (boolean) $this->dpCookieValue['dp--cookie-marketing']; | ||
} else { | ||
$this->statisticsCookieStatus = true; | ||
$this->marketingCookieStatus = true; | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -74,7 +106,7 @@ public function __construct() | |
|
||
/** | ||
* Returns cookieconsent_status cookie value | ||
* | ||
* | ||
* @param void | ||
* @return string | ||
*/ | ||
|
@@ -85,19 +117,18 @@ public function getCookieValue(): string | |
|
||
/** | ||
* Returns dp_cookieconsent_status cookie value | ||
* in array format | ||
* | ||
* | ||
* @param void | ||
* @return array | ||
*/ | ||
public function getOptoutCookieValue(): array | ||
public function getDpCookieValue(): array | ||
{ | ||
return json_decode($this->optoutCookieValue, true); | ||
return $this->dpCookieValue; | ||
} | ||
|
||
/** | ||
* Returns cookies status | ||
* | ||
* | ||
* @param void | ||
* @return bool | ||
*/ | ||
|
@@ -107,21 +138,20 @@ public function getCookieStatus(): bool | |
} | ||
|
||
/** | ||
* Returns mandatory cookies status | ||
* accepted: true, denied: false | ||
* | ||
* Returns dp cookies status | ||
* | ||
* @param void | ||
* @return bool | ||
* @return string | ||
*/ | ||
public function isMandatoryOn(): bool | ||
public function getDpCookieStatus(): string | ||
{ | ||
return $this->mandatoryCookieStatus; | ||
return $this->dpCookieStatus; | ||
} | ||
|
||
/** | ||
* Returns statistics cookies status | ||
* accepted: true, denied: false | ||
* | ||
* | ||
* @param void | ||
* @return bool | ||
*/ | ||
|
@@ -133,7 +163,7 @@ public function isStatisticsOn(): bool | |
/** | ||
* Returns marketing cookies status | ||
* accepted: true, denied: false | ||
* | ||
* | ||
* @param void | ||
* @return bool | ||
*/ | ||
|
@@ -145,9 +175,9 @@ public function isMarketingOn(): bool | |
/** | ||
* Removes cookie with defined | ||
* name, path and domain | ||
* | ||
* | ||
* @param string $name - the cookie name | ||
* @param string $path - the path for which the cookie is valid | ||
* @param string $path - the path for which the cookie is valid | ||
* @param string $domain - the domain from which the cookie comes | ||
* @return void | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
* along with Cookie Consent Plus. If not, see https://www.gnu.org/licenses/gpl-3.0.en.html. | ||
* See the file LICENSE.md for copying conditions. | ||
* Website: https://www.penguinable.it | ||
* | ||
* | ||
* @category TYPO3 | ||
* @copyright 2021 Davide Alghi | ||
* @author Davide Alghi <[email protected]> | ||
|
@@ -31,10 +31,10 @@ | |
|
||
namespace PAD\CookieconsentPlus\Xclass; | ||
|
||
use TYPO3\CMS\Core\Database\ConnectionPool; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Core\Domain\Repository\PageRepository as CmsPageRepository; | ||
use PAD\CookieconsentPlus\Cookie\CookieManager; | ||
use \PAD\CookieconsentPlus\Cookie\CookieManager; | ||
use \TYPO3\CMS\Core\Database\ConnectionPool; | ||
use \TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use \TYPO3\CMS\Core\Domain\Repository\PageRepository as CmsPageRepository; | ||
|
||
class PageRepository extends CmsPageRepository | ||
{ | ||
|
@@ -46,7 +46,6 @@ class PageRepository extends CmsPageRepository | |
const CONDITIONTYPE_VALUE_SHOWOR = 'showor'; | ||
const CONDITIONTYPE_VALUE_HIDEAND = 'hideand'; | ||
const CONDITIONTYPE_VALUE_HIDEOR = 'hideor'; | ||
const MANDATORYCONDITION_FIELD = 'tx_cookieconsentplus_mandatorycondition'; | ||
const STATISTICSCONDITION_FIELD = 'tx_cookieconsentplus_statisticscondition'; | ||
const MARKETINGCONDITION_FIELD = 'tx_cookieconsentplus_marketingcondition'; | ||
const CONDITION_VALUE_ANYVALUE = 'anyvalue'; | ||
|
@@ -60,7 +59,7 @@ class PageRepository extends CmsPageRepository | |
|
||
/** | ||
* Returns enable fields (constraints) for cookies dependency | ||
* | ||
* | ||
* @param string $table - table on which to create the query | ||
* @return string | ||
*/ | ||
|
@@ -69,13 +68,8 @@ protected function getCookiesEnableFields($table): string | |
$constraints = []; | ||
if (in_array($table, $this->allowedTables)) { | ||
$cookieManager = GeneralUtility::makeInstance(CookieManager::class); | ||
$isMandatoryOn = $cookieManager->isMandatoryOn(); | ||
$isStatisticsOn = $cookieManager->isStatisticsOn(); | ||
$isMarketingOn = $cookieManager->isMarketingOn(); | ||
$mandatoryValues = [ | ||
self::CONDITION_VALUE_ANYVALUE, | ||
$isMandatoryOn ? self::CONDITION_VALUE_ACCEPTED : self::CONDITION_VALUE_DENIED, | ||
]; | ||
$statisticsValues = [ | ||
self::CONDITION_VALUE_ANYVALUE, | ||
$isStatisticsOn ? self::CONDITION_VALUE_ACCEPTED : self::CONDITION_VALUE_DENIED, | ||
|
@@ -86,7 +80,6 @@ protected function getCookiesEnableFields($table): string | |
]; | ||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); | ||
$expressionBuilder = $queryBuilder->expr(); | ||
$mandatoryValues = array_map([$expressionBuilder, 'literal'], $mandatoryValues); | ||
$statisticsValues = array_map([$expressionBuilder, 'literal'], $statisticsValues); | ||
$marketingValues = array_map([$expressionBuilder, 'literal'], $marketingValues); | ||
$constraints[] = $expressionBuilder->eq( | ||
|
@@ -103,10 +96,6 @@ protected function getCookiesEnableFields($table): string | |
$expressionBuilder->literal(self::CONDITIONTYPE_VALUE_SHOWAND) | ||
), | ||
$expressionBuilder->andX( | ||
$expressionBuilder->in( | ||
self::MANDATORYCONDITION_FIELD, | ||
$mandatoryValues | ||
), | ||
$expressionBuilder->in( | ||
self::STATISTICSCONDITION_FIELD, | ||
$statisticsValues | ||
|
@@ -127,10 +116,6 @@ protected function getCookiesEnableFields($table): string | |
$expressionBuilder->literal(self::CONDITIONTYPE_VALUE_SHOWOR) | ||
), | ||
$expressionBuilder->orX( | ||
$expressionBuilder->in( | ||
self::MANDATORYCONDITION_FIELD, | ||
$mandatoryValues | ||
), | ||
$expressionBuilder->in( | ||
self::STATISTICSCONDITION_FIELD, | ||
$statisticsValues | ||
|
@@ -147,7 +132,7 @@ protected function getCookiesEnableFields($table): string | |
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* | ||
* In addition cookies sql constraints | ||
* are added to enableFields query | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.