‪TYPO3CMS  ‪main
GeneralInformation.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
30 
37 {
38  public function ‪__construct(
39  private readonly ‪TimeTracker $timeTracker,
40  private readonly ‪Context $context,
41  ) {}
42 
43  public function ‪getDataToStore(ServerRequestInterface $request): ‪ModuleData
44  {
45  $frontendUserAspect = $this->context->getAspect('frontend.user');
46  return new ‪ModuleData(
47  [
48  'post' => $request->getParsedBody(),
49  'get' => $request->getQueryParams(),
50  'cookie' => $request->getCookieParams(),
51  'server' => $request->getServerParams(),
52  'info' => [
53  'pageUid' => $request->getAttribute('frontend.page.information')->getId(),
54  'pageType' => $request->getAttribute('routing')->getPageType(),
55  'groupList' => implode(',', $frontendUserAspect->getGroupIds()),
56  'noCache' => !$request->getAttribute('frontend.cache.instruction')->isCachingAllowed(),
57  'noCacheReasons' => $request->getAttribute('frontend.cache.instruction')->getDisabledCacheReasons(),
58  'countUserInt' => count($request->getAttribute('frontend.controller')->config['INTincScript'] ?? []),
59  'totalParsetime' => $this->timeTracker->getParseTime(),
60  'feUser' => [
61  'uid' => $frontendUserAspect->get('id') ?: 0,
62  'username' => $frontendUserAspect->get('username') ?: '',
63  ],
64  'imagesOnPage' => $this->collectImagesOnPage($request),
65  'documentSize' => $this->collectDocumentSize($request),
66  ],
67  ]
68  );
69  }
70 
74  public function ‪getContent(‪ModuleData $data): string
75  {
76  $view = GeneralUtility::makeInstance(StandaloneView::class);
77  $templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Info/General.html';
78  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
79  $view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
80  $view->assignMultiple($data->getArrayCopy());
81  $view->assign('languageKey', $this->‪getBackendUser()->user['lang'] ?? null);
82  return $view->render();
83  }
84 
85  public function ‪getIdentifier(): string
86  {
87  return 'info_general';
88  }
89 
90  public function ‪getLabel(): string
91  {
92  return $this->‪getLanguageService()->sL(
93  'LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:sub.general.label'
94  );
95  }
96 
101  protected function ‪collectImagesOnPage(ServerRequestInterface $request): array
102  {
103  $imagesOnPage = [
104  'files' => [],
105  'total' => 0,
106  'totalSize' => 0,
107  'totalSizeHuman' => GeneralUtility::formatSize(0),
108  ];
109  if ($request->getAttribute('frontend.cache.instruction')->isCachingAllowed()) {
110  return $imagesOnPage;
111  }
112  $count = 0;
113  $totalImageSize = 0;
114  foreach (GeneralUtility::makeInstance(AssetCollector::class)->getMedia() as $file => $information) {
115  $filePath = ‪Environment::getPublicPath() . '/' . ltrim(parse_url($file, PHP_URL_PATH), '/');
116  $fileSize = is_file($filePath) ? filesize($filePath) : 0;
117  $imagesOnPage['files'][] = [
118  'name' => $file,
119  'size' => $fileSize,
120  'sizeHuman' => GeneralUtility::formatSize($fileSize),
121  ];
122  $totalImageSize += $fileSize;
123  $count++;
124  }
125  $imagesOnPage['totalSize'] = GeneralUtility::formatSize($totalImageSize);
126  $imagesOnPage['total'] = $count;
127  return $imagesOnPage;
128  }
129 
133  protected function ‪collectDocumentSize(ServerRequestInterface $request): string
134  {
135  $documentSize = 0;
136  if (!$request->getAttribute('frontend.cache.instruction')->isCachingAllowed()) {
137  $tsfe = $request->getAttribute('frontend.controller');
138  $documentSize = mb_strlen($tsfe->content, 'UTF-8');
139  }
140  return GeneralUtility::formatSize($documentSize);
141  }
142 }
‪TYPO3\CMS\Adminpanel\Modules\Info\GeneralInformation\getLabel
‪getLabel()
Definition: GeneralInformation.php:90
‪TYPO3\CMS\Core\Page\AssetCollector
Definition: AssetCollector.php:42
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface
Definition: DataProviderInterface.php:30
‪TYPO3\CMS\Adminpanel\Modules\Info\GeneralInformation\collectImagesOnPage
‪collectImagesOnPage(ServerRequestInterface $request)
Definition: GeneralInformation.php:101
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule\getBackendUser
‪getBackendUser()
Definition: AbstractSubModule.php:35
‪TYPO3\CMS\Adminpanel\Modules\Info\GeneralInformation\getDataToStore
‪getDataToStore(ServerRequestInterface $request)
Definition: GeneralInformation.php:43
‪TYPO3\CMS\Adminpanel\Modules\Info
Definition: GeneralInformation.php:18
‪TYPO3\CMS\Adminpanel\Modules\Info\GeneralInformation\collectDocumentSize
‪collectDocumentSize(ServerRequestInterface $request)
Definition: GeneralInformation.php:133
‪TYPO3\CMS\Adminpanel\Modules\Info\GeneralInformation\getIdentifier
‪getIdentifier()
Definition: GeneralInformation.php:85
‪TYPO3\CMS\Adminpanel\Modules\Info\GeneralInformation\__construct
‪__construct(private readonly TimeTracker $timeTracker, private readonly Context $context,)
Definition: GeneralInformation.php:38
‪TYPO3\CMS\Adminpanel\Modules\Info\GeneralInformation\getContent
‪getContent(ModuleData $data)
Definition: GeneralInformation.php:74
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:30
‪TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule\getLanguageService
‪getLanguageService()
Definition: AbstractSubModule.php:30
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleData
Definition: ModuleData.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\TimeTracker\TimeTracker
Definition: TimeTracker.php:34
‪TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule
Definition: AbstractSubModule.php:29
‪TYPO3\CMS\Adminpanel\Modules\Info\GeneralInformation
Definition: GeneralInformation.php:37