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