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