2 namespace TYPO3\CMS\InfoPagetsconfig\Controller
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
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
;
23 * Page TSconfig viewer
25 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
27 class InfoPageTyposcriptConfigController
extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
{
32 public function __construct() {
33 $this->getLanguageService()->includeLLFile('EXT:info_pagetsconfig/locallang.xlf');
37 * Function menu initialization
39 * @return array Menu array
41 public function modMenu() {
42 $lang = $this->getLanguageService();
44 'tsconf_parts' => array(
45 0 => $lang->getLL('tsconf_parts_0'),
46 1 => $lang->getLL('tsconf_parts_1'),
47 '1a' => $lang->getLL('tsconf_parts_1a'),
48 '1b' => $lang->getLL('tsconf_parts_1b'),
49 '1c' => $lang->getLL('tsconf_parts_1c'),
50 '1d' => $lang->getLL('tsconf_parts_1d'),
51 '1e' => $lang->getLL('tsconf_parts_1e'),
52 '1f' => $lang->getLL('tsconf_parts_1f'),
53 '1g' => $lang->getLL('tsconf_parts_1g'),
59 99 => $lang->getLL('tsconf_configFields')
61 'tsconf_alphaSort' => '1'
63 if (!$this->getBackendUser()->isAdmin()) {
64 unset($modMenuAdd['tsconf_parts'][99]);
70 * Main function of class
72 * @return string HTML output
74 public function main() {
76 if ((int)(GeneralUtility
::_GP('id')) === 0) {
77 $lang = $this->getLanguageService();
78 return $this->pObj
->doc
->section(
80 '<div class="nowrap"><div class="table-fit"><table class="table table-striped table-hover" id="tsconfig-overview">' .
83 '<th>' . $lang->getLL('pagetitle') . '</th>' .
84 '<th>' . $lang->getLL('included_tsconfig_files') . '</th>' .
85 '<th>' . $lang->getLL('written_tsconfig_lines') . '</th>' .
88 '<tbody>' . implode('', $this->getOverviewOfPagesUsingTSConfig()) . '</tbody>' .
94 $menu = BackendUtility
::getFuncMenu($this->pObj
->id
, 'SET[tsconf_parts]', $this->pObj
->MOD_SETTINGS
['tsconf_parts'], $this->pObj
->MOD_MENU
['tsconf_parts']);
95 $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>';
96 $theOutput = $this->pObj
->doc
->header($this->getLanguageService()->getLL('tsconf_title'));
98 if ($this->pObj
->MOD_SETTINGS
['tsconf_parts'] == 99) {
99 $TSparts = BackendUtility
::getPagesTSconfig($this->pObj
->id
, NULL, TRUE);
102 foreach ($TSparts as $k => $v) {
104 if ($k == 'defaultPageTSconfig') {
105 $pTitle = '<strong>' . $this->getLanguageService()->getLL('editTSconfig_default', TRUE) . '</strong>';
108 $pUids[] = substr($k, 4);
109 $row = BackendUtility
::getRecordWSOL('pages', substr($k, 4));
110 $pTitle = $this->pObj
->doc
->getHeader('pages', $row, '', FALSE);
111 $editIdList = substr($k, 4);
112 $params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=TSconfig';
113 $onclickUrl = BackendUtility
::editOnClick($params, $GLOBALS['BACK_PATH'], '');
114 $editIcon = '<a href="#" onclick="' . htmlspecialchars($onclickUrl) . '" title="' . $this->getLanguageService()->getLL('editTSconfig', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIcon('actions-document-open') . '</a>';
116 $TScontent = nl2br(htmlspecialchars(trim($v) . LF
));
117 $tsparser = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
::class);
118 $tsparser->lineNumberOffset
= 0;
119 $TScontent = $tsparser->doSyntaxHighlight(trim($v) . LF
);
121 <tr><td nowrap="nowrap" class="bgColor5">' . $pTitle . '</td></tr>
122 <tr><td nowrap="nowrap" class="bgColor4">' . $TScontent . $editIcon . '</td></tr>
123 <tr><td> </td></tr>
128 $params = '&edit[pages][' . implode(',', $pUids) . ']=edit&columnsOnly=TSconfig';
129 $onclickUrl = BackendUtility
::editOnClick($params, $GLOBALS['BACK_PATH'], '');
130 $editIcon = '<a href="#" onclick="' . htmlspecialchars($onclickUrl) . '" title="' . $this->getLanguageService()->getLL('editTSconfig_all', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIcon('actions-document-open') . '<strong>' . $this->getLanguageService()->getLL('editTSconfig_all', TRUE) . '</strong>' . '</a>';
134 $theOutput .= $this->pObj
->doc
->section('', BackendUtility
::cshItem(('_MOD_' . $GLOBALS['MCONF']['name']), 'tsconfig_edit', NULL) . $menu . '
135 <!-- Edit fields: -->
136 <table border="0" cellpadding="0" cellspacing="1">' . implode('', $lines) . '</table><br />' . $editIcon, 0, 1);
139 // Defined global here!
140 $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
::class);
142 // Do not log time-performance information
145 $tmpl->linkObjects
= 0;
147 $tmpl->ext_expandAllNotes
= 1;
148 $tmpl->ext_noPMicons
= 1;
150 $beUser = $this->getBackendUser();
151 switch ($this->pObj
->MOD_SETTINGS
['tsconf_parts']) {
153 $modTSconfig = BackendUtility
::getModTSconfig($this->pObj
->id
, 'mod');
156 $modTSconfig = $beUser->getTSConfig('mod.web_layout', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
159 $modTSconfig = $beUser->getTSConfig('mod.web_view', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
162 $modTSconfig = $beUser->getTSConfig('mod.web_modules', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
165 $modTSconfig = $beUser->getTSConfig('mod.web_list', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
168 $modTSconfig = $beUser->getTSConfig('mod.web_info', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
171 $modTSconfig = $beUser->getTSConfig('mod.web_func', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
174 $modTSconfig = $beUser->getTSConfig('mod.web_ts', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
177 $modTSconfig = $beUser->getTSConfig('RTE', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
180 $modTSconfig = $beUser->getTSConfig('TCEFORM', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
183 $modTSconfig = $beUser->getTSConfig('TCEMAIN', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
186 $modTSconfig = $beUser->getTSConfig('TSFE', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
189 $modTSconfig = $beUser->getTSConfig('user', BackendUtility
::getPagesTSconfig($this->pObj
->id
));
192 $modTSconfig['properties'] = BackendUtility
::getPagesTSconfig($this->pObj
->id
);
195 $modTSconfig = $modTSconfig['properties'];
196 if (!is_array($modTSconfig)) {
197 $modTSconfig = array();
200 $csh = BackendUtility
::cshItem('_MOD_' . $GLOBALS['MCONF']['name'], 'tsconfig_hierarchy', NULL);
201 $tree = $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj
->MOD_SETTINGS
['tsconf_alphaSort']);
203 $theOutput .= $this->pObj
->doc
->section(
207 '<div class="nowrap">' . $tree . '</div>',
218 * Renders table rows of all pages containing TSConfig together with its rootline
222 protected function getOverviewOfPagesUsingTSConfig() {
223 $db = $this->getDatabaseConnection();
224 $res = $db->exec_SELECTquery(
228 . BackendUtility
::deleteClause('pages')
229 . BackendUtility
::versioningPlaceholderClause('pages'), 'pages.uid');
230 $pageArray = array();
231 while ($row = $db->sql_fetch_assoc($res)) {
232 $this->setInPageArray($pageArray, BackendUtility
::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
234 return $this->renderList($pageArray);
239 * This function is called recursively and builds a multi-dimensional array that reflects the page
242 * @param array $hierarchicArray The hierarchic array (passed by reference)
243 * @param array $rootlineArray The rootline array
244 * @param array $row The row from the database containing the uid and TSConfig fields
247 protected function setInPageArray(&$hierarchicArray, $rootlineArray, $row) {
248 ksort($rootlineArray);
249 reset($rootlineArray);
250 if (!$rootlineArray[0]['uid']) {
251 array_shift($rootlineArray);
253 $currentElement = current($rootlineArray);
254 $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
255 array_shift($rootlineArray);
256 if (count($rootlineArray)) {
257 if (!isset($hierarchicArray[($currentElement['uid'] . '.')])) {
258 $hierarchicArray[$currentElement['uid'] . '.'] = array();
260 $this->setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
262 $hierarchicArray[$currentElement['uid'] . '_'] = $this->extractLinesFromTSConfig($row);
267 * Extract the lines of TSConfig from a given pages row
269 * @param array $row The row from the database containing the uid and TSConfig fields
272 protected function extractLinesFromTSConfig(array $row) {
275 $out['uid'] = $row['uid'];
276 $lines = GeneralUtility
::trimExplode("\r\n", $row['TSconfig']);
277 foreach ($lines as $line) {
278 if (strpos($line, '<INCLUDE_TYPOSCRIPT:') !== FALSE) {
282 $out['includeLines'] = $includeLines;
283 $out['writtenLines'] = (count($lines) - $includeLines);
288 * Render the list of pages to show.
289 * This function is called recursively
291 * @param array $pageArray The Page Array
292 * @param array $lines Lines that have been processed up to this point
293 * @param int $pageDepth The level of the current $pageArray being processed
296 protected function renderList($pageArray, $lines = array(), $pageDepth = 0) {
297 $cellStyle = 'padding-left: ' . ($pageDepth * 20) . 'px';
298 if (!is_array($pageArray)) {
302 foreach ($pageArray as $identifier => $_) {
303 if (!MathUtility
::canBeInterpretedAsInteger($identifier)) {
306 if (isset($pageArray[$identifier . '_'])) {
309 <td nowrap style="' . $cellStyle . '">
311 . htmlspecialchars(GeneralUtility
::linkThisScript(array('id' => $identifier)))
313 . IconUtility
::getSpriteIconForRecord(
315 BackendUtility
::getRecordWSOL('pages', $identifier), array('title' => ('ID: ' . $identifier))
317 . GeneralUtility
::fixed_lgd_cs($pageArray[$identifier], 30) . '</a></td>
318 <td>' . ($pageArray[($identifier . '_')]['includeLines'] === 0 ?
'' : $pageArray[($identifier . '_')]['includeLines']) . '</td>
319 <td>' . ($pageArray[$identifier . '_']['writtenLines'] === 0 ?
'' : $pageArray[$identifier . '_']['writtenLines']) . '</td>
323 <td nowrap style="' . $cellStyle . '">
324 ' . IconUtility
::getSpriteIconForRecord(
326 BackendUtility
::getRecordWSOL('pages', $identifier))
327 . GeneralUtility
::fixed_lgd_cs($pageArray[$identifier], 30) . '</td>
332 $lines = $this->renderList($pageArray[$identifier . '.'], $lines, $pageDepth +
1);
338 * Returns LanguageService
340 * @return \TYPO3\CMS\Lang\LanguageService
342 protected function getLanguageService() {
343 return $GLOBALS['LANG'];
347 * Returns the current BE user.
349 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
351 protected function getBackendUser() {
352 return $GLOBALS['BE_USER'];