TYPO3 CMS  TYPO3_8-7
InfoPageTyposcriptConfigController.php
Go to the documentation of this file.
1 <?php
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 
26 
31 {
35  protected $iconFactory;
36 
40  protected $view;
41 
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 
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 
92  public function main()
93  {
94  $pageId = (int)(GeneralUtility::_GP('id'));
95 
96  if ($pageId === 0) {
97  $this->view->assign('pageZero', 1);
98  $pagesUsingTSConfig = $this->getOverviewOfPagesUsingTSConfig();
99  if (count($pagesUsingTSConfig) > 0) {
100  $this->view->assign('overviewOfPagesUsingTSConfig', $pagesUsingTSConfig);
101  }
102  } else {
103  if ($this->pObj->MOD_SETTINGS['tsconf_parts'] == 99) {
104  $TSparts = BackendUtility::getPagesTSconfig($this->pObj->id, null, true);
105  $lines = [];
106  $pUids = [];
107 
108  foreach ($TSparts as $k => $v) {
109  if ($k !== 'uid_0') {
110  $line = [];
111  if ($k === 'defaultPageTSconfig') {
112  $line['defaultPageTSconfig'] = 1;
113  } else {
114  $editIdList = substr($k, 4);
115  $pUids[] = $editIdList;
116  $row = BackendUtility::getRecordWSOL('pages', $editIdList);
117 
118  $icon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL);
119  $urlParameters = [
120  'edit' => [
121  'pages' => [
122  $editIdList => 'edit',
123  ]
124  ],
125  'columnsOnly' => 'TSconfig',
126  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
127  ];
128  $line['editIcon'] = BackendUtility::getModuleUrl('record_edit', $urlParameters);
129  $line['editTitle'] = 'editTSconfig';
130  $line['title'] = BackendUtility::wrapClickMenuOnIcon($icon, 'pages', $row['uid'])
131  . ' ' . htmlspecialchars(BackendUtility::getRecordTitle('pages', $row));
132  }
133  $tsparser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
134  $tsparser->lineNumberOffset = 0;
135  $line['content'] = $tsparser->doSyntaxHighlight(trim($v) . LF);
136  $lines[] = $line;
137  }
138  }
139 
140  if (!empty($pUids)) {
141  $urlParameters = [
142  'edit' => [
143  'pages' => [
144  implode(',', $pUids) => 'edit',
145  ]
146  ],
147  'columnsOnly' => 'TSconfig',
148  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
149  ];
150  $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
151  $editIcon = htmlspecialchars($url);
152  $editTitle = 'editTSconfig_all';
153  } else {
154  $editIcon = '';
155  $editTitle = '';
156  }
157 
158  $this->view->assign('tsconfParts99', 1);
159  $this->view->assign('csh', BackendUtility::cshItem('_MOD_web_info', 'tsconfig_edit', null, '|'));
160  $this->view->assign('lines', $lines);
161  $this->view->assign('editIcon', $editIcon);
162  $this->view->assign('editTitle', $editTitle);
163  } else {
164  $this->view->assign('tsconfParts99', 0);
165  // Defined global here!
166  $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
167  $tmpl->ext_expandAllNotes = 1;
168  $tmpl->ext_noPMicons = 1;
169 
170  $beUser = $this->getBackendUser();
171  switch ($this->pObj->MOD_SETTINGS['tsconf_parts']) {
172  case '1':
173  $modTSconfig = BackendUtility::getModTSconfig($this->pObj->id, 'mod');
174  break;
175  case '1a':
176  $modTSconfig = $beUser->getTSConfig('mod.web_layout', BackendUtility::getPagesTSconfig($this->pObj->id));
177  break;
178  case '1b':
179  $modTSconfig = $beUser->getTSConfig('mod.web_view', BackendUtility::getPagesTSconfig($this->pObj->id));
180  break;
181  case '1c':
182  $modTSconfig = $beUser->getTSConfig('mod.web_modules', BackendUtility::getPagesTSconfig($this->pObj->id));
183  break;
184  case '1d':
185  $modTSconfig = $beUser->getTSConfig('mod.web_list', BackendUtility::getPagesTSconfig($this->pObj->id));
186  break;
187  case '1e':
188  $modTSconfig = $beUser->getTSConfig('mod.web_info', BackendUtility::getPagesTSconfig($this->pObj->id));
189  break;
190  case '1f':
191  $modTSconfig = $beUser->getTSConfig('mod.web_func', BackendUtility::getPagesTSconfig($this->pObj->id));
192  break;
193  case '1g':
194  $modTSconfig = $beUser->getTSConfig('mod.web_ts', BackendUtility::getPagesTSconfig($this->pObj->id));
195  break;
196  case '2':
197  $modTSconfig = $beUser->getTSConfig('RTE', BackendUtility::getPagesTSconfig($this->pObj->id));
198  break;
199  case '5':
200  $modTSconfig = $beUser->getTSConfig('TCEFORM', BackendUtility::getPagesTSconfig($this->pObj->id));
201  break;
202  case '6':
203  $modTSconfig = $beUser->getTSConfig('TCEMAIN', BackendUtility::getPagesTSconfig($this->pObj->id));
204  break;
205  case '3':
206  $modTSconfig = $beUser->getTSConfig('TSFE', BackendUtility::getPagesTSconfig($this->pObj->id));
207  break;
208  case '4':
209  $modTSconfig = $beUser->getTSConfig('user', BackendUtility::getPagesTSconfig($this->pObj->id));
210  break;
211  default:
212  $modTSconfig['properties'] = BackendUtility::getPagesTSconfig($this->pObj->id);
213  }
214 
215  $modTSconfig = $modTSconfig['properties'];
216  if (!is_array($modTSconfig)) {
217  $modTSconfig = [];
218  }
219 
220  $this->view->assign('csh', BackendUtility::cshItem('_MOD_web_info', 'tsconfig_hierarchy', null, '|'));
221  $this->view->assign('tree', $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']));
222  }
223  $this->view->assign('alphaSort', BackendUtility::getFuncCheck($this->pObj->id, 'SET[tsconf_alphaSort]', $this->pObj->MOD_SETTINGS['tsconf_alphaSort'], '', '', 'id="checkTsconf_alphaSort"'));
224  $this->view->assign('dropdownMenu', BackendUtility::getDropdownMenu($this->pObj->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']));
225  }
226  return $this->view->render();
227  }
228 
234  protected function getOverviewOfPagesUsingTSConfig()
235  {
236  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
237  $queryBuilder->getRestrictions()
238  ->removeAll()
239  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
240  ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
241 
242  $res = $queryBuilder
243  ->select('uid', 'TSconfig')
244  ->from('pages')
245  ->where(
246  $queryBuilder->expr()->neq(
247  'TSconfig',
248  $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)
249  )
250  )
251  ->execute();
252 
253  $pageArray = [];
254 
255  while ($row = $res->fetch()) {
256  $this->setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
257  }
258  return $this->getList($pageArray);
259  }
260 
270  protected function setInPageArray(&$hierarchicArray, $rootlineArray, $row)
271  {
272  ksort($rootlineArray);
273  reset($rootlineArray);
274  if (!$rootlineArray[0]['uid']) {
275  array_shift($rootlineArray);
276  }
277  $currentElement = current($rootlineArray);
278  $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
279  array_shift($rootlineArray);
280  if (!empty($rootlineArray)) {
281  if (!isset($hierarchicArray[$currentElement['uid'] . '.'])) {
282  $hierarchicArray[$currentElement['uid'] . '.'] = [];
283  }
284  $this->setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
285  } else {
286  $hierarchicArray[$currentElement['uid'] . '_'] = $this->extractLinesFromTSConfig($row);
287  }
288  }
289 
296  protected function extractLinesFromTSConfig(array $row)
297  {
298  $out = [];
299  $includeLines = 0;
300  $out['uid'] = $row['uid'];
301  $lines = GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
302  foreach ($lines as $line) {
303  if (strpos($line, '<INCLUDE_TYPOSCRIPT:') !== false) {
304  $includeLines++;
305  }
306  }
307  $out['includeLines'] = $includeLines;
308  $out['writtenLines'] = (count($lines) - $includeLines);
309  return $out;
310  }
311 
321  protected function getList($pageArray, $lines = [], $pageDepth = 0)
322  {
323  if (!is_array($pageArray)) {
324  return $lines;
325  }
326 
327  foreach ($pageArray as $identifier => $_) {
328  if (!MathUtility::canBeInterpretedAsInteger($identifier)) {
329  continue;
330  }
331  $line = [];
332  $line['padding'] = ($pageDepth * 20) + 10;
333  if (isset($pageArray[$identifier . '_'])) {
334  $line['link'] = GeneralUtility::linkThisScript(['id' => $identifier]);
335  $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
336  $line['title'] = 'ID: ' . $identifier;
337  $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
338  $line['includedFiles'] = ($pageArray[$identifier . '_']['includeLines'] === 0 ? '' : $pageArray[($identifier . '_')]['includeLines']);
339  $line['lines'] = ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']);
340  } else {
341  $line['link'] = '';
342  $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
343  $line['title'] = '';
344  $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
345  $line['includedFiles'] = '';
346  $line['lines'] = '';
347  }
348  $lines[] = $line;
349  $lines = $this->getList($pageArray[$identifier . '.'], $lines, $pageDepth + 1);
350  }
351  return $lines;
352  }
353 
359  protected function getLanguageService()
360  {
361  return $GLOBALS['LANG'];
362  }
363 
369  protected function getBackendUser()
370  {
371  return $GLOBALS['BE_USER'];
372  }
373 
379  protected function getFluidTemplateObject()
380  {
382  $view = GeneralUtility::makeInstance(StandaloneView::class);
383  $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Layouts')]);
384  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Partials')]);
385  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Templates')]);
386 
387  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Templates/Main.html'));
388 
389  $view->getRequest()->setControllerExtensionName('info_pagetsconfig');
390  return $view;
391  }
392 }
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
static getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
static wrapClickMenuOnIcon( $content, $table, $uid=0, $context='', $_addParams='', $_enDisItems='', $returnTagParameters=false)
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
static getFileAbsFileName($filename, $_=null, $_2=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static linkThisScript(array $getParams=[])
static makeInstance($className,... $constructorArguments)
static cshItem($table, $field, $_='', $wrap='')
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static getFuncCheck( $mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
static fixed_lgd_cs($string, $chars, $appendString='...')
static getDropdownMenu( $mainParams, $elementName, $currentValue, $menuItems, $script='', $addParams='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']