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