first commit

This commit is contained in:
salam committed 2026-10-06 19:40:28 +02:00
commit e81864e683
2984 files changed
+267797

No files matched your search

@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\DataProcessor;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* Class AbstractDataProcessor
*/
abstract class AbstractDataProcessor implements DataProcessorInterface
{
/**
* @var array
*/
protected $configuration = [];
/**
* @var array
*/
protected $settings = [];
/**
* @var ContentObjectRenderer|null
*/
protected $contentObject;
/**
* @var Arguments|null
*/
protected $controllerArguments;
/**
* AbstractDataProcessor constructor.
*
* @param array $configuration
* @param array $settings
* @param ContentObjectRenderer $contentObject
* @param Arguments $controllerArguments
*/
public function __construct(
array $configuration,
array $settings,
ContentObjectRenderer $contentObject,
Arguments $controllerArguments
) {
$this->configuration = $configuration;
$this->settings = $settings;
$this->contentObject = $contentObject;
$this->controllerArguments = $controllerArguments;
}
public function initializeDataProcessor()
{
}
/**
* @param string $path
* @return mixed
*/
public function getConfiguration(string $path = '')
{
$configuration = $this->configuration;
if (!empty($path)) {
$configuration = ArrayUtility::getValueByPath($configuration, $path, '.');
}
return $configuration;
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\DataProcessor;
/**
* Class CleanUserGroup to clean empty usergroup arguments
*/
class CleanUserGroup extends AbstractDataProcessor
{
/**
* @param array $arguments
* @return array
*/
public function process(array $arguments): array
{
if (is_array($arguments['user']['usergroup'] ?? null) && empty($arguments['user']['usergroup'][0]) && empty($arguments['user']['usergroup'][0]['__identity'])) {
unset($arguments['user']['usergroup'][0]);
}
return $arguments;
}
}
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\DataProcessor;
/**
* Interface DataProcessorInterface
*/
interface DataProcessorInterface
{
public function initializeDataProcessor();
/**
* @param array $arguments
* @return array
*/
public function process(array $arguments): array;
}
@@ -0,0 +1,125 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\DataProcessor;
use In2code\Femanager\Utility\ConfigurationUtility;
use In2code\Femanager\Utility\FrontendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/***************************************************************
* Copyright notice
*
* (c) 2017 Alex Kellner <alexander.kellner@in2code.de>, in2code.de
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project 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.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Class DataProcessorRunner
*/
class DataProcessorRunner
{
/**
* @var ContentObjectRenderer
*/
protected $contentObject;
/**
* TypoScript settings
*
* @var array
*/
protected $settings = [];
/**
* @var string
*/
protected $interface = DataProcessorInterface::class;
/**
* Call classes after submit but before action
*
* @param array $arguments
* @param array $settings
* @param ContentObjectRenderer $contentObject
* @param Arguments $controllerArguments
* @return array
* @throws \Exception
*/
public function callClasses(
array $arguments,
array $settings,
ContentObjectRenderer $contentObject,
Arguments $controllerArguments
): array {
foreach ($this->getClasses($settings) as $configuration) {
$class = $configuration['class'];
if (!class_exists($class)) {
throw new \UnexpectedValueException(
'DataProcessor class ' . $class . ' does not exists - check if file is loaded correctly',
1516373818752
);
}
if (is_subclass_of($class, $this->interface)) {
/** @var AbstractDataProcessor $dataProcessor */
/** @noinspection PhpMethodParametersCountMismatchInspection */
$dataProcessor = GeneralUtility::makeInstance(
$class,
$configuration['config'] ?? [],
$settings,
$contentObject,
$controllerArguments
);
$dataProcessor->initializeDataProcessor();
$arguments = $dataProcessor->process($arguments);
} else {
throw new \UnexpectedValueException('Finisher does not implement ' . $this->interface, 1516373829946);
}
}
return $arguments;
}
/**
* Get all classes to this event from typoscript and sort them
*
* @param array $settings
* @return array
*/
protected function getClasses(array $settings): array
{
$allDataProcessors = ConfigurationUtility::getValue('dataProcessors', $settings);
ksort($allDataProcessors);
$dataProcessors = [];
foreach ($allDataProcessors as $dataProcessor) {
if (isset($dataProcessor['events']) === true && $dataProcessor['events'] !== []) {
foreach ($dataProcessor['events'] as $controllerName => $actionList) {
if ($controllerName === FrontendUtility::getControllerName()) {
if (GeneralUtility::inList($actionList, FrontendUtility::getActionName())) {
$dataProcessors[] = $dataProcessor;
}
}
}
}
}
return $dataProcessors;
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\DataProcessor;
use In2code\Femanager\Utility\LocalizationUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
/**
* Class DateConverter
*/
class DateConverter extends AbstractDataProcessor
{
/**
* @param array $arguments
* @return array
*/
public function process(array $arguments): array
{
if (!empty($this->controllerArguments['user'])) {
foreach (GeneralUtility::trimExplode(',', $this->getConfiguration('fieldNames'), true) as $fieldName) {
$this->controllerArguments['user']
->getPropertyMappingConfiguration()
->forProperty($fieldName)
->setTypeConverterOption(
DateTimeConverter::class,
DateTimeConverter::CONFIGURATION_DATE_FORMAT,
LocalizationUtility::translate('tx_femanager_domain_model_user.dateFormat')
);
}
}
return $arguments;
}
}
@@ -0,0 +1,168 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\DataProcessor;
use In2code\Femanager\Domain\Service\FileService;
use In2code\Femanager\Utility\ConfigurationUtility;
use In2code\Femanager\Utility\FileUtility;
use In2code\Femanager\Utility\FrontendUtility;
use In2code\Femanager\Utility\ObjectUtility;
use In2code\Femanager\Utility\StringUtility;
use TYPO3\CMS\Core\Utility\File\BasicFileUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class ImageManipulation
*/
class ImageManipulation extends AbstractDataProcessor
{
/**
* @param array $arguments
* @return array
*/
public function process(array $arguments): array
{
$this->allowImageProperties();
foreach ($this->getPropertiesForUpload() as $property) {
if ($this->isFileIdentifierGiven($arguments, $property) || $this->isUploadError($arguments, $property)) {
unset($arguments['user'][$property]);
} else {
// Convert property name
$property = lcfirst(GeneralUtility::underscoredToUpperCamelCase($property));
// file upload given
foreach ($arguments['user'][$property] ?? [] as $fileItem) {
/** @noinspection PhpMethodParametersCountMismatchInspection */
$fileService = GeneralUtility::makeInstance(
FileService::class,
$this->getNewImageName($fileItem),
$fileItem
);
if ($fileService->isEverythingValid()) {
FileUtility::createFolderIfNotExists($this->getUploadFolder());
$pathAndFilename = $this->upload($fileItem);
$fileIdentifier = $fileService->indexFile($pathAndFilename);
$identifier = $this->createSysFileRelation($fileIdentifier);
$arguments['user'][$property] = [$identifier];
} else {
unset($arguments['user'][$property]);
}
}
}
}
return $arguments;
}
/**
* @param int $fileIdentifier
* @return int
*/
protected function createSysFileRelation(int $fileIdentifier): int
{
$properties = [
'pid' => FrontendUtility::getCurrentPid(),
'uid_local' => $fileIdentifier,
'tstamp' => time(),
'crdate' => time()
];
foreach ($this->getConfiguration('sysFileRelation') as $field => $value) {
$properties[$field] = $value;
}
$databaseConnectionForPages = ObjectUtility::getConnectionPool()->getConnectionForTable('sys_file_reference');
$databaseConnectionForPages->insert(
'sys_file_reference',
$properties
);
return (int)$databaseConnectionForPages->lastInsertId('sys_file_reference');
}
/**
* @param array $fileItem
* @return string New filename (absolute with path)
* @throws \Exception
*/
protected function upload(array $fileItem): string
{
$basicFileFunctions = GeneralUtility::makeInstance(BasicFileUtility::class);
$uniqueFileName = $basicFileFunctions->getUniqueName(
$this->getNewImageName($fileItem),
$this->getUploadFolder()
);
if (GeneralUtility::upload_copy_move($fileItem['tmp_name'], $uniqueFileName)) {
return $uniqueFileName;
}
throw new \UnexpectedValueException(
'File "' . $this->getNewImageName($fileItem) . '" could not be uploaded!',
1516373841798
);
}
/**
* @return array
*/
protected function getPropertiesForUpload(): array
{
$propertylist = $this->getConfiguration('propertyNamesForUpload');
return GeneralUtility::trimExplode(',', $propertylist, true);
}
/**
* @param array $fileItem
* @return string
*/
protected function getNewImageName(array $fileItem): string
{
$imageName = '';
if (!empty($fileItem['name'])) {
$imageName = $fileItem['name'];
}
$imageName = StringUtility::cleanString($imageName);
return $imageName;
}
/**
* @param bool $absolute
* @return string
*/
protected function getUploadFolder(bool $absolute = true): string
{
$path = (string)ConfigurationUtility::getConfiguration('misc.uploadFolder');
if ($absolute === true) {
$path = GeneralUtility::getFileAbsFileName($path);
}
return $path;
}
protected function allowImageProperties()
{
if (!empty($this->controllerArguments['user'])) {
$this->controllerArguments['user']->getPropertyMappingConfiguration()->forProperty(
'image'
)->allowProperties(0);
}
}
/**
* @param array $arguments
* @param $property
* @return bool
*/
protected function isFileIdentifierGiven(array $arguments, $property): bool
{
return !empty($arguments['user'][$property][0]['__identity']);
}
/**
* @param array $arguments
* @param $property
* @return bool
*/
protected function isUploadError(array $arguments, $property): bool
{
return !empty($arguments['user'][$property][0]['error']);
}
}