‪TYPO3CMS  11.5
InfoPageTyposcriptConfigController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ServerRequestInterface;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
30 use TYPO3\CMS\Core\Page\PageRenderer;
31 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
36 
42 {
45 
49  protected ‪$view;
50 
54  protected ‪$pObj;
55 
59  protected ‪$id;
60 
62  {
63  $this->iconFactory = ‪$iconFactory;
64  $this->uriBuilder = ‪$uriBuilder;
65  }
66 
72  public function ‪init(‪InfoModuleController ‪$pObj, ServerRequestInterface $request)
73  {
74  $this->‪getLanguageService()->‪includeLLFile('EXT:info/Resources/Private/Language/InfoPageTsConfig.xlf');
75  $this->view = $this->‪getFluidTemplateObject();
76  $this->pObj = ‪$pObj;
77  $this->id = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
78  // Setting MOD_MENU items as we need them for logging:
79  $this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->modMenu());
80  }
81 
87  public function ‪main(ServerRequestInterface $request)
88  {
89  if ($this->id === 0) {
90  $this->view->assign('pageZero', true);
91  $pagesUsingTSConfig = $this->‪getOverviewOfPagesUsingTSConfig();
92  if (count($pagesUsingTSConfig) > 0) {
93  $this->view->assign('overviewOfPagesUsingTSConfig', $pagesUsingTSConfig);
94  }
95  } else {
96  if ((int)$this->pObj->MOD_SETTINGS['tsconf_parts'] === 99) {
97  $rootLine = BackendUtility::BEgetRootLine($this->id, '', true);
99  $TSparts = GeneralUtility::makeInstance(PageTsConfigLoader::class)->collect($rootLine);
100  $lines = [];
101  $pUids = [];
102 
103  foreach ($TSparts as $k => $v) {
104  $line = [];
105  if ($k === 'default') {
106  $title = $this->‪getLanguageService()->‪sL('LLL:EXT:info/Resources/Private/Language/InfoPageTsConfig.xlf:editTSconfig_default');
107  $line['title'] = $title;
108  } else {
109  // Remove the "page_" prefix
110  [, $pageId] = explode('_', $k, 3);
111  $pageId = (int)$pageId;
112  $pUids[] = $pageId;
113  $row = BackendUtility::getRecordWSOL('pages', $pageId);
114 
115  $icon = $this->iconFactory->getIconForRecord('pages', $row, ‪Icon::SIZE_SMALL);
116  $urlParameters = [
117  'edit' => [
118  'pages' => [
119  $pageId => 'edit',
120  ],
121  ],
122  'columnsOnly' => 'TSconfig,tsconfig_includes',
123  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
124  ];
125  $line['editIcon'] = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
126  $line['editTitle'] = 'editTSconfig';
127  $title = BackendUtility::getRecordTitle('pages', $row);
128  $line['title'] = BackendUtility::wrapClickMenuOnIcon($icon, 'pages', $row['uid']) . ' ' . htmlspecialchars($title);
129  }
130 
131  if (‪ExtensionManagementUtility::isLoaded('t3editor')) {
132  // @todo: Let EXT:t3editor add the deps via events in the render-loops above
133  $line['content'] = $this->‪getCodeMirrorHtml(
134  $title,
135  trim($v)
136  );
137  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
138  $pageRenderer->addCssFile('EXT:t3editor/Resources/Public/JavaScript/Contrib/codemirror/lib/codemirror.css');
139  $pageRenderer->addCssFile('EXT:t3editor/Resources/Public/Css/t3editor.css');
140  $pageRenderer->loadRequireJsModule('TYPO3/CMS/T3editor/Element/CodeMirrorElement');
141  } else {
142  $line['content'] = $this->‪getTextareaMarkup(trim($v));
143  }
144 
145  $lines[] = $line;
146  }
147 
148  if (!empty($pUids)) {
149  $urlParameters = [
150  'edit' => [
151  'pages' => [
152  implode(',', $pUids) => 'edit',
153  ],
154  ],
155  'columnsOnly' => 'TSconfig,tsconfig_includes',
156  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
157  ];
158  $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
159  $editIcon = htmlspecialchars($url);
160  $editTitle = 'editTSconfig_all';
161  } else {
162  $editIcon = '';
163  $editTitle = '';
164  }
165 
166  $this->view->assign('tsconfParts99', true);
167  $this->view->assign('csh', BackendUtility::cshItem('_MOD_web_info', 'tsconfig_edit', '', '|'));
168  $this->view->assign('lines', $lines);
169  $this->view->assign('editIcon', $editIcon);
170  $this->view->assign('editTitle', $editTitle);
171  } else {
172  $this->view->assign('tsconfParts99', false);
173  // Defined global here!
174  $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
175  $tmpl->ext_expandAllNotes = 1;
176  $tmpl->ext_noPMicons = 1;
177 
178  $pageTsConfig = BackendUtility::getPagesTSconfig($this->id);
179  switch ($this->pObj->MOD_SETTINGS['tsconf_parts']) {
180  case '1':
181  $pageTsConfig = $pageTsConfig['mod.'] ?? [];
182  break;
183  case '1a':
184  $pageTsConfig = $pageTsConfig['mod.']['web_layout.'] ?? [];
185  break;
186  case '1b':
187  $pageTsConfig = $pageTsConfig['mod.']['web_view.'] ?? [];
188  break;
189  case '1d':
190  $pageTsConfig = $pageTsConfig['mod.']['web_list.'] ?? [];
191  break;
192  case '1e':
193  $pageTsConfig = $pageTsConfig['mod.']['web_info.'] ?? [];
194  break;
195  case '1g':
196  $pageTsConfig = $pageTsConfig['mod.']['web_ts.'] ?? [];
197  break;
198  case '2':
199  $pageTsConfig = $pageTsConfig['RTE.'] ?? [];
200  break;
201  case '5':
202  $pageTsConfig = $pageTsConfig['TCEFORM.'] ?? [];
203  break;
204  case '6':
205  $pageTsConfig = $pageTsConfig['TCEMAIN.'] ?? [];
206  break;
207  case '7':
208  $pageTsConfig = $pageTsConfig['TCAdefaults.'] ?? [];
209  break;
210  case '4':
211  $pageTsConfig = $pageTsConfig['user.'] ?? [];
212  break;
213  default:
214  // Entire array
215  }
216 
217  $this->view->assign('csh', BackendUtility::cshItem('_MOD_web_info', 'tsconfig_hierarchy', '', '|'));
218  $this->view->assign('tree', $tmpl->ext_getObjTree($pageTsConfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort'] ?? '0'));
219  }
220  $this->view->assign('alphaSort', BackendUtility::getFuncCheck($this->id, 'SET[tsconf_alphaSort]', $this->pObj->MOD_SETTINGS['tsconf_alphaSort'] ?? false, '', '', 'id="checkTsconf_alphaSort"'));
221  $this->view->assign('dropdownMenu', BackendUtility::getDropdownMenu($this->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']));
222  }
223  return $this->view->render();
224  }
225 
231  protected function ‪modMenu()
232  {
233  $lang = $this->‪getLanguageService();
234  $modMenuAdd = [
235  'tsconf_parts' => [
236  0 => $lang->getLL('tsconf_parts_0'),
237  1 => $lang->getLL('tsconf_parts_1') . ' [mod.]',
238  '1a' => $lang->getLL('tsconf_parts_1a') . ' [mod.web_layout.]',
239  '1b' => $lang->getLL('tsconf_parts_1b') . ' [mod.web_view.]',
240  '1d' => $lang->getLL('tsconf_parts_1d') . ' [mod.web_list.]',
241  '1e' => $lang->getLL('tsconf_parts_1e') . ' [mod.web_info.]',
242  '1g' => $lang->getLL('tsconf_parts_1g') . ' [mod.web_ts.]',
243  2 => '[RTE.]',
244  7 => '[TCAdefaults.]',
245  5 => '[TCEFORM.]',
246  6 => '[TCEMAIN.]',
247  4 => '[user.]',
248  99 => $lang->getLL('tsconf_configFields'),
249  ],
250  'tsconf_alphaSort' => '1',
251  ];
252  if (!$this->‪getBackendUser()->isAdmin()) {
253  unset($modMenuAdd['tsconf_parts'][99]);
254  }
255  return $modMenuAdd;
256  }
257 
263  protected function ‪getOverviewOfPagesUsingTSConfig()
264  {
265  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
266  $queryBuilder->getRestrictions()
267  ->removeAll()
268  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
269  ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, 0));
270 
271  $res = $queryBuilder
272  ->select('uid', 'TSconfig')
273  ->from('pages')
274  ->where(
275  $queryBuilder->expr()->neq(
276  'TSconfig',
277  $queryBuilder->createNamedParameter('', ‪Connection::PARAM_STR)
278  )
279  )
280  ->executeQuery();
281 
282  $pageArray = [];
283 
284  while ($row = $res->fetchAssociative()) {
285  $this->‪setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
286  }
287  return $this->‪getList($pageArray);
288  }
289 
299  protected function ‪setInPageArray(&$hierarchicArray, $rootlineArray, $row)
300  {
301  ksort($rootlineArray);
302  reset($rootlineArray);
303  if (!$rootlineArray[0]['uid']) {
304  array_shift($rootlineArray);
305  }
306  $currentElement = current($rootlineArray);
307  $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
308  array_shift($rootlineArray);
309  if (!empty($rootlineArray)) {
310  if (!isset($hierarchicArray[$currentElement['uid'] . '.'])) {
311  $hierarchicArray[$currentElement['uid'] . '.'] = [];
312  }
313  $this->‪setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
314  } else {
315  $hierarchicArray[$currentElement['uid'] . '_'] = $this->‪extractLinesFromTSConfig($row);
316  }
317  }
318 
325  protected function ‪extractLinesFromTSConfig(array $row)
326  {
327  $out = [];
328  $includeLines = 0;
329  $out['uid'] = $row['uid'];
330  $lines = ‪GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
331  foreach ($lines as $line) {
332  if (str_contains($line, '<INCLUDE_TYPOSCRIPT:')) {
333  $includeLines++;
334  }
335  }
336  $out['includeLines'] = $includeLines;
337  $out['writtenLines'] = (count($lines) - $includeLines);
338  return $out;
339  }
340 
350  protected function ‪getList($pageArray, $lines = [], $pageDepth = 0)
351  {
352  if (!is_array($pageArray)) {
353  return $lines;
354  }
355 
356  foreach ($pageArray as $identifier => $_) {
357  if (!‪MathUtility::canBeInterpretedAsInteger($identifier)) {
358  continue;
359  }
360  $line = [];
361  $line['padding'] = ($pageDepth * 20) + 10;
362  if (isset($pageArray[$identifier . '_'])) {
363  $line['link'] = $this->uriBuilder->buildUriFromRoute('web_info', ['id' => $identifier]);
364  $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), ‪Icon::SIZE_SMALL)->render();
365  $line['title'] = 'ID: ' . $identifier;
366  $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
367  $line['includedFiles'] = ($pageArray[$identifier . '_']['includeLines'] === 0 ? '' : $pageArray[$identifier . '_']['includeLines']);
368  $line['lines'] = ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']);
369  } else {
370  $line['link'] = '';
371  $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), ‪Icon::SIZE_SMALL)->render();
372  $line['title'] = '';
373  $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
374  $line['includedFiles'] = '';
375  $line['lines'] = '';
376  }
377  $lines[] = $line;
378  $lines = $this->‪getList($pageArray[$identifier . '.'] ?? [], $lines, $pageDepth + 1);
379  }
380  return $lines;
381  }
382 
388  protected function ‪getFluidTemplateObject()
389  {
390  ‪$view = GeneralUtility::makeInstance(StandaloneView::class);
391  ‪$view->‪setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Layouts')]);
392  ‪$view->‪setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Partials')]);
393  ‪$view->‪setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates')]);
394 
395  ‪$view->‪setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates/PageTsConfig.html'));
396 
398  return ‪$view;
399  }
400 
401  protected function ‪getCodeMirrorHtml(string $label, string $content): string
402  {
403  $codeMirrorConfig = [
404  'label' => $label,
405  'panel' => 'top',
406  'mode' => 'TYPO3/CMS/T3editor/Mode/typoscript/typoscript',
407  'autoheight' => 'true',
408  'nolazyload' => 'true',
409  'options' => GeneralUtility::jsonEncodeForHtmlAttribute([
410  'readOnly' => true,
411  'format' => 'typoscript',
412  'rows' => 'auto',
413  ], false),
414  ];
415  $textareaAttributes = [
416  'rows' => (string)count(explode(LF, $content)),
417  'readonly' => 'readonly',
418  ];
419 
420  $code = '<typo3-t3editor-codemirror ' . GeneralUtility::implodeAttributes($codeMirrorConfig, true) . '>';
421  $code .= '<textarea ' . GeneralUtility::implodeAttributes($textareaAttributes, true) . '>' . htmlspecialchars($content) . '</textarea>';
422  $code .= '</typo3-t3editor-codemirror>';
423 
424  return $code;
425  }
426 
427  protected function ‪getTextareaMarkup(string $content): string
428  {
429  return '<textarea class="form-control" rows="' . (string)count(explode(LF, $content)) . '" disabled>'
430  . htmlspecialchars($content)
431  . '</textarea>';
432  }
433 
437  protected function ‪getBackendUser(): BackendUserAuthentication
438  {
439  return ‪$GLOBALS['BE_USER'];
440  }
441 
445  protected function ‪getLanguageService(): LanguageService
446  {
447  return ‪$GLOBALS['LANG'];
448  }
449 }
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$pObj
‪InfoModuleController $pObj
Definition: InfoPageTyposcriptConfigController.php:52
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\__construct
‪__construct(IconFactory $iconFactory, UriBuilder $uriBuilder)
Definition: InfoPageTyposcriptConfigController.php:59
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Info\Controller\InfoModuleController
Definition: InfoModuleController.php:45
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\setInPageArray
‪setInPageArray(&$hierarchicArray, $rootlineArray, $row)
Definition: InfoPageTyposcriptConfigController.php:297
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\init
‪init(InfoModuleController $pObj, ServerRequestInterface $request)
Definition: InfoPageTyposcriptConfigController.php:70
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\extractLinesFromTSConfig
‪array extractLinesFromTSConfig(array $row)
Definition: InfoPageTyposcriptConfigController.php:323
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getOverviewOfPagesUsingTSConfig
‪array getOverviewOfPagesUsingTSConfig()
Definition: InfoPageTyposcriptConfigController.php:261
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getTextareaMarkup
‪getTextareaMarkup(string $content)
Definition: InfoPageTyposcriptConfigController.php:425
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader
Definition: PageTsConfigLoader.php:39
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getCodeMirrorHtml
‪getCodeMirrorHtml(string $label, string $content)
Definition: InfoPageTyposcriptConfigController.php:399
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject()
Definition: InfoPageTyposcriptConfigController.php:386
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:161
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\modMenu
‪array modMenu()
Definition: InfoPageTyposcriptConfigController.php:229
‪TYPO3\CMS\Core\Database\Connection\PARAM_STR
‪const PARAM_STR
Definition: Connection.php:54
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$id
‪$id
Definition: InfoPageTyposcriptConfigController.php:57
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: InfoPageTyposcriptConfigController.php:435
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$uriBuilder
‪UriBuilder $uriBuilder
Definition: InfoPageTyposcriptConfigController.php:44
‪TYPO3\CMS\Fluid\View\StandaloneView\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: StandaloneView.php:93
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getList
‪array getList($pageArray, $lines=[], $pageDepth=0)
Definition: InfoPageTyposcriptConfigController.php:348
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\main
‪string main(ServerRequestInterface $request)
Definition: InfoPageTyposcriptConfigController.php:85
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerExtensionName
‪setControllerExtensionName($controllerExtensionName)
Definition: Request.php:305
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplatePathAndFilename
‪setTemplatePathAndFilename($templatePathAndFilename)
Definition: AbstractTemplateView.php:113
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$iconFactory
‪IconFactory $iconFactory
Definition: InfoPageTyposcriptConfigController.php:43
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: AbstractTemplateView.php:177
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getLanguageService
‪LanguageService getLanguageService()
Definition: InfoPageTyposcriptConfigController.php:443
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef)
Definition: LanguageService.php:271
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: AbstractTemplateView.php:144
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$view
‪StandaloneView $view
Definition: InfoPageTyposcriptConfigController.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114
‪TYPO3\CMS\Info\Controller
Definition: InfoModuleController.php:16
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController
Definition: InfoPageTyposcriptConfigController.php:42
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplateRootPaths
‪setTemplateRootPaths(array $templateRootPaths)
Definition: AbstractTemplateView.php:124
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:40