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