[TASK] CleanUp References to old ClassNames
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Utility / EidUtility.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2006-2011 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 * Tools for scripts using the eID feature of index.php
31 * Included from index_ts.php
32 * Since scripts using the eID feature does not
33 * have a full FE environment initialized by default
34 * this class seeks to provide functions that can
35 * initialize parts of the FE environment as needed,
36 * eg. Frontend User session, Database connection etc.
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 */
40 /**
41 * Tools for scripts using the eID feature of index.php
42 *
43 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 * @author Dmitry Dulepov <dmitry@typo3.org>
45 */
46 class EidUtility {
47
48 /**
49 * Load and initialize Frontend User. Note, this process is slow because
50 * it creates a calls many objects. Call this method only if necessary!
51 *
52 * @return object Frontend User object (usually known as TSFE->fe_user)
53 */
54 static public function initFeUser() {
55 // Initialize the database. Do not use TSFE method as it may redirect to
56 // Install tool and call hooks, which do not expect to be called from eID
57 self::connectDB();
58 // Get TSFE instance. It knows how to initialize the user. We also
59 // need TCA because services may need extra tables!
60 self::initTCA();
61 /** @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
62 $tsfe = self::getTSFE();
63 $tsfe->initFEuser();
64 // Return FE user object:
65 return $tsfe->fe_user;
66 }
67
68 /**
69 * Connecting to database. If the function fails, last error message
70 * can be retrieved using $GLOBALS['TYPO3_DB']->sql_error().
71 *
72 * @return boolean TRUE if connection was successful
73 */
74 static public function connectDB() {
75 if (!$GLOBALS['TYPO3_DB']->isConnected()) {
76 // Attempt to connect to the database
77 $GLOBALS['TYPO3_DB']->connectDB();
78 }
79 // connectDB() throws exceptions if something went wrong,
80 // so we are sure that connect was successful here.
81 return TRUE;
82 }
83
84 /**
85 * Initializes $GLOBALS['LANG'] for use in eID scripts.
86 *
87 * @param string $language TYPO3 language code
88 * @return void
89 */
90 static public function initLanguage($language = 'default') {
91 if (!is_object($GLOBALS['LANG'])) {
92 $GLOBALS['LANG'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Lang\\LanguageService');
93 $GLOBALS['LANG']->init($language);
94 }
95 }
96
97 /**
98 * Makes TCA available inside eID
99 *
100 * @return void
101 */
102 static public function initTCA() {
103 // Some badly made extensions attempt to manipulate TCA in a wrong way
104 // (inside ext_localconf.php). Therefore $GLOBALS['TCA'] may become an array
105 // but in fact it is not loaded. The check below ensure that
106 // TCA is still loaded if such bad extensions are installed
107 if (!is_array($GLOBALS['TCA']) || !isset($GLOBALS['TCA']['pages'])) {
108 // Load TCA using TSFE
109 self::getTSFE()->includeTCA(FALSE);
110 }
111 }
112
113 /**
114 * Makes TCA for the extension available inside eID. Use this function if
115 * you need not to include the whole $GLOBALS['TCA']. However, you still need to call
116 * \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA() if you want to access column array!
117 *
118 * @param string $extensionKey Extension key
119 * @return void
120 */
121 static public function initExtensionTCA($extensionKey) {
122 $extTablesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey, 'ext_tables.php');
123 if (file_exists($extTablesPath)) {
124 $GLOBALS['_EXTKEY'] = $extensionKey;
125 require_once $extTablesPath;
126 // We do not need to save restore the value of $GLOBALS['_EXTKEY']
127 // because it is not defined to anything real outside of
128 // ext_tables.php or ext_localconf.php scope.
129 unset($GLOBALS['_EXTKEY']);
130 }
131 }
132
133 /**
134 * Creating a single static cached instance of TSFE to use with this class.
135 *
136 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController New instance of tslib_fe
137 */
138 static private function getTSFE() {
139 // Cached instance
140 static $tsfe = NULL;
141 if (is_null($tsfe)) {
142 $tsfe = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', $GLOBALS['TYPO3_CONF_VARS'], 0, 0);
143 }
144 return $tsfe;
145 }
146
147 }
148
149
150 ?>