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