|
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 parent class for 'ScriptClasses' in backend modules. 00029 * 00030 * $Id: class.t3lib_scbase.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 * 133: class t3lib_SCbase 00041 * 249: function init() 00042 * 269: function menuConfig() 00043 * 292: function mergeExternalItems($modName,$menuKey,$menuArr) 00044 * 317: function handleExternalFunctionValue($MM_key='function', $MS_value=NULL) 00045 * 335: function getExternalItemConfig($modName,$menuKey,$value='') 00046 * 349: function checkExtObj() 00047 * 363: function checkSubExtObj() 00048 * 375: function extObjHeader() 00049 * 384: function extObjContent() 00050 * 00051 * TOTAL FUNCTIONS: 9 00052 * (This index is automatically created/updated by the extension "extdeveval") 00053 * 00054 */ 00055 00056 00057 /** 00058 * EXAMPLE PROTOTYPE 00059 * 00060 * As for examples there are lots of them if you search for classes which extends 't3lib_SCbase'. 00061 * However you can see a prototype example of how a module might use this class in an index.php file typically hosting a backend module. 00062 * NOTICE: This example only outlines the basic structure of how this class is used. You should consult the documentation and other real-world examples for some actual things to do when building modules. 00063 * 00064 * // TYPICAL 'HEADER' OF A BACKEND MODULE: 00065 * unset($MCONF); 00066 * require ('conf.php'); 00067 * require ($BACK_PATH.'init.php'); 00068 * require ($BACK_PATH.'template.php'); 00069 * $LANG->includeLLFile('EXT:prototype/locallang.php'); 00070 * $BE_USER->modAccess($MCONF,1); 00071 * 00072 * // SC_mod_prototype EXTENDS THE CLASS t3lib_SCbase with a main() and printContent() function: 00073 * class SC_mod_prototype extends t3lib_SCbase { 00074 * // MAIN FUNCTION - HERE YOU CREATE THE MODULE CONTENT IN $this->content 00075 * function main() { 00076 * // TYPICALLY THE INTERNAL VAR, $this->doc is instantiated like this: 00077 * $this->doc = t3lib_div::makeInstance('mediumDoc'); 00078 * // TYPICALLY THE INTERNAL VAR, $this->backPath is set like this: 00079 * $this->backPath = $this->doc->backPath = $GLOBALS['BACK_PATH']; 00080 * // ... AND OF COURSE A LOT OF OTHER THINGS GOES ON - LIKE PUTTING CONTENT INTO $this->content 00081 * $this->content=''; 00082 * } 00083 * // PRINT CONTENT - DONE AS THE LAST THING 00084 * function printContent() { 00085 * echo $this->content; 00086 * } 00087 * } 00088 * 00089 * // CHECKING IF THERE ARE AN EXTENSION CLASS CONFIGURED FOR THIS CLASS: 00090 * if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/prototype/index.php'])) { 00091 * include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/prototype/index.php']); 00092 * } 00093 * 00094 * // MAKE INSTANCE OF THE SCRIPT CLASS AND CALL init() 00095 * $SOBE = t3lib_div::makeInstance('SC_mod_prototype'); 00096 * $SOBE->init(); 00097 * 00098 * // AFTER INIT THE INTERNAL ARRAY ->include_once MAY HOLD FILENAMES TO INCLUDE 00099 * foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE); 00100 * 00101 * // THEN WE WILL CHECK IF THERE IS A 'SUBMODULE' REGISTERED TO BE INITIALIZED AS WELL: 00102 * $SOBE->checkExtObj(); 00103 * 00104 * // THEN WE CALL THE main() METHOD AND THIS SHOULD SPARK THE CREATION OF THE MODULE OUTPUT. 00105 * $SOBE->main(); 00106 * // FINALLY THE printContent() FUNCTION WILL OUTPUT THE ACCUMULATED CONTENT 00107 * $SOBE->printContent(); 00108 */ 00109 00110 /** 00111 * Parent class for 'ScriptClasses' in backend modules. 00112 * See example comment above. 00113 * 00114 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00115 * @package TYPO3 00116 * @subpackage t3lib 00117 * @see t3lib_extobjbase 00118 */ 00119 class t3lib_SCbase { 00120 00121 /** 00122 * Loaded with the global array $MCONF which holds some module configuration from the conf.php file of backend modules. 00123 * @see init() 00124 */ 00125 var $MCONF = array(); 00126 00127 /** 00128 * The integer value of the GET/POST var, 'id'. Used for submodules to the 'Web' module (page id) 00129 * @see init() 00130 */ 00131 var $id; 00132 00133 /** 00134 * The value of GET/POST var, 'CMD' 00135 * @see init() 00136 */ 00137 var $CMD; 00138 00139 /** 00140 * A WHERE clause for selection records from the pages table based on read-permissions of the current backend user. 00141 * @see init() 00142 */ 00143 var $perms_clause; 00144 00145 00146 /** 00147 * The module menu items array. Each key represents a key for which values can range between the items in the array of that key. 00148 * @see init() 00149 */ 00150 var $MOD_MENU = array( 00151 'function' => array() 00152 ); 00153 00154 /** 00155 * Current settings for the keys of the MOD_MENU array 00156 * @see $MOD_MENU 00157 */ 00158 var $MOD_SETTINGS = array(); 00159 00160 /** 00161 * Module TSconfig based on PAGE TSconfig / USER TSconfig 00162 * @see menuConfig() 00163 */ 00164 var $modTSconfig; 00165 00166 /** 00167 * If type is 'ses' then the data is stored as session-lasting data. This means that it'll be wiped out the next time the user logs in. 00168 * Can be set from extension classes of this class before the init() function is called. 00169 * 00170 * @see menuConfig(), t3lib_BEfunc::getModuleData() 00171 */ 00172 var $modMenu_type = ''; 00173 00174 /** 00175 * dontValidateList can be used to list variables that should not be checked if their value is found in the MOD_MENU array. Used for dynamically generated menus. 00176 * Can be set from extension classes of this class before the init() function is called. 00177 * 00178 * @see menuConfig(), t3lib_BEfunc::getModuleData() 00179 */ 00180 var $modMenu_dontValidateList = ''; 00181 00182 /** 00183 * List of default values from $MOD_MENU to set in the output array (only if the values from MOD_MENU are not arrays) 00184 * Can be set from extension classes of this class before the init() function is called. 00185 * 00186 * @see menuConfig(), t3lib_BEfunc::getModuleData() 00187 */ 00188 var $modMenu_setDefaultList = ''; 00189 00190 /** 00191 * Contains module configuration parts from TBE_MODULES_EXT if found 00192 * 00193 * @see handleExternalFunctionValue() 00194 */ 00195 var $extClassConf; 00196 00197 /** 00198 * Contains absolute paths to class files to include from the global scope. This is done in the module index.php files after calling the init() function 00199 * 00200 * @see handleExternalFunctionValue() 00201 */ 00202 var $include_once = array(); 00203 00204 /** 00205 * Generally used for accumulating the output content of backend modules 00206 */ 00207 var $content = ''; 00208 00209 /** 00210 * Generally used to hold an instance of the 'template' class from typo3/template.php 00211 * 00212 * @var template 00213 */ 00214 var $doc; 00215 00216 /** 00217 * May contain an instance of a 'Function menu module' which connects to this backend module. 00218 * 00219 * @see checkExtObj() 00220 */ 00221 var $extObj; 00222 00223 00224 /** 00225 * Initializes the backend module by setting internal variables, initializing the menu. 00226 * 00227 * @return void 00228 * @see menuConfig() 00229 */ 00230 function init() { 00231 // name might be set from outside 00232 if (!$this->MCONF['name']) { 00233 $this->MCONF = $GLOBALS['MCONF']; 00234 } 00235 $this->id = intval(t3lib_div::_GP('id')); 00236 $this->CMD = t3lib_div::_GP('CMD'); 00237 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1); 00238 $this->menuConfig(); 00239 $this->handleExternalFunctionValue(); 00240 } 00241 00242 /** 00243 * Initializes the internal MOD_MENU array setting and unsetting items based on various conditions. It also merges in external menu items from the global array TBE_MODULES_EXT (see mergeExternalItems()) 00244 * Then MOD_SETTINGS array is cleaned up (see t3lib_BEfunc::getModuleData()) so it contains only valid values. It's also updated with any SET[] values submitted. 00245 * Also loads the modTSconfig internal variable. 00246 * 00247 * @return void 00248 * @see init(), $MOD_MENU, $MOD_SETTINGS, t3lib_BEfunc::getModuleData(), mergeExternalItems() 00249 */ 00250 function menuConfig() { 00251 // page/be_user TSconfig settings and blinding of menu-items 00252 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']); 00253 $this->MOD_MENU['function'] = $this->mergeExternalItems($this->MCONF['name'], 'function', $this->MOD_MENU['function']); 00254 $this->MOD_MENU['function'] = t3lib_BEfunc::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function'); 00255 00256 #debug($this->MOD_MENU['function'],$this->MCONF['name']); 00257 #debug($this->modTSconfig['properties']); 00258 00259 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData( 00260 $this->MOD_MENU, 00261 t3lib_div::_GP('SET'), 00262 $this->MCONF['name'], 00263 $this->modMenu_type, 00264 $this->modMenu_dontValidateList, 00265 $this->modMenu_setDefaultList 00266 ); 00267 } 00268 00269 /** 00270 * Merges menu items from global array $TBE_MODULES_EXT 00271 * 00272 * @param string Module name for which to find value 00273 * @param string Menu key, eg. 'function' for the function menu. 00274 * @param array The part of a MOD_MENU array to work on. 00275 * @return array Modified array part. 00276 * @access private 00277 * @see t3lib_extMgm::insertModuleFunction(), menuConfig() 00278 */ 00279 function mergeExternalItems($modName, $menuKey, $menuArr) { 00280 $mergeArray = $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey]; 00281 if (is_array($mergeArray)) { 00282 foreach ($mergeArray as $k => $v) { 00283 if ((string) $v['ws'] === '' || 00284 ($GLOBALS['BE_USER']->workspace === 0 && t3lib_div::inList($v['ws'], 'online')) || 00285 ($GLOBALS['BE_USER']->workspace === -1 && t3lib_div::inList($v['ws'], 'offline')) || 00286 ($GLOBALS['BE_USER']->workspace > 0 && t3lib_div::inList($v['ws'], 'custom'))) { 00287 $menuArr[$k] = $GLOBALS['LANG']->sL($v['title']); 00288 } 00289 } 00290 } 00291 return $menuArr; 00292 } 00293 00294 /** 00295 * Loads $this->extClassConf with the configuration for the CURRENT function of the menu. 00296 * If for this array the key 'path' is set then that is expected to be an absolute path to a file which should be included - so it is set in the internal array $this->include_once 00297 * 00298 * @param string The key to MOD_MENU for which to fetch configuration. 'function' is default since it is first and foremost used to get information per "extension object" (I think that is what its called) 00299 * @param string The value-key to fetch from the config array. If NULL (default) MOD_SETTINGS[$MM_key] will be used. This is usefull if you want to force another function than the one defined in MOD_SETTINGS[function]. Call this in init() function of your Script Class: handleExternalFunctionValue('function', $forcedSubModKey) 00300 * @return void 00301 * @see getExternalItemConfig(), $include_once, init() 00302 */ 00303 function handleExternalFunctionValue($MM_key = 'function', $MS_value = NULL) { 00304 $MS_value = is_null($MS_value) ? $this->MOD_SETTINGS[$MM_key] : $MS_value; 00305 $this->extClassConf = $this->getExternalItemConfig($this->MCONF['name'], $MM_key, $MS_value); 00306 if (is_array($this->extClassConf) && $this->extClassConf['path']) { 00307 $this->include_once[] = $this->extClassConf['path']; 00308 } 00309 } 00310 00311 /** 00312 * Returns configuration values from the global variable $TBE_MODULES_EXT for the module given. 00313 * For example if the module is named "web_info" and the "function" key ($menuKey) of MOD_SETTINGS is "stat" ($value) then you will have the values of $TBE_MODULES_EXT['webinfo']['MOD_MENU']['function']['stat'] returned. 00314 * 00315 * @param string Module name 00316 * @param string Menu key, eg. "function" for the function menu. See $this->MOD_MENU 00317 * @param string Optionally the value-key to fetch from the array that would otherwise have been returned if this value was not set. Look source... 00318 * @return mixed The value from the TBE_MODULES_EXT array. 00319 * @see handleExternalFunctionValue() 00320 */ 00321 function getExternalItemConfig($modName, $menuKey, $value = '') { 00322 return strcmp($value, '') ? $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value] : $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey]; 00323 } 00324 00325 /** 00326 * Creates an instance of the class found in $this->extClassConf['name'] in $this->extObj if any (this should hold three keys, "name", "path" and "title" if a "Function menu module" tries to connect...) 00327 * This value in extClassConf might be set by an extension (in a ext_tables/ext_localconf file) which thus "connects" to a module. 00328 * The array $this->extClassConf is set in handleExternalFunctionValue() based on the value of MOD_SETTINGS[function] 00329 * (Should be) called from global scope right after inclusion of files from the ->include_once array. 00330 * If an instance is created it is initiated with $this passed as value and $this->extClassConf as second argument. Further the $this->MOD_SETTING is cleaned up again after calling the init function. 00331 * 00332 * @return void 00333 * @see handleExternalFunctionValue(), t3lib_extMgm::insertModuleFunction(), $extObj 00334 */ 00335 function checkExtObj() { 00336 if (is_array($this->extClassConf) && $this->extClassConf['name']) { 00337 $this->extObj = t3lib_div::makeInstance($this->extClassConf['name']); 00338 $this->extObj->init($this, $this->extClassConf); 00339 // Re-write: 00340 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData( 00341 $this->MOD_MENU, 00342 t3lib_div::_GP('SET'), 00343 $this->MCONF['name'], 00344 $this->modMenu_type, 00345 $this->modMenu_dontValidateList, 00346 $this->modMenu_setDefaultList 00347 ); 00348 } 00349 } 00350 00351 /** 00352 * Calls the checkExtObj function in sub module if present. 00353 * 00354 * @return void 00355 */ 00356 function checkSubExtObj() { 00357 if (is_object($this->extObj)) { 00358 $this->extObj->checkExtObj(); 00359 } 00360 } 00361 00362 /** 00363 * Calls the 'header' function inside the "Function menu module" if present. 00364 * A header function might be needed to add JavaScript or other stuff in the head. This can't be done in the main function because the head is already written. 00365 * example call in the header function: 00366 * $this->pObj->doc->JScode = $this->pObj->doc->wrapScriptTags(' ... 00367 * 00368 * @return void 00369 */ 00370 function extObjHeader() { 00371 if (is_callable(array($this->extObj, 'head'))) { 00372 $this->extObj->head(); 00373 } 00374 } 00375 00376 /** 00377 * Calls the 'main' function inside the "Function menu module" if present 00378 * 00379 * @return void 00380 */ 00381 function extObjContent() { 00382 $this->extObj->pObj = $this; 00383 00384 if (is_callable(array($this->extObj, 'main'))) { 00385 $this->content .= $this->extObj->main(); 00386 } 00387 } 00388 } 00389 00390 ?>
1.8.0