Fixed bug #14231: csc static template "v4.3" won't include the registered plugins
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_extmgm.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (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 a class with Extension Management functions
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 114: class t3lib_extMgm
41 *
42 * SECTION: PATHS and other evaluation
43 * 131: function isLoaded($key,$exitOnError = 0)
44 * 147: function extPath($key,$script='')
45 * 165: function extRelPath($key)
46 * 182: function siteRelPath($key)
47 * 194: function getCN($key)
48 *
49 * SECTION: Adding BACKEND features
50 * 227: function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
51 * 251: function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')
52 * 309: function allowTableOnStandardPages($table)
53 * 326: function addModule($main,$sub='',$position='',$path='')
54 * 389: function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='')
55 * 408: function addPageTSConfig($content)
56 * 422: function addUserTSConfig($content)
57 * 437: function addLLrefForTCAdescr($tca_descr_key,$file_ref)
58 *
59 * SECTION: Adding SERVICES features
60 * 479: function addService($extKey, $serviceType, $serviceKey, $info)
61 * 547: function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array())
62 * 618: function deactivateService($serviceType, $serviceKey)
63 *
64 * SECTION: Adding FRONTEND features
65 * 657: function addPlugin($itemArray,$type='list_type')
66 * 682: function addPiFlexFormValue($piKeyToMatch,$value)
67 * 702: function addToInsertRecords($table,$content_table='tt_content',$content_field='records')
68 * 733: function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
69 * 808: function addStaticFile($extKey,$path,$title)
70 * 827: function addTypoScriptSetup($content)
71 * 841: function addTypoScriptConstants($content)
72 * 858: function addTypoScript($key,$type,$content,$afterStaticUid=0)
73 *
74 * SECTION: INTERNAL EXTENSION MANAGEMENT:
75 * 921: function typo3_loadExtensions()
76 * 998: function _makeIncludeHeader($key,$file)
77 * 1019: function isCacheFilesAvailable($cacheFilePrefix)
78 * 1032: function isLocalconfWritable()
79 * 1045: function cannotCacheFilesWritable($cacheFilePrefix)
80 * 1069: function currentCacheFiles()
81 * 1092: function writeCacheFiles($extensions,$cacheFilePrefix)
82 * 1130: function removeCacheFiles()
83 *
84 * TOTAL FUNCTIONS: 32
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 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
111 * @package TYPO3
112 * @subpackage t3lib
113 */
114 final class t3lib_extMgm {
115 protected static $extensionKeyMap;
116
117
118 /**************************************
119 *
120 * PATHS and other evaluation
121 *
122 ***************************************/
123
124 /**
125 * Returns true if the extension with extension key $key is loaded.
126 * Usage: 109
127 *
128 * @param string Extension key to test
129 * @param boolean If $exitOnError is true and the extension is not loaded the function will die with an error message
130 * @return boolean
131 */
132 public static function isLoaded($key, $exitOnError = 0) {
133 global $TYPO3_LOADED_EXT;
134 if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key])) {
135 throw new BadFunctionCallException(
136 'TYPO3 Fatal Error: Extension "' . $key . '" was not loaded!',
137 1270853910
138 );
139 }
140 return isset($TYPO3_LOADED_EXT[$key]);
141 }
142
143 /**
144 * Returns the absolute path to the extension with extension key $key
145 * If the extension is not loaded the function will die with an error message
146 * Useful for internal fileoperations
147 * Usage: 136
148 *
149 * @param string Extension key
150 * @param string $script is appended to the output if set.
151 * @return string
152 */
153 public static function extPath($key, $script = '') {
154 global $TYPO3_LOADED_EXT;
155 if (!isset($TYPO3_LOADED_EXT[$key])) {
156 throw new BadFunctionCallException(
157 'TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!',
158 1270853878
159 );
160 }
161 return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
162 }
163
164 /**
165 * Returns the relative path to the extension as measured from from the TYPO3_mainDir
166 * If the extension is not loaded the function will die with an error message
167 * Useful for images and links from backend
168 * Usage: 54
169 *
170 * @param string Extension key
171 * @return string
172 */
173 public static function extRelPath($key) {
174 global $TYPO3_LOADED_EXT;
175 if (!isset($TYPO3_LOADED_EXT[$key])) {
176 throw new BadFunctionCallException(
177 'TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!',
178 1270853879
179 );
180 }
181 return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
182 }
183
184 /**
185 * Returns the relative path to the extension as measured from the PATH_site (frontend)
186 * If the extension is not loaded the function will die with an error message
187 * Useful for images and links from the frontend
188 * Usage: 6
189 *
190 * @param string Extension key
191 * @return string
192 */
193 public static function siteRelPath($key) {
194 return substr(t3lib_extMgm::extPath($key), strlen(PATH_site));
195 }
196
197 /**
198 * Returns the correct class name prefix for the extension key $key
199 * Usage: 3
200 *
201 * @param string Extension key
202 * @return string
203 * @internal
204 */
205 public static function getCN($key) {
206 return substr($key, 0, 5)=='user_' ? 'user_'.str_replace('_', '', substr($key, 5)) : 'tx_'.str_replace('_', '', $key);
207 }
208
209 /**
210 * Returns the real extension key like 'tt_news' from an extension prefix like 'tx_ttnews'.
211 *
212 * @param string $prefix: The extension prefix (e.g. 'tx_ttnews')
213 * @return mixed Real extension key (string) or false (boolean) if something went wrong
214 */
215 public static function getExtensionKeyByPrefix($prefix) {
216 $result = false;
217 // Build map of short keys referencing to real keys:
218 if (!isset(self::$extensionKeyMap)) {
219 self::$extensionKeyMap = array();
220 foreach (array_keys($GLOBALS['TYPO3_LOADED_EXT']) as $extensionKey) {
221 $shortKey = str_replace('_', '', $extensionKey);
222 self::$extensionKeyMap[$shortKey] = $extensionKey;
223 }
224 }
225 // Lookup by the given short key:
226 $parts = explode('_', $prefix);
227 if (isset(self::$extensionKeyMap[$parts[1]])) {
228 $result = self::$extensionKeyMap[$parts[1]];
229 }
230 return $result;
231 }
232
233 /**
234 * Clears the extension key map.
235 *
236 * @return void
237 */
238 public static function clearExtensionKeyMap() {
239 self::$extensionKeyMap = NULL;
240 }
241
242 /**
243 * Retrieves the version of an installed extension.
244 * If the extension is not installed, this function returns an empty string.
245 *
246 * @param string $key the key of the extension to look up, must not be empty
247 * @return string the extension version as a string in the format "x.y.z",
248 * will be an empty string if the extension is not loaded
249 */
250 public static function getExtensionVersion($key) {
251 if (!is_string($key) || empty($key)) {
252 throw new InvalidArgumentException('Extension key must be a non-empty string.');
253 }
254 if (!self::isLoaded($key)) {
255 return '';
256 }
257
258 $_EXTKEY = $key;
259 include(t3lib_extMgm::extPath($key) . 'ext_emconf.php');
260
261 return $EM_CONF[$key]['version'];
262 }
263
264
265
266
267
268
269
270
271 /**************************************
272 *
273 * Adding BACKEND features
274 * (related to core features)
275 *
276 ***************************************/
277
278 /**
279 * Adding fields to an existing table definition in $TCA
280 * Adds an array with $TCA column-configuration to the $TCA-entry for that table.
281 * 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!
282 * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
283 * FOR USE IN ext_tables.php FILES
284 * Usage: 4
285 *
286 * @param string $table is the table name of a table already present in $TCA with a columns section
287 * @param array $columnArray is the array with the additional columns (typical some fields an extension wants to add)
288 * @param boolean If $addTofeInterface is true the list of fields are also added to the fe_admin_fieldList.
289 * @return void
290 */
291 public static function addTCAcolumns($table, $columnArray, $addTofeInterface = 0) {
292 global $TCA;
293 t3lib_div::loadTCA($table);
294 if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
295 $TCA[$table]['columns'] = array_merge($TCA[$table]['columns'], $columnArray); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
296 if ($addTofeInterface) $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',', array_keys($columnArray));
297 }
298 }
299
300 /**
301 * Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
302 *
303 * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
304 * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
305 * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
306 * FOR USE IN ext_tables.php FILES
307 * Usage: 1
308 *
309 * @param string Table name
310 * @param string Field list to add.
311 * @param string List of specific types to add the field list to. (If empty, all type entries are affected)
312 * @param string Insert fields before (default) or after one of this fields (commalist with "before:" or "after:" commands). Example: "before:keywords,--palette--;;4,after:description". Palettes must be passed like in the example no matter how the palette definition looks like in TCA.
313 * @return void
314 */
315 public static function addToAllTCAtypes($table, $str, $specificTypesList = '', $position = '') {
316 t3lib_div::loadTCA($table);
317 $str = trim($str);
318
319 if ($str && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['types'])) {
320 foreach($GLOBALS['TCA'][$table]['types'] as $type => &$typeDetails) {
321 if ($specificTypesList === '' || t3lib_div::inList($specificTypesList, $type)) {
322 $typeDetails['showitem'] = self::executePositionedStringInsertion(
323 $typeDetails['showitem'],
324 $str,
325 $position
326 );
327 }
328 }
329 }
330 }
331
332 /**
333 * Adds new fields to all palettes of an existing field.
334 * If the field does not have a palette yet, it's created automatically and
335 * gets called "generatedFor-$field".
336 *
337 * @param string $table: Name of the table
338 * @param string $field: Name of the field that has the palette to be extended
339 * @param string $addFields: List of fields to be added to the palette
340 * @param string $insertionPosition: Insert fields before (default) or after one
341 * of this fields (commalist with "before:" or "after:" commands).
342 * Example: "before:keywords,--palette--;;4,after:description".
343 * Palettes must be passed like in the example no matter how the
344 * palette definition looks like in TCA.
345 * @return void
346 */
347 public static function addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
348 $generatedPalette = '';
349 $processedPalettes = array();
350 t3lib_div::loadTCA($table);
351
352 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
353 $types =& $GLOBALS['TCA'][$table]['types'];
354 if (is_array($types)) {
355 // Iterate through all types and search for the field that defines the palette to be extended:
356 foreach (array_keys($types) as $type) {
357 $items = self::explodeItemList($types[$type]['showitem']);
358 if (isset($items[$field])) {
359 // If the field already has a palette, extend it:
360 if ($items[$field]['details']['palette']) {
361 $palette = $items[$field]['details']['palette'];
362 if (!isset($processedPalettes[$palette])) {
363 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
364 $processedPalettes[$palette] = true;
365 }
366 // If there's not palette yet, create one:
367 } else {
368 if ($generatedPalette) {
369 $palette = $generatedPalette;
370 } else {
371 $palette = $generatedPalette = 'generatedFor-' . $field;
372 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
373 }
374 $items[$field]['details']['palette'] = $palette;
375 $types[$type]['showitem'] = self::generateItemList($items);
376 }
377 }
378 }
379 }
380 }
381 }
382
383 /**
384 * Adds new fields to a palette.
385 * If the palette does not exist yet, it's created automatically.
386 *
387 * @param string $table: Name of the table
388 * @param string $palette: Name of the palette to be extended
389 * @param string $addFields: List of fields to be added to the palette
390 * @param string $insertionPosition: Insert fields before (default) or after one
391 * of this fields (commalist with "before:" or "after:" commands).
392 * Example: "before:keywords,--palette--;;4,after:description".
393 * Palettes must be passed like in the example no matter how the
394 * palette definition looks like in TCA.
395 * @return void
396 */
397 public static function addFieldsToPalette($table, $palette, $addFields, $insertionPosition = '') {
398 t3lib_div::loadTCA($table);
399
400 if (isset($GLOBALS['TCA'][$table])) {
401 $paletteData =& $GLOBALS['TCA'][$table]['palettes'][$palette];
402 // If palette already exists, merge the data:
403 if (is_array($paletteData)) {
404 $paletteData['showitem'] = self::executePositionedStringInsertion(
405 $paletteData['showitem'],
406 $addFields,
407 $insertionPosition
408 );
409 // If it's a new palette, just set the data:
410 } else {
411 $paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields);
412 }
413 }
414 }
415
416 /**
417 * Adds a list of new fields to the TYPO3 USER SETTINGS configuration "showitem" list, the array with
418 * the new fields itself needs to be added additionally to show up in the user setup, like
419 * $GLOBALS['TYPO3_USER_SETTINGS']['columns'] += $tempColumns
420 *
421 * @param string $addFields: List of fields to be added to the user settings
422 * @param string $insertionPosition: Insert fields before (default) or after one
423 * of this fields (commalist with "before:" or "after:" commands).
424 * Example: "before:password,after:email".
425 * @return void
426 */
427 public function addFieldsToUserSettings($addFields, $insertionPosition = '') {
428 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'] = self::executePositionedStringInsertion(
429 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'],
430 $addFields,
431 $insertionPosition
432 );
433 }
434
435 /**
436 * Inserts as list of data into an existing list.
437 * The insertion position can be defined accordant before of after existing list items.
438 *
439 * @param string $list: The list of items to be extended
440 * @param string $insertionList: The list of items to inserted
441 * @param string $insertionPosition: Insert fields before (default) or after one
442 * of this fields (commalist with "before:" or "after:" commands).
443 * Example: "before:keywords,--palette--;;4,after:description".
444 * Palettes must be passed like in the example no matter how the
445 * palette definition looks like in TCA.
446 * @return string The extended list
447 */
448 protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
449 $list = trim($list);
450 $insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
451
452 if ($insertionList) {
453 // Append data to the end (default):
454 if ($insertionPosition === '') {
455 $list.= ($list ? ', ' : '') . $insertionList;
456 // Insert data before or after insertion points:
457 } else {
458 $positions = t3lib_div::trimExplode(',', $insertionPosition, true);
459 $items = self::explodeItemList($list);
460 $isInserted = false;
461 // Iterate through all fields an check whether it's possible to inserte there:
462 foreach ($items as $item => &$itemDetails) {
463 $needles = self::getInsertionNeedles($item, $itemDetails['details']);
464 // Insert data before:
465 foreach ($needles['before'] as $needle) {
466 if (in_array($needle, $positions)) {
467 $itemDetails['rawData'] = $insertionList . ', ' . $itemDetails['rawData'];
468 $isInserted = true;
469 break;
470 }
471 }
472 // Insert data after:
473 foreach ($needles['after'] as $needle) {
474 if (in_array($needle, $positions)) {
475 $itemDetails['rawData'] .= ', ' . $insertionList;
476 $isInserted = true;
477 break;
478 }
479 }
480 // Break if insertion was already done:
481 if ($isInserted) {
482 break;
483 }
484 }
485 // If insertion point could not be determined, append the data:
486 if (!$isInserted) {
487 $list.= ($list ? ', ' : '') . $insertionList;
488 // If data was correctly inserted before or after existing items, recreate the list:
489 } else {
490 $list = self::generateItemList($items, true);
491 }
492 }
493 }
494
495 return $list;
496 }
497
498 /**
499 * Compares an existing list of items and a list of items to be inserted
500 * and returns a duplicate-free variant of that insertion list.
501 *
502 * Example:
503 * + list: 'field_a, field_b;;;;2-2-2, field_c;;;;3-3-3'
504 * + insertion: 'field_b, field_d, field_c;;;4-4-4'
505 * -> new insertion: 'field_d'
506 *
507 * @param string $insertionList: The list of items to inserted
508 * @param string $list: The list of items to be extended (default: '')
509 * @return string Duplicate-free list of items to be inserted
510 */
511 protected static function removeDuplicatesForInsertion($insertionList, $list = '') {
512 $pattern = '/(^|,)\s*\b([^;,]+)\b[^,]*/';
513 $listItems = array();
514
515 if ($list && preg_match_all($pattern, $list, $listMatches)) {
516 $listItems = $listMatches[2];
517 }
518
519 if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
520 $insertionItems = array();
521 $insertionDuplicates = false;
522
523 foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) {
524 if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) {
525 $insertionItems[$insertionItem] = true;
526 } else {
527 unset($insertionListMatches[0][$insertionIndex]);
528 $insertionDuplicates = true;
529 }
530 }
531
532 if ($insertionDuplicates) {
533 $insertionList = implode('', $insertionListMatches[0]);
534 }
535 }
536
537 return $insertionList;
538 }
539
540 /**
541 * Generates search needles that are used for inserting fields/items into an existing list.
542 *
543 * @see executePositionedStringInsertion
544 * @param string $item: The name of the field/item
545 * @param array $itemDetails: Additional details of the field/item like e.g. palette information
546 * (this array gets created by the function explodeItemList())
547 * @return array The needled to be used for inserting content before or after existing fields/items
548 */
549 protected static function getInsertionNeedles($item, array $itemDetails) {
550 if (strstr($item, '--')) {
551 // If $item is a separator (--div--) or palette (--palette--) then it may have been appended by a unique number. This must be stripped away here.
552 $item = preg_replace('/[0-9]+$/', '', $item);
553 }
554
555 $needles = array(
556 'before' => array($item, 'before:' . $item),
557 'after' => array('after:' . $item),
558 );
559
560 if ($itemDetails['palette']) {
561 $palette = $item . ';;' . $itemDetails['palette'];
562 $needles['before'][] = $palette;
563 $needles['before'][] = 'before:' . $palette;
564 $needles['after'][] = 'after:' . $palette;
565 }
566
567 return $needles;
568 }
569
570 /**
571 * Generates an array of fields/items with additional information such as e.g. the name of the palette.
572 *
573 * @param string $itemList: List of fields/items to be splitted up
574 * (this mostly reflects the data in $TCA[<table>]['types'][<type>]['showitem'])
575 * @return array An array with the names of the fields/items as keys and additional information
576 */
577 protected static function explodeItemList($itemList) {
578 $items = array();
579 $itemParts = t3lib_div::trimExplode(',', $itemList, true);
580
581 foreach ($itemParts as $itemPart) {
582 $itemDetails = t3lib_div::trimExplode(';', $itemPart, false, 5);
583 $key = $itemDetails[0];
584 if (strstr($key, '--')) {
585 // If $key is a separator (--div--) or palette (--palette--) then it will be appended by a unique number. This must be removed again when using this value!
586 $key.= count($items);
587 }
588
589 if (!isset($items[$key])) {
590 $items[$key] = array(
591 'rawData' => $itemPart,
592 'details' => array(
593 'field' => $itemDetails[0],
594 'label' => $itemDetails[1],
595 'palette' => $itemDetails[2],
596 'special' => $itemDetails[3],
597 'styles' => $itemDetails[4],
598 ),
599 );
600 }
601 }
602
603 return $items;
604 }
605
606 /**
607 * Generates a list of fields/items out of an array provided by the function getFieldsOfFieldList().
608 *
609 * @see explodeItemList
610 * @param array $items: The array of fields/items with optional additional information
611 * @param boolean $useRawData: Use raw data instead of building by using the details (default: false)
612 * @return string The list of fields/items which gets used for $TCA[<table>]['types'][<type>]['showitem']
613 * or $TCA[<table>]['palettes'][<palette>]['showitem'] in most cases
614 */
615 protected static function generateItemList(array $items, $useRawData = false) {
616 $itemParts = array();
617
618 foreach ($items as $item => $itemDetails) {
619 if (strstr($item, '--')) {
620 // If $item is a separator (--div--) or palette (--palette--) then it may have been appended by a unique number. This must be stripped away here.
621 $item = preg_replace('/[0-9]+$/', '', $item);
622 }
623
624 if ($useRawData) {
625 $itemParts[] = $itemDetails['rawData'];
626 } else {
627 $itemParts[] = (count($itemDetails['details']) > 1 ? implode(';', $itemDetails['details']) : $item);
628 }
629 }
630
631 return implode(', ', $itemParts);
632 }
633
634 /**
635 * Add tablename to default list of allowed tables on pages (in $PAGES_TYPES)
636 * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
637 * FOR USE IN ext_tables.php FILES
638 * Usage: 11
639 *
640 * @param string Table name
641 * @return void
642 */
643 public static function allowTableOnStandardPages($table) {
644 global $PAGES_TYPES;
645
646 $PAGES_TYPES['default']['allowedTables'].=','.$table;
647 }
648
649 /**
650 * Adds a module (main or sub) to the backend interface
651 * FOR USE IN ext_tables.php FILES
652 * Usage: 18
653 *
654 * @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.
655 * @param string $sub is the submodule key. If $sub is not set a blank $main module is created.
656 * @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.
657 * @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.
658 * @return void
659 */
660 public static function addModule($main, $sub = '', $position = '', $path = '') {
661 global $TBE_MODULES;
662
663 if (isset($TBE_MODULES[$main]) && $sub) { // If there is already a main module by this name:
664
665 // Adding the submodule to the correct position:
666 list($place, $modRef) = t3lib_div::trimExplode(':', $position, 1);
667 $mods = t3lib_div::trimExplode(',', $TBE_MODULES[$main], 1);
668 if (!in_array($sub, $mods)) {
669 switch(strtolower($place)) {
670 case 'after':
671 case 'before':
672 $pointer = 0;
673 reset($mods);
674 while(list($k, $m) = each($mods)) {
675 if (!strcmp($m, $modRef)) {
676 $pointer = strtolower($place)=='after'?$k+1:$k;
677 }
678 }
679 array_splice(
680 $mods, // The modules array
681 $pointer, // To insert one position from the end of the list
682 0, // Don't remove any items, just insert
683 $sub // Module to insert
684 );
685 break;
686 default:
687 if (strtolower($place)=='top') {
688 array_unshift($mods, $sub);
689 } else {
690 array_push($mods, $sub);
691 }
692 break;
693 }
694 }
695 // Re-inserting the submodule list:
696 $TBE_MODULES[$main] = implode(',', $mods);
697 } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank)
698 $TBE_MODULES[$main] = $sub;
699 }
700
701 // Adding path:
702 if ($path) {
703 $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')] = $path;
704 }
705 }
706
707 /**
708 * Adds a module path to TBE_MODULES for used with the module dispatcher, mod.php
709 * Used only for modules that are not placed in the main/sub menu hierarchy by the traditional mechanism of addModule()
710 * Examples for this is context menu functionality (like import/export) which runs as an independent module through mod.php
711 * FOR USE IN ext_tables.php FILES
712 * Example: t3lib_extMgm::addModulePath('xMOD_tximpexp', t3lib_extMgm::extPath($_EXTKEY).'app/');
713 *
714 * @param string $name is the name of the module, refer to conf.php of the module.
715 * @param string $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
716 * @return void
717 */
718 public static function addModulePath($name, $path) {
719 global $TBE_MODULES;
720
721 $TBE_MODULES['_PATHS'][$name] = $path;
722 }
723
724 /**
725 * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
726 * The arguments values are generally determined by which function menu this is supposed to interact with
727 * See Inside TYPO3 for information on how to use this function.
728 * FOR USE IN ext_tables.php FILES
729 * Usage: 26
730 *
731 * @param string Module name
732 * @param string Class name
733 * @param string Class path
734 * @param string Title of module
735 * @param string Menu array key - default is "function"
736 * @param string Workspace conditions. Blank means all workspaces, any other string can be a comma list of "online", "offline" and "custom"
737 * @return void
738 * @see t3lib_SCbase::mergeExternalItems()
739 */
740 public static function insertModuleFunction($modname, $className, $classPath, $title, $MM_key = 'function', $WS = '') {
741 global $TBE_MODULES_EXT;
742 $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className] = array(
743 'name' => $className,
744 'path' => $classPath,
745 'title' => $title,
746 'ws' => $WS
747 );
748 }
749
750 /**
751 * Adds $content to the default Page TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultPageTSconfig']
752 * Prefixed with a [GLOBAL] line
753 * FOR USE IN ext_tables.php/ext_localconf.php FILES
754 * Usage: 5
755 *
756 * @param string Page TSconfig content
757 * @return void
758 */
759 public static function addPageTSConfig($content) {
760 global $TYPO3_CONF_VARS;
761 $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
762 }
763
764 /**
765 * Adds $content to the default User TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultUserTSconfig']
766 * Prefixed with a [GLOBAL] line
767 * FOR USE IN ext_tables.php/ext_localconf.php FILES
768 * Usage: 3
769 *
770 * @param string User TSconfig content
771 * @return void
772 */
773 public static function addUserTSConfig($content) {
774 global $TYPO3_CONF_VARS;
775 $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
776 }
777
778 /**
779 * Adds a reference to a locallang file with TCA_DESCR labels
780 * FOR USE IN ext_tables.php FILES
781 * eg. t3lib_extMgm::addLLrefForTCAdescr('pages', 'EXT:lang/locallang_csh_pages.xml'); for the pages table or t3lib_extMgm::addLLrefForTCAdescr('_MOD_web_layout', 'EXT:cms/locallang_csh_weblayout.php'); for the Web > Page module.
782 * Usage: 31
783 *
784 * @param string Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
785 * @param string File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
786 * @return void
787 */
788 public static function addLLrefForTCAdescr($tca_descr_key, $file_ref) {
789 global $TCA_DESCR;
790 if ($tca_descr_key) {
791 if (!is_array($TCA_DESCR[$tca_descr_key])) {
792 $TCA_DESCR[$tca_descr_key] = array();
793 }
794 if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
795 $TCA_DESCR[$tca_descr_key]['refs'] = array();
796 }
797 $TCA_DESCR[$tca_descr_key]['refs'][] = $file_ref;
798 }
799 }
800
801
802
803
804
805
806
807
808
809
810
811
812 /**************************************
813 *
814 * Adding SERVICES features
815 *
816 * @author Rene Fritz <r.fritz@colorcube.de>
817 *
818 ***************************************/
819
820 /**
821 * Adds a service to the global services array
822 *
823 * @param string Extension key
824 * @param string Service type, cannot be prefixed "tx_"
825 * @param string Service key, must be prefixed "tx_" or "user_"
826 * @param array Service description array
827 * @return void
828 * @author Rene Fritz <r.fritz@colorcube.de>
829 */
830 public static function addService($extKey, $serviceType, $serviceKey, $info) {
831 global $T3_SERVICES, $TYPO3_CONF_VARS;
832
833 // even not available services will be included to make it possible to give the admin a feedback of non-available services.
834 // but maybe it's better to move non-available services to a different array??
835
836 if ($serviceType &&
837 !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') &&
838 (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') || t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) &&
839 is_array($info)) {
840
841 $info['priority'] = max(0, min(100, $info['priority']));
842
843 $T3_SERVICES[$serviceType][$serviceKey] = $info;
844
845 $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
846 $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
847 $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
848
849
850 // mapping a service key to a service type
851 // all service keys begin with tx_ - service types don't
852 // this way a selection of a special service key as service type is easy
853 $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
854
855
856 // change the priority (and other values) from TYPO3_CONF_VARS
857 // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
858 // even the activation is possible (a unix service might be possible on windows for some reasons)
859 if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
860
861 // no check is done here - there might be configuration values only the service type knows about, so we pass everything
862 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey], $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
863 }
864
865
866 // OS check
867 // empty $os means 'not limited to one OS', therefore a check is not needed
868 if ($T3_SERVICES[$serviceType][$serviceKey]['available'] && $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
869
870 // TYPO3_OS is not yet defined
871 $os_type = stristr(PHP_OS, 'win')&&!stristr(PHP_OS, 'darwin')?'WIN':'UNIX';
872
873 $os = t3lib_div::trimExplode(',', strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
874
875 if (!in_array($os_type, $os)) {
876 t3lib_extMgm::deactivateService($serviceType, $serviceKey);
877 }
878 }
879
880 // convert subtype list to array for quicker access
881 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
882 $serviceSubTypes = t3lib_div::trimExplode(',', $info['subtype']);
883 foreach ($serviceSubTypes as $subtype) {
884 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
885 }
886 }
887 }
888
889 /**
890 * Find the available service with highest priority
891 *
892 * @param string Service type
893 * @param string Service sub type
894 * @param mixed Service keys that should be excluded in the search for a service. Array or comma list.
895 * @return mixed Service info array if a service was found, FLASE otherwise
896 * @author Rene Fritz <r.fritz@colorcube.de>
897 */
898 public static function findService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) {
899 global $T3_SERVICES, $TYPO3_CONF_VARS;
900
901 $serviceKey = FALSE;
902 $serviceInfo = FALSE;
903 $priority = 0;
904 $quality = 0;
905
906 if (!is_array($excludeServiceKeys) ) {
907 $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
908 }
909
910 if (is_array($T3_SERVICES[$serviceType])) {
911 foreach($T3_SERVICES[$serviceType] as $key => $info) {
912
913 if (in_array($key, $excludeServiceKeys)) {
914 continue;
915 }
916
917 // select a subtype randomly
918 // usefull to start a service by service key without knowing his subtypes - for testing purposes
919 if ($serviceSubType=='*') {
920 $serviceSubType = key($info['serviceSubTypes']);
921 }
922
923 // this matches empty subtype too
924 if ($info['available'] && ($info['subtype']==$serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority']>=$priority ) {
925
926 // has a lower quality than the already found, therefore we skip this service
927 if($info['priority']==$priority && $info['quality']<$quality) {
928 continue;
929 }
930
931 // service depends on external programs - check if they exists
932 if(trim($info['exec'])) {
933 $executables = t3lib_div::trimExplode(',', $info['exec'], 1);
934 foreach($executables as $executable) {
935 if(!t3lib_exec::checkCommand($executable)) {
936 t3lib_extMgm::deactivateService($serviceType, $key);
937 $info['available'] = FALSE;
938 break;
939 }
940 }
941 }
942
943 // still available after exec check?
944 if($info['available']) {
945 $serviceKey = $key;
946 $priority = $info['priority'];
947 $quality = $info['quality'];
948 }
949 }
950 }
951 }
952
953 if ($serviceKey) {
954 $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
955 }
956 return $serviceInfo;
957 }
958
959 /**
960 * Deactivate a service
961 *
962 * @param string Service type
963 * @param string Service key
964 * @return void
965 * @author Rene Fritz <r.fritz@colorcube.de>
966 */
967 public static function deactivateService($serviceType, $serviceKey) {
968 global $T3_SERVICES;
969
970 // ... maybe it's better to move non-available services to a different array??
971 $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
972 }
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987 /**************************************
988 *
989 * Adding FRONTEND features
990 * (related specifically to "cms" extension)
991 *
992 ***************************************/
993
994 /**
995 * Adds an entry to the list of plugins in content elements of type "Insert plugin"
996 * 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)
997 * 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.
998 * 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
999 * FOR USE IN ext_tables.php FILES
1000 * Usage: 13
1001 *
1002 * @param array Item Array
1003 * @param string Type (eg. "list_type") - basically a field from "tt_content" table
1004 * @return void
1005 */
1006 public static function addPlugin($itemArray, $type = 'list_type') {
1007 global $TCA;
1008
1009 $_EXTKEY = $GLOBALS['_EXTKEY'];
1010 if ($_EXTKEY && !$itemArray[2]) {
1011 $itemArray[2] = t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif';
1012 }
1013
1014 t3lib_div::loadTCA('tt_content');
1015 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
1016 reset($TCA['tt_content']['columns'][$type]['config']['items']);
1017 while(list($k, $v) = each($TCA['tt_content']['columns'][$type]['config']['items'])) {
1018 if (!strcmp($v[1], $itemArray[1])) {
1019 $TCA['tt_content']['columns'][$type]['config']['items'][$k] = $itemArray;
1020 return;
1021 }
1022 }
1023 $TCA['tt_content']['columns'][$type]['config']['items'][] = $itemArray;
1024 }
1025 }
1026
1027 /**
1028 * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
1029 * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin or content element.
1030 * Usage: 0
1031 *
1032 * @param string Plugin key as used in the list_type field. Use the asterisk * to match all list_type values.
1033 * @param string Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
1034 * @param string Value of tt_content.CType (Content Type) to match. The default is "list" which corresponds to the "Insert Plugin" content element. Use the asterisk * to match all CType values.
1035 * @return void
1036 * @see addPlugin()
1037 */
1038 public static function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch = 'list') {
1039 global $TCA;
1040 t3lib_div::loadTCA('tt_content');
1041
1042 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
1043 $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch.','.$CTypeToMatch] = $value;
1044 }
1045 }
1046
1047 /**
1048 * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
1049 * By using $content_table and $content_field you can also use the function for other tables.
1050 * FOR USE IN ext_tables.php FILES
1051 * Usage: 9
1052 *
1053 * @param string Table name to allow for "insert record"
1054 * @param string Table name TO WHICH the $table name is applied. See $content_field as well.
1055 * @param string Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
1056 * @return void
1057 */
1058 public static function addToInsertRecords($table, $content_table = 'tt_content', $content_field = 'records') {
1059 global $TCA;
1060 t3lib_div::loadTCA($content_table);
1061 if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
1062 $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
1063 }
1064 }
1065
1066 /**
1067 * Add PlugIn to Static Template #43
1068 *
1069 * 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.
1070 * 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. It will also work for the extension "css_styled_content"
1071 * $type determines the type of frontend plugin:
1072 * "list_type" (default) - the good old "Insert plugin" entry
1073 * "menu_type" - a "Menu/Sitemap" entry
1074 * "splash_layout" - a "Textbox" entry
1075 * "CType" - a new content element type
1076 * "header_layout" - an additional header type (added to the selection of layout1-5)
1077 * "includeLib" - just includes the library for manual use somewhere in TypoScript.
1078 * (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)
1079 * FOR USE IN ext_localconf.php FILES
1080 * Usage: 2
1081 *
1082 * @param string $key is the extension key
1083 * @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.
1084 * @param string $prefix is used as a - yes, suffix - of the class name (fx. "_pi1")
1085 * @param string $type, see description above
1086 * @param boolean If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
1087 * @return void
1088 */
1089 public static function addPItoST43($key, $classFile = '', $prefix = '', $type = 'list_type', $cached = 0) {
1090 global $TYPO3_LOADED_EXT;
1091 $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_', '', $key).$prefix.'.php';
1092 $cN = t3lib_extMgm::getCN($key);
1093
1094 // General plugin:
1095 $pluginContent = trim('
1096 plugin.'.$cN.$prefix.' = USER' . ($cached ? '' : '_INT') . '
1097 plugin.'.$cN.$prefix.' {
1098 includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
1099 userFunc = '.$cN.$prefix.'->main
1100 }');
1101 t3lib_extMgm::addTypoScript($key, 'setup', '
1102 # Setting '.$key.' plugin TypoScript
1103 '.$pluginContent);
1104
1105 // After ST43:
1106 switch($type) {
1107 case 'list_type':
1108 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
1109 break;
1110 case 'menu_type':
1111 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
1112 break;
1113 case 'splash_layout':
1114 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
1115 break;
1116 case 'CType':
1117 $addLine = trim('
1118 tt_content.'.$key.$prefix.' = COA
1119 tt_content.'.$key.$prefix.' {
1120 10 = < lib.stdheader
1121 20 = < plugin.'.$cN.$prefix.'
1122 }
1123 ');
1124 break;
1125 case 'header_layout':
1126 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
1127 break;
1128 case 'includeLib':
1129 $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
1130 break;
1131 default:
1132 $addLine = '';
1133 break;
1134 }
1135 if ($addLine) {
1136 t3lib_extMgm::addTypoScript($key, 'setup', '
1137 # Setting '.$key.' plugin TypoScript
1138 '.$addLine.'
1139 ', 43);
1140 }
1141 }
1142
1143 /**
1144 * Call this method to add an entry in the static template list found in sys_templates
1145 * "static template files" are the modern equalent (provided from extensions) to the traditional records in "static_templates"
1146 * FOR USE IN ext_localconf.php FILES
1147 * Usage: 3
1148 *
1149 * @param string $extKey is of course the extension key
1150 * @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, editorcfg.txt, and include_static_file.txt is found (relative to extPath, eg. 'static/'). The file include_static_file.txt, allows you to include other static templates defined in files, from your static template, and thus corresponds to the field 'include_static_file' in the sys_template table. The syntax for this is a commaseperated list of static templates to include, like: EXT:css_styled_content/static/,EXT:da_newsletter_subscription/static/,EXT:cc_random_image/pi2/static/
1151 * @param string $title is the title in the selector box.
1152 * @return void
1153 * @see addTypoScript()
1154 */
1155 public static function addStaticFile($extKey, $path, $title) {
1156 global $TCA;
1157 t3lib_div::loadTCA('sys_template');
1158 if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
1159 $value = str_replace(',', '', 'EXT:'.$extKey.'/'.$path);
1160 $itemArray = array(trim($title.' ('.$extKey.')'), $value);
1161 $TCA['sys_template']['columns']['include_static_file']['config']['items'][] = $itemArray;
1162 }
1163 }
1164
1165 /**
1166 * Adds $content to the default TypoScript setup code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_setup']
1167 * Prefixed with a [GLOBAL] line
1168 * FOR USE IN ext_localconf.php FILES
1169 * Usage: 6
1170 *
1171 * @param string TypoScript Setup string
1172 * @return void
1173 */
1174 public static function addTypoScriptSetup($content) {
1175 global $TYPO3_CONF_VARS;
1176 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
1177 }
1178
1179 /**
1180 * Adds $content to the default TypoScript constants code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_constants']
1181 * Prefixed with a [GLOBAL] line
1182 * FOR USE IN ext_localconf.php FILES
1183 * Usage: 0
1184 *
1185 * @param string TypoScript Constants string
1186 * @return void
1187 */
1188 public static function addTypoScriptConstants($content) {
1189 global $TYPO3_CONF_VARS;
1190 $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
1191 }
1192
1193 /**
1194 * Adds $content to the default TypoScript code for either setup, constants or editorcfg as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_*']
1195 * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
1196 * FOR USE IN ext_localconf.php FILES
1197 * Usage: 7
1198 *
1199 * @param string $key is the extension key (informative only).
1200 * @param string $type is either "setup", "constants" or "editorcfg" and obviously determines which kind of TypoScript code we are adding.
1201 * @param string $content is the TS content, prefixed with a [GLOBAL] line and a comment-header.
1202 * @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.
1203 * @return void
1204 */
1205 public static function addTypoScript($key, $type, $content, $afterStaticUid = 0) {
1206 global $TYPO3_CONF_VARS;
1207
1208 if ($type=='setup' || $type=='editorcfg' || $type=='constants') {
1209 $content = '
1210
1211 [GLOBAL]
1212 #############################################
1213 ## TypoScript added by extension "'.$key.'"
1214 #############################################
1215
1216 '.$content;
1217 if ($afterStaticUid) {
1218 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
1219 // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
1220 if ($afterStaticUid==43 && is_array($TYPO3_CONF_VARS['FE']['contentRenderingTemplates'])) {
1221 foreach ($TYPO3_CONF_VARS['FE']['contentRenderingTemplates'] as $templateName) {
1222 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$templateName] .= $content;
1223 }
1224 }
1225 } else {
1226 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
1227 }
1228 }
1229 }
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248 /**************************************
1249 *
1250 * INTERNAL EXTENSION MANAGEMENT:
1251 *
1252 ***************************************/
1253
1254 /**
1255 * Loading extensions configured in $TYPO3_CONF_VARS['EXT']['extList']
1256 *
1257 * CACHING ON: ($TYPO3_CONF_VARS['EXT']['extCache'] = 1 or 2)
1258 * 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.
1259 * If cachefiles are not found they will be generated
1260 * CACHING OFF: ($TYPO3_CONF_VARS['EXT']['extCache'] = 0)
1261 * 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.
1262 * This array will later be set in the global var $TYPO3_LOADED_EXT
1263 *
1264 * Usages of this function can be seen in config_default.php
1265 * Extensions are always detected in the order local - global - system.
1266 * Usage: 1
1267 *
1268 * @return array Extension Array
1269 * @internal
1270 */
1271 public static function typo3_loadExtensions() {
1272 global $TYPO3_CONF_VARS;
1273
1274 // Select mode how to load extensions in order to speed up the FE
1275 if (TYPO3_MODE == 'FE') {
1276 if (!($extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList_FE'])) {
1277 // fall back to standard 'extList' if 'extList_FE' is not (yet) set
1278 $extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList'];
1279 }
1280 $cacheFileSuffix = '_FE';
1281 } else {
1282 $extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList'];
1283 // Works as before
1284 $cacheFileSuffix = '';
1285 }
1286 // Full list of extensions includes both required and extList:
1287 $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'] . ',' . $extLoadInContext;
1288
1289 // Empty array as a start.
1290 $extensions = array();
1291
1292 //
1293 if ($rawExtList) {
1294 // The cached File prefix.
1295 $cacheFilePrefix = 'temp_CACHED' . $cacheFileSuffix;
1296 // Setting the name for the cache files:
1297 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1) $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']), 0, 4);
1298 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
1299
1300 // If cache files available, set cache file prefix and return:
1301 if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) {
1302 // Return cache file prefix:
1303 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1304 } else { // ... but if not, configure...
1305
1306 // Prepare reserved filenames:
1307 $files = array('ext_localconf.php','ext_tables.php','ext_tables.sql','ext_tables_static+adt.sql','ext_typoscript_constants.txt','ext_typoscript_editorcfg.txt','ext_typoscript_setup.txt');
1308 // Traverse extensions and check their existence:
1309 clearstatcache(); // Clear file state cache to make sure we get good results from is_dir()
1310 $temp_extensions = array_unique(t3lib_div::trimExplode(',', $rawExtList, 1));
1311 foreach($temp_extensions as $temp_extKey) {
1312 // Check local, global and system locations:
1313 if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/')) {
1314 $extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
1315 } elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/')) {
1316 $extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/');
1317 } elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/')) {
1318 $extensions[$temp_extKey] = array('type'=>'S', 'siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/', 'typo3RelPath'=>'sysext/'.$temp_extKey.'/');
1319 }
1320
1321 // If extension was found, check for reserved filenames:
1322 if (isset($extensions[$temp_extKey])) {
1323 foreach($files as $fName) {
1324 $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
1325 if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
1326 $extensions[$temp_extKey][$fName] = $temp_filename;
1327 }
1328 }
1329 }
1330 }
1331 unset($extensions['_CACHEFILE']);
1332
1333 // write cache?
1334 if ($TYPO3_CONF_VARS['EXT']['extCache'] &&
1335 @is_dir(PATH_typo3.'sysext/') &&
1336 @is_dir(PATH_typo3.'ext/')) { // Must also find global and system extension directories to exist, otherwise caching cannot be allowed (since it is most likely a temporary server problem). This might fix a rare, unrepeatable bug where global/system extensions are not loaded resulting in fatal errors if that is cached!
1337 $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
1338 if ($wrError) {
1339 $TYPO3_CONF_VARS['EXT']['extCache'] = 0;
1340 } else {
1341 // Write cache files:
1342 $extensions = t3lib_extMgm::writeCacheFiles($extensions, $cacheFilePrefix);
1343 }
1344 }
1345 }
1346 }
1347
1348 return $extensions;
1349 }
1350
1351 /**
1352 * Returns the section headers for the compiled cache-files.
1353 *
1354 * @param string $key is the extension key
1355 * @param string $file is the filename (only informative for comment)
1356 * @return string
1357 * @internal
1358 */
1359 public static function _makeIncludeHeader($key, $file) {
1360 return '<?php
1361 ###########################
1362 ## EXTENSION: '.$key.'
1363 ## FILE: '.$file.'
1364 ###########################
1365
1366 $_EXTKEY = \''.$key.'\';
1367 $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
1368
1369 ?>';
1370 }
1371
1372 /**
1373 * Returns true if both the localconf and tables cache file exists (with $cacheFilePrefix)
1374 * Usage: 2
1375 *
1376 * @param string Prefix of the cache file to check
1377 * @return boolean
1378 * @internal
1379 */
1380 public static function isCacheFilesAvailable($cacheFilePrefix) {
1381 return
1382 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
1383 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php');
1384 }
1385
1386 /**
1387 * Returns true if the "localconf.php" file in "typo3conf/" is writable
1388 * Usage: 1
1389 *
1390 * @return boolean
1391 * @internal
1392 */
1393 public static function isLocalconfWritable() {
1394 return @is_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf.'localconf.php');
1395 }
1396
1397 /**
1398 * Returns an error string if typo3conf/ or cache-files with $cacheFilePrefix are NOT writable
1399 * Returns false if no problem.
1400 * Usage: 1
1401 *
1402 * @param string Prefix of the cache file to check
1403 * @return string
1404 * @internal
1405 */
1406 public static function cannotCacheFilesWritable($cacheFilePrefix) {
1407 $error = array();
1408 if (!@is_writable(PATH_typo3conf)) {
1409 $error[] = PATH_typo3conf;
1410 }
1411 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
1412 !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php')) {
1413 $error[] = PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
1414 }
1415 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
1416 !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php')) {
1417 $error[] = PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
1418 }
1419 return implode(', ', $error);
1420 }
1421
1422 /**
1423 * Returns an array with the two cache-files (0=>localconf, 1=>tables) from typo3conf/ if they (both) exist. Otherwise false.
1424 * Evaluation relies on $TYPO3_LOADED_EXT['_CACHEFILE']
1425 * Usage: 2
1426 *
1427 * @return array
1428 * @internal
1429 */
1430 public static function currentCacheFiles() {
1431 if (($cacheFilePrefix = $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'])) {
1432 $cacheFilePrefixFE = str_replace('temp_CACHED','temp_CACHED_FE',$cacheFilePrefix);
1433 $files = array();
1434 if (t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) {
1435 $files[] = PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
1436 $files[] = PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
1437 }
1438 if (t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefixFE)) {
1439 $files[] = PATH_typo3conf.$cacheFilePrefixFE.'_ext_localconf.php';
1440 $files[] = PATH_typo3conf.$cacheFilePrefixFE.'_ext_tables.php';
1441 }
1442 if (!empty($files)) {
1443 return $files;
1444 }
1445 }
1446 }
1447
1448 /**
1449 * Compiles/Creates the two cache-files in typo3conf/ based on $cacheFilePrefix
1450 * Returns a array with the key "_CACHEFILE" set to the $cacheFilePrefix value
1451 * Usage: 1
1452 *
1453 * @param array Extension information array
1454 * @param string Prefix for the cache files
1455 * @return array
1456 * @internal
1457 */
1458 public static function writeCacheFiles($extensions, $cacheFilePrefix) {
1459 // Making cache files:
1460 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1461 $cFiles = array();
1462 $cFiles['ext_localconf'].='<?php
1463
1464 $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extensions)).'\'));
1465
1466 ?>';
1467
1468 reset($extensions);
1469 while(list($key, $conf) = each($extensions)) {
1470 if (is_array($conf)) {
1471 if ($conf['ext_localconf.php']) {
1472 $cFiles['ext_localconf'].=t3lib_extMgm::_makeIncludeHeader($key, $conf['ext_localconf.php']);
1473 $cFiles['ext_localconf'].=trim(t3lib_div::getUrl($conf['ext_localconf.php']));
1474 }
1475 if ($conf['ext_tables.php']) {
1476 $cFiles['ext_tables'].=t3lib_extMgm::_makeIncludeHeader($key, $conf['ext_tables.php']);
1477 $cFiles['ext_tables'].=trim(t3lib_div::getUrl($conf['ext_tables.php']));
1478 }
1479 }
1480 }
1481
1482 $cFiles['ext_localconf'] = "<?php\n" . preg_replace('/<\?php|\?>/is', '', $cFiles['ext_localconf']) . "?>\n";
1483 $cFiles['ext_tables'] = "<?php\n" . preg_replace('/<\?php|\?>/is', '', $cFiles['ext_tables']) . "?>\n";
1484
1485 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php', $cFiles['ext_localconf']);
1486 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php', $cFiles['ext_tables']);
1487
1488 $extensions = array();
1489 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1490
1491 return $extensions;
1492 }
1493
1494 /**
1495 * Unlink (delete) cache files
1496 *
1497 * @return integer Number of deleted files.
1498 */
1499 public static function removeCacheFiles() {
1500 $cacheFiles = t3lib_extMgm::currentCacheFiles();
1501 $out = 0;
1502 if (is_array($cacheFiles)) {
1503 reset($cacheFiles);
1504 foreach($cacheFiles as $cfile) {
1505 @unlink($cfile);
1506 clearstatcache();
1507 $out++;
1508 }
1509 }
1510 return $out;
1511 }
1512 }
1513
1514 ?>