Fixed bug #15580: Add calls to logDeprecatedFunction() for more deprecated functions...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_eidtools.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2006-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Tools for scripts using the eID feature of index.php
29 * Included from index_ts.php
30 * Since scripts using the eID feature does not
31 * have a full FE environment initialized by default
32 * this class seeks to provide functions that can
33 * initialize parts of the FE environment as needed,
34 * eg. Frontend User session, Database connection etc.
35 *
36 * $Id$
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 */
40 /**
41 * [CLASS/FUNCTION INDEX of SCRIPT]
42 *
43 * 71: public static function initFeUser()
44 * 98: public static function connectDB()
45 * 117: public static function initLanguage($language = 'default')
46 * 131: public static function initTCA()
47 * 150: public static function initExtensionTCA($extensionKey)
48 * 167: private static function getTSFE()
49 *
50 * TOTAL FUNCTIONS: 6
51 * (This index is automatically created/updated by the extension "extdeveval")
52 *
53 */
54
55 /**
56 * Tools for scripts using the eID feature of index.php
57 *
58 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
59 * @author Dmitry Dulepov <dmitry@typo3.org>
60 * @package TYPO3
61 * @subpackage tslib
62 */
63 final class tslib_eidtools {
64
65 /**
66 * Load and initialize Frontend User. Note, this process is slow because
67 * it creates a calls many objects. Call this method only if necessary!
68 *
69 * @return object Frontend User object (usually known as TSFE->fe_user)
70 */
71 public static function initFeUser() {
72 // Initialize the database. Do not use TSFE method as it may redirect to
73 // Install tool and call hooks, which do not expect to be called from eID
74 self::connectDB();
75
76 // Get TSFE instance. It knows how to initialize the user. We also
77 // need TCA because services may need extra tables!
78 self::initTCA();
79 $tsfe = self::getTSFE();
80 /* @var $tsfe tslib_fe */
81
82 $tsfe->initFEuser();
83
84 // Return FE user object:
85 return $tsfe->fe_user;
86 }
87
88 /**
89 * Connecting to database. If the function fails, last error message
90 * can be retrieved using $GLOBALS['TYPO3_DB']->sql_error().
91 *
92 * @return boolean true if connection was successful
93 */
94 public static function connectDB() {
95 static $dbConnected = false;
96
97 if (!$dbConnected) {
98 // Attempt to connect to the database
99 if ($GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password) &&
100 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db)) {
101 $dbConnected = true;
102 }
103 }
104 return $dbConnected;
105 }
106
107 /**
108 * Initializes $GLOBALS['LANG'] for use in eID scripts.
109 *
110 * @param string $language TYPO3 language code
111 * @return void
112 */
113 public static function initLanguage($language = 'default') {
114 if (!is_object($GLOBALS['LANG'])) {
115 $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
116 $GLOBALS['LANG']->init($language);
117 }
118 }
119
120 /**
121 * Makes TCA available inside eID
122 *
123 * @return void
124 */
125 public static function initTCA() {
126 // Some badly made extensions attempt to manipulate TCA in a wrong way
127 // (inside ext_localconf.php). Therefore $TCA may become an array
128 // but in fact it is not loaded. The check below ensure that
129 // TCA is still loaded if such bad extensions are installed
130 if (!is_array($GLOBALS['TCA']) || !isset($GLOBALS['TCA']['pages'])) {
131 // Load TCA using TSFE
132 self::getTSFE()->includeTCA(false);
133 }
134 }
135
136 /**
137 * Makes TCA for the extension available inside eID. Use this function if
138 * you need not to include the whole $TCA. However, you still need to call
139 * t3lib_div::loadTCA() if you want to access column array!
140 *
141 * @param string $extensionKey Extension key
142 * @return void
143 */
144 public static function initExtensionTCA($extensionKey) {
145 $extTablesPath = t3lib_extMgm::extPath($extensionKey, 'ext_tables.php');
146 if (file_exists($extTablesPath)) {
147 $GLOBALS['_EXTKEY'] = $extensionKey;
148 require_once($extTablesPath);
149 unset($GLOBALS['_EXTKEY']);
150 // We do not need to save restore the value of $GLOBALS['_EXTKEY']
151 // because it is not defined to anything real outside of
152 // ext_tables.php or ext_localconf.php scope.
153 }
154 }
155
156 /**
157 * Creating a single static cached instance of TSFE to use with this class.
158 *
159 * @return tslib_fe New instance of tslib_fe
160 */
161 private static function getTSFE() {
162 // Cached instance
163 static $tsfe = null;
164
165 if (is_null($tsfe)) {
166 $tsfe = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], 0, 0);
167 }
168
169 return $tsfe;
170 }
171 }
172
173 ?>