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