[TASK] CGL: Fix a series of minor indentation issues
[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 use TYPO3\CMS\Core\Utility\PathUtility;
29
30 /**
31 * View class for the admin panel in frontend editing.
32 */
33 class AdminPanelView
34 {
35 /**
36 * Determines whether the update button should be shown.
37 *
38 * @var bool
39 */
40 protected $extNeedUpdate = false;
41
42 /**
43 * Force preview
44 *
45 * @var bool
46 */
47 protected $ext_forcePreview = false;
48
49 /**
50 * @var string
51 */
52 protected $extJSCODE = '';
53
54 /**
55 * @var IconFactory
56 */
57 protected $iconFactory;
58
59 /**
60 * Determines whether EXT:feedit is loaded
61 *
62 * @var bool
63 */
64 protected $extFeEditLoaded = false;
65
66 /**
67 * Constructor
68 */
69 public function __construct()
70 {
71 $this->initialize();
72 }
73
74 /**
75 * Initializes settings for the admin panel.
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 public function saveConfigOptions()
149 {
150 $input = GeneralUtility::_GP('TSFE_ADMIN_PANEL');
151 $beUser = $this->getBackendUser();
152 if (is_array($input)) {
153 // Setting
154 $beUser->uc['TSFE_adminConfig'] = array_merge(!is_array($beUser->uc['TSFE_adminConfig']) ? [] : $beUser->uc['TSFE_adminConfig'], $input);
155 unset($beUser->uc['TSFE_adminConfig']['action']);
156 // Actions:
157 if (($input['action']['clearCache'] && $this->isAdminModuleEnabled('cache')) || isset($input['preview_showFluidDebug'])) {
158 $theStartId = (int)$input['cache_clearCacheId'];
159 $this->getTypoScriptFrontendController()
160 ->clearPageCacheContent_pidList(
161 $beUser->extGetTreeList(
162 $theStartId,
163 $this->extGetFeAdminValue(
164 'cache',
165 'clearCacheLevels'
166 ),
167 0,
168 $beUser->getPagePermsClause(Permission::PAGE_SHOW)
169 ) . $theStartId
170 );
171 }
172 // Saving
173 $beUser->writeUC();
174 // Flush fluid template cache
175 $cacheManager = new CacheManager();
176 $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
177 $cacheManager->getCache('fluid_template')->flush();
178 }
179 $this->getTimeTracker()->LR = $this->extGetFeAdminValue('tsdebug', 'LR');
180 if ($this->extGetFeAdminValue('cache', 'noCache')) {
181 $this->getTypoScriptFrontendController()->set_no_cache('Admin Panel: No Caching', true);
182 }
183 }
184
185 /**
186 * Returns the value for an Admin Panel setting.
187 *
188 * @param string $sectionName Module key
189 * @param string $val Setting key
190 * @return mixed The setting value
191 */
192 public function extGetFeAdminValue($sectionName, $val = '')
193 {
194 if (!$this->isAdminModuleEnabled($sectionName)) {
195 return null;
196 }
197
198 $beUser = $this->getBackendUser();
199 // Exceptions where the values can be overridden (forced) from backend:
200 // deprecated
201 if (
202 $sectionName === 'edit' && (
203 $val === 'displayIcons' && $beUser->extAdminConfig['module.']['edit.']['forceDisplayIcons'] ||
204 $val === 'displayFieldIcons' && $beUser->extAdminConfig['module.']['edit.']['forceDisplayFieldIcons'] ||
205 $val === 'editNoPopup' && $beUser->extAdminConfig['module.']['edit.']['forceNoPopup']
206 )
207 ) {
208 return true;
209 }
210
211 // Override all settings with user TSconfig
212 if ($val && isset($beUser->extAdminConfig['override.'][$sectionName . '.'][$val])) {
213 return $beUser->extAdminConfig['override.'][$sectionName . '.'][$val];
214 }
215 if (!$val && isset($beUser->extAdminConfig['override.'][$sectionName])) {
216 return $beUser->extAdminConfig['override.'][$sectionName];
217 }
218
219 $returnValue = $val ? $beUser->uc['TSFE_adminConfig'][$sectionName . '_' . $val] : 1;
220
221 // Exception for preview
222 if ($sectionName === 'preview' && $this->ext_forcePreview) {
223 return !$val ? true : $returnValue;
224 }
225
226 // See if the menu is expanded!
227 return $this->isAdminModuleOpen($sectionName) ? $returnValue : null;
228 }
229
230 /**
231 * Enables the force preview option.
232 */
233 public function forcePreview()
234 {
235 $this->ext_forcePreview = true;
236 }
237
238 /**
239 * Returns TRUE if admin panel module is open
240 *
241 * @param string $key Module key
242 * @return bool TRUE, if the admin panel is open for the specified admin panel module key.
243 */
244 public function isAdminModuleOpen($key)
245 {
246 return $this->getBackendUser()->uc['TSFE_adminConfig']['display_top'] && $this->getBackendUser()->uc['TSFE_adminConfig']['display_' . $key];
247 }
248
249 /**
250 * @param string $key
251 * @param string $content
252 *
253 * @return string
254 */
255 protected function getModule($key, $content)
256 {
257 $output = [];
258
259 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_top'] && $this->isAdminModuleEnabled($key)) {
260 $output[] = '<div class="typo3-adminPanel-section typo3-adminPanel-section-' . ($this->isAdminModuleOpen($key) ? 'open' : 'closed') . '">';
261 $output[] = ' <div class="typo3-adminPanel-section-title">';
262 $output[] = ' ' . $this->linkSectionHeader($key, $this->extGetLL($key));
263 $output[] = ' </div>';
264 if ($this->isAdminModuleOpen($key)) {
265 $output[] = '<div class="typo3-adminPanel-section-body">';
266 $output[] = ' ' . $content;
267 $output[] = '</div>';
268 }
269 $output[] = '</div>';
270 }
271
272 return implode('', $output);
273 }
274
275 /**
276 * Creates and returns the HTML code for the Admin Panel in the TSFE frontend.
277 *
278 * @throws \UnexpectedValueException
279 * @return string HTML for the Admin Panel
280 */
281 public function display()
282 {
283 $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_tsfe.xlf');
284
285 $moduleContent = '';
286 $moduleContent .= $this->getModule('preview', $this->getPreviewModule());
287 $moduleContent .= $this->getModule('cache', $this->getCacheModule());
288 $moduleContent .= $this->getModule('edit', $this->getEditModule());
289 $moduleContent .= $this->getModule('tsdebug', $this->getTSDebugModule());
290 $moduleContent .= $this->getModule('info', $this->getInfoModule());
291
292 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'] ?? [] as $className) {
293 $hookObject = GeneralUtility::makeInstance($className);
294 if (!$hookObject instanceof AdminPanelViewHookInterface) {
295 throw new \UnexpectedValueException($className . ' must implement interface ' . AdminPanelViewHookInterface::class, 1311942539);
296 }
297 $content = $hookObject->extendAdminPanel($moduleContent, $this);
298 if ($content) {
299 $moduleContent .= '<div class="typo3-adminPanel-section typo3-adminPanel-section-open">';
300 $moduleContent .= ' <div class="typo3-adminPanel-section-body">';
301 $moduleContent .= ' ' . $content;
302 $moduleContent .= ' </div>';
303 $moduleContent .= '</div>';
304 }
305 }
306
307 $output = [];
308 $output[] = '<!-- TYPO3 Admin panel start -->';
309 $output[] = '<a id="TSFE_ADMIN_PANEL"></a>';
310 $output[] = '<form id="TSFE_ADMIN_PANEL_FORM" name="TSFE_ADMIN_PANEL_FORM" style="display: none;" 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)">';
311 if (!GeneralUtility::_GET('id')) {
312 $output[] = '<input type="hidden" name="id" value="' . $this->getTypoScriptFrontendController()->id . '" />';
313 }
314 // The dummy field is needed for Firefox: to force a page reload on submit
315 // which must change the form value with JavaScript (see "onsubmit" attribute of the "form" element")
316 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[DUMMY]" value="" />';
317 foreach (GeneralUtility::_GET() as $key => $value) {
318 if ($key !== 'TSFE_ADMIN_PANEL') {
319 if (is_array($value)) {
320 $output[] = $this->getHiddenFields($key, $value);
321 } else {
322 $output[] = '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />';
323 }
324 }
325 }
326 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[display_top]" value="0" />';
327 $output[] = ' <input id="typo3AdminPanelEnable" type="checkbox" onchange="document.TSFE_ADMIN_PANEL_FORM.submit();" name="TSFE_ADMIN_PANEL[display_top]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['display_top'] ? ' checked="checked"' : '') . '/>';
328 $output[] = ' <input id="typo3AdminPanelCollapse" type="checkbox" value="1" />';
329 $output[] = ' <div class="typo3-adminPanel typo3-adminPanel-state-' . ($this->getBackendUser()->uc['TSFE_adminConfig']['display_top'] ? 'open' : 'closed') . '">';
330 $output[] = ' <div class="typo3-adminPanel-header">';
331 $output[] = ' <span class="typo3-adminPanel-header-title">' . $this->extGetLL('adminPanelTitle') . '</span>';
332 $output[] = ' <span class="typo3-adminPanel-header-user">' . htmlspecialchars($this->getBackendUser()->user['username']) . '</span>';
333 $output[] = ' <label for="typo3AdminPanelEnable" class="typo3-adminPanel-header-enable">';
334 $output[] = ' <span class="typo3-adminPanel-header-enable-enabled">';
335 $output[] = ' ' . $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render('inline');
336 $output[] = ' </span>';
337 $output[] = ' <span class="typo3-adminPanel-header-enable-disabled">';
338 $output[] = ' ' . $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render('inline');
339 $output[] = ' </span>';
340 $output[] = ' </label>';
341 $output[] = ' <label for="typo3AdminPanelCollapse" class="typo3-adminPanel-header-collapse">';
342 $output[] = ' <span class="typo3-adminPanel-header-collapse-enabled">';
343 $output[] = ' ' . $this->iconFactory->getIcon('actions-view-list-collapse', Icon::SIZE_SMALL)->render('inline');
344 $output[] = ' </span>';
345 $output[] = ' <span class="typo3-adminPanel-header-collapse-disabled">';
346 $output[] = ' ' . $this->iconFactory->getIcon('actions-view-list-expand', Icon::SIZE_SMALL)->render('inline');
347 $output[] = ' </span>';
348 $output[] = ' </label>';
349 $output[] = ' </div>';
350 if ($moduleContent && $this->extNeedUpdate) {
351 $output[] = '<div class="typo3-adminPanel-actions">';
352 $output[] = ' <input class="typo3-adminPanel-btn typo3-adminPanel-btn-dark" type="submit" value="' . $this->extGetLL('update') . '" />';
353 $output[] = '</div>';
354 }
355 $output[] = ' <div class="typo3-adminPanel-body">';
356 $output[] = ' ' . $moduleContent;
357 $output[] = ' </div>';
358 $output[] = ' </div>';
359 $output[] = '</form>';
360 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_top']) {
361 $evalFieldJavaScriptFile = GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Public/JavaScript/jsfunc.evalfield.js');
362 $output[] = '<script type="text/javascript" src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($evalFieldJavaScriptFile)) . '"></script>';
363 $output[] = '<script type="text/javascript">/*<![CDATA[*/' . GeneralUtility::minifyJavaScript('
364 var evalFunc = new evalFunc();
365 // TSFEtypo3FormFieldSet()
366 function TSFEtypo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue) { //
367 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
368 var theValue = document.TSFE_ADMIN_PANEL_FORM[theField].value;
369 if (checkbox && theValue==checkboxValue) {
370 document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value="";
371 alert(theField);
372 document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"].checked = "";
373 } else {
374 document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue);
375 if (document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"]) {
376 document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"].checked = "on";
377 }
378 }
379 }
380 // TSFEtypo3FormFieldGet()
381 function TSFEtypo3FormFieldGet(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off) { //
382 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
383 if (checkbox_off) {
384 document.TSFE_ADMIN_PANEL_FORM[theField].value=checkboxValue;
385 }else{
386 document.TSFE_ADMIN_PANEL_FORM[theField].value = evalFunc.evalObjValue(theFObj, document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value);
387 }
388 TSFEtypo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue);
389 }') . '/*]]>*/</script>';
390 $output[] = '<script language="javascript" type="text/javascript">' . $this->extJSCODE . '</script>';
391 }
392 $cssFileLocation = GeneralUtility::getFileAbsFileName('EXT:frontend/Resources/Public/Css/adminpanel.css');
393 $output[] = '<link type="text/css" rel="stylesheet" href="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($cssFileLocation)) . '" media="all" />';
394 $output[] = $this->getAdminPanelHeaderData();
395 $output[] = '<!-- TYPO3 admin panel end -->';
396
397 return implode('', $output);
398 }
399
400 /**
401 * Fetches recursively all GET parameters as hidden fields.
402 * Called from display()
403 *
404 * @param string $key Current key
405 * @param array $val Current value
406 * @return string Hidden fields
407 * @see display()
408 */
409 protected function getHiddenFields($key, array $val)
410 {
411 $out = '';
412 foreach ($val as $k => $v) {
413 if (is_array($v)) {
414 $out .= $this->getHiddenFields($key . '[' . $k . ']', $v);
415 } else {
416 $out .= '<input type="hidden" name="' . htmlspecialchars($key) . '[' . htmlspecialchars($k) . ']" value="' . htmlspecialchars($v) . '">' . LF;
417 }
418 }
419 return $out;
420 }
421
422 /*****************************************************
423 * Creating sections of the Admin Panel
424 ****************************************************/
425 /**
426 * Creates the content for the "preview" section ("module") of the Admin Panel
427 *
428 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
429 * @see display()
430 */
431 protected function getPreviewModule()
432 {
433 $output = [];
434 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_preview']) {
435 $this->extNeedUpdate = true;
436
437 $output[] = '<div class="typo3-adminPanel-form-group">';
438 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
439 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[preview_showHiddenPages]" value="0" />';
440 $output[] = ' <label for="' . htmlspecialchars('preview_showHiddenPages') . '">';
441 $output[] = ' <input type="checkbox" id="preview_showHiddenPages" name="TSFE_ADMIN_PANEL[preview_showHiddenPages]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['preview_showHiddenPages'] ? ' checked="checked"' : '') . ' />';
442 $output[] = ' ' . $this->extGetLL('preview_showHiddenPages');
443 $output[] = ' </label>';
444 $output[] = ' </div>';
445 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
446 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[preview_showHiddenRecords]" value="0" />';
447 $output[] = ' <label for="' . htmlspecialchars('preview_showHiddenRecords') . '">';
448 $output[] = ' <input type="checkbox" id="preview_showHiddenRecords" name="TSFE_ADMIN_PANEL[preview_showHiddenRecords]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['preview_showHiddenRecords'] ? ' checked="checked"' : '') . ' />';
449 $output[] = ' ' . $this->extGetLL('preview_showHiddenRecords');
450 $output[] = ' </label>';
451 $output[] = ' </div>';
452 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
453 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[preview_showFluidDebug]" value="0" />';
454 $output[] = ' <label for="' . htmlspecialchars('preview_showFluidDebug') . '">';
455 $output[] = ' <input type="checkbox" id="preview_showFluidDebug" name="TSFE_ADMIN_PANEL[preview_showFluidDebug]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['preview_showFluidDebug'] ? ' checked="checked"' : '') . ' />';
456 $output[] = ' ' . $this->extGetLL('preview_showFluidDebug');
457 $output[] = ' </label>';
458 $output[] = ' </div>';
459 $output[] = '</div>';
460
461 // Simulate date
462 $output[] = '<div class="typo3-adminPanel-form-group">';
463 $output[] = ' <label for="' . htmlspecialchars('preview_simulateDate') . '">';
464 $output[] = ' ' . $this->extGetLL('preview_simulateDate');
465 $output[] = ' </label>';
466 $output[] = ' <input type="text" id="preview_simulateDate" name="TSFE_ADMIN_PANEL[preview_simulateDate]_hr" onchange="TSFEtypo3FormFieldGet(\'TSFE_ADMIN_PANEL[preview_simulateDate]\', \'datetime\', \'\', 1,0);" />';
467 // the hidden field must be placed after the _hr field to avoid the timestamp being overridden by the date string
468 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[preview_simulateDate]" value="' . $this->getBackendUser()->uc['TSFE_adminConfig']['preview_simulateDate'] . '" />';
469 $output[] = '</div>';
470 $this->extJSCODE .= 'TSFEtypo3FormFieldSet("TSFE_ADMIN_PANEL[preview_simulateDate]", "datetime", "", 0, 0);';
471
472 // Frontend Usergroups
473 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
474 ->getQueryBuilderForTable('fe_groups');
475 $queryBuilder->getRestrictions()
476 ->removeAll()
477 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
478 $optionCount = $queryBuilder->count('fe_groups.uid')
479 ->from('fe_groups')
480 ->from('pages')
481 ->where(
482 $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('fe_groups.pid')),
483 $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)
484 )
485 ->execute()
486 ->fetchColumn(0);
487 if ($optionCount > 0) {
488 $result = $queryBuilder->select('fe_groups.uid', 'fe_groups.title')
489 ->from('fe_groups')
490 ->from('pages')
491 ->where(
492 $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('fe_groups.pid')),
493 $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)
494 )
495 ->orderBy('fe_groups.title')
496 ->execute();
497 $output[] = '<div class="typo3-adminPanel-form-group">';
498 $output[] = ' <label for="' . htmlspecialchars('preview_simulateUserGroup') . '">';
499 $output[] = ' ' . $this->extGetLL('preview_simulateUserGroup');
500 $output[] = ' </label>';
501 $output[] = ' <select id="preview_simulateUserGroup" name="TSFE_ADMIN_PANEL[preview_simulateUserGroup]">';
502 $output[] = ' <option value="0">&nbsp;</option>';
503 while ($row = $result->fetch()) {
504 $output[] = '<option value="' . $row['uid'] . '" ' . ($this->getBackendUser()->uc['TSFE_adminConfig']['preview_simulateUserGroup'] == $row['uid'] ? ' selected="selected"' : '') . '>';
505 $output[] = htmlspecialchars(($row['title'] . ' [' . $row['uid'] . ']'));
506 $output[] = '</option>';
507 }
508 $output[] = ' </select>';
509 $output[] = '</div>';
510 }
511 }
512 return implode('', $output);
513 }
514
515 /**
516 * Creates the content for the "cache" section ("module") of the Admin Panel
517 *
518 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
519 * @see display()
520 */
521 protected function getCacheModule()
522 {
523 $output = [];
524 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_cache']) {
525 $this->extNeedUpdate = true;
526
527 $output[] = '<div class="typo3-adminPanel-form-group">';
528 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
529 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[cache_noCache]" value="0" />';
530 $output[] = ' <label for="' . htmlspecialchars('cache_noCache') . '">';
531 $output[] = ' <input type="checkbox" id="cache_noCache" name="TSFE_ADMIN_PANEL[cache_noCache]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['cache_noCache'] ? ' checked="checked"' : '') . ' />';
532 $output[] = ' ' . $this->extGetLL('cache_noCache');
533 $output[] = ' </label>';
534 $output[] = ' </div>';
535 $output[] = '</div>';
536
537 $levels = $this->getBackendUser()->uc['TSFE_adminConfig']['cache_clearCacheLevels'];
538 $output[] = '<div class="typo3-adminPanel-form-group">';
539 $output[] = ' <label for="' . htmlspecialchars('cache_clearCacheLevels') . '">';
540 $output[] = ' ' . $this->extGetLL('cache_clearLevels');
541 $output[] = ' </label>';
542 $output[] = ' <select id="cache_clearCacheLevels" name="TSFE_ADMIN_PANEL[cache_clearCacheLevels]">';
543 $output[] = ' <option value="0"' . ($levels == 0 ? ' selected="selected"' : '') . '>';
544 $output[] = ' ' . $this->extGetLL('div_Levels_0');
545 $output[] = ' </option>';
546 $output[] = ' <option value="1"' . ($levels == 1 ? ' selected="selected"' : '') . '>';
547 $output[] = ' ' . $this->extGetLL('div_Levels_1');
548 $output[] = ' </option>';
549 $output[] = ' <option value="2"' . ($levels == 2 ? ' selected="selected"' : '') . '>';
550 $output[] = ' ' . $this->extGetLL('div_Levels_2');
551 $output[] = ' </option>';
552 $output[] = ' </select>';
553 $output[] = '</div>';
554
555 $output[] = '<div class="typo3-adminPanel-form-group">';
556 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[cache_clearCacheId]" value="' . $GLOBALS['TSFE']->id . '" />';
557 $output[] = ' <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default" type="submit" value="' . $this->extGetLL('update') . '" />';
558 $output[] = '</div>';
559 $output[] = '<div class="typo3-adminPanel-form-group">';
560 $output[] = ' <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default" type="submit" name="TSFE_ADMIN_PANEL[action][clearCache]" value="' . $this->extGetLL('cache_doit') . '" />';
561 $output[] = '</div>';
562 }
563 return implode('', $output);
564 }
565
566 /**
567 * Creates the content for the "edit" section ("module") of the Admin Panel
568 *
569 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
570 * @see display()
571 */
572 protected function getEditModule()
573 {
574 $output = [];
575 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_edit']) {
576 $this->extNeedUpdate = true;
577
578 // If another page module was specified, replace the default Page module with the new one
579 $newPageModule = trim($this->getBackendUser()->getTSConfigVal('options.overridePageModule'));
580 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
581
582 if ($this->extFeEditLoaded) {
583 $output[] = '<div class="typo3-adminPanel-form-group">';
584 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
585 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[edit_displayFieldIcons]" value="0" />';
586 $output[] = ' <label for="' . htmlspecialchars('edit_displayFieldIcons') . '">';
587 $output[] = ' <input type="checkbox" id="edit_displayFieldIcons" name="TSFE_ADMIN_PANEL[edit_displayFieldIcons]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['edit_displayFieldIcons'] ? ' checked="checked"' : '') . ' />';
588 $output[] = ' ' . $this->extGetLL('edit_displayFieldIcons');
589 $output[] = ' </label>';
590 $output[] = ' </div>';
591 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
592 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[edit_displayIcons]" value="0" />';
593 $output[] = ' <label for="' . htmlspecialchars('edit_displayIcons') . '">';
594 $output[] = ' <input type="checkbox" id="edit_displayIcons" name="TSFE_ADMIN_PANEL[edit_displayIcons]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['edit_displayIcons'] ? ' checked="checked"' : '') . ' />';
595 $output[] = ' ' . $this->extGetLL('edit_displayIcons');
596 $output[] = ' </label>';
597 $output[] = ' </div>';
598 $output[] = '</div>';
599 }
600
601 $output[] = $this->ext_makeToolBar();
602
603 if (!GeneralUtility::_GP('ADMCMD_view')) {
604 $onClick = '
605 if (parent.opener && parent.opener.top && parent.opener.top.TS) {
606 parent.opener.top.fsMod.recentIds["web"]=' . (int)$this->getTypoScriptFrontendController()->page['uid'] . ';
607 if (parent.opener.top && parent.opener.top.nav_frame && parent.opener.top.nav_frame.refresh_nav) {
608 parent.opener.top.nav_frame.refresh_nav();
609 }
610 parent.opener.top.goToModule("' . $pageModule . '");
611 parent.opener.top.focus();
612 } else {
613 vHWin=window.open(' . GeneralUtility::quoteJSvalue(BackendUtility::getBackendScript()) . ',\'' . md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '\');
614 vHWin.focus();
615 }
616 return false;
617 ';
618 $output[] = '<div class="typo3-adminPanel-form-group">';
619 $output[] = ' <a class="typo3-adminPanel-btn typo3-adminPanel-btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '">';
620 $output[] = ' ' . $this->extGetLL('edit_openAB');
621 $output[] = ' </a>';
622 $output[] = '</div>';
623 }
624 }
625 return implode('', $output);
626 }
627
628 /**
629 * Creates the content for the "tsdebug" section ("module") of the Admin Panel
630 *
631 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
632 * @see display()
633 */
634 protected function getTSDebugModule()
635 {
636 $output = [];
637 $beuser = $this->getBackendUser();
638 if ($beuser->uc['TSFE_adminConfig']['display_tsdebug']) {
639 $this->extNeedUpdate = true;
640
641 $output[] = '<div class="typo3-adminPanel-form-group">';
642 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
643 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_tree]" value="0" />';
644 $output[] = ' <label for="' . htmlspecialchars('tsdebug_tree') . '">';
645 $output[] = ' <input type="checkbox" id="tsdebug_tree" name="TSFE_ADMIN_PANEL[tsdebug_tree]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['tsdebug_tree'] ? ' checked="checked"' : '') . ' />';
646 $output[] = ' ' . $this->extGetLL('tsdebug_tree');
647 $output[] = ' </label>';
648 $output[] = ' </div>';
649 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
650 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_displayTimes]" value="0" />';
651 $output[] = ' <label for="' . htmlspecialchars('tsdebug_displayTimes') . '">';
652 $output[] = ' <input type="checkbox" id="tsdebug_displayTimes" name="TSFE_ADMIN_PANEL[tsdebug_displayTimes]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['tsdebug_displayTimes'] ? ' checked="checked"' : '') . ' />';
653 $output[] = ' ' . $this->extGetLL('tsdebug_displayTimes');
654 $output[] = ' </label>';
655 $output[] = ' </div>';
656 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
657 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_displayMessages]" value="0" />';
658 $output[] = ' <label for="' . htmlspecialchars('tsdebug_displayMessages') . '">';
659 $output[] = ' <input type="checkbox" id="tsdebug_displayMessages" name="TSFE_ADMIN_PANEL[tsdebug_displayMessages]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['tsdebug_displayMessages'] ? ' checked="checked"' : '') . ' />';
660 $output[] = ' ' . $this->extGetLL('tsdebug_displayMessages');
661 $output[] = ' </label>';
662 $output[] = ' </div>';
663 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
664 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_LR]" value="0" />';
665 $output[] = ' <label for="' . htmlspecialchars('tsdebug_LR') . '">';
666 $output[] = ' <input type="checkbox" id="tsdebug_LR" name="TSFE_ADMIN_PANEL[tsdebug_LR]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['tsdebug_LR'] ? ' checked="checked"' : '') . ' />';
667 $output[] = ' ' . $this->extGetLL('tsdebug_LR');
668 $output[] = ' </label>';
669 $output[] = ' </div>';
670 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
671 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_displayContent]" value="0" />';
672 $output[] = ' <label for="' . htmlspecialchars('tsdebug_displayContent') . '">';
673 $output[] = ' <input type="checkbox" id="tsdebug_displayContent" name="TSFE_ADMIN_PANEL[tsdebug_displayContent]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['tsdebug_displayContent'] ? ' checked="checked"' : '') . ' />';
674 $output[] = ' ' . $this->extGetLL('tsdebug_displayContent');
675 $output[] = ' </label>';
676 $output[] = ' </div>';
677 $output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
678 $output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[tsdebug_forceTemplateParsing]" value="0" />';
679 $output[] = ' <label for="' . htmlspecialchars('tsdebug_forceTemplateParsing') . '">';
680 $output[] = ' <input type="checkbox" id="tsdebug_forceTemplateParsing" name="TSFE_ADMIN_PANEL[tsdebug_forceTemplateParsing]" value="1"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['tsdebug_forceTemplateParsing'] ? ' checked="checked"' : '') . ' />';
681 $output[] = ' ' . $this->extGetLL('tsdebug_forceTemplateParsing');
682 $output[] = ' </label>';
683 $output[] = ' </div>';
684 $output[] = '</div>';
685
686 $timeTracker = $this->getTimeTracker();
687 $timeTracker->printConf['flag_tree'] = $this->extGetFeAdminValue('tsdebug', 'tree');
688 $timeTracker->printConf['allTime'] = $this->extGetFeAdminValue('tsdebug', 'displayTimes');
689 $timeTracker->printConf['flag_messages'] = $this->extGetFeAdminValue('tsdebug', 'displayMessages');
690 $timeTracker->printConf['flag_content'] = $this->extGetFeAdminValue('tsdebug', 'displayContent');
691 $output[] = $timeTracker->printTSlog();
692 }
693 return implode('', $output);
694 }
695
696 /**
697 * Creates the content for the "info" section ("module") of the Admin Panel
698 *
699 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
700 * @see display()
701 */
702 protected function getInfoModule()
703 {
704 $output = [];
705 $tsfe = $this->getTypoScriptFrontendController();
706 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_info']) {
707 $tableArr = [];
708 if ($this->extGetFeAdminValue('cache', 'noCache')) {
709 $theBytes = 0;
710 $count = 0;
711 if (!empty($tsfe->imagesOnPage)) {
712 $tableArr[] = [$this->extGetLL('info_imagesOnPage'), count($tsfe->imagesOnPage), true];
713 foreach ($GLOBALS['TSFE']->imagesOnPage as $file) {
714 $fs = @filesize($file);
715 $tableArr[] = [TAB . $file, GeneralUtility::formatSize($fs)];
716 $theBytes += $fs;
717 $count++;
718 }
719 }
720 // Add an empty line
721 $tableArr[] = [$this->extGetLL('info_imagesSize'), GeneralUtility::formatSize($theBytes), true];
722 $tableArr[] = [$this->extGetLL('info_DocumentSize'), GeneralUtility::formatSize(strlen($tsfe->content)), true];
723 $tableArr[] = ['', ''];
724 }
725 $tableArr[] = [$this->extGetLL('info_id'), $tsfe->id];
726 $tableArr[] = [$this->extGetLL('info_type'), $tsfe->type];
727 $tableArr[] = [$this->extGetLL('info_groupList'), $tsfe->gr_list];
728 $tableArr[] = [$this->extGetLL('info_noCache'), $this->extGetLL('info_noCache_' . ($tsfe->no_cache ? 'no' : 'yes'))];
729 $tableArr[] = [$this->extGetLL('info_countUserInt'), count($tsfe->config['INTincScript'] ?? [])];
730
731 if (!empty($tsfe->fe_user->user['uid'])) {
732 $tableArr[] = [$this->extGetLL('info_feuserName'), htmlspecialchars($tsfe->fe_user->user['username'])];
733 $tableArr[] = [$this->extGetLL('info_feuserId'), htmlspecialchars($tsfe->fe_user->user['uid'])];
734 }
735
736 $tableArr[] = [$this->extGetLL('info_totalParsetime'), $this->getTimeTracker()->getParseTime() . ' ms', true];
737 $table = '';
738 foreach ($tableArr as $key => $arr) {
739 $label = (isset($arr[2]) ? '<strong>' . $arr[0] . '</strong>' : $arr[0]);
740 $value = (string)$arr[1] !== '' ? $arr[1] : '';
741 $table .= '
742 <tr>
743 <td>' . $label . '</td>
744 <td>' . htmlspecialchars($value) . '</td>
745 </tr>';
746 }
747
748 $output[] = '<div class="typo3-adminPanel-table-overflow">';
749 $output[] = ' <table class="typo3-adminPanel-table">';
750 $output[] = ' ' . $table;
751 $output[] = ' </table>';
752 $output[] = '</div>';
753 }
754
755 return implode('', $output);
756 }
757
758 /*****************************************************
759 * Admin Panel Layout Helper functions
760 ****************************************************/
761 /**
762 * Returns a row (with colspan=4) which is a header for a section in the Admin Panel.
763 * 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
764 * See the functions get*Module
765 *
766 * @param string $sectionSuffix The suffix to the display_ label. Also selects the label from the LOCAL_LANG array.
767 * @return string HTML table row.
768 * @see extGetItem()
769 */
770 public function extGetHead($sectionSuffix)
771 {
772 return $this->linkSectionHeader($sectionSuffix, $this->extGetLL($sectionSuffix));
773 }
774
775 /**
776 * Wraps a string in a link which will open/close a certain part of the Admin Panel
777 *
778 * @param string $sectionSuffix The code for the display_ label/key
779 * @param string $sectionTitle Title (in HTML-format)
780 * @param string $className The classname for the <a> tag
781 * @return string $className Linked input string
782 * @see extGetHead()
783 */
784 public function linkSectionHeader($sectionSuffix, $sectionTitle, $className = '')
785 {
786 $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;';
787
788 $output = [];
789 $output[] = '<span class="typo3-adminPanel-section-title-identifier"></span>';
790 $output[] = '<a href="javascript:void(0)" onclick="' . htmlspecialchars($onclick) . '">';
791 $output[] = ' ' . $sectionTitle;
792 $output[] = '</a>';
793 $output[] = '<input type="hidden" name="TSFE_ADMIN_PANEL[display_' . $sectionSuffix . ']" value="' . $this->isAdminModuleOpen($sectionSuffix) . '" />';
794
795 return implode('', $output);
796 }
797
798 /**
799 * Returns a row (with 4 columns) for content in a section of the Admin Panel.
800 * It will take $pre as a key to a label to display and $element as the content to put into the forth cell.
801 *
802 * @param string $title Key to label
803 * @param string $content The HTML content for the forth table cell.
804 * @param string $checkbox The HTML for a checkbox or hidden fields.
805 * @param string $innerDivClass The Class attribute for the td element.
806 * @param string $outerDivClass The Class attribute for the tr element.
807 * @return string HTML table row.
808 * @see extGetHead()
809 */
810 public function extGetItem($title, $content = '', $checkbox = '', $outerDivClass = null, $innerDivClass = null)
811 {
812 $title = $title ? '<label for="' . htmlspecialchars($title) . '">' . $this->extGetLL($title) . '</label>' : '';
813 $outerDivClass === null ? $out = '<div>' : $out = '<div class="' . $outerDivClass . '">';
814 $innerDivClass === null ? $out .= '<div>' : $out .= '<div class="' . $innerDivClass . '">';
815 $out .= $checkbox . $title . $content . '</div>
816 </div>';
817 return $out;
818 }
819
820 /**
821 * Creates the tool bar links for the "edit" section of the Admin Panel.
822 *
823 * @return string A string containing images wrapped in <a>-tags linking them to proper functions.
824 */
825 public function ext_makeToolBar()
826 {
827 $tsfe = $this->getTypoScriptFrontendController();
828 // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead:
829 $tsConfig = BackendUtility::getModTSconfig($tsfe->page['uid'], 'mod');
830 $moduleName = $tsConfig['properties']['newContentElementWizard.']['override'] ?? 'new_content_element';
831 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
832 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
833 $newContentWizScriptPath = (string)$uriBuilder->buildUriFromRoute($moduleName);
834 $perms = $this->getBackendUser()->calcPerms($tsfe->page);
835 $langAllowed = $this->getBackendUser()->checkLanguageAccess($tsfe->sys_language_uid);
836 $id = $tsfe->id;
837 $returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI');
838 $classes = 'typo3-adminPanel-btn typo3-adminPanel-btn-default';
839 $output = [];
840 $output[] = '<div class="typo3-adminPanel-form-group">';
841 $output[] = ' <div class="typo3-adminPanel-btn-group" role="group">';
842
843 // History
844 $link = (string)$uriBuilder->buildUriFromRoute(
845 'record_history',
846 [
847 'element' => 'pages:' . $id,
848 'returnUrl' => $returnUrl
849 ]
850 );
851 $title = $this->extGetLL('edit_recordHistory');
852 $output[] = '<a class="' . $classes . '" href="' . htmlspecialchars($link) . '#latest" title="' . $title . '">';
853 $output[] = ' ' . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render();
854 $output[] = '</a>';
855
856 // New Content
857 if ($perms & Permission::CONTENT_EDIT && $langAllowed) {
858 $params = '';
859 if ($tsfe->sys_language_uid) {
860 $params = '&sys_language_uid=' . $tsfe->sys_language_uid;
861 }
862 $link = $newContentWizScriptPath . 'id=' . $id . $params . '&returnUrl=' . rawurlencode($returnUrl);
863 $icon = $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render();
864 $title = $this->extGetLL('edit_newContentElement');
865 $output[] = '<a class="' . $classes . '" href="' . htmlspecialchars($link) . '" title="' . $title . '">';
866 $output[] = ' ' . $icon;
867 $output[] = '</a>';
868 }
869
870 // Move Page
871 if ($perms & Permission::PAGE_EDIT) {
872 $link = (string)$uriBuilder->buildUriFromRoute(
873 'move_element',
874 [
875 'table' => 'pages',
876 'uid' => $id,
877 'returnUrl' => $returnUrl
878 ]
879 );
880 $icon = $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL)->render();
881 $title = $this->extGetLL('edit_move_page');
882 $output[] = '<a class="' . $classes . '" href="' . htmlspecialchars($link) . '" title="' . $title . '">';
883 $output[] = ' ' . $icon;
884 $output[] = '</a>';
885 }
886
887 // New Page
888 if ($perms & Permission::PAGE_NEW) {
889 $link = (string)$uriBuilder->buildUriFromRoute(
890 'db_new',
891 [
892 'id' => $id,
893 'pagesOnly' => 1,
894 'returnUrl' => $returnUrl
895 ]
896 );
897 $icon = $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render();
898 $title = $this->extGetLL('edit_newPage');
899 $output[] = '<a class="' . $classes . '" href="' . htmlspecialchars($link) . '" title="' . $title . '">';
900 $output[] = ' ' . $icon;
901 $output[] = '</a>';
902 }
903
904 // Edit Page
905 if ($perms & Permission::PAGE_EDIT) {
906 $link = (string)$uriBuilder->buildUriFromRoute(
907 'record_edit',
908 [
909 'edit[pages][' . $id . ']' => 'edit',
910 'noView' => 1,
911 'returnUrl' => $returnUrl
912 ]
913 );
914 $icon = $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render();
915 $title = $this->extGetLL('edit_editPageProperties');
916 $output[] = '<a class="' . $classes . '" href="' . htmlspecialchars($link) . '" title="' . $title . '">';
917 $output[] = ' ' . $icon;
918 $output[] = '</a>';
919 }
920
921 // Edit Page Overlay
922 if ($perms & Permission::PAGE_EDIT && $tsfe->sys_language_uid && $langAllowed) {
923 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
924 ->getQueryBuilderForTable('pages');
925 $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
926 $row = $queryBuilder
927 ->select('uid', 'pid', 't3ver_state')
928 ->from('pages')
929 ->where(
930 $queryBuilder->expr()->eq(
931 $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
932 $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
933 ),
934 $queryBuilder->expr()->eq(
935 $GLOBALS['TCA']['pages']['ctrl']['languageField'],
936 $queryBuilder->createNamedParameter($tsfe->sys_language_uid, \PDO::PARAM_INT)
937 )
938 )
939 ->setMaxResults(1)
940 ->execute()
941 ->fetch();
942 $tsfe->sys_page->versionOL('pages', $row);
943 if (is_array($row)) {
944 $link = (string)$uriBuilder->buildUriFromRoute(
945 'record_edit',
946 [
947 'edit[pages][' . $row['uid'] . ']' => 'edit',
948 'noView' => 1,
949 'returnUrl' => $returnUrl
950 ]
951 );
952 $icon = $this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)->render();
953 $title = $this->extGetLL('edit_editPageOverlay');
954 $output[] = '<a class="' . $classes . '" href="' . htmlspecialchars($link) . '" title="' . $title . '">';
955 $output[] = ' ' . $icon;
956 $output[] = '</a>';
957 }
958 }
959
960 // Open list view
961 if ($this->getBackendUser()->check('modules', 'web_list')) {
962 $link = (string)$uriBuilder->buildUriFromRoute(
963 'web_list',
964 [
965 'id' => $id,
966 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
967 ]
968 );
969 $icon = $this->iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render();
970 $title = $this->extGetLL('edit_db_list');
971 $output[] = '<a class="' . $classes . '" href="' . htmlspecialchars($link) . '" title="' . $title . '">';
972 $output[] = ' ' . $icon;
973 $output[] = '</a>';
974 }
975
976 $output[] = ' </div>';
977 $output[] = '</div>';
978 return implode('', $output);
979 }
980
981 /**
982 * Translate given key
983 *
984 * @param string $key Key for a label in the $LOCAL_LANG array of "sysext/lang/Resources/Private/Language/locallang_tsfe.xlf
985 * @param bool $convertWithHtmlspecialchars If TRUE the language-label will be sent through htmlspecialchars
986 * @return string The value for the $key
987 */
988 protected function extGetLL($key, $convertWithHtmlspecialchars = true)
989 {
990 $labelStr = $this->getLanguageService()->getLL($key);
991 if ($convertWithHtmlspecialchars) {
992 $labelStr = htmlspecialchars($labelStr);
993 }
994 return $labelStr;
995 }
996
997 /**
998 * Returns LanguageService
999 *
1000 * @return \TYPO3\CMS\Core\Localization\LanguageService
1001 */
1002 protected function getLanguageService()
1003 {
1004 return $GLOBALS['LANG'];
1005 }
1006
1007 /**
1008 * Returns the current BE user.
1009 *
1010 * @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
1011 */
1012 protected function getBackendUser()
1013 {
1014 return $GLOBALS['BE_USER'];
1015 }
1016
1017 /**
1018 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
1019 */
1020 protected function getTypoScriptFrontendController()
1021 {
1022 return $GLOBALS['TSFE'];
1023 }
1024
1025 /**
1026 * @return TimeTracker
1027 */
1028 protected function getTimeTracker()
1029 {
1030 return GeneralUtility::makeInstance(TimeTracker::class);
1031 }
1032 }