first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package bk2k/bootstrap-package.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace BK2K\BootstrapPackage\DataProcessing;
|
||||
|
||||
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
|
||||
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
||||
|
||||
/**
|
||||
* Minimal TypoScript configuration
|
||||
* Assign all available typoscript constants for a key to template view, the
|
||||
* default key that is used is `page` and the default variable is `constants`.
|
||||
*
|
||||
* 10 = BK2K\BootstrapPackage\DataProcessing\ConstantsProcessor
|
||||
*
|
||||
*
|
||||
* Advanced TypoScript configuration
|
||||
*
|
||||
* 10 = BK2K\BootstrapPackage\DataProcessing\ConstantsProcessor
|
||||
* 10 {
|
||||
* key = page
|
||||
* as = constants
|
||||
* }
|
||||
*/
|
||||
class ConstantsProcessor implements DataProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @param ContentObjectRenderer $cObj The data of the content element or page
|
||||
* @param array $contentObjectConfiguration The configuration of Content Object
|
||||
* @param array $processorConfiguration The configuration of this processor
|
||||
* @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
|
||||
* @return array the processed data as key/value store
|
||||
*/
|
||||
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
|
||||
{
|
||||
// The key to process
|
||||
$key = $cObj->stdWrapValue('key', $processorConfiguration);
|
||||
if (empty($key)) {
|
||||
$key = 'page';
|
||||
}
|
||||
|
||||
// Collect variables
|
||||
$flatConstants = $this->getFlatConstants($key);
|
||||
$typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class);
|
||||
$typoScriptParser->parse($flatConstants);
|
||||
$typoScriptArray = $typoScriptParser->setup;
|
||||
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
|
||||
$constants = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptArray);
|
||||
|
||||
// Set the target variable
|
||||
$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration);
|
||||
if (!empty($targetVariableName)) {
|
||||
$processedData[$targetVariableName] = $constants;
|
||||
} else {
|
||||
$processedData['constants'] = $constants;
|
||||
}
|
||||
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function getFlatConstants($key)
|
||||
{
|
||||
$flatvariables = '';
|
||||
$prefix = $key . '.';
|
||||
if ($GLOBALS['TSFE']->tmpl->flatSetup === null
|
||||
|| !is_array($GLOBALS['TSFE']->tmpl->flatSetup)
|
||||
|| count($GLOBALS['TSFE']->tmpl->flatSetup) === 0) {
|
||||
$GLOBALS['TSFE']->tmpl->generateConfig();
|
||||
}
|
||||
foreach ($GLOBALS['TSFE']->tmpl->flatSetup as $constant => $value) {
|
||||
if (strpos($constant, $prefix) === 0) {
|
||||
$flatvariables .= substr($constant, strlen($prefix)) . ' = ' . $value . PHP_EOL;
|
||||
}
|
||||
}
|
||||
return $flatvariables;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package bk2k/bootstrap-package.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace BK2K\BootstrapPackage\DataProcessing;
|
||||
|
||||
use TYPO3\CMS\Core\Resource\File;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Resource\ProcessedFile;
|
||||
use TYPO3\CMS\Core\Utility\CsvUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\DataProcessing\FilesProcessor;
|
||||
|
||||
/**
|
||||
* CsvFileProcessor
|
||||
*/
|
||||
class CsvFileProcessor extends FilesProcessor
|
||||
{
|
||||
/**
|
||||
* @param ContentObjectRenderer $cObj The data of the content element or page
|
||||
* @param array $contentObjectConfiguration The configuration of Content Object
|
||||
* @param array $processorConfiguration The configuration of this processor
|
||||
* @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
|
||||
* @return array the processed data as key/value store
|
||||
*/
|
||||
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
|
||||
{
|
||||
// Set the maximum amount of columns
|
||||
$maximumColumns = $cObj->stdWrapValue('maximumColumns', $processorConfiguration, 0);
|
||||
|
||||
// Set the field delimiter which is "," by default
|
||||
$fieldDelimiter = $cObj->stdWrapValue('fieldDelimiter', $processorConfiguration, ',');
|
||||
|
||||
// Set the field enclosure which is " by default
|
||||
$fieldEnclosure = $cObj->stdWrapValue('fieldEnclosure', $processorConfiguration, '"');
|
||||
|
||||
// Get processed files
|
||||
$processedData = parent::process($cObj, $contentObjectConfiguration, $processorConfiguration, $processedData);
|
||||
$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'files');
|
||||
$files = $processedData[$targetVariableName];
|
||||
unset($processedData[$targetVariableName]);
|
||||
|
||||
foreach ($files as $key => $value) {
|
||||
if (is_object($value) && in_array(get_class($value), [FileReference::class, File::class], true)) {
|
||||
/** @var ProcessedFile $value */
|
||||
if ($value->getExtension() !== 'csv') {
|
||||
unset($files[$key]);
|
||||
} else {
|
||||
$originalFile = $value->getOriginalFile();
|
||||
$content = $originalFile->getContents();
|
||||
$files[$key] = [
|
||||
'file' => $value,
|
||||
'bodytext' => $content,
|
||||
'table' => CsvUtility::csvToArray(
|
||||
$content,
|
||||
$fieldDelimiter,
|
||||
$fieldEnclosure,
|
||||
(int)$maximumColumns
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$files = array_values(array_filter($files));
|
||||
$processedData[$targetVariableName] = $files;
|
||||
|
||||
return $processedData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package bk2k/bootstrap-package.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace BK2K\BootstrapPackage\DataProcessing;
|
||||
|
||||
use TYPO3\CMS\Core\Resource\File;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
||||
|
||||
/**
|
||||
* File Filter Processor
|
||||
* The DataProcessor requires a prepared array with Files or FilesReferences.
|
||||
* This required array is usually generated by the FilesProcessor so it must be
|
||||
* called first.
|
||||
*
|
||||
* Please note that the output variable name of the FilesProcessor
|
||||
* must be provided to the FileFilterProcessor.
|
||||
*
|
||||
*
|
||||
* Options:
|
||||
* variableName - Resultset to work on
|
||||
* predefinedList - Can be 'image', 'media' or 'text', will reference the
|
||||
* global TYPO3 settings for that file type, for example:
|
||||
* ['GFX']['imagefile_ext'] or ['SYS']['mediafile_ext']
|
||||
* allowedFileExtensions - List of allowed file extensions,
|
||||
* if set predefinedList will be overridden
|
||||
*
|
||||
*
|
||||
* Basic Example:
|
||||
* 10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
|
||||
* 10 {
|
||||
* references.fieldName = image
|
||||
* folders.field = image_folder
|
||||
* sorting.field = filelink_sorting
|
||||
* as = files
|
||||
* }
|
||||
* 20 = BK2K\BootstrapPackage\DataProcessing\FileFilterProcessor
|
||||
* 20 {
|
||||
* variableName = files
|
||||
* predefinedList = image
|
||||
* }
|
||||
*
|
||||
*
|
||||
* Advanced Example:
|
||||
* 10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
|
||||
* 10 {
|
||||
* references.fieldName = image
|
||||
* }
|
||||
* 20 = BK2K\BootstrapPackage\DataProcessing\FileFilterProcessor
|
||||
* 20 {
|
||||
* allowedFileExtensions = jpg, jpeg, gif
|
||||
* }
|
||||
*/
|
||||
class FileFilterProcessor implements DataProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @param ContentObjectRenderer $cObj The data of the content element or page
|
||||
* @param array $contentObjectConfiguration The configuration of Content Object
|
||||
* @param array $processorConfiguration The configuration of this processor
|
||||
* @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
|
||||
* @return array the processed data as key/value store
|
||||
*/
|
||||
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
|
||||
{
|
||||
$confVars = $GLOBALS['TYPO3_CONF_VARS'];
|
||||
$predefinedLists = [
|
||||
'image' => isset($confVars['GFX']['imagefile_ext']) ? $confVars['GFX']['imagefile_ext'] : 'gif,jpg,jpeg,tif,tiff,bmp,pcx,tga,png,pdf,ai,svg',
|
||||
'media' => isset($confVars['SYS']['mediafile_ext']) ? $confVars['SYS']['mediafile_ext'] : 'gif,jpg,jpeg,bmp,png,pdf,svg,ai,mp3,wav,mp4,ogg,flac,opus,webm,youtube,vimeo',
|
||||
'text' => isset($confVars['SYS']['textfile_ext']) ? $confVars['SYS']['textfile_ext'] : 'txt,ts,typoscript,html,htm,css,tmpl,js,sql,xml,csv,xlf,yaml,yml',
|
||||
];
|
||||
$predefinedList = $cObj->stdWrapValue('predefinedList', $processorConfiguration, 'image');
|
||||
$allowedFileExtensions = array_key_exists($predefinedList, $predefinedLists) ? $predefinedLists[$predefinedList] : '';
|
||||
$allowedFileExtensions = GeneralUtility::trimExplode(',', $cObj->stdWrapValue('allowedFileExtensions', $processorConfiguration, $allowedFileExtensions));
|
||||
if (empty($allowedFileExtensions)) {
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
$variableName = $cObj->stdWrapValue('variableName', $processorConfiguration, 'files');
|
||||
if (!isset($processedData[$variableName]) || empty($processedData[$variableName])) {
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
foreach ($processedData[$variableName] as $key => $value) {
|
||||
if (is_object($value)
|
||||
&& in_array(get_class($value), [FileReference::class, File::class], true)
|
||||
&& !in_array($value->getExtension(), $allowedFileExtensions, true)
|
||||
) {
|
||||
unset($processedData[$variableName][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $processedData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
/*
|
||||
* This file is part of the package bk2k/bootstrap-package.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace BK2K\BootstrapPackage\DataProcessing;
|
||||
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
||||
|
||||
/**
|
||||
* Minimal TypoScript configuration
|
||||
* Process field pi_flexform and overrides the values stored in data
|
||||
*
|
||||
* 10 = BK2K\BootstrapPackage\DataProcessing\FlexFormProcessor
|
||||
*
|
||||
*
|
||||
* Advanced TypoScript configuration
|
||||
* Process field assigned in fieldName and stores processed data to new key
|
||||
*
|
||||
* 10 = BK2K\BootstrapPackage\DataProcessing\FlexFormProcessor
|
||||
* 10 {
|
||||
* fieldName = pi_flexform
|
||||
* as = flexform
|
||||
* }
|
||||
*/
|
||||
class FlexFormProcessor implements DataProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @var FlexFormService
|
||||
*/
|
||||
protected $flexFormService;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContentObjectRenderer $cObj The data of the content element or page
|
||||
* @param array $contentObjectConfiguration The configuration of Content Object
|
||||
* @param array $processorConfiguration The configuration of this processor
|
||||
* @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
|
||||
* @return array the processed data as key/value store
|
||||
*/
|
||||
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
|
||||
{
|
||||
// The field name to process
|
||||
$fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration);
|
||||
if (empty($fieldName)) {
|
||||
$fieldName = 'pi_flexform';
|
||||
}
|
||||
if (!$processedData['data'][$fieldName]) {
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
// Process Flexform
|
||||
$originalValue = $processedData['data'][$fieldName];
|
||||
if (!is_string($originalValue)) {
|
||||
return $processedData;
|
||||
}
|
||||
$flexformData = $this->flexFormService->convertFlexFormContentToArray($originalValue);
|
||||
|
||||
// Set the target variable
|
||||
$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration);
|
||||
if (!empty($targetVariableName)) {
|
||||
$processedData[$targetVariableName] = $flexformData;
|
||||
} else {
|
||||
$processedData['data'][$fieldName] = $flexformData;
|
||||
}
|
||||
|
||||
return $processedData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package bk2k/bootstrap-package.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace BK2K\BootstrapPackage\DataProcessing;
|
||||
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
||||
|
||||
/**
|
||||
* This processor generates a set of file objects.
|
||||
*
|
||||
* 10 = BK2K\BootstrapPackage\DataProcessing\StaticFilesProcessor
|
||||
* 10 {
|
||||
* files {
|
||||
* 0.field = image
|
||||
* 1 = EXT:bootstrap_package/Resources/Public/Images/Icons/icon-1.png
|
||||
* circle = EXT:bootstrap_package/Resources/Public/Images/Icons/icon-circle.png
|
||||
* }
|
||||
* as = staticFiles
|
||||
* }
|
||||
*/
|
||||
class StaticFilesProcessor implements DataProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @param ContentObjectRenderer $cObj The data of the content element or page
|
||||
* @param array $contentObjectConfiguration The configuration of Content Object
|
||||
* @param array $processorConfiguration The configuration of this processor
|
||||
* @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
|
||||
* @return array the processed data as key/value store
|
||||
*/
|
||||
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
|
||||
{
|
||||
if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
// Collect possible files
|
||||
$files = [];
|
||||
if (!empty($processorConfiguration['files.'])) {
|
||||
$filesConfiguration = $processorConfiguration['files.'];
|
||||
foreach ($filesConfiguration as $key => $file) {
|
||||
$key = substr($key, -1) === '.' ? substr_replace($key, '', -1) : $key;
|
||||
$value = $cObj->stdWrapValue($key, $filesConfiguration);
|
||||
if (!empty($value)) {
|
||||
$files[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get file objects
|
||||
$images = [];
|
||||
if (!empty($files)) {
|
||||
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
|
||||
foreach ($files as $key => $file) {
|
||||
$absFilename = GeneralUtility::getFileAbsFileName($file);
|
||||
if (file_exists($absFilename)) {
|
||||
$images[$key] = $resourceFactory->retrieveFileOrFolderObject($absFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the target variable
|
||||
$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration);
|
||||
if (!empty($targetVariableName)) {
|
||||
$processedData[$targetVariableName] = $images;
|
||||
} else {
|
||||
$processedData['staticFiles'] = $images;
|
||||
}
|
||||
|
||||
return $processedData;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user