51540029605492afc9cfa375a838bb31a5c879f8
[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 \TYPO3\CMS\Frontend\Http\RequestHandler 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 = $updateButton = '';
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 $updateButton = '<div class="typo3-adminPanel-itemRow updatebutton"><div class="typo3-adminPanel-section-content">
285 <input class="btn btn-default" type="submit" value="' . $this->extGetLL('update') . '" />
286 </div></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 . $updateButton . $moduleContent . '</div></form>';
308 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_top']) {
309 $out .= '<script type="text/javascript" src="' . htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix) . ExtensionManagementUtility::siteRelPath('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 $cssPath = htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix . ExtensionManagementUtility::siteRelPath('t3skin')) . 'stylesheets/standalone/admin_panel.css';
339 $out .= '<script src="' . GeneralUtility::locationHeaderUrl(ExtensionManagementUtility::siteRelPath('frontend') . 'Resources/Public/JavaScript/AdminPanel.js') . '" type="text/javascript"></script><script type="text/javascript">/*<![CDATA[*/' . 'typo3AdminPanel = new TYPO3AdminPanel();typo3AdminPanel.init("typo3-adminPanel-header", "TSFE_ADMIN_PANEL_FORM");' . '/*]]>*/</script>
340 <link type="text/css" rel="stylesheet" href="' . $cssPath . '" media="all" />
341 <!--
342 TYPO3 admin panel end
343 -->
344 ';
345 return $out;
346 }
347
348 /**
349 * Fetches recursively all GET parameters as hidden fields.
350 * Called from display()
351 *
352 * @param string $key Current key
353 * @param array $val Current value
354 * @return string Hidden fields
355 * @see display()
356 */
357 protected function getHiddenFields($key, array $val)
358 {
359 $out = '';
360 foreach ($val as $k => $v) {
361 if (is_array($v)) {
362 $out .= $this->getHiddenFields($key . '[' . $k . ']', $v);
363 } else {
364 $out .= '<input type="hidden" name="' . htmlspecialchars($key) . '[' . htmlspecialchars($k) . ']" value="' . htmlspecialchars($v) . '">' . LF;
365 }
366 }
367 return $out;
368 }
369
370 /*****************************************************
371 * Creating sections of the Admin Panel
372 ****************************************************/
373 /**
374 * Creates the content for the "preview" section ("module") of the Admin Panel
375 *
376 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
377 * @see display()
378 */
379 protected function getPreviewModule()
380 {
381 $out = $this->extGetHead('preview');
382 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_preview']) {
383 $this->extNeedUpdate = true;
384 $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"' : '') . ' />');
385 $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"' : '') . ' />');
386 // Simulate date
387 $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'] . '" />');
388 $this->extJSCODE .= 'TSFEtypo3FormFieldSet("TSFE_ADMIN_PANEL[preview_simulateDate]", "datetime", "", 0, 0);';
389 // Simulate fe_user:
390
391 $options = '';
392
393 $res = $this->getDatabaseConnection()->exec_SELECTquery(
394 'fe_groups.uid, fe_groups.title',
395 'fe_groups,pages',
396 'pages.uid=fe_groups.pid AND pages.deleted=0 ' . BackendUtility::deleteClause('fe_groups') . ' AND ' . $this->getBackendUser()->getPagePermsClause(1),
397 '',
398 'fe_groups.title ASC'
399 );
400 while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
401 $options .= '<option value="' . $row['uid'] . '"' . ($this->getBackendUser()->uc['TSFE_adminConfig']['preview_simulateUserGroup'] == $row['uid'] ? ' selected="selected"' : '') . '>' . htmlspecialchars(($row['title'] . ' [' . $row['uid'] . ']')) . '</option>';
402 }
403 $this->getDatabaseConnection()->sql_free_result($res);
404 if ($options) {
405 $options = '<option value="0">&nbsp;</option>' . $options;
406 $out .= $this->extGetItem('preview_simulateUserGroup', '<select id="preview_simulateUserGroup" name="TSFE_ADMIN_PANEL[preview_simulateUserGroup]">' . $options . '</select>');
407 }
408 }
409 return $out;
410 }
411
412 /**
413 * Creates the content for the "cache" section ("module") of the Admin Panel
414 *
415 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
416 * @see display()
417 */
418 protected function getCacheModule()
419 {
420 $out = $this->extGetHead('cache');
421 $beUser = $this->getBackendUser();
422 if ($beUser->uc['TSFE_adminConfig']['display_cache']) {
423 $this->extNeedUpdate = true;
424 $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"' : '') . ' />');
425 $levels = $beUser->uc['TSFE_adminConfig']['cache_clearCacheLevels'];
426 $options = '';
427 $options .= '<option value="0"' . ($levels == 0 ? ' selected="selected"' : '') . '>' . $this->extGetLL('div_Levels_0') . '</option>';
428 $options .= '<option value="1"' . ($levels == 1 ? ' selected="selected"' : '') . '>' . $this->extGetLL('div_Levels_1') . '</option>';
429 $options .= '<option value="2"' . ($levels == 2 ? ' selected="selected"' : '') . '>' . $this->extGetLL('div_Levels_2') . '</option>';
430 $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') . '" />');
431 // Generating tree:
432 $depth = (int)$this->extGetFeAdminValue('cache', 'clearCacheLevels');
433 $outTable = '';
434 $tsfe = $this->getTypoScriptFrontendController();
435 $beUser->extPageInTreeInfo = array();
436 $beUser->extPageInTreeInfo[] = array($tsfe->page['uid'], htmlspecialchars($tsfe->page['title']), $depth + 1);
437 $beUser->extGetTreeList($tsfe->id, $depth, 0, $beUser->getPagePermsClause(1));
438 foreach ($beUser->extPageInTreeInfo as $key => $row) {
439 $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>';
440 }
441 $outTable = '<table class="typo3-adminPanel-table"><thead><tr><th colspan="2">' . $this->extGetLL('cache_cacheEntries') . '</th></tr></thead>' . $outTable . '</table>';
442 $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') . '" />';
443
444 $out .= $this->extGetItem('', $outTable, '', 'typo3-adminPanel-tableRow', 'typo3-adminPanel-table-wrapper');
445 }
446 return $out;
447 }
448
449 /**
450 * Creates the content for the "edit" section ("module") of the Admin Panel
451 *
452 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
453 * @see display()
454 */
455 protected function getEditModule()
456 {
457 $out = $this->extGetHead('edit');
458 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_edit']) {
459 // If another page module was specified, replace the default Page module with the new one
460 $newPageModule = trim($this->getBackendUser()->getTSConfigVal('options.overridePageModule'));
461 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
462 $this->extNeedUpdate = true;
463 if ($this->extFeEditLoaded) {
464 $out .= $this->extGetItem('edit_displayFieldIcons', '',
465 '<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"' : '') . ' />');
466 $out .= $this->extGetItem('edit_displayIcons', '',
467 '<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"' : '') . ' />');
468 }
469 $out .= $this->extGetItem('', $this->ext_makeToolBar());
470 if (!GeneralUtility::_GP('ADMCMD_view')) {
471 $out .= $this->extGetItem('', '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(('
472 if (parent.opener && parent.opener.top && parent.opener.top.TS) {
473 parent.opener.top.fsMod.recentIds["web"]=' . (int)$this->getTypoScriptFrontendController()->page['uid'] . ';
474 if (parent.opener.top.content && parent.opener.top.content.nav_frame && parent.opener.top.content.nav_frame.refresh_nav) {
475 parent.opener.top.content.nav_frame.refresh_nav();
476 }
477 parent.opener.top.goToModule("' . $pageModule . '");
478 parent.opener.top.focus();
479 } else {
480 vHWin=window.open(' . GeneralUtility::quoteJSvalue(BackendUtility::getBackendScript()) . ',\'' . md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '\');
481 vHWin.focus();
482 }
483 return false;
484 ')) . '">' . $this->extGetLL('edit_openAB') . '</a>');
485 }
486 }
487 return $out;
488 }
489
490 /**
491 * Creates the content for the "tsdebug" section ("module") of the Admin Panel
492 *
493 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
494 * @see display()
495 */
496 protected function getTSDebugModule()
497 {
498 $out = $this->extGetHead('tsdebug');
499 $beuser = $this->getBackendUser();
500 if ($beuser->uc['TSFE_adminConfig']['display_tsdebug']) {
501 $this->extNeedUpdate = true;
502 $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"' : '') . ' />');
503 $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"' : '') . ' />');
504 $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"' : '') . ' />');
505 $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"' : '') . ' />');
506 $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"' : '') . ' />');
507 $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"' : '') . ' />');
508 $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"' : '') . ' />');
509 $timeTracker = $this->getTimeTracker();
510 $timeTracker->printConf['flag_tree'] = $this->extGetFeAdminValue('tsdebug', 'tree');
511 $timeTracker->printConf['allTime'] = $this->extGetFeAdminValue('tsdebug', 'displayTimes');
512 $timeTracker->printConf['flag_messages'] = $this->extGetFeAdminValue('tsdebug', 'displayMessages');
513 $timeTracker->printConf['flag_content'] = $this->extGetFeAdminValue('tsdebug', 'displayContent');
514 $timeTracker->printConf['flag_queries'] = $this->extGetFeAdminValue('tsdebug', 'displayQueries');
515 $out .= $this->extGetItem('', $timeTracker->printTSlog(), '', 'typo3-adminPanel-tableRow', 'typo3-adminPanel-table-wrapper scroll-table');
516 }
517 return $out;
518 }
519
520 /**
521 * Creates the content for the "info" section ("module") of the Admin Panel
522 *
523 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
524 * @see display()
525 */
526 protected function getInfoModule()
527 {
528 $head = $this->extGetHead('info');
529 $out = '';
530 $tsfe = $this->getTypoScriptFrontendController();
531 if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_info']) {
532 $tableArr = array();
533 if ($this->extGetFeAdminValue('cache', 'noCache')) {
534 $theBytes = 0;
535 $count = 0;
536 if (!empty($tsfe->imagesOnPage)) {
537 $tableArr[] = array($this->extGetLL('info_imagesOnPage'), count($tsfe->imagesOnPage), true);
538 foreach ($GLOBALS['TSFE']->imagesOnPage as $file) {
539 $fs = @filesize($file);
540 $tableArr[] = array(TAB . $file, GeneralUtility::formatSize($fs));
541 $theBytes += $fs;
542 $count++;
543 }
544 }
545 // Add an empty line
546 $tableArr[] = array($this->extGetLL('info_imagesSize'), GeneralUtility::formatSize($theBytes), true);
547 $tableArr[] = array($this->extGetLL('info_DocumentSize'), GeneralUtility::formatSize(strlen($tsfe->content)), true);
548 $tableArr[] = array('', '');
549 }
550 $tableArr[] = array($this->extGetLL('info_id'), $tsfe->id);
551 $tableArr[] = array($this->extGetLL('info_type'), $tsfe->type);
552 $tableArr[] = array($this->extGetLL('info_groupList'), $tsfe->gr_list);
553 $tableArr[] = array($this->extGetLL('info_noCache'), $this->extGetLL('info_noCache_' . ($tsfe->no_cache ? 'no' : 'yes')));
554 $tableArr[] = array($this->extGetLL('info_countUserInt'), count($tsfe->config['INTincScript']));
555
556 if (!empty($tsfe->fe_user->user['uid'])) {
557 $tableArr[] = array($this->extGetLL('info_feuserName'), htmlspecialchars($tsfe->fe_user->user['username']));
558 $tableArr[] = array($this->extGetLL('info_feuserId'), htmlspecialchars($tsfe->fe_user->user['uid']));
559 }
560 $tableArr[] = array($this->extGetLL('info_totalParsetime'), $tsfe->scriptParseTime . ' ms', true);
561 $table = '';
562 foreach ($tableArr as $key => $arr) {
563 $label = (isset($arr[2]) ? '<strong>' . $arr[0] . '</strong>' : $arr[0]);
564 $value = (string)$arr[1] !== '' ? $arr[1] : '';
565 $table .=
566 '<tr class="typo3-adminPanel-itemRow ' . ($key % 2 == 0 ? 'line-even' : 'line-odd') . '">
567 <td>' . $label . '</td>
568 <td>' . htmlspecialchars($value) . '</td>
569 </tr>';
570 }
571 $out .= $table;
572 $out = '<table class="typo3-adminPanel-table">' . $out . '</table>';
573 $out = $this->extGetItem('', $out, '', 'typo3-adminPanel-tableRow', 'typo3-adminPanel-table-wrapper');
574 }
575
576 $out = $head . $out;
577 return $out;
578 }
579
580 /*****************************************************
581 * Admin Panel Layout Helper functions
582 ****************************************************/
583 /**
584 * Returns a row (with colspan=4) which is a header for a section in the Admin Panel.
585 * 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
586 * See the functions get*Module
587 *
588 * @param string $sectionSuffix The suffix to the display_ label. Also selects the label from the LOCAL_LANG array.
589 * @return string HTML table row.
590 * @see extGetItem()
591 */
592 public function extGetHead($sectionSuffix)
593 {
594 $settingName = 'display_' . $sectionSuffix;
595 $isVisible = $this->getBackendUser()->uc['TSFE_adminConfig'][$settingName];
596 $cssClassName = 'typo3-adminPanel-section-' . ($isVisible ? 'open' : 'closed');
597 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>';
598 }
599
600 /**
601 * Wraps a string in a link which will open/close a certain part of the Admin Panel
602 *
603 * @param string $sectionSuffix The code for the display_ label/key
604 * @param string $sectionTitle Title (in HTML-format)
605 * @param string $className The classname for the <a> tag
606 * @return string $className Linked input string
607 * @see extGetHead()
608 */
609 public function linkSectionHeader($sectionSuffix, $sectionTitle, $className = '')
610 {
611 $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;';
612 $content = '<div class="typo3-adminPanel-label">
613 <a href="javascript:void(0)" onclick="' . htmlspecialchars($onclick) . '"' . ($className ? ' class="fa ' . htmlspecialchars($className) . '"' : '') . '>'
614 . $sectionTitle .
615 '</a>
616 </div>';
617 return $content;
618 }
619
620 /**
621 * Returns a row (with 4 columns) for content in a section of the Admin Panel.
622 * It will take $pre as a key to a label to display and $element as the content to put into the forth cell.
623 *
624 * @param string $title Key to label
625 * @param string $content The HTML content for the forth table cell.
626 * @param string $checkbox The HTML for a checkbox or hidden fields.
627 * @param string $innerDivClass The Class attribute for the td element.
628 * @param string $outerDivClass The Class attribute for the tr element.
629 * @return string HTML table row.
630 * @see extGetHead()
631 */
632 public function extGetItem($title, $content = '', $checkbox = '', $outerDivClass = null, $innerDivClass = null)
633 {
634 $title = $title ? '<label for="' . htmlspecialchars($title) . '">' . $this->extGetLL($title) . '</label>' : '';
635 $outerDivClass === null ? $out = '<div class="typo3-adminPanel-itemRow">' : $out = '<div class="' . $outerDivClass . '">';
636 $innerDivClass === null ? $out .= '<div class="typo3-adminPanel-section-content">' : $out .= '<div class="' . $innerDivClass . '">';
637 $out .= $checkbox . $title . $content . '</div>
638 </div>';
639 return $out;
640 }
641
642 /**
643 * Creates the tool bar links for the "edit" section of the Admin Panel.
644 *
645 * @return string A string containing images wrapped in <a>-tags linking them to proper functions.
646 */
647 public function ext_makeToolBar()
648 {
649 $tsfe = $this->getTypoScriptFrontendController();
650 // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead:
651 $tsConfig = BackendUtility::getModTSconfig($tsfe->page['uid'], 'mod');
652 $moduleName = $tsConfig['properties']['newContentElementWizard.']['override'] ?: 'new_content_element';
653 $newContentWizScriptPath = BackendUtility::getModuleUrl($moduleName);
654 $perms = $this->getBackendUser()->calcPerms($tsfe->page);
655 $langAllowed = $this->getBackendUser()->checkLanguageAccess($tsfe->sys_language_uid);
656 $id = $tsfe->id;
657 $returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI');
658
659 $icon = $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render();
660 $link = BackendUtility::getModuleUrl('record_history', array('element' => 'pages:' . $id, 'returnUrl' => $returnUrl));
661 $toolBar = '<a class="t3-icon btn btn-default" href="' . htmlspecialchars($link) . '#latest" title="' . $this->extGetLL('edit_recordHistory') . '">' . $icon . '</a>';
662 if ($perms & Permission::CONTENT_EDIT && $langAllowed) {
663 $params = '';
664 if ($tsfe->sys_language_uid) {
665 $params = '&sys_language_uid=' . $tsfe->sys_language_uid;
666 }
667 $icon = $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render();
668 $link = $newContentWizScriptPath . 'id=' . $id . $params . '&returnUrl=' . rawurlencode($returnUrl);
669 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars($link) . '" title="' . $this->extGetLL('edit_newContentElement') . '"">' . $icon . '</a>';
670 }
671 if ($perms & Permission::PAGE_EDIT) {
672 $icon = $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL)->render();
673 $link = BackendUtility::getModuleUrl('move_element', ['table' => 'pages', 'uid' => $id, 'returnUrl' => $returnUrl]);
674 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars($link) . '" title="' . $this->extGetLL('edit_move_page') . '">' . $icon . '</a>';
675 }
676 if ($perms & Permission::PAGE_NEW) {
677 $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') . '">'
678 . $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render()
679 . '</a>';
680 }
681 if ($perms & Permission::PAGE_EDIT) {
682 $icon = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render();
683 $url = BackendUtility::getModuleUrl('record_edit', array(
684 'edit[pages][' . $id . ']' => 'edit',
685 'noView' => 1,
686 'returnUrl' => $returnUrl
687 ));
688 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars($url) . '">' . $icon . '</a>';
689 if ($tsfe->sys_language_uid && $langAllowed) {
690 $row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
691 'uid,pid,t3ver_state',
692 'pages_language_overlay',
693 'pid=' . (int)$id .
694 ' AND sys_language_uid=' . $tsfe->sys_language_uid .
695 $tsfe->sys_page->enableFields('pages_language_overlay')
696 );
697 $tsfe->sys_page->versionOL('pages_language_overlay', $row);
698 if (is_array($row)) {
699 $icon = '<span title="' . $this->extGetLL('edit_editPageOverlay', true) . '">'
700 . $this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)->render() . '</span>';
701 $url = BackendUtility::getModuleUrl('record_edit', array(
702 'edit[pages_language_overlay][' . $row['uid'] . ']' => 'edit',
703 'noView' => 1,
704 'returnUrl' => $returnUrl
705 ));
706 $toolBar .= '<a href="' . htmlspecialchars($url) . '">' . $icon . '</a>';
707 }
708 }
709 }
710 if ($this->getBackendUser()->check('modules', 'web_list')) {
711 $urlParams = array(
712 'id' => $id,
713 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
714 );
715 $icon = '<span title="' . $this->extGetLL('edit_db_list', false) . '">' . $this->iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render() . '</span>';
716 $toolBar .= '<a class="t3-icon btn btn-default" href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_list', $urlParams)) . '">' . $icon . '</a>';
717 }
718
719 $toolBar = '<div class="toolbar btn-group" role="group">' . $toolBar . '</div>';
720 return $toolBar;
721 }
722
723 /**
724 * Translate given key
725 *
726 * @param string $key Key for a label in the $LOCAL_LANG array of "sysext/lang/locallang_tsfe.xlf
727 * @param bool $convertWithHtmlspecialchars If TRUE the language-label will be sent through htmlspecialchars
728 * @return string The value for the $key
729 */
730 protected function extGetLL($key, $convertWithHtmlspecialchars = true)
731 {
732 $labelStr = $this->getLanguageService()->getLL($key);
733 if ($convertWithHtmlspecialchars) {
734 $labelStr = htmlspecialchars($labelStr);
735 }
736 return $labelStr;
737 }
738
739 /**
740 * Returns LanguageService
741 *
742 * @return \TYPO3\CMS\Lang\LanguageService
743 */
744 protected function getLanguageService()
745 {
746 return $GLOBALS['LANG'];
747 }
748
749 /**
750 * Returns the current BE user.
751 *
752 * @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
753 */
754 protected function getBackendUser()
755 {
756 return $GLOBALS['BE_USER'];
757 }
758
759 /**
760 * Returns the database connection
761 *
762 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
763 */
764 protected function getDatabaseConnection()
765 {
766 return $GLOBALS['TYPO3_DB'];
767 }
768
769 /**
770 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
771 */
772 protected function getTypoScriptFrontendController()
773 {
774 return $GLOBALS['TSFE'];
775 }
776
777 /**
778 * @return \TYPO3\CMS\Core\TimeTracker\TimeTracker
779 */
780 protected function getTimeTracker()
781 {
782 return $GLOBALS['TT'];
783 }
784 }