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