* Various improvements to the admin panel:
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsfebeuserauth.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2007 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 $row = '<img src="'.TYPO3_mainDir.'gfx/ol/blank.gif" width="18" height="16" align="absmiddle" border="0" alt="" />';
166 $row.= '<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="" />';
167 $row.= '<strong>'.$this->extFw($this->extGetLL('adminOptions')).'</strong>';
168 $row.= $this->extFw(': '.$this->user['username']);
169
170 $header='
171 <tr class="typo3-adminPanel-hRow" style="background-color:#9ba1a8;">
172 <td colspan="4" style="text-align:left; white-space:nowrap;">'.
173 $this->extItemLink('top',$row).'
174 <img src="clear.gif" width="40" height="1" alt="" />
175 <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>
176 </tr>';
177
178 $query = !t3lib_div::_GET('id') ? ('<input type="hidden" name="id" value="'.$GLOBALS['TSFE']->id.'" />'.chr(10)) : '';
179 // the dummy field is needed for Firefox: to force a page reload on submit with must change the form value with JavaScript (see "onsubmit" attribute of the "form" element")
180 $query.= '<input type="hidden" name="TSFE_ADMIN_PANEL[DUMMY]" value="">';
181 foreach (t3lib_div::_GET() as $k => $v) {
182 if ($k != 'TSFE_ADMIN_PANEL') {
183 if (is_array($v)) {
184 $query.= $this->extPrintFeAdminDialogHiddenFields($k,$v);
185 } else {
186 $query.= '<input type="hidden" name="'.$k.'" value="'.htmlspecialchars($v).'">'.chr(10);
187 }
188 }
189 }
190
191 $out = '
192 <!--
193 ADMIN PANEL
194 -->
195 <a name="TSFE_ADMIN"></a>
196 <form name="TSFE_ADMIN_PANEL_FORM" action="'.htmlspecialchars(t3lib_div::getIndpEnv('SCRIPT_NAME')).'#TSFE_ADMIN" method="get" style="margin:0;" onsubmit="document.forms.TSFE_ADMIN_PANEL_FORM[\'TSFE_ADMIN_PANEL[DUMMY]\'].value=Math.random().toString().substring(2,8)">'.
197 $query.'
198 <table border="0" cellpadding="0" cellspacing="0" class="typo3-adminPanel" style="background-color:#f6f2e6; border: 1px solid black; z-index:0; position:absolute;">'.
199 $header.
200 $out.'
201 </table>
202 </form>';
203
204 if ($this->uc['TSFE_adminConfig']['display_top']) {
205 $out.= '<script type="text/javascript" src="t3lib/jsfunc.evalfield.js"></script>';
206 $out.= '
207 <script type="text/javascript">
208 /*<![CDATA[*/
209 var evalFunc = new evalFunc();
210 // TSFEtypo3FormFieldSet()
211 function TSFEtypo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue) { //
212 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
213 var theValue = document.TSFE_ADMIN_PANEL_FORM[theField].value;
214 if (checkbox && theValue==checkboxValue) {
215 document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value="";
216 document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"].checked = "";
217 } else {
218 document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue);
219 document.TSFE_ADMIN_PANEL_FORM[theField+"_cb"].checked = "on";
220 }
221 }
222 // TSFEtypo3FormFieldGet()
223 function TSFEtypo3FormFieldGet(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off) { //
224 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
225 if (checkbox_off) {
226 document.TSFE_ADMIN_PANEL_FORM[theField].value=checkboxValue;
227 }else{
228 document.TSFE_ADMIN_PANEL_FORM[theField].value = evalFunc.evalObjValue(theFObj, document.TSFE_ADMIN_PANEL_FORM[theField+"_hr"].value);
229 }
230 TSFEtypo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue);
231 }
232 /*]]>*/
233 </script>
234 <script language="javascript" type="text/javascript">'.$this->extJSCODE.'</script>';
235 }
236 return "\n\n\n\n".$out.'<br />';
237 }
238
239 /**
240 * Fetches recursively all GET parameters as hidden fields.
241 * Called from extPrintFeAdminDialog.
242 *
243 * @param string current key
244 * @param mixed current value
245 * @return string hidden fields
246 * @see extPrintFeAdminDialog()
247 */
248 function extPrintFeAdminDialogHiddenFields($key,&$val) {
249 $out = '';
250 foreach($val as $k => $v) {
251 if (is_array($v)) {
252 $out.= $this->extPrintFeAdminDialogHiddenFields($key.'['.$k.']',$v);
253 } else {
254 $out.= '<input type="hidden" name="'.$key.'['.$k.']" value="'.htmlspecialchars($v).'">'.chr(10);
255 }
256 }
257 return $out;
258 }
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275 /*****************************************************
276 *
277 * Creating sections of the Admin Panel
278 *
279 ****************************************************/
280
281 /**
282 * Creates the content for the "preview" section ("module") of the Admin Panel
283 *
284 * @param string Optional start-value; The generated content is added to this variable.
285 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
286 * @see extPrintFeAdminDialog()
287 */
288 function extGetCategory_preview($out='') {
289 $out.= $this->extGetHead('preview');
290 if ($this->uc['TSFE_adminConfig']['display_preview']) {
291 $this->extNeedUpdate = 1;
292 $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"':'').' />', 'left');
293 $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"':'').' />', 'left');
294
295 // Simulate date
296 $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'].'" />', 'left');
297 $this->extJSCODE.= 'TSFEtypo3FormFieldSet("TSFE_ADMIN_PANEL[preview_simulateDate]", "datetime", "", 1,0);';
298
299 // Simulate fe_user:
300 $options = '<option value="0"></option>';
301 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
302 'fe_groups.uid, fe_groups.title',
303 'fe_groups,pages',
304 'pages.uid=fe_groups.pid AND pages.deleted=0 '.t3lib_BEfunc::deleteClause('fe_groups').' AND '.$this->getPagePermsClause(1)
305 );
306 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
307 $options.= '<option value="'.$row['uid'].'"'.($this->uc['TSFE_adminConfig']['preview_simulateUserGroup']==$row['uid']?' selected="selected"':'').'>'.htmlspecialchars('['.$row['uid'].'] '.$row['title']).'</option>';
308 }
309 $out.= $this->extGetItem('preview_simulateUserGroup', '<select name="TSFE_ADMIN_PANEL[preview_simulateUserGroup]">'.$options.'</select>', 'left');
310 }
311 return $out;
312 }
313
314 /**
315 * Creates the content for the "cache" section ("module") of the Admin Panel
316 *
317 * @param string Optional start-value; The generated content is added to this variable.
318 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
319 * @see extPrintFeAdminDialog()
320 */
321 function extGetCategory_cache($out='') {
322 $out.= $this->extGetHead('cache');
323 if ($this->uc['TSFE_adminConfig']['display_cache']) {
324 $this->extNeedUpdate = 1;
325 $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"':'').' />');
326
327 $options = '';
328 $options.= '<option value="0"'.($this->uc['TSFE_adminConfig']['cache_clearCacheLevels']==0?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_0').'</option>';
329 $options.= '<option value="1"'.($this->uc['TSFE_adminConfig']['cache_clearCacheLevels']==1?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_1').'</option>';
330 $options.= '<option value="2"'.($this->uc['TSFE_adminConfig']['cache_clearCacheLevels']==2?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_2').'</option>';
331
332 $out.= $this->extGetItem('cache_clearLevels', '<select name="TSFE_ADMIN_PANEL[cache_clearCacheLevels]">'.$options.'</select>'.
333 '<input type="hidden" name="TSFE_ADMIN_PANEL[cache_clearCacheId]" value="'.$GLOBALS['TSFE']->id.'" /><input type="submit" value="'.$this->extGetLL('update').'" />');
334
335 // Generating tree:
336 $depth = $this->extGetFeAdminValue('cache','clearCacheLevels');
337 $outTable = '';
338 $this->extPageInTreeInfo = array();
339 $this->extPageInTreeInfo[] = array($GLOBALS['TSFE']->page['uid'],$GLOBALS['TSFE']->page['title'],$depth+1);
340 $this->extGetTreeList($GLOBALS['TSFE']->id, $depth,0,$this->getPagePermsClause(1));
341 reset($this->extPageInTreeInfo);
342 while(list(,$row)=each($this->extPageInTreeInfo)) {
343 $outTable.= '
344 <tr>
345 <td style="white-space: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>
346 <td><img src="clear.gif" width="10" height="1" alt="" /></td>
347 <td>'.$this->extFw($this->extGetNumberOfCachedPages($row[0])).'</td>
348 </tr>';
349 }
350 $outTable = '<br /><table border="0" cellpadding="0" cellspacing="0">'.$outTable.'</table>';
351 $outTable.= '<input type="submit" name="TSFE_ADMIN_PANEL[action][clearCache]" value="'.$this->extGetLL('cache_doit').'" />';
352
353 $out.= $this->extGetItem('cache_cacheEntries', $outTable);
354 }
355 return $out;
356 }
357
358 /**
359 * Creates the content for the "publish" section ("module") of the Admin Panel
360 *
361 * @param string Optional start-value; The generated content is added to this variable.
362 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
363 * @see extPrintFeAdminDialog()
364 */
365 function extGetCategory_publish($out='') {
366 $out.= $this->extGetHead('publish');
367 if ($this->uc['TSFE_adminConfig']['display_publish']) {
368 $this->extNeedUpdate = 1;
369 $options = '';
370 $options.= '<option value="0"'.($this->uc['TSFE_adminConfig']['publish_levels']==0?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_0').'</option>';
371 $options.= '<option value="1"'.($this->uc['TSFE_adminConfig']['publish_levels']==1?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_1').'</option>';
372 $options.= '<option value="2"'.($this->uc['TSFE_adminConfig']['publish_levels']==2?' selected="selected"':'').'>'.$this->extGetLL('div_Levels_2').'</option>';
373 $out.= $this->extGetItem('publish_levels', '<select name="TSFE_ADMIN_PANEL[publish_levels]">'.$options.'</select>'.
374 '<input type="hidden" name="TSFE_ADMIN_PANEL[publish_id]" value="'.$GLOBALS['TSFE']->id.'" />&nbsp;<input type="submit" value="'.$this->extGetLL('update').'" />');
375
376 // Generating tree:
377 $depth = $this->extGetFeAdminValue('publish','levels');
378 $outTable = '';
379 $this->extPageInTreeInfo = array();
380 $this->extPageInTreeInfo[] = array($GLOBALS['TSFE']->page['uid'],$GLOBALS['TSFE']->page['title'],$depth+1);
381 $this->extGetTreeList($GLOBALS['TSFE']->id, $depth,0,$this->getPagePermsClause(1));
382 reset($this->extPageInTreeInfo);
383 while(list(,$row)=each($this->extPageInTreeInfo)) {
384 $outTable.= '
385 <tr>
386 <td style="white-space: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>
387 <td><img src="clear.gif" width="10" height="1" alt="" /></td>
388 <td>'.$this->extFw('...').'</td>
389 </tr>';
390 }
391 $outTable = '<br /><table border="0" cellpadding="0" cellspacing="0">'.$outTable.'</table>';
392 $outTable.= '&nbsp;<input type="submit" name="TSFE_ADMIN_PANEL[action][publish]" value="'.$this->extGetLL('publish_doit').'" />';
393
394 $out.= $this->extGetItem('publish_tree', $outTable);
395 }
396 return $out;
397 }
398
399 /**
400 * Creates the content for the "edit" section ("module") of the Admin Panel
401 *
402 * @param string Optional start-value; The generated content is added to this variable.
403 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
404 * @see extPrintFeAdminDialog()
405 */
406 function extGetCategory_edit($out='') {
407 $out.= $this->extGetHead('edit');
408 if ($this->uc['TSFE_adminConfig']['display_edit']) {
409
410 // If another page module was specified, replace the default Page module with the new one
411 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
412 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
413
414 $this->extNeedUpdate = 1;
415 $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"':'').' />');
416 $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"':'').' />');
417 $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"':'').' />');
418 $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"':'').' />');
419 $out.= $this->extGetItem('', $this->ext_makeToolBar());
420
421 if (!t3lib_div::_GP('ADMCMD_view')) {
422 $out.= $this->extGetItem('', '<a href="#" onclick="'.
423 htmlspecialchars('
424 if (parent.opener && parent.opener.top && parent.opener.top.TS) {
425 parent.opener.top.fsMod.recentIds["web"]='.intval($GLOBALS['TSFE']->page['uid']).';
426 if (parent.opener.top.content && parent.opener.top.content.nav_frame && parent.opener.top.content.nav_frame.refresh_nav) {
427 parent.opener.top.content.nav_frame.refresh_nav();
428 }
429 parent.opener.top.goToModule("'.$pageModule.'");
430 parent.opener.top.focus();
431 } else {
432 vHWin=window.open(\''.TYPO3_mainDir.'alt_main.php\',\''.md5('Typo3Backend-'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']).'\',\'status=1,menubar=1,scrollbars=1,resizable=1\');
433 vHWin.focus();
434 }
435 return false;
436 ').
437 '">'.$this->extFw($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 * @param string Optional start-value; The generated content is added to this variable.
447 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
448 * @see extPrintFeAdminDialog()
449 */
450 function extGetCategory_tsdebug($out='') {
451 $out.= $this->extGetHead('tsdebug');
452 if ($this->uc['TSFE_adminConfig']['display_tsdebug']) {
453 $this->extNeedUpdate = 1;
454
455 $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"':'').' />');
456 $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"':'').' />');
457 $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"':'').' />');
458 $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"':'').' />');
459 $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"':'').' />');
460 $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"':'').' />');
461 $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"':'').' />');
462
463 $out.= '
464 <tr>
465 <td colspan="4"><table border="0" cellpadding="0" cellspacing="0">'.$content.'</table></td>
466 </tr>';
467
468 $GLOBALS['TT']->printConf['flag_tree'] = $this->extGetFeAdminValue('tsdebug','tree');
469 $GLOBALS['TT']->printConf['allTime'] = $this->extGetFeAdminValue('tsdebug','displayTimes');
470 $GLOBALS['TT']->printConf['flag_messages'] = $this->extGetFeAdminValue('tsdebug','displayMessages');
471 $GLOBALS['TT']->printConf['flag_content'] = $this->extGetFeAdminValue('tsdebug','displayContent');
472 $GLOBALS['TT']->printConf['flag_queries'] = $this->extGetFeAdminValue('tsdebug','displayQueries');
473
474 $out.= '
475 <tr>
476 <td><img src="clear.gif" width="50" height="1" alt="" /></td>
477 <td colspan="3">'.$GLOBALS['TT']->printTSlog().'</td>
478 </tr>';
479 }
480 return $out;
481 }
482
483 /**
484 * Creates the content for the "info" section ("module") of the Admin Panel
485 *
486 * @param string Optional start-value; The generated content is added to this variable.
487 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
488 * @see extPrintFeAdminDialog()
489 */
490 function extGetCategory_info($out='') {
491 $out.= $this->extGetHead('info');
492 if ($this->uc['TSFE_adminConfig']['display_info']) {
493 $tableArr = array();
494
495 if ($this->extGetFeAdminValue('cache','noCache')) {
496 $theBytes = 0;
497 $count = 0;
498
499 if (count($GLOBALS['TSFE']->imagesOnPage)) {
500 $tableArr[] = array('*Images on this page:*', '');
501 foreach ($GLOBALS['TSFE']->imagesOnPage as $file) {
502 $fs = @filesize($file);
503 $tableArr[] = array('&ndash; '.$file, t3lib_div::formatSize($fs));
504 $theBytes+= $fs;
505 $count++;
506 }
507 }
508 $tableArr[] = array('', ''); // Add an empty line
509
510 $tableArr[] = array('*Total number of images:*', $count);
511 $tableArr[] = array('*Total image file sizes:*', t3lib_div::formatSize($theBytes));
512 $tableArr[] = array('*Document size:*', t3lib_div::formatSize(strlen($GLOBALS['TSFE']->content)));
513 $tableArr[] = array('*Total page load:*', t3lib_div::formatSize(strlen($GLOBALS['TSFE']->content)+$theBytes));
514 $tableArr[] = array('', '');
515 }
516
517 $tableArr[] = array('id:', $GLOBALS['TSFE']->id);
518 $tableArr[] = array('type:', $GLOBALS['TSFE']->type);
519 $tableArr[] = array('gr_list:', $GLOBALS['TSFE']->gr_list);
520 $tableArr[] = array('no_cache:', $GLOBALS['TSFE']->no_cache);
521 $tableArr[] = array('fe_user, name:', $GLOBALS['TSFE']->fe_user->user['username']);
522 $tableArr[] = array('fe_user, uid:', $GLOBALS['TSFE']->fe_user->user['uid']);
523 $tableArr[] = array('', ''); // Add an empty line
524
525 // parsetime:
526 $tableArr[] = array('*Total parsetime:*', $GLOBALS['TSFE']->scriptParseTime.' ms');
527
528 $table = '';
529 foreach ($tableArr as $arr) {
530 if (strlen($arr[0])) { // Put text wrapped by "*" between <strong> tags
531 $value1 = preg_replace('/^\*(.*)\*$/', '$1', $arr[0], -1, $count);
532 $value1 = ($count?'<strong>':'') . $this->extFw($value1) . ($count?'</strong>':'');
533 } else {
534 $value1 = $this->extFw('&nbsp;');
535 }
536
537 $value2 = strlen($arr[1]) ? $arr[1] : '&nbsp;';
538 $value2 = $this->extFw($value2);
539
540 $table.= '
541 <tr>
542 <td style="text-align:left">'.$value1.'</td>
543 <td style="text-align:right">'.$value2.'</td>
544 </tr>';
545 }
546
547 $table = '<table border="0" cellpadding="0" cellspacing="0">'.$table.'</table>';
548
549 $out.= '<tr><td><img src="clear.gif" width="50" height="1" alt="" /></td><td colspan="3">'.$table.'</td></tr>';
550 }
551 return $out;
552 }
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571 /*****************************************************
572 *
573 * Admin Panel Layout Helper functions
574 *
575 ****************************************************/
576
577 /**
578 * Returns a row (with colspan=4) which is a header for a section in the Admin Panel.
579 * 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
580 * See the functions extGetCategory_*
581 *
582 * @param string The suffix to the display_ label. Also selects the label from the LOCAL_LANG array.
583 * @return string HTML table row.
584 * @access private
585 * @see extGetItem()
586 */
587 function extGetHead($pre) {
588 $out = '<img src="'.TYPO3_mainDir.'gfx/ol/blank.gif" width="18" height="16" align="absmiddle" border="0" alt="" />';
589 $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="" />';
590 $out.= $this->extFw($this->extGetLL($pre));
591
592 $out = $this->extItemLink($pre,$out);
593 return '
594 <tr class="typo3-adminPanel-itemHRow" style="background-color:#abbbb4;">
595 <td colspan="4" style="text-align:left; border-top:dashed 1px #007a8c; white-space:nowrap;">'.$out.'<input type="hidden" name="TSFE_ADMIN_PANEL[display_'.$pre.']" value="'.$this->uc['TSFE_adminConfig']['display_'.$pre].'" /></td>
596 </tr>';
597 }
598
599 /**
600 * Wraps a string in a link which will open/close a certain part of the Admin Panel
601 *
602 * @param string The code for the display_ label/key
603 * @param string Input string
604 * @return string Linked input string
605 * @access private
606 * @see extGetHead()
607 */
608 function extItemLink($pre,$str) {
609 return '<a href="#" style="text-decoration:none;" onclick="'.
610 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;').
611 '">'.$str.'</a>';
612 }
613
614 /**
615 * Returns a row (with 4 columns) for content in a section of the Admin Panel.
616 * It will take $pre as a key to a label to display and $element as the content to put into the forth cell.
617 *
618 * @param string Key to label
619 * @param string The HTML content for the forth table cell.
620 * @param string Alignment of the HTML content (default is "center")
621 * @return string HTML table row.
622 * @access private
623 * @see extGetHead()
624 */
625 function extGetItem($pre,$element,$align='center') {
626 $out = '
627 <tr class="typo3-adminPanel-itemRow">
628 <td><img src="clear.gif" width="50" height="1" alt="" /></td>
629 <td style="text-align:left; white-space:nowrap;">'.($pre ? $this->extFw($this->extGetLL($pre)) : '&nbsp;').'</td>
630 <td><img src="clear.gif" width="40" height="1" alt="" /></td>
631 <td style="text-align:'.$align.'; white-space:nowrap;">'.$element.'</td>
632 </tr>';
633
634 return $out;
635 }
636
637 /**
638 * Wraps a string in a span-tag with black verdana font
639 *
640 * @param string The string to wrap
641 * @return string
642 */
643 function extFw($str) {
644 return '<span style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:0.6em; color:black;">'.$str.'</span>';
645 }
646
647 /**
648 * Creates the tool bar links for the "edit" section of the Admin Panel.
649 *
650 * @return string A string containing images wrapped in <a>-tags linking them to proper functions.
651 */
652 function ext_makeToolBar() {
653 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
654 $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
655 $tmpTSc = $tmpTSc ['properties']['newContentWiz.']['overrideWithExtension'];
656 $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');
657
658 $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
659 $langAllowed = $GLOBALS['BE_USER']->checkLanguageAccess($GLOBALS['TSFE']->sys_language_uid);
660
661 $toolBar = '';
662 $id = $GLOBALS['TSFE']->id;
663 $toolBar.= '<a href="'.htmlspecialchars(TYPO3_mainDir.'show_rechis.php?element='.rawurlencode('pages:'.$id).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'#latest">'.
664 '<img src="'.TYPO3_mainDir.'gfx/history2.gif" width="13" height="12" hspace="2" border="0" valign="top" title="'.$this->extGetLL('edit_recordHistory').'" alt="" /></a>';
665
666 if ($perms&16 && $langAllowed) {
667 $params = '';
668 if ($GLOBALS['TSFE']->sys_language_uid) $params = '&sys_language_uid='.$GLOBALS['TSFE']->sys_language_uid;
669 $toolBar.= '<a href="'.htmlspecialchars($newContentWizScriptPath.'?id='.$id.$params.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
670 '<img src="'.TYPO3_mainDir.'gfx/new_record.gif" width="16" height="12" hspace="1" border="0" valign="top" title="'.$this->extGetLL('edit_newContentElement').'" alt="" /></a>';
671 }
672 if ($perms&2) {
673 $toolBar.= '<a href="'.htmlspecialchars(TYPO3_mainDir.'move_el.php?table=pages&uid='.$id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
674 '<img src="'.TYPO3_mainDir.'gfx/move_page.gif" width="11" height="12" hspace="2" border="0" valign="top" title="'.$this->extGetLL('edit_move_page').'" alt="" /></a>';
675 }
676 if ($perms&8) {
677 $toolBar.= '<a href="'.htmlspecialchars(TYPO3_mainDir.'db_new.php?id='.$id.'&pagesOnly=1&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
678 '<img src="'.TYPO3_mainDir.'gfx/new_page.gif" width="13" height="12" hspace="0" border="0" valign="top" title="'.$this->extGetLL('edit_newPage').'" alt="" /></a>';
679 }
680 if ($perms&2) {
681 $params = '&edit[pages]['.$id.']=edit';
682 $toolBar.= '<a href="'.htmlspecialchars(TYPO3_mainDir.'alt_doc.php?'.$params.'&noView=1&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
683 '<img src="'.TYPO3_mainDir.'gfx/edit2.gif" width="11" height="12" hspace="2" border="0" valign="top" title="'.$this->extGetLL('edit_editPageProperties').'" alt="" /></a>';
684
685 if ($GLOBALS['TSFE']->sys_language_uid && $langAllowed) {
686 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
687 'uid,pid,t3ver_state', 'pages_language_overlay',
688 'pid='.intval($id).' AND sys_language_uid='.$GLOBALS['TSFE']->sys_language_uid.$GLOBALS['TSFE']->sys_page->enableFields('pages_language_overlay'),
689 '', '', '1');
690 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
691 $GLOBALS['TSFE']->sys_page->versionOL('pages_language_overlay',$row);
692 if (is_array($row)) {
693 $params='&edit[pages_language_overlay]['.$row['uid'].']=edit';
694 $toolBar.= '<a href="'.htmlspecialchars(TYPO3_mainDir.'alt_doc.php?'.$params.'&noView=1&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
695 '<img src="'.TYPO3_mainDir.'gfx/edit3.gif" width="11" height="12" hspace="2" border="0" valign="top" title="'.$this->extGetLL('edit_editPageOverlay').'" alt="" /></a>';
696 }
697 }
698 }
699 if ($this->check('modules','web_list')) {
700 $toolBar.= '<a href="'.htmlspecialchars(TYPO3_mainDir.'db_list.php?id='.$id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
701 '<img src="'.TYPO3_mainDir.'gfx/list.gif" width="11" height="11" hspace="2" border="0" valign="top" title="'.$this->extGetLL('edit_db_list').'" alt="" /></a>';
702 }
703
704 return $toolBar;
705 }
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725 /*****************************************************
726 *
727 * TSFE BE user Access Functions
728 *
729 ****************************************************/
730
731 /**
732 * Implementing the access checks that the typo3/init.php script does before a user is ever logged in.
733 * Used in the frontend.
734 *
735 * @return boolean Returns true if access is OK
736 * @see typo3/init.php, t3lib_beuserauth::backendCheckLogin()
737 */
738 function checkBackendAccessSettingsFromInitPhp() {
739 global $TYPO3_CONF_VARS;
740
741 // **********************
742 // Check Hardcoded lock on BE:
743 // **********************
744 if ($TYPO3_CONF_VARS['BE']['adminOnly'] < 0) {
745 return FALSE;
746 }
747
748 // **********************
749 // Check IP
750 // **********************
751 if (trim($TYPO3_CONF_VARS['BE']['IPmaskList'])) {
752 if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['BE']['IPmaskList'])) {
753 return FALSE;
754 }
755 }
756
757
758 // **********************
759 // Check SSL (https)
760 // **********************
761 if (intval($TYPO3_CONF_VARS['BE']['lockSSL']) && $TYPO3_CONF_VARS['BE']['lockSSL'] != 3) {
762 if (!t3lib_div::getIndpEnv('TYPO3_SSL')) {
763 return FALSE;
764 }
765 }
766
767 // Finally a check from t3lib_beuserauth::backendCheckLogin()
768 if (!$TYPO3_CONF_VARS['BE']['adminOnly'] || $this->isAdmin()) {
769 return TRUE;
770 } else return FALSE;
771 }
772
773
774 /**
775 * Evaluates if the Backend User has read access to the input page record.
776 * 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.
777 * Read access means that previewing is allowed etc.
778 * Used in index_ts.php
779 *
780 * @param array The page record to evaluate for
781 * @return boolean True if read access
782 */
783 function extPageReadAccess($pageRec) {
784 return $this->isInWebMount($pageRec['uid']) && $this->doesUserHaveAccess($pageRec,1);
785 }
786
787 /**
788 * Checks if a Admin Panel section ("module") is available for the user. If so, true is returned.
789 *
790 * @param string The module key, eg. "edit", "preview", "info" etc.
791 * @return boolean
792 * @see extPrintFeAdminDialog()
793 */
794 function extAdmModuleEnabled($key) {
795 // Returns true if the module checked is "preview" and the forcePreview flag is set.
796 if ($key=="preview" && $this->ext_forcePreview) return true;
797
798 // If key is not set, only "all" is checked
799 if ($this->extAdminConfig['enable.']['all']) return true;
800 if ($this->extAdminConfig['enable.'][$key]) {
801 return true;
802 }
803 }
804
805 /**
806 * Saves any change in settings made in the Admin Panel.
807 * Called from index_ts.php right after access check for the Admin Panel
808 *
809 * @return void
810 */
811 function extSaveFeAdminConfig() {
812 $input = t3lib_div::_GET('TSFE_ADMIN_PANEL');
813 if (is_array($input)) {
814 // Setting
815 $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...
816 unset($this->uc['TSFE_adminConfig']['action']);
817
818 // Actions:
819 if ($input['action']['clearCache'] && $this->extAdmModuleEnabled('cache')) {
820 $this->extPageInTreeInfo=array();
821 $theStartId = intval($input['cache_clearCacheId']);
822 $GLOBALS['TSFE']->clearPageCacheContent_pidList($this->extGetTreeList($theStartId, $this->extGetFeAdminValue('cache','clearCacheLevels'),0,$this->getPagePermsClause(1)).$theStartId);
823 }
824 if ($input['action']['publish'] && $this->extAdmModuleEnabled('publish')) {
825 $theStartId = intval($input['publish_id']);
826 $this->extPublishList = $this->extGetTreeList($theStartId, $this->extGetFeAdminValue('publish','levels'),0,$this->getPagePermsClause(1)).$theStartId;
827 }
828
829 // Saving
830 $this->writeUC();
831 }
832 $GLOBALS['TT']->LR = $this->extGetFeAdminValue('tsdebug','LR');
833
834 if ($this->extGetFeAdminValue('cache','noCache')) {
835 $GLOBALS['TSFE']->set_no_cache();
836 }
837 }
838
839 /**
840 * Returns the value for a Admin Panel setting. You must specify both the module-key and the internal setting key.
841 *
842 * @param string Module key
843 * @param string Setting key
844 * @return string The setting value
845 */
846 function extGetFeAdminValue($pre,$val='') {
847 if ($this->extAdmModuleEnabled($pre)) { // Check if module is enabled.
848 // Exceptions where the values can be overridden from backend:
849 // deprecated
850 if ($pre.'_'.$val == 'edit_displayIcons' && $this->extAdminConfig['module.']['edit.']['forceDisplayIcons']) {
851 return true;
852 }
853 if ($pre.'_'.$val == 'edit_displayFieldIcons' && $this->extAdminConfig['module.']['edit.']['forceDisplayFieldIcons']) {
854 return true;
855 }
856
857 // override all settings with user TSconfig
858 if ($this->extAdminConfig['override.'][$pre.'.'][$val] && $val) {
859 return $this->extAdminConfig['override.'][$pre.'.'][$val];
860 }
861 if ($this->extAdminConfig['override.'][$pre]) {
862 return $this->extAdminConfig['override.'][$pre];
863 }
864
865 $retVal = $val ? $this->uc['TSFE_adminConfig'][$pre.'_'.$val] : 1;
866
867 if ($pre=='preview' && $this->ext_forcePreview) {
868 if (!$val) {
869 return true;
870 } else {
871 return $retVal;
872 }
873 }
874
875 // regular check:
876 if ($this->extIsAdmMenuOpen($pre)) { // See if the menu is expanded!
877 return $retVal;
878 }
879 }
880 }
881
882 /**
883 * Returns true if admin panel module is open
884 *
885 * @param string Module key
886 * @return boolean True, if the admin panel is open for the specified admin panel module key.
887 */
888 function extIsAdmMenuOpen($pre) {
889 return $this->uc['TSFE_adminConfig']['display_top'] && $this->uc['TSFE_adminConfig']['display_'.$pre];
890 }
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907 /*****************************************************
908 *
909 * TSFE BE user Access Functions
910 *
911 ****************************************************/
912
913 /**
914 * Generates a list of Page-uid's from $id. List does not include $id itself
915 * The only pages excluded from the list are deleted pages.
916 *
917 * @param integer Start page id
918 * @param integer Depth to traverse down the page tree.
919 * @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'
920 * @param string Perms clause
921 * @return string Returns the list with a comma in the end (if any pages selected!)
922 */
923 function extGetTreeList($id,$depth,$begin=0,$perms_clause) {
924 $depth=intval($depth);
925 $begin=intval($begin);
926 $id=intval($id);
927 $theList='';
928
929 if ($id && $depth>0) {
930 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
931 'uid,title',
932 'pages',
933 'pid='.$id.' AND doktype IN ('.$GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'].') AND deleted=0 AND '.$perms_clause
934 );
935 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
936 if ($begin<=0) {
937 $theList.= $row['uid'].',';
938 $this->extPageInTreeInfo[]=array($row['uid'],$row['title'],$depth);
939 }
940 if ($depth>1) {
941 $theList.= $this->extGetTreeList($row['uid'], $depth-1,$begin-1,$perms_clause);
942 }
943 }
944 }
945 return $theList;
946 }
947
948 /**
949 * Returns the number of cached pages for a page id.
950 *
951 * @param integer The page id.
952 * @return integer The number of pages for this page in the table "cache_pages"
953 */
954 function extGetNumberOfCachedPages($page_id) {
955 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_pages', 'page_id='.intval($page_id));
956 list($num) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
957 return $num;
958 }
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980 /*****************************************************
981 *
982 * Localization handling
983 *
984 ****************************************************/
985
986 /**
987 * 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.
988 * 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
989 *
990 * @param string Key for a label in the $LOCAL_LANG array of "sysext/lang/locallang_tsfe.php"
991 * @return string The value for the $key
992 */
993 function extGetLL($key) {
994 global $LOCAL_LANG;
995 if (!is_array($LOCAL_LANG)) {
996 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_tsfe.php');
997 #include('./'.TYPO3_mainDir.'sysext/lang/locallang_tsfe.php');
998 if (!is_array($LOCAL_LANG)) {
999 $LOCAL_LANG = array();
1000 }
1001 }
1002
1003 $labelStr = htmlspecialchars($GLOBALS['LANG']->getLL($key)); // Label string in the default backend output charset.
1004
1005 // Convert to utf-8, then to entities:
1006 if ($GLOBALS['LANG']->charSet!='utf-8') {
1007 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_encode($labelStr,$GLOBALS['LANG']->charSet);
1008 }
1009 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_to_entities($labelStr);
1010
1011 // Return the result:
1012 return $labelStr;
1013 }
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027 /*****************************************************
1028 *
1029 * Frontend Editing
1030 *
1031 ****************************************************/
1032
1033 /**
1034 * Returns true in an edit-action is sent from the Admin Panel
1035 *
1036 * @return boolean
1037 * @see index_ts.php
1038 */
1039 function extIsEditAction() {
1040 if (is_array($this->TSFE_EDIT)) {
1041 if ($this->TSFE_EDIT['cancel']) {
1042 unset($this->TSFE_EDIT['cmd']);
1043 } else {
1044 $cmd = (string)$this->TSFE_EDIT['cmd'];
1045 if (($cmd!='edit' || (is_array($this->TSFE_EDIT['data']) && ($this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']))) && $cmd!='new') {
1046 // $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.
1047 return true;
1048 }
1049 }
1050 }
1051 return false;
1052 }
1053
1054 /**
1055 * Returns true if an edit form is shown on the page.
1056 * Used from index_ts.php where a true return-value will result in classes etc. being included.
1057 *
1058 * @return boolean
1059 * @see index_ts.php
1060 */
1061 function extIsFormShown() {
1062 if (is_array($this->TSFE_EDIT)) {
1063 $cmd = (string)$this->TSFE_EDIT['cmd'];
1064 if ($cmd=='edit' || $cmd=='new') {
1065 return true;
1066 }
1067 }
1068 }
1069
1070 /**
1071 * Management of the on-page frontend editing forms and edit panels.
1072 * Basically taking in the data and commands and passes them on to the proper classes as they should be.
1073 *
1074 * @return void
1075 * @see index_ts.php
1076 */
1077 function extEditAction() {
1078 global $TCA, $TYPO3_CONF_VARS;
1079 // Commands:
1080 list($table,$uid) = explode(':',$this->TSFE_EDIT['record']);
1081 if ($this->TSFE_EDIT['cmd'] && $table && $uid && isset($TCA[$table])) {
1082 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
1083 $tce->stripslashes_values=0;
1084 $recData = array();
1085 $cmdData = array();
1086 $cmd = $this->TSFE_EDIT['cmd'];
1087
1088 // ****************
1089 // extEditAction HOOK
1090 // ****************
1091 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction'])) {
1092 $_params = array();
1093 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction'] as $_funcRef) {
1094 t3lib_div::callUserFunction($_funcRef,$_params,$this);
1095 }
1096 }
1097
1098 switch($cmd) {
1099 case 'hide':
1100 case 'unhide':
1101 $hideField = $TCA[$table]['ctrl']['enablecolumns']['disabled'];
1102 if ($hideField) {
1103 $recData[$table][$uid][$hideField] = ($cmd=='hide' ? 1 : 0);
1104 $tce->start($recData,Array());
1105 $tce->process_datamap();
1106 }
1107 break;
1108 case 'up':
1109 case 'down':
1110 $sortField = $TCA[$table]['ctrl']['sortby'];
1111 if ($sortField) {
1112 if ($cmd=='up') {
1113 $op= '<';
1114 $desc=' DESC';
1115 } else {
1116 $op= '>';
1117 $desc='';
1118 }
1119
1120 // Get self:
1121 $fields = array_unique(t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['copyAfterDuplFields'].',uid,pid,'.$sortField,1));
1122 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',',$fields), $table, 'uid='.$uid);
1123 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1124 // record before or after
1125 $preview = $this->extGetFeAdminValue('preview');
1126 $copyAfterFieldsQuery = '';
1127 if ($preview) {
1128 $ignore = array('starttime'=>1, 'endtime'=>1, 'disabled'=>1, 'fe_group'=>1);
1129 }
1130 if ($TCA[$table]['ctrl']['copyAfterDuplFields']) {
1131 $cAFields = t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['copyAfterDuplFields'],1);
1132 while(list(,$fN)=each($cAFields)) {
1133 $copyAfterFieldsQuery.= ' AND '.$fN.'="'.$row[$fN].'"';
1134 }
1135 }
1136
1137 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1138 'uid,pid',
1139 $table,
1140 'pid='.intval($row['pid']).
1141 ' AND '.$sortField.$op.intval($row[$sortField]).
1142 $copyAfterFieldsQuery.
1143 $GLOBALS['TSFE']->sys_page->enableFields($table,'',$ignore),
1144 '',
1145 $sortField.$desc,
1146 '2'
1147 );
1148 if ($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1149 if($cmd=='down') {
1150 $cmdData[$table][$uid]['move'] = -$row2['uid'];
1151 } elseif ($row3 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // Must take the second record above...
1152 $cmdData[$table][$uid]['move'] = -$row3['uid'];
1153 } else { // ... and if that does not exist, use pid
1154 $cmdData[$table][$uid]['move'] = $row['pid'];
1155 }
1156 } elseif ($cmd=='up') {
1157 $cmdData[$table][$uid]['move'] = $row['pid'];
1158 }
1159 }
1160 if (count($cmdData)) {
1161 $tce->start(Array(),$cmdData);
1162 $tce->process_cmdmap();
1163 }
1164 }
1165 break;
1166 case 'delete':
1167 $cmdData[$table][$uid]['delete'] = 1;
1168 if (count($cmdData)) {
1169 $tce->start(Array(),$cmdData);
1170 $tce->process_cmdmap();
1171 }
1172 break;
1173 }
1174 }
1175 // Data:
1176 if (($this->TSFE_EDIT['doSave'] || $this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']) && is_array($this->TSFE_EDIT['data'])) {
1177 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
1178 $tce->stripslashes_values = 0;
1179 $tce->start($this->TSFE_EDIT['data'],Array());
1180 $tce->process_uploads($_FILES);
1181 $tce->process_datamap();
1182 }
1183 }
1184 }
1185
1186
1187 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsfebeuserauth.php']) {
1188 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsfebeuserauth.php']);
1189 }
1190
1191 ?>