‪TYPO3CMS  10.4
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 
33 
39 {
43  protected ‪$iconFactory;
44 
48  protected ‪$view;
49 
53  protected ‪$pObj;
54 
58  protected ‪$id;
59 
65  public function ‪init(‪$pObj)
66  {
67  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
68  $this->‪getLanguageService()->‪includeLLFile('EXT:info/Resources/Private/Language/InfoPageTsConfig.xlf');
69  $this->view = $this->‪getFluidTemplateObject();
70  $this->pObj = ‪$pObj;
71  $this->id = (int)GeneralUtility::_GP('id');
72  // Setting MOD_MENU items as we need them for logging:
73  $this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->modMenu());
74  }
75 
81  public function ‪main()
82  {
83  $pageId = (int)GeneralUtility::_GP('id');
84  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
85 
86  if ($pageId === 0) {
87  $this->view->assign('pageZero', 1);
88  $pagesUsingTSConfig = $this->‪getOverviewOfPagesUsingTSConfig();
89  if (count($pagesUsingTSConfig) > 0) {
90  $this->view->assign('overviewOfPagesUsingTSConfig', $pagesUsingTSConfig);
91  }
92  } else {
93  if ($this->pObj->MOD_SETTINGS['tsconf_parts'] == 99) {
94  $rootLine = ‪BackendUtility::BEgetRootLine($this->id, '', true);
96  $TSparts = GeneralUtility::makeInstance(PageTsConfigLoader::class)->collect($rootLine);
97  $lines = [];
98  $pUids = [];
99 
100  foreach ($TSparts as $k => $v) {
101  $line = [];
102  if ($k === 'default') {
103  $line['defaultPageTSconfig'] = 1;
104  } else {
105  // Remove the "page_" prefix
106  [, $pageId] = explode('_', $k, 3);
107  $pageId = (int)$pageId;
108  $pUids[] = $pageId;
109  $row = ‪BackendUtility::getRecordWSOL('pages', $pageId);
110 
111  $icon = $this->iconFactory->getIconForRecord('pages', $row, ‪Icon::SIZE_SMALL);
112  $urlParameters = [
113  'edit' => [
114  'pages' => [
115  $pageId => 'edit',
116  ]
117  ],
118  'columnsOnly' => 'TSconfig,tsconfig_includes',
119  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
120  ];
121  $line['editIcon'] = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
122  $line['editTitle'] = 'editTSconfig';
123  $line['title'] = ‪BackendUtility::wrapClickMenuOnIcon($icon, 'pages', $row['uid'])
124  . ' ' . htmlspecialchars(‪BackendUtility::getRecordTitle('pages', $row));
125  }
126  $tsparser = GeneralUtility::makeInstance(TypoScriptParser::class);
127  $tsparser->lineNumberOffset = 0;
128  $line['content'] = $tsparser->doSyntaxHighlight(trim($v) . LF);
129  $lines[] = $line;
130  }
131 
132  if (!empty($pUids)) {
133  $urlParameters = [
134  'edit' => [
135  'pages' => [
136  implode(',', $pUids) => 'edit',
137  ]
138  ],
139  'columnsOnly' => 'TSconfig,tsconfig_includes',
140  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
141  ];
142  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
143  $editIcon = htmlspecialchars($url);
144  $editTitle = 'editTSconfig_all';
145  } else {
146  $editIcon = '';
147  $editTitle = '';
148  }
149 
150  $this->view->assign('tsconfParts99', 1);
151  $this->view->assign('csh', ‪BackendUtility::cshItem('_MOD_web_info', 'tsconfig_edit', '', '|'));
152  $this->view->assign('lines', $lines);
153  $this->view->assign('editIcon', $editIcon);
154  $this->view->assign('editTitle', $editTitle);
155  } else {
156  $this->view->assign('tsconfParts99', 0);
157  // Defined global here!
158  $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
159  $tmpl->ext_expandAllNotes = 1;
160  $tmpl->ext_noPMicons = 1;
161 
162  $pageTsConfig = ‪BackendUtility::getPagesTSconfig($this->id);
163  switch ($this->pObj->MOD_SETTINGS['tsconf_parts']) {
164  case '1':
165  $pageTsConfig = $pageTsConfig['mod.'] ?? [];
166  break;
167  case '1a':
168  $pageTsConfig = $pageTsConfig['mod.']['web_layout.'] ?? [];
169  break;
170  case '1b':
171  $pageTsConfig = $pageTsConfig['mod.']['web_view.'] ?? [];
172  break;
173  case '1c':
174  $pageTsConfig = $pageTsConfig['mod.']['web_modules.'] ?? [];
175  break;
176  case '1d':
177  $pageTsConfig = $pageTsConfig['mod.']['web_list.'] ?? [];
178  break;
179  case '1e':
180  $pageTsConfig = $pageTsConfig['mod.']['web_info.'] ?? [];
181  break;
182  case '1g':
183  $pageTsConfig = $pageTsConfig['mod.']['web_ts.'] ?? [];
184  break;
185  case '2':
186  $pageTsConfig = $pageTsConfig['RTE.'] ?? [];
187  break;
188  case '5':
189  $pageTsConfig = $pageTsConfig['TCEFORM.'] ?? [];
190  break;
191  case '6':
192  $pageTsConfig = $pageTsConfig['TCEMAIN.'] ?? [];
193  break;
194  case '7':
195  $pageTsConfig = $pageTsConfig['TCAdefaults.'] ?? [];
196  break;
197  case '4':
198  $pageTsConfig = $pageTsConfig['user.'] ?? [];
199  break;
200  default:
201  // Entire array
202  }
203 
204  $this->view->assign('csh', ‪BackendUtility::cshItem('_MOD_web_info', 'tsconfig_hierarchy', '', '|'));
205  $this->view->assign('tree', $tmpl->ext_getObjTree($pageTsConfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']));
206  }
207  $this->view->assign('alphaSort', ‪BackendUtility::getFuncCheck($this->id, 'SET[tsconf_alphaSort]', $this->pObj->MOD_SETTINGS['tsconf_alphaSort'], '', '', 'id="checkTsconf_alphaSort"'));
208  $this->view->assign('dropdownMenu', ‪BackendUtility::getDropdownMenu($this->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']));
209  }
210  return $this->view->render();
211  }
212 
218  protected function ‪modMenu()
219  {
220  $lang = $this->‪getLanguageService();
221  $modMenuAdd = [
222  'tsconf_parts' => [
223  0 => $lang->getLL('tsconf_parts_0'),
224  1 => $lang->getLL('tsconf_parts_1') . ' [mod.]',
225  '1a' => $lang->getLL('tsconf_parts_1a') . ' [mod.web_layout.]',
226  '1b' => $lang->getLL('tsconf_parts_1b') . ' [mod.web_view.]',
227  '1c' => $lang->getLL('tsconf_parts_1c') . ' [mod.web_modules.]',
228  '1d' => $lang->getLL('tsconf_parts_1d') . ' [mod.web_list.]',
229  '1e' => $lang->getLL('tsconf_parts_1e') . ' [mod.web_info.]',
230  '1g' => $lang->getLL('tsconf_parts_1g') . ' [mod.web_ts.]',
231  2 => '[RTE.]',
232  7 => '[TCAdefaults.]',
233  5 => '[TCEFORM.]',
234  6 => '[TCEMAIN.]',
235  4 => '[user.]',
236  99 => $lang->getLL('tsconf_configFields')
237  ],
238  'tsconf_alphaSort' => '1'
239  ];
240  if (!$this->‪getBackendUser()->isAdmin()) {
241  unset($modMenuAdd['tsconf_parts'][99]);
242  }
243  return $modMenuAdd;
244  }
245 
251  protected function ‪getOverviewOfPagesUsingTSConfig()
252  {
253  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
254  $queryBuilder->getRestrictions()
255  ->removeAll()
256  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
257  ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, 0));
258 
259  $res = $queryBuilder
260  ->select('uid', 'TSconfig')
261  ->from('pages')
262  ->where(
263  $queryBuilder->expr()->neq(
264  'TSconfig',
265  $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)
266  )
267  )
268  ->execute();
269 
270  $pageArray = [];
271 
272  while ($row = $res->fetch()) {
273  $this->‪setInPageArray($pageArray, ‪BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
274  }
275  return $this->‪getList($pageArray);
276  }
277 
287  protected function ‪setInPageArray(&$hierarchicArray, $rootlineArray, $row)
288  {
289  ksort($rootlineArray);
290  reset($rootlineArray);
291  if (!$rootlineArray[0]['uid']) {
292  array_shift($rootlineArray);
293  }
294  $currentElement = current($rootlineArray);
295  $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
296  array_shift($rootlineArray);
297  if (!empty($rootlineArray)) {
298  if (!isset($hierarchicArray[$currentElement['uid'] . '.'])) {
299  $hierarchicArray[$currentElement['uid'] . '.'] = [];
300  }
301  $this->‪setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
302  } else {
303  $hierarchicArray[$currentElement['uid'] . '_'] = $this->‪extractLinesFromTSConfig($row);
304  }
305  }
306 
313  protected function ‪extractLinesFromTSConfig(array $row)
314  {
315  $out = [];
316  $includeLines = 0;
317  $out['uid'] = $row['uid'];
318  $lines = ‪GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
319  foreach ($lines as $line) {
320  if (strpos($line, '<INCLUDE_TYPOSCRIPT:') !== false) {
321  $includeLines++;
322  }
323  }
324  $out['includeLines'] = $includeLines;
325  $out['writtenLines'] = (count($lines) - $includeLines);
326  return $out;
327  }
328 
338  protected function ‪getList($pageArray, $lines = [], $pageDepth = 0)
339  {
340  if (!is_array($pageArray)) {
341  return $lines;
342  }
343 
344  foreach ($pageArray as $identifier => $_) {
345  if (!‪MathUtility::canBeInterpretedAsInteger($identifier)) {
346  continue;
347  }
348  $line = [];
349  $line['padding'] = ($pageDepth * 20) + 10;
350  if (isset($pageArray[$identifier . '_'])) {
351  $line['link'] = GeneralUtility::linkThisScript(['id' => $identifier]);
352  $line['icon'] = $this->iconFactory->getIconForRecord('pages', ‪BackendUtility::getRecordWSOL('pages', $identifier), ‪Icon::SIZE_SMALL)->render();
353  $line['title'] = 'ID: ' . $identifier;
354  $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
355  $line['includedFiles'] = ($pageArray[$identifier . '_']['includeLines'] === 0 ? '' : $pageArray[$identifier . '_']['includeLines']);
356  $line['lines'] = ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']);
357  } else {
358  $line['link'] = '';
359  $line['icon'] = $this->iconFactory->getIconForRecord('pages', ‪BackendUtility::getRecordWSOL('pages', $identifier), ‪Icon::SIZE_SMALL)->render();
360  $line['title'] = '';
361  $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
362  $line['includedFiles'] = '';
363  $line['lines'] = '';
364  }
365  $lines[] = $line;
366  $lines = $this->‪getList($pageArray[$identifier . '.'], $lines, $pageDepth + 1);
367  }
368  return $lines;
369  }
370 
376  protected function ‪getFluidTemplateObject()
377  {
378  ‪$view = GeneralUtility::makeInstance(StandaloneView::class);
379  ‪$view->‪setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Layouts')]);
380  ‪$view->‪setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Partials')]);
381  ‪$view->‪setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates')]);
382 
383  ‪$view->‪setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates/PageTsConfig.html'));
384 
386  return ‪$view;
387  }
388 
392  protected function ‪getBackendUser(): ‪BackendUserAuthentication
393  {
394  return ‪$GLOBALS['BE_USER'];
395  }
396 
400  protected function ‪getLanguageService(): ‪LanguageService
401  {
402  return ‪$GLOBALS['LANG'];
403  }
404 }
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$pObj
‪InfoModuleController $pObj
Definition: InfoPageTyposcriptConfigController.php:50
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Info\Controller\InfoModuleController
Definition: InfoModuleController.php:41
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef, $setGlobal=null, $mergeLocalOntoDefault=null)
Definition: LanguageService.php:297
‪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:284
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
Definition: TypoScriptParser.php:37
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\extractLinesFromTSConfig
‪array extractLinesFromTSConfig(array $row)
Definition: InfoPageTyposcriptConfigController.php:310
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getOverviewOfPagesUsingTSConfig
‪array getOverviewOfPagesUsingTSConfig()
Definition: InfoPageTyposcriptConfigController.php:248
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader
Definition: PageTsConfigLoader.php:39
‪TYPO3\CMS\Backend\Utility\BackendUtility\cshItem
‪static string cshItem($table, $field, $_='', $wrap='')
Definition: BackendUtility.php:2306
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject()
Definition: InfoPageTyposcriptConfigController.php:373
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\main
‪string main()
Definition: InfoPageTyposcriptConfigController.php:78
‪TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
Definition: ExtendedTemplateService.php:43
‪TYPO3\CMS\Backend\Utility\BackendUtility\BEgetRootLine
‪static array BEgetRootLine($uid, $clause='', $workspaceOL=false, array $additionalFields=[])
Definition: BackendUtility.php:343
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\modMenu
‪array modMenu()
Definition: InfoPageTyposcriptConfigController.php:215
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$id
‪$id
Definition: InfoPageTyposcriptConfigController.php:55
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: InfoPageTyposcriptConfigController.php:389
‪TYPO3\CMS\Fluid\View\StandaloneView\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: StandaloneView.php:116
‪TYPO3\CMS\Backend\Utility\BackendUtility\wrapClickMenuOnIcon
‪static string wrapClickMenuOnIcon( $content, $table, $uid=0, $context='', $_addParams='', $_enDisItems='', $returnTagParameters=false)
Definition: BackendUtility.php:2510
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\init
‪init($pObj)
Definition: InfoPageTyposcriptConfigController.php:62
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getList
‪array getList($pageArray, $lines=[], $pageDepth=0)
Definition: InfoPageTyposcriptConfigController.php:335
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Utility\BackendUtility\getDropdownMenu
‪static string getDropdownMenu( $mainParams, $elementName, $currentValue, $menuItems, $script='', $addParams='')
Definition: BackendUtility.php:2653
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id)
Definition: BackendUtility.php:698
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerExtensionName
‪setControllerExtensionName($controllerExtensionName)
Definition: Request.php:193
‪TYPO3\CMS\Backend\Utility\BackendUtility\getFuncCheck
‪static string getFuncCheck( $mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
Definition: BackendUtility.php:2709
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplatePathAndFilename
‪setTemplatePathAndFilename($templatePathAndFilename)
Definition: AbstractTemplateView.php:103
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$iconFactory
‪IconFactory $iconFactory
Definition: InfoPageTyposcriptConfigController.php:42
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪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:167
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\getLanguageService
‪LanguageService getLanguageService()
Definition: InfoPageTyposcriptConfigController.php:397
‪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:134
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController\$view
‪StandaloneView $view
Definition: InfoPageTyposcriptConfigController.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Info\Controller
Definition: InfoModuleController.php:16
‪TYPO3\CMS\Info\Controller\InfoPageTyposcriptConfigController
Definition: InfoPageTyposcriptConfigController.php:39
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplateRootPaths
‪setTemplateRootPaths(array $templateRootPaths)
Definition: AbstractTemplateView.php:114
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:39