Added feature #11460: felogin - Integrate possibility to disable redirects on the fly
[Packages/TYPO3.CMS.git] / typo3 / sysext / felogin / pi1 / class.tx_felogin_pi1.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2009 Steffen Kamper <info@sk-typo3.de>
6 * Based on Newloginbox (c) 2002-2004 Kasper Skaarhoj <kasper@typo3.com>
7 *
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 *
26 * The code was adapted from newloginbox, see manual for detailed description
27 ***************************************************************/
28 /**
29 * Plugin 'Website User Login' for the 'felogin' extension.
30 *
31 * @author Steffen Kamper <info@sk-typo3.de>
32 * @package TYPO3
33 * @subpackage tx_felogin
34 */
35 class tx_felogin_pi1 extends tslib_pibase {
36 var $prefixId = 'tx_felogin_pi1'; // Same as class name
37 var $scriptRelPath = 'pi1/class.tx_felogin_pi1.php'; // Path to this script relative to the extension dir.
38 var $extKey = 'felogin'; // The extension key.
39 var $pi_checkCHash = true;
40 var $userIsLoggedIn; // Is user logged in?
41 var $template;
42 var $uploadDir;
43 var $redirectUrl;
44 protected $noRedirect = false;
45
46 /**
47 * The main method of the plugin
48 *
49 * @param string $content: The PlugIn content
50 * @param array $conf: The PlugIn configuration
51 *
52 * @return string The content that is displayed on the website
53 */
54 public function main($content,$conf) {
55
56 // Loading TypoScript array into object variable:
57 $this->conf = $conf;
58 $this->uploadDir = 'uploads/tx_felogin/';
59
60 // Loading default pivars
61 $this->pi_setPiVarDefaults();
62
63 // Loading language-labels
64 $this->pi_loadLL();
65
66 // Init FlexForm configuration for plugin:
67 $this->pi_initPIflexForm();
68 $this->mergeflexFormValuesIntoConf();
69
70
71 // Get storage PIDs:
72 if ($this->conf['storagePid']) {
73 if (intval($this->conf['recursive'])) {
74 $this->spid = $this->pi_getPidList($this->conf['storagePid'], intval($this->conf['recursive']));
75 } else {
76 $this->spid = $this->conf['storagePid'];
77 }
78 } else {
79 $pids = $GLOBALS['TSFE']->getStorageSiterootPids();
80 $this->spid = $pids['_STORAGE_PID'];
81 }
82
83 // GPvars:
84 $this->logintype = t3lib_div::_GP('logintype');
85 $this->redirectUrl = t3lib_div::_GP('redirect_url');
86 $this->noRedirect = ($this->piVars['noredirect'] || $this->conf['redirectDisable']);
87
88 // if config.typolinkLinkAccessRestrictedPages is set, the var is return_url
89 $returnUrl = t3lib_div::_GP('return_url');
90 if ($returnUrl) {
91 $this->redirectUrl = $returnUrl;
92 }
93
94 // Get Template
95 $templateFile = $this->conf['templateFile'] ? $this->conf['templateFile'] : 'EXT:felogin/template.html';
96 $this->template = $this->cObj->fileResource($templateFile);
97
98 // Is user logged in?
99 $this->userIsLoggedIn = $GLOBALS['TSFE']->loginUser;
100
101 // Redirect
102 if ($this->conf['redirectMode'] && !$this->conf['redirectDisable'] && !$this->noRedirect) {
103 $this->redirectUrl = $this->processRedirect();
104 }
105
106
107 // What to display
108 $content='';
109 if ($this->piVars['forgot']) {
110 $content .= $this->showForgot();
111 } else {
112 if($this->userIsLoggedIn && !$this->logintype) {
113 $content .= $this->showLogout();
114 } else {
115 $content .= $this->showLogin();
116 }
117 }
118
119
120
121 // Process the redirect
122 if (($this->logintype === 'login' || $this->logintype === 'logout') && $this->redirectUrl && !$this->noRedirect) {
123 if (!$GLOBALS['TSFE']->fe_user->cookieId) {
124 $content .= '<p style="color:red; font-weight:bold;">' . $this->pi_getLL('cookie_warning', '', 1) . '</p>';
125 } else {
126 header('Location: '.t3lib_div::locationHeaderUrl($this->redirectUrl));
127 exit;
128 }
129 }
130 return $this->conf['wrapContentInBaseClass'] ? $this->pi_wrapInBaseClass($content) : $content;
131
132 }
133
134 /**
135 * Shows the forgot password form
136 *
137 * @return string content
138 */
139 protected function showForgot() {
140 $subpart = $this->cObj->getSubpart($this->template, '###TEMPLATE_FORGOT###');
141 $subpartArray = $linkpartArray = array();
142
143 if ($this->piVars['forgot_email']) {
144 if (t3lib_div::validEmail($this->piVars['forgot_email'])) {
145 // look for user record and send the password
146 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
147 'uid, username, password',
148 'fe_users',
149 'email='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars['forgot_email'], 'fe_users').' AND pid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->spid).') '.$this->cObj->enableFields('fe_users')
150 );
151
152 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
153 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
154 $msg = sprintf($this->pi_getLL('ll_forgot_email_password', '', 0), $this->piVars['forgot_email'], $row['username'], $row['password']);
155 } else {
156 $msg = sprintf($this->pi_getLL('ll_forgot_email_nopassword', '', 0), $this->piVars['forgot_email']);
157 }
158
159
160 // Generate new password with md5 and save it in user record
161 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) && t3lib_extMgm::isLoaded('kb_md5fepw')) {
162 $newPass = $this->generatePassword(8);
163 $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
164 'fe_users',
165 'uid=' . $row['uid'],
166 array('password' => md5($newPass))
167 );
168 $msg = sprintf($this->pi_getLL('ll_forgot_email_password', '', 0),$this->piVars['forgot_email'], $row['username'], $newPass);
169 }
170
171 $this->cObj->sendNotifyEmail($msg, $this->piVars['forgot_email'], '', $this->conf['email_from'], $this->conf['email_fromName'], $this->conf['replyTo']);
172 $markerArray['###STATUS_MESSAGE###'] = $this->cObj->stdWrap(sprintf($this->pi_getLL('ll_forgot_message_emailSent', '', 1), '<em>' . htmlspecialchars($this->piVars['forgot_email']) .'</em>'), $this->conf['forgotMessage_stdWrap.']);
173 $subpartArray['###FORGOT_FORM###'] = '';
174
175
176 } else {
177 //wrong email
178 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('forgot_message', $this->conf['forgotMessage_stdWrap.']);
179 $markerArray['###BACKLINK_LOGIN###'] = '';
180 }
181 } else {
182 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('forgot_message', $this->conf['forgotMessage_stdWrap.']);
183 $markerArray['###BACKLINK_LOGIN###'] = '';
184 }
185
186 $markerArray['###BACKLINK_LOGIN###'] = $this->getPageLink($this->pi_getLL('ll_forgot_header_backToLogin', '', 1), array());
187 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('forgot_header', $this->conf['forgotHeader_stdWrap.']);
188
189 $markerArray['###LEGEND###'] = $this->pi_getLL('send_password', '', 1);
190 $markerArray['###ACTION_URI###'] = $this->getPageLink('', array($this->prefixId . '[forgot]'=>1), true);
191 $markerArray['###EMAIL_LABEL###'] = $this->pi_getLL('your_email', '', 1);
192 $markerArray['###FORGOT_PASSWORD_ENTEREMAIL###'] = $this->pi_getLL('forgot_password_enterEmail', '', 1);
193 $markerArray['###FORGOT_EMAIL###'] = $this->prefixId.'[forgot_email]';
194 $markerArray['###SEND_PASSWORD###'] = $this->pi_getLL('send_password', '', 1);
195 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
196
197 return $this->cObj->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
198 }
199
200 /**
201 * Shows logout form
202 *
203 * @return string The content.
204 */
205 protected function showLogout() {
206 $subpart = $this->cObj->getSubpart($this->template, '###TEMPLATE_LOGOUT###');
207 $subpartArray = $linkpartArray = array();
208
209 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('status_header',$this->conf['logoutHeader_stdWrap.']);
210 $markerArray['###STATUS_MESSAGE###']=$this->getDisplayText('status_message',$this->conf['logoutMessage_stdWrap.']);$this->cObj->stdWrap($this->flexFormValue('message','s_status'),$this->conf['logoutMessage_stdWrap.']);
211
212 $markerArray['###LEGEND###'] = $this->pi_getLL('logout', '', 1);
213 $markerArray['###ACTION_URI###'] = $this->getPageLink('',array(),true);
214 $markerArray['###LOGOUT_LABEL###'] = $this->pi_getLL('logout', '', 1);
215 $markerArray['###NAME###'] = htmlspecialchars($GLOBALS['TSFE']->fe_user->user['name']);
216 $markerArray['###STORAGE_PID###'] = $this->spid;
217 $markerArray['###USERNAME###'] = htmlspecialchars($GLOBALS['TSFE']->fe_user->user['username']);
218 $markerArray['###USERNAME_LABEL###'] = $this->pi_getLL('username', '', 1);
219 $markerArray['###NOREDIRECT###'] = $this->noRedirect ? '1' : '0';
220 $markerArray['###PREFIXID###'] = $this->prefixId;
221 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
222
223 if ($this->redirectUrl) {
224 // use redirectUrl for action tag because of possible access restricted pages
225 $markerArray['###ACTION_URI###'] = htmlspecialchars($this->redirectUrl);
226 $this->redirectUrl = '';
227 }
228 return $this->cObj->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
229 }
230
231 /**
232 * Shows login form
233 *
234 * @return string content
235 */
236 protected function showLogin() {
237 $subpart = $this->cObj->getSubpart($this->template, '###TEMPLATE_LOGIN###');
238 $subpartArray = $linkpartArray = array();
239
240 $gpRedirectUrl = '';
241
242 $markerArray['###LEGEND###'] = $this->pi_getLL('oLabel_header_welcome', '', 1);
243
244 if($this->logintype === 'login') {
245 if($this->userIsLoggedIn) {
246 // login success
247 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('success_header',$this->conf['successHeader_stdWrap.']);
248 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('success_message', $this->conf['successMessage_stdWrap.']);
249 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
250 $subpartArray['###LOGIN_FORM###'] = '';
251
252 // Hook for general actions after after login has been confirmed (by Thomas Danzl <thomas@danzl.org>)
253 if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_confirmed']) {
254 $_params = array();
255 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_confirmed'] as $_funcRef) {
256 if ($_funcRef) {
257 t3lib_div::callUserFunction($_funcRef, $_params, $this);
258 }
259 }
260 }
261
262 } else {
263 // login error
264 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('error_header',$this->conf['errorHeader_stdWrap.']);
265 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('error_message',$this->conf['errorMessage_stdWrap.']);
266 $gpRedirectUrl = t3lib_div::_GP('redirect_url');
267 }
268 } else {
269 if($this->logintype === 'logout') {
270 // login form after logout
271 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('logout_header',$this->conf['welcomeHeader_stdWrap.']);
272 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('logout_message',$this->conf['welcomeMessage_stdWrap.']);
273 } else {
274 // login form
275 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('welcome_header',$this->conf['welcomeHeader_stdWrap.']);
276 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('welcome_message',$this->conf['welcomeMessage_stdWrap.']);
277 }
278 }
279
280
281 // Hook (used by kb_md5fepw extension by Kraft Bernhard <kraftb@gmx.net>)
282 // This hook allows to call User JS functions.
283 // The methods should also set the required JS functions to get included
284 $onSubmit = '';
285 $extraHidden = '';
286 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['loginFormOnSubmitFuncs'])) {
287 $_params = array();
288 $onSubmitAr = array();
289 $extraHiddenAr = array();
290 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['loginFormOnSubmitFuncs'] as $funcRef) {
291 list($onSub, $hid) = t3lib_div::callUserFunction($funcRef, $_params, $this);
292 $onSubmitAr[] = $onSub;
293 $extraHiddenAr[] = $hid;
294 }
295 }
296 if (count($onSubmitAr)) {
297 $onSubmit = implode('; ', $onSubmitAr).'; return true;';
298 $extraHidden = implode(chr(10), $extraHiddenAr);
299 }
300
301 // Login form
302 $markerArray['###ACTION_URI###'] = $this->getPageLink('',array(),true);
303 $markerArray['###EXTRA_HIDDEN###'] = $extraHidden; // used by kb_md5fepw extension...
304 $markerArray['###LEGEND###'] = $this->pi_getLL('login', '', 1);
305 $markerArray['###LOGIN_LABEL###'] = $this->pi_getLL('login', '', 1);
306 $markerArray['###ON_SUBMIT###'] = $onSubmit; // used by kb_md5fepw extension...
307 $markerArray['###PASSWORD_LABEL###'] = $this->pi_getLL('password', '', 1);
308 $markerArray['###STORAGE_PID###'] = $this->spid;
309 $markerArray['###USERNAME_LABEL###'] = $this->pi_getLL('username', '', 1);
310 $markerArray['###REDIRECT_URL###'] = $gpRedirectUrl ? htmlspecialchars($gpRedirectUrl) : htmlspecialchars($this->redirectUrl);
311 $markerArray['###NOREDIRECT###'] = $this->noRedirect ? '1' : '0';
312 $markerArray['###PREFIXID###'] = $this->prefixId;
313 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
314
315 if ($this->flexFormValue('showForgotPassword','sDEF') || $this->conf['showForgotPasswordLink']) {
316 $linkpartArray['###FORGOT_PASSWORD_LINK###'] = explode('|',$this->getPageLink('|',array($this->prefixId.'[forgot]'=>1)));
317 $markerArray['###FORGOT_PASSWORD###'] = $this->pi_getLL('ll_forgot_header', '', 1);
318 } else {
319 $subpartArray['###FORGOTP_VALID###'] = '';
320 }
321
322
323
324 if (($this->conf['showPermaLogin']) && ($GLOBALS['TYPO3_CONF_VARS']['FE']['permalogin'] == 0 || $GLOBALS['TYPO3_CONF_VARS']['FE']['permalogin'] == 1) && $GLOBALS['TYPO3_CONF_VARS']['FE']['lifetime'] > 0) {
325 $markerArray['###PERMALOGIN###'] = $this->pi_getLL('permalogin', '', 1);
326 if($GLOBALS['TYPO3_CONF_VARS']['FE']['permalogin'] == 1) {
327 $markerArray['###PERMALOGIN_HIDDENFIELD_ATTRIBUTES###'] = 'disabled="disabled"';
328 $markerArray['###PERMALOGIN_CHECKBOX_ATTRIBUTES###'] = 'checked="checked"';
329 } else {
330 $markerArray['###PERMALOGIN_HIDDENFIELD_ATTRIBUTES###'] = '';
331 $markerArray['###PERMALOGIN_CHECKBOX_ATTRIBUTES###'] = '';
332 }
333 } else {
334 $subpartArray['###PERMALOGIN_VALID###'] = '';
335 }
336 return $this->cObj->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
337 }
338
339 /**
340 * Process redirect methods. The function searches for a redirect url using all configured methods.
341 *
342 * @return string redirect url
343 */
344 protected function processRedirect() {
345 if ($this->conf['redirectMode']) {
346 foreach (t3lib_div::trimExplode(',', $this->conf['redirectMode'],1) as $redirMethod) {
347 if ($GLOBALS['TSFE']->loginUser && $this->logintype === 'login') {
348 // logintype is needed because the login-page wouldn't be accessible anymore after a login (would always redirect)
349 switch ($redirMethod) {
350 case 'groupLogin': // taken from dkd_redirect_at_login written by Ingmar Schlecht; database-field changed
351 $groupData = $GLOBALS['TSFE']->fe_user->groupData;
352 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
353 'felogin_redirectPid',
354 $GLOBALS['TSFE']->fe_user->usergroup_table,
355 'felogin_redirectPid!="" AND uid IN (' . implode(',', $groupData['uid']) . ')'
356 );
357 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
358 $redirect_url = $this->pi_getPageLink($row[0],array(),true); // take the first group with a redirect page
359 }
360 break;
361 case 'userLogin':
362 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
363 'felogin_redirectPid',
364 $GLOBALS['TSFE']->fe_user->user_table,
365 $GLOBALS['TSFE']->fe_user->userid_column . '=' . $GLOBALS['TSFE']->fe_user->user['uid'] . ' AND felogin_redirectPid!=""'
366 );
367 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
368 $redirect_url = $this->pi_getPageLink($row[0], array(), true);
369 }
370 break;
371 case 'login':
372 if ($this->conf['redirectPageLogin']) {
373 $redirect_url = $this->pi_getPageLink(intval($this->conf['redirectPageLogin']), array(), true);
374 }
375 break;
376 case 'getpost':
377 $redirect_url = $this->redirectUrl;
378 break;
379 case 'referer':
380 $redirect_url = t3lib_div::getIndpEnv('HTTP_REFERER');
381 // avoid forced logout, when trying to login immediatly after a logout
382 $redirect_url = preg_replace('/[&?]logintype=[a-z]+/', '', $redirect_url);
383 break;
384 case 'refererDomains':
385 // Auto redirect.
386 // Feature to redirect to the page where the user came from (HTTP_REFERER).
387 // Allowed domains to redirect to, can be configured with plugin.tx_felogin_pi1.domains
388 // Thanks to plan2.net / Martin Kutschker for implementing this feature.
389 if (!$redirect_url && $this->conf['domains']) {
390 $redirect_url = t3lib_div::getIndpEnv('HTTP_REFERER');
391 // is referring url allowed to redirect?
392 $match = array();
393 if (preg_match('/^http://([[:alnum:]._-]+)//', $redirect_url, $match)) {
394 $redirect_domain = $match[1];
395 $found = false;
396 foreach(split(',', $this->conf['domains']) as $d) {
397 if (preg_match('/(^|\.)/'.$d.'$', $redirect_domain)) {
398 $found = true;
399 break;
400 }
401 }
402 if (!$found) {
403 $redirect_url = '';
404 }
405 }
406
407 // Avoid forced logout, when trying to login immediatly after a logout
408 $redirect_url = preg_replace('/[&?]logintype=[a-z]+/', '', $redirect_url);
409 }
410 break;
411 }
412 } else if ($this->logintype === 'login') { // after login-error
413 switch ($redirMethod) {
414 case 'loginError':
415 if ($this->conf['redirectPageLoginError']) {
416 $redirect_url = $this->pi_getPageLink(intval($this->conf['redirectPageLoginError']), array(), true);
417 }
418 break;
419 }
420 } elseif ($this->logintype === 'logout') { // after logout
421
422 // Hook for general actions after after logout has been confirmed
423 if ($this->logintype === 'logout' && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['logout_confirmed']) {
424 $_params = array();
425 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['logout_confirmed'] as $_funcRef) {
426 if ($_funcRef) {
427 t3lib_div::callUserFunction($_funcRef, $_params, $this);
428 }
429 }
430 }
431
432 switch ($redirMethod) {
433 case 'logout':
434 if ($this->conf['redirectPageLogout']) {
435 $redirect_url = $this->pi_getPageLink(intval($this->conf['redirectPageLogout']), array(), true);
436 }
437 break;
438 }
439 } else { // not logged in
440 // Placeholder for maybe future options
441 switch ($redirMethod) {
442 case 'getpost':
443 // preserve the get/post value
444 $redirect_url = $this->redirectUrl;
445 break;
446 }
447 }
448
449 if ($redirect_url && $this->conf['redirectFirstMethod']) {
450 break;
451 }
452 }
453 }
454 return $redirect_url;
455 }
456
457 /**
458 * Reads flexform configuration and merge it with $this->conf
459 *
460 * @return void
461 */
462 protected function mergeflexFormValuesIntoConf() {
463 $flex = array();
464 if ($this->flexFormValue('showForgotPassword', 'sDEF')) {
465 $flex['showForgotPassword'] = $this->flexFormValue('showForgotPassword','sDEF');
466 }
467
468 if ($this->flexFormValue('showPermaLogin', 'sDEF')) {
469 $flex['showPermaLogin'] = $this->flexFormValue('showPermaLogin', 'sDEF');
470 }
471
472 if ($this->flexFormValue('pages', 'sDEF')) {
473 $flex['pages'] = $this->flexFormValue('pages', 'sDEF');
474 }
475
476 if ($this->flexFormValue('recursive', 'sDEF')) {
477 $flex['recursive'] = $this->flexFormValue('recursive', 'sDEF');
478 }
479
480 if ($this->flexFormValue('templateFile', 'sDEF')) {
481 $flex['templateFile'] = $this->uploadDir . $this->flexFormValue('templateFile', 'sDEF');
482 }
483
484 if ($this->flexFormValue('redirectMode', 's_redirect')) {
485 $flex['redirectMode'] = $this->flexFormValue('redirectMode', 's_redirect');
486 }
487
488 if ($this->flexFormValue('redirectFirstMethod', 's_redirect')) {
489 $flex['redirectFirstMethod'] = $this->flexFormValue('redirectFirstMethod', 's_redirect');
490 }
491
492 if ($this->flexFormValue('redirectDisable', 's_redirect')) {
493 $flex['redirectDisable'] = $this->flexFormValue('redirectDisable', 's_redirect');
494 }
495
496 if ($this->flexFormValue('redirectPageLogin', 's_redirect')) {
497 $flex['redirectPageLogin'] = $this->flexFormValue('redirectPageLogin', 's_redirect');
498 }
499
500 if ($this->flexFormValue('redirectPageLoginError', 's_redirect')) {
501 $flex['redirectPageLoginError'] = $this->flexFormValue('redirectPageLoginError','s_redirect');
502 }
503
504 if ($this->flexFormValue('redirectPageLogout', 's_redirect')) {
505 $flex['redirectPageLogout'] = $this->flexFormValue('redirectPageLogout', 's_redirect');
506 }
507
508 $pid = $flex['pages'] ? $this->pi_getPidList($flex['pages'], $flex['recursive']) : 0;
509 if ($pid > 0) {
510 $flex['storagePid'] = $pid;
511 }
512
513 $this->conf = array_merge($this->conf, $flex);
514 }
515
516 /**
517 * Loads a variable from the flexform
518 *
519 * @param string name of variable
520 * @param string name of sheet
521 * @return string value of var
522 */
523 protected function flexFormValue($var, $sheet) {
524 return $this->pi_getFFvalue($this->cObj->data['pi_flexform'], $var,$sheet);
525 }
526
527 /**
528 * Generate link with typolink function
529 *
530 * @param string linktext
531 * @param array link vars
532 * @param boolean true: returns only url false (default) returns the link)
533 *
534 * @return string link or url
535 */
536 protected function getPageLink($label, $piVars,$returnUrl = false) {
537 $additionalParams = '';
538
539 if (count($piVars)) {
540 foreach($piVars as $key=>$val) {
541 $additionalParams .= '&' . $key . '=' . $val;
542 }
543 }
544 // should GETvars be preserved?
545 if ($this->conf['preserveGETvars']) {
546 $additionalParams .= $this->getPreserveGetVars();
547 }
548
549 $this->conf['linkConfig.']['parameter'] = $GLOBALS['TSFE']->id;
550 if ($additionalParams) {
551 $this->conf['linkConfig.']['additionalParams'] = $additionalParams;
552 }
553
554 if ($returnUrl) {
555 return htmlspecialchars($this->cObj->typolink_url($this->conf['linkConfig.']));
556 } else {
557 return $this->cObj->typolink($label,$this->conf['linkConfig.']);
558 }
559 }
560
561 /**
562 * Is used by TS-setting preserveGETvars
563 * possible values are "all" or a commaseperated list of GET-vars
564 * they are used as additionalParams for link generation
565 *
566 * @return string additionalParams-string
567 */
568 protected function getPreserveGetVars() {
569
570 $params = '';
571 $preserveVars =! ($this->conf['preserveGETvars'] || $this->conf['preserveGETvars']=='all' ? array() : implode(',', (array)$this->conf['preserveGETvars']));
572 $getVars = t3lib_div::_GET();
573
574 foreach ($getVars as $key => $val) {
575 if (stristr($key,$this->prefixId) === false) {
576 if (is_array($val)) {
577 foreach ($val as $key1 => $val1) {
578 if ($this->conf['preserveGETvars'] == 'all' || in_array($key . '[' . $key1 .']', $preserveVars)) {
579 $params .= '&' . $key . '[' . $key1 . ']=' . $val1;
580 }
581 }
582 } else {
583 if (!in_array($key, array('id','no_cache','logintype','redirect_url','cHash'))) {
584 $params .= '&' . $key . '=' . $val;
585 }
586 }
587 }
588 }
589 return $params;
590 }
591
592 /**
593 * Is used by forgot password - function with md5 option.
594 *
595 * @author Bernhard Kraft
596 *
597 * @param int length of new password
598 * @return string new password
599 */
600 protected function generatePassword($len) {
601 $pass = '';
602 while ($len--) {
603 $char = rand(0,35);
604 if ($char < 10) {
605 $pass .= '' . $char;
606 } else {
607 $pass .= chr($char - 10 + 97);
608 }
609 }
610 return $pass;
611 }
612
613 /**
614 * Returns the header / message value from flexform if present, else from locallang.xml
615 *
616 * @param string label name
617 * @param string TS stdWrap array
618 * @return string label text
619 */
620 protected function getDisplayText($label, $stdWrapArray=array()) {
621 $text = $this->flexFormValue($label, 's_messages') ? $this->cObj->stdWrap($this->flexFormValue($label, 's_messages'), $stdWrapArray) : $this->cObj->stdWrap($this->pi_getLL('ll_'.$label, '', 1), $stdWrapArray);
622 $replace = $this->getUserFieldMarkers();
623 return strtr($text, $replace);
624 }
625
626 /**
627 * Returns Array of markers filled with user fields
628 *
629 * @return array marker array
630 */
631 protected function getUserFieldMarkers() {
632 $marker = array();
633 // replace markers with fe_user data
634 if ($GLOBALS['TSFE']->fe_user->user) {
635 // all fields of fe_user will be replaced, scheme is ###FEUSER_FIELDNAME###
636 foreach ($GLOBALS['TSFE']->fe_user->user as $field => $value) {
637 $marker['###FEUSER_' . t3lib_div::strtoupper($field) . '###'] = $this->cObj->stdWrap($value, $this->conf['userfields.'][$field . '.']);
638 }
639 // add ###USER### for compatibility
640 $marker['###USER###'] = $marker['###FEUSER_USERNAME###'];
641 }
642 return $marker;
643 }
644 }
645
646
647
648 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/felogin/pi1/class.tx_felogin_pi1.php']) {
649 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/felogin/pi1/class.tx_felogin_pi1.php']);
650 }
651
652 ?>