TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
InfoPageTyposcriptConfigController.php
Go to the documentation of this file.
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 
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  $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  $editIdList = substr($k, 4);
112  $pUids[] = $editIdList;
113  $row = BackendUtility::getRecordWSOL('pages', $editIdList);
114 
115  $icon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL);
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 
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(
243  $queryBuilder->expr()->neq(
244  'TSconfig',
245  $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)
246  )
247  )
248  ->groupBy('uid')
249  ->execute();
250 
251  $pageArray = [];
252 
253  while ($row = $res->fetch()) {
254  $this->setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
255  }
256  return $this->getList($pageArray);
257  }
258 
269  protected function setInPageArray(&$hierarchicArray, $rootlineArray, $row)
270  {
271  ksort($rootlineArray);
272  reset($rootlineArray);
273  if (!$rootlineArray[0]['uid']) {
274  array_shift($rootlineArray);
275  }
276  $currentElement = current($rootlineArray);
277  $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
278  array_shift($rootlineArray);
279  if (!empty($rootlineArray)) {
280  if (!isset($hierarchicArray[$currentElement['uid'] . '.'])) {
281  $hierarchicArray[$currentElement['uid'] . '.'] = [];
282  }
283  $this->setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
284  } else {
285  $hierarchicArray[$currentElement['uid'] . '_'] = $this->extractLinesFromTSConfig($row);
286  }
287  }
288 
295  protected function extractLinesFromTSConfig(array $row)
296  {
297  $out = [];
298  $includeLines = 0;
299  $out['uid'] = $row['uid'];
300  $lines = GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
301  foreach ($lines as $line) {
302  if (strpos($line, '<INCLUDE_TYPOSCRIPT:') !== false) {
303  $includeLines++;
304  }
305  }
306  $out['includeLines'] = $includeLines;
307  $out['writtenLines'] = (count($lines) - $includeLines);
308  return $out;
309  }
310 
320  protected function getList($pageArray, $lines = [], $pageDepth = 0)
321  {
322  if (!is_array($pageArray)) {
323  return $lines;
324  }
325 
326  foreach ($pageArray as $identifier => $_) {
327  if (!MathUtility::canBeInterpretedAsInteger($identifier)) {
328  continue;
329  }
330  $line = [];
331  $line['padding'] = ($pageDepth * 20);
332  if (isset($pageArray[$identifier . '_'])) {
333  $line['link'] = GeneralUtility::linkThisScript(['id' => $identifier]);
334  $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
335  $line['title'] = 'ID: ' . $identifier;
336  $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
337  $line['includedFiles'] = ($pageArray[$identifier . '_']['includeLines'] === 0 ? '' : $pageArray[($identifier . '_')]['includeLines']);
338  $line['lines'] = ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']);
339  } else {
340  $line['link'] = '';
341  $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
342  $line['title'] = '';
343  $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
344  $line['includedFiles'] = '';
345  $line['lines'] = '';
346  }
347  $lines[] = $line;
348  $lines = $this->getList($pageArray[$identifier . '.'], $lines, $pageDepth + 1);
349  }
350  return $lines;
351  }
352 
358  protected function getLanguageService()
359  {
360  return $GLOBALS['LANG'];
361  }
362 
368  protected function getBackendUser()
369  {
370  return $GLOBALS['BE_USER'];
371  }
372 
378  protected function getFluidTemplateObject()
379  {
381  $view = GeneralUtility::makeInstance(StandaloneView::class);
382  $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Layouts')]);
383  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Partials')]);
384  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Templates')]);
385 
386  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Templates/Main.html'));
387 
388  $view->getRequest()->setControllerExtensionName('info_pagetsconfig');
389  return $view;
390  }
391 }
static getRecordWSOL($table, $uid, $fields= '*', $where= '', $useDeleteClause=true, $unsetMovePointers=false)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static getDropdownMenu($mainParams, $elementName, $currentValue, $menuItems, $script= '', $addParams= '')
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static BEgetRootLine($uid, $clause= '', $workspaceOL=false)
static linkThisScript(array $getParams=[])
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
static getFuncCheck($mainParams, $elementName, $currentValue, $script= '', $addParams= '', $tagParams= '')
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static wrapClickMenuOnIcon($content, $table, $uid=0, $listFrame=true, $addParams= '', $enDisItems= '', $returnTagParameters=false)
static getFileAbsFileName($filename, $_=null, $_2=null)