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