[BUGFIX] lineNumber count in Template Analyzer
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate / Classes / Controller / TemplateAnalyzerModuleFunctionController.php
index a1b8908..6b957e8 100644 (file)
@@ -15,7 +15,7 @@ namespace TYPO3\CMS\TsTemplate\Controller;
  *
  *  The GNU General Public License can be found at
  *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  A copy is found in the text file GPL.txt and important notices to the license
  *  from the author is found in LICENSE.txt distributed with these scripts.
  *
  *
@@ -99,6 +99,8 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
         * @todo Define visibility
         */
        public function main() {
+               $theOutput = '';
+
                // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
                // Checking for more than one template an if, set a menu...
                $manyTemplatesMenu = $this->pObj->templateMenu();
@@ -106,11 +108,16 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
                if ($manyTemplatesMenu) {
                        $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
                }
+
                // BUGBUG: Should we check if the uset may at all read and write template-records???
                $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
+
                // initialize
                if ($existTemplate) {
-                       $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('currentTemplate', TRUE), \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $GLOBALS['tplRow']) . '<strong>' . $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']['title']) . '</strong>' . htmlspecialchars((trim($GLOBALS['tplRow']['sitetitle']) ? ' (' . $GLOBALS['tplRow']['sitetitle'] . ')' : '')));
+                       $theOutput .= $this->pObj->doc->section(
+                               $GLOBALS['LANG']->getLL('currentTemplate', TRUE),
+                               \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $GLOBALS['tplRow']) . '<strong>' . $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']['title']) . '</strong>' . htmlspecialchars((trim($GLOBALS['tplRow']['sitetitle']) ? ' (' . $GLOBALS['tplRow']['sitetitle'] . ')' : ''))
+                       );
                }
                if ($manyTemplatesMenu) {
                        $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
@@ -118,20 +125,18 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
                $GLOBALS['tmpl']->clearList_const_temp = array_flip($GLOBALS['tmpl']->clearList_const);
                $GLOBALS['tmpl']->clearList_setup_temp = array_flip($GLOBALS['tmpl']->clearList_setup);
                $pointer = count($GLOBALS['tmpl']->hierarchyInfo);
-               $GLOBALS['tmpl']->hierarchyInfoArr = $GLOBALS['tmpl']->ext_process_hierarchyInfo(array(), $pointer);
-               $GLOBALS['tmpl']->processIncludes();
-               $hierarArr = array();
-               $head = '<tr class="t3-row-header">';
-               $head .= '<td>' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>';
-               $head .= '<td>' . $GLOBALS['LANG']->getLL('rootlevel', TRUE) . '</td>';
-               $head .= '<td>' . $GLOBALS['LANG']->getLL('clearSetup', TRUE) . '</td>';
-               $head .= '<td>' . $GLOBALS['LANG']->getLL('clearConstants', TRUE) . '</td>';
-               $head .= '<td>' . $GLOBALS['LANG']->getLL('pid', TRUE) . '</td>';
-               $head .= '<td>' . $GLOBALS['LANG']->getLL('rootline', TRUE) . '</td>';
-               $head .= '<td>' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '</td>';
-               $head .= '</tr>';
-               $hierar = implode(array_reverse($GLOBALS['tmpl']->ext_getTemplateHierarchyArr($GLOBALS['tmpl']->hierarchyInfoArr, '', array(), 1)), '');
-               $hierar = '<table id="ts-analyzer" cellpadding="0" cellspacing="0">' . $head . $hierar . '</table>';
+               $hierarchyInfo = $GLOBALS['tmpl']->ext_process_hierarchyInfo(array(), $pointer);
+               $head = '<thead><tr>';
+               $head .= '<th>' . $GLOBALS['LANG']->getLL('title', TRUE) . '</th>';
+               $head .= '<th>' . $GLOBALS['LANG']->getLL('rootlevel', TRUE) . '</th>';
+               $head .= '<th>' . $GLOBALS['LANG']->getLL('clearSetup', TRUE) . '</th>';
+               $head .= '<th>' . $GLOBALS['LANG']->getLL('clearConstants', TRUE) . '</th>';
+               $head .= '<th>' . $GLOBALS['LANG']->getLL('pid', TRUE) . '</th>';
+               $head .= '<th>' . $GLOBALS['LANG']->getLL('rootline', TRUE) . '</th>';
+               $head .= '<th>' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '</th>';
+               $head .= '</tr></thead>';
+               $hierar = implode(array_reverse($GLOBALS['tmpl']->ext_getTemplateHierarchyArr($hierarchyInfo, '', array(), 1)), '');
+               $hierar = '<table class="t3-table" id="ts-analyzer">' . $head . $hierar . '</table>';
                $theOutput .= $this->pObj->doc->spacer(5);
                $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', TRUE), $hierar, 0, 1);
                $urlParameters = array(
@@ -153,21 +158,21 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
                        $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', TRUE), '', 0, 1);
                        $theOutput .= $this->pObj->doc->sectionEnd();
                        $theOutput .= '
-                               <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
+                               <table class="t3-table ts-typoscript">
                        ';
                        // Don't know why -2 and not 0... :-) But works.
-                       $GLOBALS['tmpl']->ext_lineNumberOffset = -2;
+                       $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
                        $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'const';
-                       $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines(('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'])))) + 1;
-                       reset($GLOBALS['tmpl']->clearList_const);
                        foreach ($GLOBALS['tmpl']->constants as $key => $val) {
-                               $cVal = current($GLOBALS['tmpl']->clearList_const);
-                               if ($cVal == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
+                               $currentTemplateId = $GLOBALS['tmpl']->hierarchyInfo[$key]['templateID'];
+                               if ($currentTemplateId == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
                                        $theOutput .= '
                                                <tr>
-                                                       </td><td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[$cVal]) . '</strong></td></tr>
+                                                       <td><strong>' . htmlspecialchars($GLOBALS['tmpl']->hierarchyInfo[$key]['title']) . '</strong></td>
+                                               </tr>
                                                <tr>
-                                                       <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' . $GLOBALS['tmpl']->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) . '</td></tr></table>
+                                                       <td>
+                                                               <table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td nowrap="nowrap">' . $GLOBALS['tmpl']->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) . '</td></tr></table>
                                                        </td>
                                                </tr>
                                        ';
@@ -176,7 +181,6 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
                                        }
                                }
                                $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
-                               next($GLOBALS['tmpl']->clearList_const);
                        }
                        $theOutput .= '
                                </table>
@@ -188,19 +192,18 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
                        $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', TRUE), '', 0, 1);
                        $theOutput .= $this->pObj->doc->sectionEnd();
                        $theOutput .= '
-                               <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
+                               <table class="t3-table ts-typoscript">
                        ';
                        $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
                        $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'setup';
-                       $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines(('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'])))) + 1;
-                       reset($GLOBALS['tmpl']->clearList_setup);
                        foreach ($GLOBALS['tmpl']->config as $key => $val) {
-                               if (current($GLOBALS['tmpl']->clearList_setup) == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
+                               $currentTemplateId = $GLOBALS['tmpl']->hierarchyInfo[$key]['templateID'];
+                               if ($currentTemplateId == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
                                        $theOutput .= '
                                                <tr>
-                                                       <td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[current($GLOBALS['tmpl']->clearList_setup)]) . '</strong></td></tr>
+                                                       <td><strong>' . htmlspecialchars($GLOBALS['tmpl']->hierarchyInfo[$key]['title']) . '</strong></td></tr>
                                                <tr>
-                                                       <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' . $GLOBALS['tmpl']->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) . '</td></tr></table>
+                                                       <td><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td nowrap="nowrap">' . $GLOBALS['tmpl']->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) . '</td></tr></table>
                                                        </td>
                                                </tr>
                                        ';
@@ -209,7 +212,6 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
                                        }
                                }
                                $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
-                               next($GLOBALS['tmpl']->clearList_setup);
                        }
                        $theOutput .= '
                                </table>
@@ -219,5 +221,3 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
        }
 
 }
-
-?>
\ No newline at end of file