981a73d92a586f0031754d4dda0ae221301ab6f3
[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\Type\Bitmask\Permission;
20 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * View class for the admin panel in frontend editing.
25 */
26 class AdminPanelView {
27
28 /**
29 * Determines whether the update button should be shown.
30 *
31 * @var bool
32 */
33 protected $extNeedUpdate = FALSE;
34
35 /**
36 * Force preview
37 *
38 * @var bool
39 */
40 protected $ext_forcePreview = FALSE;
41
42 /**
43 * @var string
44 */
45 protected $extJSCODE = '';
46
47 /**
48 * Constructor
49 */
50 public function __construct() {
51 $this->initialize();
52 }
53
54 /**
55 * Initializes settings for the admin panel.
56 *
57 * @return void
58 */
59 public function initialize() {
60 $this->saveConfigOptions();
61 // Setting some values based on the admin panel
62 $GLOBALS['TSFE']->forceTemplateParsing = $this->extGetFeAdminValue('tsdebug', 'forceTemplateParsing');
63 $GLOBALS['TSFE']->displayEditIcons = $this->extGetFeAdminValue('edit', 'displayIcons');
64 $GLOBALS['TSFE']->displayFieldEditIcons = $this->extGetFeAdminValue('edit', 'displayFieldIcons');
65 if ($this->extGetFeAdminValue('tsdebug', 'displayQueries')) {
66 // Do not override if the value is already set in \TYPO3\CMS\Core\Database\DatabaseConnection
67 if ($GLOBALS['TYPO3_DB']->explainOutput == 0) {
68 // Enable execution of EXPLAIN SELECT queries
69 $GLOBALS['TYPO3_DB']->explainOutput = 3;
70 }
71 }
72 if (GeneralUtility::_GP('ADMCMD_editIcons')) {
73 $GLOBALS['TSFE']->displayFieldEditIcons = 1;
74 }
75 if (GeneralUtility::_GP('ADMCMD_simUser')) {
76 $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['preview_simulateUserGroup'] = (int)GeneralUtility::_GP('ADMCMD_simUser');
77 $this->ext_forcePreview = TRUE;
78 }
79 if (GeneralUtility::_GP('ADMCMD_simTime')) {
80 $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['preview_simulateDate'] = (int)GeneralUtility::_GP('ADMCMD_simTime');
81 $this->ext_forcePreview = TRUE;
82 }
83 if ($GLOBALS['TSFE']->forceTemplateParsing) {
84 $GLOBALS['TSFE']->set_no_cache('Admin Panel: Force template parsing', TRUE);
85 } elseif ($GLOBALS['TSFE']->displayEditIcons) {
86 $GLOBALS['TSFE']->set_no_cache('Admin Panel: Display edit icons', TRUE);
87 } elseif ($GLOBALS['TSFE']->displayFieldEditIcons) {
88 $GLOBALS['TSFE']->set_no_cache('Admin Panel: Display field edit icons', TRUE);
89 } elseif (GeneralUtility::_GP('ADMCMD_view')) {
90 $GLOBALS['TSFE']->set_no_cache('Admin Panel: Display preview', TRUE);
91 }
92 }
93
94 /**
95 * Add an additional stylesheet
96 *
97 * @return string
98 */
99 public function getAdminPanelHeaderData() {
100 $result = '';
101 if (!empty($GLOBALS['TBE_STYLES']['stylesheets']['admPanel'])) {
102 $stylesheet = GeneralUtility::locationHeaderUrl($GLOBALS['TBE_STYLES']['stylesheets']['admPanel']);
103 $result = '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($stylesheet) . '" />';
104 }
105 return $result;
106 }
107
108 /**
109 * Checks if an Admin Panel section ("module") is available for the user. If so, TRUE is returned.
110 *
111 * @param string $key The module key, eg. "edit", "preview", "info" etc.
112 * @return bool
113 */
114 public function isAdminModuleEnabled($key) {
115 $result = FALSE;
116 // Returns TRUE if the module checked is "preview" and the forcePreview flag is set.
117 if ($key === 'preview' && $this->ext_forcePreview) {
118 $result = TRUE;
119 } elseif (!empty($GLOBALS['BE_USER']->extAdminConfig['enable.']['all'])) {
120 $result = TRUE;
121 } elseif (!empty($GLOBALS['BE_USER']->extAdminConfig['enable.'][$key])) {
122 $result = TRUE;
123 }
124 return $result;
125 }
126
127 /**
128 * Saves any change in settings made in the Admin Panel.
129 * Called from index_ts.php right after access check for the Admin Panel
130 *
131 * @return void
132 */
133 public function saveConfigOptions() {
134 $input = GeneralUtility::_GP('TSFE_ADMIN_PANEL');
135 if (is_array($input)) {
136 // Setting
137 $GLOBALS['BE_USER']->uc['TSFE_adminConfig'] = array_merge(!is_array($GLOBALS['BE_USER']->uc['TSFE_adminConfig']) ? array() : $GLOBALS['BE_USER']->uc['TSFE_adminConfig'], $input);
138 unset($GLOBALS['BE_USER']->uc['TSFE_adminConfig']['action']);
139 // Actions:
140 if ($input['action']['clearCache'] && $this->isAdminModuleEnabled('cache')) {
141 $GLOBALS['BE_USER']->extPageInTreeInfo = array();
142 $theStartId = (int)$input['cache_clearCacheId'];
143 $GLOBALS['TSFE']->clearPageCacheContent_pidList($GLOBALS['BE_USER']->extGetTreeList($theStartId, $this->extGetFeAdminValue('cache', 'clearCacheLevels'), 0, $GLOBALS['BE_USER']->getPagePermsClause(1)) . $theStartId);
144 }
145 // Saving
146 $GLOBALS['BE_USER']->writeUC();
147 }
148 $GLOBALS['TT']->LR = $this->extGetFeAdminValue('tsdebug', 'LR');
149 if ($this->extGetFeAdminValue('cache', 'noCache')) {
150 $GLOBALS['TSFE']->set_no_cache('Admin Panel: No Caching', TRUE);
151 }
152 }
153
154 /**
155 * Returns the value for an Admin Panel setting.
156 *
157 * @param string $sectionName Module key
158 * @param string $val Setting key
159 * @return mixed The setting value
160 */
161 public function extGetFeAdminValue($sectionName, $val = '') {
162 if (!$this->isAdminModuleEnabled($sectionName)) {
163 return NULL;
164 }
165
166 // Exceptions where the values can be overridden (forced) from backend:
167 // deprecated
168 if (
169 $sectionName === 'edit' && (
170 $val === 'displayIcons' && $GLOBALS['BE_USER']->extAdminConfig['module.']['edit.']['forceDisplayIcons'] ||
171 $val === 'displayFieldIcons' && $GLOBALS['BE_USER']->extAdminConfig['module.']['edit.']['forceDisplayFieldIcons'] ||
172 $val === 'editNoPopup' && $GLOBALS['BE_USER']->extAdminConfig['module.']['edit.']['forceNoPopup']
173 )
174 ) {
175 return TRUE;
176 }
177
178 // Override all settings with user TSconfig
179 if ($val && isset($GLOBALS['BE_USER']->extAdminConfig['override.'][$sectionName . '.'][$val])) {
180 return $GLOBALS['BE_USER']->extAdminConfig['override.'][$sectionName . '.'][$val];
181 }
182 if (isset($GLOBALS['BE_USER']->extAdminConfig['override.'][$sectionName])) {
183 return $GLOBALS['BE_USER']->extAdminConfig['override.'][$sectionName];
184 }
185
186 $returnValue = $val ? $GLOBALS['BE_USER']->uc['TSFE_adminConfig'][$sectionName . '_' . $val] : 1;
187
188 // Exception for preview
189 if ($sectionName === 'preview' && $this->ext_forcePreview) {
190 return !$val ? TRUE : $returnValue;
191 }
192
193 // See if the menu is expanded!
194 return $this->isAdminModuleOpen($sectionName) ? $returnValue : NULL;
195 }
196
197 /**
198 * Enables the force preview option.
199 *
200 * @return void
201 */
202 public function forcePreview() {
203 $this->ext_forcePreview = TRUE;
204 }
205
206 /**
207 * Returns TRUE if admin panel module is open
208 *
209 * @param string $key Module key
210 * @return bool TRUE, if the admin panel is open for the specified admin panel module key.
211 */
212 public function isAdminModuleOpen($key) {
213 return $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_top'] && $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_' . $key];
214 }
215
216 /**
217 * Creates and returns the HTML code for the Admin Panel in the TSFE frontend.
218 *
219 * @throws \UnexpectedValueException
220 * @return string HTML for the Admin Panel
221 */
222 public function display() {
223 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_tsfe.xlf');
224 $moduleContent = $footer = '';
225
226 if ($GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_top']) {
227 if ($this->isAdminModuleEnabled('preview')) {
228 $moduleContent .= $this->getPreviewModule();
229 }
230 if ($this->isAdminModuleEnabled('cache')) {
231 $moduleContent .= $this->getCacheModule();
232 }
233 if ($this->isAdminModuleEnabled('edit')) {
234 $moduleContent .= $this->getEditModule();
235 }
236 if ($this->isAdminModuleEnabled('tsdebug')) {
237 $moduleContent .= $this->getTSDebugModule();
238 }
239 if ($this->isAdminModuleEnabled('info')) {
240 $moduleContent .= $this->getInfoModule();
241 }
242 }
243 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'])) {
244 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'] as $classRef) {
245 $hookObject = GeneralUtility::getUserObj($classRef);
246 if (!$hookObject instanceof AdminPanelViewHookInterface) {
247 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Frontend\\View\\AdminPanelViewHookInterface', 1311942539);
248 }
249 $moduleContent .= $hookObject->extendAdminPanel($moduleContent, $this);
250 }
251 }
252 $row = $this->extGetLL('adminPanelTitle') . ': <span class="typo3-adminPanel-beuser">' . htmlspecialchars($GLOBALS['BE_USER']->user['username']) . '</span>';
253 $isVisible = $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_top'];
254 $cssClassName = 'typo3-adminPanel-panel-' . ($isVisible ? 'open' : 'closed');
255 $header = '<tr class="typo3-adminPanel-header">' . '<td colspan="2" id="typo3-adminPanel-header" class="' . $cssClassName . '">' . '<span class="typo3-adminPanel-header-title">' . $row . '</span>' . $this->linkSectionHeader('top', '<span class="typo3-adminPanel-header-button"></span>', 'typo3-adminPanel-header-buttonWrapper') . '<input type="hidden" name="TSFE_ADMIN_PANEL[display_top]" value="' . $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_top'] . '" /></td>' . '</tr>';
256 if ($moduleContent && $this->extNeedUpdate) {
257 $footer = '<tr class="typo3-adminPanel-footer">
258 <td colspan="2">
259 <input class="typo3-adminPanel-update" type="submit" value="' . $this->extGetLL('update') . '" />
260 </td>
261 </tr>';
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"></a>
282 <form id="TSFE_ADMIN_PANEL_FORM" name="TSFE_ADMIN_PANEL_FORM" action="' . htmlspecialchars(GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT')) . '#TSFE_ADMIN" method="get" onsubmit="document.forms.TSFE_ADMIN_PANEL_FORM[\'TSFE_ADMIN_PANEL[DUMMY]\'].value=Math.random().toString().substring(2,8)">' . $query . '<table class="typo3-adminPanel">' . $header . $moduleContent . $footer . '</table></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 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 $row) {
407 $outTable .= '<tr>' . '<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 = '<br /><table>' . $outTable . '</table>';
410 $outTable .= '<input type="submit" name="TSFE_ADMIN_PANEL[action][clearCache]" value="' . $this->extGetLL('cache_doit') . '" />';
411 $out .= $this->extGetItem('cache_cacheEntries', $outTable);
412 }
413 return $out;
414 }
415
416 /**
417 * Creates the content for the "edit" section ("module") of the Admin Panel
418 *
419 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
420 * @see display()
421 */
422 protected function getEditModule() {
423 $out = $this->extGetHead('edit');
424 if ($GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_edit']) {
425 // If another page module was specified, replace the default Page module with the new one
426 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
427 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
428 $this->extNeedUpdate = TRUE;
429 $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"' : '') . ' />');
430 $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"' : '') . ' />');
431 $out .= $this->extGetItem('', $this->ext_makeToolBar());
432 if (!GeneralUtility::_GP('ADMCMD_view')) {
433 $out .= $this->extGetItem('', '<a href="#" onclick="' . htmlspecialchars(('
434 if (parent.opener && parent.opener.top && parent.opener.top.TS) {
435 parent.opener.top.fsMod.recentIds["web"]=' . (int)$GLOBALS['TSFE']->page['uid'] . ';
436 if (parent.opener.top.content && parent.opener.top.content.nav_frame && parent.opener.top.content.nav_frame.refresh_nav) {
437 parent.opener.top.content.nav_frame.refresh_nav();
438 }
439 parent.opener.top.goToModule("' . $pageModule . '");
440 parent.opener.top.focus();
441 } else {
442 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\');
443 vHWin.focus();
444 }
445 return false;
446 ')) . '">' . $this->extGetLL('edit_openAB') . '</a>');
447 }
448 }
449 return $out;
450 }
451
452 /**
453 * Creates the content for the "tsdebug" section ("module") of the Admin Panel
454 *
455 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
456 * @see display()
457 */
458 protected function getTSDebugModule() {
459 $out = $this->extGetHead('tsdebug');
460 if ($GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_tsdebug']) {
461 $this->extNeedUpdate = TRUE;
462 $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"' : '') . ' />');
463 $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"' : '') . ' />');
464 $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"' : '') . ' />');
465 $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"' : '') . ' />');
466 $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"' : '') . ' />');
467 $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"' : '') . ' />');
468 $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"' : '') . ' />');
469 $GLOBALS['TT']->printConf['flag_tree'] = $this->extGetFeAdminValue('tsdebug', 'tree');
470 $GLOBALS['TT']->printConf['allTime'] = $this->extGetFeAdminValue('tsdebug', 'displayTimes');
471 $GLOBALS['TT']->printConf['flag_messages'] = $this->extGetFeAdminValue('tsdebug', 'displayMessages');
472 $GLOBALS['TT']->printConf['flag_content'] = $this->extGetFeAdminValue('tsdebug', 'displayContent');
473 $GLOBALS['TT']->printConf['flag_queries'] = $this->extGetFeAdminValue('tsdebug', 'displayQueries');
474 $out .= '<tr><td colspan="2">' . $GLOBALS['TT']->printTSlog() . '</td></tr>';
475 }
476 return $out;
477 }
478
479 /**
480 * Creates the content for the "info" section ("module") of the Admin Panel
481 *
482 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
483 * @see display()
484 */
485 protected function getInfoModule() {
486 $head = $this->extGetHead('info');
487 $out = '';
488 if ($GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_info']) {
489 $tableArr = array();
490 if ($this->extGetFeAdminValue('cache', 'noCache')) {
491 $theBytes = 0;
492 $count = 0;
493 if (!empty($GLOBALS['TSFE']->imagesOnPage)) {
494 $tableArr[] = array($this->extGetLL('info_imagesOnPage'), count($GLOBALS['TSFE']->imagesOnPage), TRUE);
495 foreach ($GLOBALS['TSFE']->imagesOnPage as $file) {
496 $fs = @filesize($file);
497 $tableArr[] = array(TAB . $file, GeneralUtility::formatSize($fs));
498 $theBytes += $fs;
499 $count++;
500 }
501 }
502 // Add an empty line
503 $tableArr[] = array($this->extGetLL('info_imagesSize'), GeneralUtility::formatSize($theBytes), TRUE);
504 $tableArr[] = array($this->extGetLL('info_DocumentSize'), GeneralUtility::formatSize(strlen($GLOBALS['TSFE']->content)), TRUE);
505 $tableArr[] = array('', '');
506 }
507 $tableArr[] = array($this->extGetLL('info_id'), $GLOBALS['TSFE']->id);
508 $tableArr[] = array($this->extGetLL('info_type'), $GLOBALS['TSFE']->type);
509 $tableArr[] = array($this->extGetLL('info_groupList'), $GLOBALS['TSFE']->gr_list);
510 $tableArr[] = array($this->extGetLL('info_noCache'), $this->extGetLL('info_noCache_' . ($GLOBALS['TSFE']->no_cache ? 'no' : 'yes')));
511 $tableArr[] = array($this->extGetLL('info_countUserInt'), count($GLOBALS['TSFE']->config['INTincScript']));
512
513 if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
514 $tableArr[] = array($this->extGetLL('info_feuserName'), htmlspecialchars($GLOBALS['TSFE']->fe_user->user['username']));
515 $tableArr[] = array($this->extGetLL('info_feuserId'), htmlspecialchars($GLOBALS['TSFE']->fe_user->user['uid']));
516 }
517 $tableArr[] = array($this->extGetLL('info_totalParsetime'), $GLOBALS['TSFE']->scriptParseTime . ' ms', TRUE);
518 $table = '';
519 foreach ($tableArr as $key => $arr) {
520 $label = (isset($arr[2]) ? '<strong>' . $arr[0] . '</strong>' : $arr[0]);
521 $value = (string)$arr[1] !== '' ? $arr[1] : '';
522 $table .=
523 '<tr class="typo3-adminPanel-itemRow ' . ($key % 2 == 0 ? 'line-even' : 'line-odd') . '">
524 <td class="typo3-adminPanel-section-content-title">' . $label . '</td>
525 <td class="typo3-adminPanel-section-content">' . htmlspecialchars($value) . '</td>
526 </tr>';
527 }
528 $out .= $table;
529 $out = '<tr><td colspan="2"><table class="admin-panel-table">' . $out . '</table></td></tr>';
530 }
531
532 $out = $head . $out;
533 return $out;
534 }
535
536 /*****************************************************
537 * Admin Panel Layout Helper functions
538 ****************************************************/
539 /**
540 * Returns a row (with colspan=4) which is a header for a section in the Admin Panel.
541 * 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
542 * See the functions get*Module
543 *
544 * @param string $sectionSuffix The suffix to the display_ label. Also selects the label from the LOCAL_LANG array.
545 * @return string HTML table row.
546 * @see extGetItem()
547 */
548 public function extGetHead($sectionSuffix) {
549 $settingName = 'display_' . $sectionSuffix;
550 $isVisible = $GLOBALS['BE_USER']->uc['TSFE_adminConfig'][$settingName];
551 $cssClassName = 'typo3-adminPanel-section-' . ($isVisible ? 'open' : 'closed');
552 return '<tr class="typo3-adminPanel-section-title"><td colspan="2">' . $this->linkSectionHeader($sectionSuffix, $this->extGetLL($sectionSuffix), $cssClassName) . '<input type="hidden" name="TSFE_ADMIN_PANEL[' . $settingName . ']" value="' . $isVisible . '" /></td></tr>';
553 }
554
555 /**
556 * Wraps a string in a link which will open/close a certain part of the Admin Panel
557 *
558 * @param string $sectionSuffix The code for the display_ label/key
559 * @param string $sectionTitle Title (in HTML-format)
560 * @param string $className The classname for the <a> tag
561 * @return string $className Linked input string
562 * @see extGetHead()
563 */
564 public function linkSectionHeader($sectionSuffix, $sectionTitle, $className = '') {
565 $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;';
566 $content = '<div class="typo3-adminPanel-label">
567 <a href="javascript:void(0)" onclick="' . htmlspecialchars($onclick) . '"' . ($className ? ' class="' . htmlspecialchars($className) . '"' : '') . '>'
568 . $sectionTitle .
569 '</a>
570 </div>';
571 return $content;
572 }
573
574 /**
575 * Returns a row (with 4 columns) for content in a section of the Admin Panel.
576 * It will take $pre as a key to a label to display and $element as the content to put into the forth cell.
577 *
578 * @param string $title Key to label
579 * @param string $content The HTML content for the forth table cell.
580 * @param string $checkbox The HTML for a checkbox or hidden fields
581 * @return string HTML table row.
582 * @see extGetHead()
583 */
584 public function extGetItem($title, $content = '', $checkbox = '') {
585 $title = $title ? '<label for="' . htmlspecialchars($title) . '">' . $this->extGetLL($title) . '</label>' : '';
586 $out = '<tr class="typo3-adminPanel-itemRow">
587 <td class="typo3-adminPanel-section-content">' . $checkbox . $title . $content . '</td>
588 </tr>';
589 return $out;
590 }
591
592 /**
593 * Creates the tool bar links for the "edit" section of the Admin Panel.
594 *
595 * @return string A string containing images wrapped in <a>-tags linking them to proper functions.
596 */
597 public function ext_makeToolBar() {
598 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
599 $tsConfig = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod.web_list');
600 $tsConfig = $tsConfig['properties']['newContentWiz.']['overrideWithExtension'];
601 $newContentWizScriptPath = ExtensionManagementUtility::isLoaded($tsConfig) ? ExtensionManagementUtility::extRelPath($tsConfig) . 'mod1/db_new_content_el.php?' : BackendUtility::getModuleUrl('new_content_element') . '&';
602 $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
603 $langAllowed = $GLOBALS['BE_USER']->checkLanguageAccess($GLOBALS['TSFE']->sys_language_uid);
604 $id = $GLOBALS['TSFE']->id;
605 $returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI');
606
607 $icon = IconUtility::getSpriteIcon('actions-document-history-open', array('title' => $this->extGetLL('edit_recordHistory', FALSE)));
608 $toolBar = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('record_history', array('element' => 'pages:' . $id, 'returnUrl' => $returnUrl))) . '#latest">' . $icon . '</a>';
609 if ($perms & Permission::CONTENT_EDIT && $langAllowed) {
610 $params = '';
611 if ($GLOBALS['TSFE']->sys_language_uid) {
612 $params = '&sys_language_uid=' . $GLOBALS['TSFE']->sys_language_uid;
613 }
614 $icon = IconUtility::getSpriteIcon('actions-document-new', array('title' => $this->extGetLL('edit_newContentElement', FALSE)));
615 $toolBar .= '<a href="' . htmlspecialchars($newContentWizScriptPath . 'id=' . $id . $params . '&returnUrl=' . rawurlencode($returnUrl)) . '">' . $icon . '</a>';
616 }
617 if ($perms & Permission::PAGE_EDIT) {
618 $icon = IconUtility::getSpriteIcon('actions-document-move', array('title' => $this->extGetLL('edit_move_page', FALSE)));
619 $toolBar .= '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('move_element', ['table' => 'pages', 'uid' => $id, 'returnUrl' => $returnUrl])) . '">' . $icon . '</a>';
620 }
621 if ($perms & Permission::PAGE_NEW) {
622 $icon = IconUtility::getSpriteIcon('actions-page-new', array('title' => $this->extGetLL('edit_newPage', FALSE)));
623 $toolBar .= '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('db_new', ['id' => $id, 'pagesOnly' => 1, 'returnUrl' => $returnUrl])) . '">' . $icon . '</a>';
624 }
625 if ($perms & Permission::PAGE_EDIT) {
626 $icon = IconUtility::getSpriteIcon('actions-document-open', array('title' => $this->extGetLL('edit_editPageProperties', FALSE)));
627 $url = BackendUtility::getModuleUrl('record_edit', array(
628 'edit[pages][' . $id . ']' => 'edit',
629 'noView' => 1,
630 'returnUrl' => $returnUrl
631 ));
632 $toolBar .= '<a href="' . htmlspecialchars($url) . '">' . $icon . '</a>';
633 if ($GLOBALS['TSFE']->sys_language_uid && $langAllowed) {
634 $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
635 'uid,pid,t3ver_state',
636 'pages_language_overlay',
637 'pid=' . (int)$id .
638 ' AND sys_language_uid=' . $GLOBALS['TSFE']->sys_language_uid .
639 $GLOBALS['TSFE']->sys_page->enableFields('pages_language_overlay')
640 );
641 $GLOBALS['TSFE']->sys_page->versionOL('pages_language_overlay', $row);
642 if (is_array($row)) {
643 $icon = IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay', array('title' => $this->extGetLL('edit_editPageOverlay', FALSE)));
644 $url = BackendUtility::getModuleUrl('record_edit', array(
645 'edit[pages_language_overlay][' . $row['uid'] . ']' => 'edit',
646 'noView' => 1,
647 'returnUrl' => $returnUrl
648 ));
649 $toolBar .= '<a href="' . htmlspecialchars($url) . '">' . $icon . '</a>';
650 }
651 }
652 }
653 if ($GLOBALS['BE_USER']->check('modules', 'web_list')) {
654 $urlParams = array(
655 'id' => $id,
656 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
657 );
658 $icon = IconUtility::getSpriteIcon('actions-system-list-open', array('title' => $this->extGetLL('edit_db_list', FALSE)));
659 $toolBar .= '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_list', $urlParams)) . '">' . $icon . '</a>';
660 }
661
662 $toolBar = '<div class="toolbar">' . $toolBar . '</div>';
663
664 return $toolBar;
665 }
666
667 /**
668 * Translate given key
669 *
670 * @param string $key Key for a label in the $LOCAL_LANG array of "sysext/lang/locallang_tsfe.xlf
671 * @param bool $convertWithHtmlspecialchars If TRUE the language-label will be sent through htmlspecialchars
672 * @return string The value for the $key
673 */
674 protected function extGetLL($key, $convertWithHtmlspecialchars = TRUE) {
675 $labelStr = $GLOBALS['LANG']->getLL($key);
676 if ($convertWithHtmlspecialchars) {
677 $labelStr = htmlspecialchars($labelStr);
678 }
679 return $labelStr;
680 }
681
682 }