[TASK] Call explicit render() on icon objects
[Packages/TYPO3.CMS.git] / typo3 / sysext / info_pagetsconfig / Classes / Controller / InfoPageTyposcriptConfigController.php
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
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Core\Utility\MathUtility;
22
23 /**
24 * Page TSconfig viewer
25 */
26 class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
27 /**
28 * @var IconFactory
29 */
30 protected $iconFactory;
31
32 /**
33 * Constructor
34 */
35 public function __construct() {
36 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
37 $this->getLanguageService()->includeLLFile('EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf');
38 }
39
40 /**
41 * Function menu initialization
42 *
43 * @return array Menu array
44 */
45 public function modMenu() {
46 $lang = $this->getLanguageService();
47 $modMenuAdd = array(
48 'tsconf_parts' => array(
49 0 => $lang->getLL('tsconf_parts_0'),
50 1 => $lang->getLL('tsconf_parts_1'),
51 '1a' => $lang->getLL('tsconf_parts_1a'),
52 '1b' => $lang->getLL('tsconf_parts_1b'),
53 '1c' => $lang->getLL('tsconf_parts_1c'),
54 '1d' => $lang->getLL('tsconf_parts_1d'),
55 '1e' => $lang->getLL('tsconf_parts_1e'),
56 '1f' => $lang->getLL('tsconf_parts_1f'),
57 '1g' => $lang->getLL('tsconf_parts_1g'),
58 2 => 'RTE.',
59 5 => 'TCEFORM.',
60 6 => 'TCEMAIN.',
61 3 => 'TSFE.',
62 4 => 'user.',
63 99 => $lang->getLL('tsconf_configFields')
64 ),
65 'tsconf_alphaSort' => '1'
66 );
67 if (!$this->getBackendUser()->isAdmin()) {
68 unset($modMenuAdd['tsconf_parts'][99]);
69 }
70 return $modMenuAdd;
71 }
72
73 /**
74 * Main function of class
75 *
76 * @return string HTML output
77 */
78 public function main() {
79 if ((int)(GeneralUtility::_GP('id')) === 0) {
80 $lang = $this->getLanguageService();
81 return $this->pObj->doc->section(
82 '',
83 '<div class="nowrap"><div class="table-fit"><table class="table table-striped table-hover" id="tsconfig-overview">' .
84 '<thead>' .
85 '<tr>' .
86 '<th>' . $lang->getLL('pagetitle') . '</th>' .
87 '<th>' . $lang->getLL('included_tsconfig_files') . '</th>' .
88 '<th>' . $lang->getLL('written_tsconfig_lines') . '</th>' .
89 '</tr>' .
90 '</thead>' .
91 '<tbody>' . implode('', $this->getOverviewOfPagesUsingTSConfig()) . '</tbody>' .
92 '</table></div>',
93 0,
94 1
95 );
96 } else {
97 $menu = '<div class="form-inline form-inline-spaced">';
98 $menu .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']);
99 $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>';
100 $menu .= '</div>';
101 $theOutput = $this->pObj->doc->header($this->getLanguageService()->getLL('tsconf_title'));
102
103 if ($this->pObj->MOD_SETTINGS['tsconf_parts'] == 99) {
104 $TSparts = BackendUtility::getPagesTSconfig($this->pObj->id, NULL, TRUE);
105 $lines = array();
106 $pUids = array();
107 foreach ($TSparts as $k => $v) {
108 if ($k != 'uid_0') {
109 if ($k == 'defaultPageTSconfig') {
110 $pTitle = '<strong>' . $this->getLanguageService()->getLL('editTSconfig_default', TRUE) . '</strong>';
111 $editIcon = '';
112 } else {
113 $pUids[] = substr($k, 4);
114 $row = BackendUtility::getRecordWSOL('pages', substr($k, 4));
115 $pTitle = $this->pObj->doc->getHeader('pages', $row, '', FALSE);
116 $editIdList = substr($k, 4);
117 $urlParameters = [
118 'edit' => [
119 'pages' => [
120 $editIdList => 'edit',
121 ]
122 ],
123 'columnsOnly' => 'TSconfig',
124 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
125 ];
126 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
127 $editIcon = '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('editTSconfig', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
128 }
129 $TScontent = nl2br(htmlspecialchars(trim($v) . LF));
130 $tsparser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
131 $tsparser->lineNumberOffset = 0;
132 $TScontent = $tsparser->doSyntaxHighlight(trim($v) . LF);
133 $lines[] = '
134 <tr><td nowrap="nowrap" class="bgColor5">' . $pTitle . '</td></tr>
135 <tr><td nowrap="nowrap" class="bgColor4">' . $TScontent . $editIcon . '</td></tr>
136 <tr><td>&nbsp;</td></tr>
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 = '<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>';
152 } else {
153 $editIcon = '';
154 }
155 $theOutput .= $this->pObj->doc->section('', 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, 0, 1);
158
159 } else {
160 // Defined global here!
161 $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
162
163 // Do not log time-performance information
164 $tmpl->tt_track = 0;
165 $tmpl->fixedLgd = 0;
166 $tmpl->linkObjects = 0;
167 $tmpl->bType = '';
168 $tmpl->ext_expandAllNotes = 1;
169 $tmpl->ext_noPMicons = 1;
170
171 $beUser = $this->getBackendUser();
172 switch ($this->pObj->MOD_SETTINGS['tsconf_parts']) {
173 case '1':
174 $modTSconfig = BackendUtility::getModTSconfig($this->pObj->id, 'mod');
175 break;
176 case '1a':
177 $modTSconfig = $beUser->getTSConfig('mod.web_layout', BackendUtility::getPagesTSconfig($this->pObj->id));
178 break;
179 case '1b':
180 $modTSconfig = $beUser->getTSConfig('mod.web_view', BackendUtility::getPagesTSconfig($this->pObj->id));
181 break;
182 case '1c':
183 $modTSconfig = $beUser->getTSConfig('mod.web_modules', BackendUtility::getPagesTSconfig($this->pObj->id));
184 break;
185 case '1d':
186 $modTSconfig = $beUser->getTSConfig('mod.web_list', BackendUtility::getPagesTSconfig($this->pObj->id));
187 break;
188 case '1e':
189 $modTSconfig = $beUser->getTSConfig('mod.web_info', BackendUtility::getPagesTSconfig($this->pObj->id));
190 break;
191 case '1f':
192 $modTSconfig = $beUser->getTSConfig('mod.web_func', BackendUtility::getPagesTSconfig($this->pObj->id));
193 break;
194 case '1g':
195 $modTSconfig = $beUser->getTSConfig('mod.web_ts', BackendUtility::getPagesTSconfig($this->pObj->id));
196 break;
197 case '2':
198 $modTSconfig = $beUser->getTSConfig('RTE', BackendUtility::getPagesTSconfig($this->pObj->id));
199 break;
200 case '5':
201 $modTSconfig = $beUser->getTSConfig('TCEFORM', BackendUtility::getPagesTSconfig($this->pObj->id));
202 break;
203 case '6':
204 $modTSconfig = $beUser->getTSConfig('TCEMAIN', BackendUtility::getPagesTSconfig($this->pObj->id));
205 break;
206 case '3':
207 $modTSconfig = $beUser->getTSConfig('TSFE', BackendUtility::getPagesTSconfig($this->pObj->id));
208 break;
209 case '4':
210 $modTSconfig = $beUser->getTSConfig('user', BackendUtility::getPagesTSconfig($this->pObj->id));
211 break;
212 default:
213 $modTSconfig['properties'] = BackendUtility::getPagesTSconfig($this->pObj->id);
214 }
215
216 $modTSconfig = $modTSconfig['properties'];
217 if (!is_array($modTSconfig)) {
218 $modTSconfig = array();
219 }
220
221 $csh = BackendUtility::cshItem('_MOD_web_info', 'tsconfig_hierarchy', NULL);
222 $tree = $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']);
223
224 $theOutput .= $this->pObj->doc->section(
225 '',
226 $csh .
227 $menu .
228 '<div class="nowrap">' . $tree . '</div>',
229 0,
230 1
231 );
232 }
233 }
234
235 return $theOutput;
236 }
237
238 /**
239 * Renders table rows of all pages containing TSConfig together with its rootline
240 *
241 * @return array
242 */
243 protected function getOverviewOfPagesUsingTSConfig() {
244 $db = $this->getDatabaseConnection();
245 $res = $db->exec_SELECTquery(
246 'uid, TSconfig',
247 'pages',
248 'TSconfig != \'\''
249 . BackendUtility::deleteClause('pages')
250 . BackendUtility::versioningPlaceholderClause('pages'), 'pages.uid');
251 $pageArray = array();
252 while ($row = $db->sql_fetch_assoc($res)) {
253 $this->setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
254 }
255 return $this->renderList($pageArray);
256 }
257
258 /**
259 * Set page in array
260 * This function is called recursively and builds a multi-dimensional array that reflects the page
261 * hierarchy.
262 *
263 * @param array $hierarchicArray The hierarchic array (passed by reference)
264 * @param array $rootlineArray The rootline array
265 * @param array $row The row from the database containing the uid and TSConfig fields
266 * @return void
267 */
268 protected function setInPageArray(&$hierarchicArray, $rootlineArray, $row) {
269 ksort($rootlineArray);
270 reset($rootlineArray);
271 if (!$rootlineArray[0]['uid']) {
272 array_shift($rootlineArray);
273 }
274 $currentElement = current($rootlineArray);
275 $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
276 array_shift($rootlineArray);
277 if (!empty($rootlineArray)) {
278 if (!isset($hierarchicArray[($currentElement['uid'] . '.')])) {
279 $hierarchicArray[$currentElement['uid'] . '.'] = array();
280 }
281 $this->setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
282 } else {
283 $hierarchicArray[$currentElement['uid'] . '_'] = $this->extractLinesFromTSConfig($row);
284 }
285 }
286
287 /**
288 * Extract the lines of TSConfig from a given pages row
289 *
290 * @param array $row The row from the database containing the uid and TSConfig fields
291 * @return array
292 */
293 protected function extractLinesFromTSConfig(array $row) {
294 $out = array();
295 $includeLines = 0;
296 $out['uid'] = $row['uid'];
297 $lines = GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
298 foreach ($lines as $line) {
299 if (strpos($line, '<INCLUDE_TYPOSCRIPT:') !== FALSE) {
300 $includeLines++;
301 }
302 }
303 $out['includeLines'] = $includeLines;
304 $out['writtenLines'] = (count($lines) - $includeLines);
305 return $out;
306 }
307
308 /**
309 * Render the list of pages to show.
310 * This function is called recursively
311 *
312 * @param array $pageArray The Page Array
313 * @param array $lines Lines that have been processed up to this point
314 * @param int $pageDepth The level of the current $pageArray being processed
315 * @return array
316 */
317 protected function renderList($pageArray, $lines = array(), $pageDepth = 0) {
318 $cellStyle = 'padding-left: ' . ($pageDepth * 20) . 'px';
319 if (!is_array($pageArray)) {
320 return $lines;
321 }
322
323 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
324 foreach ($pageArray as $identifier => $_) {
325 if (!MathUtility::canBeInterpretedAsInteger($identifier)) {
326 continue;
327 }
328 if (isset($pageArray[$identifier . '_'])) {
329 $lines[] = '
330 <tr>
331 <td nowrap style="' . $cellStyle . '">
332 <a href="'
333 . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $identifier)))
334 . '" title="' . htmlspecialchars('ID: ' . $identifier) . '">'
335 . $iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render()
336 . GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30) . '</a></td>
337 <td>' . ($pageArray[($identifier . '_')]['includeLines'] === 0 ? '' : $pageArray[($identifier . '_')]['includeLines']) . '</td>
338 <td>' . ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']) . '</td>
339 </tr>';
340 } else {
341 $lines[] = '<tr>
342 <td nowrap style="' . $cellStyle . '">'
343 . $iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render()
344 . GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30) . '</td>
345 <td></td>
346 <td></td>
347 </tr>';
348 }
349 $lines = $this->renderList($pageArray[$identifier . '.'], $lines, $pageDepth + 1);
350 }
351 return $lines;
352 }
353
354 /**
355 * Returns LanguageService
356 *
357 * @return \TYPO3\CMS\Lang\LanguageService
358 */
359 protected function getLanguageService() {
360 return $GLOBALS['LANG'];
361 }
362
363 /**
364 * Returns the current BE user.
365 *
366 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
367 */
368 protected function getBackendUser() {
369 return $GLOBALS['BE_USER'];
370 }
371
372 }