[FEATURE] Add Page TSConfig overview in Web->Info 39/36039/7
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Fri, 16 Jan 2015 11:52:18 +0000 (12:52 +0100)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Sat, 17 Jan 2015 15:37:14 +0000 (16:37 +0100)
Analog to the pagetree overview of Web->Template the module
Web->Info->TSConfig will now show a list of pages holding TSConfig
settings if pid 0 is selected.

Fixes: #19833
Releases: master
Change-Id: I83ba1e14fe12ad4d1be80a694c9d4cb40dc85e0c
Reviewed-on: http://review.typo3.org/36039
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Tested-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
typo3/sysext/info_pagetsconfig/Classes/Controller/InfoPageTyposcriptConfigController.php
typo3/sysext/info_pagetsconfig/locallang.xlf

index 397a396..73d15a8 100644 (file)
@@ -15,6 +15,9 @@ namespace TYPO3\CMS\InfoPagetsconfig\Controller;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
 
 /**
  * Page TSconfig viewer
@@ -68,125 +71,266 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
         * @return string HTML output
         */
        public function main() {
-               $menu = BackendUtility::getFuncMenu($this->pObj->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']);
-               $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>';
-               $theOutput = $this->pObj->doc->header($GLOBALS['LANG']->getLL('tsconf_title'));
-
-               if ($this->pObj->MOD_SETTINGS['tsconf_parts'] == 99) {
-                       $TSparts = BackendUtility::getPagesTSconfig($this->pObj->id, NULL, TRUE);
-                       $lines = array();
-                       $pUids = array();
-                       foreach ($TSparts as $k => $v) {
-                               if ($k != 'uid_0') {
-                                       if ($k == 'defaultPageTSconfig') {
-                                               $pTitle = '<strong>' . $GLOBALS['LANG']->getLL('editTSconfig_default', TRUE) . '</strong>';
-                                               $editIcon = '';
-                                       } else {
-                                               $pUids[] = substr($k, 4);
-                                               $row = BackendUtility::getRecordWSOL('pages', substr($k, 4));
-                                               $pTitle = $this->pObj->doc->getHeader('pages', $row, '', FALSE);
-                                               $editIdList = substr($k, 4);
-                                               $params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=TSconfig';
-                                               $onclickUrl = BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'], '');
-                                               $editIcon = '<a href="#" onclick="' . htmlspecialchars($onclickUrl) . '" title="' . $GLOBALS['LANG']->getLL('editTSconfig', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open') . '</a>';
+
+               if ((int)(GeneralUtility::_GP('id')) === 0) {
+                       $lang = $this->getLanguageService();
+                       return $this->pObj->doc->section(
+                               '',
+                               '<div class="nowrap"><div class="table-fit"><table class="table table-striped table-hover" id="tsconfig-overview">' .
+                               '<thead>' .
+                               '<tr>' .
+                               '<th>' . $lang->getLL('pagetitle') . '</th>' .
+                               '<th>' . $lang->getLL('included_tsconfig_files') . '</th>' .
+                               '<th>' . $lang->getLL('written_tsconfig_lines') . '</th>' .
+                               '</tr>' .
+                               '</thead>' .
+                               '<tbody>' . implode('', $this->getOverviewOfPagesUsingTSConfig()) . '</tbody>' .
+                               '</table></div>',
+                               0,
+                               1
+                       );
+               } else {
+                       $menu = BackendUtility::getFuncMenu($this->pObj->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']);
+                       $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>';
+                       $theOutput = $this->pObj->doc->header($GLOBALS['LANG']->getLL('tsconf_title'));
+
+                       if ($this->pObj->MOD_SETTINGS['tsconf_parts'] == 99) {
+                               $TSparts = BackendUtility::getPagesTSconfig($this->pObj->id, NULL, TRUE);
+                               $lines = array();
+                               $pUids = array();
+                               foreach ($TSparts as $k => $v) {
+                                       if ($k != 'uid_0') {
+                                               if ($k == 'defaultPageTSconfig') {
+                                                       $pTitle = '<strong>' . $GLOBALS['LANG']->getLL('editTSconfig_default', TRUE) . '</strong>';
+                                                       $editIcon = '';
+                                               } else {
+                                                       $pUids[] = substr($k, 4);
+                                                       $row = BackendUtility::getRecordWSOL('pages', substr($k, 4));
+                                                       $pTitle = $this->pObj->doc->getHeader('pages', $row, '', FALSE);
+                                                       $editIdList = substr($k, 4);
+                                                       $params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=TSconfig';
+                                                       $onclickUrl = BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'], '');
+                                                       $editIcon = '<a href="#" onclick="' . htmlspecialchars($onclickUrl) . '" title="' . $GLOBALS['LANG']->getLL('editTSconfig', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open') . '</a>';
+                                               }
+                                               $TScontent = nl2br(htmlspecialchars(trim($v) . LF));
+                                               $tsparser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
+                                               $tsparser->lineNumberOffset = 0;
+                                               $TScontent = $tsparser->doSyntaxHighlight(trim($v) . LF);
+                                               $lines[] = '
+                                                       <tr><td nowrap="nowrap" class="bgColor5">' . $pTitle . '</td></tr>
+                                                       <tr><td nowrap="nowrap" class="bgColor4">' . $TScontent . $editIcon . '</td></tr>
+                                                       <tr><td>&nbsp;</td></tr>
+                                               ';
                                        }
-                                       $TScontent = nl2br(htmlspecialchars(trim($v) . LF));
-                                       $tsparser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
-                                       $tsparser->lineNumberOffset = 0;
-                                       $TScontent = $tsparser->doSyntaxHighlight(trim($v) . LF);
-                                       $lines[] = '
-                                               <tr><td nowrap="nowrap" class="bgColor5">' . $pTitle . '</td></tr>
-                                               <tr><td nowrap="nowrap" class="bgColor4">' . $TScontent . $editIcon . '</td></tr>
-                                               <tr><td>&nbsp;</td></tr>
-                                       ';
                                }
-                       }
-                       if (count($pUids)) {
-                               $params = '&edit[pages][' . implode(',', $pUids) . ']=edit&columnsOnly=TSconfig';
-                               $onclickUrl = BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'], '');
-                               $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>';
+                               if (count($pUids)) {
+                                       $params = '&edit[pages][' . implode(',', $pUids) . ']=edit&columnsOnly=TSconfig';
+                                       $onclickUrl = BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'], '');
+                                       $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>';
+                               } else {
+                                       $editIcon = '';
+                               }
+                               $theOutput .= $this->pObj->doc->section('', BackendUtility::cshItem(('_MOD_' . $GLOBALS['MCONF']['name']), 'tsconfig_edit', NULL) . $menu . '
+                                               <!-- Edit fields: -->
+                                               <table border="0" cellpadding="0" cellspacing="1">' . implode('', $lines) . '</table><br />' . $editIcon, 0, 1);
+
                        } else {
-                               $editIcon = '';
-                       }
-                       $theOutput .= $this->pObj->doc->section('', BackendUtility::cshItem(('_MOD_' . $GLOBALS['MCONF']['name']), 'tsconfig_edit', NULL) . $menu . '
-                                       <!-- Edit fields: -->
-                                       <table border="0" cellpadding="0" cellspacing="1">' . implode('', $lines) . '</table><br />' . $editIcon, 0, 1);
+                               // Defined global here!
+                               $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
 
-               } else {
-                       // Defined global here!
-                       $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
-
-                       // Do not log time-performance information
-                       $tmpl->tt_track = 0;
-                       $tmpl->fixedLgd = 0;
-                       $tmpl->linkObjects = 0;
-                       $tmpl->bType = '';
-                       $tmpl->ext_expandAllNotes = 1;
-                       $tmpl->ext_noPMicons = 1;
-
-                       switch ($this->pObj->MOD_SETTINGS['tsconf_parts']) {
-                               case '1':
-                                       $modTSconfig = BackendUtility::getModTSconfig($this->pObj->id, 'mod');
-                                       break;
-                               case '1a':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_layout', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '1b':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_view', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '1c':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_modules', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '1d':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_list', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '1e':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_info', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '1f':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_func', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '1g':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_ts', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '2':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '5':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('TCEFORM', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '6':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('TCEMAIN', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '3':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('TSFE', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               case '4':
-                                       $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('user', BackendUtility::getPagesTSconfig($this->pObj->id));
-                                       break;
-                               default:
-                                       $modTSconfig['properties'] = BackendUtility::getPagesTSconfig($this->pObj->id);
+                               // Do not log time-performance information
+                               $tmpl->tt_track = 0;
+                               $tmpl->fixedLgd = 0;
+                               $tmpl->linkObjects = 0;
+                               $tmpl->bType = '';
+                               $tmpl->ext_expandAllNotes = 1;
+                               $tmpl->ext_noPMicons = 1;
+
+
+                               switch ($this->pObj->MOD_SETTINGS['tsconf_parts']) {
+                                       case '1':
+                                               $modTSconfig = BackendUtility::getModTSconfig($this->pObj->id, 'mod');
+                                               break;
+                                       case '1a':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_layout', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '1b':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_view', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '1c':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_modules', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '1d':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_list', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '1e':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_info', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '1f':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_func', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '1g':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('mod.web_ts', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '2':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '5':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('TCEFORM', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '6':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('TCEMAIN', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '3':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('TSFE', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       case '4':
+                                               $modTSconfig = $GLOBALS['BE_USER']->getTSConfig('user', BackendUtility::getPagesTSconfig($this->pObj->id));
+                                               break;
+                                       default:
+                                               $modTSconfig['properties'] = BackendUtility::getPagesTSconfig($this->pObj->id);
+                               }
+
+                               $modTSconfig = $modTSconfig['properties'];
+                               if (!is_array($modTSconfig)) {
+                                       $modTSconfig = array();
+                               }
+
+                               $csh = BackendUtility::cshItem('_MOD_' . $GLOBALS['MCONF']['name'], 'tsconfig_hierarchy', NULL);
+                               $tree = $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']);
+
+                               $theOutput .= $this->pObj->doc->section(
+                                       '',
+                                       $csh .
+                                       $menu .
+                                       '<div class="nowrap">' . $tree . '</div>',
+                                       0,
+                                       1
+                               );
                        }
+               }
+
+               return $theOutput;
+       }
+
+       /**
+        * Renders table rows of all pages containing TSConfig together with its rootline
+        *
+        * @return array
+        */
+       protected function getOverviewOfPagesUsingTSConfig() {
+               $db = $this->getDatabaseConnection();
+               $res = $db->exec_SELECTquery(
+                       'uid, TSconfig',
+                       'pages',
+                       'TSconfig != \'\''
+                       . BackendUtility::deleteClause('pages')
+                       . BackendUtility::versioningPlaceholderClause('pages'), 'pages.uid');
+               $pageArray = array();
+               while ($row = $db->sql_fetch_assoc($res)) {
+                       $this->setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
+               }
+               return $this->renderList($pageArray);
+       }
 
-                       $modTSconfig = $modTSconfig['properties'];
-                       if (!is_array($modTSconfig)) {
-                               $modTSconfig = array();
+       /**
+        * Set page in array
+        * This function is called recursively and builds a multi-dimensional array that reflects the page
+        * hierarchy.
+        *
+        * @param array $hierarchicArray The hierarchic array (passed by reference)
+        * @param array $rootlineArray The rootline array
+        * @param array $row The row from the database containing the uid and TSConfig fields
+        * @return void
+        */
+       protected function setInPageArray(&$hierarchicArray, $rootlineArray, $row) {
+               ksort($rootlineArray);
+               reset($rootlineArray);
+               if (!$rootlineArray[0]['uid']) {
+                       array_shift($rootlineArray);
+               }
+               $currentElement = current($rootlineArray);
+               $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
+               array_shift($rootlineArray);
+               if (count($rootlineArray)) {
+                       if (!isset($hierarchicArray[($currentElement['uid'] . '.')])) {
+                               $hierarchicArray[$currentElement['uid'] . '.'] = array();
                        }
+                       $this->setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
+               } else {
+                       $hierarchicArray[$currentElement['uid'] . '_'] = $this->extractLinesFromTSConfig($row);
+               }
+       }
 
-                       $csh = BackendUtility::cshItem('_MOD_' . $GLOBALS['MCONF']['name'], 'tsconfig_hierarchy', NULL);
-                       $tree = $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']);
+       /**
+        * Extract the lines of TSConfig from a given pages row
+        *
+        * @param array $row The row from the database containing the uid and TSConfig fields
+        * @return array
+        */
+       protected function extractLinesFromTSConfig(array $row) {
+               $out = array();
+               $includeLines = 0;
+               $out['uid'] = $row['uid'];
+               $lines = GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
+               foreach ($lines as $line) {
+                       if (strpos($line, '<INCLUDE_TYPOSCRIPT:') !== FALSE) {
+                               $includeLines++;
+                       }
+               }
+               $out['includeLines'] = $includeLines;
+               $out['writtenLines'] = (count($lines) - $includeLines);
+               return $out;
+       }
 
-                       $theOutput .= $this->pObj->doc->section(
-                               '',
-                               $csh .
-                               $menu .
-                               '<div class="nowrap">' . $tree . '</div>',
-                               0,
-                               1
-                       );
+       /**
+        * Render the list of pages to show.
+        * This function is called recursively
+        *
+        * @param array $pageArray The Page Array
+        * @param array $lines Lines that have been processed up to this point
+        * @param int $pageDepth The level of the current $pageArray being processed
+        * @return array
+        */
+       protected function renderList($pageArray, $lines = array(), $pageDepth = 0) {
+               $cellStyle = 'padding-left: ' . ($pageDepth * 20) . 'px';
+               if (!is_array($pageArray)) {
+                       return $lines;
                }
 
-               return $theOutput;
+               foreach ($pageArray as $identifier => $_) {
+                       if (!MathUtility::canBeInterpretedAsInteger($identifier)) {
+                               continue;
+                       }
+                       if (isset($pageArray[$identifier . '_'])) {
+                               $lines[] = '
+                               <tr>
+                                       <td nowrap style="' . $cellStyle . '">
+                                               <a href="'
+                                       . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $identifier)))
+                                       . '">'
+                                       . IconUtility::getSpriteIconForRecord(
+                                               'pages',
+                                               BackendUtility::getRecordWSOL('pages', $identifier), array('title' => ('ID: ' . $identifier))
+                                       )
+                                       . GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30) . '</a></td>
+                                       <td>' . ($pageArray[($identifier . '_')]['includeLines'] === 0 ? '' : $pageArray[($identifier . '_')]['includeLines']) . '</td>
+                                       <td>' . ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']) . '</td>
+                                       </tr>';
+                       } else {
+                               $lines[] = '<tr>
+                                       <td nowrap style="' . $cellStyle . '">
+                                       ' . IconUtility::getSpriteIconForRecord(
+                                               'pages',
+                                               BackendUtility::getRecordWSOL('pages', $identifier))
+                                       . GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30) . '</td>
+                                       <td></td>
+                                       <td></td>
+                                       </tr>';
+                       }
+                       $lines = $this->renderList($pageArray[$identifier . '.'], $lines, $pageDepth + 1);
+               }
+               return $lines;
        }
 
 }
index b48ef10..0371014 100644 (file)
                        <trans-unit id="sort_alphabetic" xml:space="preserve">
                                <source>Sort alphabetically:</source>
                        </trans-unit>
+                       <trans-unit id="pagetitle" xml:space="preserve">
+                               <source>Pagetitle:</source>
+                       </trans-unit>
+                       <trans-unit id="included_tsconfig_files" xml:space="preserve">
+                               <source>Included Files:</source>
+                       </trans-unit>
+                       <trans-unit id="written_tsconfig_lines" xml:space="preserve">
+                               <source>Lines:</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>