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