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