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