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