|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2006-2011 Kasper Skårhøj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 /** 00028 * Tools for scripts using the eID feature of index.php 00029 * Included from index_ts.php 00030 * Since scripts using the eID feature does not 00031 * have a full FE environment initialized by default 00032 * this class seeks to provide functions that can 00033 * initialize parts of the FE environment as needed, 00034 * eg. Frontend User session, Database connection etc. 00035 * 00036 * $Id: class.tslib_eidtools.php 10120 2011-01-18 20:03:36Z ohader $ 00037 * 00038 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00039 */ 00040 /** 00041 * [CLASS/FUNCTION INDEX of SCRIPT] 00042 * 00043 * 71: public static function initFeUser() 00044 * 98: public static function connectDB() 00045 * 117: public static function initLanguage($language = 'default') 00046 * 131: public static function initTCA() 00047 * 150: public static function initExtensionTCA($extensionKey) 00048 * 167: private static function getTSFE() 00049 * 00050 * TOTAL FUNCTIONS: 6 00051 * (This index is automatically created/updated by the extension "extdeveval") 00052 * 00053 */ 00054 00055 /** 00056 * Tools for scripts using the eID feature of index.php 00057 * 00058 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00059 * @author Dmitry Dulepov <dmitry@typo3.org> 00060 * @package TYPO3 00061 * @subpackage tslib 00062 */ 00063 final class tslib_eidtools { 00064 00065 /** 00066 * Load and initialize Frontend User. Note, this process is slow because 00067 * it creates a calls many objects. Call this method only if necessary! 00068 * 00069 * @return object Frontend User object (usually known as TSFE->fe_user) 00070 */ 00071 public static function initFeUser() { 00072 // Initialize the database. Do not use TSFE method as it may redirect to 00073 // Install tool and call hooks, which do not expect to be called from eID 00074 self::connectDB(); 00075 00076 // Get TSFE instance. It knows how to initialize the user. We also 00077 // need TCA because services may need extra tables! 00078 self::initTCA(); 00079 $tsfe = self::getTSFE(); 00080 /* @var $tsfe tslib_fe */ 00081 00082 $tsfe->initFEuser(); 00083 00084 // Return FE user object: 00085 return $tsfe->fe_user; 00086 } 00087 00088 /** 00089 * Connecting to database. If the function fails, last error message 00090 * can be retrieved using $GLOBALS['TYPO3_DB']->sql_error(). 00091 * 00092 * @return boolean true if connection was successful 00093 */ 00094 public static function connectDB() { 00095 static $dbConnected = false; 00096 00097 if (!$dbConnected) { 00098 // Attempt to connect to the database 00099 if ($GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password) && 00100 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db)) { 00101 $dbConnected = true; 00102 } 00103 } 00104 return $dbConnected; 00105 } 00106 00107 /** 00108 * Initializes $GLOBALS['LANG'] for use in eID scripts. 00109 * 00110 * @param string $language TYPO3 language code 00111 * @return void 00112 */ 00113 public static function initLanguage($language = 'default') { 00114 if (!is_object($GLOBALS['LANG'])) { 00115 $GLOBALS['LANG'] = t3lib_div::makeInstance('language'); 00116 $GLOBALS['LANG']->init($language); 00117 } 00118 } 00119 00120 /** 00121 * Makes TCA available inside eID 00122 * 00123 * @return void 00124 */ 00125 public static function initTCA() { 00126 // Some badly made extensions attempt to manipulate TCA in a wrong way 00127 // (inside ext_localconf.php). Therefore $TCA may become an array 00128 // but in fact it is not loaded. The check below ensure that 00129 // TCA is still loaded if such bad extensions are installed 00130 if (!is_array($GLOBALS['TCA']) || !isset($GLOBALS['TCA']['pages'])) { 00131 // Load TCA using TSFE 00132 self::getTSFE()->includeTCA(false); 00133 } 00134 } 00135 00136 /** 00137 * Makes TCA for the extension available inside eID. Use this function if 00138 * you need not to include the whole $TCA. However, you still need to call 00139 * t3lib_div::loadTCA() if you want to access column array! 00140 * 00141 * @param string $extensionKey Extension key 00142 * @return void 00143 */ 00144 public static function initExtensionTCA($extensionKey) { 00145 $extTablesPath = t3lib_extMgm::extPath($extensionKey, 'ext_tables.php'); 00146 if (file_exists($extTablesPath)) { 00147 $GLOBALS['_EXTKEY'] = $extensionKey; 00148 require_once($extTablesPath); 00149 unset($GLOBALS['_EXTKEY']); 00150 // We do not need to save restore the value of $GLOBALS['_EXTKEY'] 00151 // because it is not defined to anything real outside of 00152 // ext_tables.php or ext_localconf.php scope. 00153 } 00154 } 00155 00156 /** 00157 * Creating a single static cached instance of TSFE to use with this class. 00158 * 00159 * @return tslib_fe New instance of tslib_fe 00160 */ 00161 private static function getTSFE() { 00162 // Cached instance 00163 static $tsfe = null; 00164 00165 if (is_null($tsfe)) { 00166 $tsfe = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], 0, 0); 00167 } 00168 00169 return $tsfe; 00170 } 00171 } 00172 00173 ?>
1.8.0