[BUGFIX] Remove double encoding from link
[Packages/TYPO3.CMS.git] / typo3 / sysext / info_pagetsconfig / Classes / Controller / InfoPageTyposcriptConfigController.php
1 <?php
2 namespace TYPO3\CMS\InfoPagetsconfig\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\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
20 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Core\Utility\MathUtility;
25 use TYPO3\CMS\Fluid\View\StandaloneView;
26
27 /**
28 * Page TSconfig viewer
29 */
30 class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
31 {
32 /**
33 * @var IconFactory
34 */
35 protected $iconFactory;
36
37 /**
38 * @var StandaloneView
39 */
40 protected $view;
41
42 /**
43 * Constructor
44 */
45 public function __construct()
46 {
47 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
48 $this->getLanguageService()->includeLLFile('EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf');
49
50 $this->view = $this->getFluidTemplateObject();
51 }
52
53 /**
54 * Function menu initialization
55 *
56 * @return array Menu array
57 */
58 public function modMenu()
59 {
60 $lang = $this->getLanguageService();
61 $modMenuAdd = [
62 'tsconf_parts' => [
63 0 => $lang->getLL('tsconf_parts_0'),
64 1 => $lang->getLL('tsconf_parts_1'),
65 '1a' => $lang->getLL('tsconf_parts_1a'),
66 '1b' => $lang->getLL('tsconf_parts_1b'),
67 '1c' => $lang->getLL('tsconf_parts_1c'),
68 '1d' => $lang->getLL('tsconf_parts_1d'),
69 '1e' => $lang->getLL('tsconf_parts_1e'),
70 '1f' => $lang->getLL('tsconf_parts_1f'),
71 '1g' => $lang->getLL('tsconf_parts_1g'),
72 2 => 'RTE.',
73 5 => 'TCEFORM.',
74 6 => 'TCEMAIN.',
75 3 => 'TSFE.',
76 4 => 'user.',
77 99 => $lang->getLL('tsconf_configFields')
78 ],
79 'tsconf_alphaSort' => '1'
80 ];
81 if (!$this->getBackendUser()->isAdmin()) {
82 unset($modMenuAdd['tsconf_parts'][99]);
83 }
84 return $modMenuAdd;
85 }
86
87 /**
88 * Main function of class
89 *
90 * @return string HTML output
91 */
92 public function main()
93 {
94 $pageId = (int)(GeneralUtility::_GP('id'));
95
96 if ($pageId === 0) {
97 $this->view->assign('pageZero', 1);
98 $this->view->assign('overviewOfPagesUsingTSConfig', $this->getOverviewOfPagesUsingTSConfig());
99 } else {
100 if ($this->pObj->MOD_SETTINGS['tsconf_parts'] == 99) {
101 $TSparts = BackendUtility::getPagesTSconfig($this->pObj->id, null, true);
102 $lines = [];
103 $pUids = [];
104
105 foreach ($TSparts as $k => $v) {
106 if ($k != 'uid_0') {
107 $line = [];
108 if ($k == 'defaultPageTSconfig') {
109 $line['defaultPageTSconfig'] = 1;
110 } else {
111 $pUids[] = substr($k, 4);
112 $row = BackendUtility::getRecordWSOL('pages', substr($k, 4));
113
114 $icon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL);
115 $editIdList = substr($k, 4);
116 $urlParameters = [
117 'edit' => [
118 'pages' => [
119 $editIdList => 'edit',
120 ]
121 ],
122 'columnsOnly' => 'TSconfig',
123 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
124 ];
125 $line['editIcon'] = BackendUtility::getModuleUrl('record_edit', $urlParameters);
126 $line['editTitle'] = 'editTSconfig';
127 $line['title'] = BackendUtility::wrapClickMenuOnIcon($icon, 'pages', $row['uid'])
128 . ' ' . htmlspecialchars(BackendUtility::getRecordTitle('pages', $row));
129 }
130 $tsparser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
131 $tsparser->lineNumberOffset = 0;
132 $line['content'] = $tsparser->doSyntaxHighlight(trim($v) . LF);
133 $lines[] = $line;
134 }
135 }
136
137 if (!empty($pUids)) {
138 $urlParameters = [
139 'edit' => [
140 'pages' => [
141 implode(',', $pUids) => 'edit',
142 ]
143 ],
144 'columnsOnly' => 'TSconfig',
145 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
146 ];
147 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
148 $editIcon = htmlspecialchars($url);
149 $editTitle = 'editTSconfig_all';
150 } else {
151 $editIcon = '';
152 $editTitle = '';
153 }
154
155 $this->view->assign('tsconfParts99', 1);
156 $this->view->assign('csh', BackendUtility::cshItem('_MOD_web_info', 'tsconfig_edit', null, '|'));
157 $this->view->assign('lines', $lines);
158 $this->view->assign('editIcon', $editIcon);
159 $this->view->assign('editTitle', $editTitle);
160 } else {
161 $this->view->assign('tsconfParts99', 0);
162 // Defined global here!
163 $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
164 $tmpl->ext_expandAllNotes = 1;
165 $tmpl->ext_noPMicons = 1;
166
167 $beUser = $this->getBackendUser();
168 switch ($this->pObj->MOD_SETTINGS['tsconf_parts']) {
169 case '1':
170 $modTSconfig = BackendUtility::getModTSconfig($this->pObj->id, 'mod');
171 break;
172 case '1a':
173 $modTSconfig = $beUser->getTSConfig('mod.web_layout', BackendUtility::getPagesTSconfig($this->pObj->id));
174 break;
175 case '1b':
176 $modTSconfig = $beUser->getTSConfig('mod.web_view', BackendUtility::getPagesTSconfig($this->pObj->id));
177 break;
178 case '1c':
179 $modTSconfig = $beUser->getTSConfig('mod.web_modules', BackendUtility::getPagesTSconfig($this->pObj->id));
180 break;
181 case '1d':
182 $modTSconfig = $beUser->getTSConfig('mod.web_list', BackendUtility::getPagesTSconfig($this->pObj->id));
183 break;
184 case '1e':
185 $modTSconfig = $beUser->getTSConfig('mod.web_info', BackendUtility::getPagesTSconfig($this->pObj->id));
186 break;
187 case '1f':
188 $modTSconfig = $beUser->getTSConfig('mod.web_func', BackendUtility::getPagesTSconfig($this->pObj->id));
189 break;
190 case '1g':
191 $modTSconfig = $beUser->getTSConfig('mod.web_ts', BackendUtility::getPagesTSconfig($this->pObj->id));
192 break;
193 case '2':
194 $modTSconfig = $beUser->getTSConfig('RTE', BackendUtility::getPagesTSconfig($this->pObj->id));
195 break;
196 case '5':
197 $modTSconfig = $beUser->getTSConfig('TCEFORM', BackendUtility::getPagesTSconfig($this->pObj->id));
198 break;
199 case '6':
200 $modTSconfig = $beUser->getTSConfig('TCEMAIN', BackendUtility::getPagesTSconfig($this->pObj->id));
201 break;
202 case '3':
203 $modTSconfig = $beUser->getTSConfig('TSFE', BackendUtility::getPagesTSconfig($this->pObj->id));
204 break;
205 case '4':
206 $modTSconfig = $beUser->getTSConfig('user', BackendUtility::getPagesTSconfig($this->pObj->id));
207 break;
208 default:
209 $modTSconfig['properties'] = BackendUtility::getPagesTSconfig($this->pObj->id);
210 }
211
212 $modTSconfig = $modTSconfig['properties'];
213 if (!is_array($modTSconfig)) {
214 $modTSconfig = [];
215 }
216
217 $this->view->assign('csh', BackendUtility::cshItem('_MOD_web_info', 'tsconfig_hierarchy', null, '|'));
218 $this->view->assign('tree', $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']));
219 }
220 $this->view->assign('alphaSort', BackendUtility::getFuncCheck($this->pObj->id, 'SET[tsconf_alphaSort]', $this->pObj->MOD_SETTINGS['tsconf_alphaSort'], '', '', 'id="checkTsconf_alphaSort"'));
221 $this->view->assign('dropdownMenu', BackendUtility::getDropdownMenu($this->pObj->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']));
222 }
223 return $this->view->render();
224 }
225
226 /**
227 * Renders table rows of all pages containing TSConfig together with its rootline
228 *
229 * @return array
230 */
231 protected function getOverviewOfPagesUsingTSConfig()
232 {
233 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
234 $queryBuilder->getRestrictions()
235 ->removeAll()
236 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
237 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
238
239 $res = $queryBuilder
240 ->select('uid', 'TSconfig')
241 ->from('pages')
242 ->where($queryBuilder->expr()->neq('TSconfig', $queryBuilder->quote('')))
243 ->groupBy('uid')
244 ->execute();
245
246 $pageArray = [];
247
248 while ($row = $res->fetch()) {
249 $this->setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
250 }
251 return $this->getList($pageArray);
252 }
253
254 /**
255 * Set page in array
256 * This function is called recursively and builds a multi-dimensional array that reflects the page
257 * hierarchy.
258 *
259 * @param array $hierarchicArray The hierarchic array (passed by reference)
260 * @param array $rootlineArray The rootline array
261 * @param array $row The row from the database containing the uid and TSConfig fields
262 * @return void
263 */
264 protected function setInPageArray(&$hierarchicArray, $rootlineArray, $row)
265 {
266 ksort($rootlineArray);
267 reset($rootlineArray);
268 if (!$rootlineArray[0]['uid']) {
269 array_shift($rootlineArray);
270 }
271 $currentElement = current($rootlineArray);
272 $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
273 array_shift($rootlineArray);
274 if (!empty($rootlineArray)) {
275 if (!isset($hierarchicArray[$currentElement['uid'] . '.'])) {
276 $hierarchicArray[$currentElement['uid'] . '.'] = [];
277 }
278 $this->setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
279 } else {
280 $hierarchicArray[$currentElement['uid'] . '_'] = $this->extractLinesFromTSConfig($row);
281 }
282 }
283
284 /**
285 * Extract the lines of TSConfig from a given pages row
286 *
287 * @param array $row The row from the database containing the uid and TSConfig fields
288 * @return array
289 */
290 protected function extractLinesFromTSConfig(array $row)
291 {
292 $out = [];
293 $includeLines = 0;
294 $out['uid'] = $row['uid'];
295 $lines = GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
296 foreach ($lines as $line) {
297 if (strpos($line, '<INCLUDE_TYPOSCRIPT:') !== false) {
298 $includeLines++;
299 }
300 }
301 $out['includeLines'] = $includeLines;
302 $out['writtenLines'] = (count($lines) - $includeLines);
303 return $out;
304 }
305
306 /**
307 * Get the list of pages to show.
308 * This function is called recursively
309 *
310 * @param array $pageArray The Page Array
311 * @param array $lines Lines that have been processed up to this point
312 * @param int $pageDepth The level of the current $pageArray being processed
313 * @return array
314 */
315 protected function getList($pageArray, $lines = [], $pageDepth = 0)
316 {
317 if (!is_array($pageArray)) {
318 return $lines;
319 }
320
321 foreach ($pageArray as $identifier => $_) {
322 if (!MathUtility::canBeInterpretedAsInteger($identifier)) {
323 continue;
324 }
325 $line = [];
326 $line['padding'] = ($pageDepth * 20);
327 if (isset($pageArray[$identifier . '_'])) {
328 $line['link'] = GeneralUtility::linkThisScript(['id' => $identifier]);
329 $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
330 $line['title'] = 'ID: ' . $identifier;
331 $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
332 $line['includedFiles'] = ($pageArray[$identifier . '_']['includeLines'] === 0 ? '' : $pageArray[($identifier . '_')]['includeLines']);
333 $line['lines'] = ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']);
334 } else {
335 $line['link'] = '';
336 $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
337 $line['title'] = '';
338 $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
339 $line['includedFiles'] = '';
340 $line['lines'] = '';
341 }
342 $lines[] = $line;
343 $lines = $this->getList($pageArray[$identifier . '.'], $lines, $pageDepth + 1);
344 }
345 return $lines;
346 }
347
348 /**
349 * Returns LanguageService
350 *
351 * @return \TYPO3\CMS\Lang\LanguageService
352 */
353 protected function getLanguageService()
354 {
355 return $GLOBALS['LANG'];
356 }
357
358 /**
359 * Returns the current BE user.
360 *
361 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
362 */
363 protected function getBackendUser()
364 {
365 return $GLOBALS['BE_USER'];
366 }
367
368 /**
369 * returns a new standalone view, shorthand function
370 *
371 * @return StandaloneView
372 */
373 protected function getFluidTemplateObject()
374 {
375 /** @var StandaloneView $view */
376 $view = GeneralUtility::makeInstance(StandaloneView::class);
377 $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Layouts')]);
378 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Partials')]);
379 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Templates')]);
380
381 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Templates/Main.html'));
382
383 $view->getRequest()->setControllerExtensionName('info_pagetsconfig');
384 return $view;
385 }
386 }