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