Skip to content

Commit

Permalink
Merge pull request #7 from t3solution/2.0.1
Browse files Browse the repository at this point in the history
New release v2.0.1
  • Loading branch information
t3solution authored Jul 11, 2023
2 parents b3b1cd6 + 3d6ed06 commit 286f432
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 193 deletions.
126 changes: 42 additions & 84 deletions Classes/Controller/ConsentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@

namespace T3S\ContentConsent\Controller;

use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use Psr\Http\Message\ResponseInterface;
use T3SBS\T3sbootstrap\Domain\Repository\ConfigRepository;

/*
* This file is part of the TYPO3 extension content_consent.
Expand All @@ -31,25 +26,59 @@ class ConsentController extends ActionController
public function indexAction(): ResponseInterface
{
$contentConsent = FALSE;
$customThumbnail = [];
$defaultThumbnail = [];
$properties = [];
$extension = '';
$type = 0;
$currentRecord = $this->request->getAttribute('currentContentObject')->data['uid'];
$thumbnails = null;
$t3sbSettings = [];
if ( $this->settings['consent']['cookie'] && isset($_COOKIE['t3scontentconsent_'.$currentRecord])

if ( $this->settings['consent']['cookie']
&& isset($_COOKIE['t3scontentconsent_'.$currentRecord])
&& $_COOKIE['t3scontentconsent_'.$currentRecord] == 'allow' ) {

$contentConsent = TRUE;

} else {

$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$thumbnails = $fileRepository->findByRelation('tt_content', 'settings.consent.thumbnail', $currentRecord);
if ( ExtensionManagementUtility::isLoaded('t3sbootstrap') ) {
$t3sbSettings = self::getT3sbSettings($fileRepository);

// Custom thumbnail
if ( !empty($this->settings['consent']['thumbnail']) ) {

$relatedCustomThumbnails = $fileRepository->findByRelation('tt_content', 'settings.consent.thumbnail', $currentRecord);
$customThumbnail = !empty($relatedCustomThumbnails[0]) ? $relatedCustomThumbnails[0] : [];
$defaultThumbnail = [];
if ( empty($customThumbnail) ) {
// if media is hidden -> use default
$defaultThumbnail = $fileRepository->findByRelation('tt_content', 'assets', (int) $this->settings['consent']['contentByUid'])[0];
}
}

// Default thumbnail
if ( !empty($this->settings['consent']['defaultThumbnail']) ) {

$relatedDefaultThumbnails = $fileRepository->findByRelation('tt_content', 'assets', (int) $this->settings['consent']['contentByUid']);
if ( !empty($relatedDefaultThumbnails[0]) ) {
$defaultThumbnail = $relatedDefaultThumbnails[0];
$properties = $defaultThumbnail->getOriginalFile()->getProperties();
$extension = $properties['extension'];
$type = $properties['type'];
}

} else {

$defaultThumbnail = [];
}
}

$assignedValues = [
'currentRecord' => $currentRecord,
'contentConsent' => $contentConsent,
'thumbnail' => empty($thumbnails[0]) ? FALSE : $thumbnails[0],
't3sb' => $t3sbSettings,
'extension' => $extension,
'type' => $type,
'customThumbnail' => $customThumbnail,
'defaultThumbnail' => $defaultThumbnail,
'typeNum' => (int) $this->settings['ajaxTypeNum']
];
$this->view->assignMultiple($assignedValues);
Expand Down Expand Up @@ -77,82 +106,11 @@ public function ajaxAction(): ResponseInterface
$conf ['dontCheckPid'] = 1;

$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);

$data = $cObj->cObjGetSingle('RECORDS', $conf);

return $this->responseFactory->createResponse()
->withHeader('Content-Type', 'application/json')
->withBody($this->streamFactory->createStream($data));
}



/**
* Returns settings from EXT:t3sbootstrap if loaded
*
* @param FileRepository $fileRepository
*
* @return array
*/
private function getT3sbSettings($fileRepository): array
{
$contentByUid = (int) $this->settings['consent']['contentByUid'];
$t3sbSettings = ['image'=>FALSE];
$content = self::getData($contentByUid);

if ($content['image_zoom'] && ( $content['assets'] || $content['image'])) {
$extconf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('t3sbootstrap');
$typoscript = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT,'t3sbootstrap');
$lazyLoad = empty($extconf['lazyLoad']) ? FALSE : TRUE;
$cdn = $typoscript['module.']['tx_t3sbootstrap.']['settings.']['cdn.']['enable'];
$lightboxSelection = (int) GeneralUtility::makeInstance(ConfigRepository::class)->findAll()[0]->getLightboxSelection();
if (empty($lightboxSelection)) {
$lightboxSelection = 0;
} else {
if ($lightboxSelection == 1) {
$lightboxVersion = $typoscript['module.']['tx_t3sbootstrap.']['settings.']['cdn.']['baguetteBox'];
}
if ($lightboxSelection == 2) {
$lightboxVersion = $typoscript['module.']['tx_t3sbootstrap.']['settings.']['cdn.']['halkabox'];
}
if ($lightboxSelection == 3) {
$lightboxVersion = $typoscript['module.']['tx_t3sbootstrap.']['settings.']['cdn.']['glightbox'];
}
}

$t3sbSettings = [
'image'=>TRUE,
'lazyLoad'=>$lazyLoad,
'cdn'=>$cdn,
'lightboxSelection'=>$lightboxSelection,
'lightboxVersion'=>$lightboxVersion
];
}

return $t3sbSettings;
}



/**
* Returns data from tt_content
*
* @param int $contentByUid
*
* @return array
*/
public function getData($contentByUid): array
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$result = $queryBuilder
->select('image_zoom', 'assets', 'image')
->from('tt_content')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($contentByUid, \PDO::PARAM_INT))
)
->executeQuery();

return $result->fetchAssociative();
}

}
26 changes: 19 additions & 7 deletions Configuration/FlexForms/Consent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,27 @@
<renderType>selectSingle</renderType>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0">LLL:EXT:t3sbootstrap/Resources/Private/Language/locallang_be.xlf:secondary</numIndex>
<numIndex index="0">Secondary</numIndex>
<numIndex index="1">secondary</numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">LLL:EXT:t3sbootstrap/Resources/Private/Language/locallang_be.xlf:primary</numIndex>
<numIndex index="0">Primary</numIndex>
<numIndex index="1">primary</numIndex>
</numIndex>
<numIndex index="2" type="array">
<numIndex index="0">LLL:EXT:t3sbootstrap/Resources/Private/Language/locallang_be.xlf:success</numIndex>
<numIndex index="0">Success</numIndex>
<numIndex index="1">success</numIndex>
</numIndex>
<numIndex index="3" type="array">
<numIndex index="0">LLL:EXT:t3sbootstrap/Resources/Private/Language/locallang_be.xlf:info</numIndex>
<numIndex index="0">Info</numIndex>
<numIndex index="1">info</numIndex>
</numIndex>
<numIndex index="4" type="array">
<numIndex index="0">LLL:EXT:t3sbootstrap/Resources/Private/Language/locallang_be.xlf:warning</numIndex>
<numIndex index="0">Warning</numIndex>
<numIndex index="1">warning</numIndex>
</numIndex>
<numIndex index="5" type="array">
<numIndex index="0">LLL:EXT:t3sbootstrap/Resources/Private/Language/locallang_be.xlf:danger</numIndex>
<numIndex index="0">Danger</numIndex>
<numIndex index="1">danger</numIndex>
</numIndex>
<numIndex index="6" type="array">
Expand All @@ -94,7 +94,7 @@
<numIndex index="1">light</numIndex>
</numIndex>
<numIndex index="8" type="array">
<numIndex index="0">LLL:EXT:t3sbootstrap/Resources/Private/Language/locallang_be.xlf:link</numIndex>
<numIndex index="0">Link</numIndex>
<numIndex index="1">link</numIndex>
</numIndex>
</items>
Expand Down Expand Up @@ -125,11 +125,23 @@
</TCEforms>
</settings.consent.cookie>

<settings.consent.defaultThumbnail>
<TCEforms>
<label>Default thumbnail from YouTube, Vimeo or Content Element</label>
<description>only if "Thumbnail" is not set</description>
<config>
<type>check</type>
<default>1</default>
</config>
</TCEforms>
</settings.consent.defaultThumbnail>

<settings.consent.thumbnail>
<TCEforms>
<label>Thumbnail (background-image)</label>
<config>
<type>inline</type>
<maxitems>1</maxitems>
<foreign_table>sys_file_reference</foreign_table>
<foreign_field>uid_foreign</foreign_field>
<foreign_sortby>sorting_foreign</foreign_sortby>
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Introduction/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Introduction
What does it do?
================

Similar to Google Maps, embedding YouTube videos in your own website is not entirely unproblematic. This is because embedding establishes various connections to Google servers, through which several cookies are stored in the user's browser and information about them is sent to YouTube and Google's DoubleClick advertising service.
Similar to Google Maps, embedding YouTube- or Vimeo videos in your own website is not entirely unproblematic. This is because embedding establishes various connections to Google servers, through which several cookies are stored in the user's browser and information about them is sent to YouTube and Google's DoubleClick advertising service.

With this extension you can reload any content element and plugin via Ajax. The JS-Framework jQuery is not needed!
So you can embed e.g. YouTube videos or Google Maps DSGVO compliant and give the user the possibility to load this content.
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Monthly Downloads](https://poser.pugx.org/t3s/content_consent/d/monthly)](https://packagist.org/packages/t3s/content_consent)
[![License](https://poser.pugx.org/t3s/content_consent/license)](https://packagist.org/packages/t3s/content_consent)

> Provides a content consent plugin to load any content elements and custom plugins by ajax without jQuery! So you can include Google Maps or YouTube videos GDPR/DSGVO compliant. Best used with Bootstrap 5.
> Provides a content consent plugin to load any content elements and custom plugins by ajax without jQuery! So you can include Google Maps, YouTube- or Vimeo videos GDPR/DSGVO compliant. Best used with Bootstrap 5.
## 1. Usage

Expand All @@ -14,7 +14,8 @@

#### Installation using Composer

The recommended way to install the extension is by using Composer. In your Composer based TYPO3 project root, just do `composer require t3s/content-consent`.
The recommended way to install the extension is by using Composer.
In your Composer based TYPO3 project root, just do `composer require t3s/content-consent`.

#### Installation as extension from TYPO3 Extension Repository (TER)

Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Layouts/Default.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div class="tx-content-consent d-flex">
<div class="tx-content-consent">
<f:render section="content" />
</div>
</html>
Loading

0 comments on commit 286f432

Please sign in to comment.