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