[FEATURE] Merge extensions TS/Template
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate / Classes / Controller / TemplateAnalyzerModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\TsTemplate\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * TypoScript template analyzer
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
36
37 /**
38 * Init
39 *
40 * @param object $pObj
41 * @param array $conf
42 * @return void
43 * @todo Define visibility
44 */
45 public function init(&$pObj, $conf) {
46 parent::init($pObj, $conf);
47 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf');
48 $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
49 }
50
51 /**
52 * Mod menu
53 *
54 * @return array
55 * @todo Define visibility
56 */
57 public function modMenu() {
58 return array(
59 'ts_analyzer_checkSetup' => '1',
60 'ts_analyzer_checkConst' => '1',
61 'ts_analyzer_checkLinenum' => '1',
62 'ts_analyzer_checkComments' => '1',
63 'ts_analyzer_checkCrop' => '1',
64 'ts_analyzer_checkSyntax' => '1'
65 );
66 }
67
68 /**
69 * Initialize editor
70 *
71 * @param integer $pageId
72 * @param integer $template_uid
73 * @return integer
74 * @todo Define visibility
75 */
76 public function initialize_editor($pageId, $template_uid = 0) {
77 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
78 $GLOBALS['tmpl'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
79 // Do not log time-performance information
80 $GLOBALS['tmpl']->tt_track = 0;
81 $GLOBALS['tmpl']->init();
82 // Gets the rootLine
83 $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
84 $GLOBALS['rootLine'] = $sys_page->getRootLine($pageId);
85 // This generates the constants/config + hierarchy info for the template.
86 $GLOBALS['tmpl']->runThroughTemplates($GLOBALS['rootLine'], $template_uid);
87 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
88 $GLOBALS['tplRow'] = $GLOBALS['tmpl']->ext_getFirstTemplate($pageId, $template_uid);
89 if (is_array($GLOBALS['tplRow'])) {
90 // IF there was a template...
91 return 1;
92 }
93 }
94
95 /**
96 * Main
97 *
98 * @return string
99 * @todo Define visibility
100 */
101 public function main() {
102 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
103 // Checking for more than one template an if, set a menu...
104 $manyTemplatesMenu = $this->pObj->templateMenu();
105 $template_uid = 0;
106 if ($manyTemplatesMenu) {
107 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
108 }
109 // BUGBUG: Should we check if the uset may at all read and write template-records???
110 $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
111 // initialize
112 if ($existTemplate) {
113 $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'] . ')' : '')));
114 }
115 if ($manyTemplatesMenu) {
116 $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
117 }
118 $GLOBALS['tmpl']->clearList_const_temp = array_flip($GLOBALS['tmpl']->clearList_const);
119 $GLOBALS['tmpl']->clearList_setup_temp = array_flip($GLOBALS['tmpl']->clearList_setup);
120 $pointer = count($GLOBALS['tmpl']->hierarchyInfo);
121 $GLOBALS['tmpl']->hierarchyInfoArr = $GLOBALS['tmpl']->ext_process_hierarchyInfo(array(), $pointer);
122 $GLOBALS['tmpl']->processIncludes();
123 $hierarArr = array();
124 $head = '<tr class="t3-row-header">';
125 $head .= '<td>' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>';
126 $head .= '<td>' . $GLOBALS['LANG']->getLL('rootlevel', TRUE) . '</td>';
127 $head .= '<td>' . $GLOBALS['LANG']->getLL('clearSetup', TRUE) . '</td>';
128 $head .= '<td>' . $GLOBALS['LANG']->getLL('clearConstants', TRUE) . '</td>';
129 $head .= '<td>' . $GLOBALS['LANG']->getLL('pid', TRUE) . '</td>';
130 $head .= '<td>' . $GLOBALS['LANG']->getLL('rootline', TRUE) . '</td>';
131 $head .= '<td>' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '</td>';
132 $head .= '</tr>';
133 $hierar = implode(array_reverse($GLOBALS['tmpl']->ext_getTemplateHierarchyArr($GLOBALS['tmpl']->hierarchyInfoArr, '', array(), 1)), '');
134 $hierar = '<table id="ts-analyzer" cellpadding="0" cellspacing="0">' . $head . $hierar . '</table>';
135 $theOutput .= $this->pObj->doc->spacer(5);
136 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', TRUE), $hierar, 0, 1);
137 $urlParameters = array(
138 'id' => $GLOBALS['SOBE']->id,
139 'template' => 'all'
140 );
141 $aHref = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_ts', $urlParameters);
142 $completeLink = '<p><a href="' . htmlspecialchars($aHref) . '">' . $GLOBALS['LANG']->getLL('viewCompleteTS', TRUE) . '</a></p>';
143 $theOutput .= $this->pObj->doc->spacer(5);
144 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('completeTS', TRUE), $completeLink, 0, 1);
145 $theOutput .= $this->pObj->doc->spacer(15);
146 // Output options
147 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions', TRUE), '', FALSE, TRUE);
148 $addParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') ? '&template=' . \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') : '';
149 $theOutput .= '<div class="tst-analyzer-options">' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkLinenum]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], '', $addParams, 'id="checkTs_analyzer_checkLinenum"') . '<label for="checkTs_analyzer_checkLinenum">' . $GLOBALS['LANG']->getLL('lineNumbers', TRUE) . '</label> ' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkSyntax]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], '', $addParams, 'id="checkTs_analyzer_checkSyntax"') . '<label for="checkTs_analyzer_checkSyntax">' . $GLOBALS['LANG']->getLL('syntaxHighlight', TRUE) . '</label> ' . (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'] ? \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkComments]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], '', $addParams, 'id="checkTs_analyzer_checkComments"') . '<label for="checkTs_analyzer_checkComments">' . $GLOBALS['LANG']->getLL('comments', TRUE) . '</label> ' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkCrop]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], '', $addParams, 'id="checkTs_analyzer_checkCrop"') . '<label for="checkTs_analyzer_checkCrop">' . $GLOBALS['LANG']->getLL('cropLines', TRUE) . '</label> ' : '') . '</div>';
150 $theOutput .= $this->pObj->doc->spacer(25);
151 // Output Constants
152 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template')) {
153 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', TRUE), '', 0, 1);
154 $theOutput .= $this->pObj->doc->sectionEnd();
155 $theOutput .= '
156 <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
157 ';
158 // Don't know why -2 and not 0... :-) But works.
159 $GLOBALS['tmpl']->ext_lineNumberOffset = -2;
160 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'const';
161 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines(('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'])))) + 1;
162 reset($GLOBALS['tmpl']->clearList_const);
163 foreach ($GLOBALS['tmpl']->constants as $key => $val) {
164 $cVal = current($GLOBALS['tmpl']->clearList_const);
165 if ($cVal == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
166 $theOutput .= '
167 <tr>
168 </td><td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[$cVal]) . '</strong></td></tr>
169 <tr>
170 <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>
171 </td>
172 </tr>
173 ';
174 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') != 'all') {
175 break;
176 }
177 }
178 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
179 next($GLOBALS['tmpl']->clearList_const);
180 }
181 $theOutput .= '
182 </table>
183 ';
184 }
185 // Output setup
186 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template')) {
187 $theOutput .= $this->pObj->doc->spacer(15);
188 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', TRUE), '', 0, 1);
189 $theOutput .= $this->pObj->doc->sectionEnd();
190 $theOutput .= '
191 <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
192 ';
193 $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
194 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'setup';
195 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines(('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'])))) + 1;
196 reset($GLOBALS['tmpl']->clearList_setup);
197 foreach ($GLOBALS['tmpl']->config as $key => $val) {
198 if (current($GLOBALS['tmpl']->clearList_setup) == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
199 $theOutput .= '
200 <tr>
201 <td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[current($GLOBALS['tmpl']->clearList_setup)]) . '</strong></td></tr>
202 <tr>
203 <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>
204 </td>
205 </tr>
206 ';
207 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') != 'all') {
208 break;
209 }
210 }
211 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
212 next($GLOBALS['tmpl']->clearList_setup);
213 }
214 $theOutput .= '
215 </table>
216 ';
217 }
218 return $theOutput;
219 }
220
221 }
222
223 ?>