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