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