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