Fixed #11356: Backend Login News is not templateable
[Packages/TYPO3.CMS.git] / typo3 / index.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 * Login-screen of TYPO3.
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 December/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 * 87: class SC_index
42 * 120: function init()
43 * 159: function main()
44 * 268: function printContent()
45 *
46 * SECTION: Various functions
47 * 292: function makeLoginForm()
48 * 337: function makeLogoutForm()
49 * 379: function wrapLoginForm($content)
50 * 438: function checkRedirect()
51 * 495: function makeInterfaceSelectorBox()
52 * 549: function makeCopyrightNotice()
53 * 582: function makeLoginBoxImage()
54 * 622: function makeLoginNews()
55 *
56 * TOTAL FUNCTIONS: 11
57 * (This index is automatically created/updated by the extension "extdeveval")
58 *
59 */
60
61
62 define('TYPO3_PROCEED_IF_NO_USER', 1);
63 require('init.php');
64 require('template.php');
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 /**
81 * Script Class for rendering the login form
82 *
83 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
84 * @package TYPO3
85 * @subpackage core
86 */
87 class SC_index {
88
89 // Internal, GPvars:
90 var $redirect_url; // GPvar: redirect_url; The URL to redirect to after login.
91 var $GPinterface; // GPvar: Defines which interface to load (from interface selector)
92 var $u; // GPvar: preset username
93 var $p; // GPvar: preset password
94 var $L; // GPvar: If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it
95 var $loginRefresh; // Login-refresh boolean; The backend will call this script with this value set when the login is close to being expired and the form needs to be redrawn.
96 var $commandLI; // Value of forms submit button for login.
97
98 // Internal, static:
99 var $redirectToURL; // Set to the redirect URL of the form (may be redirect_url or "backend.php")
100
101 // Internal, dynamic:
102 var $content; // Content accumulation
103
104 var $interfaceSelector; // A selector box for selecting value for "interface" may be rendered into this variable
105 var $interfaceSelector_jump; // A selector box for selecting value for "interface" may be rendered into this variable - this will have an onchange action which will redirect the user to the selected interface right away
106 var $interfaceSelector_hidden; // A hidden field, if the interface is not set.
107 var $addFields_hidden = ''; // Additional hidden fields to be placed at the login form
108
109 // sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
110 var $loginSecurityLevel = 'superchallenged';
111
112
113
114
115 /**
116 * Initialize the login box. Will also react on a &L=OUT flag and exit.
117 *
118 * @return void
119 */
120 function init() {
121 // We need a PHP session session for most login levels
122 session_start();
123
124 $this->redirect_url = t3lib_div::_GP('redirect_url');
125 $this->GPinterface = t3lib_div::_GP('interface');
126
127 // Grabbing preset username and password, for security reasons this feature only works if SSL is used
128 if (t3lib_div::getIndpEnv('TYPO3_SSL')) {
129 $this->u = t3lib_div::_GP('u');
130 $this->p = t3lib_div::_GP('p');
131 }
132
133 // If "L" is "OUT", then any logged in is logged out. If redirect_url is given, we redirect to it
134 $this->L = t3lib_div::_GP('L');
135
136 // Login
137 $this->loginRefresh = t3lib_div::_GP('loginRefresh');
138
139 // Value of "Login" button. If set, the login button was pressed.
140 $this->commandLI = t3lib_div::_GP('commandLI');
141
142 // sets the level of security from conf vars
143 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
144 $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
145 }
146
147 // try to get the preferred browser language
148 $preferredBrowserLanguage = $GLOBALS['LANG']->csConvObj->getPreferredClientLanguage(t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE'));
149 // if we found a $preferredBrowserLanguage and it is not the default language and no be_user is logged in
150 // initialize $GLOBALS['LANG'] again with $preferredBrowserLanguage
151 if ($preferredBrowserLanguage != 'default' && !$GLOBALS['BE_USER']->user['uid']) {
152 $GLOBALS['LANG']->init($preferredBrowserLanguage);
153 }
154 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_login.xml');
155
156 // check if labels from $GLOBALS['TYPO3_CONF_VARS']['BE']['loginLabels'] were changed,
157 // and merge them to $GLOBALS['LOCAL_LANG'] if needed
158 $this->mergeOldLoginLabels();
159
160 // Setting the redirect URL to "backend.php" if no alternative input is given
161 $this->redirectToURL = ($this->redirect_url ? $this->redirect_url : 'backend.php');
162
163
164 // Do a logout if the command is set
165 if ($this->L == 'OUT' && is_object($GLOBALS['BE_USER'])) {
166 $GLOBALS['BE_USER']->logoff();
167 if ($this->redirect_url) {
168 t3lib_div::redirect($this->redirect_url);
169 }
170 exit;
171 }
172 }
173
174
175 /**
176 * Main function - creating the login/logout form
177 *
178 * @return void
179 */
180 function main() {
181 global $TBE_TEMPLATE, $TYPO3_CONF_VARS, $BE_USER;
182
183 // Initialize template object:
184 $TBE_TEMPLATE->bodyTagAdditions = ' onload="startUp();"';
185 $TBE_TEMPLATE->moduleTemplate = $TBE_TEMPLATE->getHtmlTemplate('templates/login.html');
186
187 // Set JavaScript for creating a MD5 hash of the password:
188 $TBE_TEMPLATE->JScode.= $this->getJScode();
189
190 // Checking, if we should make a redirect.
191 // Might set JavaScript in the header to close window.
192 $this->checkRedirect();
193
194 // Initialize interface selectors:
195 $this->makeInterfaceSelectorBox();
196
197 // Creating form based on whether there is a login or not:
198 if (!$BE_USER->user['uid']) {
199 $TBE_TEMPLATE->form = $this->startForm();
200 $loginForm = $this->makeLoginForm();
201 } else {
202 $TBE_TEMPLATE->form = '
203 <form action="index.php" method="post" name="loginform">
204 <input type="hidden" name="login_status" value="logout" />
205 ';
206 $loginForm = $this->makeLogoutForm();
207 }
208
209 // Starting page:
210 $this->content.=$TBE_TEMPLATE->startPage('TYPO3 Login: '.$TYPO3_CONF_VARS['SYS']['sitename']);
211
212 // Add login form:
213 $this->content.=$this->wrapLoginForm($loginForm);
214
215 $this->content.= $TBE_TEMPLATE->endPage();
216 }
217
218 /**
219 * Outputting the accumulated content to screen
220 *
221 * @return void
222 */
223 function printContent() {
224 echo $this->content;
225 }
226
227 /*****************************
228 *
229 * Various functions
230 *
231 ******************************/
232
233 /**
234 * Creates the login form
235 * This is drawn when NO login exists.
236 *
237 * @return string HTML output
238 */
239 function makeLoginForm() {
240 $content = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGIN_FORM###');
241 $markers = array(
242 'VALUE_USERNAME' => htmlspecialchars($this->u),
243 'VALUE_PASSWORD' => htmlspecialchars($this->p),
244 'VALUE_SUBMIT' => $GLOBALS['LANG']->getLL('labels.submitLogin', true),
245 );
246
247 // show an error message if the login command was successful already, otherwise remove the subpart
248 if (!$this->commandLI) {
249 $content = t3lib_parsehtml::substituteSubpart($content, '###LOGIN_ERROR###', '');
250 } else {
251 $markers['ERROR_MESSAGE'] = $GLOBALS['LANG']->getLL('error.login', true);
252 }
253
254
255 // remove the interface selector markers if it's not available
256 if (!($this->interfaceSelector && !$this->loginRefresh)) {
257 $content = t3lib_parsehtml::substituteSubpart($content, '###INTERFACE_SELECTOR###', '');
258 } else {
259 $markers['LABEL_INTERFACE'] = $GLOBALS['LANG']->getLL('labels.interface', true);
260 $markers['VALUE_INTERFACE'] = $this->interfaceSelector_jump;
261 }
262
263 return t3lib_parsehtml::substituteMarkerArray($content, $markers, '###|###');
264 }
265
266
267 /**
268 * Creates the logout form
269 * This is drawn if a user login already exists.
270 *
271 * @return string HTML output
272 */
273 function makeLogoutForm() {
274 $content = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGOUT_FORM###');
275 $markers = array(
276 'LABEL_USERNAME' => $GLOBALS['LANG']->getLL('labels.username', true),
277 'VALUE_USERNAME' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
278 'VALUE_SUBMIT' => $GLOBALS['LANG']->getLL('labels.submitLogout', true),
279 );
280
281 // remove the interface selector markers if it's not available
282 if (!$this->interfaceSelector_jump) {
283 $content = t3lib_parsehtml::substituteSubpart($content, '###INTERFACE_SELECTOR###', '');
284 } else {
285 $markers['LABEL_INTERFACE'] = $GLOBALS['LANG']->getLL('labels.interface', true);
286 $markers['VALUE_INTERFACE'] = $this->interfaceSelector_jump;
287 }
288
289 return t3lib_parsehtml::substituteMarkerArray($content, $markers, '###|###');
290 }
291
292
293 /**
294 * Wrapping the login form table in another set of tables etc:
295 *
296 * @param string HTML content for the login form
297 * @return string The HTML for the page.
298 */
299 function wrapLoginForm($content) {
300 $mainContent = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###PAGE###');
301
302 if ($GLOBALS['TBE_STYLES']['logo_login']) {
303 $logo = '<img src="'.htmlspecialchars($GLOBALS['BACK_PATH'] . $GLOBALS['TBE_STYLES']['logo_login']) . '" alt="" />';
304 } else {
305 $logo = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/typo3logo.gif','width="123" height="34"').' alt="" />';
306 }
307
308 $markers = array(
309 'LOGO' => $logo,
310 'LOGINBOX_IMAGE' => $this->makeLoginBoxImage(),
311 'FORM' => $content,
312 'NEWS' => $this->makeLoginNews(),
313 'COPYRIGHT' => $this->makeCopyrightNotice(),
314 'CSS_ERRORCLASS' => ($this->commandLI ? ' class="error"' : ''),
315
316 // the labels will be replaced later on, thus the other parts above
317 // can use these markers as well and it will be replaced
318 'HEADLINE' => $GLOBALS['LANG']->getLL('headline', true),
319 'INFO' => $GLOBALS['LANG']->getLL('info.jscookies', true),
320 'ERROR_JAVASCRIPT' => $GLOBALS['LANG']->getLL('error.javascript', true),
321 'ERROR_COOKIES' => $GLOBALS['LANG']->getLL('error.cookies', true),
322 'LABEL_DONATELINK' => $GLOBALS['LANG']->getLL('labels.donate', true),
323 'LABEL_USERNAME' => $GLOBALS['LANG']->getLL('labels.username', true),
324 'LABEL_PASSWORD' => $GLOBALS['LANG']->getLL('labels.password', true),
325
326 // global variables will now be replaced (at last)
327 'SITENAME' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
328 );
329 return t3lib_parsehtml::substituteMarkerArray($mainContent, $markers, '###|###');
330 }
331
332
333 /**
334 * Checking, if we should perform some sort of redirection OR closing of windows.
335 *
336 * @return void
337 */
338 function checkRedirect() {
339 global $BE_USER,$TBE_TEMPLATE;
340
341 // Do redirect:
342 // If a user is logged in AND a) if either the login is just done (commandLI) or b) a loginRefresh is done or c) the interface-selector is NOT enabled (If it is on the other hand, it should not just load an interface, because people has to choose then...)
343 if ($BE_USER->user['uid'] && ($this->commandLI || $this->loginRefresh || !$this->interfaceSelector)) {
344
345 // If no cookie has been set previously we tell people that this is a problem. This assumes that a cookie-setting script (like this one) has been hit at least once prior to this instance.
346 if (!$_COOKIE[$BE_USER->name]) {
347 if ($this->commandLI=='setCookie') {
348 // we tried it a second time but still no cookie
349 // 26/4 2005: This does not work anymore, because the saving of challenge values in $_SESSION means the system will act as if the password was wrong.
350 t3lib_BEfunc::typo3PrintError ('Login-error',"Yeah, that's a classic. No cookies, no TYPO3.<br /><br />Please accept cookies from TYPO3 - otherwise you'll not be able to use the system.",0);
351 exit;
352 } else {
353 // try it once again - that might be needed for auto login
354 $this->redirectToURL = 'index.php?commandLI=setCookie';
355 }
356 }
357
358 if (($redirectToURL = (string)$BE_USER->getTSConfigVal('auth.BE.redirectToURL'))) {
359 $this->redirectToURL = $redirectToURL;
360 $this->GPinterface = '';
361 }
362
363 // store interface
364 $BE_USER->uc['interfaceSetup'] = $this->GPinterface;
365 $BE_USER->writeUC();
366
367 // Based on specific setting of interface we set the redirect script:
368 switch ($this->GPinterface) {
369 case 'backend':
370 $this->redirectToURL = 'backend.php';
371 break;
372 case 'backend_old':
373 $this->redirectToURL = 'alt_main.php';
374 break;
375 case 'frontend':
376 $this->redirectToURL = '../';
377 break;
378 }
379
380 // If there is a redirect URL AND if loginRefresh is not set...
381 if (!$this->loginRefresh) {
382 header('Location: '.t3lib_div::locationHeaderUrl($this->redirectToURL));
383 exit;
384 } else {
385 $TBE_TEMPLATE->JScode.=$TBE_TEMPLATE->wrapScriptTags('
386 if (parent.opener && parent.opener.busy) {
387 parent.opener.busy.loginRefreshed();
388 parent.close();
389 }
390 ');
391 }
392
393 } elseif (!$BE_USER->user['uid'] && $this->commandLI) {
394 sleep(5); // Wrong password, wait for 5 seconds
395 }
396 }
397
398 /**
399 * Making interface selector:
400 *
401 * @return void
402 */
403 function makeInterfaceSelectorBox() {
404 global $TYPO3_CONF_VARS;
405
406 // Reset variables:
407 $this->interfaceSelector = '';
408 $this->interfaceSelector_hidden='';
409 $this->interfaceSelector_jump = '';
410
411 // If interfaces are defined AND no input redirect URL in GET vars:
412 if ($TYPO3_CONF_VARS['BE']['interfaces'] && ($this->commandLI || !$this->redirect_url)) {
413 $parts = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['BE']['interfaces']);
414 if (count($parts)>1) { // Only if more than one interface is defined will we show the selector:
415
416 // Initialize:
417 $tempLabels = t3lib_div::trimExplode(',', $GLOBALS['LANG']->getLL('availableInterfaces'));
418 $labels=array();
419
420 $labels['backend'] = $tempLabels[0];
421 $labels['backend_old'] = $tempLabels[2];
422 $labels['frontend'] = $tempLabels[1];
423
424 $jumpScript=array();
425 $jumpScript['backend'] = 'backend.php';
426 $jumpScript['backend_old'] = 'alt_main.php';
427 $jumpScript['frontend'] = '../';
428
429 // Traverse the interface keys:
430 foreach($parts as $valueStr) {
431 $this->interfaceSelector.='
432 <option value="'.htmlspecialchars($valueStr).'"'.(t3lib_div::_GP('interface')==htmlspecialchars($valueStr) ? ' selected="selected"' : '').'>'.htmlspecialchars($labels[$valueStr]).'</option>';
433 $this->interfaceSelector_jump.='
434 <option value="'.htmlspecialchars($jumpScript[$valueStr]).'">'.htmlspecialchars($labels[$valueStr]).'</option>';
435 }
436 $this->interfaceSelector='
437 <select id="interfaceselector" name="interface" class="c-interfaceselector">'.$this->interfaceSelector.'
438 </select>';
439 $this->interfaceSelector_jump='
440 <select id="interfaceselector" name="interface" class="c-interfaceselector" onchange="window.location.href=this.options[this.selectedIndex].value;">'.$this->interfaceSelector_jump.'
441 </select>';
442
443 } else { // If there is only ONE interface value set:
444
445 $this->interfaceSelector_hidden='<input type="hidden" name="interface" value="'.trim($TYPO3_CONF_VARS['BE']['interfaces']).'" />';
446 }
447 }
448 }
449
450 /**
451 * COPYRIGHT notice
452 *
453 * Warning:
454 * DO NOT prevent this notice from being shown in ANY WAY.
455 * According to the GPL license an interactive application must show such a notice on start-up ('If the program is interactive, make it output a short notice... ' - see GPL.txt)
456 * Therefore preventing this notice from being properly shown is a violation of the license, regardless of whether you remove it or use a stylesheet to obstruct the display.
457 *
458 * @return string Text/Image (HTML) for copyright notice.
459 */
460 function makeCopyrightNotice() {
461
462 // Get values from TYPO3_CONF_VARS:
463 $loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyProvider']));
464 $loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyURL']));
465 $loginImageSmall = (trim($GLOBALS['TBE_STYLES']['loginBoxImageSmall'])) ? trim($GLOBALS['TBE_STYLES']['loginBoxImageSmall']) : 'gfx/loginlogo_transp.gif';
466
467 // Make warranty note:
468 if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10) {
469 $warrantyNote='Warranty is supplied by '.htmlspecialchars($loginCopyrightWarrantyProvider).'; <a href="'.htmlspecialchars($loginCopyrightWarrantyURL).'" target="_blank">click for details.</a>';
470 } else {
471 $warrantyNote='TYPO3 comes with ABSOLUTELY NO WARRANTY; <a href="http://typo3.com/1316.0.html" target="_blank">click for details.</a>';
472 }
473
474 // Compile full copyright notice:
475 $copyrightNotice = '<a href="http://typo3.com/" target="_blank">'.
476 '<img src="'.$loginImageSmall.'" alt="TYPO3 logo" align="left" />'.
477 'TYPO3 CMS'.($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightShowVersion']?' ver. '.htmlspecialchars($GLOBALS['TYPO_VERSION']):'').
478 '</a>. '.
479 'Copyright &copy; '.TYPO3_copyright_year.' Kasper Sk&#229;rh&#248;j. Extensions are copyright of their respective owners. '.
480 'Go to <a href="http://typo3.com/" target="_blank">http://typo3.com/</a> for details. '.
481 $warrantyNote.' '.
482 'This is free software, and you are welcome to redistribute it under certain conditions; <a href="http://typo3.com/1316.0.html" target="_blank">click for details</a>. '.
483 'Obstructing the appearance of this notice is prohibited by law.';
484
485 // Return notice:
486 return $copyrightNotice;
487 }
488
489 /**
490 * Returns the login box image, whether the default or an image from the rotation folder.
491 *
492 * @return string HTML image tag.
493 */
494 function makeLoginBoxImage() {
495 $loginboxImage = '';
496 if ($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']) { // Look for rotation image folder:
497 $absPath = t3lib_div::resolveBackPath(PATH_typo3.$GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']);
498
499 // Get rotation folder:
500 $dir = t3lib_div::getFileAbsFileName($absPath);
501 if ($dir && @is_dir($dir)) {
502
503 // Get files for rotation into array:
504 $files = t3lib_div::getFilesInDir($dir,'png,jpg,gif');
505
506 // Pick random file:
507 $randImg = array_rand($files, 1);
508
509 // Get size of random file:
510 $imgSize = @getimagesize($dir.$files[$randImg]);
511
512 $imgAuthor = is_array($GLOBALS['TBE_STYLES']['loginBoxImage_author'])&&$GLOBALS['TBE_STYLES']['loginBoxImage_author'][$files[$randImg]] ? htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_author'][$files[$randImg]]) : '';
513
514 // Create image tag:
515 if (is_array($imgSize)) {
516 $loginboxImage = '<img src="'.htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder'].$files[$randImg]).'" '.$imgSize[3].' id="loginbox-image" alt="'.$imgAuthor.'" title="'.$imgAuthor.'" />';
517 }
518 }
519 } else { // If no rotation folder configured, print default image:
520
521 if (strstr(TYPO3_version,'-dev')) { // development version
522 $loginImage = 'loginbox_image_dev.png';
523 $imagecopy = 'You are running a development version of TYPO3 '.TYPO3_branch;
524 } else {
525 $loginImage = 'loginbox_image.jpg';
526 $imagecopy = 'Photo by J.C. Franca (www.digitalphoto.com.br)';
527 }
528 $loginboxImage = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/'.$loginImage,'width="200" height="133"').' id="loginbox-image" alt="'.$imagecopy.'" title="'.$imagecopy.'" />';
529 }
530
531 // Return image tag:
532 return $loginboxImage;
533 }
534
535 /**
536 * Make login news - renders the HTML content for a list of news shown under
537 * the login form. News data is added through $TYPO3_CONF_VARS
538 *
539 * @return string HTML content
540 * @credits Idea by Jan-Hendrik Heuing
541 */
542 function makeLoginNews() {
543 $newsContent = '';
544
545 // Traverse news array IF there are records in it:
546 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']) && count($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'])) {
547
548 // get the main news template, and replace the subpart after looped through
549 $newsContent = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGIN_NEWS###');
550 $newsItemTemplate = t3lib_parsehtml::getSubpart($newsContent, '###NEWS_ITEM###');
551
552 $newsItemContent = '';
553 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] as $newsItem) {
554 $newsItemMarker = array(
555 '###HEADER###' => htmlspecialchars($newsItem['header']),
556 '###DATE###' => htmlspecialchars($newsItem['date']),
557 '###CONTENT###' => trim($newsItem['content'])
558 );
559 $newsItemContent .= t3lib_parsehtml::substituteMarkerArray($newsItemTemplate, $newsItemMarker);
560 }
561
562 $title = ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNewsTitle'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['loginNewsTitle'] : $GLOBALS['LANG']->getLL('newsheadline'));
563
564 $newsContent = t3lib_parsehtml::substituteMarker($newsContent, '###NEWS_HEADLINE###', htmlspecialchars($title));
565 $newsContent = t3lib_parsehtml::substituteSubpart($newsContent, '###NEWS_ITEM###', $newsItemContent);
566 }
567
568 return $newsContent;
569 }
570
571 /**
572 * Returns the form tag
573 *
574 * @return string Opening form tag string
575 */
576 function startForm() {
577 $output = '';
578
579 // The form defaults to 'no login'. This prevents plain
580 // text logins to the Backend. The 'sv' extension changes the form to
581 // use superchallenged method and rsaauth extension makes rsa authetication.
582 $form = '<form action="index.php" method="post" name="loginform" ' .
583 'onsubmit="alert(\'No authentication methods available. Please, ' .
584 'contact your TYPO3 administrator.\');return false">';
585
586 // Call hooks. If they do not return anything, we fail to login
587 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginFormHook'])) {
588 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginFormHook'] as $function) {
589 $params = array();
590 $formCode = t3lib_div::callUserFunction($function, $params, $this);
591 if ($formCode) {
592 $form = $formCode;
593 break;
594 }
595 }
596 }
597
598 $output .= $form .
599 '<input type="hidden" name="login_status" value="login" />' .
600 '<input type="hidden" name="userident" value="" />' .
601 '<input type="hidden" name="redirect_url" value="'.htmlspecialchars($this->redirectToURL).'" />' .
602 '<input type="hidden" name="loginRefresh" value="'.htmlspecialchars($this->loginRefresh).'" />' .
603 $this->interfaceSelector_hidden . $this->addFields_hidden;
604
605 return $output;
606 }
607
608 /**
609 * Outputs an empty string. This function is obsolete and kept for the
610 * compatibility only.
611 *
612 * @param string $unused Unused
613 * @return string HTML output
614 * @deprecated since TYPO3 4.3, all the functionality was put in $this->startForm() and $this->addFields_hidden
615 */
616 function getHiddenFields($unused = '') {
617 t3lib_div::logDeprecatedFunction();
618 return '';
619 }
620
621 /**
622 * Creates JavaScript for the login form
623 *
624 * @return string JavaScript code
625 */
626 function getJScode() {
627 $JSCode = '';
628 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginScriptHook'])) {
629 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginScriptHook'] as $function) {
630 $params = array();
631 $JSCode = t3lib_div::callUserFunction($function, $params, $this);
632 if ($JSCode) {
633 break;
634 }
635 }
636 }
637 $JSCode .= $GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
638 function startUp() {
639 // If the login screen is shown in the login_frameset window for re-login, then try to get the username of the current/former login from opening windows main frame:
640 if (parent.opener && parent.opener.TS && parent.opener.TS.username && document.loginform && document.loginform.username) {
641 document.loginform.username.value = parent.opener.TS.username;
642 }
643
644 // Wait a few millisecons before calling checkFocus(). This might be necessary because some browsers need some time to auto-fill in the form fields
645 window.setTimeout("checkFocus()", 50);
646 }
647
648 // This moves focus to the right input field:
649 function checkFocus() {
650 // If for some reason there already is a username in the username form field, move focus to the password field:
651 if (document.loginform.username && document.loginform.username.value == "") {
652 document.loginform.username.focus();
653 } else if (document.loginform.p_field && document.loginform.p_field.type!="hidden") {
654 document.loginform.p_field.focus();
655 }
656 }
657 ');
658
659 return $JSCode;
660 }
661
662
663 /**
664 * Checks if labels from $GLOBALS['TYPO3_CONF_VARS']['BE']['loginLabels'] were changed, and merge them to $GLOBALS['LOCAL_LANG'] if needed
665 *
666 * This method keeps backwards compatibility, if you modified your
667 * labels with the install tool, we recommend to transfer this labels to a locallang.xml file
668 * using the llxml extension
669 *
670 * @return void
671 */
672 protected function mergeOldLoginLabels() {
673 // Getting login labels
674 $oldLoginLabels = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['loginLabels']);
675 if ($oldLoginLabels != '') {
676 // md5 hash of the default loginLabels string
677 $defaultOldLoginLabelsHash = 'bcf0d32e58c6454ea50c6c956f1f18f0';
678 // compare loginLabels from TYPO3_CONF_VARS to default value
679 if (md5($oldLoginLabels) != $defaultOldLoginLabelsHash) {
680 $lang = $GLOBALS['LANG']->lang;
681 $oldLoginLabelArray = explode('|',$oldLoginLabels);
682 $overrideLabelKeys = array(
683 'labels.username' => $oldLoginLabelArray[0],
684 'labels.password' => $oldLoginLabelArray[1],
685 'labels.interface' => $oldLoginLabelArray[2],
686 'labels.submitLogin' => $oldLoginLabelArray[3],
687 'labels.submitLogout' => $oldLoginLabelArray[4],
688 'availableInterfaces' => $oldLoginLabelArray[5],
689 'headline' => $oldLoginLabelArray[6],
690 'info.jscookies' => $oldLoginLabelArray[7],
691 'newsheadline' => $oldLoginLabelArray[8],
692 'error.login' => $oldLoginLabelArray[9],
693 );
694 if (!is_array($GLOBALS['LOCAL_LANG'][$lang])) {
695 $GLOBALS['LOCAL_LANG'][$lang] = array();
696 }
697 // now override the labels from the LOCAL_LANG with the TYPO3_CONF_VARS
698 foreach ($overrideLabelKeys as $labelKey => $label) {
699 $GLOBALS['LOCAL_LANG'][$lang][$labelKey] = $GLOBALS['LOCAL_LANG']['default'][$labelKey] = $label;
700 }
701 }
702 }
703 }
704 }
705
706
707 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']) {
708 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']);
709 }
710
711
712
713 // Make instance:
714 $SOBE = t3lib_div::makeInstance('SC_index');
715 $SOBE->init();
716 $SOBE->main();
717 $SOBE->printContent();
718
719 ?>