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