[FEATURE] New API for the admin panel
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / AdminPanel / InfoModule.php
1 <?php
2 declare(strict_types=1);
3
4 namespace TYPO3\CMS\Frontend\AdminPanel;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
22
23 /**
24 * Admin Panel Info Module
25 */
26 class InfoModule extends AbstractModule implements AdminPanelModuleInterface
27 {
28 /**
29 * Creates the content for the "info" section ("module") of the Admin Panel
30 *
31 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
32 * @see display()
33 */
34 public function getContent(): string
35 {
36 $output = [];
37 $tsfe = $this->getTypoScriptFrontendController();
38 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_info']) {
39 $tableArr = [];
40 if ($this->getBackendUser()->adminPanel->extGetFeAdminValue('cache', 'noCache')) {
41 $theBytes = 0;
42 $count = 0;
43 if (!empty($tsfe->imagesOnPage)) {
44 $tableArr[] = [$this->extGetLL('info_imagesOnPage'), count($tsfe->imagesOnPage), true];
45 foreach ($GLOBALS['TSFE']->imagesOnPage as $file) {
46 $fs = @filesize($file);
47 $tableArr[] = [TAB . $file, GeneralUtility::formatSize($fs)];
48 $theBytes += $fs;
49 $count++;
50 }
51 }
52 // Add an empty line
53 $tableArr[] = [$this->extGetLL('info_imagesSize'), GeneralUtility::formatSize($theBytes), true];
54 $tableArr[] = [
55 $this->extGetLL('info_DocumentSize'),
56 GeneralUtility::formatSize(strlen($tsfe->content)),
57 true,
58 ];
59 $tableArr[] = ['', ''];
60 }
61 $tableArr[] = [$this->extGetLL('info_id'), $tsfe->id];
62 $tableArr[] = [$this->extGetLL('info_type'), $tsfe->type];
63 $tableArr[] = [$this->extGetLL('info_groupList'), $tsfe->gr_list];
64 $tableArr[] = [
65 $this->extGetLL('info_noCache'),
66 $this->extGetLL('info_noCache_' . ($tsfe->no_cache ? 'no' : 'yes')),
67 ];
68 $tableArr[] = [$this->extGetLL('info_countUserInt'), count($tsfe->config['INTincScript'] ?? [])];
69
70 if (!empty($tsfe->fe_user->user['uid'])) {
71 $tableArr[] = [$this->extGetLL('info_feuserName'), htmlspecialchars($tsfe->fe_user->user['username'])];
72 $tableArr[] = [$this->extGetLL('info_feuserId'), htmlspecialchars($tsfe->fe_user->user['uid'])];
73 }
74
75 $tableArr[] = [
76 $this->extGetLL('info_totalParsetime'),
77 $this->getTimeTracker()->getParseTime() . ' ms',
78 true,
79 ];
80 $table = '';
81 foreach ($tableArr as $key => $arr) {
82 $label = (isset($arr[2]) ? '<strong>' . $arr[0] . '</strong>' : $arr[0]);
83 $value = (string)$arr[1] !== '' ? $arr[1] : '';
84 $table .= '
85 <tr>
86 <td>' . $label . '</td>
87 <td>' . htmlspecialchars((string)$value) . '</td>
88 </tr>';
89 }
90
91 $output[] = '<div class="typo3-adminPanel-table-overflow">';
92 $output[] = ' <table class="typo3-adminPanel-table">';
93 $output[] = ' ' . $table;
94 $output[] = ' </table>';
95 $output[] = '</div>';
96 }
97
98 return implode('', $output);
99 }
100
101 /**
102 * @inheritdoc
103 */
104 public function getIdentifier(): string
105 {
106 return 'info';
107 }
108
109 /**
110 * @inheritdoc
111 */
112 public function getLabel(): string
113 {
114 return $this->extGetLL('info');
115 }
116
117 /**
118 * @return TypoScriptFrontendController
119 */
120 protected function getTypoScriptFrontendController(): TypoScriptFrontendController
121 {
122 return $GLOBALS['TSFE'];
123 }
124
125 /**
126 * @return TimeTracker
127 */
128 protected function getTimeTracker(): TimeTracker
129 {
130 return GeneralUtility::makeInstance(TimeTracker::class);
131 }
132 }