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