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