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