ab13758491d2b5913ba6168fee6b1cdf6663dae0
[Packages/TYPO3.CMS.git] / typo3 / sysext / info / Classes / Controller / PageInformationController.php
1 <?php
2 namespace TYPO3\CMS\Info\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 TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Backend\View\PageLayoutView;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Class for displaying page information (records, page record properties)
24 */
25 class PageInformationController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
26 {
27 /**
28 * Returns the menu array
29 *
30 * @return array
31 */
32 public function modMenu()
33 {
34 return [
35 'pages' => [
36 0 => $GLOBALS['LANG']->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_webinfo.xlf:pages_0'),
37 2 => $GLOBALS['LANG']->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_webinfo.xlf:pages_2'),
38 1 => $GLOBALS['LANG']->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_webinfo.xlf:pages_1')
39 ],
40 'depth' => [
41 0 => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_0'),
42 1 => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_1'),
43 2 => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_2'),
44 3 => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_3'),
45 4 => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_4'),
46 999 => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_infi')
47 ]
48 ];
49 }
50
51 /**
52 * MAIN function for page information display
53 *
54 * @return string Output HTML for the module.
55 */
56 public function main()
57 {
58 $theOutput = '<h1>' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:page_title')) . '</h1>';
59 $dblist = GeneralUtility::makeInstance(PageLayoutView::class);
60 $dblist->descrTable = '_MOD_web_info';
61 $dblist->thumbs = 0;
62 $dblist->script = BackendUtility::getModuleUrl('web_info');
63 $dblist->showIcon = 0;
64 $dblist->setLMargin = 0;
65 $dblist->agePrefixes = $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears');
66 $dblist->pI_showUser = true;
67
68 switch ((int)$this->pObj->MOD_SETTINGS['pages']) {
69 case 1:
70 $dblist->fieldArray = ['title', 'uid'] + array_keys($this->cleanTableNames());
71 break;
72 case 2:
73 $dblist->fieldArray = [
74 'title',
75 'uid',
76 'lastUpdated',
77 'newUntil',
78 'cache_timeout',
79 'php_tree_stop',
80 'TSconfig',
81 'is_siteroot',
82 'fe_login_mode'
83 ];
84 break;
85 default:
86 $dblist->fieldArray = [
87 'title',
88 'uid',
89 'alias',
90 'starttime',
91 'endtime',
92 'fe_group',
93 'target',
94 'url',
95 'shortcut',
96 'shortcut_mode'
97 ];
98 }
99
100 // PAGES:
101 $this->pObj->MOD_SETTINGS['pages_levels'] = $this->pObj->MOD_SETTINGS['depth'];
102 // ONLY for the sake of dblist module which uses this value.
103 $h_func = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[depth]', $this->pObj->MOD_SETTINGS['depth'], $this->pObj->MOD_MENU['depth']);
104 $h_func .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[pages]', $this->pObj->MOD_SETTINGS['pages'], $this->pObj->MOD_MENU['pages']);
105 $dblist->start($this->pObj->id, 'pages', 0);
106 $dblist->generateList();
107 // CSH
108 $optionKey = $this->pObj->MOD_SETTINGS['pages'];
109 $cshPagetreeOverview = BackendUtility::cshItem($dblist->descrTable, 'func_' . $optionKey, null, '<span class="btn btn-default btn-sm">|</span>');
110
111 $theOutput .= '<div class="form-inline form-inline-spaced">'
112 . $h_func
113 . '<div class="form-group">' . $cshPagetreeOverview . '</div>'
114 . '</div>'
115 . $dblist->HTMLcode;
116
117 // Additional footer content
118 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/web_info/class.tx_cms_webinfo.php']['drawFooterHook'] ?? [] as $hook) {
119 $params = [];
120 $theOutput .= GeneralUtility::callUserFunction($hook, $params, $this);
121 }
122 return $theOutput;
123 }
124
125 /**
126 * Function, which fills in the internal array, $this->allowedTableNames with all tables to
127 * which the user has access. Also a set of standard tables (pages, sys_filemounts, etc...)
128 * are filtered out. So what is left is basically all tables which makes sense to list content from.
129 *
130 * @return string[]
131 */
132 protected function cleanTableNames()
133 {
134 // Get all table names:
135 $tableNames = array_flip(array_keys($GLOBALS['TCA']));
136 // Unset common names:
137 unset($tableNames['pages']);
138 unset($tableNames['sys_filemounts']);
139 unset($tableNames['sys_action']);
140 unset($tableNames['sys_workflows']);
141 unset($tableNames['be_users']);
142 unset($tableNames['be_groups']);
143 $allowedTableNames = [];
144 // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
145 if (is_array($tableNames)) {
146 foreach ($tableNames as $k => $v) {
147 if (!$GLOBALS['TCA'][$k]['ctrl']['hideTable'] && $this->getBackendUser()->check('tables_select', $k)) {
148 $allowedTableNames['table_' . $k] = $k;
149 }
150 }
151 }
152 return $allowedTableNames;
153 }
154
155 /**
156 * @return BackendUserAuthentication
157 */
158 protected function getBackendUser()
159 {
160 return $GLOBALS['BE_USER'];
161 }
162 }