* Merging all changes from TYPO3_4-0 branch back into HEAD
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsfebeuserauth.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
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 textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Class for TYPO3 backend user authentication in the TSFE frontend
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 103: class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth
42 * 129: function extInitFeAdmin()
43 * 154: function extPrintFeAdminDialog()
44 *
45 * SECTION: Creating sections of the Admin Panel
46 * 250: function extGetCategory_preview($out='')
47 * 283: function extGetCategory_cache($out='')
48 * 321: function extGetCategory_publish($out='')
49 * 356: function extGetCategory_edit($out='')
50 * 400: function extGetCategory_tsdebug($out='')
51 * 433: function extGetCategory_info($out='')
52 *
53 * SECTION: Admin Panel Layout Helper functions
54 * 506: function extGetHead($pre)
55 * 526: function extItemLink($pre,$str)
56 * 542: function extGetItem($pre,$element)
57 * 559: function extFw($str)
58 * 568: function ext_makeToolBar()
59 *
60 * SECTION: TSFE BE user Access Functions
61 * 637: function checkBackendAccessSettingsFromInitPhp()
62 * 682: function extPageReadAccess($pageRec)
63 * 693: function extAdmModuleEnabled($key)
64 * 709: function extSaveFeAdminConfig()
65 * 741: function extGetFeAdminValue($pre,$val='')
66 * 783: function extIsAdmMenuOpen($pre)
67 *
68 * SECTION: TSFE BE user Access Functions
69 * 818: function extGetTreeList($id,$depth,$begin=0,$perms_clause)
70 * 849: function extGetNumberOfCachedPages($page_id)
71 *
72 * SECTION: Localization handling
73 * 888: function extGetLL($key)
74 *
75 * SECTION: Frontend Editing
76 * 932: function extIsEditAction()
77 * 954: function extIsFormShown()
78 * 970: function extEditAction()
79 *
80 * TOTAL FUNCTIONS: 25
81 * (This index is automatically created/updated by the extension "extdeveval")
82 *
83 */
84
85
86
87
88
89
90
91
92
93
94
95 /**
96 * TYPO3 backend user authentication in the TSFE frontend.
97 * This includes mainly functions related to the Admin Panel
98 *
99 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
100 * @package TYPO3
101 * @subpackage t3lib
102 */
103 class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth {
104 var $formfield_uname = ''; // formfield with login-name
105 var $formfield_uident = ''; // formfield with password
106 var $formfield_chalvalue = ''; // formfield with a unique value which is used to encrypt the password and username
107 var $security_level = ''; // sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
108 var $writeStdLog = 0; // Decides if the writelog() function is called at login and logout
109 var $writeAttemptLog = 0; // If the writelog() functions is called if a login-attempt has be tried without success
110 var $auth_include = ''; // this is the name of the include-file containing the login form. If not set, login CAN be anonymous. If set login IS needed.
111
112 var $extNeedUpdate=0;
113 var $extPublishList='';
114 var $extPageInTreeInfo=array();
115 var $ext_forcePreview=0;
116 var $langSplitIndex=0;
117 var $extAdmEnabled = 0; // General flag which is set if the adminpanel should be displayed at all..
118
119
120
121
122 /**
123 * Initialize the usage of Admin Panel.
124 * Called from index_ts.php if a backend users is correctly logged in.
125 * Sets $this->extAdminConfig to the "admPanel" config for the user and $this->extAdmEnabled = 1 IF access is enabled.
126 *
127 * @return void
128 */
129 function extInitFeAdmin() {
130 $this->extAdminConfig = $this->getTSConfigProp('admPanel');
131 if (is_array($this->extAdminConfig['enable.'])) {
132 reset($this->extAdminConfig['enable.']);
133 while(list($k,$v)=each($this->extAdminConfig['enable.'])) {
134 if ($v) {
135 $this->extAdmEnabled=1; // Enable panel
136 break;
137 }
138 }
139 }
140
141 // Init TSFE_EDIT variables if either the admPanel is enabled or if forceDisplayIcons is set
142 if($this->extAdmEnabled || $this->extGetFeAdminValue('edit', 'displayIcons')) {
143 $this->TSFE_EDIT = t3lib_div::_POST('TSFE_EDIT');
144 }
145 }
146
147 /**
148 * Creates and returns the HTML code for the Admin Panel in the TSFE frontend.
149 * Called from index_ts.php - in the end of the script
150 *
151 * @return string HTML for the Admin Panel
152 * @see index_ts.php
153 */
154 function extPrintFeAdminDialog() {
155 $out='';
156 if ($this->uc['TSFE_adminConfig']['display_top']) {
157 if ($this->extAdmModuleEnabled('preview')) $out.= $this->extGetCategory_preview();
158 if ($this->extAdmModuleEnabled('cache')) $out.= $this->extGetCategory_cache();
159 if ($this->extAdmModuleEnabled('publish')) $out.= $this->extGetCategory_publish();
160 if ($this->extAdmModuleEnabled('edit')) $out.= $this->extGetCategory_edit();
161 if ($this->extAdmModuleEnabled('tsdebug')) $out.= $this->extGetCategory_tsdebug();
162 if ($this->extAdmModuleEnabled('info')) $out.= $this->extGetCategory_info();
163 }
164
165 $header='
166 <tr class="typo3-adminPanel-hRow" style="background-color:#9ba1a8;">
167 <td colspan="4" nowrap="nowrap">'.
168 $this->extItemLink('top','<img src="'.TYPO3_mainDir.'gfx/ol/'.($this->uc['TSFE_adminConfig']['display_top']?'minus':'plus').'bullet.gif" width="18" height="16" align="absmiddle" border="0" alt="" /><strong>'.$this->extFw($this->extGetLL('adminOptions')).'</strong>').
169 $this->extFw(': '.$this->user['username']).'
170 <img src="clear.gif" width="40" height="1" alt="" />
171 <input type="hidden" name="TSFE_ADMIN_PANEL[display_top]" value="'.$this->uc['TSFE_adminConfig']['display_top'].'" />'.($this->extNeedUpdate?'<input type="submit" value="'.$this->extGetLL('update').'" />':'').'</td>
172 </tr>';
173
174 $query='';
175 foreach(t3lib_div::_GET() as $k => $v) {
176 if ($k != 'TSFE_ADMIN_PANEL') {
177 if (is_array($v)) {
178 $query.=$this->extPrintFeAdminDialogHiddenFields($k,$v);
179 } else {
180 $query.='<input type="hidden" name="'.$k.'" value="'.htmlspecialchars($v).'">'.chr(10);
181 }
182 }
183 }
184 $out='
185 <!--
186 ADMIN PANEL
187 -->
188 <a name="TSFE_ADMIN"></a>
189 <form name="TSFE_ADMIN_PANEL_FORM" action="'.htmlspecialchars(t3lib_div::getIndpEnv('SCRIPT_NAME')).'#TSFE_ADMIN" method="get" style="margin:0;">
190 '.$query.
191 ' <table border="0" cellpadding="0" cellspacing="0" class="typo3-adminPanel" style="background-color:#f6f2e6; border: 1px solid black; z-index:0; position:absolute;">'.$header.$out.'
192 </table>
193 </form>';
194
195 if ($this->uc['TSFE_adminConfig']['display_top']) {
196 $out.='<script type="text/javascript" src="t3lib/jsfunc.evalfield.js"></script>';
197 $out.='
198 <script type="text/javascript">
199 /*<![CDATA[*/
200 var evalFunc = new evalFunc();
201 // TSFEtypo3FormFieldSet()
202 function TSFEtypo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue) { //
203 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
204 var theValue = document.TSFE_ADMIN_PANEL_FORM[theField].value;
205 if (checkbox && theValue==checkboxValue) {
206 document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value="";
207 document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"].checked = "";
208 } else {
209 document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue);
210 document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"].checked = "on";
211 }
212 }
213 // TSFEtypo3FormFieldGet()
214 function TSFEtypo3FormFieldGet(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off) { //
215 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
216 if (checkbox_off) {
217 document.TSFE_ADMIN_PANEL_FORM[theField].value=checkboxValue;
218 }else{
219 document.TSFE_ADMIN_PANEL_FORM[theField].value = evalFunc.evalObjValue(theFObj, document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value);
220 }
221 TSFEtypo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue);
222 }
223 /*]]>*/
224 </script>
225 <script language="javascript" type="text/javascript">'.$this->extJSCODE.'</script>';
226 }
227 return "\n\n\n\n".$out.'<br />';
228 }
229
230 /**
231 * Fetches recursively all GET parameters as hidden fields.
232 * Called from extPrintFeAdminDialog.
233 *
234 * @param string current key
235 * @param mixed current value
236 * @return string hidden fields
237 * @see extPrintFeAdminDialog()
238 */
239 function extPrintFeAdminDialogHiddenFields($key,&$val) {
240 $out='';
241 foreach($val as $k => $v) {
242 if (is_array($v)) {
243 $out.=$this->extPrintFeAdminDialogHiddenFields($key.'['.$k.']',$v);
244 } else {
245 $out.='<input type="hidden" name="'.$key.'['.$k.']" value="'.htmlspecialchars($v).'">'.chr(10);
246 }
247 }
248 return $out;
249 }
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266 /*****************************************************
267 *
268 * Creating sections of the Admin Panel
269 *
270 ****************************************************/
271
272 /**
273 * Creates the content for the "preview" section ("module") of the Admin Panel
274 *
275 * @param string Optional start-value; The generated content is added to this variable.
276 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
277 * @see extPrintFeAdminDialog()
278 */
279 function extGetCategory_preview($out='') {
280 $out.=$this->extGetHead('preview');
281 if ($this->uc['TSFE_adminConfig']['display_preview']) {
282 $this->extNeedUpdate = 1;
283 $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"'.($this->uc['TSFE_adminConfig']['preview_showHiddenPages']?' checked="checked"':'').' />');
284 $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"'.($this->uc['TSFE_adminConfig']['preview_showHiddenRecords']?' checked="checked"':'').' />');
285
286 // Simulate date
287 $out.= $this->extGetItem('preview_simulateDate', '<input type="checkbox" name="TSFE_ADMIN_PANEL[preview_simulateDate]_cb" onclick="TSFEtypo3FormFieldGet(\'TSFE_ADMIN_PANEL[preview_simulateDate]\', \'datetime\', \'\',1,0,1);" /><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="'.$this->uc['TSFE_adminConfig']['preview_simulateDate'].'" />');
288 $this->extJSCODE.= 'TSFEtypo3FormFieldSet("TSFE_ADMIN_PANEL[preview_simulateDate]", "datetime", "", 1,0);';
289
290 // Simulate fe_user:
291 $options = '<option value="0"></option>';
292 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
293 'fe_groups.uid, fe_groups.title',
294 'fe_groups,pages',
295 'pages.uid=fe_groups.pid AND pages.deleted=0 '.t3lib_BEfunc::deleteClause('fe_groups').' AND '.$this->getPagePermsClause(1)
296 );
297 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
298 $options.= '<option value="'.$row['uid'].'"'.($this->uc['TSFE_adminConfig']['preview_simulateUserGroup']==$row['uid']?' selected="selected"':'').'>'.htmlspecialchars('['.$row['uid'].'] '.$row['title']).'</option>';
299 }
300 $out.= $this->extGetItem('preview_simulateUserGroup', '<select name="TSFE_ADMIN_PANEL[preview_simulateUserGroup]">'.$options.'</select>');
301 }
302 return $out;
303 }
304
305 /**
306 * Creates the content for the "cache" section ("module") of the Admin Panel
307 *
308 * @param string Optional start-value; The generated content is added to this variable.
309 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
310 * @see extPrintFeAdminDialog()
311 */
312 function extGetCategory_cache($out='') {
313 $out.=$this->extGetHead('cache');
314 if ($this->uc['TSFE_adminConfig']['display_cache']) {
315 $this->extNeedUpdate=1;
316 $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"'.($this->uc['TSFE_adminConfig']['cache_noCache']?' checked="checked"':'').' />');
317
318 $options='';
319 $options.='<option value="0"'.($this->uc['TSFE_adminConfig']['cache_clearCacheLevels']==0?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_0').'</option>';
320 $options.='<option value="1"'.($this->uc['TSFE_adminConfig']['cache_clearCacheLevels']==1?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_1').'</option>';
321 $options.='<option value="2"'.($this->uc['TSFE_adminConfig']['cache_clearCacheLevels']==2?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_2').'</option>';
322 $out.=$this->extGetItem('cache_clearLevels', '<select name="TSFE_ADMIN_PANEL[cache_clearCacheLevels]">'.$options.'</select>'.
323 '<input type="hidden" name="TSFE_ADMIN_PANEL[cache_clearCacheId]" value="'.$GLOBALS['TSFE']->id.'" /><input type="submit" value="'.$this->extGetLL('update').'" />');
324
325 // Generating tree:
326 $depth=$this->extGetFeAdminValue('cache','clearCacheLevels');
327 $outTable='';
328 $this->extPageInTreeInfo=array();
329 $this->extPageInTreeInfo[]=array($GLOBALS['TSFE']->page['uid'],$GLOBALS['TSFE']->page['title'],$depth+1);
330 $this->extGetTreeList($GLOBALS['TSFE']->id, $depth,0,$this->getPagePermsClause(1));
331 reset($this->extPageInTreeInfo);
332 while(list(,$row)=each($this->extPageInTreeInfo)) {
333 $outTable.='<tr><td nowrap="nowrap"><img src="clear.gif" width="'.(($depth+1-$row[2])*18).'" height="1" alt="" /><img src="'.TYPO3_mainDir.'gfx/i/pages.gif" width="18" height="16" align="absmiddle" border="0" alt="" />'.$this->extFw($row[1]).'</td><td><img src="clear.gif" width="10" height="1" alt="" /></td><td>'.$this->extFw($this->extGetNumberOfCachedPages($row[0])).'</td></tr>';
334 }
335 $outTable='<br /><table border="0" cellpadding="0" cellspacing="0">'.$outTable.'</table>';
336 $outTable.='<input type="submit" name="TSFE_ADMIN_PANEL[action][clearCache]" value="'.$this->extGetLL('cache_doit').'" />';
337 $out.=$this->extGetItem('cache_cacheEntries', $outTable);
338
339 }
340 return $out;
341 }
342
343 /**
344 * Creates the content for the "publish" section ("module") of the Admin Panel
345 *
346 * @param string Optional start-value; The generated content is added to this variable.
347 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
348 * @see extPrintFeAdminDialog()
349 */
350 function extGetCategory_publish($out='') {
351 $out.=$this->extGetHead('publish');
352 if ($this->uc['TSFE_adminConfig']['display_publish']) {
353 $this->extNeedUpdate=1;
354 $options='';
355 $options.='<option value="0"'.($this->uc['TSFE_adminConfig']['publish_levels']==0?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_0').'</option>';
356 $options.='<option value="1"'.($this->uc['TSFE_adminConfig']['publish_levels']==1?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_1').'</option>';
357 $options.='<option value="2"'.($this->uc['TSFE_adminConfig']['publish_levels']==2?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_2').'</option>';
358 $out.=$this->extGetItem('publish_levels', '<select name="TSFE_ADMIN_PANEL[publish_levels]">'.$options.'</select>'.
359 '<input type="hidden" name="TSFE_ADMIN_PANEL[publish_id]" value="'.$GLOBALS['TSFE']->id.'" /><input type="submit" value="'.$this->extGetLL('update').'" />');
360
361 // Generating tree:
362 $depth=$this->extGetFeAdminValue('publish','levels');
363 $outTable='';
364 $this->extPageInTreeInfo=array();
365 $this->extPageInTreeInfo[]=array($GLOBALS['TSFE']->page['uid'],$GLOBALS['TSFE']->page['title'],$depth+1);
366 $this->extGetTreeList($GLOBALS['TSFE']->id, $depth,0,$this->getPagePermsClause(1));
367 reset($this->extPageInTreeInfo);
368 while(list(,$row)=each($this->extPageInTreeInfo)) {
369 $outTable.='<tr><td nowrap="nowrap"><img src="clear.gif" width="'.(($depth+1-$row[2])*18).'" height="1" alt="" /><img src="'.TYPO3_mainDir.'gfx/i/pages.gif" width="18" height="16" align="absmiddle" border="0" alt="" />'.$this->extFw($row[1]).'</td><td><img src="clear.gif" width="10" height="1" alt="" /></td><td>'.$this->extFw('...').'</td></tr>';
370 }
371 $outTable='<br /><table border="0" cellpadding="0" cellspacing="0">'.$outTable.'</table>';
372 $outTable.='<input type="submit" name="TSFE_ADMIN_PANEL[action][publish]" value="'.$this->extGetLL('publish_doit').'" />';
373 $out.=$this->extGetItem('publish_tree', $outTable);
374 }
375 return $out;
376 }
377
378 /**
379 * Creates the content for the "edit" section ("module") of the Admin Panel
380 *
381 * @param string Optional start-value; The generated content is added to this variable.
382 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
383 * @see extPrintFeAdminDialog()
384 */
385 function extGetCategory_edit($out='') {
386 $out.=$this->extGetHead('edit');
387 if ($this->uc['TSFE_adminConfig']['display_edit']) {
388
389 // If another page module was specified, replace the default Page module with the new one
390 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
391 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
392
393 $this->extNeedUpdate=1;
394 $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"'.($this->uc['TSFE_adminConfig']['edit_displayFieldIcons']?' checked="checked"':'').' />');
395 $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"'.($this->uc['TSFE_adminConfig']['edit_displayIcons']?' checked="checked"':'').' />');
396 $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"'.($this->uc['TSFE_adminConfig']['edit_editFormsOnPage']?' checked="checked"':'').' />');
397 $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"'.($this->uc['TSFE_adminConfig']['edit_editNoPopup']?' checked="checked"':'').' />');
398
399 $out.=$this->extGetItem('', $this->ext_makeToolBar());
400 if (!t3lib_div::_GP('ADMCMD_view')) {
401 $out.=$this->extGetItem('', '<a href="#" onclick="'.
402 htmlspecialchars('
403 if (parent.opener && parent.opener.top && parent.opener.top.TS) {
404 parent.opener.top.fsMod.recentIds["web"]='.intval($GLOBALS['TSFE']->page['uid']).';
405 if (parent.opener.top.content && parent.opener.top.content.nav_frame && parent.opener.top.content.nav_frame.refresh_nav) {
406 parent.opener.top.content.nav_frame.refresh_nav();
407 }
408 parent.opener.top.goToModule("'.$pageModule.'");
409 parent.opener.top.focus();
410 } else {
411 vHWin=window.open(\''.TYPO3_mainDir.'alt_main.php\',\''.md5('Typo3Backend-'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']).'\',\'status=1,menubar=1,scrollbars=1,resizable=1\');
412 vHWin.focus();
413 }
414 return false;
415 ').
416 '">'.$this->extFw($this->extGetLL('edit_openAB')).'</a>');
417 }
418 }
419 return $out;
420 }
421
422 /**
423 * Creates the content for the "tsdebug" section ("module") of the Admin Panel
424 *
425 * @param string Optional start-value; The generated content is added to this variable.
426 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
427 * @see extPrintFeAdminDialog()
428 */
429 function extGetCategory_tsdebug($out='') {
430 $out.=$this->extGetHead('tsdebug');
431 if ($this->uc['TSFE_adminConfig']['display_tsdebug']) {
432 $this->extNeedUpdate=1;
433
434 $content='';
435 $content.=$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"'.($this->uc['TSFE_adminConfig']['tsdebug_tree']?' checked="checked"':'').' />');
436 $content.=$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"'.($this->uc['TSFE_adminConfig']['tsdebug_displayTimes']?' checked="checked"':'').' />');
437 $content.=$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"'.($this->uc['TSFE_adminConfig']['tsdebug_displayMessages']?' checked="checked"':'').' />');
438 $content.=$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"'.($this->uc['TSFE_adminConfig']['tsdebug_LR']?' checked="checked"':'').' />');
439 $content.=$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"'.($this->uc['TSFE_adminConfig']['tsdebug_displayContent']?' checked="checked"':'').' />');
440 $content.=$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"'.($this->uc['TSFE_adminConfig']['tsdebug_displayQueries']?' checked="checked"':'').' />');
441 $content.=$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"'.($this->uc['TSFE_adminConfig']['tsdebug_forceTemplateParsing']?' checked="checked"':'').' />');
442
443 $out.='<tr><td colspan="4" nowrap="nowrap"><table border="0" cellpadding="0" cellspacing="0">'.$content.'</table></td></tr>';
444
445 $GLOBALS['TT']->printConf['flag_tree'] = $this->extGetFeAdminValue('tsdebug','tree');
446 $GLOBALS['TT']->printConf['allTime'] = $this->extGetFeAdminValue('tsdebug','displayTimes');
447 $GLOBALS['TT']->printConf['flag_messages'] = $this->extGetFeAdminValue('tsdebug','displayMessages');
448 $GLOBALS['TT']->printConf['flag_content'] = $this->extGetFeAdminValue('tsdebug','displayContent');
449 $GLOBALS['TT']->printConf['flag_queries'] = $this->extGetFeAdminValue('tsdebug','displayQueries');
450 $out.='<tr><td><img src="clear.gif" width="50" height="1" alt="" /></td><td colspan="3">'.$GLOBALS['TT']->printTSlog().'</td></tr>';
451 }
452 return $out;
453 }
454
455 /**
456 * Creates the content for the "info" section ("module") of the Admin Panel
457 *
458 * @param string Optional start-value; The generated content is added to this variable.
459 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
460 * @see extPrintFeAdminDialog()
461 */
462 function extGetCategory_info($out='') {
463 $out.=$this->extGetHead('info');
464 if ($this->uc['TSFE_adminConfig']['display_info']) {
465
466 if (is_array($GLOBALS['TSFE']->imagesOnPage) && $this->extGetFeAdminValue('cache','noCache')) {
467 reset($GLOBALS['TSFE']->imagesOnPage);
468 $theBytes=0;
469 $count=0;
470 $fileTable='';
471 while(list(,$file)=each($GLOBALS['TSFE']->imagesOnPage)) {
472 $fs=@filesize($file);
473 $fileTable.='<tr><td>'.$this->extFw($file).'</td><td align="right">'.$this->extFw(t3lib_div::formatSize($fs)).'</td></tr>';
474 $theBytes+=$fs;
475 $count++;
476 }
477 $fileTable.='<tr><td><strong>'.$this->extFw('Total number of images:').'</strong></td><td>'.$this->extFw($count).'</td></tr>';
478 $fileTable.='<tr><td><strong>'.$this->extFw('Total image file sizes:').'</strong></td><td align="right">'.$this->extFw(t3lib_div::formatSize($theBytes)).'</td></tr>';
479 $fileTable.='<tr><td><strong>'.$this->extFw('Document size:').'</strong></td><td align="right">'.$this->extFw(t3lib_div::formatSize(strlen($GLOBALS['TSFE']->content))).'</td></tr>';
480 $fileTable.='<tr><td><strong>'.$this->extFw('Total page load:').'</strong></td><td align="right">'.$this->extFw(t3lib_div::formatSize(strlen($GLOBALS['TSFE']->content)+$theBytes)).'</td></tr>';
481 $fileTable.='<tr><td>&nbsp;</td></tr>';
482 }
483
484 $fileTable.='<tr><td>'.$this->extFw('id:').'</td><td>'.$this->extFw($GLOBALS['TSFE']->id).'</td></tr>';
485 $fileTable.='<tr><td>'.$this->extFw('type:').'</td><td>'.$this->extFw($GLOBALS['TSFE']->type).'</td></tr>';
486 $fileTable.='<tr><td>'.$this->extFw('gr_list:').'</td><td>'.$this->extFw($GLOBALS['TSFE']->gr_list).'</td></tr>';
487 $fileTable.='<tr><td>'.$this->extFw('no_cache:').'</td><td>'.$this->extFw($GLOBALS['TSFE']->no_cache).'</td></tr>';
488 $fileTable.='<tr><td>'.$this->extFw('fe_user, name:').'</td><td>'.$this->extFw($GLOBALS['TSFE']->fe_user->user['username']).'</td></tr>';
489 $fileTable.='<tr><td>'.$this->extFw('fe_user, uid:').'</td><td>'.$this->extFw($GLOBALS['TSFE']->fe_user->user['uid']).'</td></tr>';
490 $fileTable.='<tr><td>&nbsp;</td></tr>';
491
492 // parsetime:
493 $fileTable.='<tr><td>'.$this->extFw('Total parsetime:').'</td><td>'.$this->extFw($GLOBALS['TSFE']->scriptParseTime.' ms').'</td></tr>';
494
495 $fileTable='<table border="0" cellpadding="0" cellspacing="0">'.$fileTable.'</table>';
496
497 $out.='<tr><td><img src="clear.gif" width="50" height="1" alt="" /></td><td colspan="3">'.$fileTable.'</td></tr>';
498 }
499 return $out;
500 }
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519 /*****************************************************
520 *
521 * Admin Panel Layout Helper functions
522 *
523 ****************************************************/
524
525 /**
526 * Returns a row (with colspan=4) which is a header for a section in the Admin Panel.
527 * 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
528 * See the functions extGetCategory_*
529 *
530 * @param string The suffix to the display_ label. Also selects the label from the LOCAL_LANG array.
531 * @return string HTML table row.
532 * @access private
533 * @see extGetItem()
534 */
535 function extGetHead($pre) {
536 $out.='<img src="'.TYPO3_mainDir.'gfx/ol/blank.gif" width="18" height="16" align="absmiddle" border="0" alt="" />';
537 $out.='<img src="'.TYPO3_mainDir.'gfx/ol/'.($this->uc['TSFE_adminConfig']['display_'.$pre]?'minus':'plus').'bullet.gif" width="18" height="16" align="absmiddle" border="0" alt="" />';
538 $out.=$this->extFw($this->extGetLL($pre));
539 $out=$this->extItemLink($pre,$out);
540 return '
541 <tr class="typo3-adminPanel-itemHRow" style="background-color:#abbbb4;">
542 <td colspan="4" nowrap="nowrap" style="border-top:dashed 1px #007a8c;">'.$out.'<input type="hidden" name="TSFE_ADMIN_PANEL[display_'.$pre.']" value="'.$this->uc['TSFE_adminConfig']['display_'.$pre].'" /></td>
543 </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 The code for the display_ label/key
550 * @param string Input string
551 * @return string Linked input string
552 * @access private
553 * @see extGetHead()
554 */
555 function extItemLink($pre,$str) {
556 return '<a href="#" style="text-decoration:none;" onclick="'.
557 htmlspecialchars('document.TSFE_ADMIN_PANEL_FORM[\'TSFE_ADMIN_PANEL[display_'.$pre.']\'].value='.($this->uc['TSFE_adminConfig']['display_'.$pre]?'0':'1').'; document.TSFE_ADMIN_PANEL_FORM.submit(); return false;').
558 '">'.$str.'</a>';
559 }
560
561 /**
562 * Returns a row (with 4 columns) for content in a section of the Admin Panel.
563 * It will take $pre as a key to a label to display and $element as the content to put into the forth cell.
564 *
565 * @param string Key to label
566 * @param string The HTML content for the forth table cell.
567 * @return string HTML table row.
568 * @access private
569 * @see extGetHead()
570 */
571 function extGetItem($pre,$element) {
572 return '
573 <tr class="typo3-adminPanel-itemRow">
574 <td><img src="clear.gif" width="50" height="1" alt="" /></td>
575 <td nowrap="nowrap">'.($pre ? $this->extFw($this->extGetLL($pre)) : '&nbsp;').'</td>
576 <td><img src="clear.gif" width="40" height="1" alt="" /></td>
577 <td>'.$element.'</td>
578 </tr>';
579
580 }
581
582 /**
583 * Wraps a string in a font-tag with verdana, size 1 and black
584 *
585 * @param string The string to wrap
586 * @return string
587 */
588 function extFw($str) {
589 return '<font face="verdana,arial" size="1" color="black">'.$str.'</font>';
590 }
591
592 /**
593 * Creates the tool bar links for the "edit" section of the Admin Panel.
594 *
595 * @return string A string containing images wrapped in <a>-tags linking them to proper functions.
596 */
597 function ext_makeToolBar() {
598 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
599 $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
600 $tmpTSc = $tmpTSc ['properties']['newContentWiz.']['overrideWithExtension'];
601 $newContentWizScriptPath = t3lib_extMgm::isLoaded($tmpTSc) ? (t3lib_extMgm::extRelPath($tmpTSc).'mod1/db_new_content_el.php') : (TYPO3_mainDir.'sysext/cms/layout/db_new_content_el.php');
602
603
604 $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
605 $langAllowed = $GLOBALS['BE_USER']->checkLanguageAccess($GLOBALS['TSFE']->sys_language_uid);
606
607 $toolBar='';
608 $id = $GLOBALS['TSFE']->id;
609 $toolBar.='<a href="'.htmlspecialchars(TYPO3_mainDir.'show_rechis.php?element='.rawurlencode('pages:'.$id).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'#latest">'.
610 '<img src="'.TYPO3_mainDir.'gfx/history2.gif" width="13" height="12" hspace="2" border="0" align="top" title="'.$this->extGetLL('edit_recordHistory').'" alt="" /></a>';
611
612 if ($perms&16 && $langAllowed) {
613 $params = '';
614 if ($GLOBALS['TSFE']->sys_language_uid) $params = '&sys_language_uid='.$GLOBALS['TSFE']->sys_language_uid;
615 $toolBar.='<a href="'.htmlspecialchars($newContentWizScriptPath.'?id='.$id.$params.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
616 '<img src="'.TYPO3_mainDir.'gfx/new_record.gif" width="16" height="12" hspace="1" border="0" align="top" title="'.$this->extGetLL('edit_newContentElement').'" alt="" /></a>';
617 }
618 if ($perms&2) {
619 $toolBar.='<a href="'.htmlspecialchars(TYPO3_mainDir.'move_el.php?table=pages&uid='.$id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
620 '<img src="'.TYPO3_mainDir.'gfx/move_page.gif" width="11" height="12" hspace="2" border="0" align="top" title="'.$this->extGetLL('edit_move_page').'" alt="" /></a>';
621 }
622 if ($perms&8) {
623 $toolBar.='<a href="'.htmlspecialchars(TYPO3_mainDir.'db_new.php?id='.$id.'&pagesOnly=1&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
624 '<img src="'.TYPO3_mainDir.'gfx/new_page.gif" width="13" height="12" hspace="0" border="0" align="top" title="'.$this->extGetLL('edit_newPage').'" alt="" /></a>';
625 }
626 if ($perms&2) {
627 $params='&edit[pages]['.$id.']=edit';
628 $toolBar.='<a href="'.htmlspecialchars(TYPO3_mainDir.'alt_doc.php?'.$params.'&noView=1&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
629 '<img src="'.TYPO3_mainDir.'gfx/edit2.gif" width="11" height="12" hspace="2" border="0" align="top" title="'.$this->extGetLL('edit_editPageProperties').'" alt="" /></a>';
630 }
631 if ($this->check('modules','web_list')) {
632 $toolBar.='<a href="'.htmlspecialchars(TYPO3_mainDir.'db_list.php?id='.$id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
633 '<img src="'.TYPO3_mainDir.'gfx/list.gif" width="11" height="11" hspace="2" border="0" align="top" title="'.$this->extGetLL('edit_db_list').'" alt="" /></a>';
634 }
635 return $toolBar;
636 }
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656 /*****************************************************
657 *
658 * TSFE BE user Access Functions
659 *
660 ****************************************************/
661
662 /**
663 * Implementing the access checks that the typo3/init.php script does before a user is ever logged in.
664 * Used in the frontend.
665 *
666 * @return boolean Returns true if access is OK
667 * @see typo3/init.php, t3lib_beuserauth::backendCheckLogin()
668 */
669 function checkBackendAccessSettingsFromInitPhp() {
670 global $TYPO3_CONF_VARS;
671
672 // **********************
673 // Check Hardcoded lock on BE:
674 // **********************
675 if ($TYPO3_CONF_VARS['BE']['adminOnly'] < 0) {
676 return FALSE;
677 }
678
679 // **********************
680 // Check IP
681 // **********************
682 if (trim($TYPO3_CONF_VARS['BE']['IPmaskList'])) {
683 if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['BE']['IPmaskList'])) {
684 return FALSE;
685 }
686 }
687
688
689 // **********************
690 // Check SSL (https)
691 // **********************
692 if (intval($TYPO3_CONF_VARS['BE']['lockSSL']) && $TYPO3_CONF_VARS['BE']['lockSSL'] != 3) {
693 if (!t3lib_div::getIndpEnv('TYPO3_SSL')) {
694 return FALSE;
695 }
696 }
697
698 // Finally a check from t3lib_beuserauth::backendCheckLogin()
699 if (!$TYPO3_CONF_VARS['BE']['adminOnly'] || $this->isAdmin()) {
700 return TRUE;
701 } else return FALSE;
702 }
703
704
705 /**
706 * Evaluates if the Backend User has read access to the input page record.
707 * The evaluation is based on both read-permission and whether the page is found in one of the users webmounts. Only if both conditions are true will the function return true.
708 * Read access means that previewing is allowed etc.
709 * Used in index_ts.php
710 *
711 * @param array The page record to evaluate for
712 * @return boolean True if read access
713 */
714 function extPageReadAccess($pageRec) {
715 return $this->isInWebMount($pageRec['uid']) && $this->doesUserHaveAccess($pageRec,1);
716 }
717
718 /**
719 * Checks if a Admin Panel section ("module") is available for the user. If so, true is returned.
720 *
721 * @param string The module key, eg. "edit", "preview", "info" etc.
722 * @return boolean
723 * @see extPrintFeAdminDialog()
724 */
725 function extAdmModuleEnabled($key) {
726 // Returns true if the module checked is "preview" and the forcePreview flag is set.
727 if ($key=="preview" && $this->ext_forcePreview) return true;
728 // If key is not set, only "all" is checked
729 if ($this->extAdminConfig['enable.']['all']) return true;
730 if ($this->extAdminConfig['enable.'][$key]) {
731 return true;
732 }
733 }
734
735 /**
736 * Saves any change in settings made in the Admin Panel.
737 * Called from index_ts.php right after access check for the Admin Panel
738 *
739 * @return void
740 */
741 function extSaveFeAdminConfig() {
742 $input = t3lib_div::_GET('TSFE_ADMIN_PANEL');
743 if (is_array($input)) {
744 // Setting
745 $this->uc['TSFE_adminConfig'] = array_merge(!is_array($this->uc['TSFE_adminConfig'])?array():$this->uc['TSFE_adminConfig'], $input); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
746 unset($this->uc['TSFE_adminConfig']['action']);
747
748 // Actions:
749 if ($input['action']['clearCache'] && $this->extAdmModuleEnabled('cache')) {
750 $this->extPageInTreeInfo=array();
751 $theStartId = intval($input['cache_clearCacheId']);
752 $GLOBALS['TSFE']->clearPageCacheContent_pidList($this->extGetTreeList($theStartId, $this->extGetFeAdminValue('cache','clearCacheLevels'),0,$this->getPagePermsClause(1)).$theStartId);
753 }
754 if ($input['action']['publish'] && $this->extAdmModuleEnabled('publish')) {
755 $theStartId = intval($input['publish_id']);
756 $this->extPublishList = $this->extGetTreeList($theStartId, $this->extGetFeAdminValue('publish','levels'),0,$this->getPagePermsClause(1)).$theStartId;
757 }
758
759 // Saving
760 $this->writeUC();
761 }
762 $GLOBALS['TT']->LR = $this->extGetFeAdminValue('tsdebug','LR');
763 if ($this->extGetFeAdminValue('cache','noCache')) {$GLOBALS['TSFE']->set_no_cache();}
764 }
765
766 /**
767 * Returns the value for a Admin Panel setting. You must specify both the module-key and the internal setting key.
768 *
769 * @param string Module key
770 * @param string Setting key
771 * @return string The setting value
772 */
773 function extGetFeAdminValue($pre,$val='') {
774 if ($this->extAdmModuleEnabled($pre)) { // Check if module is enabled.
775 // Exceptions where the values can be overridden from backend:
776 // deprecated
777 if ($pre.'_'.$val == 'edit_displayIcons' && $this->extAdminConfig['module.']['edit.']['forceDisplayIcons']) {
778 return true;
779 }
780 if ($pre.'_'.$val == 'edit_displayFieldIcons' && $this->extAdminConfig['module.']['edit.']['forceDisplayFieldIcons']) {
781 return true;
782 }
783
784 // override all settings with user TSconfig
785 if ($this->extAdminConfig['override.'][$pre.'.'][$val] && $val) {
786 return $this->extAdminConfig['override.'][$pre.'.'][$val];
787 }
788 if ($this->extAdminConfig['override.'][$pre]) {
789 return $this->extAdminConfig['override.'][$pre];
790 }
791
792 $retVal = $val ? $this->uc['TSFE_adminConfig'][$pre.'_'.$val] : 1;
793
794 if ($pre=='preview' && $this->ext_forcePreview) {
795 if (!$val) {
796 return true;
797 } else {
798 return $retVal;
799 }
800 }
801
802 // regular check:
803 if ($this->extIsAdmMenuOpen($pre)) { // See if the menu is expanded!
804 return $retVal;
805 }
806 }
807 }
808
809 /**
810 * Returns true if admin panel module is open
811 *
812 * @param string Module key
813 * @return boolean True, if the admin panel is open for the specified admin panel module key.
814 */
815 function extIsAdmMenuOpen($pre) {
816 return $this->uc['TSFE_adminConfig']['display_top'] && $this->uc['TSFE_adminConfig']['display_'.$pre];
817 }
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834 /*****************************************************
835 *
836 * TSFE BE user Access Functions
837 *
838 ****************************************************/
839
840 /**
841 * Generates a list of Page-uid's from $id. List does not include $id itself
842 * The only pages excluded from the list are deleted pages.
843 *
844 * @param integer Start page id
845 * @param integer Depth to traverse down the page tree.
846 * @param integer $begin is an optional integer that determines at which level in the tree to start collecting uid's. Zero means 'start right away', 1 = 'next level and out'
847 * @param string Perms clause
848 * @return string Returns the list with a comma in the end (if any pages selected!)
849 */
850 function extGetTreeList($id,$depth,$begin=0,$perms_clause) {
851 $depth=intval($depth);
852 $begin=intval($begin);
853 $id=intval($id);
854 $theList='';
855
856 if ($id && $depth>0) {
857 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
858 'uid,title',
859 'pages',
860 'pid='.$id.' AND doktype IN ('.$GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'].') AND deleted=0 AND '.$perms_clause
861 );
862 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
863 if ($begin<=0) {
864 $theList.=$row['uid'].',';
865 $this->extPageInTreeInfo[]=array($row['uid'],$row['title'],$depth);
866 }
867 if ($depth>1) {
868 $theList.=$this->extGetTreeList($row['uid'], $depth-1,$begin-1,$perms_clause);
869 }
870 }
871 }
872 return $theList;
873 }
874
875 /**
876 * Returns the number of cached pages for a page id.
877 *
878 * @param integer The page id.
879 * @return integer The number of pages for this page in the table "cache_pages"
880 */
881 function extGetNumberOfCachedPages($page_id) {
882 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_pages', 'page_id='.intval($page_id));
883 list($num) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
884 return $num;
885 }
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907 /*****************************************************
908 *
909 * Localization handling
910 *
911 ****************************************************/
912
913 /**
914 * Returns the label for key, $key. If a translation for the language set in $this->uc['lang'] is found that is returned, otherwise the default value.
915 * 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.php" so that the values therein can be used for labels in the Admin Panel
916 *
917 * @param string Key for a label in the $LOCAL_LANG array of "sysext/lang/locallang_tsfe.php"
918 * @return string The value for the $key
919 */
920 function extGetLL($key) {
921 global $LOCAL_LANG;
922 if (!is_array($LOCAL_LANG)) {
923 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_tsfe.php');
924 #include('./'.TYPO3_mainDir.'sysext/lang/locallang_tsfe.php');
925 if (!is_array($LOCAL_LANG)) $LOCAL_LANG=array();
926 }
927
928 $labelStr = htmlspecialchars($GLOBALS['LANG']->getLL($key)); // Label string in the default backend output charset.
929
930 // Convert to utf-8, then to entities:
931 if ($GLOBALS['LANG']->charSet!='utf-8') {
932 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_encode($labelStr,$GLOBALS['LANG']->charSet);
933 }
934 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_to_entities($labelStr);
935
936 // Return the result:
937 return $labelStr;
938 }
939
940
941
942
943
944
945
946
947
948
949
950
951
952 /*****************************************************
953 *
954 * Frontend Editing
955 *
956 ****************************************************/
957
958 /**
959 * Returns true in an edit-action is sent from the Admin Panel
960 *
961 * @return boolean
962 * @see index_ts.php
963 */
964 function extIsEditAction() {
965 if (is_array($this->TSFE_EDIT)) {
966 if ($this->TSFE_EDIT['cancel']) {
967 unset($this->TSFE_EDIT['cmd']);
968 } else {
969 $cmd = (string)$this->TSFE_EDIT['cmd'];
970 if (($cmd!='edit' || (is_array($this->TSFE_EDIT['data']) && ($this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']))) && $cmd!='new') {
971 // $cmd can be a command like "hide" or "move". If $cmd is "edit" or "new" it's an indication to show the formfields. But if data is sent with update-flag then $cmd = edit is accepted because edit may be sendt because of .keepGoing flag.
972 return true;
973 }
974 }
975 }
976 return false;
977 }
978
979 /**
980 * Returns true if an edit form is shown on the page.
981 * Used from index_ts.php where a true return-value will result in classes etc. being included.
982 *
983 * @return boolean
984 * @see index_ts.php
985 */
986 function extIsFormShown() {
987 if (is_array($this->TSFE_EDIT)) {
988 $cmd=(string)$this->TSFE_EDIT['cmd'];
989 if ($cmd=='edit' || $cmd=='new') {
990 return true;
991 }
992 }
993 }
994
995 /**
996 * Management of the on-page frontend editing forms and edit panels.
997 * Basically taking in the data and commands and passes them on to the proper classes as they should be.
998 *
999 * @return void
1000 * @see index_ts.php
1001 */
1002 function extEditAction() {
1003 global $TCA, $TYPO3_CONF_VARS;
1004 // Commands:
1005 list($table,$uid) = explode(':',$this->TSFE_EDIT['record']);
1006 if ($this->TSFE_EDIT['cmd'] && $table && $uid && isset($TCA[$table])) {
1007 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
1008 $tce->stripslashes_values=0;
1009 $recData=array();
1010 $cmdData=array();
1011 $cmd=$this->TSFE_EDIT['cmd'];
1012
1013 // ****************
1014 // extEditAction HOOK
1015 // ****************
1016 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction'])) {
1017 $_params = array();
1018 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction'] as $_funcRef) {
1019 t3lib_div::callUserFunction($_funcRef,$_params,$this);
1020 }
1021 }
1022
1023 switch($cmd) {
1024 case 'hide':
1025 case 'unhide':
1026 $hideField = $TCA[$table]['ctrl']['enablecolumns']['disabled'];
1027 if ($hideField) {
1028 $recData[$table][$uid][$hideField]=($cmd=='hide'?1:0);
1029 $tce->start($recData,Array());
1030 $tce->process_datamap();
1031 }
1032 break;
1033 case 'up':
1034 case 'down':
1035 $sortField = $TCA[$table]['ctrl']['sortby'];
1036 if ($sortField) {
1037 if ($cmd=='up') {
1038 $op= '<';
1039 $desc=' DESC';
1040 } else {
1041 $op= '>';
1042 $desc='';
1043 }
1044 // Get self:
1045 $fields = array_unique(t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['copyAfterDuplFields'].',uid,pid,'.$sortField,1));
1046 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',',$fields), $table, 'uid='.$uid);
1047 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1048 // record before or after
1049 $preview = $this->extGetFeAdminValue('preview');
1050 $copyAfterFieldsQuery = '';
1051 if ($preview) {$ignore = array('starttime'=>1, 'endtime'=>1, 'disabled'=>1, 'fe_group'=>1);}
1052 if ($TCA[$table]['ctrl']['copyAfterDuplFields']) {
1053 $cAFields = t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['copyAfterDuplFields'],1);
1054 while(list(,$fN)=each($cAFields)) {
1055 $copyAfterFieldsQuery.=' AND '.$fN.'="'.$row[$fN].'"';
1056 }
1057 }
1058
1059 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1060 'uid,pid',
1061 $table,
1062 'pid='.intval($row['pid']).
1063 ' AND '.$sortField.$op.intval($row[$sortField]).
1064 $copyAfterFieldsQuery.
1065 t3lib_pageSelect::enableFields($table,'',$ignore),
1066 '',
1067 $sortField.$desc,
1068 '2'
1069 );
1070 if ($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1071 if($cmd=='down') {
1072 $cmdData[$table][$uid]['move']= -$row2['uid'];
1073 } elseif ($row3 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // Must take the second record above...
1074 $cmdData[$table][$uid]['move']= -$row3['uid'];
1075 } else { // ... and if that does not exist, use pid
1076 $cmdData[$table][$uid]['move']= $row['pid'];
1077 }
1078 } elseif ($cmd=='up') {
1079 $cmdData[$table][$uid]['move']= $row['pid'];
1080 }
1081 }
1082 if (count($cmdData)) {
1083 $tce->start(Array(),$cmdData);
1084 $tce->process_cmdmap();
1085 }
1086 }
1087 break;
1088 case 'delete':
1089 $cmdData[$table][$uid]['delete']= 1;
1090 if (count($cmdData)) {
1091 $tce->start(Array(),$cmdData);
1092 $tce->process_cmdmap();
1093 }
1094 break;
1095 }
1096 }
1097 // Data:
1098 if (($this->TSFE_EDIT['doSave'] || $this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']) && is_array($this->TSFE_EDIT['data'])) {
1099 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
1100 $tce->stripslashes_values=0;
1101 $tce->start($this->TSFE_EDIT['data'],Array());
1102 $tce->process_uploads($_FILES);
1103 $tce->process_datamap();
1104 }
1105 }
1106 }
1107
1108
1109 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsfebeuserauth.php']) {
1110 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsfebeuserauth.php']);
1111 }
1112 ?>