[BUGFIX] Fix access to time tracker in eID scripts
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / EidRequestHandler.php
1 <?php
2 namespace TYPO3\CMS\Frontend;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Core\Bootstrap;
18 use TYPO3\CMS\Frontend\Utility\EidUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Core\Core\RequestHandlerInterface;
21
22 /**
23 * Lightweight alternative to the regular RequestHandler used when $_GET[eID] is set.
24 * In the future, logic from the EidUtility will be moved to this class.
25 */
26 class EidRequestHandler implements RequestHandlerInterface {
27
28 /**
29 * Instance of the current TYPO3 bootstrap
30 * @var Bootstrap
31 */
32 protected $bootstrap;
33
34 /**
35 * Constructor handing over the bootstrap
36 *
37 * @param Bootstrap $bootstrap
38 */
39 public function __construct(Bootstrap $bootstrap) {
40 $this->bootstrap = $bootstrap;
41 }
42
43 /**
44 * Handles a frontend request based on the _GP "eID" variable.
45 *
46 * @return void
47 */
48 public function handleRequest() {
49 // Timetracking started
50 $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
51 if (empty($configuredCookieName)) {
52 $configuredCookieName = 'be_typo_user';
53 }
54 if ($_COOKIE[$configuredCookieName]) {
55 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\TimeTracker();
56 } else {
57 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
58 }
59
60 $GLOBALS['TT']->start();
61
62 // Hook to preprocess the current request
63 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
64 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
65 $hookParameters = array();
66 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
67 }
68 unset($hookFunction);
69 unset($hookParameters);
70 }
71
72 // Remove any output produced until now
73 $this->bootstrap->endOutputBufferingAndCleanPreviousOutput();
74 require EidUtility::getEidScriptPath();
75 $this->bootstrap->shutdown();
76 exit;
77 }
78
79 /**
80 * This request handler can handle any frontend request.
81 *
82 * @return bool If the request is not an eID request, TRUE otherwise FALSE
83 */
84 public function canHandleRequest() {
85 return GeneralUtility::_GP('eID') ? TRUE : FALSE;
86 }
87
88 /**
89 * Returns the priority - how eager the handler is to actually handle the
90 * request.
91 *
92 * @return int The priority of the request handler.
93 */
94 public function getPriority() {
95 return 80;
96 }
97 }