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