TYPO3  7.6
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 
22 
27 {
31  protected $iconFactory;
32 
36  public function __construct()
37  {
38  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
39  $this->getLanguageService()->includeLLFile('EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf');
40  }
41 
47  public function modMenu()
48  {
49  $lang = $this->getLanguageService();
50  $modMenuAdd = array(
51  'tsconf_parts' => array(
52  0 => $lang->getLL('tsconf_parts_0'),
53  1 => $lang->getLL('tsconf_parts_1'),
54  '1a' => $lang->getLL('tsconf_parts_1a'),
55  '1b' => $lang->getLL('tsconf_parts_1b'),
56  '1c' => $lang->getLL('tsconf_parts_1c'),
57  '1d' => $lang->getLL('tsconf_parts_1d'),
58  '1e' => $lang->getLL('tsconf_parts_1e'),
59  '1f' => $lang->getLL('tsconf_parts_1f'),
60  '1g' => $lang->getLL('tsconf_parts_1g'),
61  2 => 'RTE.',
62  5 => 'TCEFORM.',
63  6 => 'TCEMAIN.',
64  3 => 'TSFE.',
65  4 => 'user.',
66  99 => $lang->getLL('tsconf_configFields')
67  ),
68  'tsconf_alphaSort' => '1'
69  );
70  if (!$this->getBackendUser()->isAdmin()) {
71  unset($modMenuAdd['tsconf_parts'][99]);
72  }
73  return $modMenuAdd;
74  }
75 
81  public function main()
82  {
83  if ((int)(GeneralUtility::_GP('id')) === 0) {
84  $lang = $this->getLanguageService();
85  return '<div class="nowrap"><div class="table-fit"><table class="table table-striped table-hover" id="tsconfig-overview">' .
86  '<thead>' .
87  '<tr>' .
88  '<th>' . $lang->getLL('pagetitle') . '</th>' .
89  '<th>' . $lang->getLL('included_tsconfig_files') . '</th>' .
90  '<th>' . $lang->getLL('written_tsconfig_lines') . '</th>' .
91  '</tr>' .
92  '</thead>' .
93  '<tbody>' . implode('', $this->getOverviewOfPagesUsingTSConfig()) . '</tbody>' .
94  '</table></div>';
95  } else {
96  $menu = '<div class="form-inline form-inline-spaced">';
97  $menu .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']);
98  $menu .= '<div class="checkbox"><label for="checkTsconf_alphaSort">' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[tsconf_alphaSort]', $this->pObj->MOD_SETTINGS['tsconf_alphaSort'], '', '', 'id="checkTsconf_alphaSort"') . ' ' . $this->getLanguageService()->getLL('sort_alphabetic', true) . '</label></div>';
99  $menu .= '</div>';
100  $theOutput = $this->pObj->doc->header($this->getLanguageService()->getLL('tsconf_title'));
101 
102  if ($this->pObj->MOD_SETTINGS['tsconf_parts'] == 99) {
103  $TSparts = BackendUtility::getPagesTSconfig($this->pObj->id, null, true);
104  $lines = array();
105  $pUids = array();
106  foreach ($TSparts as $k => $v) {
107  if ($k != 'uid_0') {
108  if ($k == 'defaultPageTSconfig') {
109  $pTitle = '<strong>' . $this->getLanguageService()->getLL('editTSconfig_default', true) . '</strong>';
110  $editIcon = '';
111  } else {
112  $pUids[] = substr($k, 4);
113  $row = BackendUtility::getRecordWSOL('pages', substr($k, 4));
114  $pTitle = $this->pObj->doc->getHeader('pages', $row, '', false);
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  $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
126  $editIcon = '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('editTSconfig', true) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
127  }
128  $TScontent = nl2br(htmlspecialchars(trim($v) . LF));
129  $tsparser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
130  $tsparser->lineNumberOffset = 0;
131  $TScontent = $tsparser->doSyntaxHighlight(trim($v) . LF);
132  $lines[] = '
133  <tr><td nowrap="nowrap" class="bgColor5">' . $pTitle . '</td></tr>
134  <tr><td nowrap="nowrap" class="bgColor4">' . $TScontent . $editIcon . '</td></tr>
135  <tr><td>&nbsp;</td></tr>
136  ';
137  }
138  }
139  if (!empty($pUids)) {
140  $urlParameters = [
141  'edit' => [
142  'pages' => [
143  implode(',', $pUids) => 'edit',
144  ]
145  ],
146  'columnsOnly' => 'TSconfig',
147  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
148  ];
149  $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
150  $editIcon = '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('editTSconfig_all', true) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '<strong>' . $this->getLanguageService()->getLL('editTSconfig_all', true) . '</strong>' . '</a>';
151  } else {
152  $editIcon = '';
153  }
154  $theOutput .= '<div>';
155  $theOutput .= BackendUtility::cshItem('_MOD_web_info', 'tsconfig_edit', null) . $menu . '
156  <!-- Edit fields: -->
157  <table border="0" cellpadding="0" cellspacing="1">' . implode('', $lines) . '</table><br />' . $editIcon;
158  $theOutput .= '</div>';
159 
160  } else {
161  // Defined global here!
162  $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
163 
164  // Do not log time-performance information
165  $tmpl->tt_track = 0;
166  $tmpl->fixedLgd = 0;
167  $tmpl->linkObjects = 0;
168  $tmpl->bType = '';
169  $tmpl->ext_expandAllNotes = 1;
170  $tmpl->ext_noPMicons = 1;
171 
172  $beUser = $this->getBackendUser();
173  switch ($this->pObj->MOD_SETTINGS['tsconf_parts']) {
174  case '1':
175  $modTSconfig = BackendUtility::getModTSconfig($this->pObj->id, 'mod');
176  break;
177  case '1a':
178  $modTSconfig = $beUser->getTSConfig('mod.web_layout', BackendUtility::getPagesTSconfig($this->pObj->id));
179  break;
180  case '1b':
181  $modTSconfig = $beUser->getTSConfig('mod.web_view', BackendUtility::getPagesTSconfig($this->pObj->id));
182  break;
183  case '1c':
184  $modTSconfig = $beUser->getTSConfig('mod.web_modules', BackendUtility::getPagesTSconfig($this->pObj->id));
185  break;
186  case '1d':
187  $modTSconfig = $beUser->getTSConfig('mod.web_list', BackendUtility::getPagesTSconfig($this->pObj->id));
188  break;
189  case '1e':
190  $modTSconfig = $beUser->getTSConfig('mod.web_info', BackendUtility::getPagesTSconfig($this->pObj->id));
191  break;
192  case '1f':
193  $modTSconfig = $beUser->getTSConfig('mod.web_func', BackendUtility::getPagesTSconfig($this->pObj->id));
194  break;
195  case '1g':
196  $modTSconfig = $beUser->getTSConfig('mod.web_ts', BackendUtility::getPagesTSconfig($this->pObj->id));
197  break;
198  case '2':
199  $modTSconfig = $beUser->getTSConfig('RTE', BackendUtility::getPagesTSconfig($this->pObj->id));
200  break;
201  case '5':
202  $modTSconfig = $beUser->getTSConfig('TCEFORM', BackendUtility::getPagesTSconfig($this->pObj->id));
203  break;
204  case '6':
205  $modTSconfig = $beUser->getTSConfig('TCEMAIN', BackendUtility::getPagesTSconfig($this->pObj->id));
206  break;
207  case '3':
208  $modTSconfig = $beUser->getTSConfig('TSFE', BackendUtility::getPagesTSconfig($this->pObj->id));
209  break;
210  case '4':
211  $modTSconfig = $beUser->getTSConfig('user', BackendUtility::getPagesTSconfig($this->pObj->id));
212  break;
213  default:
214  $modTSconfig['properties'] = BackendUtility::getPagesTSconfig($this->pObj->id);
215  }
216 
217  $modTSconfig = $modTSconfig['properties'];
218  if (!is_array($modTSconfig)) {
219  $modTSconfig = array();
220  }
221 
222  $csh = BackendUtility::cshItem('_MOD_web_info', 'tsconfig_hierarchy', null);
223  $tree = $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']);
224 
225  $theOutput .= '<div>';
226  $theOutput .= $csh . $menu . '<div class="nowrap">' . $tree . '</div>';
227  $theOutput .= '</div>';
228  }
229  }
230 
231  return $theOutput;
232  }
233 
239  protected function getOverviewOfPagesUsingTSConfig()
240  {
241  $db = $this->getDatabaseConnection();
242  $res = $db->exec_SELECTquery(
243  'uid, TSconfig',
244  'pages',
245  'TSconfig != \'\''
247  . BackendUtility::versioningPlaceholderClause('pages'), 'pages.uid');
248  $pageArray = array();
249  while ($row = $db->sql_fetch_assoc($res)) {
250  $this->setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
251  }
252  return $this->renderList($pageArray);
253  }
254 
265  protected function setInPageArray(&$hierarchicArray, $rootlineArray, $row)
266  {
267  ksort($rootlineArray);
268  reset($rootlineArray);
269  if (!$rootlineArray[0]['uid']) {
270  array_shift($rootlineArray);
271  }
272  $currentElement = current($rootlineArray);
273  $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
274  array_shift($rootlineArray);
275  if (!empty($rootlineArray)) {
276  if (!isset($hierarchicArray[($currentElement['uid'] . '.')])) {
277  $hierarchicArray[$currentElement['uid'] . '.'] = array();
278  }
279  $this->setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
280  } else {
281  $hierarchicArray[$currentElement['uid'] . '_'] = $this->extractLinesFromTSConfig($row);
282  }
283  }
284 
291  protected function extractLinesFromTSConfig(array $row)
292  {
293  $out = array();
294  $includeLines = 0;
295  $out['uid'] = $row['uid'];
296  $lines = GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
297  foreach ($lines as $line) {
298  if (strpos($line, '<INCLUDE_TYPOSCRIPT:') !== false) {
299  $includeLines++;
300  }
301  }
302  $out['includeLines'] = $includeLines;
303  $out['writtenLines'] = (count($lines) - $includeLines);
304  return $out;
305  }
306 
316  protected function renderList($pageArray, $lines = array(), $pageDepth = 0)
317  {
318  $cellStyle = 'padding-left: ' . ($pageDepth * 20) . 'px';
319  if (!is_array($pageArray)) {
320  return $lines;
321  }
322 
323  foreach ($pageArray as $identifier => $_) {
324  if (!MathUtility::canBeInterpretedAsInteger($identifier)) {
325  continue;
326  }
327  if (isset($pageArray[$identifier . '_'])) {
328  $lines[] = '
329  <tr>
330  <td nowrap style="' . $cellStyle . '">
331  <a href="'
332  . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $identifier)))
333  . '" title="' . htmlspecialchars('ID: ' . $identifier) . '">'
334  . $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render()
335  . GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30) . '</a></td>
336  <td>' . ($pageArray[($identifier . '_')]['includeLines'] === 0 ? '' : $pageArray[($identifier . '_')]['includeLines']) . '</td>
337  <td>' . ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']) . '</td>
338  </tr>';
339  } else {
340  $lines[] = '<tr>
341  <td nowrap style="' . $cellStyle . '">'
342  . $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render()
343  . GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30) . '</td>
344  <td></td>
345  <td></td>
346  </tr>';
347  }
348  $lines = $this->renderList($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 }