|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-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 * Contains the base class for 'Extension Objects' in backend modules. 00029 * 00030 * $Id: class.t3lib_extobjbase.php 10121 2011-01-18 20:15:30Z ohader $ 00031 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj 00032 * 00033 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00034 */ 00035 /** 00036 * [CLASS/FUNCTION INDEX of SCRIPT] 00037 * 00038 * 00039 * 00040 * 145: class t3lib_extobjbase 00041 * 197: function init(&$pObj,$conf) 00042 * 221: function handleExternalFunctionValue() 00043 * 237: function incLocalLang() 00044 * 253: function checkExtObj() 00045 * 268: function extObjContent() 00046 * 279: function modMenu() 00047 * 00048 * TOTAL FUNCTIONS: 6 00049 * (This index is automatically created/updated by the extension "extdeveval") 00050 * 00051 */ 00052 00053 00054 /** 00055 * EXAMPLE: One level. 00056 * 00057 * This can be seen in the extension 'cms' where the info module have a function added. In 'ext_tables.php' this is done by this function call: 00058 * 00059 * t3lib_extMgm::insertModuleFunction( 00060 * 'web_info', 00061 * 'tx_cms_webinfo_page', 00062 * t3lib_extMgm::extPath($_EXTKEY).'web_info/class.tx_cms_webinfo.php', 00063 * 'LLL:EXT:cms/locallang_tca.php:mod_tx_cms_webinfo_page' 00064 * ); 00065 * 00066 * 00067 * 00068 * EXAMPLE: Two levels. 00069 * This is the advanced example. You can see it with the extension 'func_wizards' which is the first layer but then providing another layer for extensions to connect by. 00070 * The key used in TBE_MODULES_EXT is normally 'function' (for the 'function menu') but the 'func_wizards' extension uses an alternative key for its configuration: 'wiz'. 00071 * In the 'ext_tables.php' file of an extension ('wizard_crpages') which uses the framework provided by 'func_wizards' this looks like this: 00072 * 00073 * t3lib_extMgm::insertModuleFunction( 00074 * 'web_func', 00075 * 'tx_wizardcrpages_webfunc_2', 00076 * t3lib_extMgm::extPath($_EXTKEY).'class.tx_wizardcrpages_webfunc_2.php', 00077 * 'LLL:EXT:wizard_crpages/locallang.php:wiz_crMany', 00078 * 'wiz' 00079 * ); 00080 * 00081 * But for this two-level thing to work it also requires that the parent module (the real backend module) supports it. 00082 * This is the case for the modules web_func and web_info since they have two times inclusion sections in their index.php scripts. For example (from web_func): 00083 * 00084 * // Make instance: 00085 * $SOBE = t3lib_div::makeInstance("SC_mod_web_func_index"); 00086 * $SOBE->init(); 00087 * 00088 * // Include files? 00089 * foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE); 00090 * $SOBE->checkExtObj(); // Checking for first level external objects 00091 * 00092 * // Repeat Include files! - if any files has been added by second-level extensions 00093 * foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE); 00094 * $SOBE->checkSubExtObj(); // Checking second level external objects 00095 * 00096 * $SOBE->main(); 00097 * $SOBE->printContent(); 00098 * 00099 * Notice that the first part is as usual: Include classes and call $SOBE->checkExtObj() to initialize any level-1 sub-modules 00100 * But then again ->include_once is traversed IF the initialization of the level-1 modules might have added more files!! 00101 * And after that $SOBE->checkSubExtObj() is called to initialize the second level. 00102 * In this way even a third level could be supported - but most likely that is a too layered model to be practical. 00103 * 00104 * Anyways, the final interesting thing is to see what the framework "func_wizard" actually does: 00105 * 00106 * class tx_funcwizards_webfunc extends t3lib_extobjbase { 00107 * var $localLangFile = "locallang.php"; 00108 * var $function_key = "wiz"; 00109 * function init(&$pObj,$conf) { 00110 * // OK, handles ordinary init. This includes setting up the menu array with ->modMenu 00111 * parent::init($pObj,$conf); 00112 * // Making sure that any further external classes are added to the include_once array. Notice that inclusion happens twice in the main script because of this!!! 00113 * $this->handleExternalFunctionValue(); 00114 * } 00115 * .... 00116 * 00117 * Notice that the handleExternalFunctionValue of this class (t3lib_extobjbase) is called and that the ->function_key internal var is set! 00118 * 00119 * The two level-2 sub-module "wizard_crpages" and "wizard_sortpages" are totally normal "submodules". 00120 */ 00121 00122 /** 00123 * Parent class for 'Extension Objects' in backend modules. 00124 * Used for 'submodules' to other modules. Also called 'Function menu modules' in t3lib_extMgm. And now its even called 'Extension Objects'. Or 'Module functions'. Wish we had just one name. Or a name at all...(?) Thank God its not so advanced when it works... 00125 * In other words this class is used for backend modules which is not true backend modules appearing in the menu but rather adds themselves as a new entry in the function menu which typically exists for a backend module (like Web>Functions, Web>Info or Tools etc...) 00126 * The magic that binds this together is stored in the global variable $TBE_MODULES_EXT where extensions wanting to connect a module based on this class to an existing backend module store configuration which consists of the classname, script-path and a label (title/name) 00127 * For more information about this, please see the large example comment for the class t3lib_SCbase. This will show the principle of a 'level-1' connection. 00128 * The more advanced example - having two layers as it is done by the 'func_wizards' extension with the 'web_info' module - can be seen in the comment above. 00129 * 00130 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00131 * @package TYPO3 00132 * @subpackage t3lib 00133 * @see t3lib_SCbase,tx_funcwizards_webfunc::init(), tx_funcwizards_webfunc, tx_wizardsortpages_webfunc_2 00134 */ 00135 class t3lib_extobjbase { 00136 00137 /** 00138 * Contains a reference to the parent (calling) object (which is probably an instance of an extension class to t3lib_SCbase) 00139 * 00140 * @var t3lib_SCbase 00141 * @see init() 00142 */ 00143 var $pObj; // parent SC object 00144 00145 /** 00146 * Set to the directory name of this class file. 00147 * @see init() 00148 */ 00149 var $thisPath = ''; 00150 00151 /** 00152 * Can be hardcoded to the name of a locallang.php file (from the same directory as the class file) to use/load 00153 * @see incLocalLang() 00154 */ 00155 var $localLangFile = 'locallang.php'; 00156 00157 /** 00158 * Contains module configuration parts from TBE_MODULES_EXT if found 00159 * 00160 * @see handleExternalFunctionValue() 00161 */ 00162 var $extClassConf; 00163 00164 /** 00165 * If this value is set it points to a key in the TBE_MODULES_EXT array (not on the top level..) where another classname/filepath/title can be defined for sub-subfunctions. 00166 * This is a little hard to explain, so see it in action; it used in the extension 'func_wizards' in order to provide yet a layer of interfacing with the backend module. 00167 * The extension 'func_wizards' has this description: 'Adds the 'Wizards' item to the function menu in Web>Func. This is just a framework for wizard extensions.' - so as you can see it is designed to allow further connectivity - 'level 2' 00168 * 00169 * @see handleExternalFunctionValue(), tx_funcwizards_webfunc 00170 */ 00171 var $function_key = ''; 00172 00173 00174 /** 00175 * Initialize the object 00176 * 00177 * @param object A reference to the parent (calling) object (which is probably an instance of an extension class to t3lib_SCbase) 00178 * @param array The configuration set for this module - from global array TBE_MODULES_EXT 00179 * @return void 00180 * @see t3lib_SCbase::checkExtObj() 00181 */ 00182 function init(&$pObj, $conf) { 00183 global $LANG; 00184 00185 $this->pObj = $pObj; 00186 00187 // Path of this script: 00188 $this->thisPath = dirname($conf['path']); 00189 if (!@is_dir($this->thisPath)) { 00190 throw new RuntimeException( 00191 'TYPO3 Fatal Error: Extension "' . $this->thisPath . ' was not a directory as expected...', 00192 1270853912 00193 ); 00194 } 00195 00196 // Local lang: 00197 $this->incLocalLang(); 00198 00199 // Setting MOD_MENU items as we need them for logging: 00200 $this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->modMenu()); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble... 00201 } 00202 00203 /** 00204 * If $this->function_key is set (which means there are two levels of object connectivity) then $this->extClassConf is loaded with the TBE_MODULES_EXT configuration for that sub-sub-module 00205 * 00206 * @return void 00207 * @see $function_key, tx_funcwizards_webfunc::init() 00208 */ 00209 function handleExternalFunctionValue() { 00210 // Must clean first to make sure the correct key is set... 00211 $this->pObj->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->pObj->MOD_MENU, t3lib_div::_GP('SET'), $this->pObj->MCONF['name']); 00212 if ($this->function_key) { 00213 $this->extClassConf = $this->pObj->getExternalItemConfig($this->pObj->MCONF['name'], $this->function_key, $this->pObj->MOD_SETTINGS[$this->function_key]); 00214 if (is_array($this->extClassConf) && $this->extClassConf['path']) { 00215 $this->pObj->include_once[] = $this->extClassConf['path']; 00216 } 00217 } 00218 } 00219 00220 /** 00221 * Including any locallang file configured and merging its content over the current global LOCAL_LANG array (which is EXPECTED to exist!!!) 00222 * 00223 * @return void 00224 */ 00225 function incLocalLang() { 00226 global $LANG; 00227 #if ($this->localLangFile && @is_file($this->thisPath.'/'.$this->localLangFile)) { 00228 # include($this->thisPath.'/'.$this->localLangFile); 00229 if ($this->localLangFile && (@is_file($this->thisPath . '/' . $this->localLangFile) || @is_file($this->thisPath . '/' . substr($this->localLangFile, 0, -4) . '.xml'))) { 00230 $LOCAL_LANG = $LANG->includeLLFile($this->thisPath . '/' . $this->localLangFile, FALSE); 00231 if (is_array($LOCAL_LANG)) { 00232 $GLOBALS['LOCAL_LANG'] = t3lib_div::array_merge_recursive_overrule((array) $GLOBALS['LOCAL_LANG'], $LOCAL_LANG); 00233 } 00234 } 00235 } 00236 00237 /** 00238 * Same as t3lib_SCbase::checkExtObj() 00239 * 00240 * @return void 00241 * @see t3lib_SCbase::checkExtObj() 00242 */ 00243 function checkExtObj() { 00244 if (is_array($this->extClassConf) && $this->extClassConf['name']) { 00245 $this->extObj = t3lib_div::makeInstance($this->extClassConf['name']); 00246 $this->extObj->init($this->pObj, $this->extClassConf); 00247 00248 // Re-write: 00249 $this->pObj->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->pObj->MOD_MENU, t3lib_div::_GP('SET'), $this->pObj->MCONF['name']); 00250 } 00251 } 00252 00253 /** 00254 * Calls the main function inside ANOTHER sub-submodule which might exist. 00255 * 00256 * @return void 00257 */ 00258 function extObjContent() { 00259 if (is_object($this->extObj)) { 00260 return $this->extObj->main(); 00261 } 00262 } 00263 00264 /** 00265 * Dummy function - but is used to set up additional menu items for this submodule. 00266 * For an example see the extension 'cms' where the 'web_info' submodule is defined in cms/web_info/class.tx_cms_webinfo.php, tx_cms_webinfo_page::modMenu() 00267 * 00268 * @return array A MOD_MENU array which will be merged together with the one from the parent object 00269 * @see init(), tx_cms_webinfo_page::modMenu() 00270 */ 00271 function modMenu() { 00272 return array(); 00273 } 00274 } 00275 00276 ?>
1.8.0