[TASK] Language handling: splitLabels and locallang.php should be removed
[Packages/TYPO3.CMS.git] / typo3 / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * Revised for TYPO3 3.6 December/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36
37 define('TYPO3_PROCEED_IF_NO_USER', 1);
38 require('init.php');
39 require('template.php');
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 /**
56 * Script Class for rendering the login form
57 *
58 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
59 * @package TYPO3
60 * @subpackage core
61 */
62 class SC_index {
63
64 // Internal, GPvars:
65 var $redirect_url; // GPvar: redirect_url; The URL to redirect to after login.
66 var $GPinterface; // GPvar: Defines which interface to load (from interface selector)
67 var $u; // GPvar: preset username
68 var $p; // GPvar: preset password
69 var $L; // GPvar: If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it
70 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.
71 var $commandLI; // Value of forms submit button for login.
72
73 // Internal, static:
74 var $redirectToURL; // Set to the redirect URL of the form (may be redirect_url or "backend.php")
75
76 // Internal, dynamic:
77 var $content; // Content accumulation
78
79 var $interfaceSelector; // A selector box for selecting value for "interface" may be rendered into this variable
80 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
81 var $interfaceSelector_hidden; // A hidden field, if the interface is not set.
82 var $addFields_hidden = ''; // Additional hidden fields to be placed at the login form
83
84 // sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
85 var $loginSecurityLevel = 'superchallenged';
86
87
88
89
90 /**
91 * Initialize the login box. Will also react on a &L=OUT flag and exit.
92 *
93 * @return void
94 */
95 function init() {
96 // We need a PHP session session for most login levels
97 session_start();
98
99 $this->redirect_url = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('redirect_url'));
100 $this->GPinterface = t3lib_div::_GP('interface');
101
102 // Grabbing preset username and password, for security reasons this feature only works if SSL is used
103 if (t3lib_div::getIndpEnv('TYPO3_SSL')) {
104 $this->u = t3lib_div::_GP('u');
105 $this->p = t3lib_div::_GP('p');
106 }
107
108 // If "L" is "OUT", then any logged in is logged out. If redirect_url is given, we redirect to it
109 $this->L = t3lib_div::_GP('L');
110
111 // Login
112 $this->loginRefresh = t3lib_div::_GP('loginRefresh');
113
114 // Value of "Login" button. If set, the login button was pressed.
115 $this->commandLI = t3lib_div::_GP('commandLI');
116
117 // sets the level of security from conf vars
118 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
119 $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
120 }
121
122 // try to get the preferred browser language
123 $preferredBrowserLanguage = $GLOBALS['LANG']->csConvObj->getPreferredClientLanguage(t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE'));
124 // if we found a $preferredBrowserLanguage and it is not the default language and no be_user is logged in
125 // initialize $GLOBALS['LANG'] again with $preferredBrowserLanguage
126 if ($preferredBrowserLanguage != 'default' && !$GLOBALS['BE_USER']->user['uid']) {
127 $GLOBALS['LANG']->init($preferredBrowserLanguage);
128 }
129 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_login.xml');
130
131 // check if labels from $GLOBALS['TYPO3_CONF_VARS']['BE']['loginLabels'] were changed,
132 // and merge them to $GLOBALS['LOCAL_LANG'] if needed
133 $this->mergeOldLoginLabels();
134
135 // Setting the redirect URL to "backend.php" if no alternative input is given
136 $this->redirectToURL = ($this->redirect_url ? $this->redirect_url : 'backend.php');
137
138
139 // Do a logout if the command is set
140 if ($this->L == 'OUT' && is_object($GLOBALS['BE_USER'])) {
141 $GLOBALS['BE_USER']->logoff();
142 if ($this->redirect_url) {
143 t3lib_utility_Http::redirect($this->redirect_url);
144 }
145 exit;
146 }
147 }
148
149
150 /**
151 * Main function - creating the login/logout form
152 *
153 * @return void
154 */
155 function main() {
156 // Initialize template object:
157 $GLOBALS['TBE_TEMPLATE']->bodyTagAdditions = ' onload="startUp();"';
158 $GLOBALS['TBE_TEMPLATE']->moduleTemplate = $GLOBALS['TBE_TEMPLATE']->getHtmlTemplate('templates/login.html');
159
160 $GLOBALS['TBE_TEMPLATE']->getPageRenderer()->loadExtJS();
161 $GLOBALS['TBE_TEMPLATE']->getPageRenderer()->loadPrototype();
162 $GLOBALS['TBE_TEMPLATE']->getPageRenderer()->loadScriptaculous();
163
164 // Set JavaScript for creating a MD5 hash of the password:
165 $GLOBALS['TBE_TEMPLATE']->JScode.= $this->getJScode();
166
167 // Checking, if we should make a redirect.
168 // Might set JavaScript in the header to close window.
169 $this->checkRedirect();
170
171 // Initialize interface selectors:
172 $this->makeInterfaceSelectorBox();
173
174 // Creating form based on whether there is a login or not:
175 if (!$GLOBALS['BE_USER']->user['uid']) {
176 $GLOBALS['TBE_TEMPLATE']->form = $this->startForm();
177 $loginForm = $this->makeLoginForm();
178 } else {
179 $GLOBALS['TBE_TEMPLATE']->form = '
180 <form action="index.php" method="post" name="loginform">
181 <input type="hidden" name="login_status" value="logout" />
182 ';
183 $loginForm = $this->makeLogoutForm();
184 }
185
186 // Starting page:
187 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage('TYPO3 Login: ' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']), FALSE);
188
189 // Add login form:
190 $this->content.=$this->wrapLoginForm($loginForm);
191
192 $this->content.= $GLOBALS['TBE_TEMPLATE']->endPage();
193 }
194
195 /**
196 * Outputting the accumulated content to screen
197 *
198 * @return void
199 */
200 function printContent() {
201 echo $this->content;
202 }
203
204 /*****************************
205 *
206 * Various functions
207 *
208 ******************************/
209
210 /**
211 * Creates the login form
212 * This is drawn when NO login exists.
213 *
214 * @return string HTML output
215 */
216 function makeLoginForm() {
217 $content = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGIN_FORM###');
218 $markers = array(
219 'VALUE_USERNAME' => htmlspecialchars($this->u),
220 'VALUE_PASSWORD' => htmlspecialchars($this->p),
221 'VALUE_SUBMIT' => $GLOBALS['LANG']->getLL('labels.submitLogin', TRUE),
222 );
223
224 // show an error message if the login command was successful already, otherwise remove the subpart
225 if (!$this->commandLI) {
226 $content = t3lib_parsehtml::substituteSubpart($content, '###LOGIN_ERROR###', '');
227 } else {
228 $markers['ERROR_MESSAGE'] = $GLOBALS['LANG']->getLL('error.login', TRUE);
229 $markers['ERROR_LOGIN_TITLE'] = $GLOBALS['LANG']->getLL('error.login.title', TRUE);
230 $markers['ERROR_LOGIN_DESCRIPTION'] = $GLOBALS['LANG']->getLL('error.login.description', TRUE);
231 }
232
233
234 // remove the interface selector markers if it's not available
235 if (!($this->interfaceSelector && !$this->loginRefresh)) {
236 $content = t3lib_parsehtml::substituteSubpart($content, '###INTERFACE_SELECTOR###', '');
237 } else {
238 $markers['LABEL_INTERFACE'] = $GLOBALS['LANG']->getLL('labels.interface', TRUE);
239 $markers['VALUE_INTERFACE'] = $this->interfaceSelector;
240 }
241
242 return t3lib_parsehtml::substituteMarkerArray($content, $markers, '###|###');
243 }
244
245
246 /**
247 * Creates the logout form
248 * This is drawn if a user login already exists.
249 *
250 * @return string HTML output
251 */
252 function makeLogoutForm() {
253 $content = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGOUT_FORM###');
254 $markers = array(
255 'LABEL_USERNAME' => $GLOBALS['LANG']->getLL('labels.username', TRUE),
256 'VALUE_USERNAME' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
257 'VALUE_SUBMIT' => $GLOBALS['LANG']->getLL('labels.submitLogout', TRUE),
258 );
259
260 // remove the interface selector markers if it's not available
261 if (!$this->interfaceSelector_jump) {
262 $content = t3lib_parsehtml::substituteSubpart($content, '###INTERFACE_SELECTOR###', '');
263 } else {
264 $markers['LABEL_INTERFACE'] = $GLOBALS['LANG']->getLL('labels.interface', TRUE);
265 $markers['VALUE_INTERFACE'] = $this->interfaceSelector_jump;
266 }
267
268 return t3lib_parsehtml::substituteMarkerArray($content, $markers, '###|###');
269 }
270
271
272 /**
273 * Wrapping the login form table in another set of tables etc:
274 *
275 * @param string HTML content for the login form
276 * @return string The HTML for the page.
277 */
278 function wrapLoginForm($content) {
279 $mainContent = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###PAGE###');
280
281 if ($GLOBALS['TBE_STYLES']['logo_login']) {
282 $logo = '<img src="'.htmlspecialchars($GLOBALS['BACK_PATH'] . $GLOBALS['TBE_STYLES']['logo_login']) . '" alt="" />';
283 } else {
284 $logo = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/typo3logo.gif','width="123" height="34"').' alt="" />';
285 }
286
287 $markers = array(
288 'LOGO' => $logo,
289 'LOGINBOX_IMAGE' => $this->makeLoginBoxImage(),
290 'FORM' => $content,
291 'NEWS' => $this->makeLoginNews(),
292 'COPYRIGHT' => $this->makeCopyrightNotice(),
293 'CSS_ERRORCLASS' => ($this->commandLI ? ' class="error"' : ''),
294 'CSS_OPENIDCLASS' => 't3-login-openid-' . (t3lib_extMgm::isLoaded('openid') ? 'enabled' : 'disabled'),
295
296 // the labels will be replaced later on, thus the other parts above
297 // can use these markers as well and it will be replaced
298 'HEADLINE' => $GLOBALS['LANG']->getLL('headline', TRUE),
299 'INFO_ABOUT' => $GLOBALS['LANG']->getLL('info.about', TRUE),
300 'INFO_RELOAD' => $GLOBALS['LANG']->getLL('info.reset', TRUE),
301 'INFO' => $GLOBALS['LANG']->getLL('info.cookies_and_js', TRUE),
302 'ERROR_JAVASCRIPT' => $GLOBALS['LANG']->getLL('error.javascript', TRUE),
303 'ERROR_COOKIES' => $GLOBALS['LANG']->getLL('error.cookies', TRUE),
304 'ERROR_COOKIES_IGNORE' => $GLOBALS['LANG']->getLL('error.cookies_ignore', TRUE),
305 'ERROR_CAPSLOCK' => $GLOBALS['LANG']->getLL('error.capslock', TRUE),
306 'ERROR_FURTHERHELP' => $GLOBALS['LANG']->getLL('error.furtherInformation', TRUE),
307 'LABEL_DONATELINK' => $GLOBALS['LANG']->getLL('labels.donate', TRUE),
308 'LABEL_USERNAME' => $GLOBALS['LANG']->getLL('labels.username', TRUE),
309 'LABEL_OPENID' => $GLOBALS['LANG']->getLL('labels.openId', TRUE),
310 'LABEL_PASSWORD' => $GLOBALS['LANG']->getLL('labels.password', TRUE),
311 'LABEL_WHATISOPENID' => $GLOBALS['LANG']->getLL('labels.whatIsOpenId', TRUE),
312 'LABEL_SWITCHOPENID' => $GLOBALS['LANG']->getLL('labels.switchToOpenId', TRUE),
313 'LABEL_SWITCHDEFAULT' => $GLOBALS['LANG']->getLL('labels.switchToDefault', TRUE),
314 'CLEAR' => $GLOBALS['LANG']->getLL('clear', TRUE),
315 'LOGIN_PROCESS' => $GLOBALS['LANG']->getLL('login_process', TRUE),
316 'SITELINK' => '<a href="/">###SITENAME###</a>',
317
318 // global variables will now be replaced (at last)
319 'SITENAME' => htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'])
320 );
321 return t3lib_parsehtml::substituteMarkerArray($mainContent, $markers, '###|###');
322 }
323
324
325 /**
326 * Checking, if we should perform some sort of redirection OR closing of windows.
327 *
328 * @return void
329 */
330 function checkRedirect() {
331 // Do redirect:
332 // 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...)
333 if ($GLOBALS['BE_USER']->user['uid'] && ($this->commandLI || $this->loginRefresh || !$this->interfaceSelector)) {
334
335 // 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.
336 if (!$_COOKIE[t3lib_beUserAuth::getCookieName()]) {
337 if ($this->commandLI=='setCookie') {
338 // we tried it a second time but still no cookie
339 // 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.
340 throw new RuntimeException('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.', 1294586846);
341 } else {
342 // try it once again - that might be needed for auto login
343 $this->redirectToURL = 'index.php?commandLI=setCookie';
344 }
345 }
346
347 if (($redirectToURL = (string)$GLOBALS['BE_USER']->getTSConfigVal('auth.BE.redirectToURL'))) {
348 $this->redirectToURL = $redirectToURL;
349 $this->GPinterface = '';
350 }
351
352 // store interface
353 $GLOBALS['BE_USER']->uc['interfaceSetup'] = $this->GPinterface;
354 $GLOBALS['BE_USER']->writeUC();
355
356 // Based on specific setting of interface we set the redirect script:
357 switch ($this->GPinterface) {
358 case 'backend':
359 case 'backend_old':
360 $this->redirectToURL = 'backend.php';
361 break;
362 case 'frontend':
363 $this->redirectToURL = '../';
364 break;
365 }
366
367 $formProtection = t3lib_formprotection_Factory::get();
368 // If there is a redirect URL AND if loginRefresh is not set...
369 if (!$this->loginRefresh) {
370 $formProtection->storeSessionTokenInRegistry();
371 t3lib_utility_Http::redirect($this->redirectToURL);
372 } else {
373 $formProtection->setSessionTokenFromRegistry();
374 $formProtection->persistSessionToken();
375 $GLOBALS['TBE_TEMPLATE']->JScode.=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
376 if (parent.opener && (parent.opener.busy || parent.opener.TYPO3.loginRefresh)) {
377 if (parent.opener.TYPO3.loginRefresh) {
378 parent.opener.TYPO3.loginRefresh.startTimer();
379 } else {
380 parent.opener.busy.loginRefreshed();
381 }
382 parent.close();
383 }
384 ');
385 }
386 } elseif (!$GLOBALS['BE_USER']->user['uid'] && $this->commandLI) {
387 sleep(5); // Wrong password, wait for 5 seconds
388 }
389 }
390
391 /**
392 * Making interface selector:
393 *
394 * @return void
395 */
396 function makeInterfaceSelectorBox() {
397 // Reset variables:
398 $this->interfaceSelector = '';
399 $this->interfaceSelector_hidden='';
400 $this->interfaceSelector_jump = '';
401
402 // If interfaces are defined AND no input redirect URL in GET vars:
403 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces'] && ($this->commandLI || !$this->redirect_url)) {
404 $parts = t3lib_div::trimExplode(',',$GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces']);
405 if (count($parts)>1) { // Only if more than one interface is defined will we show the selector:
406
407 // Initialize:
408 $labels=array();
409
410 $labels['backend'] = $GLOBALS['LANG']->getLL('interface.backend');
411 $labels['backend_old'] = $GLOBALS['LANG']->getLL('interface.backend_old');
412 $labels['frontend'] = $GLOBALS['LANG']->getLL('interface.frontend');
413
414 $jumpScript=array();
415 $jumpScript['backend'] = 'backend.php';
416 $jumpScript['backend_old'] = 'backend.php';
417 $jumpScript['frontend'] = '../';
418
419 // Traverse the interface keys:
420 foreach($parts as $valueStr) {
421 $this->interfaceSelector.='
422 <option value="'.htmlspecialchars($valueStr).'"'.(t3lib_div::_GP('interface')==htmlspecialchars($valueStr) ? ' selected="selected"' : '').'>'.htmlspecialchars($labels[$valueStr]).'</option>';
423 $this->interfaceSelector_jump.='
424 <option value="'.htmlspecialchars($jumpScript[$valueStr]).'">'.htmlspecialchars($labels[$valueStr]).'</option>';
425 }
426 $this->interfaceSelector='
427 <select id="t3-interfaceselector" name="interface" class="c-interfaceselector" tabindex="3">'.$this->interfaceSelector.'
428 </select>';
429 $this->interfaceSelector_jump='
430 <select id="t3-interfaceselector" name="interface" class="c-interfaceselector" tabindex="3" onchange="window.location.href=this.options[this.selectedIndex].value;">'.$this->interfaceSelector_jump.'
431 </select>';
432
433 } elseif (!$this->redirect_url) {
434 // If there is only ONE interface value set and no redirect_url is present:
435 $this->interfaceSelector_hidden='<input type="hidden" name="interface" value="'.trim($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces']).'" />';
436 }
437 }
438 }
439
440 /**
441 * COPYRIGHT notice
442 *
443 * Warning:
444 * DO NOT prevent this notice from being shown in ANY WAY.
445 * 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)
446 * 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.
447 *
448 * @return string Text/Image (HTML) for copyright notice.
449 */
450 function makeCopyrightNotice() {
451
452 // Get values from TYPO3_CONF_VARS:
453 $loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyProvider']));
454 $loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyURL']));
455 $loginImageSmall = (trim($GLOBALS['TBE_STYLES']['loginBoxImageSmall'])) ? trim($GLOBALS['TBE_STYLES']['loginBoxImageSmall']) : 'gfx/loginlogo_transp.gif';
456
457 // Make warranty note:
458 if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10) {
459 $warrantyNote = sprintf($GLOBALS['LANG']->getLL('warranty.by'), htmlspecialchars($loginCopyrightWarrantyProvider), '<a href="' . htmlspecialchars($loginCopyrightWarrantyURL) . '" target="_blank">', '</a>');
460 } else {
461 $warrantyNote = sprintf($GLOBALS['LANG']->getLL('no.warranty'), '<a href="' . TYPO3_URL_LICENSE . '" target="_blank">', '</a>');
462 }
463
464 // Compile full copyright notice:
465 $copyrightNotice = '<a href="' . TYPO3_URL_GENERAL . '" target="_blank">'.
466 '<img src="' . $loginImageSmall . '" alt="' . $GLOBALS['LANG']->getLL('typo3.logo') . '" align="left" />' .
467 $GLOBALS['LANG']->getLL('typo3.cms') . ($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightShowVersion']?' ' . $GLOBALS['LANG']->getLL('version.short') . ' ' . htmlspecialchars($GLOBALS['TYPO_VERSION']):'') .
468 '</a>. ' .
469 $GLOBALS['LANG']->getLL('copyright') . ' &copy; ' . TYPO3_copyright_year . ' Kasper Sk&#229;rh&#248;j. ' . $GLOBALS['LANG']->getLL('extension.copyright') . ' ' .
470 sprintf($GLOBALS['LANG']->getLL('details.link'), '<a href="' . TYPO3_URL_GENERAL . '" target="_blank">' . TYPO3_URL_GENERAL . '</a>') . '<br /> ' .
471 $warrantyNote . ' ' .
472 sprintf($GLOBALS['LANG']->getLL('free.software'), '<a href="' . TYPO3_URL_LICENSE . '" target="_blank">', '</a> ') .
473 $GLOBALS['LANG']->getLL('keep.notice');
474
475 // Return notice:
476 return $copyrightNotice;
477 }
478
479 /**
480 * Returns the login box image, whether the default or an image from the rotation folder.
481 *
482 * @return string HTML image tag.
483 */
484 function makeLoginBoxImage() {
485 $loginboxImage = '';
486 if ($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']) { // Look for rotation image folder:
487 $absPath = t3lib_div::resolveBackPath(PATH_typo3.$GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']);
488
489 // Get rotation folder:
490 $dir = t3lib_div::getFileAbsFileName($absPath);
491 if ($dir && @is_dir($dir)) {
492
493 // Get files for rotation into array:
494 $files = t3lib_div::getFilesInDir($dir,'png,jpg,gif');
495
496 // Pick random file:
497 $randImg = array_rand($files, 1);
498
499 // Get size of random file:
500 $imgSize = @getimagesize($dir.$files[$randImg]);
501
502 $imgAuthor = is_array($GLOBALS['TBE_STYLES']['loginBoxImage_author'])&&$GLOBALS['TBE_STYLES']['loginBoxImage_author'][$files[$randImg]] ? htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_author'][$files[$randImg]]) : '';
503
504 // Create image tag:
505 if (is_array($imgSize)) {
506 $loginboxImage = '<img src="'.htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder'].$files[$randImg]).'" '.$imgSize[3].' id="loginbox-image" alt="'.$imgAuthor.'" title="'.$imgAuthor.'" />';
507 }
508 }
509 } else { // If no rotation folder configured, print default image:
510
511 if (strstr(TYPO3_version,'-dev')) { // development version
512 $loginImage = 'loginbox_image_dev.png';
513 $imagecopy = 'You are running a development version of TYPO3 '.TYPO3_branch;
514 } else {
515 $loginImage = 'loginbox_image.jpg';
516 $imagecopy = 'Photo by J.C. Franca (www.digitalphoto.com.br)';
517 }
518 $loginboxImage = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/'.$loginImage,'width="200" height="133"').' id="loginbox-image" alt="'.$imagecopy.'" title="'.$imagecopy.'" />';
519 }
520
521 // Return image tag:
522 return $loginboxImage;
523 }
524
525 /**
526 * Make login news - renders the HTML content for a list of news shown under
527 * the login form. News data is added through $GLOBALS['TYPO3_CONF_VARS']
528 *
529 * @return string HTML content
530 * @credits Idea by Jan-Hendrik Heuing
531 * @deprecated $GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] is deprecated since 4.5. Use system news records instead.
532 */
533 function makeLoginNews() {
534 $newsContent = '';
535
536 $systemNews = $this->getSystemNews();
537 if (count($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'])) {
538 t3lib_div::logDeprecatedFunction();
539
540 $GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] = array_merge(
541 $systemNews,
542 $GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']
543 );
544 } else {
545 $GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] = $systemNews;
546 }
547
548 // Traverse news array IF there are records in it:
549 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']) && count($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']) && !t3lib_div::_GP('loginRefresh')) {
550 $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml_proc');
551 // get the main news template, and replace the subpart after looped through
552 $newsContent = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGIN_NEWS###');
553 $newsItemTemplate = t3lib_parsehtml::getSubpart($newsContent, '###NEWS_ITEM###');
554
555 $newsItem = '';
556 $count = 1;
557 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] as $newsItemData) {
558 $additionalClass = '';
559 if ($count == 1) {
560 $additionalClass = ' first-item';
561 } elseif($count == count($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'])) {
562 $additionalClass = ' last-item';
563 }
564
565 $newsItemContent = $htmlParser->TS_transform_rte($htmlParser->TS_links_rte($newsItemData['content']));
566 $newsItemMarker = array(
567 '###HEADER###' => htmlspecialchars($newsItemData['header']),
568 '###DATE###' => htmlspecialchars($newsItemData['date']),
569 '###CONTENT###' => $newsItemContent,
570 '###CLASS###' => $additionalClass
571 );
572
573 $count++;
574 $newsItem .= t3lib_parsehtml::substituteMarkerArray($newsItemTemplate, $newsItemMarker);
575 }
576
577 $title = ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNewsTitle'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['loginNewsTitle'] : $GLOBALS['LANG']->getLL('newsheadline'));
578
579 $newsContent = t3lib_parsehtml::substituteMarker($newsContent, '###NEWS_HEADLINE###', htmlspecialchars($title));
580 $newsContent = t3lib_parsehtml::substituteSubpart($newsContent, '###NEWS_ITEM###', $newsItem);
581 }
582
583 return $newsContent;
584 }
585
586 /**
587 * Gets news from sys_news and converts them into a format suitable for
588 * showing them at the login screen.
589 *
590 * @return array An array of login news.
591 */
592 protected function getSystemNews() {
593 $systemNewsTable = 'sys_news';
594 $systemNews = array();
595
596 $systemNewsRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
597 'title, content, crdate',
598 $systemNewsTable,
599 '1=1' .
600 t3lib_BEfunc::BEenableFields($systemNewsTable) .
601 t3lib_BEfunc::deleteClause($systemNewsTable),
602 '',
603 'crdate DESC'
604 );
605
606 foreach ($systemNewsRecords as $systemNewsRecord) {
607 $systemNews[] = array(
608 'date' => date(
609 $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],
610 $systemNewsRecord['crdate']
611 ),
612 'header' => $systemNewsRecord['title'],
613 'content' => $systemNewsRecord['content']
614 );
615 }
616
617 return $systemNews;
618 }
619
620 /**
621 * Returns the form tag
622 *
623 * @return string Opening form tag string
624 */
625 function startForm() {
626 $output = '';
627
628 // The form defaults to 'no login'. This prevents plain
629 // text logins to the Backend. The 'sv' extension changes the form to
630 // use superchallenged method and rsaauth extension makes rsa authetication.
631 $form = '<form action="index.php" method="post" name="loginform" ' .
632 'onsubmit="alert(\'No authentication methods available. Please, ' .
633 'contact your TYPO3 administrator.\');return false">';
634
635 // Call hooks. If they do not return anything, we fail to login
636 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginFormHook'])) {
637 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginFormHook'] as $function) {
638 $params = array();
639 $formCode = t3lib_div::callUserFunction($function, $params, $this);
640 if ($formCode) {
641 $form = $formCode;
642 break;
643 }
644 }
645 }
646
647 $output .= $form .
648 '<input type="hidden" name="login_status" value="login" />' .
649 '<input type="hidden" name="userident" value="" />' .
650 '<input type="hidden" name="redirect_url" value="'.htmlspecialchars($this->redirectToURL).'" />' .
651 '<input type="hidden" name="loginRefresh" value="'.htmlspecialchars($this->loginRefresh).'" />' .
652 $this->interfaceSelector_hidden . $this->addFields_hidden;
653
654 return $output;
655 }
656
657 /**
658 * Creates JavaScript for the login form
659 *
660 * @return string JavaScript code
661 */
662 function getJScode() {
663 $JSCode = '';
664 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginScriptHook'])) {
665 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginScriptHook'] as $function) {
666 $params = array();
667 $JSCode = t3lib_div::callUserFunction($function, $params, $this);
668 if ($JSCode) {
669 break;
670 }
671 }
672 }
673 $JSCode .= $GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
674 function startUp() {
675 // 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:
676 try {
677 if (parent.opener && parent.opener.TS && parent.opener.TS.username && document.loginform && document.loginform.username) {
678 document.loginform.username.value = parent.opener.TS.username;
679 }
680 }
681 catch(error) {
682 //continue
683 }
684
685 // Wait a few millisecons before calling checkFocus(). This might be necessary because some browsers need some time to auto-fill in the form fields
686 window.setTimeout("checkFocus()", 50);
687 }
688
689 // This moves focus to the right input field:
690 function checkFocus() {
691 // If for some reason there already is a username in the username form field, move focus to the password field:
692 if (document.loginform.username && document.loginform.username.value == "") {
693 document.loginform.username.focus();
694 } else if (document.loginform.p_field && document.loginform.p_field.type!="hidden") {
695 document.loginform.p_field.focus();
696 }
697 }
698
699 // This function shows a warning, if user has capslock enabled
700 // parameter showWarning: shows warning if TRUE and capslock active, otherwise only hides warning, if capslock gets inactive
701 function checkCapslock(e, showWarning) {
702 if (!isCapslock(e)) {
703 document.getElementById(\'t3-capslock\').style.display = \'none\';
704 } else if (showWarning) {
705 document.getElementById(\'t3-capslock\').style.display = \'block\';
706 }
707 }
708
709 // Checks weather capslock is enabled (returns TRUE if enabled, false otherwise)
710 // thanks to http://24ways.org/2007/capturing-caps-lock
711
712 function isCapslock(e) {
713 var ev = e ? e : window.event;
714 if (!ev) {
715 return;
716 }
717 var targ = ev.target ? ev.target : ev.srcElement;
718 // get key pressed
719 var which = -1;
720 if (ev.which) {
721 which = ev.which;
722 } else if (ev.keyCode) {
723 which = ev.keyCode;
724 }
725 // get shift status
726 var shift_status = false;
727 if (ev.shiftKey) {
728 shift_status = ev.shiftKey;
729 } else if (ev.modifiers) {
730 shift_status = !!(ev.modifiers & 4);
731 }
732 return (((which >= 65 && which <= 90) && !shift_status) ||
733 ((which >= 97 && which <= 122) && shift_status));
734 }
735
736 // prevent opening the login form in the backend frameset
737 if (top.location.href != self.location.href) {
738 top.location.href = self.location.href;
739 }
740
741 ');
742
743 return $JSCode;
744 }
745
746
747 /**
748 * Checks if labels from $GLOBALS['TYPO3_CONF_VARS']['BE']['loginLabels'] were changed, and merge them to $GLOBALS['LOCAL_LANG'] if needed
749 *
750 * This method keeps backwards compatibility, if you modified your
751 * labels with the install tool, we recommend to transfer this labels to a locallang.xml file
752 * using the llxml extension
753 *
754 * @return void
755 * @deprecated since TYPO3 4.6, remove in TYPO3 4.8
756 */
757 protected function mergeOldLoginLabels() {
758 // Getting login labels
759 $oldLoginLabels = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['loginLabels']);
760 if ($oldLoginLabels != '') {
761 t3lib_div::deprecationLog('The use of $GLOBALS[\'TYPO3_CONF_VARS\'][\'BE\'][\'loginLabels\'] has been deprecated as of TYPO3 4.3, please use the according locallang.xml file.');
762 // md5 hash of the default loginLabels string
763 $defaultOldLoginLabelsHash = 'bcf0d32e58c6454ea50c6c956f1f18f0';
764 // compare loginLabels from TYPO3_CONF_VARS to default value
765 if (md5($oldLoginLabels) != $defaultOldLoginLabelsHash) {
766 $lang = $GLOBALS['LANG']->lang;
767 $oldLoginLabelArray = explode('|',$oldLoginLabels);
768 $overrideLabelKeys = array(
769 'labels.username' => $oldLoginLabelArray[0],
770 'labels.password' => $oldLoginLabelArray[1],
771 'labels.interface' => $oldLoginLabelArray[2],
772 'labels.submitLogin' => $oldLoginLabelArray[3],
773 'labels.submitLogout' => $oldLoginLabelArray[4],
774 'availableInterfaces' => $oldLoginLabelArray[5],
775 'headline' => $oldLoginLabelArray[6],
776 'info.jscookies' => $oldLoginLabelArray[7],
777 'newsheadline' => $oldLoginLabelArray[8],
778 'error.login' => $oldLoginLabelArray[9],
779 );
780 if (!is_array($GLOBALS['LOCAL_LANG'][$lang])) {
781 $GLOBALS['LOCAL_LANG'][$lang] = array();
782 }
783 // now override the labels from the LOCAL_LANG with the TYPO3_CONF_VARS
784 foreach ($overrideLabelKeys as $labelKey => $label) {
785 $GLOBALS['LANG']->overrideLL($labelKey, $label);
786 }
787 }
788 }
789 }
790 }
791
792
793 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/index.php'])) {
794 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/index.php']);
795 }
796
797
798
799 // Make instance:
800 $SOBE = t3lib_div::makeInstance('SC_index');
801 $SOBE->init();
802 $SOBE->main();
803 $SOBE->printContent();
804
805 ?>