[BUGFIX] Replace mentions of index_ts.php
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Utility / EidUtility.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Utility;
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\Core\Utility\ExtensionManagementUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
21 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
22 use TYPO3\CMS\Lang\LanguageService;
23
24 /**
25 * Tools for scripts using the eID feature of the TYPO3 Frontend.
26 * Included from \TYPO3\CMS\Frontend\Http\RequestHandler.
27 * Since scripts using the eID feature does not
28 * have a full FE environment initialized by default
29 * this class seeks to provide functions that can
30 * initialize parts of the FE environment as needed,
31 * eg. Frontend User session, Database connection etc.
32 */
33 class EidUtility
34 {
35 /**
36 * Load and initialize Frontend User. Note, this process is slow because
37 * it creates a calls many objects. Call this method only if necessary!
38 *
39 * @return FrontendUserAuthentication Frontend User object (usually known as TSFE->fe_user)
40 */
41 public static function initFeUser()
42 {
43 // Get TSFE instance. It knows how to initialize the user. We also
44 // need TCA because services may need extra tables!
45 self::initTCA();
46 /** @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
47 $tsfe = self::getTSFE();
48 $tsfe->initFEuser();
49 // Return FE user object:
50 return $tsfe->fe_user;
51 }
52
53 /**
54 * Initializes $GLOBALS['LANG'] for use in eID scripts.
55 *
56 * @param string $language TYPO3 language code
57 * @return void
58 */
59 public static function initLanguage($language = 'default')
60 {
61 if (!is_object($GLOBALS['LANG'])) {
62 $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
63 $GLOBALS['LANG']->init($language);
64 }
65 }
66
67 /**
68 * Makes TCA available inside eID
69 *
70 * @return void
71 */
72 public static function initTCA()
73 {
74 // Some badly made extensions attempt to manipulate TCA in a wrong way
75 // (inside ext_localconf.php). Therefore $GLOBALS['TCA'] may become an array
76 // but in fact it is not loaded. The check below ensure that
77 // TCA is still loaded if such bad extensions are installed
78 if (!is_array($GLOBALS['TCA']) || !isset($GLOBALS['TCA']['pages'])) {
79 Bootstrap::getInstance()->loadCachedTca();
80 }
81 }
82
83 /**
84 * Makes TCA for the extension available inside eID. Use this function if
85 * you need not to include the whole $GLOBALS['TCA'].
86 *
87 * @param string $extensionKey Extension key
88 * @return void
89 */
90 public static function initExtensionTCA($extensionKey)
91 {
92 $extTablesPath = ExtensionManagementUtility::extPath($extensionKey, 'ext_tables.php');
93 if (file_exists($extTablesPath)) {
94 $GLOBALS['_EXTKEY'] = $extensionKey;
95 require_once $extTablesPath;
96 // We do not need to save restore the value of $GLOBALS['_EXTKEY']
97 // because it is not defined to anything real outside of
98 // ext_tables.php or ext_localconf.php scope.
99 unset($GLOBALS['_EXTKEY']);
100 }
101 }
102
103 /**
104 * Creating a single static cached instance of TSFE to use with this class.
105 *
106 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController New instance of \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
107 */
108 private static function getTSFE()
109 {
110 // Cached instance
111 static $tsfe = null;
112 if (is_null($tsfe)) {
113 $tsfe = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $GLOBALS['TYPO3_CONF_VARS'], 0, 0);
114 }
115 return $tsfe;
116 }
117 }