7f12bae0d1d90bb8618852db0779961acdb7d2cd
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_extmgm.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 a class with Extension Management functions
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 * 111: class t3lib_extMgm
42 *
43 * SECTION: PATHS and other evaluation
44 * 127: function isLoaded($key,$exitOnError=0)
45 * 142: function extPath($key,$script='')
46 * 156: function extRelPath($key)
47 * 170: function siteRelPath($key)
48 * 181: function getCN($key)
49 *
50 * SECTION: Adding BACKEND features
51 * 213: function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
52 * 235: function addToAllTCAtypes($table,$str,$specificTypesList='')
53 * 253: function allowTableOnStandardPages($table)
54 * 269: function addModule($main,$sub='',$position='',$path='')
55 * 330: function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function')
56 * 347: function addPageTSConfig($content)
57 * 360: function addUserTSConfig($content)
58 * 373: function addLLrefForTCAdescr($tca_descr_key,$file_ref)
59 *
60 * SECTION: Adding SERVICES features
61 * 416: function addService($extKey, $serviceType, $serviceKey, $info)
62 * 483: function findService($serviceType, $serviceSubType='', $excludeServiceKeys='')
63 * 528: function deactivateService($serviceType, $serviceKey)
64 *
65 * SECTION: Adding FRONTEND features
66 * 567: function addPlugin($itemArray,$type='list_type')
67 * 591: function addPiFlexFormValue($piKeyToMatch,$value)
68 * 607: function addToInsertRecords($table)
69 * 637: function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
70 * 711: function addStaticFile($extKey,$path,$title)
71 * 729: function addTypoScriptSetup($content)
72 * 742: function addTypoScriptConstants($content)
73 * 758: function addTypoScript($key,$type,$content,$afterStaticUid=0)
74 *
75 * SECTION: INTERNAL EXTENSION MANAGEMENT:
76 * 820: function typo3_loadExtensions()
77 * 899: function _makeIncludeHeader($key,$file)
78 * 919: function isCacheFilesAvailable($cacheFilePrefix)
79 * 931: function isLocalconfWritable()
80 * 943: function cannotCacheFilesWritable($cacheFilePrefix)
81 * 966: function currentCacheFiles()
82 * 988: function writeCacheFiles($extensions,$cacheFilePrefix)
83 *
84 * TOTAL FUNCTIONS: 31
85 * (This index is automatically created/updated by the extension "extdeveval")
86 *
87 */
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 /**
105 * Extension Management functions
106 *
107 * This class is never instantiated, rather the methods inside is called as functions like
108 * t3lib_extMgm::isLoaded('my_extension');
109 *
110 */
111 class t3lib_extMgm {
112
113
114 /**************************************
115 *
116 * PATHS and other evaluation
117 *
118 ***************************************/
119
120 /**
121 * Returns true if the extension with extension key $key is loaded.
122 *
123 * @param string Extension key to test
124 * @param boolean If $exitOnError is true and the extension is not loaded the function will die with an error message
125 * @return boolean
126 */
127 function isLoaded($key,$exitOnError=0) {
128 global $TYPO3_LOADED_EXT;
129 if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key])) die('Fatal Error: Extension "'.$key.'" was not loaded.');
130 return isset($TYPO3_LOADED_EXT[$key]);
131 }
132
133 /**
134 * Returns the absolute path to the extension with extension key $key
135 * If the extension is not loaded the function will die with an error message
136 * Useful for internal fileoperations
137 *
138 * @param string Extension key
139 * @param string $script is appended to the output if set.
140 * @return string
141 */
142 function extPath($key,$script='') {
143 global $TYPO3_LOADED_EXT;
144 if (!isset($TYPO3_LOADED_EXT[$key])) die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!');
145 return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
146 }
147
148 /**
149 * Returns the relative path to the extension as measured from from the TYPO3_mainDir
150 * If the extension is not loaded the function will die with an error message
151 * Useful for images and links from backend
152 *
153 * @param string Extension key
154 * @return string
155 */
156 function extRelPath($key) {
157 global $TYPO3_LOADED_EXT;
158 if (!isset($TYPO3_LOADED_EXT[$key])) die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!');
159 return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
160 }
161
162 /**
163 * Returns the relative path to the extension as measured from the PATH_site (frontend)
164 * If the extension is not loaded the function will die with an error message
165 * Useful for images and links from the frontend
166 *
167 * @param string Extension key
168 * @return string
169 */
170 function siteRelPath($key) {
171 return substr(t3lib_extMgm::extPath($key),strlen(PATH_site));
172 }
173
174 /**
175 * Returns the correct class name prefix for the extension key $key
176 *
177 * @param string Extension key
178 * @return string
179 * @internal
180 */
181 function getCN($key) {
182 return substr($key,0,5)=='user_' ? 'user_'.str_replace('_','',substr($key,5)) : 'tx_'.str_replace('_','',$key);
183 }
184
185
186
187
188
189
190
191
192
193
194 /**************************************
195 *
196 * Adding BACKEND features
197 * (related to core features)
198 *
199 ***************************************/
200
201 /**
202 * Adding fields to an existing table definition in $TCA
203 * Adds an array with $TCA column-configuration to the $TCA-entry for that table.
204 * This function adds the configuration needed for rendering of the field in TCEFORMS - but it does NOT add the field names to the types lists!
205 * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
206 * FOR USE IN ext_tables.php FILES
207 *
208 * @param string $table is the table name of a table already present in $TCA with a columns section
209 * @param array $columnArray is the array with the additional columns (typical some fields an extension wants to add)
210 * @param boolean If $addTofeInterface is true the list of fields are also added to the fe_admin_fieldList.
211 * @return void
212 */
213 function addTCAcolumns($table,$columnArray,$addTofeInterface=0) {
214 global $TCA;
215 t3lib_div::loadTCA($table);
216 if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
217 $TCA[$table]['columns'] = array_merge($TCA[$table]['columns'],$columnArray); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
218 if ($addTofeInterface) $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',',array_keys($columnArray));
219 }
220 }
221
222 /**
223 * Makes fields visible on the form, adding them to the end.
224 *
225 * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
226 * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
227 * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
228 * FOR USE IN ext_tables.php FILES
229 *
230 * @param string Table name
231 * @param string Field list to add.
232 * @param string List of specific types to add the field list to. (If empty, all type entries are affected)
233 * @return void
234 */
235 function addToAllTCAtypes($table,$str,$specificTypesList='') {
236 global $TCA;
237 t3lib_div::loadTCA($table);
238 if (trim($str) && is_array($TCA[$table]) && is_array($TCA[$table]['types'])) {
239 foreach($TCA[$table]['types'] as $k => $v) {
240 if (!$specificTypesList || t3lib_div::inList($specificTypesList,$k)) $TCA[$table]['types'][$k]['showitem'].=', '.trim($str);
241 }
242 }
243 }
244
245 /**
246 * Add tablename to default list of allowed tables on pages.
247 * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
248 * FOR USE IN ext_tables.php FILES
249 *
250 * @param string Table name
251 * @return void
252 */
253 function allowTableOnStandardPages($table) {
254 global $PAGES_TYPES;
255
256 $PAGES_TYPES['default']['allowedTables'].=','.$table;
257 }
258
259 /**
260 * Adds a module (main or sub) to the backend interface
261 * FOR USE IN ext_tables.php FILES
262 *
263 * @param string $main is the main module key, $sub is the submodule key. So $main would be an index in the $TBE_MODULES array and $sub could be an element in the lists there.
264 * @param string $sub is the submodule key. If $sub is not set a blank $main module is created.
265 * @param string $position can be used to set the position of the $sub module within the list of existing submodules for the main module. $position has this syntax: [cmd]:[submodule-key]. cmd can be "after", "before" or "top" (or blank which is default). If "after"/"before" then submodule will be inserted after/before the existing submodule with [submodule-key] if found. If not found, the bottom of list. If "top" the module is inserted in the top of the submodule list.
266 * @param string $path is the absolute path to the module. If this value is defined the path is added as an entry in $TBE_MODULES['_PATHS'][ main_sub ]=$path; and thereby tells the backend where the newly added modules is found in the system.
267 * @return void
268 */
269 function addModule($main,$sub='',$position='',$path='') {
270 global $TBE_MODULES;
271
272 if (isset($TBE_MODULES[$main]) && $sub) { // If there is already a main module by this name:
273
274 // Adding the submodule to the correct position:
275 list($place,$modRef)=t3lib_div::trimExplode(':',$position,1);
276 $mods = t3lib_div::trimExplode(',',$TBE_MODULES[$main],1);
277 if (!in_array($sub,$mods)) {
278 switch(strtolower($place)) {
279 case 'after':
280 case 'before':
281 $pointer=0;
282 reset($mods);
283 while(list($k,$m)=each($mods)) {
284 if (!strcmp($m,$modRef)) {
285 $pointer=strtolower($place)=='after'?$k+1:$k;
286 }
287 }
288 array_splice(
289 $mods, // The modules array
290 $pointer, // To insert one position from the end of the list
291 0, // Don't remove any items, just insert
292 $sub // Module to insert
293 );
294 break;
295 default:
296 if (strtolower($place)=='top') {
297 array_unshift($mods,$sub);
298 } else {
299 array_push($mods,$sub);
300 }
301 break;
302 }
303 }
304 // Re-inserting the submodule list:
305 $TBE_MODULES[$main]=implode(',',$mods);
306 } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank)
307 $TBE_MODULES[$main]=$sub;
308 }
309
310 // Adding path:
311 if ($path) {
312 $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')]=$path;
313 }
314 }
315
316 /**
317 * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
318 * The arguments values are generally determined by which function menu this is supposed to interact with
319 * See Inside TYPO3 for information on how to use this function.
320 * FOR USE IN ext_tables.php FILES
321 *
322 * @param string Module name
323 * @param string Class name
324 * @param string Class path
325 * @param string Title
326 * @param string
327 * @return void
328 * @see t3lib_SCbase::mergeExternalItems()
329 */
330 function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function') {
331 global $TBE_MODULES_EXT;
332 $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className]=array(
333 'name' => $className,
334 'path' => $classPath,
335 'title' => $title,
336 );
337 }
338
339 /**
340 * Adds $content to the default Page TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultPageTSconfig']
341 * Prefixed with a [GLOBAL] line
342 * FOR USE IN ext_tables.php/ext_locallang.php FILES
343 *
344 * @param string
345 * @return void
346 */
347 function addPageTSConfig($content) {
348 global $TYPO3_CONF_VARS;
349 $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
350 }
351
352 /**
353 * Adds $content to the default User TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultUserTSconfig']
354 * Prefixed with a [GLOBAL] line
355 * FOR USE IN ext_tables.php/ext_locallang.php FILES
356 *
357 * @param string
358 * @return void
359 */
360 function addUserTSConfig($content) {
361 global $TYPO3_CONF_VARS;
362 $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
363 }
364
365 /**
366 * Adds a reference to a locallang file with TCA_DESCR labels
367 * FOR USE IN ext_tables.php FILES
368 *
369 * @param string
370 * @param string
371 * @return void
372 */
373 function addLLrefForTCAdescr($tca_descr_key,$file_ref) {
374 global $TCA_DESCR;
375 if ($tca_descr_key) {
376 if (!is_array($TCA_DESCR[$tca_descr_key])) {
377 $TCA_DESCR[$tca_descr_key]=array();
378 }
379 if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
380 $TCA_DESCR[$tca_descr_key]['refs']=array();
381 }
382 $TCA_DESCR[$tca_descr_key]['refs'][]=$file_ref;
383 }
384 }
385
386
387
388
389
390
391
392
393
394
395
396
397
398 /**************************************
399 *
400 * Adding SERVICES features
401 *
402 * @author René Fritz <r.fritz@colorcube.de>
403 *
404 ***************************************/
405
406 /**
407 * Adds a service to the global services array
408 *
409 * @param string Extension key
410 * @param string Service type
411 * @param string Service key
412 * @param array Service description array
413 * @return void
414 * @author René Fritz <r.fritz@colorcube.de>
415 */
416 function addService($extKey, $serviceType, $serviceKey, $info) {
417 global $T3_SERVICES,$TYPO3_CONF_VARS;
418
419 // even not available services will be included to make it possible to give the admin a feedback of non-available services.
420 // but maybe it's better to move non-available services to a different array??
421 #debug($serviceType);
422 #debug($serviceKey);
423 #debug($info);
424 if ($serviceType AND substr($serviceType,0,3)!='tx_' AND substr($serviceKey,0,3)=='tx_' AND is_array($info)) {
425 #debug($extKey);
426 $info['priority'] = max(0,min(100,$info['priority']));
427
428 $T3_SERVICES[$serviceType][$serviceKey]=$info;
429
430 $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
431 $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
432 $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
433
434
435 // mapping a service key to a service type
436 // all service keys begin with tx_ - service types don't
437 // this way a selection of a special service key as service type is easy
438 $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
439
440
441 // change the priority (and other values) from TYPO3_CONF_VARS
442 // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
443 // even the activation is possible (a unix service might be possible on windows for some reasons)
444 if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
445
446 // no check is done here - there might be configuration values only the service type knows about, so we pass everything
447 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey],$TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
448 }
449
450
451 // OS check
452 // empty $os means 'not limited to one OS', therefore a check is not needed
453 if ($T3_SERVICES[$serviceType][$serviceKey]['available'] AND $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
454
455 // TYPO3_OS is not yet defined
456 $os_type = stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
457
458 $os = t3lib_div::trimExplode(',',strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
459
460 if (!in_array($os_type,$os)) {
461 t3lib_extMgm::deactivateService($serviceType, $serviceKey);
462 }
463 }
464
465 // convert subtype list to array for quicker access
466 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
467 $serviceSubTypes = t3lib_div::trimExplode(',',$info['subtype']);
468 foreach ($serviceSubTypes as $subtype) {
469 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
470 }
471 }
472 }
473
474 /**
475 * Find the available service with highest priority
476 *
477 * @param string Service type
478 * @param string Service sub type
479 * @param string Service key that should be excluded in the search for a service
480 * @return mixed Service info array if a service was found, FLASE otherwise
481 * @author René Fritz <r.fritz@colorcube.de>
482 */
483 function findService($serviceType, $serviceSubType='', $excludeServiceKeys='') {
484 global $T3_SERVICES;
485
486 $serviceKey = FALSE;
487 $serviceInfo = FALSE;
488 $priority = 0;
489 $quality = 0;
490
491 if (is_array($T3_SERVICES[$serviceType])) {
492 foreach($T3_SERVICES[$serviceType] as $key => $info) {
493 if (t3lib_div::inList($excludeServiceKeys,$key)) {
494 continue;
495 }
496
497 // select a subtype randomly
498 // usefull to start a service by service key without knowing his subtypes - for testing purposes
499 if ($serviceSubType=='*') {
500 $serviceSubType = key($info['serviceSubTypes']);
501 }
502
503 if( $info['available'] AND ($info['subtype']=='' XOR $info['serviceSubTypes'][$serviceSubType]) AND $info['priority']>=$priority ) {
504 if($info['priority']==$priority AND $info['quality']<$quality) {
505 continue;
506 }
507 $serviceKey = $key;
508 $priority = $info['priority'];
509 $quality = $info['quality'];
510 }
511 }
512 }
513
514 if ($serviceKey) {
515 $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
516 }
517 return $serviceInfo;
518 }
519
520 /**
521 * Deactivate a service
522 *
523 * @param string Service type
524 * @param string Service key
525 * @return void
526 * @author René Fritz <r.fritz@colorcube.de>
527 */
528 function deactivateService($serviceType, $serviceKey) {
529 global $T3_SERVICES;
530
531 // ... maybe it's better to move non-available services to a different array??
532 $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
533 }
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548 /**************************************
549 *
550 * Adding FRONTEND features
551 * (related specifically to "cms" extension)
552 *
553 ***************************************/
554
555 /**
556 * Adds an entry to the list of plugins in content elements of type "Insert plugin"
557 *
558 * Takes the $itemArray (label,value[,icon]) and adds to the items-array of $TCA[tt_content] elements with CType "listtype" (or another field if $type points to another fieldname)
559 * If the value (array pos. 1) is already found in that items-array, the entry is substituted, otherwise the input array is added to the bottom.
560 * Use this function to add a frontend plugin to this list of plugin-types - or more generally use this function to add an entry to any selectorbox/radio-button set in the TCEFORMS
561 * FOR USE IN ext_tables.php FILES
562 *
563 * @param array Item Array
564 * @param string Type
565 * @return void
566 */
567 function addPlugin($itemArray,$type='list_type') {
568 global $TCA;
569 t3lib_div::loadTCA('tt_content');
570 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
571 reset($TCA['tt_content']['columns'][$type]['config']['items']);
572 while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items'])) {
573 if (!strcmp($v[1],$itemArray[1])) {
574 $TCA['tt_content']['columns'][$type]['config']['items'][$k]=$itemArray;
575 return;
576 }
577 }
578 $TCA['tt_content']['columns'][$type]['config']['items'][]=$itemArray;
579 }
580 }
581
582 /**
583 * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
584 * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin.
585 *
586 * @param string The same value as the key for the plugin
587 * @param string Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
588 * @return void
589 * @see addPlugin()
590 */
591 function addPiFlexFormValue($piKeyToMatch,$value) {
592 global $TCA;
593 t3lib_div::loadTCA('tt_content');
594
595 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
596 $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch] = $value;
597 }
598 }
599
600 /**
601 * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
602 * FOR USE IN ext_tables.php FILES
603 *
604 * @param string Table name
605 * @return void
606 */
607 function addToInsertRecords($table) {
608 global $TCA;
609 t3lib_div::loadTCA('tt_content');
610 if (is_array($TCA['tt_content']['columns']) && isset($TCA['tt_content']['columns']['records']['config']['allowed'])) {
611 $TCA['tt_content']['columns']['records']['config']['allowed'].=','.$table;
612 }
613 }
614
615 /**
616 * Add PlugIn to Static Template #43
617 *
618 * When adding a frontend plugin you will have to add both an entry to the TCA definition of tt_content table AND to the TypoScript template which must initiate the rendering.
619 * Since the static template with uid 43 is the "content.default" and practically always used for rendering the content elements it's very useful to have this function automatically adding the necessary TypoScript for calling your plugin.
620 * $type determines the type of frontend plugin:
621 * "list_type" (default) - the good old "Insert plugin" entry
622 * "menu_type" - a "Menu/Sitemap" entry
623 * "splash_layout" - a "Textbox" entry
624 * "CType" - a new content element type
625 * "header_layout" - an additional header type (added to the selection of layout1-5)
626 * "includeLib" - just includes the library for manual use somewhere in TypoScript.
627 * (Remember that your $type definition should correspond to the column/items array in $TCA[tt_content] where you added the selector item for the element! See addPlugin() function)
628 * FOR USE IN ext_locallang.php FILES
629 *
630 * @param string $key is the extension key
631 * @param string $classFile is the PHP-class filename relative to the extension root directory. If set to blank a default value is chosen according to convensions.
632 * @param string $prefix is used as a - yes, suffix - of the class name (fx. "_pi1")
633 * @param string $type, see description above
634 * @param boolean If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
635 * @return void
636 */
637 function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0) {
638 global $TYPO3_LOADED_EXT;
639 $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_','',$key).$prefix.'.php';
640 $cN = t3lib_extMgm::getCN($key);
641
642 // General plugin:
643 if ($cached) {
644 $pluginContent = trim('
645 includeLibs.'.$cN.$prefix.' = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
646 plugin.'.$cN.$prefix.' = USER
647 plugin.'.$cN.$prefix.' {
648 userFunc = '.$cN.$prefix.'->main
649 }');
650 } else {
651 $pluginContent = trim('
652 plugin.'.$cN.$prefix.' = USER_INT
653 plugin.'.$cN.$prefix.' {
654 includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
655 userFunc = '.$cN.$prefix.'->main
656 }');
657 }
658 t3lib_extMgm::addTypoScript($key,'setup','
659 # Setting '.$key.' plugin TypoScript
660 '.$pluginContent);
661
662 // After ST43:
663 switch($type) {
664 case 'list_type':
665 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
666 break;
667 case 'menu_type':
668 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
669 break;
670 case 'splash_layout':
671 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
672 break;
673 case 'CType':
674 $addLine = trim('
675 tt_content.'.$key.$prefix.' = COA
676 tt_content.'.$key.$prefix.' {
677 10 = < lib.stdheader
678 20 = < plugin.'.$cN.$prefix.'
679 }
680 ');
681 break;
682 case 'header_layout':
683 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
684 break;
685 case 'includeLib':
686 $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
687 break;
688 default:
689 $addLine = '';
690 break;
691 }
692 if ($addLine) {
693 t3lib_extMgm::addTypoScript($key,'setup','
694 # Setting '.$key.' plugin TypoScript
695 '.$addLine.'
696 ',43);
697 }
698 }
699
700 /**
701 * Call this method to add an entry in the static template list found in sys_templates
702 * "static template files" are the modern equalent (provided from extensions) to the traditional records in "static_templates"
703 * FOR USE IN ext_locallang.php FILES
704 *
705 * @param string $extKey is of course the extension key
706 * @param string $path is the path where the template files (fixed names) include_static.txt (integer list of uids from the table "static_templates"), constants.txt, setup.txt and editorcfg.txt is found (relative to extPath, eg. 'static/')
707 * @param string $title is the title in the selector box.
708 * @return void
709 * @see addTypoScript()
710 */
711 function addStaticFile($extKey,$path,$title) {
712 global $TCA;
713 t3lib_div::loadTCA('sys_template');
714 if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
715 $value = str_replace(',','','EXT:'.$extKey.'/'.$path);
716 $itemArray=array(trim($title.' ('.$extKey.')'),$value);
717 $TCA['sys_template']['columns']['include_static_file']['config']['items'][]=$itemArray;
718 }
719 }
720
721 /**
722 * Adds $content to the default TypoScript setup code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_setup']
723 * Prefixed with a [GLOBAL] line
724 * FOR USE IN ext_locallang.php FILES
725 *
726 * @param string TypoScript
727 * @return void
728 */
729 function addTypoScriptSetup($content) {
730 global $TYPO3_CONF_VARS;
731 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
732 }
733
734 /**
735 * Adds $content to the default TypoScript constants code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_constants']
736 * Prefixed with a [GLOBAL] line
737 * FOR USE IN ext_locallang.php FILES
738 *
739 * @param string
740 * @return void
741 */
742 function addTypoScriptConstants($content) {
743 global $TYPO3_CONF_VARS;
744 $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
745 }
746
747 /**
748 * Adds $content to the default TypoScript code for either setup, constants or editorcfg as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_*']
749 * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
750 * FOR USE IN ext_locallang.php FILES
751 *
752 * @param string $key is the extension key (informative only).
753 * @param string $type is either "setup", "constants" or "editorcfg" and obviously determines which kind of TypoScript code we are adding.
754 * @param string $content is the TS content, prefixed with a [GLOBAL] line and a comment-header.
755 * @param string $afterStaticUid is either an integer pointing to a uid of a static_template or a string pointing to the "key" of a static_file template ([reduced extension_key]/[local path]). The points is that the TypoScript you add is included only IF that static template is included (and in that case, right after). So effectively the TypoScript you set can specifically overrule settings from those static templates.
756 * @return void
757 */
758 function addTypoScript($key,$type,$content,$afterStaticUid=0) {
759 global $TYPO3_CONF_VARS;
760
761 if ($type=='setup' || $type=='editorcfg' || $type=='constants') {
762 $content = '
763
764 [GLOBAL]
765 #############################################
766 ## TypoScript added by extension "'.$key.'"
767 #############################################
768
769 '.$content;
770 if ($afterStaticUid) {
771 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
772 if ($afterStaticUid==43) { // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
773 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content;
774 }
775 } else {
776 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
777 }
778 }
779 }
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798 /**************************************
799 *
800 * INTERNAL EXTENSION MANAGEMENT:
801 *
802 ***************************************/
803
804 /**
805 * Loading extensions configured in $TYPO3_CONF_VARS['EXT']['extList']
806 *
807 * CACHING ON: ($TYPO3_CONF_VARS['EXT']['extCache'] = 1 or 2)
808 * If caching is enabled (and possible), the output will be $extensions['_CACHEFILE'] set to the cacheFilePrefix. Subsequently the cache files must be included then since those will eventually set up the extensions.
809 * If cachefiles are not found they will be generated
810 * CACHING OFF: ($TYPO3_CONF_VARS['EXT']['extCache'] = 0)
811 * The returned value will be an array where each key is an extension key and the value is an array with filepaths for the extension.
812 * This array will later be set in the global var $TYPO3_LOADED_EXT
813 *
814 * Usages of this function can be see in config_default.php
815 * Extensions are always detected in the order local - global - system.
816 *
817 * @return array Extension Array
818 * @internal
819 */
820 function typo3_loadExtensions() {
821 global $TYPO3_CONF_VARS;
822
823 // Full list of extensions includes both required and extList:
824 $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'].','.$TYPO3_CONF_VARS['EXT']['extList'];
825
826 // Empty array as a start.
827 $extensions = array();
828
829 //
830 if ($rawExtList) {
831 // The cached File prefix.
832 $cacheFilePrefix = 'temp_CACHED';
833 // Setting the name for the cache files:
834 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1) $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']),0,4);
835 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
836
837 // If cache files available, set cache file prefix and return:
838 if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) {
839 // Return cache file prefix:
840 $extensions['_CACHEFILE'] = $cacheFilePrefix;
841 } else {
842 // ... but if not, configure...
843 $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
844 while(list(,$temp_extKey)=each($temp_extensions)) {
845 if (@is_dir(PATH_site.'typo3conf/ext/'.$temp_extKey)) {
846 $extensions[$temp_extKey]=array('type'=>'L','siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/','typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
847 } elseif (@is_dir(PATH_site.TYPO3_mainDir.'ext/'.$temp_extKey)) {
848 $extensions[$temp_extKey]=array('type'=>'G','siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/','typo3RelPath'=>'ext/'.$temp_extKey.'/');
849 } elseif (@is_dir(PATH_site.TYPO3_mainDir.'sysext/'.$temp_extKey)) {
850 $extensions[$temp_extKey]=array('type'=>'S','siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/','typo3RelPath'=>'sysext/'.$temp_extKey.'/');
851 }
852
853 $files = t3lib_div::trimExplode(',','
854 ext_localconf.php,
855 ext_tables.php,
856 ext_tables.sql,
857 ext_tables_static+adt.sql,
858 ext_typoscript_constants.txt,
859 ext_typoscript_editorcfg.txt,
860 ext_typoscript_setup.txt
861 ',1);
862 reset($files);
863 while(list(,$fName)=each($files)) {
864 $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
865 if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
866 $extensions[$temp_extKey][$fName]=$temp_filename;
867 }
868 }
869 }
870 unset($extensions['_CACHEFILE']);
871
872
873 // write cache?
874 if ($TYPO3_CONF_VARS['EXT']['extCache']) {
875 $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
876 if ($wrError) {
877 //debug('Cannot write cache files: '.$wrError.'. Disabling the cache...');
878 $TYPO3_CONF_VARS['EXT']['extCache']=0;
879 } else {
880 // Write cache files:
881 $extensions = t3lib_extMgm::writeCacheFiles($extensions,$cacheFilePrefix);
882 }
883 }
884 }
885 }
886
887 #debug($extensions);
888 return $extensions;
889 }
890
891 /**
892 * Returns the section headers for the compiled cache-files.
893 *
894 * @param string $key is the extension key
895 * @param string $file is the filename (only informative for comment)
896 * @return string
897 * @internal
898 */
899 function _makeIncludeHeader($key,$file) {
900 return '<?php
901 ###########################
902 ## EXTENSION: '.$key.'
903 ## FILE: '.$file.'
904 ###########################
905
906 $_EXTKEY = \''.$key.'\';
907 $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
908
909 ?>';
910 }
911
912 /**
913 * Returns true if both the localconf and tables cache file exists (with $cacheFilePrefix)
914 *
915 * @param string
916 * @return boolean
917 * @internal
918 */
919 function isCacheFilesAvailable($cacheFilePrefix) {
920 return
921 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
922 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php');
923 }
924
925 /**
926 * Returns true if the "localconf.php" file in "typo3conf/" is writable
927 *
928 * @return boolean
929 * @internal
930 */
931 function isLocalconfWritable() {
932 return is_writeable(PATH_typo3conf) && is_writeable(PATH_typo3conf.'localconf.php');
933 }
934
935 /**
936 * Returns an error string if typo3conf/ or cache-files with $cacheFilePrefix are NOT writable
937 * Returns false if no problem.
938 *
939 * @param string
940 * @return string
941 * @internal
942 */
943 function cannotCacheFilesWritable($cacheFilePrefix) {
944 $error=array();
945 if (!@is_writeable(PATH_typo3conf)) {
946 $error[]=PATH_typo3conf;
947 }
948 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
949 !@is_writeable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php')) {
950 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
951 }
952 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
953 !@is_writeable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php')) {
954 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
955 }
956 return implode(', ',$error);
957 }
958
959 /**
960 * Returns an array with the two cache-files (0=>localconf, 1=>tables) from typo3conf/ if they (both) exist. Otherwise false.
961 * Evaluation relies on $TYPO3_LOADED_EXT['_CACHEFILE']
962 *
963 * @return array
964 * @internal
965 */
966 function currentCacheFiles() {
967 global $TYPO3_LOADED_EXT;
968
969 if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
970 if (t3lib_extMgm::isCacheFilesAvailable($TYPO3_LOADED_EXT['_CACHEFILE'])) {
971 return array(
972 PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php',
973 PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php'
974 );
975 }
976 }
977 }
978
979 /**
980 * Compiles/Creates the two cache-files in typo3conf/ based on $cacheFilePrefix
981 * Returns a array with the key "_CACHEFILE" set to the $cacheFilePrefix value
982 *
983 * @param array
984 * @param string
985 * @return array
986 * @internal
987 */
988 function writeCacheFiles($extensions,$cacheFilePrefix) {
989 // Making cache files:
990 $extensions['_CACHEFILE'] = $cacheFilePrefix;
991 $cFiles=array();
992 $cFiles['ext_localconf'].='<?php
993
994 $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extensions)).'\'));
995
996 ?>';
997
998 reset($extensions);
999 while(list($key,$conf)=each($extensions)) {
1000 if (is_array($conf)) {
1001 if ($conf['ext_localconf.php']) {
1002 $cFiles['ext_localconf'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_localconf.php']);
1003 $cFiles['ext_localconf'].=trim(t3lib_div::getUrl($conf['ext_localconf.php']));
1004 }
1005 if ($conf['ext_tables.php']) {
1006 $cFiles['ext_tables'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_tables.php']);
1007 $cFiles['ext_tables'].=trim(t3lib_div::getUrl($conf['ext_tables.php']));
1008 }
1009 }
1010 }
1011
1012 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php',$cFiles['ext_localconf']);
1013 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php',$cFiles['ext_tables']);
1014
1015 $extensions=array();
1016 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1017
1018 return $extensions;
1019 }
1020 }
1021
1022 ?>