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