6b7d91a7c850652123fd5139691795aca190dae5
[Packages/TYPO3.CMS.git] / typo3 / sysext / about / Classes / Controller / AboutController.php
1 <?php
2 namespace TYPO3\CMS\About\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\ModuleLoader;
20 use TYPO3\CMS\Backend\Template\ModuleTemplate;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Http\HtmlResponse;
23 use TYPO3\CMS\Core\Package\PackageManager;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Fluid\View\StandaloneView;
26 use TYPO3Fluid\Fluid\View\ViewInterface;
27
28 /**
29 * Module 'about' shows some standard information for TYPO3 CMS:
30 * About-text, version number, available modules and so on.
31 */
32 class AboutController
33 {
34 /**
35 * ModuleTemplate object
36 *
37 * @var ModuleTemplate
38 */
39 protected $moduleTemplate;
40
41 /**
42 * @var ViewInterface
43 */
44 protected $view;
45
46 /**
47 * Main action: Show standard information
48 *
49 * @param ServerRequestInterface $request the incoming PSR-7 request
50 * @return ResponseInterface the HTML output
51 */
52 public function indexAction(ServerRequestInterface $request): ResponseInterface
53 {
54 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
55 $this->initializeView('index');
56 $warnings = [];
57 // Hook for additional warnings
58 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'] ?? [] as $className) {
59 $hookObj = GeneralUtility::makeInstance($className);
60 if (method_exists($hookObj, 'displayWarningMessages_postProcess')) {
61 $hookObj->displayWarningMessages_postProcess($warnings);
62 }
63 }
64
65 $this->view->assignMultiple([
66 'copyrightYear' => TYPO3_copyright_year,
67 'donationUrl' => TYPO3_URL_DONATE,
68 'currentVersion' => TYPO3_version,
69 'loadedExtensions' => $this->getLoadedExtensions(),
70 'copyRightNotice' => BackendUtility::TYPO3_copyRightNotice(),
71 'warnings' => $warnings,
72 'modules' => $this->getModulesData()
73 ]);
74
75 $this->moduleTemplate->setContent($this->view->render());
76 return new HtmlResponse($this->moduleTemplate->renderContent());
77 }
78
79 /**
80 * Create array with data of all main modules (Web, File, ...)
81 * and its nested sub modules
82 *
83 * @return array
84 */
85 protected function getModulesData(): array
86 {
87 $loadedModules = GeneralUtility::makeInstance(ModuleLoader::class);
88 $loadedModules->observeWorkspaces = true;
89 $loadedModules->load($GLOBALS['TBE_MODULES']);
90 $mainModulesData = [];
91 foreach ($loadedModules->modules as $moduleName => $moduleInfo) {
92 $moduleLabels = $loadedModules->getLabelsForModule($moduleName);
93 $mainModuleData = [
94 'name' => $moduleName,
95 'label' => $moduleLabels['title']
96 ];
97 if (is_array($moduleInfo['sub']) && !empty($moduleInfo['sub'])) {
98 $mainModuleData['subModules'] = $this->getSubModuleData($loadedModules, $moduleName);
99 }
100 $mainModulesData[] = $mainModuleData;
101 }
102 return $mainModulesData;
103 }
104
105 /**
106 * Create array with data of all subModules of a specific main module
107 *
108 * @param ModuleLoader $loadedModules the module loader instance
109 * @param string $moduleName Name of the main module
110 * @return array
111 */
112 protected function getSubModuleData(ModuleLoader $loadedModules, $moduleName): array
113 {
114 $subModulesData = [];
115 foreach ($loadedModules->modules[$moduleName]['sub'] as $subModuleName => $subModuleInfo) {
116 $moduleLabels = $loadedModules->getLabelsForModule($moduleName . '_' . $subModuleName);
117 $subModuleData = [];
118 $subModuleData['name'] = $subModuleName;
119 $subModuleData['icon'] = $subModuleInfo['icon'];
120 $subModuleData['iconIdentifier'] = $subModuleInfo['iconIdentifier'];
121 $subModuleData['label'] = $moduleLabels['title'];
122 $subModuleData['shortDescription'] = $moduleLabels['shortdescription'];
123 $subModuleData['longDescription'] = $moduleLabels['description'];
124 $subModulesData[] = $subModuleData;
125 }
126 return $subModulesData;
127 }
128
129 /**
130 * Fetches a list of all active (loaded) extensions in the current system
131 *
132 * @return array
133 */
134 protected function getLoadedExtensions(): array
135 {
136 $extensions = [];
137 $packageManager = GeneralUtility::makeInstance(PackageManager::class);
138 foreach ($packageManager->getActivePackages() as $package) {
139 // Skip system extensions (= type: typo3-cms-framework)
140 if ($package->getValueFromComposerManifest('type') !== 'typo3-cms-extension') {
141 continue;
142 }
143 $extensions[] = [
144 'key' => $package->getPackageKey(),
145 'title' => $package->getPackageMetaData()->getDescription(),
146 'authors' => $package->getValueFromComposerManifest('authors')
147 ];
148 }
149 return $extensions;
150 }
151
152 /**
153 * Initializes the view by setting the templateName
154 *
155 * @param string $templateName
156 */
157 protected function initializeView(string $templateName)
158 {
159 $this->view = GeneralUtility::makeInstance(StandaloneView::class);
160 $this->view->setTemplate($templateName);
161 $this->view->setTemplateRootPaths(['EXT:about/Resources/Private/Templates/About']);
162 $this->view->setPartialRootPaths(['EXT:about/Resources/Private/Partials']);
163 $this->view->setLayoutRootPaths(['EXT:about/Resources/Private/Layouts']);
164 }
165 }