first commit

This commit is contained in:
salam committed 2026-10-19 08:18:39 +02:00
commit 1218dd1517
12716 files changed
+989233

No files matched your search

@@ -0,0 +1,92 @@
<?php
namespace TYPO3\CMS\Extbase\Service;
/*
* 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!
*/
/**
* Cache clearing helper functions
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
class CacheService implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* @var \SplStack
*/
protected $pageIdStack;
/**
* @var \TYPO3\CMS\Core\Cache\CacheManager
*/
protected $cacheManager;
/**
* @param \TYPO3\CMS\Core\Cache\CacheManager $cacheManager
*/
public function injectCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
{
$this->cacheManager = $cacheManager;
}
/**
* Initializes the pageIdStack
*/
public function __construct()
{
$this->pageIdStack = new \SplStack;
}
/**
* @return \SplStack
*/
public function getPageIdStack()
{
return $this->pageIdStack;
}
/**
* Clears the page cache
*
* @param mixed $pageIdsToClear (int) single or (array) multiple pageIds to clear the cache for
*/
public function clearPageCache($pageIdsToClear = null)
{
if ($pageIdsToClear === null) {
$this->cacheManager->flushCachesInGroup('pages');
} else {
if (!is_array($pageIdsToClear)) {
$pageIdsToClear = [(int)$pageIdsToClear];
}
$tags = array_map(function ($item) {
return 'pageId_' . $item;
}, $pageIdsToClear);
$this->cacheManager->flushCachesInGroupByTags('pages', $tags);
}
}
/**
* Walks through the pageIdStack, collects all pageIds
* as array and passes them on to clearPageCache.
*/
public function clearCachesOfRegisteredPageIds()
{
if (!$this->pageIdStack->isEmpty()) {
$pageIds = [];
while (!$this->pageIdStack->isEmpty()) {
$pageIds[] = (int)$this->pageIdStack->pop();
}
$pageIds = array_values(array_unique($pageIds));
$this->clearPageCache($pageIds);
}
}
}
@@ -0,0 +1,65 @@
<?php
namespace TYPO3\CMS\Extbase\Service;
/*
* 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!
*/
use TYPO3\CMS\Core\Core\Environment;
/**
* Service for determining environment params
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
class EnvironmentService implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* Detects if TYPO3_MODE is defined and its value is "FE"
*
* @return bool
*/
public function isEnvironmentInFrontendMode()
{
return (defined('TYPO3_MODE') && TYPO3_MODE === 'FE') ?: false;
}
/**
* Detects if TYPO3_MODE is defined and its value is "BE"
*
* @return bool
*/
public function isEnvironmentInBackendMode()
{
return (defined('TYPO3_MODE') && TYPO3_MODE === 'BE') ?: false;
}
/**
* Detects if we are running a script from the command line.
*
* @return bool
* @deprecated since TYPO3 v9.4 and will be removed in TYPO3 v10.0
* @see Environment::isCli()
*/
public function isEnvironmentInCliMode()
{
trigger_error('EnvironmentService::isEnvironmentInCliMode will be removed in TYPO3 v10.0. Use Environment::isCli() instead.', E_USER_DEPRECATED);
return Environment::isCli();
}
/**
* @return string
*/
public function getServerRequestMethod()
{
return isset($_SERVER['REQUEST_METHOD']) && is_string($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
}
}
@@ -0,0 +1,252 @@
<?php
namespace TYPO3\CMS\Extbase\Service;
/*
* 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!
*/
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
/**
* Service for determining basic extension params
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
class ExtensionService implements \TYPO3\CMS\Core\SingletonInterface
{
const PLUGIN_TYPE_PLUGIN = 'list_type';
const PLUGIN_TYPE_CONTENT_ELEMENT = 'CType';
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
*/
protected $objectManager;
/**
* @var ConfigurationManagerInterface
*/
protected $configurationManager;
/**
* Cache of result for getTargetPidByPlugin()
* @var array
*/
protected $targetPidPluginCache = [];
/**
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
*/
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
}
/**
* @param ConfigurationManagerInterface $configurationManager
*/
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
{
$this->configurationManager = $configurationManager;
}
/**
* Determines the plugin namespace of the specified plugin (defaults to "tx_[extensionname]_[pluginname]")
* If plugin.tx_$pluginSignature.view.pluginNamespace is set, this value is returned
* If pluginNamespace is not specified "tx_[extensionname]_[pluginname]" is returned.
*
* @param string $extensionName name of the extension to retrieve the namespace for
* @param string $pluginName name of the plugin to retrieve the namespace for
* @return string plugin namespace
*/
public function getPluginNamespace($extensionName, $pluginName)
{
$pluginSignature = strtolower($extensionName . '_' . $pluginName);
$defaultPluginNamespace = 'tx_' . $pluginSignature;
$frameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
if (!isset($frameworkConfiguration['view']['pluginNamespace']) || empty($frameworkConfiguration['view']['pluginNamespace'])) {
return $defaultPluginNamespace;
}
return $frameworkConfiguration['view']['pluginNamespace'];
}
/**
* Iterates through the global TypoScript configuration and returns the name of the plugin
* that matches specified extensionName, controllerName and actionName.
* If no matching plugin was found, NULL is returned.
* If more than one plugin matches and the current plugin is not configured to handle the action,
* an Exception will be thrown
*
* @param string $extensionName name of the target extension (UpperCamelCase)
* @param string $controllerName name of the target controller (UpperCamelCase)
* @param string $actionName name of the target action (lowerCamelCase)
* @throws \TYPO3\CMS\Extbase\Exception
* @return string name of the target plugin (UpperCamelCase) or NULL if no matching plugin configuration was found
*/
public function getPluginNameByAction($extensionName, $controllerName, $actionName)
{
$frameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
// check, whether the current plugin is configured to handle the action
if (!empty($frameworkConfiguration['extensionName']) && $extensionName === $frameworkConfiguration['extensionName']) {
if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]) && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['actions'])) {
return $frameworkConfiguration['pluginName'];
}
}
$plugins = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'] ?? false;
if (!$plugins) {
return null;
}
$pluginNames = [];
foreach ($plugins as $pluginName => $pluginConfiguration) {
foreach ($pluginConfiguration['controllers'] ?? [] as $pluginControllerName => $pluginControllerActions) {
if (strtolower($pluginControllerName) !== strtolower($controllerName)) {
continue;
}
if (in_array($actionName, $pluginControllerActions['actions'])) {
$pluginNames[] = $pluginName;
}
}
}
if (count($pluginNames) > 1) {
throw new \TYPO3\CMS\Extbase\Exception('There is more than one plugin that can handle this request (Extension: "' . $extensionName . '", Controller: "' . $controllerName . '", action: "' . $actionName . '"). Please specify "pluginName" argument', 1280825466);
}
return !empty($pluginNames) ? $pluginNames[0] : null;
}
/**
* Checks if the given action is cacheable or not.
*
* @param string $extensionName Name of the target extension, without underscores
* @param string $pluginName Name of the target plugin
* @param string $controllerName Name of the target controller
* @param string $actionName Name of the action to be called
* @return bool TRUE if the specified plugin action is cacheable, otherwise FALSE
*/
public function isActionCacheable($extensionName, $pluginName, $controllerName, $actionName)
{
$frameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]) && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]) && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions']) && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])) {
return false;
}
return true;
}
/**
* Determines the target page of the specified plugin.
* If plugin.tx_$pluginSignature.view.defaultPid is set, this value is used as target page id
* If defaultPid is set to "auto", a the target pid is determined by loading the tt_content record that contains this plugin
* If the page could not be determined, NULL is returned
* If defaultPid is "auto" and more than one page contains the specified plugin, an Exception is thrown
*
* @param string $extensionName name of the extension to retrieve the target PID for
* @param string $pluginName name of the plugin to retrieve the target PID for
* @throws \TYPO3\CMS\Extbase\Exception
* @return int uid of the target page or NULL if target page could not be determined
*/
public function getTargetPidByPlugin($extensionName, $pluginName)
{
$frameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
if (!isset($frameworkConfiguration['view']['defaultPid']) || empty($frameworkConfiguration['view']['defaultPid'])) {
return null;
}
$pluginSignature = strtolower($extensionName . '_' . $pluginName);
if ($frameworkConfiguration['view']['defaultPid'] === 'auto') {
if (!array_key_exists($pluginSignature, $this->targetPidPluginCache)) {
$languageId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'id', 0);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tt_content');
$queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
$pages = $queryBuilder
->select('pid')
->from('tt_content')
->where(
$queryBuilder->expr()->eq(
'list_type',
$queryBuilder->createNamedParameter($pluginSignature, \PDO::PARAM_STR)
),
$queryBuilder->expr()->eq(
'CType',
$queryBuilder->createNamedParameter('list', \PDO::PARAM_STR)
),
$queryBuilder->expr()->eq(
'sys_language_uid',
$queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
)
)
->setMaxResults(2)
->execute()
->fetchAll();
if (count($pages) > 1) {
throw new \TYPO3\CMS\Extbase\Exception('There is more than one "' . $pluginSignature . '" plugin in the current page tree. Please remove one plugin or set the TypoScript configuration "plugin.tx_' . $pluginSignature . '.view.defaultPid" to a fixed page id', 1280773643);
}
$this->targetPidPluginCache[$pluginSignature] = !empty($pages) ? $pages[0]['pid'] : null;
}
return $this->targetPidPluginCache[$pluginSignature];
}
return (int)$frameworkConfiguration['view']['defaultPid'];
}
/**
* This returns the name of the first controller of the given plugin.
*
* @param string $extensionName name of the extension to retrieve the target PID for
* @param string $pluginName name of the plugin to retrieve the target PID for
* @return string|null
*/
public function getDefaultControllerNameByPlugin($extensionName, $pluginName)
{
$controllers = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'] ?? false;
return $controllers ? key($controllers) : null;
}
/**
* This returns the name of the first action of the given plugin controller.
*
* @param string $extensionName name of the extension to retrieve the target PID for
* @param string $pluginName name of the plugin to retrieve the target PID for
* @param string $controllerName name of the controller to retrieve default action for
* @return string|null
*/
public function getDefaultActionNameByPluginAndController($extensionName, $pluginName, $controllerName)
{
$actions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'] ?? false;
return $actions ? current($actions) : null;
}
/**
* Resolve the page type number to use for building a link for a specific format
*
* @param string $extensionName name of the extension that has defined the target page type
* @param string $format The format for which to look up the page type
* @return int Page type number for target page
*/
public function getTargetPageTypeByFormat($extensionName, $format)
{
// Legacy location
$settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $extensionName);
if (isset($settings['view']['formatToPageTypeMapping']) && is_array($settings['view']['formatToPageTypeMapping'])) {
trigger_error('Extension "' . $extensionName . '": Defining settings.view.formatToPageTypeMapping will be removed in TYPO3 10. Move definition to view.formatToPageTypeMapping.', E_USER_DEPRECATED);
$formatToPageTypeMapping = $settings['view']['formatToPageTypeMapping'];
}
// Default behaviour
$settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName);
if (isset($settings['view']['formatToPageTypeMapping']) && is_array($settings['view']['formatToPageTypeMapping'])) {
ArrayUtility::mergeRecursiveWithOverrule($formatToPageTypeMapping, $settings['view']['formatToPageTypeMapping']);
}
return $formatToPageTypeMapping[$format] ?? 0;
}
}
@@ -0,0 +1,202 @@
<?php
namespace TYPO3\CMS\Extbase\Service;
/*
* 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!
*/
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
/**
* Service for processing images
*/
class ImageService implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* @var ResourceFactory
*/
protected $resourceFactory;
/**
* @var EnvironmentService
*/
protected $environmentService;
/**
* ImageService constructor.
*
* @param EnvironmentService|null $environmentService
* @param ResourceFactory|null $resourceFactory
*/
public function __construct(EnvironmentService $environmentService = null, ResourceFactory $resourceFactory = null)
{
$this->environmentService = $environmentService ?? GeneralUtility::makeInstance(EnvironmentService::class);
$this->resourceFactory = $resourceFactory ?? ResourceFactory::getInstance();
}
/**
* Create a processed file
*
* @param FileInterface|FileReference $image
* @param array $processingInstructions
* @return ProcessedFile
*/
public function applyProcessingInstructions($image, $processingInstructions)
{
if (is_callable([$image, 'getOriginalFile'])) {
// Get the original file from the file reference
$image = $image->getOriginalFile();
}
$processedImage = $image->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingInstructions);
$this->setCompatibilityValues($processedImage);
return $processedImage;
}
/**
* Get public url of image depending on the environment
*
* @param FileInterface $image
* @param bool|false $absolute Force absolute URL
* @return string
*/
public function getImageUri(FileInterface $image, $absolute = false)
{
$imageUrl = $image->getPublicUrl();
$parsedUrl = parse_url($imageUrl);
// no prefix in case of an already fully qualified URL
if (isset($parsedUrl['host'])) {
$uriPrefix = '';
} elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
$uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
} else {
$uriPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
}
if ($absolute) {
// If full URL has no scheme we add the same scheme as used by the site
// so we have an absolute URL also usable outside of browser scope (e.g. in an email message)
if (isset($parsedUrl['host']) && !isset($parsedUrl['scheme'])) {
$uriPrefix = (GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https:' : 'http:') . $uriPrefix;
}
return GeneralUtility::locationHeaderUrl($uriPrefix . $imageUrl);
}
return $uriPrefix . $imageUrl;
}
/**
* Get File or FileReference object
*
* This method is a factory and compatibility method that does not belong to
* this service, but is put here for pragmatic reasons for the time being.
* It should be removed once we do not support string sources for images anymore.
*
* @param string $src
* @param mixed $image
* @param bool $treatIdAsReference
* @return FileInterface|FileReference
* @throws \UnexpectedValueException
* @internal
*/
public function getImage($src, $image, $treatIdAsReference)
{
if ($image === null) {
$image = $this->getImageFromSourceString($src, $treatIdAsReference);
} elseif (is_callable([$image, 'getOriginalResource'])) {
// We have a domain model, so we need to fetch the FAL resource object from there
$image = $image->getOriginalResource();
}
if (!($image instanceof File || $image instanceof FileReference)) {
$class = is_object($image) ? get_class($image) : 'null';
throw new \UnexpectedValueException('Supplied file object type ' . $class . ' for ' . $src . ' must be File or FileReference.', 1382687163);
}
return $image;
}
/**
* Get File or FileReference object by src
*
* @param string $src
* @param bool $treatIdAsReference
* @return FileInterface|FileReference|\TYPO3\CMS\Core\Resource\Folder
*/
protected function getImageFromSourceString($src, $treatIdAsReference)
{
if ($this->environmentService->isEnvironmentInBackendMode() && strpos($src, '../') === 0) {
$src = substr($src, 3);
}
if (MathUtility::canBeInterpretedAsInteger($src)) {
if ($treatIdAsReference) {
$image = $this->resourceFactory->getFileReferenceObject($src);
} else {
$image = $this->resourceFactory->getFileObject($src);
}
} elseif (strpos($src, 't3://file') === 0) {
// We have a t3://file link to a file in FAL
$linkService = GeneralUtility::makeInstance(LinkService::class);
$data = $linkService->resolveByStringRepresentation($src);
$image = $data['file'];
} else {
// We have a combined identifier or legacy (storage 0) path
$image = $this->resourceFactory->retrieveFileOrFolderObject($src);
}
return $image;
}
/**
* Set compatibility values to frontend controller object
* in case we are in frontend environment.
*
* @param ProcessedFile $processedImage
*/
protected function setCompatibilityValues(ProcessedFile $processedImage)
{
if ($this->environmentService->isEnvironmentInFrontendMode()) {
$GLOBALS['TSFE']->lastImageInfo = $this->getCompatibilityImageResourceValues($processedImage);
$GLOBALS['TSFE']->imagesOnPage[] = $processedImage->getPublicUrl();
}
}
/**
* Calculates the compatibility values
* This is duplicate code taken from ContentObjectRenderer::getImgResource()
* Ideally we should get rid of this code in both places.
*
* @param ProcessedFile $processedImage
* @return array
*/
protected function getCompatibilityImageResourceValues(ProcessedFile $processedImage)
{
return [
0 => $processedImage->getProperty('width'),
1 => $processedImage->getProperty('height'),
2 => $processedImage->getExtension(),
3 => $processedImage->getPublicUrl(),
'origFile' => $processedImage->getOriginalFile()->getPublicUrl(),
'origFile_mtime' => $processedImage->getOriginalFile()->getModificationTime(),
// This is needed by \TYPO3\CMS\Frontend\Imaging\GifBuilder,
// in order for the setup-array to create a unique filename hash.
'originalFile' => $processedImage->getOriginalFile(),
'processedFile' => $processedImage
];
}
}