[FEATURE] Add fluid debug information to admin panel
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / View / AdminPanelView.php
1 <?php
2 namespace TYPO3\CMS\Frontend\View;
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\Core\Cache\CacheManager;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
21 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
25 use TYPO3\CMS\Core\Type\Bitmask\Permission;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29 /**
30 * View class for the admin panel in frontend editing.
31 */
32 class AdminPanelView
33 {
34 /**
35 * Determines whether the update button should be shown.
36 *
37 * @var bool
38 */
39 protected $extNeedUpdate = false;
40
41 /**
42 * Force preview
43 *
44 * @var bool
45 */
46 protected $ext_forcePreview = false;
47
48 /**
49 * @var string
50 */
51 protected $extJSCODE = '';
52
53 /**
54 * @var IconFactory
55 */
56 protected $iconFactory;
57
58 /**
59 * Determines whether EXT:feedit is loaded
60 *
61 * @var bool
62 */
63 protected $extFeEditLoaded = false;
64
65 /**
66 * Constructor
67 */
68 public function __construct()
69 {
70 $this->initialize();
71 }
72
73 /**
74 * Initializes settings for the admin panel.
75 *
76 * @return void
77 */
78 public function initialize()
79 {
80 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
81 $this->saveConfigOptions();
82 $typoScriptFrontend = $this->getTypoScriptFrontendController();
83 // Setting some values based on the admin panel
84 $this->extFeEditLoaded = ExtensionManagementUtility::isLoaded('feedit');
85 $typoScriptFrontend->forceTemplateParsing = $this->extGetFeAdminValue('tsdebug', 'forceTemplateParsing');
86 $typoScriptFrontend->displayEditIcons = $this->extGetFeAdminValue('edit', 'displayIcons');
87 $typoScriptFrontend->displayFieldEditIcons = $this->extGetFeAdminValue('edit', 'displayFieldIcons');
88 if ($this->extGetFeAdminValue('tsdebug', 'displayQueries')) {
89 // Do not override if the value is already set in \TYPO3\CMS\Core\Database\DatabaseConnection
90 if ($this->getDatabaseConnection()->explainOutput == 0) {
91 // Enable execution of EXPLAIN SELECT queries
92 $this->getDatabaseConnection()->explainOutput = 3;
93 }
94 }
95 if (GeneralUtility::_GP('ADMCMD_editIcons')) {
96 $typoScriptFrontend->displayFieldEditIcons = 1;
97 }
98 if (GeneralUtility::_GP('ADMCMD_simUser')) {
99 $this->getBackendUser()->uc['TSFE_adminConfig']['preview_simulateUserGroup'] = (int)GeneralUtility::_GP('ADMCMD_simUser');
100 $this->ext_forcePreview = true;
101 }
102 if (GeneralUtility::_GP('ADMCMD_simTime')) {
103 $this->getBackendUser()->uc['TSFE_adminConfig']['preview_simulateDate'] = (int)GeneralUtility::_GP('ADMCMD_simTime');
104 $this->ext_forcePreview = true;
105 }
106 if ($typoScriptFrontend->forceTemplateParsing) {
107 $typoScriptFrontend->set_no_cache('Admin Panel: Force template parsing', true);
108 } elseif ($this->extFeEditLoaded && $typoScriptFrontend->displayEditIcons) {
109 $typoScriptFrontend->set_no_cache('Admin Panel: Display edit icons', true);
110 } elseif ($this->extFeEditLoaded && $typoScriptFrontend->displayFieldEditIcons) {
111 $typoScriptFrontend->set_no_cache('Admin Panel: Display field edit icons', true);
112 } elseif (GeneralUtility::_GP('ADMCMD_view')) {
113 $typoScriptFrontend->set_no_cache('Admin Panel: Display preview', true);
114 }
115 }
116
117 /**
118 * Add an additional stylesheet
119 *
120 * @return string
121 */
122 public function getAdminPanelHeaderData()
123 {
124 $result = '';
125 if (!empty($GLOBALS['TBE_STYLES']['stylesheets']['admPanel'])) {
126 $stylesheet = GeneralUtility::locationHeaderUrl($GLOBALS['TBE_STYLES']['stylesheets']['admPanel']);
127 $result = '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($stylesheet) . '" />';
128 }
129 return $result;
130 }
131
132 /**
133 * Checks if an Admin Panel section ("module") is available for the user. If so, TRUE is returned.
134 *
135 * @param string $key The module key, eg. "edit", "preview", "info" etc.
136 * @return bool
137 */
138 public function isAdminModuleEnabled($key)
139 {
140 $result = false;
141 // Returns TRUE if the module checked is "preview" and the forcePreview flag is set.
142 if ($key === 'preview' && $this->ext_forcePreview) {
143 $result = true;
144 } elseif (!empty($this->getBackendUser()->extAdminConfig['enable.']['all'])) {
145 $result = true;
146 } elseif (!empty($this->getBackendUser()->extAdminConfig['enable.'][$key])) {
147 $result = true;
148 }
149 return $result;
150 }
151
152 /**
153 * Saves any change in settings made in the Admin Panel.
154 * Called from \TYPO3\CMS\Frontend\Http\RequestHandler right after access check for the Admin Panel
155 *
156 * @return void
157 */
158 public function saveConfigOptions()
159 {
160 $input = GeneralUtility::_GP('TSFE_ADMIN_PANEL');
161 $beUser = $this->getBackendUser();
162 if (is_array($input)) {
163 // Setting
164 $beUser->uc['TSFE_adminConfig'] = array_merge(!is_array($beUser->uc['TSFE_adminConfig']) ? [] : $beUser->uc['TSFE_adminConfig'], $input);
165 unset($beUser->uc['TSFE_adminConfig']['action']);
166 // Actions:
167 if ($input['action']['clearCache'] && $this->isAdminModuleEnabled('cache')) {
168 $beUser->extPageInTreeInfo = [];
169 $theStartId = (int)$input['cache_clearCacheId'];
170 $this->getTypoScriptFrontendController()->clearPageCacheContent_pidList($beUser->extGetTreeList($theStartId, $this->extGetFeAdminValue('cache', 'clearCacheLevels'), 0, $beUser->getPagePermsClause(1)) . $theStartId);
171 }
172 // Saving
173 $beUser->writeUC();
174 // Flush fluid template cache
175 $cacheManager = new CacheManager();
176 $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
177 $cacheManager->getCache('fluid_template')->flush();
178 }
179 $this->getTimeTracker()->LR = $this->extGetFeAdminValue('tsdebug', 'LR');
180 if ($this->extGetFeAdminValue('cache', 'noCache')) {
181 $this->getTypoScriptFrontendController()->set_no_cache('Admin Panel: No Caching', true);
182 }
183 }
184
185 /**
186 * Returns the value for an Admin Panel setting.
187 *
188 * @param string $sectionName Module key
189 * @param string $val Setting key
190 * @return mixed The setting value
191 */
192 public function extGetFeAdminValue($sectionName, $val = '')
193 {
194 if (!$this->isAdminModuleEnabled($sectionName)) {
195 return null;
196 }
197
198 $beUser = $this->getBackendUser();
199 // Exceptions where the values can be overridden (forced) from backend:
200 // deprecated
201 if (
202 $sectionName === 'edit' && (
203 $val === 'displayIcons' && $beUser->extAdminConfig['module.']['edit.']['forceDisplayIcons'] ||
204 $val === 'displayFieldIcons' && $beUser->extAdminConfig['module.']['edit.']['forceDisplayFieldIcons'] ||
205 $val === 'editNoPopup' && $beUser->extAdminConfig['module.']['edit.']['forceNoPopup']
206 )
207 ) {
208 return true;
209 }
210
211 // Override all settings with user TSconfig
212 if ($val && isset($beUser->extAdminConfig['override.'][$sectionName . '.'][$val])) {
213 return $beUser->extAdminConfig['override.'][$sectionName . '.'][$val];
214 }
215 if (isset($beUser->extAdminConfig['override.'][$sectionName])) {
216 return $beUser->extAdminConfig['override.'][$sectionName];
217 }
218
219 $returnValue = $val ? $beUser->uc['TSFE_adminConfig'][$sectionName . '_' . $val] : 1;
220
221 // Exception for preview
222 if ($sectionName === 'preview' && $this->ext_forcePreview) {
223 return !$val ? true : $returnValue;
224 }
225
226 // See if the menu is expanded!
227 return $this->isAdminModuleOpen($sectionName) ? $returnValue : null;
228 }
229
230 /**
231 * Enables the force preview option.
232 *
233 * @return void
234 */
235 public function forcePreview()
236 {
237 $this->ext_forcePreview = true;
238 }
239
240 /**
241 * Returns TRUE if admin panel module is open
242 *
243 * @param string $key Module key
244 * @return bool TRUE, if the admin panel is open for the specified admin panel module key.
245 */
246 public function isAdminModuleOpen($key)
247 {
248 return $this->getBackendUser()->uc['TSFE_adminConfig']['display_top'] && $this->getBackendUser()->uc['TSFE_adminConfig']['display_' . $key];
249 }
250
251 /**
252 * Creates and returns the HTML code for the Admin Panel in the TSFE frontend.
253 *
254 * @throws \UnexpectedValueException
255 * @return string HTML for the Admin Panel
256 */
257 public function display()
258 {
259 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_tsfe.xlf');
260 $moduleContent = $updateButton = '';
261
262 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_top']) {
263 if ($this->isAdminModuleEnabled('preview')) {
264 $moduleContent .= $this->getPreviewModule();
265 }
266 if ($this->isAdminModuleEnabled('cache')) {
267 $moduleContent .= $this->getCacheModule();
268 }
269 if ($this->isAdminModuleEnabled('edit')) {
270 $moduleContent .= $this->getEditModule();
271 }
272 if ($this->isAdminModuleEnabled('tsdebug')) {
273 $moduleContent .= $this->getTSDebugModule();
274 }
275 if ($this->isAdminModuleEnabled('info')) {
276 $moduleContent .= $this->getInfoModule();
277 }
278 }
279 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'])) {
280 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'] as $classRef) {
281 $hookObject = GeneralUtility::getUserObj($classRef);
282 if (!$hookObject instanceof AdminPanelViewHookInterface) {
283 throw new \UnexpectedValueException($classRef . ' must implement interface ' . AdminPanelViewHookInterface::class, 1311942539);
284 }
285 $moduleContent .= $hookObject->extendAdminPanel($moduleContent, $this);
286 }
287 }
288 $row = $this->extGetLL('adminPanelTitle') . ': <span class="typo3-adminPanel-beuser">' . htmlspecialchars($this->getBackendUser()->user['username']) . '</span>';
289 $isVisible = $this->getBackendUser()->uc['TSFE_adminConfig']['display_top'];
290 $cssClassName = 'typo3-adminPanel-panel-' . ($isVisible ? 'open' : 'closed');
291 $header = '<div class="typo3-adminPanel-header">' . '<div id="typo3-adminPanel-header" class="' . $cssClassName . '">' . '<span class="typo3-adminPanel-header-title">' . $row . '</span>' . $this->linkSectionHeader('top', '<span class="typo3-adminPanel-header-button fa"></span>', 'typo3-adminPanel-header-buttonWrapper') . '<input type="hidden" name="TSFE_ADMIN_PANEL[display_top]" value="' . $this->getBackendUser()->uc['TSFE_adminConfig']['display_top'] . '" /></div>' . '</div>';
292 if ($moduleContent && $this->extNeedUpdate) {
293 $updateButton = '<div class="typo3-adminPanel-itemRow updatebutton"><div class="typo3-adminPanel-section-content">
294 <input class="btn btn-default" type="submit" value="' . $this->extGetLL('update') . '" />
295 </div></div>';
296 }
297 $query = !GeneralUtility::_GET('id') ? '<input type="hidden" name="id" value="' . $this->getTypoScriptFrontendController()->id . '" />' : '';
298
299 // The dummy field is needed for Firefox: to force a page reload on submit
300 // which must change the form value with JavaScript (see "onsubmit" attribute of the "form" element")
301 $query .= '<input type="hidden" name="TSFE_ADMIN_PANEL[DUMMY]" value="" />';
302 foreach (GeneralUtility::_GET() as $key => $value) {
303 if ($key != 'TSFE_ADMIN_PANEL') {
304 if (is_array($value)) {
305 $query .= $this->getHiddenFields($key, $value);
306 } else {
307 $query .= '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />';
308 }
309 }
310 }
311 $out = '
312 <!--
313 TYPO3 Admin panel start
314 -->
315 <a id="TSFE_ADMIN_PANEL"></a>
316 <form id="TSFE_ADMIN_PANEL_FORM" name="TSFE_ADMIN_PANEL_FORM" action="' . htmlspecialchars(GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT')) . '#TSFE_ADMIN_PANEL" method="get" onsubmit="document.forms.TSFE_ADMIN_PANEL_FORM[\'TSFE_ADMIN_PANEL[DUMMY]\'].value=Math.random().toString().substring(2,8)">' . $query . '<div class="typo3-adminPanel">' . $header . $updateButton . $moduleContent . '</div></form>';
317 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_top']) {
318 $out .= '<script type="text/javascript" src="' . htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix) . ExtensionManagementUtility::siteRelPath('backend') . 'Resources/Public/JavaScript/jsfunc.evalfield.js"></script>';
319 $out .= '<script type="text/javascript">/*<![CDATA[*/' . GeneralUtility::minifyJavaScript('
320 var evalFunc = new evalFunc();
321 // TSFEtypo3FormFieldSet()
322 function TSFEtypo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue) { //
323 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
324 var theValue = document.TSFE_ADMIN_PANEL_FORM[theField].value;
325 if (checkbox && theValue==checkboxValue) {
326 document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value="";
327 alert(theField);
328 document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"].checked = "";
329 } else {
330 document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue);
331 if (document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"]) {
332 document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"].checked = "on";
333 }
334 }
335 }
336 // TSFEtypo3FormFieldGet()
337 function TSFEtypo3FormFieldGet(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off) { //
338 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
339 if (checkbox_off) {
340 document.TSFE_ADMIN_PANEL_FORM[theField].value=checkboxValue;
341 }else{
342 document.TSFE_ADMIN_PANEL_FORM[theField].value = evalFunc.evalObjValue(theFObj, document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value);
343 }
344 TSFEtypo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue);
345 }') . '/*]]>*/</script><script language="javascript" type="text/javascript">' . $this->extJSCODE . '</script>';
346 }
347 $cssPath = htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix . ExtensionManagementUtility::siteRelPath('frontend')) . 'Resources/Public/Css/adminpanel.css';
348 $out .= '<script src="' . GeneralUtility::locationHeaderUrl(ExtensionManagementUtility::siteRelPath('frontend') . 'Resources/Public/JavaScript/AdminPanel.js') . '" type="text/javascript"></script><script type="text/javascript">/*<![CDATA[*/' . 'typo3AdminPanel = new TYPO3AdminPanel();typo3AdminPanel.init("typo3-adminPanel-header", "TSFE_ADMIN_PANEL_FORM");' . '/*]]>*/</script>
349 <link type="text/css" rel="stylesheet" href="' . $cssPath . '" media="all" />';
350 $out .= $this->getAdminPanelHeaderData();
351 $out .='
352 <!--
353 TYPO3 admin panel end
354 -->
355 ';
356
357 return $out;
358 }
359
360 /**
361 * Fetches recursively all GET parameters as hidden fields.
362 * Called from display()
363 *
364 * @param string $key Current key
365 * @param array $val Current value
366 * @return string Hidden fields
367 * @see display()
368 */
369 protected function getHiddenFields($key, array $val)
370 {
371 $out = '';
372 foreach ($val as $k => $v) {
373 if (is_array($v)) {
374 $out .= $this->getHiddenFields($key . '[' . $k . ']', $v);
375 } else {
376 $out .= '<input type="hidden" name="' . htmlspecialchars($key) . '[' . htmlspecialchars($k) . ']" value="' . htmlspecialchars($v) . '">' . LF;
377 }
378 }
379 return $out;
380 }
381
382 /*****************************************************
383 * Creating sections of the Admin Panel
384 ****************************************************/
385 /**
386 * Creates the content for the "preview" section ("module") of the Admin Panel
387 *
388 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
389 * @see display()
390 */
391 protected function getPreviewModule()
392 {
393 $out = $this->extGetHead('preview');
394 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_preview']) {
395 $this->extNeedUpdate = true;
396 $out .= $this->extGetItem('preview_showHiddenPages', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[preview_showHiddenPages]" value="0" /><input type="checkbox" id="preview_showHiddenPages" name="TSFE_ADMIN_PANEL[preview_showHiddenPages]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['preview_showHiddenPages'] ? ' checked="checked"' : '') . ' />');
397 $out .= $this->extGetItem('preview_showHiddenRecords', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[preview_showHiddenRecords]" value="0" /><input type="checkbox" id="preview_showHiddenRecords" name="TSFE_ADMIN_PANEL[preview_showHiddenRecords]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['preview_showHiddenRecords'] ? ' checked="checked"' : '') . ' />');
398 if (\TYPO3\CMS\Core\Utility\GeneralUtility::getApplicationContext()->isDevelopment()) {
399 $out .= $this->extGetItem('preview_showFluidDebug', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[preview_showFluidDebug]" value="0" /><input type="checkbox" id="preview_showFluidDebug" name="TSFE_ADMIN_PANEL[preview_showFluidDebug]" value="1"' . (!empty($this->getBackendUser()->uc['TSFE_adminConfig']['preview_showFluidDebug']) ? ' checked="checked"' : '') . ' />');
400 }
401 // Simulate date
402 $out .= $this->extGetItem('preview_simulateDate', '<input type="text" id="preview_simulateDate" name="TSFE_ADMIN_PANEL[preview_simulateDate]_hr" onchange="TSFEtypo3FormFieldGet(\'TSFE_ADMIN_PANEL[preview_simulateDate]\', \'datetime\', \'\', 1,0);" /><input type="hidden" name="TSFE_ADMIN_PANEL[preview_simulateDate]" value="' . $this->getBackendUser()->uc['TSFE_adminConfig']['preview_simulateDate'] . '" />');
403 $this->extJSCODE .= 'TSFEtypo3FormFieldSet("TSFE_ADMIN_PANEL[preview_simulateDate]", "datetime", "", 0, 0);';
404 // Simulate fe_user:
405
406 $options = '';
407
408 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
409 ->getQueryBuilderForTable('fe_groups');
410 $queryBuilder->getRestrictions()
411 ->removeAll()
412 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
413
414 $result = $queryBuilder->select('fe_groups.uid', 'fe_groups.title')
415 ->from('fe_groups')
416 ->from('pages')
417 ->where(
418 $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('fe_groups.pid')),
419 $this->getBackendUser()->getPagePermsClause(1)
420 )
421 ->orderBy('fe_groups.title')
422 ->execute();
423
424 while ($row = $result->fetch()) {
425 $options .= '<option value="' . $row['uid'] . '"'
426 . ($this->getBackendUser()->uc['TSFE_adminConfig']['preview_simulateUserGroup'] == $row['uid'] ? ' selected="selected"' : '')
427 . '>' . htmlspecialchars(($row['title'] . ' [' . $row['uid'] . ']')) . '</option>';
428 }
429 if ($options) {
430 $options = '<option value="0">&nbsp;</option>' . $options;
431 $out .= $this->extGetItem(
432 'preview_simulateUserGroup',
433 '<select id="preview_simulateUserGroup" name="TSFE_ADMIN_PANEL[preview_simulateUserGroup]">'
434 . $options . '</select>'
435 );
436 }
437 }
438 return $out;
439 }
440
441 /**
442 * Creates the content for the "cache" section ("module") of the Admin Panel
443 *
444 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
445 * @see display()
446 */
447 protected function getCacheModule()
448 {
449 $out = $this->extGetHead('cache');
450 $beUser = $this->getBackendUser();
451 if ($beUser->uc['TSFE_adminConfig']['display_cache']) {
452 $this->extNeedUpdate = true;
453 $out .= $this->extGetItem('cache_noCache', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[cache_noCache]" value="0" /><input id="cache_noCache" type="checkbox" name="TSFE_ADMIN_PANEL[cache_noCache]" value="1"' . ($beUser->uc['TSFE_adminConfig']['cache_noCache'] ? ' checked="checked"' : '') . ' />');
454 $levels = $beUser->uc['TSFE_adminConfig']['cache_clearCacheLevels'];
455 $options = '';
456 $options .= '<option value="0"' . ($levels == 0 ? ' selected="selected"' : '') . '>' . $this->extGetLL('div_Levels_0') . '</option>';
457 $options .= '<option value="1"' . ($levels == 1 ? ' selected="selected"' : '') . '>' . $this->extGetLL('div_Levels_1') . '</option>';
458 $options .= '<option value="2"' . ($levels == 2 ? ' selected="selected"' : '') . '>' . $this->extGetLL('div_Levels_2') . '</option>';
459 $out .= $this->extGetItem('cache_clearLevels', '<select id="cache_clearLevels" name="TSFE_ADMIN_PANEL[cache_clearCacheLevels]">' . $options . '</select>' . '<input type="hidden" name="TSFE_ADMIN_PANEL[cache_clearCacheId]" value="' . $GLOBALS['TSFE']->id . '" /> <input class="btn btn-default" type="submit" value="' . $this->extGetLL('update') . '" />');
460 // Generating tree:
461 $depth = (int)$this->extGetFeAdminValue('cache', 'clearCacheLevels');
462 $outTable = '';
463 $tsfe = $this->getTypoScriptFrontendController();
464 $beUser->extPageInTreeInfo = [];
465 $beUser->extPageInTreeInfo[] = [$tsfe->page['uid'], htmlspecialchars($tsfe->page['title']), $depth + 1];
466 $beUser->extGetTreeList($tsfe->id, $depth, 0, $beUser->getPagePermsClause(1));
467 foreach ($beUser->extPageInTreeInfo as $key => $row) {
468 $outTable .= '<tr class="typo3-adminPanel-itemRow ' . ($key % 2 == 0 ? 'line-even' : 'line-odd') . '">' . '<td><span style="width: ' . ($depth + 1 - $row[2]) * 18 . 'px; height: 1px; display: inline-block;"></span>' . $this->iconFactory->getIcon('apps-pagetree-page-default', Icon::SIZE_SMALL)->render() . htmlspecialchars($row[1]) . '</td><td>' . $beUser->extGetNumberOfCachedPages($row[0]) . '</td></tr>';
469 }
470 $outTable = '<table class="typo3-adminPanel-table"><thead><tr><th colspan="2">' . $this->extGetLL('cache_cacheEntries') . '</th></tr></thead>' . $outTable . '</table>';
471 $outTable .= '<span class="fa fa-bolt clear-cache-icon"><!-- --></span><input class="btn btn-default clear-cache" type="submit" name="TSFE_ADMIN_PANEL[action][clearCache]" value="' . $this->extGetLL('cache_doit') . '" />';
472
473 $out .= $this->extGetItem('', $outTable, '', 'typo3-adminPanel-tableRow', 'typo3-adminPanel-table-wrapper');
474 }
475 return $out;
476 }
477
478 /**
479 * Creates the content for the "edit" section ("module") of the Admin Panel
480 *
481 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
482 * @see display()
483 */
484 protected function getEditModule()
485 {
486 $out = $this->extGetHead('edit');
487 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_edit']) {
488 // If another page module was specified, replace the default Page module with the new one
489 $newPageModule = trim($this->getBackendUser()->getTSConfigVal('options.overridePageModule'));
490 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
491 $this->extNeedUpdate = true;
492 if ($this->extFeEditLoaded) {
493 $out .= $this->extGetItem('edit_displayFieldIcons', '',
494 '<input type="hidden" name="TSFE_ADMIN_PANEL[edit_displayFieldIcons]" value="0" /><input type="checkbox" id="edit_displayFieldIcons" name="TSFE_ADMIN_PANEL[edit_displayFieldIcons]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['edit_displayFieldIcons'] ? ' checked="checked"' : '') . ' />');
495 $out .= $this->extGetItem('edit_displayIcons', '',
496 '<input type="hidden" name="TSFE_ADMIN_PANEL[edit_displayIcons]" value="0" /><input type="checkbox" id="edit_displayIcons" name="TSFE_ADMIN_PANEL[edit_displayIcons]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['edit_displayIcons'] ? ' checked="checked"' : '') . ' />');
497 }
498 $out .= $this->extGetItem('', $this->ext_makeToolBar());
499 if (!GeneralUtility::_GP('ADMCMD_view')) {
500 $out .= $this->extGetItem('', '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(('
501 if (parent.opener && parent.opener.top && parent.opener.top.TS) {
502 parent.opener.top.fsMod.recentIds["web"]=' . (int)$this->getTypoScriptFrontendController()->page['uid'] . ';
503 if (parent.opener.top.content && parent.opener.top.content.nav_frame && parent.opener.top.content.nav_frame.refresh_nav) {
504 parent.opener.top.content.nav_frame.refresh_nav();
505 }
506 parent.opener.top.goToModule("' . $pageModule . '");
507 parent.opener.top.focus();
508 } else {
509 vHWin=window.open(' . GeneralUtility::quoteJSvalue(BackendUtility::getBackendScript()) . ',\'' . md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '\');
510 vHWin.focus();
511 }
512 return false;
513 ')) . '">' . $this->extGetLL('edit_openAB') . '</a>');
514 }
515 }
516 return $out;
517 }
518
519 /**
520 * Creates the content for the "tsdebug" section ("module") of the Admin Panel
521 *
522 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
523 * @see display()
524 */
525 protected function getTSDebugModule()
526 {
527 $out = $this->extGetHead('tsdebug');
528 $beuser = $this->getBackendUser();
529 if ($beuser->uc['TSFE_adminConfig']['display_tsdebug']) {
530 $this->extNeedUpdate = true;
531 $out .= $this->extGetItem('tsdebug_tree', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_tree]" value="0" /><input type="checkbox" id="tsdebug_tree" name="TSFE_ADMIN_PANEL[tsdebug_tree]" value="1"' . ($beuser->uc['TSFE_adminConfig']['tsdebug_tree'] ? ' checked="checked"' : '') . ' />');
532 $out .= $this->extGetItem('tsdebug_displayTimes', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_displayTimes]" value="0" /><input id="tsdebug_displayTimes" type="checkbox" name="TSFE_ADMIN_PANEL[tsdebug_displayTimes]" value="1"' . ($beuser->uc['TSFE_adminConfig']['tsdebug_displayTimes'] ? ' checked="checked"' : '') . ' />');
533 $out .= $this->extGetItem('tsdebug_displayMessages', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_displayMessages]" value="0" /><input type="checkbox" id="tsdebug_displayMessages" name="TSFE_ADMIN_PANEL[tsdebug_displayMessages]" value="1"' . ($beuser->uc['TSFE_adminConfig']['tsdebug_displayMessages'] ? ' checked="checked"' : '') . ' />');
534 $out .= $this->extGetItem('tsdebug_LR', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_LR]" value="0" /><input type="checkbox" id="tsdebug_LR" name="TSFE_ADMIN_PANEL[tsdebug_LR]" value="1"' . ($beuser->uc['TSFE_adminConfig']['tsdebug_LR'] ? ' checked="checked"' : '') . ' />');
535 $out .= $this->extGetItem('tsdebug_displayContent', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_displayContent]" value="0" /><input type="checkbox" id="tsdebug_displayContent" name="TSFE_ADMIN_PANEL[tsdebug_displayContent]" value="1"' . ($beuser->uc['TSFE_adminConfig']['tsdebug_displayContent'] ? ' checked="checked"' : '') . ' />');
536 $out .= $this->extGetItem('tsdebug_displayQueries', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_displayQueries]" value="0" /><input type="checkbox" id="tsdebug_displayQueries" name="TSFE_ADMIN_PANEL[tsdebug_displayQueries]" value="1"' . ($beuser->uc['TSFE_adminConfig']['tsdebug_displayQueries'] ? ' checked="checked"' : '') . ' />');
537 $out .= $this->extGetItem('tsdebug_forceTemplateParsing', '', '<input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_forceTemplateParsing]" value="0" /><input type="checkbox" id="tsdebug_forceTemplateParsing" name="TSFE_ADMIN_PANEL[tsdebug_forceTemplateParsing]" value="1"' . ($beuser->uc['TSFE_adminConfig']['tsdebug_forceTemplateParsing'] ? ' checked="checked"' : '') . ' />');
538 $timeTracker = $this->getTimeTracker();
539 $timeTracker->printConf['flag_tree'] = $this->extGetFeAdminValue('tsdebug', 'tree');
540 $timeTracker->printConf['allTime'] = $this->extGetFeAdminValue('tsdebug', 'displayTimes');
541 $timeTracker->printConf['flag_messages'] = $this->extGetFeAdminValue('tsdebug', 'displayMessages');
542 $timeTracker->printConf['flag_content'] = $this->extGetFeAdminValue('tsdebug', 'displayContent');
543 $timeTracker->printConf['flag_queries'] = $this->extGetFeAdminValue('tsdebug', 'displayQueries');
544 $out .= $this->extGetItem('', $timeTracker->printTSlog(), '', 'typo3-adminPanel-tableRow', 'typo3-adminPanel-table-wrapper scroll-table');
545 }
546 return $out;
547 }
548
549 /**
550 * Creates the content for the "info" section ("module") of the Admin Panel
551 *
552 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
553 * @see display()
554 */
555 protected function getInfoModule()
556 {
557 $head = $this->extGetHead('info');
558 $out = '';
559 $tsfe = $this->getTypoScriptFrontendController();
560 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_info']) {
561 $tableArr = [];
562 if ($this->extGetFeAdminValue('cache', 'noCache')) {
563 $theBytes = 0;
564 $count = 0;
565 if (!empty($tsfe->imagesOnPage)) {
566 $tableArr[] = [$this->extGetLL('info_imagesOnPage'), count($tsfe->imagesOnPage), true];
567 foreach ($GLOBALS['TSFE']->imagesOnPage as $file) {
568 $fs = @filesize($file);
569 $tableArr[] = [TAB . $file, GeneralUtility::formatSize($fs)];
570 $theBytes += $fs;
571 $count++;
572 }
573 }
574 // Add an empty line
575 $tableArr[] = [$this->extGetLL('info_imagesSize'), GeneralUtility::formatSize($theBytes), true];
576 $tableArr[] = [$this->extGetLL('info_DocumentSize'), GeneralUtility::formatSize(strlen($tsfe->content)), true];
577 $tableArr[] = ['', ''];
578 }
579 $tableArr[] = [$this->extGetLL('info_id'), $tsfe->id];
580 $tableArr[] = [$this->extGetLL('info_type'), $tsfe->type];
581 $tableArr[] = [$this->extGetLL('info_groupList'), $tsfe->gr_list];
582 $tableArr[] = [$this->extGetLL('info_noCache'), $this->extGetLL('info_noCache_' . ($tsfe->no_cache ? 'no' : 'yes'))];
583 $tableArr[] = [$this->extGetLL('info_countUserInt'), count($tsfe->config['INTincScript'])];
584
585 if (!empty($tsfe->fe_user->user['uid'])) {
586 $tableArr[] = [$this->extGetLL('info_feuserName'), htmlspecialchars($tsfe->fe_user->user['username'])];
587 $tableArr[] = [$this->extGetLL('info_feuserId'), htmlspecialchars($tsfe->fe_user->user['uid'])];
588 }
589 $tableArr[] = [$this->extGetLL('info_totalParsetime'), $tsfe->scriptParseTime . ' ms', true];
590 $table = '';
591 foreach ($tableArr as $key => $arr) {
592 $label = (isset($arr[2]) ? '<strong>' . $arr[0] . '</strong>' : $arr[0]);
593 $value = (string)$arr[1] !== '' ? $arr[1] : '';
594 $table .=
595 '<tr class="typo3-adminPanel-itemRow ' . ($key % 2 == 0 ? 'line-even' : 'line-odd') . '">
596 <td>' . $label . '</td>
597 <td>' . htmlspecialchars($value) . '</td>
598 </tr>';
599 }
600 $out .= $table;
601 $out = '<table class="typo3-adminPanel-table">' . $out . '</table>';
602 $out = $this->extGetItem('', $out, '', 'typo3-adminPanel-tableRow', 'typo3-adminPanel-table-wrapper');
603 }
604
605 $out = $head . $out;
606 return $out;
607 }
608
609 /*****************************************************
610 * Admin Panel Layout Helper functions
611 ****************************************************/
612 /**
613 * Returns a row (with colspan=4) which is a header for a section in the Admin Panel.
614 * It will have a plus/minus icon and a label which is linked so that it submits the form which surrounds the whole Admin Panel when clicked, alterting the TSFE_ADMIN_PANEL[display_' . $pre . '] value
615 * See the functions get*Module
616 *
617 * @param string $sectionSuffix The suffix to the display_ label. Also selects the label from the LOCAL_LANG array.
618 * @return string HTML table row.
619 * @see extGetItem()
620 */
621 public function extGetHead($sectionSuffix)
622 {
623 $settingName = 'display_' . $sectionSuffix;
624 $isVisible = $this->getBackendUser()->uc['TSFE_adminConfig'][$settingName];
625 $cssClassName = 'typo3-adminPanel-section-' . ($isVisible ? 'open' : 'closed');
626 return '<div class="typo3-adminPanel-section-title"><div class="wrapper">' . $this->linkSectionHeader($sectionSuffix, $this->extGetLL($sectionSuffix), $cssClassName) . '<input type="hidden" name="TSFE_ADMIN_PANEL[' . $settingName . ']" value="' . $isVisible . '" /></div></div>';
627 }
628
629 /**
630 * Wraps a string in a link which will open/close a certain part of the Admin Panel
631 *
632 * @param string $sectionSuffix The code for the display_ label/key
633 * @param string $sectionTitle Title (in HTML-format)
634 * @param string $className The classname for the <a> tag
635 * @return string $className Linked input string
636 * @see extGetHead()
637 */
638 public function linkSectionHeader($sectionSuffix, $sectionTitle, $className = '')
639 {
640 $onclick = 'document.TSFE_ADMIN_PANEL_FORM[' . GeneralUtility::quoteJSvalue('TSFE_ADMIN_PANEL[display_' . $sectionSuffix . ']') . '].value=' . ($this->getBackendUser()->uc['TSFE_adminConfig']['display_' . $sectionSuffix] ? '0' : '1') . ';document.TSFE_ADMIN_PANEL_FORM.submit();return false;';
641 $content = '<div class="typo3-adminPanel-label">
642 <a href="javascript:void(0)" onclick="' . htmlspecialchars($onclick) . '"' . ($className ? ' class="fa ' . htmlspecialchars($className) . '"' : '') . '>'
643 . $sectionTitle .
644 '</a>
645 </div>';
646 return $content;
647 }
648
649 /**
650 * Returns a row (with 4 columns) for content in a section of the Admin Panel.
651 * It will take $pre as a key to a label to display and $element as the content to put into the forth cell.
652 *
653 * @param string $title Key to label
654 * @param string $content The HTML content for the forth table cell.
655 * @param string $checkbox The HTML for a checkbox or hidden fields.
656 * @param string $innerDivClass The Class attribute for the td element.
657 * @param string $outerDivClass The Class attribute for the tr element.
658 * @return string HTML table row.
659 * @see extGetHead()
660 */
661 public function extGetItem($title, $content = '', $checkbox = '', $outerDivClass = null, $innerDivClass = null)
662 {
663 $title = $title ? '<label for="' . htmlspecialchars($title) . '">' . $this->extGetLL($title) . '</label>' : '';
664 $outerDivClass === null ? $out = '<div class="typo3-adminPanel-itemRow">' : $out = '<div class="' . $outerDivClass . '">';
665 $innerDivClass === null ? $out .= '<div class="typo3-adminPanel-section-content">' : $out .= '<div class="' . $innerDivClass . '">';
666 $out .= $checkbox . $title . $content . '</div>
667 </div>';
668 return $out;
669 }
670
671 /**
672 * Creates the tool bar links for the "edit" section of the Admin Panel.
673 *
674 * @return string A string containing images wrapped in <a>-tags linking them to proper functions.
675 */
676 public function ext_makeToolBar()
677 {
678 $tsfe = $this->getTypoScriptFrontendController();
679 // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead:
680 $tsConfig = BackendUtility::getModTSconfig($tsfe->page['uid'], 'mod');
681 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
682 ? $tsConfig['properties']['newContentElementWizard.']['override']
683 : 'new_content_element';
684 $newContentWizScriptPath = BackendUtility::getModuleUrl($moduleName);
685 $perms = $this->getBackendUser()->calcPerms($tsfe->page);
686 $langAllowed = $this->getBackendUser()->checkLanguageAccess($tsfe->sys_language_uid);
687 $id = $tsfe->id;
688 $returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI');
689
690 $icon = $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render();
691 $link = BackendUtility::getModuleUrl('record_history', ['element' => 'pages:' . $id, 'returnUrl' => $returnUrl]);
692 $toolBar = '<a class="t3-icon btn btn-default" href="' . htmlspecialchars($link) . '#latest" title="' . $this->extGetLL('edit_recordHistory') . '">' . $icon . '</a>';
693 if ($perms & Permission::CONTENT_EDIT && $langAllowed) {
694 $params = '';
695 if ($tsfe->sys_language_uid) {
696 $params = '&sys_language_uid=' . $tsfe->sys_language_uid;
697 }
698 $icon = $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render();
699 $link = $newContentWizScriptPath . 'id=' . $id . $params . '&returnUrl=' . rawurlencode($returnUrl);
700 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars($link) . '" title="' . $this->extGetLL('edit_newContentElement') . '"">' . $icon . '</a>';
701 }
702 if ($perms & Permission::PAGE_EDIT) {
703 $icon = $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL)->render();
704 $link = BackendUtility::getModuleUrl('move_element', ['table' => 'pages', 'uid' => $id, 'returnUrl' => $returnUrl]);
705 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars($link) . '" title="' . $this->extGetLL('edit_move_page') . '">' . $icon . '</a>';
706 }
707 if ($perms & Permission::PAGE_NEW) {
708 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars(BackendUtility::getModuleUrl('db_new', ['id' => $id, 'pagesOnly' => 1, 'returnUrl' => $returnUrl])) . '" title="' . $this->extGetLL('edit_newPage') . '">'
709 . $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render()
710 . '</a>';
711 }
712 if ($perms & Permission::PAGE_EDIT) {
713 $icon = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render();
714 $url = BackendUtility::getModuleUrl('record_edit', [
715 'edit[pages][' . $id . ']' => 'edit',
716 'noView' => 1,
717 'returnUrl' => $returnUrl
718 ]);
719 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars($url) . '">' . $icon . '</a>';
720 if ($tsfe->sys_language_uid && $langAllowed) {
721 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
722 ->getQueryBuilderForTable('pages_language_overlay');
723 $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
724 $row = $queryBuilder
725 ->select('uid', 'pid', 't3ver_state')
726 ->from('pages_language_overlay')
727 ->where(
728 $queryBuilder->expr()->eq('pid', (int)$id),
729 $queryBuilder->expr()->eq(
730 'sys_language_uid',
731 (int)$tsfe->sys_language_uid
732 )
733 )
734 ->setMaxResults(1)
735 ->execute()
736 ->fetch();
737
738 $tsfe->sys_page->versionOL('pages_language_overlay', $row);
739 if (is_array($row)) {
740 $icon = '<span title="' . $this->extGetLL('edit_editPageOverlay', true) . '">'
741 . $this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)->render() . '</span>';
742 $url = BackendUtility::getModuleUrl('record_edit', [
743 'edit[pages_language_overlay][' . $row['uid'] . ']' => 'edit',
744 'noView' => 1,
745 'returnUrl' => $returnUrl
746 ]);
747 $toolBar .= '<a href="' . htmlspecialchars($url) . '">' . $icon . '</a>';
748 }
749 }
750 }
751 if ($this->getBackendUser()->check('modules', 'web_list')) {
752 $urlParams = [
753 'id' => $id,
754 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
755 ];
756 $icon = '<span title="' . $this->extGetLL('edit_db_list', false) . '">' . $this->iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render() . '</span>';
757 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_list', $urlParams)) . '">' . $icon . '</a>';
758 }
759
760 $toolBar = '<div class="toolbar btn-group" role="group">' . $toolBar . '</div>';
761 return $toolBar;
762 }
763
764 /**
765 * Translate given key
766 *
767 * @param string $key Key for a label in the $LOCAL_LANG array of "sysext/lang/locallang_tsfe.xlf
768 * @param bool $convertWithHtmlspecialchars If TRUE the language-label will be sent through htmlspecialchars
769 * @return string The value for the $key
770 */
771 protected function extGetLL($key, $convertWithHtmlspecialchars = true)
772 {
773 $labelStr = $this->getLanguageService()->getLL($key);
774 if ($convertWithHtmlspecialchars) {
775 $labelStr = htmlspecialchars($labelStr);
776 }
777 return $labelStr;
778 }
779
780 /**
781 * Returns LanguageService
782 *
783 * @return \TYPO3\CMS\Lang\LanguageService
784 */
785 protected function getLanguageService()
786 {
787 return $GLOBALS['LANG'];
788 }
789
790 /**
791 * Returns the current BE user.
792 *
793 * @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
794 */
795 protected function getBackendUser()
796 {
797 return $GLOBALS['BE_USER'];
798 }
799
800 /**
801 * Returns the database connection
802 *
803 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
804 */
805 protected function getDatabaseConnection()
806 {
807 return $GLOBALS['TYPO3_DB'];
808 }
809
810 /**
811 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
812 */
813 protected function getTypoScriptFrontendController()
814 {
815 return $GLOBALS['TSFE'];
816 }
817
818 /**
819 * @return TimeTracker
820 */
821 protected function getTimeTracker()
822 {
823 return GeneralUtility::makeInstance(TimeTracker::class);
824 }
825 }