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