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