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