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,124 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
class CacheModule extends AbstractModule implements PageSettingsProviderInterface, InitializableInterface, ResourceProviderInterface
{
/**
* @return string
*/
public function getIconIdentifier(): string
{
return 'apps-toolbar-menu-cache';
}
/**
* @return string
*/
public function getPageSettings(): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Settings/Cache.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$feCacheClear = $this->getBackendUser()->isAdmin() || $this->getBackendUser()->getTSConfig()['options.']['clearCache.']['pages'];
$view->assignMultiple(
[
'isEnabled' => $this->getBackendUser()->uc['AdminPanel']['display_cache'],
'noCache' => $this->getBackendUser()->uc['AdminPanel']['cache_noCache'],
'currentId' => $this->getTypoScriptFrontendController()->id,
'clearPageCacheUrl' => $feCacheClear ? (string)$uriBuilder->buildUriFromRoute('tce_db', ['cacheCmd' => 'pages']) : '',
'clearCurrentPageCacheUrl' => (string)$uriBuilder->buildUriFromRoute(
'tce_db',
[
'cacheCmd' => $this->getTypoScriptFrontendController()->id,
]
),
]
);
return $view->render();
}
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'cache';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
$locallangFileAndPath = 'LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:module.label';
return $this->getLanguageService()->sL($locallangFileAndPath);
}
/**
* @inheritdoc
*/
public function initializeModule(ServerRequestInterface $request): void
{
if ($this->configurationService->getConfigurationOption('cache', 'noCache')) {
$this->getTypoScriptFrontendController()->set_no_cache('Admin Panel: No Caching', true);
}
}
/**
* @return TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
/**
* @return array
*/
public function getJavaScriptFiles(): array
{
return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Cache.js'];
}
/**
* Returns a string array with css files that will be rendered after the module
*
* Example: return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Edit.css'];
*
* @return array
*/
public function getCssFiles(): array
{
return [];
}
}
@@ -0,0 +1,208 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules\Debug;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleSettingsProviderInterface;
use TYPO3\CMS\Adminpanel\Service\ConfigurationService;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Log Sub Module of the AdminPanel
*
* @internal
*/
class Log extends AbstractSubModule implements DataProviderInterface, ModuleSettingsProviderInterface, InitializableInterface
{
protected $logLevel = LogLevel::INFO;
/**
* @var ConfigurationService
*/
protected $configurationService;
public function __construct()
{
$this->configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
}
/**
* @return string
*/
public function getIdentifier(): string
{
return 'debug_log';
}
/**
* Sub-Module label
*
* @return string
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.log.label'
);
}
/**
* @inheritdoc
*/
public function getDataToStore(ServerRequestInterface $request): ModuleData
{
$levels = [];
for ($i = 1; $i <= LogLevel::DEBUG; $i++) {
$levels[] = [
'level' => $i,
'levelName' => LogLevel::getName($i),
];
}
$log = InMemoryLogWriter::$log;
$logArray = [];
/** @var \TYPO3\CMS\Core\Log\LogRecord $logRecord */
foreach ($log as $logRecord) {
$entry = $logRecord->toArray();
// store only necessary info
unset($entry['data']);
$logArray[] = $entry;
}
return new ModuleData(
[
'levels' => $levels,
'startLevel' => (int)$this->getConfigOption('startLevel'),
'log' => $logArray,
]
);
}
/**
* @inheritdoc
*/
public function getSettings(): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Debug/LogSettings.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$levels = [];
for ($i = 1; $i <= LogLevel::DEBUG; $i++) {
$levels[] = [
'level' => $i,
'levelName' => LogLevel::getName($i),
];
}
$view->assignMultiple(
[
'levels' => $levels,
'startLevel' => (int)$this->getConfigOption('startLevel'),
'groupByComponent' => $this->getConfigOption('groupByComponent'),
'groupByLevel' => $this->getConfigOption('groupByLevel'),
]
);
return $view->render();
}
/**
* Sub-Module content as rendered HTML
*
* @param \TYPO3\CMS\Adminpanel\ModuleApi\ModuleData $data
* @return string
*/
public function getContent(ModuleData $data): string
{
$this->logLevel = $this->getConfigOption('startLevel');
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Debug/Log.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$sortedLog = [];
// settings for this module
$groupByComponent = $this->getConfigOption('groupByComponent');
$groupByLevel = $this->getConfigOption('groupByLevel');
foreach ($data['log'] as $logRecord) {
if ($logRecord['level'] > $this->logLevel) {
continue;
}
if ($groupByComponent && $groupByLevel) {
$sortedLog[$logRecord['component']][LogLevel::getName($logRecord['level'])][] = $logRecord;
} elseif ($groupByComponent) {
$sortedLog[$logRecord['component']][] = $logRecord;
} elseif ($groupByLevel) {
$sortedLog[$logRecord['level']][] = $logRecord;
} else {
$sortedLog[] = $logRecord;
}
}
$data['log'] = $sortedLog;
$data['groupByComponent'] = $groupByComponent;
$data['groupByLevel'] = $groupByLevel;
$view->assignMultiple($data->getArrayCopy());
return $view->render();
}
/**
* @inheritdoc
*/
public function initializeModule(ServerRequestInterface $request): void
{
$this->logLevel = $this->getConfigOption('startLevel');
// set inMemoryLogWriter recursively for all configured namespaces/areas so we don't lose log entries
$configWithInMemoryWriter = $this->setLoggingConfigRecursive($GLOBALS['TYPO3_CONF_VARS']['LOG'] ?? []);
// in case there are empty array parts, remove them
$GLOBALS['TYPO3_CONF_VARS']['LOG'] = array_filter(
$configWithInMemoryWriter
);
}
protected function setLoggingConfigRecursive(array $logConfig): array
{
foreach ($logConfig as $key => $value) {
if ($key === 'writerConfiguration') {
$logConfig[$key] = $value;
$logConfig[$key][LogLevel::DEBUG][InMemoryLogWriter::class] = [];
} elseif (is_array($value)) {
$logConfig[$key] = $this->setLoggingConfigRecursive($value);
}
}
return $logConfig;
}
/**
* @param string $option
* @return string
*/
protected function getConfigOption(string $option): string
{
return $this->configurationService->getConfigurationOption('debug_log', $option);
}
}
@@ -0,0 +1,131 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules\Debug;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Admin Panel Query Information module for showing SQL Queries
*
* @internal
*/
class QueryInformation extends AbstractSubModule implements DataProviderInterface
{
/**
* Identifier for this Sub-module,
* for example "preview" or "cache"
*
* @return string
*/
public function getIdentifier(): string
{
return 'debug_queryinformation';
}
/**
* Sub-Module label
*
* @return string
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:submodule.queryInformation.label'
);
}
/**
* @param ServerRequestInterface $request
* @return \TYPO3\CMS\Adminpanel\ModuleApi\ModuleData
* @throws \Doctrine\DBAL\DBALException
*/
public function getDataToStore(ServerRequestInterface $request): ModuleData
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$connection = $connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
$logger = $connection->getConfiguration()->getSQLLogger();
$data = [];
if ($logger instanceof DoctrineSqlLogger) {
$queries = $logger->getQueries();
$data['queries'] = $this->groupQueries($queries) ?? [];
$data['totalTime'] = array_sum(array_column($queries, 'executionMS')) * 1000;
}
return new ModuleData($data);
}
/**
* @param \TYPO3\CMS\Adminpanel\ModuleApi\ModuleData $data
* @return string Returns content of admin panel
*/
public function getContent(ModuleData $data): string
{
$view = new StandaloneView();
$view->setTemplatePathAndFilename(
'EXT:adminpanel/Resources/Private/Templates/Modules/Debug/QueryInformation.html'
);
$this->getLanguageService()->includeLLFile('EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf');
$view->assignMultiple($data->getArrayCopy());
return $view->render();
}
/**
* @param array $queries
* @return array
*/
protected function groupQueries(array $queries): array
{
$groupedQueries = [];
foreach ($queries as $query) {
$identifier = sha1($query['sql']) . sha1(json_encode($query['backtrace']));
if (is_array($query['params'])) {
foreach ($query['params'] as $k => $param) {
if (is_array($param)) {
$query['params'][$k] = implode(',', $param);
}
}
}
if (isset($groupedQueries[$identifier])) {
$groupedQueries[$identifier]['count']++;
$groupedQueries[$identifier]['time'] += ($query['executionMS'] * 1000);
$groupedQueries[$identifier]['queries'][] = $query;
} else {
$groupedQueries[$identifier] = [
'sql' => $query['sql'],
'time' => $query['executionMS'] * 1000,
'count' => 1,
'queries' => [
$query,
],
];
}
}
uasort(
$groupedQueries,
function ($a, $b) {
return $b['time'] <=> $a['time'];
}
);
return $groupedQueries;
}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules;
/*
* 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\Adminpanel\Log\InMemoryLogWriter;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
use TYPO3\CMS\Adminpanel\ModuleApi\ShortInfoProviderInterface;
use TYPO3\CMS\Core\Log\LogRecord;
/**
* Debug Module of the AdminPanel
*/
class DebugModule extends AbstractModule implements ShortInfoProviderInterface
{
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'debug';
}
/**
* @inheritdoc
*/
public function getIconIdentifier(): string
{
return 'actions-debug';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:module.label'
);
}
public function getShortInfo(): string
{
$errorsAndWarnings = array_filter(InMemoryLogWriter::$log, function (LogRecord $entry) {
return $entry->getLevel() <= 4;
});
return sprintf($this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf:module.shortinfo'
), count($errorsAndWarnings));
}
}
@@ -0,0 +1,153 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface;
use TYPO3\CMS\Adminpanel\Service\EditToolbarService;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Admin Panel Edit Module
*/
class EditModule extends AbstractModule implements PageSettingsProviderInterface, InitializableInterface, ResourceProviderInterface
{
/**
* Creates the content for the "edit" section ("module") of the Admin Panel
*
* @return string HTML content for the section. Consists of a string with table-rows with four columns.
*/
public function getPageSettings(): string
{
$editToolbarService = GeneralUtility::makeInstance(EditToolbarService::class);
$toolbar = $editToolbarService->createToolbar();
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Settings/Edit.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple(
[
'feEdit' => ExtensionManagementUtility::isLoaded('feedit'),
'display' => [
'fieldIcons' => $this->configurationService->getConfigurationOption('edit', 'displayFieldIcons'),
'displayIcons' => $this->configurationService->getConfigurationOption('edit', 'displayIcons'),
],
'toolbar' => $toolbar,
'script' => [
'pageUid' => (int)$this->getTypoScriptFrontendController()->page['uid'],
'pageModule' => $this->getPageModule(),
'backendScript' => BackendUtility::getBackendScript(),
't3BeSitenameMd5' => md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']),
],
]
);
return $view->render();
}
/**
* @return TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
/**
* @return string
*/
private function getPageModule(): string
{
$pageModule = trim($this->getBackendUser()->getTSConfig()['options.']['overridePageModule'] ?? '');
return BackendUtility::isModuleSetInTBE_MODULES($pageModule) ? $pageModule : 'web_layout';
}
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'edit';
}
/**
* @inheritdoc
*/
public function getIconIdentifier(): string
{
return 'actions-open';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
$locallangFileAndPath = 'LLL:EXT:adminpanel/Resources/Private/Language/locallang_edit.xlf:module.label';
return $this->getLanguageService()->sL($locallangFileAndPath);
}
/**
* Initialize the edit module
* Includes the frontend edit initialization
*
* @param ServerRequestInterface $request
*
* @todo move into fe_edit (including the module)
*/
public function initializeModule(ServerRequestInterface $request): void
{
$extFeEditLoaded = ExtensionManagementUtility::isLoaded('feedit');
$typoScriptFrontend = $this->getTypoScriptFrontendController();
$typoScriptFrontend->displayEditIcons = $this->configurationService->getConfigurationOption('edit', 'displayIcons');
$typoScriptFrontend->displayFieldEditIcons = $this->configurationService->getConfigurationOption('edit', 'displayFieldIcons');
if ($request->getQueryParams()['ADMCMD_editIcons'] ?? $request->getParsedBody()['ADMCMD_editIcons'] ?? false) {
$typoScriptFrontend->displayFieldEditIcons = '1';
}
if ($extFeEditLoaded && $typoScriptFrontend->displayEditIcons) {
$typoScriptFrontend->set_no_cache('Admin Panel: Display edit icons', true);
}
if ($extFeEditLoaded && $typoScriptFrontend->displayFieldEditIcons) {
$typoScriptFrontend->set_no_cache('Admin Panel: Display field edit icons', true);
}
}
/**
* @return array
*/
public function getJavaScriptFiles(): array
{
return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Edit.js'];
}
/**
* Returns a string array with css files that will be rendered after the module
*
* @return array
*/
public function getCssFiles(): array
{
return [];
}
}
@@ -0,0 +1,186 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules\Info;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* General information module displaying info about the current
* request
*
* @internal
*/
class GeneralInformation extends AbstractSubModule implements DataProviderInterface
{
/**
* @inheritdoc
*/
public function getDataToStore(ServerRequestInterface $request): ModuleData
{
/** @var UserAspect $frontendUserAspect */
$frontendUserAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
$tsfe = $this->getTypoScriptFrontendController();
return new ModuleData(
[
'post' => $_POST,
'get' => $_GET,
'cookie' => $_COOKIE,
'server' => $_SERVER,
'info' => [
'pageUid' => $tsfe->id,
'pageType' => $tsfe->type,
'groupList' => implode(',', $frontendUserAspect->getGroupIds()),
'noCache' => $this->isNoCacheEnabled(),
'countUserInt' => count($tsfe->config['INTincScript'] ?? []),
'totalParsetime' => $this->getTimeTracker()->getParseTime(),
'feUser' => [
'uid' => $frontendUserAspect->get('id') ?: 0,
'username' => $frontendUserAspect->get('username') ?: '',
],
'imagesOnPage' => $this->collectImagesOnPage(),
'documentSize' => $this->collectDocumentSize(),
],
]
);
}
/**
* Creates the content for the "info" section ("module") of the Admin Panel
*
* @param \TYPO3\CMS\Adminpanel\ModuleApi\ModuleData $data
* @return string HTML content for the section. Consists of a string with table-rows with four columns.
* @see display()
*/
public function getContent(ModuleData $data): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Info/General.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple($data->getArrayCopy());
return $view->render();
}
/**
* Identifier for this Sub-module,
* for example "preview" or "cache"
*
* @return string
*/
public function getIdentifier(): string
{
return 'info_general';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:sub.general.label'
);
}
/**
* Collects images from TypoScriptFrontendController and calculates the total size.
* Returns human readable image sizes for fluid template output
*
* @return array
*/
protected function collectImagesOnPage(): array
{
$imagesOnPage = [
'files' => [],
'total' => 0,
'totalSize' => 0,
'totalSizeHuman' => GeneralUtility::formatSize(0),
];
if ($this->isNoCacheEnabled() === false) {
return $imagesOnPage;
}
$count = 0;
$totalImageSize = 0;
if (!empty($this->getTypoScriptFrontendController()->imagesOnPage)) {
foreach ($this->getTypoScriptFrontendController()->imagesOnPage as $file) {
$fileSize = @filesize($file);
$imagesOnPage['files'][] = [
'name' => $file,
'size' => $fileSize,
'sizeHuman' => GeneralUtility::formatSize($fileSize),
];
$totalImageSize += $fileSize;
$count++;
}
}
$imagesOnPage['totalSize'] = GeneralUtility::formatSize($totalImageSize);
$imagesOnPage['total'] = $count;
return $imagesOnPage;
}
/**
* Gets the document size from the current page in a human readable format
*
* @return string
*/
protected function collectDocumentSize(): string
{
$documentSize = 0;
if ($this->isNoCacheEnabled() === true) {
$documentSize = mb_strlen($this->getTypoScriptFrontendController()->content, 'UTF-8');
}
return GeneralUtility::formatSize($documentSize);
}
/**
* @return bool
*/
protected function isNoCacheEnabled(): bool
{
return (bool)$this->getTypoScriptFrontendController()->no_cache;
}
/**
* @return TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
/**
* @return TimeTracker
*/
protected function getTimeTracker(): TimeTracker
{
return GeneralUtility::makeInstance(TimeTracker::class);
}
}
@@ -0,0 +1,84 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules\Info;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* PhpInformation admin panel sub module
*
* @internal
*/
class PhpInformation extends AbstractSubModule implements DataProviderInterface
{
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'info_php';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:sub.php.label'
);
}
/**
* @inheritdoc
*/
public function getDataToStore(ServerRequestInterface $request): ModuleData
{
return new ModuleData(
[
'general' => [
'PHP_VERSION' => PHP_VERSION,
'PHP_OS' => PHP_OS,
'PHP_SAPI' => PHP_SAPI,
'Peak Memory Usage' => GeneralUtility::formatSize(memory_get_peak_usage()),
],
'loadedExtensions' => implode(', ', get_loaded_extensions()),
'constants' => get_defined_constants(true),
]
);
}
/**
* @inheritdoc
*/
public function getContent(ModuleData $data): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Info/PhpInfo.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple($data->getArrayCopy());
return $view->render();
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules\Info;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* RequestInformation submodule of the admin panel
*
* @internal
*/
class RequestInformation extends AbstractSubModule implements DataProviderInterface
{
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'info-request';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:sub.request.label'
);
}
/**
* @inheritdoc
*/
public function getDataToStore(ServerRequestInterface $request): ModuleData
{
return new ModuleData(
[
'post' => $_POST,
'get' => $_GET,
'cookie' => $_COOKIE,
'session' => $_SESSION,
'server' => $_SERVER,
]
);
}
/**
* @inheritdoc
*/
public function getContent(ModuleData $data): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Info/RequestInformation.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple($data->getArrayCopy());
return $view->render();
}
}
@@ -0,0 +1,73 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules;
/*
* 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\Adminpanel\ModuleApi\AbstractModule;
use TYPO3\CMS\Adminpanel\ModuleApi\ShortInfoProviderInterface;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Admin Panel Info Module
*/
class InfoModule extends AbstractModule implements ShortInfoProviderInterface
{
/**
* @inheritdoc
*/
public function getIconIdentifier(): string
{
return 'actions-document-info';
}
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'info';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:module.label'
);
}
/**
* @inheritdoc
*/
public function getShortInfo(): string
{
$parseTime = $this->getTimeTracker()->getParseTime();
return sprintf($this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:module.shortinfo'
), $parseTime);
}
/**
* @return TimeTracker
*/
protected function getTimeTracker(): TimeTracker
{
return GeneralUtility::makeInstance(TimeTracker::class);
}
}
@@ -0,0 +1,257 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface;
use TYPO3\CMS\Adminpanel\Repositories\FrontendGroupsRepository;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\DateTimeAspect;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\Context\VisibilityAspect;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Admin Panel Preview Module
*/
class PreviewModule extends AbstractModule implements InitializableInterface, PageSettingsProviderInterface, ResourceProviderInterface
{
/**
* module configuration, set on initialize
*
* @var array
*/
protected $config;
/**
* @inheritdoc
*/
public function getIconIdentifier(): string
{
return 'actions-preview';
}
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'preview';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_preview.xlf:module.label'
);
}
/**
* @inheritdoc
*/
public function initializeModule(ServerRequestInterface $request): void
{
// Backend preview params (ADMCMD_) take precedence over configured admin panel values
$simulateGroupByRequest = (int)($request->getQueryParams()['ADMCMD_simUser'] ?? 0);
$simulateTimeByRequest = (int)($request->getQueryParams()['ADMCMD_simTime'] ?? 0);
$this->config = [
'showHiddenPages' => (bool)$this->getConfigOptionForModule('showHiddenPages'),
'simulateDate' => $simulateTimeByRequest ?: (int)$this->getConfigOptionForModule('simulateDate'),
'showHiddenRecords' => (bool)$this->getConfigOptionForModule('showHiddenRecords'),
'simulateUserGroup' => $simulateGroupByRequest ?: (int)$this->getConfigOptionForModule('simulateUserGroup'),
'showFluidDebug' => (bool)$this->getConfigOptionForModule('showFluidDebug'),
];
if ($this->config['showFluidDebug']) {
// forcibly unset fluid caching as it does not care about the tsfe based caching settings
unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['frontend']);
$GLOBALS['TSFE']->set_no_cache('Cache is disabled if fluid debugging is enabled', true);
}
$this->initializeFrontendPreview(
$this->config['showHiddenPages'],
$this->config['showHiddenRecords'],
$this->config['simulateDate'],
$this->config['simulateUserGroup']
);
}
/**
* @inheritdoc
*/
public function getPageSettings(): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Settings/Preview.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$frontendGroupsRepository = GeneralUtility::makeInstance(FrontendGroupsRepository::class);
$view->assignMultiple(
[
'show' => [
'pageId' => (int)$this->getTypoScriptFrontendController()->id,
'hiddenPages' => $this->config['showHiddenPages'],
'hiddenRecords' => $this->config['showHiddenRecords'],
'fluidDebug' => $this->config['showFluidDebug'],
],
'simulateDate' => $this->config['simulateDate'],
'frontendUserGroups' => [
'availableGroups' => $frontendGroupsRepository->getAvailableFrontendUserGroups(),
'selected' => (int)$this->config['simulateUserGroup'],
],
]
);
return $view->render();
}
/**
* @param string $option
* @return string
*/
protected function getConfigOptionForModule(string $option): string
{
return $this->configurationService->getConfigurationOption(
'preview',
$option
);
}
/**
* @return TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
/**
* Initialize frontend preview functionality incl.
* simulation of users or time
*
* @param bool $showHiddenPages
* @param bool $showHiddenRecords
* @param int $simulateDate
* @param int $simulateUserGroup UID of the fe_group to simulate
* @throws \Exception
*/
protected function initializeFrontendPreview(
bool $showHiddenPages,
bool $showHiddenRecords,
int $simulateDate,
int $simulateUserGroup
): void {
$context = GeneralUtility::makeInstance(Context::class);
$typoScriptFrontendController = $this->getTypoScriptFrontendController();
$typoScriptFrontendController->clear_preview();
$typoScriptFrontendController->fePreview = 1;
// Modify visibility settings (hidden pages + hidden content)
$context->setAspect(
'visibility',
GeneralUtility::makeInstance(VisibilityAspect::class, $showHiddenPages, $showHiddenRecords)
);
// Simulate date
$simTime = null;
if ($simulateDate) {
$simTime = $this->parseDate($simulateDate);
if ($simTime) {
$GLOBALS['SIM_EXEC_TIME'] = $simTime;
$GLOBALS['SIM_ACCESS_TIME'] = $simTime - $simTime % 60;
$context->setAspect(
'date',
GeneralUtility::makeInstance(
DateTimeAspect::class,
new \DateTimeImmutable('@' . $GLOBALS['SIM_EXEC_TIME'])
)
);
}
}
// simulate usergroup
if ($simulateUserGroup) {
$typoScriptFrontendController->simUserGroup = $simulateUserGroup;
if (!$typoScriptFrontendController->fe_user instanceof FrontendUserAuthentication) {
$typoScriptFrontendController->fe_user = GeneralUtility::makeInstance(
FrontendUserAuthentication::class
);
}
if (!is_array($typoScriptFrontendController->fe_user->user)) {
// This can be removed once #90989 is fixed
$typoScriptFrontendController->fe_user->user = ['uid' => PHP_INT_MAX];
}
$typoScriptFrontendController->fe_user->user[$typoScriptFrontendController->fe_user->usergroup_column] = $simulateUserGroup;
$context->setAspect(
'frontend.user',
GeneralUtility::makeInstance(
UserAspect::class,
$typoScriptFrontendController->fe_user ?: null,
[$simulateUserGroup]
)
);
}
if (!$simulateUserGroup && !$simTime && !$showHiddenPages && !$showHiddenRecords) {
$typoScriptFrontendController->fePreview = 0;
}
}
/**
* @return array
*/
public function getJavaScriptFiles(): array
{
return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Preview.js'];
}
/**
* The simulated date needs to be a timestring (UTC)
*
* Simulation date is either set via configuration of AdminPanel (Date and Time Fields) or via ADMCMD_ $_GET
* parameter from backend previews
*
* @param int $simulateDate
* @return int
*/
protected function parseDate(int $simulateDate): ?int
{
try {
$simTime = (new \DateTime('@' . $simulateDate))->getTimestamp();
$simTime = max($simTime, 60);
} catch (\Exception $e) {
$simTime = null;
}
return $simTime;
}
/**
* Returns a string array with css files that will be rendered after the module
*
* @return array
*/
public function getCssFiles(): array
{
return [];
}
}
@@ -0,0 +1,193 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules\TsDebug;
/*
* 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 Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleSettingsProviderInterface;
use TYPO3\CMS\Adminpanel\Service\ConfigurationService;
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Class TypoScriptWaterfall
*
* @internal
*/
class TypoScriptWaterfall extends AbstractSubModule implements InitializableInterface, ModuleSettingsProviderInterface
{
/**
* @var ConfigurationService
*/
protected $configurationService;
public function __construct()
{
$this->configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
}
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'typoscript-waterfall';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_tsdebug.xlf:sub.waterfall.label'
);
}
/**
* @inheritdoc
*/
public function initializeModule(ServerRequestInterface $request): void
{
$typoScriptFrontend = $this->getTypoScriptFrontendController();
$typoScriptFrontend->forceTemplateParsing = $this->getConfigurationOption(
'forceTemplateParsing'
);
if ($typoScriptFrontend->forceTemplateParsing) {
$typoScriptFrontend->set_no_cache('Admin Panel: Force template parsing', true);
}
$this->getTimeTracker()->LR = (bool)$this->getConfigurationOption('LR');
}
/**
* Creates the content for the "tsdebug" section ("module") of the Admin Panel
*
* @param ModuleData $data
* @return string HTML
*/
public function getContent(ModuleData $data): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/TsDebug/TypoScript.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple(
[
'tree' => (int)$this->getConfigurationOption('tree'),
'display' => [
'times' => (int)$this->getConfigurationOption('displayTimes'),
'messages' => (int)$this->getConfigurationOption('displayMessages'),
'content' => (int)$this->getConfigurationOption('displayContent'),
],
'trackContentRendering' => (int)$this->getConfigurationOption('LR'),
'forceTemplateParsing' => (int)$this->getConfigurationOption('forceTemplateParsing'),
'typoScriptLog' => $this->renderTypoScriptLog(),
]
);
return $view->render();
}
/**
* @inheritdoc
*/
public function getSettings(): string
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/TsDebug/TypoScriptSettings.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple(
[
'tree' => (int)$this->getConfigurationOption('tree'),
'display' => [
'times' => (int)$this->getConfigurationOption('displayTimes'),
'messages' => (int)$this->getConfigurationOption('displayMessages'),
'content' => (int)$this->getConfigurationOption('displayContent'),
],
'trackContentRendering' => (int)$this->getConfigurationOption('LR'),
'forceTemplateParsing' => (int)$this->getConfigurationOption('forceTemplateParsing')
]
);
return $view->render();
}
/**
* Returns the current BE user.
*
* @return BackendUserAuthentication|FrontendBackendUserAuthentication
*/
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
/**
* @param string $option
* @return bool
*/
protected function getConfigurationOption(string $option): bool
{
return (bool)$this->configurationService->getConfigurationOption('tsdebug', $option);
}
/**
* Renders the TypoScript log as string
*
* @return string
*/
protected function renderTypoScriptLog(): string
{
$timeTracker = $this->getTimeTracker();
$timeTracker->printConf['flag_tree'] = $this->getConfigurationOption('tree');
$timeTracker->printConf['allTime'] = $this->getConfigurationOption(
'displayTimes'
);
$timeTracker->printConf['flag_messages'] = $this->getConfigurationOption(
'displayMessages'
);
$timeTracker->printConf['flag_content'] = $this->getConfigurationOption(
'displayContent'
);
return $timeTracker->printTSlog();
}
/**
* @return TimeTracker
*/
protected function getTimeTracker(): TimeTracker
{
return GeneralUtility::makeInstance(TimeTracker::class);
}
/**
* @return TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
}
@@ -0,0 +1,79 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Modules;
/*
* 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\Adminpanel\ModuleApi\AbstractModule;
use TYPO3\CMS\Adminpanel\ModuleApi\ShortInfoProviderInterface;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Admin Panel TypoScript Debug Module
*/
class TsDebugModule extends AbstractModule implements ShortInfoProviderInterface
{
/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'tsdebug';
}
/**
* @inheritdoc
*/
public function getIconIdentifier(): string
{
return 'mimetypes-x-content-template-static';
}
/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_tsdebug.xlf:module.label'
);
}
/**
* @inheritdoc
*/
public function getShortInfo(): string
{
$messageCount = 0;
foreach ($this->getTimeTracker()->tsStackLog as $log) {
$messageCount += count($log['message'] ?? []);
}
return sprintf(
$this->getLanguageService()->sL(
'LLL:EXT:adminpanel/Resources/Private/Language/locallang_tsdebug.xlf:module.shortinfo'
),
$messageCount
);
}
/**
* @return TimeTracker
*/
protected function getTimeTracker(): TimeTracker
{
return GeneralUtility::makeInstance(TimeTracker::class);
}
}