c9cada6bd5e9548f8b84620d04d9d7f6f8639148
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Controller / PageInformationController.php
1 <?php
2 namespace TYPO3\CMS\Frontend\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:frontend/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 = 1;
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 'no_cache',
79 'cache_timeout',
80 'php_tree_stop',
81 'TSconfig',
82 'is_siteroot',
83 'fe_login_mode'
84 ];
85 break;
86 default:
87 $dblist->fieldArray = [
88 'title',
89 'uid',
90 'alias',
91 'starttime',
92 'endtime',
93 'fe_group',
94 'target',
95 'url',
96 'shortcut',
97 'shortcut_mode'
98 ];
99 }
100
101 // PAGES:
102 $this->pObj->MOD_SETTINGS['pages_levels'] = $this->pObj->MOD_SETTINGS['depth'];
103 // ONLY for the sake of dblist module which uses this value.
104 $h_func = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[depth]', $this->pObj->MOD_SETTINGS['depth'], $this->pObj->MOD_MENU['depth']);
105 $h_func .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[pages]', $this->pObj->MOD_SETTINGS['pages'], $this->pObj->MOD_MENU['pages']);
106 $dblist->start($this->pObj->id, 'pages', 0);
107 $dblist->generateList();
108 // CSH
109 $theOutput .= '<div>';
110 $theOutput .= BackendUtility::cshItem($dblist->descrTable, 'pagetree_overview', null, '<span class="btn btn-default btn-sm">|</span><br />')
111 . '<div class="form-inline form-inline-spaced">'
112 . $h_func
113 . '</div>'
114 . $dblist->HTMLcode;
115 $theOutput .= '</div>';
116 // Additional footer content
117 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/web_info/class.tx_cms_webinfo.php']['drawFooterHook'];
118 if (is_array($footerContentHook)) {
119 foreach ($footerContentHook as $hook) {
120 $params = [];
121 $theOutput .= GeneralUtility::callUserFunction($hook, $params, $this);
122 }
123 }
124 return $theOutput;
125 }
126
127 /**
128 * Function, which fills in the internal array, $this->allowedTableNames with all tables to
129 * which the user has access. Also a set of standard tables (pages, sys_filemounts, etc...)
130 * are filtered out. So what is left is basically all tables which makes sense to list content from.
131 *
132 * @return string[]
133 */
134 protected function cleanTableNames()
135 {
136 // Get all table names:
137 $tableNames = array_flip(array_keys($GLOBALS['TCA']));
138 // Unset common names:
139 unset($tableNames['pages']);
140 unset($tableNames['sys_filemounts']);
141 unset($tableNames['sys_action']);
142 unset($tableNames['sys_workflows']);
143 unset($tableNames['be_users']);
144 unset($tableNames['be_groups']);
145 $allowedTableNames = [];
146 // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
147 if (is_array($tableNames)) {
148 foreach ($tableNames as $k => $v) {
149 if (!$GLOBALS['TCA'][$k]['ctrl']['hideTable'] && $this->getBackendUser()->check('tables_select', $k)) {
150 $allowedTableNames['table_' . $k] = $k;
151 }
152 }
153 }
154 return $allowedTableNames;
155 }
156
157 /**
158 * @return BackendUserAuthentication
159 */
160 protected function getBackendUser()
161 {
162 return $GLOBALS['BE_USER'];
163 }
164 }