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