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