Initial commit - Typo3 11.5.41

This commit is contained in:
Matteo Gallo
2026-07-03 17:53:31 +02:00
commit 5ca4743197
6811 changed files with 568848 additions and 0 deletions
@@ -0,0 +1,70 @@
<?php
/*
* Copyright (c) 2021.
*
* @category TYPO3
*
* @copyright 2021 Dirk Persky (https://github.com/DirkPersky)
* @author Dirk Persky <info@dp-wired.de>
* @license MIT
*/
namespace DirkPersky\DpCookieconsent\Controller;
use ArrayObject;
use DirkPersky\DpCookieconsent\Domain\Repository\CookieRepository;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation\Inject;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
class CookieController extends ActionController
{
/**
* @var CookieRepository
*/
protected $cookieRepository;
/**
* @param CookieRepository
*/
public function injectCookieRepository(CookieRepository $cookieRepository)
{
$this->cookieRepository = $cookieRepository;
}
/**
* @return void
*/
public function listAction()
{
$cObj = $this->configurationManager->getContentObject();
// parse Flexform
$flexFormData = GeneralUtility::makeInstance(FlexFormService::class)->convertFlexFormContentToArray($cObj->data['pi_flexform']);
// get Cookies
$cookies = $this->cookieRepository->findByPid($flexFormData['settings']['startingpoint'], $flexFormData['settings']['recursive']);
// group cookies
$grouped = new ArrayObject([]);
foreach ($cookies as $cookie) {
$category = $cookie->getCategory();
if (!isset($grouped[$category])) {
$grouped[$category] = new ArrayObject([
'category' => $category,
'items' => new ArrayObject([])
]);
}
$grouped[$category]['items'][] = $cookie;
}
// update settings
$this->settings['base_uri'] = parse_url($this->request->getBaseUri());
$this->view->assign('settings', $this->settings);
// add data to view
$this->view->assign('data', $cObj->data);
$this->view->assign('cookies', $cookies);
$this->view->assign('grouped', $grouped);
}
}
@@ -0,0 +1,50 @@
<?php
/*
* Copyright (c) 2021.
*
* @category TYPO3
*
* @copyright 2021 Dirk Persky (https://github.com/DirkPersky)
* @author Dirk Persky <info@dp-wired.de>
* @license MIT
*/
namespace DirkPersky\DpCookieconsent\Controller;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Service\FlexFormService;
class ScriptController extends ActionController{
/**
* @return void
*/
public function listAction()
{
$cObj = $this->configurationManager->getContentObject();
// parse Flexform
$flexFormData = GeneralUtility::makeInstance(FlexFormService::class)->convertFlexFormContentToArray($cObj->data['pi_flexform']);
// remove duplicate Settings
unset($flexFormData['settings']);
// add data to view
$this->view->assign('flexform',$flexFormData);
$this->view->assign('data', $cObj->data);
}
/**
* @param $content
* @return void
*/
public function showAction()
{
$cObj = $this->configurationManager->getContentObject();
// parse Flexform
$flexFormData = GeneralUtility::makeInstance(FlexFormService::class)->convertFlexFormContentToArray($cObj->data['pi_flexform']);
// remove duplicate Settings
unset($flexFormData['settings']);
// add data to view
$this->view->assign('flexform',$flexFormData);
$this->view->assign('data', $cObj->data);
}
}
@@ -0,0 +1,42 @@
<?php
/*
* Copyright (c) 2021.
*
* @category TYPO3
*
* @copyright 2021 Dirk Persky (https://github.com/DirkPersky)
* @author Dirk Persky <info@dp-wired.de>
* @license MIT
*/
namespace DirkPersky\DpCookieconsent\DataProcessing;
use DirkPersky\DpCookieconsent\Domain\Repository\CookieRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
class CookieScriptsProcessor implements DataProcessorInterface
{
public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
): array
{
if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
// leave $processedData unchanged in case there were previous other processors
return $processedData;
}
/** @var CookieRepository $cookieRepository */
$cookieRepository = GeneralUtility::makeInstance(CookieRepository::class);
/** find all Cookies for site */
$cookies = $cookieRepository->findActiveScripts((int)$processorConfiguration['pid']);
// set the storage into a variable, default "dp_cookie_scripts"
$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'dp_cookie_scripts');
// store result
$processedData[$targetVariableName] = $cookies;
return $processedData;
}
}
@@ -0,0 +1,381 @@
<?php
/*
* Copyright (c) 2021.
*
* @category TYPO3
*
* @copyright 2021 Dirk Persky (https://github.com/DirkPersky)
* @author Dirk Persky <info@dp-wired.de>
* @license MIT
*/
namespace DirkPersky\DpCookieconsent\Domain\Model;
use DateTime;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* This file is part of the "dp_cookieconsent" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
class Cookie extends AbstractEntity
{
/**
* @var string
*/
protected $durationTime;
/**
* @var string
*/
protected $scriptSrc;
/**
* @var string
*/
protected $script;
/**
* @var string
*/
protected $category = '';
/**
* @var string
*/
protected $name = '';
/**
* @var string
*/
protected $description = '';
/**
* @var string
*/
protected $duration = '';
/**
* @var string
*/
protected $vendor = '';
/**
* @var string
*/
protected $vendorLink = '';
/**
* @var DateTime
*/
protected $crdate;
/**
* @var DateTime
*/
protected $tstamp;
/**
* @var DateTime
*/
protected $starttime;
/**
* @var DateTime
*/
protected $endtime;
/**
* @var bool
*/
protected $hidden = false;
/**
* @var bool
*/
protected $deleted = false;
/**
* @var int
*/
protected $sorting = 0;
/**
* @return bool
*/
public function getHidden(): bool
{
return $this->hidden;
}
/**
* @param bool $hidden
*/
public function setHidden(bool $hidden): void
{
$this->hidden = $hidden;
}
/**
* @return bool
*/
public function getDeleted(): bool
{
return $this->deleted;
}
/**
* @param bool $deleted
*/
public function setDeleted(bool $deleted): void
{
$this->deleted = $deleted;
}
/**
* @return string
*/
public function getDurationTime(): string
{
return $this->durationTime;
}
/**
* @param string $durationTime
*/
public function setDurationTime(string $durationTime): void
{
$this->durationTime = $durationTime;
}
/**
* @return string
*/
public function getScriptSrc(): string
{
return $this->scriptSrc;
}
/**
* @param string $scriptSrc
*/
public function setScriptSrc(string $scriptSrc): void
{
$this->scriptSrc = $scriptSrc;
}
/**
* @return string
*/
public function getScript(): string
{
return $this->script;
}
/**
* @param string $script
*/
public function setScript(string $script): void
{
$this->script = $script;
}
/**
* @return string
*/
public function getCategory(): string
{
return $this->category;
}
/**
* @param string $category
*/
public function setCategory(string $category): void
{
$this->category = $category;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription(string $description): void
{
$this->description = $description;
}
/**
* @return string
*/
public function getDuration(): string
{
return $this->duration;
}
/**
* @param string $duration
*/
public function setDuration(string $duration): void
{
$this->duration = $duration;
}
/**
* @return string
*/
public function getVendor(): string
{
return $this->vendor;
}
/**
* @param string $vendor
*/
public function setVendor(string $vendor): void
{
$this->vendor = $vendor;
}
/**
* @return string
*/
public function getVendorLink(): string
{
return $this->vendorLink;
}
/**
* @param string $vendorLink
*/
public function setVendorLink(string $vendorLink): void
{
$this->vendorLink = $vendorLink;
}
/**
* @return DateTime
*/
public function getCrdate(): DateTime
{
return $this->crdate;
}
/**
* @param DateTime $crdate
*/
public function setCrdate(DateTime $crdate): void
{
$this->crdate = $crdate;
}
/**
* @return DateTime
*/
public function getTstamp(): DateTime
{
return $this->tstamp;
}
/**
* @param DateTime $tstamp
*/
public function setTstamp(DateTime $tstamp): void
{
$this->tstamp = $tstamp;
}
/**
* @return DateTime
*/
public function getStarttime(): DateTime
{
return $this->starttime;
}
/**
* @param DateTime $starttime
*/
public function setStarttime(DateTime $starttime): void
{
$this->starttime = $starttime;
}
/**
* @return DateTime
*/
public function getEndtime(): DateTime
{
return $this->endtime;
}
/**
* @param DateTime $endtime
*/
public function setEndtime(DateTime $endtime): void
{
$this->endtime = $endtime;
}
/**
* @return int
*/
public function getSorting(): int
{
return $this->sorting;
}
/**
* @param int $sorting
*/
public function setSorting(int $sorting): void
{
$this->sorting = $sorting;
}
/**
* @return string
*/
public function getType(): string
{
switch ($this->category) {
case '1':
$type = 'statistics';
break;
case '2':
$type = 'marketing';
break;
default:
$type = 'required';
}
return $type;
}
}
@@ -0,0 +1,98 @@
<?php
/*
* Copyright (c) 2021.
*
* @category TYPO3
*
* @copyright 2021 Dirk Persky (https://github.com/DirkPersky)
* @author Dirk Persky <info@dp-wired.de>
* @license MIT
*/
namespace DirkPersky\DpCookieconsent\Domain\Repository;
use TYPO3\CMS\Core\Database\QueryGenerator;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
class CookieRepository extends Repository
{
// Order by BE sorting
protected $defaultOrderings = array(
'sorting' => QueryInterface::ORDER_ASCENDING
);
public function initializeObject()
{
/** @var Typo3QuerySettings $querySettings */
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
// don't add sys_language_uid constraint
$querySettings->setRespectSysLanguage(FALSE);
// save default Settings
$this->setDefaultQuerySettings($querySettings);
}
protected function getPidList($pidList, $recursive = '')
{
$recursive = (int)$recursive;
// if no recursiv return pidList
if ($recursive <= 0) return GeneralUtility::intExplode(',', $pidList);
// get DB query for getting pids
$queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
// explode list
$storagePids = GeneralUtility::intExplode(',', $pidList);
// build PID list
$recursiveStoragePids = $storagePids;
// loop pids and get tree
foreach ($storagePids as $startPid) {
if ($startPid >= 0) {
// get tree
$pids = $queryGenerator->getTreeList($startPid, $recursive);
// explode to array
$pids = GeneralUtility::intExplode(',', $pids);
// if not empty add to list
if (!empty($pids)) $recursiveStoragePids = array_merge($recursiveStoragePids, $pids);
}
}
// return array
return array_unique($recursiveStoragePids);
}
/**
* @param integer $pid
* @return mixed
*/
public function findByPid($pid, $recursive = '')
{
$query = $this->createQuery();
// set new storage PIDs
$query->getQuerySettings()->setStoragePageIds($this->getPidList($pid, $recursive));
// execute statement
return $query->execute();
}
public function findActiveScripts($pid, $recursive = 250)
{
$query = $this->createQuery();
// set new storage PIDs
$query->getQuerySettings()->setStoragePageIds($this->getPidList($pid, $recursive));
// set filter
$query->matching(
$query->logicalAnd(
$query->logicalNot(
$query->logicalAnd(
$query->equals('script', ''),
$query->equals('script_src', '')
)
),
$query->greaterThan('category', 0)
)
);
// execute statement
return $query->execute();
}
}
@@ -0,0 +1,57 @@
<?php
/*
* Copyright (c) 2021.
*
* @category TYPO3
*
* @copyright 2021 Dirk Persky (https://github.com/DirkPersky)
* @author Dirk Persky <info@dp-wired.de>
* @license MIT
*/
namespace DirkPersky\DpCookieconsent\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
class PlainRenderingMiddleware implements MiddlewareInterface
{
private const namespace = 'tx_dpcookieconsent_pi1';
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$frontendController = $GLOBALS['TSFE'];
// check for default handling
if (!$frontendController->isGeneratePage() || !isset($request->getQueryParams()[self::namespace])) {
return $handler->handle($request);
}
// prepare rendering overwrite
$frontendController->config['config']['debug'] = 0;
$frontendController->config['config']['disableAllHeaderCode'] = 1;
$frontendController->config['config']['disableCharsetHeader'] = 0;
// disable svgstore
if (isset($frontendController->config['config']['svgstore.'])) $frontendController->config['config']['svgstore.']['enabled'] = 0;
// set UID
$uid = $request->getQueryParams()[self::namespace]['content'];
// prepare typoscript
$frontendController->pSetup = [
'10' => 'COA',
'10.' => [
'10' => 'RECORDS',
'10.' => [
'tables' => 'tt_content',
'source' => "tt_content_{$uid}"
]
],
];
// change fluid Layout to remove Wrap
if (isset($frontendController->tmpl->setup['lib.']['contentElement.'])) $frontendController->tmpl->setup['lib.']['contentElement.']['layoutRootPaths.'][999] = 'EXT:dp_cookieconsent/Resources/Private/Overwrite/Layouts/';
// handle result
return $handler->handle($request);
}
}
@@ -0,0 +1,41 @@
<?php
/**
* Copyright (c) 2020.
*
* @category TYPO3
*
* @copyright 2020 Dirk Persky
* @author Dirk Persky <info@dp-wired.de>
* @license MIT
*/
namespace DirkPersky\DpCookieconsent\ViewHelpers;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
class JsonViewHelper extends AbstractViewHelper {
/**
* Replaces newline characters by HTML line breaks.
*
* @return string the altered string.
* @api
*/
public function render() {
$value = $this->renderChildren();
$options = JSON_HEX_TAG;
return json_encode($value, $options);
}
}