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