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