f77f528175d98d289711dd7a32e78854876f0c9a
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_scbase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (kasper@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 * Contains the parent class for 'ScriptClasses' in backend modules.
29 *
30 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 *
32 * @author Kasper Skårhøj <kasper@typo3.com>
33 * @package TYPO3
34 * @subpackage t3lib
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 136: class t3lib_SCbase
42 * 252: function init()
43 * 269: function menuConfig()
44 * 289: function mergeExternalItems($modName,$menuKey,$menuArr)
45 * 308: function handleExternalFunctionValue($MM_key='function')
46 * 325: function getExternalItemConfig($modName,$menuKey,$value='')
47 * 339: function checkExtObj()
48 * 353: function checkSubExtObj()
49 * 362: function extObjContent()
50 *
51 * TOTAL FUNCTIONS: 8
52 * (This index is automatically created/updated by the extension "extdeveval")
53 *
54 */
55 /**
56 * EXAMPLE PROTOTYPE
57 *
58 * As for examples there are lots of them if you search for classes which extends 't3lib_SCbase'.
59 * 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.
60 * 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.
61 *
62 * // TYPICAL 'HEADER' OF A BACKEND MODULE:
63 * unset($MCONF);
64 * require ('conf.php');
65 * require ($BACK_PATH.'init.php');
66 * require ($BACK_PATH.'template.php');
67 * $LANG->includeLLFile('EXT:prototype/locallang.php');
68 * require_once(PATH_t3lib.'class.t3lib_scbase.php'); // NOTICE THE INCLUSION OF t3lib_SCbase
69 * $BE_USER->modAccess($MCONF,1);
70 *
71 * // SC_mod_prototype EXTENDS THE CLASS t3lib_SCbase with a main() and printContent() function:
72 * class SC_mod_prototype extends t3lib_SCbase {
73 * // MAIN FUNCTION - HERE YOU CREATE THE MODULE CONTENT IN $this->content
74 * function main() {
75 * // TYPICALLY THE INTERNAL VAR, $this->doc is instantiated like this:
76 * $this->doc = t3lib_div::makeInstance('mediumDoc');
77 * // TYPICALLY THE INTERNAL VAR, $this->backPath is set like this:
78 * $this->backPath = $this->doc->backPath = $GLOBALS['BACK_PATH'];
79 * // ... AND OF COURSE A LOT OF OTHER THINGS GOES ON - LIKE PUTTING CONTENT INTO $this->content
80 * $this->content='';
81 * }
82 * // PRINT CONTENT - DONE AS THE LAST THING
83 * function printContent() {
84 * echo $this->content;
85 * }
86 * }
87 *
88 * // CHECKING IF THERE ARE AN EXTENSION CLASS CONFIGURED FOR THIS CLASS:
89 * if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/prototype/index.php']) {
90 * include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/prototype/index.php']);
91 * }
92 *
93 * // MAKE INSTANCE OF THE SCRIPT CLASS AND CALL init()
94 * $SOBE = t3lib_div::makeInstance('SC_mod_prototype');
95 * $SOBE->init();
96 *
97 * // AFTER INIT THE INTERNAL ARRAY ->include_once MAY HOLD FILENAMES TO INCLUDE
98 * reset($SOBE->include_once);
99 * while(list(,$INC_FILE)=each($SOBE->include_once)) {include_once($INC_FILE);}
100 *
101 * // THEN WE WILL CHECK IF THERE IS A 'SUBMODULE' REGISTERED TO BE INITIALIZED AS WELL:
102 * $SOBE->checkExtObj();
103 *
104 * // THEN WE CALL THE main() METHOD AND THIS SHOULD SPARK THE CREATION OF THE MODULE OUTPUT.
105 * $SOBE->main();
106 * // FINALLY THE printContent() FUNCTION WILL OUTPUT THE ACCUMULATED CONTENT
107 * $SOBE->printContent();
108 */
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 /**
130 * Parent class for 'ScriptClasses' in backend modules.
131 * See example comment above.
132 *
133 * @author Kasper Skårhøj <kasper@typo3.com>
134 * @see t3lib_extobjbase
135 */
136 class t3lib_SCbase {
137
138 /**
139 * Loaded with the global array $MCONF which holds some module configuration from the conf.php file of backend modules.
140 * @see init()
141 */
142 var $MCONF=array();
143
144 /**
145 * The integer value of the GET/POST var, 'id'. Used for submodules to the 'Web' module.
146 * @see init()
147 */
148 var $id;
149
150 /**
151 * The value of GET/POST var, 'CMD'
152 * @see init()
153 */
154 var $CMD;
155
156 /**
157 * A WHERE clause for selection records from the pages table based on read-permissions of the current backend user.
158 * @see init()
159 */
160 var $perms_clause;
161
162
163
164 /**
165 * The module menu items array. Each key represents a key for which values can range between the items in the array of that key.
166 * @see init()
167 */
168 var $MOD_MENU= Array (
169 'function' => array()
170 );
171
172 /**
173 * Current settings for the keys of the MOD_MENU array
174 * @see $MOD_MENU
175 */
176 var $MOD_SETTINGS=array();
177
178 /**
179 * Module TSconfig based on PAGE TSconfig / USER TSconfig
180 * @see menuConfig()
181 */
182 var $modTSconfig;
183
184 /**
185 * 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.
186 * Can be set from extension classes of this class before the init() function is called.
187 *
188 * @see menuConfig(), t3lib_BEfunc::getModuleData()
189 */
190 var $modMenu_type = '';
191
192 /**
193 * 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.
194 * Can be set from extension classes of this class before the init() function is called.
195 *
196 * @see menuConfig(), t3lib_BEfunc::getModuleData()
197 */
198 var $modMenu_dontValidateList = '';
199
200 /**
201 * List of default values from $MOD_MENU to set in the output array (only if the values from MOD_MENU are not arrays)
202 * Can be set from extension classes of this class before the init() function is called.
203 *
204 * @see menuConfig(), t3lib_BEfunc::getModuleData()
205 */
206 var $modMenu_setDefaultList = '';
207
208 /**
209 * Contains module configuration parts from TBE_MODULES_EXT if found
210 *
211 * @see handleExternalFunctionValue()
212 */
213 var $extClassConf;
214
215 /**
216 * 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
217 *
218 * @see handleExternalFunctionValue()
219 */
220 var $include_once=array();
221
222 /**
223 * Generally used for accumulating the output content of backend modules
224 */
225 var $content='';
226
227 /**
228 * Generally used to hold an instance of the 'template' class from typo3/template.php
229 */
230 var $doc;
231
232 /**
233 * May contain an instance of a 'Function menu module' which connects to this backend module.
234 *
235 * @see checkExtObj()
236 */
237 var $extObj;
238
239
240
241
242
243
244
245
246 /**
247 * Initializes the backend module by setting internal variables, initializing the menu.
248 *
249 * @return void
250 * @see menuConfig()
251 */
252 function init() {
253 $this->MCONF = $GLOBALS['MCONF'];
254 $this->id = intval(t3lib_div::GPvar('id'));
255 $this->CMD = t3lib_div::GPvar('CMD');
256 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
257 $this->menuConfig();
258 $this->handleExternalFunctionValue();
259 }
260
261 /**
262 * 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())
263 * 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.
264 * Also loads the modTSconfig internal variable.
265 *
266 * @return void
267 * @see init(), $MOD_MENU, $MOD_SETTINGS, t3lib_BEfunc::getModuleData(), mergeExternalItems()
268 */
269 function menuConfig() {
270 // page/be_user TSconfig settings and blinding of menu-items
271 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']);
272 $this->MOD_MENU['function'] = $this->mergeExternalItems($this->MCONF['name'],'function',$this->MOD_MENU['function']);
273 $this->MOD_MENU['function'] = t3lib_BEfunc::unsetMenuItems($this->modTSconfig['properties'],$this->MOD_MENU['function'],'menu.function');
274
275 // CLEANSE 'function' SETTINGS
276 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::GPvar('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
277 }
278
279 /**
280 * Merges menu items from global array $TBE_MODULES_EXT
281 *
282 * @param string Module name for which to find value
283 * @param string Menu key, eg. 'function' for the function menu.
284 * @param array The part of a MOD_MENU array to work on.
285 * @return array Modified array part.
286 * @access private
287 * @see t3lib_extMgm::insertModuleFunction(), menuConfig()
288 */
289 function mergeExternalItems($modName,$menuKey,$menuArr) {
290 $mergeArray = $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
291 if (is_array($mergeArray)) {
292 reset($mergeArray);
293 while(list($k,$v)=each($mergeArray)) {
294 $menuArr[$k]=$GLOBALS['LANG']->sL($v['title']);
295 }
296 }
297 return $menuArr;
298 }
299
300 /**
301 * Loads $this->extClassConf with the configuration for the CURRENT function of the menu.
302 * 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
303 *
304 * @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)
305 * @return void
306 * @see $include_once, init()
307 */
308 function handleExternalFunctionValue($MM_key='function') {
309 $this->extClassConf = $this->getExternalItemConfig($this->MCONF['name'],$MM_key,$this->MOD_SETTINGS[$MM_key]);
310 if (is_array($this->extClassConf) && $this->extClassConf['path']) {
311 $this->include_once[]=$this->extClassConf['path'];
312 }
313 }
314
315 /**
316 * Returns configuration values from the global variable $TBE_MODULES_EXT for the module given.
317 * 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.
318 *
319 * @param string Module name
320 * @param string Menu key, eg. "function" for the function menu. See $this->MOD_MENU
321 * @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...
322 * @return mixed The value from the TBE_MODULES_EXT array.
323 * @see handleExternalFunctionValue()
324 */
325 function getExternalItemConfig($modName,$menuKey,$value='') {
326 return strcmp($value,'')?$GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value]:$GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
327 }
328
329 /**
330 * 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...)
331 * This value in extClassConf might be set by an extension (in a ext_tables/ext_localconf file) which thus "connects" to a module.
332 * The array $this->extClassConf is set in handleExternalFunctionValue() based on the value of MOD_SETTINGS[function]
333 * (Should be) called from global scope right after inclusion of files from the ->include_once array.
334 * 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.
335 *
336 * @return void
337 * @see handleExternalFunctionValue(), t3lib_extMgm::insertModuleFunction(), $extObj
338 */
339 function checkExtObj() {
340 if (is_array($this->extClassConf) && $this->extClassConf['name']) {
341 $this->extObj = t3lib_div::makeInstance($this->extClassConf['name']);
342 $this->extObj->init($this,$this->extClassConf);
343 // Re-write:
344 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::GPvar('SET'), $this->MCONF['name']);
345 }
346 }
347
348 /**
349 * Calls the checkExtObj function in sub module if present.
350 *
351 * @return void
352 */
353 function checkSubExtObj() {
354 if (is_object($this->extObj)) $this->extObj->checkExtObj();
355 }
356
357 /**
358 * Calls the main function inside the "Function menu module" if present
359 *
360 * @return void
361 */
362 function extObjContent() {
363 if (is_object($this->extObj)) $this->content.=$this->extObj->main();
364 }
365 }
366 ?>