Added feature #13953: Hookrequest - t3lib_page::getRecordOverlay (thanks to Tolleiv...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsfebeuserauth.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 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 /**
105 * Form field with login name.
106 *
107 * @var string
108 */
109 public $formfield_uname = '';
110
111 /**
112 * Form field with password.
113 *
114 * @var string
115 */
116 public $formfield_uident = '';
117
118 /**
119 * Form field with a unique value which is used to encrypt the password and username.
120 *
121 * @var string
122 */
123 public $formfield_chalvalue = '';
124
125 /**
126 * Sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username.
127 * from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
128 *
129 * @var string
130 */
131 public $security_level = '';
132
133 /**
134 * Decides if the writelog() function is called at login and logout.
135 *
136 * @var boolean
137 */
138 public $writeStdLog = false;
139
140 /**
141 * If the writelog() functions is called if a login-attempt has be tried without success.
142 *
143 * @var boolean
144 */
145 public $writeAttemptLog = false;
146
147 /**
148 * This is the name of the include-file containing the login form. If not set, login CAN be anonymous. If set login IS needed.
149 *
150 * @var string
151 */
152 public $auth_include = '';
153
154 /**
155 * Array of page related information (uid, title, depth).
156 *
157 * @var array
158 */
159 public $extPageInTreeInfo = array();
160
161 /**
162 * General flag which is set if the adminpanel should be displayed at all.
163 *
164 * @var boolean
165 */
166 public $extAdmEnabled = false;
167
168 /**
169 * Instance of the admin panel
170 *
171 * @var tslib_AdminPanel
172 */
173 public $adminPanel = null;
174
175 /**
176 * Class for frontend editing.
177 *
178 * @var t3lib_frontendedit
179 */
180 public $frontendEdit = null;
181
182 /**
183 * Initializes the admin panel.
184 *
185 * @return void
186 */
187 public function initializeAdminPanel() {
188 $this->extAdminConfig = $this->getTSConfigProp('admPanel');
189
190 if (isset($this->extAdminConfig['enable.'])) {
191 foreach($this->extAdminConfig['enable.'] as $key => $value) {
192 if ($value) {
193 $this->adminPanel = t3lib_div::makeInstance('tslib_AdminPanel');
194 $this->extAdmEnabled = true;
195
196 break;
197 }
198 }
199 }
200 }
201
202 /**
203 * Initializes frontend editing.
204 *
205 * @return void
206 */
207 public function initializeFrontendEdit() {
208 if (isset($this->extAdminConfig['enable.']) && $this->isFrontendEditingActive()) {
209 foreach($this->extAdminConfig['enable.'] as $key => $value) {
210 if ($value) {
211 if ($GLOBALS['TSFE'] instanceof tslib_fe) {
212 // Grab the Page TSConfig property that determines which controller to use.
213 $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
214 $controllerKey = isset($pageTSConfig['TSFE.']['frontendEditingController']) ? $pageTSConfig['TSFE.']['frontendEditingController'] : 'default';
215 } else {
216 $controllerKey = 'default';
217 }
218
219 $controllerClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey];
220 if ($controllerClass) {
221 $this->frontendEdit = t3lib_div::getUserObj($controllerClass, false);
222 }
223
224 break;
225 }
226 }
227 }
228 }
229
230 /**
231 * Determines whether frontend editing is currently active.
232 *
233 * @return boolean Wheter frontend editing is active
234 */
235 public function isFrontendEditingActive() {
236 return ($this->extAdmEnabled
237 && ($this->adminPanel->isAdminModuleEnabled('edit') && $this->adminPanel->isAdminModuleOpen('edit')
238 || $GLOBALS['TSFE']->displayEditIcons == 1)
239 );
240 }
241
242 /**
243 * Delegates to the appropriate view and renders the admin panel content.
244 *
245 * @return string.
246 */
247 public function displayAdminPanel() {
248 $content = $this->adminPanel->display();
249
250 return $content;
251 }
252
253 /**
254 * Determines whether the admin panel is enabled and visible.
255 *
256 * @return boolean Whether the admin panel is enabled and visible
257 */
258 public function isAdminPanelVisible() {
259 return ($this->extAdmEnabled && !$this->extAdminConfig['hide'] && $GLOBALS['TSFE']->config['config']['admPanel']);
260 }
261
262 /*****************************************************
263 *
264 * TSFE BE user Access Functions
265 *
266 ****************************************************/
267
268 /**
269 * Implementing the access checks that the typo3/init.php script does before a user is ever logged in.
270 * Used in the frontend.
271 *
272 * @return boolean Returns true if access is OK
273 * @see typo3/init.php, t3lib_beuserauth::backendCheckLogin()
274 */
275 public function checkBackendAccessSettingsFromInitPhp() {
276 global $TYPO3_CONF_VARS;
277
278 // **********************
279 // Check Hardcoded lock on BE:
280 // **********************
281 if ($TYPO3_CONF_VARS['BE']['adminOnly'] < 0) {
282 return false;
283 }
284
285 // **********************
286 // Check IP
287 // **********************
288 if (trim($TYPO3_CONF_VARS['BE']['IPmaskList'])) {
289 if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['BE']['IPmaskList'])) {
290 return false;
291 }
292 }
293
294
295 // **********************
296 // Check SSL (https)
297 // **********************
298 if (intval($TYPO3_CONF_VARS['BE']['lockSSL']) && $TYPO3_CONF_VARS['BE']['lockSSL'] != 3) {
299 if (!t3lib_div::getIndpEnv('TYPO3_SSL')) {
300 return false;
301 }
302 }
303
304 // Finally a check from t3lib_beuserauth::backendCheckLogin()
305 if ($this->isUserAllowedToLogin()) {
306 return true;
307 } else {
308 return false;
309 }
310 }
311
312
313 /**
314 * Evaluates if the Backend User has read access to the input page record.
315 * 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.
316 * Read access means that previewing is allowed etc.
317 * Used in index_ts.php
318 *
319 * @param array The page record to evaluate for
320 * @return boolean True if read access
321 */
322 public function extPageReadAccess($pageRec) {
323 return $this->isInWebMount($pageRec['uid']) && $this->doesUserHaveAccess($pageRec, 1);
324 }
325
326 /*****************************************************
327 *
328 * TSFE BE user Access Functions
329 *
330 ****************************************************/
331
332 /**
333 * Generates a list of Page-uid's from $id. List does not include $id itself
334 * The only pages excluded from the list are deleted pages.
335 *
336 * @param integer Start page id
337 * @param integer Depth to traverse down the page tree.
338 * @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'
339 * @param string Perms clause
340 * @return string Returns the list with a comma in the end (if any pages selected!)
341 */
342 public function extGetTreeList($id, $depth, $begin=0, $perms_clause) {
343 $depth=intval($depth);
344 $begin=intval($begin);
345 $id=intval($id);
346 $theList='';
347
348 if ($id && $depth > 0) {
349 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
350 'uid,title',
351 'pages',
352 'pid=' . $id . ' AND doktype IN (' . $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ') AND deleted=0 AND ' . $perms_clause
353 );
354 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
355 if ($begin <= 0) {
356 $theList .= $row['uid'].',';
357 $this->extPageInTreeInfo[] = array($row['uid'], htmlspecialchars($row['title'],$depth));
358 }
359 if ($depth > 1) {
360 $theList .= $this->extGetTreeList($row['uid'], $depth-1, $begin-1, $perms_clause);
361 }
362 }
363 }
364 return $theList;
365 }
366
367 /**
368 * Returns the number of cached pages for a page id.
369 *
370 * @param integer The page id.
371 * @return integer The number of pages for this page in the table "cache_pages"
372 */
373 public function extGetNumberOfCachedPages($pageId) {
374 if (TYPO3_UseCachingFramework) {
375 $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
376 $pageCacheEntries = $pageCache->getByTag('pageId_' . (int) $pageId);
377 $count = count($pageCacheEntries);
378 } else {
379 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_pages', 'page_id='.intval($pageId));
380 list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
381 }
382 return $count;
383 }
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405 /*****************************************************
406 *
407 * Localization handling
408 *
409 ****************************************************/
410
411 /**
412 * 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.
413 * 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
414 *
415 * @param string Key for a label in the $LOCAL_LANG array of "sysext/lang/locallang_tsfe.php"
416 * @return string The value for the $key
417 */
418 public function extGetLL($key) {
419 global $LOCAL_LANG;
420 if (!is_array($LOCAL_LANG)) {
421 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_tsfe.php');
422 #include('./'.TYPO3_mainDir.'sysext/lang/locallang_tsfe.php');
423 if (!is_array($LOCAL_LANG)) {
424 $LOCAL_LANG = array();
425 }
426 }
427
428 $labelStr = htmlspecialchars($GLOBALS['LANG']->getLL($key)); // Label string in the default backend output charset.
429
430 // Convert to utf-8, then to entities:
431 if ($GLOBALS['LANG']->charSet != 'utf-8') {
432 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_encode($labelStr, $GLOBALS['LANG']->charSet);
433 }
434 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_to_entities($labelStr);
435
436 // Return the result:
437 return $labelStr;
438 }
439
440 }
441
442
443 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsfebeuserauth.php']) {
444 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsfebeuserauth.php']);
445 }
446
447 ?>