2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Extension Management functions
31 * This class is never instantiated, rather the methods inside is called as functions like
32 * t3lib_extMgm::isLoaded('my_extension');
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 protected static $extensionKeyMap;
43 * TRUE, if ext_tables file was read from cache for this script run.
44 * The frontend tends to do that multiple times, but the caching framework does
45 * not allow this (via a require_once call). This variable is used to track
46 * the access to the cache file to read the single ext_tables.php if it was
47 * already read from cache
49 * @TODO: See if we can get rid of the 'load multiple times' scenario in fe
52 protected static $extTablesWasReadFromCacheOnce = FALSE;
54 /**************************************
56 * PATHS and other evaluation
58 ***************************************/
61 * Returns TRUE if the extension with extension key $key is loaded.
63 * @param string $key Extension key to test
64 * @param boolean $exitOnError If $exitOnError is TRUE and the extension is not loaded the function will die with an error message
66 * @throws BadFunctionCallException
68 public static function isLoaded($key, $exitOnError = FALSE) {
69 $isLoaded = in_array($key, static::getLoadedExtensionListArray());
70 if ($exitOnError && !$isLoaded) {
71 throw new BadFunctionCallException(
72 'TYPO3 Fatal Error: Extension "' . $key . '" is not loaded!',
80 * Returns the absolute path to the extension with extension key $key
81 * If the extension is not loaded the function will die with an error message
82 * Useful for internal fileoperations
84 * @param $key string Extension key
85 * @param $script string $script is appended to the output if set.
86 * @throws BadFunctionCallException
89 public static function extPath($key, $script = '') {
90 if (isset($GLOBALS['TYPO3_LOADED_EXT'])) {
91 if (!isset($GLOBALS['TYPO3_LOADED_EXT'][$key])) {
92 throw new BadFunctionCallException(
93 'TYPO3 Fatal Error: Extension key "' . $key . '" is NOT loaded!',
98 $extensionPath = PATH_site
. $GLOBALS['TYPO3_LOADED_EXT'][$key]['siteRelPath'];
100 $loadedExtensions = array_flip(static::getLoadedExtensionListArray());
102 if (!isset($loadedExtensions[$key])) {
103 throw new BadFunctionCallException(
104 'TYPO3 Fatal Error: Extension key "' . $key . '" is NOT loaded!',
109 if (@is_dir
(PATH_typo3conf
. 'ext/' . $key . '/')) {
110 $extensionPath = PATH_typo3conf
. 'ext/' . $key . '/';
111 } elseif (@is_dir
(PATH_typo3
. 'ext/' . $key . '/')) {
112 $extensionPath = PATH_typo3
. 'ext/' . $key . '/';
113 } elseif (@is_dir
(PATH_typo3
. 'sysext/' . $key . '/')) {
114 $extensionPath = PATH_typo3
. 'sysext/' . $key . '/';
116 throw new BadFunctionCallException(
117 'TYPO3 Fatal Error: Extension "' . $key . '" NOT found!',
123 return $extensionPath . $script;
127 * Returns the relative path to the extension as measured from from the TYPO3_mainDir
128 * If the extension is not loaded the function will die with an error message
129 * Useful for images and links from backend
131 * @param string $key Extension key
134 public static function extRelPath($key) {
135 if (!isset($GLOBALS['TYPO3_LOADED_EXT'][$key])) {
136 throw new BadFunctionCallException(
137 'TYPO3 Fatal Error: Extension key "' . $key . '" is NOT loaded!',
141 return $GLOBALS['TYPO3_LOADED_EXT'][$key]['typo3RelPath'];
145 * Returns the relative path to the extension as measured from the PATH_site (frontend)
146 * If the extension is not loaded the function will die with an error message
147 * Useful for images and links from the frontend
149 * @param string $key Extension key
152 public static function siteRelPath($key) {
153 return substr(self
::extPath($key), strlen(PATH_site
));
157 * Returns the correct class name prefix for the extension key $key
159 * @param string $key Extension key
163 public static function getCN($key) {
164 return substr($key, 0, 5) == 'user_' ?
'user_' . str_replace('_', '', substr($key, 5)) : 'tx_' . str_replace('_', '', $key);
168 * Returns the real extension key like 'tt_news' from an extension prefix like 'tx_ttnews'.
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
173 public static function getExtensionKeyByPrefix($prefix) {
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;
183 // Lookup by the given short key:
184 $parts = explode('_', $prefix);
185 if (isset(self
::$extensionKeyMap[$parts[1]])) {
186 $result = self
::$extensionKeyMap[$parts[1]];
192 * Clears the extension key map.
196 public static function clearExtensionKeyMap() {
197 self
::$extensionKeyMap = NULL;
201 * Retrieves the version of an installed extension.
202 * If the extension is not installed, this function returns an empty string.
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
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);
212 if (!static::isLoaded($key)) {
215 $runtimeCache = $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
216 $cacheIdentifier = 'extMgmExtVersion-' . $key;
218 if (!($extensionVersion = $runtimeCache->get($cacheIdentifier))) {
222 include(self
::extPath($key) . 'ext_emconf.php');
223 $extensionVersion = $EM_CONF[$key]['version'];
224 $runtimeCache->set($cacheIdentifier, $extensionVersion);
226 return $extensionVersion;
229 /**************************************
231 * Adding BACKEND features
232 * (related to core features)
234 ***************************************/
237 * Adding fields to an existing table definition in $GLOBALS['TCA']
238 * Adds an array with $GLOBALS['TCA'] column-configuration to the $GLOBALS['TCA']-entry for that table.
239 * 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!
240 * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
241 * FOR USE IN ext_tables.php FILES
243 * @param string $table The table name of a table already present in $GLOBALS['TCA'] with a columns section
244 * @param array $columnArray The array with the additional columns (typical some fields an extension wants to add)
245 * @param boolean $addTofeInterface If $addTofeInterface is TRUE the list of fields are also added to the fe_admin_fieldList.
248 public static function addTCAcolumns($table, $columnArray, $addTofeInterface = 0) {
249 t3lib_div
::loadTCA($table);
250 if (is_array($columnArray) && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'])) {
251 // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
252 $GLOBALS['TCA'][$table]['columns'] = array_merge($GLOBALS['TCA'][$table]['columns'], $columnArray);
253 if ($addTofeInterface) {
254 $GLOBALS['TCA'][$table]['feInterface']['fe_admin_fieldList'] .= ',' . implode(',', array_keys($columnArray));
260 * Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
262 * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
263 * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
264 * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
265 * FOR USE IN ext_tables.php FILES
267 * @param string $table Table name
268 * @param string $str Field list to add.
269 * @param string $specificTypesList List of specific types to add the field list to. (If empty, all type entries are affected)
270 * @param string $position Insert fields before (default) or after one
271 * of this fields (commalist with "before:", "after:" or "replace:" commands).
272 * Example: "before:keywords,--palette--;;4,after:description".
273 * Palettes must be passed like in the example no matter how the palette definition looks like in TCA.
274 * It will add the list of new fields before or after a palette or replace the field inside the palette,
275 * when the field given in $position is found inside a palette used by the type.
278 public static function addToAllTCAtypes($table, $str, $specificTypesList = '', $position = '') {
279 t3lib_div
::loadTCA($table);
281 $palettesChanged = array();
282 if ($str && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['types'])) {
283 foreach ($GLOBALS['TCA'][$table]['types'] as $type => &$typeDetails) {
284 if ($specificTypesList === '' || t3lib_div
::inList($specificTypesList, $type)) {
285 $fieldExists = FALSE;
286 if ($position != '' && is_array($GLOBALS['TCA'][$table]['palettes'])) {
287 $positionArray = t3lib_div
::trimExplode(':', $position);
288 if ($positionArray[0] == 'replace') {
289 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
290 if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
291 && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) {
292 self
::addFieldsToPalette($table, $palette, $str, $position);
293 // Save that palette in case other types use it
294 $palettesChanged[] = $palette;
296 } elseif (in_array($palette, $palettesChanged)) {
301 if (strpos($typeDetails['showitem'], $str) !== FALSE) {
304 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
305 if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
306 && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) {
307 $position = $positionArray[0] . ':--palette--;;' . $palette;
313 if (strpos($typeDetails['showitem'], $str) !== FALSE) {
315 } elseif (is_array($GLOBALS['TCA'][$table]['palettes'])) {
316 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
317 if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
318 && strpos($paletteDetails['showitem'], $str) !== FALSE) {
324 if ($fieldExists === FALSE) {
325 $typeDetails['showitem'] = self
::executePositionedStringInsertion(
326 $typeDetails['showitem'],
338 * Adds new fields to all palettes of an existing field.
339 * If the field does not have a palette yet, it's created automatically and
340 * gets called "generatedFor-$field".
342 * @param string $table Name of the table
343 * @param string $field Name of the field that has the palette to be extended
344 * @param string $addFields List of fields to be added to the palette
345 * @param string $insertionPosition Insert fields before (default) or after one
346 * of this fields (commalist with "before:", "after:" or "replace:" commands).
347 * Example: "before:keywords,--palette--;;4,after:description".
348 * Palettes must be passed like in the example no matter how the
349 * palette definition looks like in TCA.
352 public static function addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
353 $generatedPalette = '';
354 $processedPalettes = array();
355 t3lib_div
::loadTCA($table);
357 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
358 $types =& $GLOBALS['TCA'][$table]['types'];
359 if (is_array($types)) {
360 // Iterate through all types and search for the field that defines the palette to be extended:
361 foreach (array_keys($types) as $type) {
362 $items = self
::explodeItemList($types[$type]['showitem']);
363 if (isset($items[$field])) {
364 // If the field already has a palette, extend it:
365 if ($items[$field]['details']['palette']) {
366 $palette = $items[$field]['details']['palette'];
367 if (!isset($processedPalettes[$palette])) {
368 self
::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
369 $processedPalettes[$palette] = TRUE;
371 // If there's not palette yet, create one:
373 if ($generatedPalette) {
374 $palette = $generatedPalette;
376 $palette = $generatedPalette = 'generatedFor-' . $field;
377 self
::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
379 $items[$field]['details']['palette'] = $palette;
380 $types[$type]['showitem'] = self
::generateItemList($items);
389 * Adds new fields to a palette.
390 * If the palette does not exist yet, it's created automatically.
392 * @param string $table Name of the table
393 * @param string $palette Name of the palette to be extended
394 * @param string $addFields List of fields to be added to the palette
395 * @param string $insertionPosition Insert fields before (default) or after one
396 * of this fields (commalist with "before:", "after:" or "replace:" commands).
397 * Example: "before:keywords,--palette--;;4,after:description".
398 * Palettes must be passed like in the example no matter how the
399 * palette definition looks like in TCA.
402 public static function addFieldsToPalette($table, $palette, $addFields, $insertionPosition = '') {
403 t3lib_div
::loadTCA($table);
405 if (isset($GLOBALS['TCA'][$table])) {
406 $paletteData =& $GLOBALS['TCA'][$table]['palettes'][$palette];
407 // If palette already exists, merge the data:
408 if (is_array($paletteData)) {
409 $paletteData['showitem'] = self
::executePositionedStringInsertion(
410 $paletteData['showitem'],
414 // If it's a new palette, just set the data:
416 $paletteData['showitem'] = self
::removeDuplicatesForInsertion($addFields);
422 * Add an item to a select field item list.
424 * Warning: Do not use this method for radio or check types, especially not
425 * with $relativeToField and $relativePosition parameters. This would shift
426 * existing database data 'off by one'.
428 * As an example, this can be used to add an item to tt_content CType select
429 * drop-down after the existing 'mailform' field with these parameters:
430 * - $table = 'tt_content'
433 * 'LLL:EXT:cms/locallang_ttc.xml:CType.I.10',
435 * 'i/tt_content_login.gif',
437 * - $relativeToField = mailform
438 * - $relativePosition = after
440 * @throws InvalidArgumentException If given parameters are not of correct
441 * type or out of bounds
442 * @throws RuntimeException If reference to related position fields can not
443 * be found or if select field is not defined
445 * @param string $table Name of TCA table
446 * @param string $field Name of TCA field
447 * @param array $item New item to add
448 * @param string $relativeToField Add item relative to existing field
449 * @param string $relativePosition Valid keywords: 'before', 'after'
450 * or 'replace' to relativeToField field
454 public static function addTcaSelectItem($table, $field, array $item, $relativeToField = '', $relativePosition = '') {
455 if (!is_string($table)) {
456 throw new InvalidArgumentException(
457 'Given table is of type "' . gettype($table) . '" but a string is expected.',
461 if (!is_string($field)) {
462 throw new InvalidArgumentException(
463 'Given field is of type "' . gettype($field) . '" but a string is expected.',
467 if (!is_string($relativeToField)) {
468 throw new InvalidArgumentException(
469 'Given relative field is of type "' . gettype($relativeToField) . '" but a string is expected.',
473 if (!is_string($relativePosition)) {
474 throw new InvalidArgumentException(
475 'Given relative position is of type "' . gettype($relativePosition) . '" but a string is expected.',
479 if ($relativePosition !== '' && $relativePosition !== 'before' && $relativePosition !== 'after' && $relativePosition !== 'replace') {
480 throw new InvalidArgumentException(
481 'Relative position must be either empty or one of "before", "after", "replace".',
486 t3lib_div
::loadTCA($table);
488 if (!is_array($GLOBALS['TCA'][$table]['columns'][$field]['config']['items'])) {
489 throw new RuntimeException(
490 'Given select field item list was not found.',
495 // Make sure item keys are integers
496 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'] = array_values($GLOBALS['TCA'][$table]['columns'][$field]['config']['items']);
498 if (strlen($relativePosition) > 0) {
499 // Insert at specified position
500 $matchedPosition = t3lib_utility_Array
::filterByValueRecursive(
502 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items']
504 if (count($matchedPosition) > 0) {
505 $relativeItemKey = key($matchedPosition);
506 if ($relativePosition === 'replace') {
507 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][$relativeItemKey] = $item;
509 if ($relativePosition === 'before') {
510 $offset = $relativeItemKey;
512 $offset = $relativeItemKey +
1;
514 array_splice($GLOBALS['TCA'][$table]['columns'][$field]['config']['items'], $offset, 0, array(0 => $item));
517 // Insert at new item at the end of the array if relative position was not found
518 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][] = $item;
521 // Insert at new item at the end of the array
522 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][] = $item;
527 * Gets the TCA configuration for a field handling (FAL) files.
529 * @param string $fieldName Name of the field to be used
530 * @param array $customSettingOverride Custom field settings overriding the basics
531 * @param string $allowedFileExtensions Comma list of allowed file extensions (e.g. "jpg,gif,pdf")
534 public static function getFileFieldTCAConfig($fieldName, array $customSettingOverride = array(), $allowedFileExtensions = '', $disallowedFileExtensions = '') {
535 $fileFieldTCAConfig = array(
537 'foreign_table' => 'sys_file_reference',
538 'foreign_field' => 'uid_foreign',
539 'foreign_sortby' => 'sorting_foreign',
540 'foreign_table_field' => 'tablenames',
541 'foreign_match_fields' => array(
542 'fieldname' => $fieldName,
544 'foreign_label' => 'uid_local',
545 'foreign_selector' => 'uid_local',
546 'foreign_selector_fieldTcaOverride' => array(
548 'appearance' => array(
549 'elementBrowserType' => 'file',
550 'elementBrowserAllowed' => $allowedFileExtensions,
556 'userFunc' => 't3lib_file_Utility_FileExtensionFilter->filterInlineChildren',
557 'parameters' => array(
558 'allowedFileExtensions' => $allowedFileExtensions,
559 'disallowedFileExtensions' => $disallowedFileExtensions,
563 'appearance' => array(
564 'useSortable' => TRUE,
565 'headerThumbnail' => 'uid_local',
566 'enabledControls' => array(
577 return t3lib_div
::array_merge_recursive_overrule($fileFieldTCAConfig, $customSettingOverride);
581 * Adds a list of new fields to the TYPO3 USER SETTINGS configuration "showitem" list, the array with
582 * the new fields itself needs to be added additionally to show up in the user setup, like
583 * $GLOBALS['TYPO3_USER_SETTINGS']['columns'] += $tempColumns
585 * @param string $addFields List of fields to be added to the user settings
586 * @param string $insertionPosition Insert fields before (default) or after one
587 * of this fields (commalist with "before:", "after:" or "replace:" commands).
588 * Example: "before:password,after:email".
591 public static function addFieldsToUserSettings($addFields, $insertionPosition = '') {
592 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'] = self
::executePositionedStringInsertion(
593 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'],
600 * Inserts as list of data into an existing list.
601 * The insertion position can be defined accordant before of after existing list items.
603 * @param string $list The list of items to be extended
604 * @param string $insertionList The list of items to inserted
605 * @param string $insertionPosition Insert fields before (default) or after one
606 * of this fields (commalist with "before:" or "after:" commands).
607 * Example: "before:keywords,--palette--;;4,after:description".
608 * Palettes must be passed like in the example no matter how the
609 * palette definition looks like in TCA.
610 * @return string The extended list
612 protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
614 $insertionList = self
::removeDuplicatesForInsertion($insertionList, $list);
616 if ($insertionList) {
617 // Append data to the end (default):
618 if ($insertionPosition === '') {
619 $list .= ($list ?
', ' : '') . $insertionList;
620 // Insert data before or after insertion points:
622 $positions = t3lib_div
::trimExplode(',', $insertionPosition, TRUE);
623 $items = self
::explodeItemList($list);
625 // Iterate through all fields an check whether it's possible to inserte there:
626 foreach ($items as $item => &$itemDetails) {
627 $needles = self
::getInsertionNeedles($item, $itemDetails['details']);
628 // Insert data before:
629 foreach ($needles['before'] as $needle) {
630 if (in_array($needle, $positions)) {
631 $itemDetails['rawData'] = $insertionList . ', ' . $itemDetails['rawData'];
636 // Insert data after:
637 foreach ($needles['after'] as $needle) {
638 if (in_array($needle, $positions)) {
639 $itemDetails['rawData'] .= ', ' . $insertionList;
644 // Replace with data:
645 foreach ($needles['replace'] as $needle) {
646 if (in_array($needle, $positions)) {
647 $itemDetails['rawData'] = $insertionList;
652 // Break if insertion was already done:
657 // If insertion point could not be determined, append the data:
659 $list .= ($list ?
', ' : '') . $insertionList;
660 // If data was correctly inserted before or after existing items, recreate the list:
662 $list = self
::generateItemList($items, TRUE);
671 * Compares an existing list of items and a list of items to be inserted
672 * and returns a duplicate-free variant of that insertion list.
675 * + list: 'field_a, field_b;;;;2-2-2, field_c;;;;3-3-3'
676 * + insertion: 'field_b, field_d, field_c;;;4-4-4'
677 * -> new insertion: 'field_d'
679 * @param string $insertionList The list of items to inserted
680 * @param string $list The list of items to be extended (default: '')
681 * @return string Duplicate-free list of items to be inserted
683 protected static function removeDuplicatesForInsertion($insertionList, $list = '') {
684 $pattern = '/(^|,)\s*\b([^;,]+)\b[^,]*/';
685 $listItems = array();
687 if ($list && preg_match_all($pattern, $list, $listMatches)) {
688 $listItems = $listMatches[2];
691 if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
692 $insertionItems = array();
693 $insertionDuplicates = FALSE;
695 foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) {
696 if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) {
697 $insertionItems[$insertionItem] = TRUE;
699 unset($insertionListMatches[0][$insertionIndex]);
700 $insertionDuplicates = TRUE;
704 if ($insertionDuplicates) {
705 $insertionList = implode('', $insertionListMatches[0]);
709 return $insertionList;
713 * Generates search needles that are used for inserting fields/items into an existing list.
715 * @see executePositionedStringInsertion
716 * @param string $item The name of the field/item
717 * @param array $itemDetails Additional details of the field/item like e.g. palette information
718 * (this array gets created by the function explodeItemList())
719 * @return array The needled to be used for inserting content before or after existing fields/items
721 protected static function getInsertionNeedles($item, array $itemDetails) {
722 if (strstr($item, '--')) {
723 // 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.
724 $item = preg_replace('/[0-9]+$/', '', $item);
728 'before' => array($item, 'before:' . $item),
729 'after' => array('after:' . $item),
730 'replace' => array('replace:' . $item),
733 if ($itemDetails['palette']) {
734 $palette = $item . ';;' . $itemDetails['palette'];
735 $needles['before'][] = $palette;
736 $needles['before'][] = 'before:' . $palette;
737 $needles['after'][] = 'after:' . $palette;
738 $needles['replace'][] = 'replace:' . $palette;
745 * Generates an array of fields/items with additional information such as e.g. the name of the palette.
747 * @param string $itemList List of fields/items to be splitted up
748 * (this mostly reflects the data in $GLOBALS['TCA'][<table>]['types'][<type>]['showitem'])
749 * @return array An array with the names of the fields/items as keys and additional information
751 protected static function explodeItemList($itemList) {
753 $itemParts = t3lib_div
::trimExplode(',', $itemList, TRUE);
755 foreach ($itemParts as $itemPart) {
756 $itemDetails = t3lib_div
::trimExplode(';', $itemPart, FALSE, 5);
757 $key = $itemDetails[0];
758 if (strstr($key, '--')) {
759 // 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!
760 $key .= count($items);
763 if (!isset($items[$key])) {
764 $items[$key] = array(
765 'rawData' => $itemPart,
767 'field' => $itemDetails[0],
768 'label' => $itemDetails[1],
769 'palette' => $itemDetails[2],
770 'special' => $itemDetails[3],
771 'styles' => $itemDetails[4],
781 * Generates a list of fields/items out of an array provided by the function getFieldsOfFieldList().
783 * @see explodeItemList
784 * @param array $items The array of fields/items with optional additional information
785 * @param boolean $useRawData Use raw data instead of building by using the details (default: FALSE)
786 * @return string The list of fields/items which gets used for $GLOBALS['TCA'][<table>]['types'][<type>]['showitem']
787 * or $GLOBALS['TCA'][<table>]['palettes'][<palette>]['showitem'] in most cases
789 protected static function generateItemList(array $items, $useRawData = FALSE) {
790 $itemParts = array();
792 foreach ($items as $item => $itemDetails) {
793 if (strstr($item, '--')) {
794 // 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.
795 $item = preg_replace('/[0-9]+$/', '', $item);
799 $itemParts[] = $itemDetails['rawData'];
801 $itemParts[] = (count($itemDetails['details']) > 1 ?
implode(';', $itemDetails['details']) : $item);
805 return implode(', ', $itemParts);
809 * Add tablename to default list of allowed tables on pages (in $PAGES_TYPES)
810 * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
811 * FOR USE IN ext_tables.php FILES
813 * @param string $table Table name
816 public static function allowTableOnStandardPages($table) {
817 $GLOBALS['PAGES_TYPES']['default']['allowedTables'] .= ',' . $table;
820 * Adds a ExtJS module (main or sub) to the backend interface
821 * FOR USE IN ext_tables.php FILES
824 * @param string $extensionName
825 * @param string $mainModuleName Is the main module key
826 * @param string $subModuleName Is the submodule key, if blank a plain main module is generated
827 * @param string $position Passed to t3lib_extMgm::addModule, see reference there
828 * @param array $moduleConfiguration Icon with array keys: access, icon, labels to configure the module
829 * @throws InvalidArgumentException
831 public static function addExtJSModule($extensionName, $mainModuleName, $subModuleName = '', $position = '', array $moduleConfiguration = array()) {
832 if (empty($extensionName)) {
833 throw new InvalidArgumentException('The extension name must not be empty', 1325938973);
836 $extensionKey = t3lib_div
::camelCaseToLowerCaseUnderscored($extensionName);
837 $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
839 $defaultModuleConfiguration = array(
841 'icon' => 'gfx/typo3.png',
843 'extRelPath' => self
::extRelPath($extensionKey) . 'Classes/'
846 // Add mandatory parameter to use new pagetree
847 if ($mainModuleName === 'web') {
848 $defaultModuleConfiguration['navigationComponentId'] = 'typo3-pagetree';
851 $moduleConfiguration = t3lib_div
::array_merge_recursive_overrule($defaultModuleConfiguration, $moduleConfiguration);
853 if ((strlen($subModuleName) > 0)) {
854 $moduleSignature = $mainModuleName . '_' . $subModuleName;
856 $moduleSignature = $mainModuleName;
859 $moduleConfiguration['name'] = $moduleSignature;
860 $moduleConfiguration['script'] = 'extjspaneldummy.html';
861 $moduleConfiguration['extensionName'] = $extensionName;
862 $moduleConfiguration['configureModuleFunction'] = array('t3lib_extMgm', 'configureModule');
864 $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature] = $moduleConfiguration;
866 self
::addModule($mainModuleName, $subModuleName, $position);
870 * This method is called from t3lib_loadModules::checkMod and it replaces old conf.php.
872 * The original function for is called
873 * Tx_Extbase_Utility_Extension::configureModule, the refered function can
876 * @param string $moduleSignature The module name
877 * @param string $modulePath Absolute path to module (not used by Extbase currently)
878 * @return array Configuration of the module
880 public static function configureModule($moduleSignature, $modulePath) {
881 $moduleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature];
882 $iconPathAndFilename = $moduleConfiguration['icon'];
883 if (substr($iconPathAndFilename, 0, 4) === 'EXT:') {
884 list($extensionKey, $relativePath) = explode('/', substr($iconPathAndFilename, 4), 2);
885 $iconPathAndFilename = self
::extPath($extensionKey) . $relativePath;
887 // TODO: skin support
889 $moduleLabels = array(
890 'tabs_images' => array(
891 'tab' => $iconPathAndFilename,
894 'tablabel' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_labels_tablabel'),
895 'tabdescr' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_labels_tabdescr'),
898 'tab' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_tabs_tab')
901 $GLOBALS['LANG']->addModuleLabels($moduleLabels, $moduleSignature . '_');
903 return $moduleConfiguration;
907 * Adds a module (main or sub) to the backend interface
908 * FOR USE IN ext_tables.php FILES
910 * @param string $main 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.
911 * @param string $sub The submodule key. If $sub is not set a blank $main module is created.
912 * @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.
913 * @param string $path 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.
916 public static function addModule($main, $sub = '', $position = '', $path = '') {
917 if (isset($GLOBALS['TBE_MODULES'][$main]) && $sub) {
918 // If there is already a main module by this name:
920 // Adding the submodule to the correct position:
921 list($place, $modRef) = t3lib_div
::trimExplode(':', $position, 1);
922 $mods = t3lib_div
::trimExplode(',', $GLOBALS['TBE_MODULES'][$main], 1);
923 if (!in_array($sub, $mods)) {
924 switch (strtolower($place)) {
929 foreach ($mods as $k => $m) {
930 if (!strcmp($m, $modRef)) {
931 $pointer = strtolower($place) == 'after' ?
$k +
1 : $k;
937 $mods, // The modules array
938 $pointer, // To insert one position from the end of the list
939 0, // Don't remove any items, just insert
940 $sub // Module to insert
943 // If requested module is not found: Add at the end
944 array_push($mods, $sub);
948 if (strtolower($place) == 'top') {
949 array_unshift($mods, $sub);
951 array_push($mods, $sub);
956 // Re-inserting the submodule list:
957 $GLOBALS['TBE_MODULES'][$main] = implode(',', $mods);
958 } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank)
959 $GLOBALS['TBE_MODULES'][$main] = $sub;
964 $GLOBALS['TBE_MODULES']['_PATHS'][$main . ($sub ?
'_' . $sub : '')] = $path;
969 * Registers an Ext.Direct component with access restrictions.
971 * @param string $endpointName
972 * @param string $callbackClass
973 * @param string $moduleName Optional: must be <mainmodule> or <mainmodule>_<submodule>
974 * @param string $accessLevel Optional: can be 'admin' or 'user,group'
977 public static function registerExtDirectComponent($endpointName, $callbackClass, $moduleName = NULL, $accessLevel = NULL) {
978 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'][$endpointName] = array(
979 'callbackClass' => $callbackClass,
980 'moduleName' => $moduleName,
981 'accessLevel' => $accessLevel,
986 * Adds a module path to $GLOBALS['TBE_MODULES'] for used with the module dispatcher, mod.php
987 * Used only for modules that are not placed in the main/sub menu hierarchy by the traditional mechanism of addModule()
988 * Examples for this is context menu functionality (like import/export) which runs as an independent module through mod.php
989 * FOR USE IN ext_tables.php FILES
990 * Example: t3lib_extMgm::addModulePath('xMOD_tximpexp', t3lib_extMgm::extPath($_EXTKEY).'app/');
992 * @param string $name The name of the module, refer to conf.php of the module.
993 * @param string $path The absolute path to the module directory inside of which "index.php" and "conf.php" is found.
996 public static function addModulePath($name, $path) {
997 $GLOBALS['TBE_MODULES']['_PATHS'][$name] = $path;
1001 * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
1002 * The arguments values are generally determined by which function menu this is supposed to interact with
1003 * See Inside TYPO3 for information on how to use this function.
1004 * FOR USE IN ext_tables.php FILES
1006 * @param string $modname Module name
1007 * @param string $className Class name
1008 * @param string $classPath Class path
1009 * @param string $title Title of module
1010 * @param string $MM_key Menu array key - default is "function"
1011 * @param string $WS Workspace conditions. Blank means all workspaces, any other string can be a comma list of "online", "offline" and "custom"
1013 * @see t3lib_SCbase::mergeExternalItems()
1015 public static function insertModuleFunction($modname, $className, $classPath, $title, $MM_key = 'function', $WS = '') {
1016 $GLOBALS['TBE_MODULES_EXT'][$modname]['MOD_MENU'][$MM_key][$className] = array(
1017 'name' => $className,
1018 'path' => $classPath,
1025 * Adds some more content to a key of TYPO3_CONF_VARS array.
1027 * This also tracks which content was added by extensions (in TYPO3_CONF_VARS_extensionAdded)
1028 * so that they cannot be editted again through the Install Tool.
1031 * @param string $group The group ('FE', 'BE', 'SYS' ...)
1032 * @param string $key The key of this setting within the group
1033 * @param string $content The text to add (include leading "\n" in case of multi-line entries)
1036 public static function appendToTypoConfVars($group, $key, $content) {
1037 $GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$group][$key] .= $content;
1038 $GLOBALS['TYPO3_CONF_VARS'][$group][$key] .= $content;
1042 * Adds $content to the default Page TSconfig as set in $GLOBALS['TYPO3_CONF_VARS'][BE]['defaultPageTSconfig']
1043 * Prefixed with a [GLOBAL] line
1044 * FOR USE IN ext_tables.php/ext_localconf.php FILES
1046 * @param string $content Page TSconfig content
1049 public static function addPageTSConfig($content) {
1050 self
::appendToTypoConfVars('BE', 'defaultPageTSconfig', "\n[GLOBAL]\n" . $content);
1054 * Adds $content to the default User TSconfig as set in $GLOBALS['TYPO3_CONF_VARS'][BE]['defaultUserTSconfig']
1055 * Prefixed with a [GLOBAL] line
1056 * FOR USE IN ext_tables.php/ext_localconf.php FILES
1058 * @param string $content User TSconfig content
1061 public static function addUserTSConfig($content) {
1062 self
::appendToTypoConfVars('BE', 'defaultUserTSconfig', "\n[GLOBAL]\n" . $content);
1066 * Adds a reference to a locallang file with $GLOBALS['TCA_DESCR'] labels
1067 * FOR USE IN ext_tables.php FILES
1068 * 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.
1070 * @param string $tca_descr_key Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
1071 * @param string $file_ref File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
1074 public static function addLLrefForTCAdescr($tca_descr_key, $file_ref) {
1075 if ($tca_descr_key) {
1076 if (!is_array($GLOBALS['TCA_DESCR'][$tca_descr_key])) {
1077 $GLOBALS['TCA_DESCR'][$tca_descr_key] = array();
1079 if (!is_array($GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'])) {
1080 $GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'] = array();
1082 $GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'][] = $file_ref;
1087 * Registers a navigation component
1089 * @param string $module
1090 * @param string $componentId
1093 public static function addNavigationComponent($module, $componentId) {
1094 $GLOBALS['TBE_MODULES']['_navigationComponents'][$module] = array(
1095 'componentId' => $componentId,
1096 'extKey' => $GLOBALS['_EXTKEY'],
1097 'isCoreComponent' => FALSE,
1102 * Registers a core navigation component
1104 * @param string $module
1105 * @param string $componentId
1108 public static function addCoreNavigationComponent($module, $componentId) {
1109 self
::addNavigationComponent($module, $componentId);
1110 $GLOBALS['TBE_MODULES']['_navigationComponents'][$module]['isCoreComponent'] = TRUE;
1113 /**************************************
1115 * Adding SERVICES features
1117 ***************************************/
1120 * Adds a service to the global services array
1122 * @param string $extKey Extension key
1123 * @param string $serviceType Service type, must not be prefixed "tx_" or "Tx_"
1124 * @param string $serviceKey Service key, must be prefixed "tx_", "Tx_" or "user_"
1125 * @param array $info Service description array
1128 public static function addService($extKey, $serviceType, $serviceKey, $info) {
1129 if ($serviceType && is_array($info)) {
1130 $info['priority'] = max(0, min(100, $info['priority']));
1132 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey] = $info;
1134 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['extKey'] = $extKey;
1135 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
1136 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceType'] = $serviceType;
1138 // Change the priority (and other values) from $GLOBALS['TYPO3_CONF_VARS']
1139 // $GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey]['priority']
1140 // even the activation is possible (a unix service might be possible on windows for some reasons)
1141 if (is_array($GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey])) {
1143 // No check is done here - there might be configuration values only the service type knows about, so
1144 // we pass everything
1145 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey] = array_merge(
1146 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey],
1147 $GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey]
1152 // Empty $os means 'not limited to one OS', therefore a check is not needed
1153 if ($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['available']
1154 && $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['os'] != '') {
1156 // TYPO3_OS is not yet defined
1157 $os_type = stristr(PHP_OS
, 'win') && !stristr(PHP_OS
, 'darwin') ?
'WIN' : 'UNIX';
1159 $os = t3lib_div
::trimExplode(',', strtoupper($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['os']));
1161 if (!in_array($os_type, $os)) {
1162 self
::deactivateService($serviceType, $serviceKey);
1166 // Convert subtype list to array for quicker access
1167 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceSubTypes'] = array();
1168 $serviceSubTypes = t3lib_div
::trimExplode(',', $info['subtype']);
1169 foreach ($serviceSubTypes as $subtype) {
1170 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
1176 * Find the available service with highest priority
1178 * @param string $serviceType Service type
1179 * @param string $serviceSubType Service sub type
1180 * @param mixed $excludeServiceKeys Service keys that should be excluded in the search for a service. Array or comma list.
1181 * @return mixed Service info array if a service was found, FALSE otherwise
1183 public static function findService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) {
1184 $serviceKey = FALSE;
1185 $serviceInfo = FALSE;
1189 if (!is_array($excludeServiceKeys)) {
1190 $excludeServiceKeys = t3lib_div
::trimExplode(',', $excludeServiceKeys, 1);
1193 if (is_array($GLOBALS['T3_SERVICES'][$serviceType])) {
1195 foreach ($GLOBALS['T3_SERVICES'][$serviceType] as $key => $info) {
1197 if (in_array($key, $excludeServiceKeys)) {
1201 // Select a subtype randomly
1202 // Useful to start a service by service key without knowing his subtypes - for testing purposes
1203 if ($serviceSubType == '*') {
1204 $serviceSubType = key($info['serviceSubTypes']);
1207 // This matches empty subtype too
1208 if ($info['available'] && ($info['subtype'] == $serviceSubType ||
$info['serviceSubTypes'][$serviceSubType]) && $info['priority'] >= $priority) {
1210 // Has a lower quality than the already found, therefore we skip this service
1211 if ($info['priority'] == $priority && $info['quality'] < $quality) {
1215 // Check if the service is available
1216 $info['available'] = self
::isServiceAvailable($serviceType, $key, $info);
1218 // Still available after exec check?
1219 if ($info['available']) {
1221 $priority = $info['priority'];
1222 $quality = $info['quality'];
1229 $serviceInfo = $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey];
1231 return $serviceInfo;
1235 * Find a specific service identified by its key
1236 * Note that this completely bypasses the notions of priority and quality
1238 * @param string $serviceKey Service key
1239 * @return array Service info array if a service was found
1240 * @throws t3lib_exception
1242 public static function findServiceByKey($serviceKey) {
1243 if (is_array($GLOBALS['T3_SERVICES'])) {
1244 // Loop on all service types
1245 // NOTE: we don't care about the actual type, we are looking for a specific key
1246 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $servicesPerType) {
1247 if (isset($servicesPerType[$serviceKey])) {
1248 $serviceDetails = $servicesPerType[$serviceKey];
1249 // Test if service is available
1250 if (self
::isServiceAvailable($serviceType, $serviceKey, $serviceDetails)) {
1251 // We have found the right service, return its information
1252 return $serviceDetails;
1257 throw new t3lib_exception('Service not found for key: ' . $serviceKey, 1319217244);
1261 * Check if a given service is available, based on the executable files it depends on
1263 * @param string $serviceType Type of service
1264 * @param string $serviceKey Specific key of the service
1265 * @param array $serviceDetails Information about the service
1266 * @return boolean Service availability
1268 public static function isServiceAvailable($serviceType, $serviceKey, $serviceDetails) {
1270 // If the service depends on external programs - check if they exists
1271 if (trim($serviceDetails['exec'])) {
1272 $executables = t3lib_div
::trimExplode(',', $serviceDetails['exec'], 1);
1273 foreach ($executables as $executable) {
1274 // If at least one executable file is not available, exit early returning FALSE
1275 if (!t3lib_exec
::checkCommand($executable)) {
1276 self
::deactivateService($serviceType, $serviceKey);
1281 // The service is available
1286 * Deactivate a service
1288 * @param string $serviceType Service type
1289 * @param string $serviceKey Service key
1292 public static function deactivateService($serviceType, $serviceKey) {
1293 // ... maybe it's better to move non-available services to a different array??
1294 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['available'] = FALSE;
1297 /**************************************
1299 * Adding FRONTEND features
1300 * (related specifically to "cms" extension)
1302 ***************************************/
1305 * Adds an entry to the list of plugins in content elements of type "Insert plugin"
1306 * 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)
1307 * 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.
1308 * 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
1309 * FOR USE IN ext_tables.php FILES
1311 * @param array $itemArray Item Array
1312 * @param string $type Type (eg. "list_type") - basically a field from "tt_content" table
1315 public static function addPlugin($itemArray, $type = 'list_type') {
1316 $_EXTKEY = $GLOBALS['_EXTKEY'];
1317 if ($_EXTKEY && !$itemArray[2]) {
1318 $itemArray[2] = self
::extRelPath($_EXTKEY) .
1319 $GLOBALS['TYPO3_LOADED_EXT'][$_EXTKEY]['ext_icon'];
1322 t3lib_div
::loadTCA('tt_content');
1323 if (is_array($GLOBALS['TCA']['tt_content']['columns']) && is_array($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'])) {
1324 foreach ($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'] as $k => $v) {
1325 if (!strcmp($v[1], $itemArray[1])) {
1326 $GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'][$k] = $itemArray;
1330 $GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'][] = $itemArray;
1335 * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
1336 * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin or content element.
1338 * @param string $piKeyToMatch Plugin key as used in the list_type field. Use the asterisk * to match all list_type values.
1339 * @param string $value Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
1340 * @param string $CTypeToMatch 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.
1344 public static function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch = 'list') {
1345 t3lib_div
::loadTCA('tt_content');
1347 if (is_array($GLOBALS['TCA']['tt_content']['columns']) && is_array($GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds'])) {
1348 $GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch . ',' . $CTypeToMatch] = $value;
1353 * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
1354 * By using $content_table and $content_field you can also use the function for other tables.
1355 * FOR USE IN ext_tables.php FILES
1357 * @param string $table Table name to allow for "insert record"
1358 * @param string $content_table Table name TO WHICH the $table name is applied. See $content_field as well.
1359 * @param string $content_field Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
1362 public static function addToInsertRecords($table, $content_table = 'tt_content', $content_field = 'records') {
1363 t3lib_div
::loadTCA($content_table);
1364 if (is_array($GLOBALS['TCA'][$content_table]['columns']) && isset($GLOBALS['TCA'][$content_table]['columns'][$content_field]['config']['allowed'])) {
1365 $GLOBALS['TCA'][$content_table]['columns'][$content_field]['config']['allowed'] .= ',' . $table;
1370 * Add PlugIn to Static Template #43
1372 * 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.
1373 * 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"
1374 * $type determines the type of frontend plugin:
1375 * "list_type" (default) - the good old "Insert plugin" entry
1376 * "menu_type" - a "Menu/Sitemap" entry
1377 * "splash_layout" - a "Textbox" entry
1378 * "CType" - a new content element type
1379 * "header_layout" - an additional header type (added to the selection of layout1-5)
1380 * "includeLib" - just includes the library for manual use somewhere in TypoScript.
1381 * (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)
1382 * FOR USE IN ext_localconf.php FILES
1384 * @param string $key The extension key
1385 * @param string $classFile The PHP-class filename relative to the extension root directory. If set to blank a default value is chosen according to convensions.
1386 * @param string $prefix Is used as a - yes, suffix - of the class name (fx. "_pi1")
1387 * @param string $type See description above
1388 * @param boolean $cached If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
1391 public static function addPItoST43($key, $classFile = '', $prefix = '', $type = 'list_type', $cached = 0) {
1392 $classFile = $classFile ?
$classFile : 'pi/class.tx_' . str_replace('_', '', $key) . $prefix . '.php';
1393 $cN = self
::getCN($key);
1396 $pluginContent = trim('
1397 plugin.' . $cN . $prefix . ' = USER' . ($cached ?
'' : '_INT') . '
1398 plugin.' . $cN . $prefix . ' {
1399 includeLibs = ' . $GLOBALS['TYPO3_LOADED_EXT'][$key]['siteRelPath'] . $classFile . '
1400 userFunc = ' . $cN . $prefix . '->main
1402 self
::addTypoScript($key, 'setup', '
1403 # Setting ' . $key . ' plugin TypoScript
1404 ' . $pluginContent);
1409 $addLine = 'tt_content.list.20.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1412 $addLine = 'tt_content.menu.20.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1414 case 'splash_layout':
1415 $addLine = 'tt_content.splash.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1419 tt_content.' . $key . $prefix . ' = COA
1420 tt_content.' . $key . $prefix . ' {
1421 10 = < lib.stdheader
1422 20 = < plugin.' . $cN . $prefix . '
1426 case 'header_layout':
1427 $addLine = 'lib.stdheader.10.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1430 $addLine = 'page.1000 = < plugin.' . $cN . $prefix;
1437 self
::addTypoScript($key, 'setup', '
1438 # Setting ' . $key . ' plugin TypoScript
1445 * Call this method to add an entry in the static template list found in sys_templates
1446 * "static template files" are the modern equivalent (provided from extensions) to the traditional records in "static_templates"
1447 * FOR USE IN ext_localconf.php FILES
1449 * @param string $extKey Is of course the extension key
1450 * @param string $path Is the path where the template files (fixed names) include_static.txt (integer list of uids from the table "static_templates"), constants.txt, setup.txt, and 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/
1451 * @param string $title Is the title in the selector box.
1453 * @see addTypoScript()
1455 public static function addStaticFile($extKey, $path, $title) {
1456 t3lib_div
::loadTCA('sys_template');
1457 if ($extKey && $path && is_array($GLOBALS['TCA']['sys_template']['columns'])) {
1458 $value = str_replace(',', '', 'EXT:' . $extKey . '/' . $path);
1459 $itemArray = array(trim($title . ' (' . $extKey . ')'), $value);
1460 $GLOBALS['TCA']['sys_template']['columns']['include_static_file']['config']['items'][] = $itemArray;
1465 * Adds $content to the default TypoScript setup code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_setup']
1466 * Prefixed with a [GLOBAL] line
1467 * FOR USE IN ext_localconf.php FILES
1469 * @param string $content TypoScript Setup string
1472 public static function addTypoScriptSetup($content) {
1473 self
::appendToTypoConfVars('FE', 'defaultTypoScript_setup', "\n[GLOBAL]\n" . $content);
1477 * Adds $content to the default TypoScript constants code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_constants']
1478 * Prefixed with a [GLOBAL] line
1479 * FOR USE IN ext_localconf.php FILES
1481 * @param string $content TypoScript Constants string
1484 public static function addTypoScriptConstants($content) {
1485 self
::appendToTypoConfVars('FE', 'defaultTypoScript_constants', "\n[GLOBAL]\n" . $content);
1489 * Adds $content to the default TypoScript code for either setup or constants as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_*']
1490 * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
1491 * FOR USE IN ext_localconf.php FILES
1493 * @param string $key Is the extension key (informative only).
1494 * @param string $type Is either "setup" or "constants" and obviously determines which kind of TypoScript code we are adding.
1495 * @param string $content Is the TS content, prefixed with a [GLOBAL] line and a comment-header.
1496 * @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.
1499 public static function addTypoScript($key, $type, $content, $afterStaticUid = 0) {
1500 if ($type == 'setup' ||
$type == 'constants') {
1504 #############################################
1505 ## TypoScript added by extension "' . $key . '"
1506 #############################################
1509 if ($afterStaticUid) {
1510 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type . '.'][$afterStaticUid] .= $content;
1511 // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
1512 if ($afterStaticUid == 43 && is_array($GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'])) {
1513 foreach ($GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'] as $templateName) {
1514 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type . '.'][$templateName] .= $content;
1518 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type] .= $content;
1523 /***************************************
1525 * Internal extension management methods
1527 ***************************************/
1530 * Load the extension information array. This array is set as
1531 * $GLOBALS['TYPO3_LOADED_EXT'] in bootstrap. It contains basic information
1532 * about every loaded extension.
1534 * This is an internal method. It is only used during bootstrap and
1535 * extensions should not use it!
1537 * @param boolean $allowCaching If FALSE, the array will not be read / created from cache
1538 * @return array Result array that will be set as $GLOBALS['TYPO3_LOADED_EXT']
1540 * @see createTypo3LoadedExtensionInformationArray
1542 public static function loadTypo3LoadedExtensionInformation($allowCaching = TRUE) {
1543 if ($allowCaching) {
1544 $cacheIdentifier = self
::getTypo3LoadedExtensionInformationCacheIdentifier();
1545 /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
1546 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1547 if ($codeCache->has($cacheIdentifier)) {
1548 $typo3LoadedExtensionArray = $codeCache->requireOnce($cacheIdentifier);
1550 $typo3LoadedExtensionArray = self
::createTypo3LoadedExtensionInformationArray();
1553 'return ' . var_export($typo3LoadedExtensionArray, TRUE) . ';'
1557 $typo3LoadedExtensionArray = self
::createTypo3LoadedExtensionInformationArray();
1560 return $typo3LoadedExtensionArray;
1564 * Set up array with basic information about loaded extension:
1567 * 'extensionKey' => array(
1568 * 'type' => Either S, L or G, inidicating if the extension is a system, a local or a global extension
1569 * 'siteRelPath' => Relative path to the extension from document root
1570 * 'typo3RelPath' => Relative path to extension from typo3/ subdirectory
1571 * 'ext_localconf.php' => Absolute path to ext_localconf.php file of extension
1572 * 'ext_...' => Further absolute path of extension files, see $extensionFilesToCheckFor var for details
1576 * @return array Result array that will be set as $GLOBALS['TYPO3_LOADED_EXT']
1578 protected static function createTypo3LoadedExtensionInformationArray() {
1579 $loadedExtensions = static::getLoadedExtensionListArray();
1580 $loadedExtensionInformation = array();
1582 $extensionFilesToCheckFor = array(
1583 'ext_localconf.php',
1586 'ext_tables_static+adt.sql',
1587 'ext_typoscript_constants.txt',
1588 'ext_typoscript_setup.txt'
1591 // Clear file status cache to make sure we get good results from is_dir()
1594 foreach ($loadedExtensions as $extensionKey) {
1595 // Determine if extension is installed locally, globally or system (in this order)
1596 if (@is_dir
(PATH_typo3conf
. 'ext/' . $extensionKey . '/')) {
1598 $loadedExtensionInformation[$extensionKey] = array(
1600 'siteRelPath' => 'typo3conf/ext/' . $extensionKey . '/',
1601 'typo3RelPath' => '../typo3conf/ext/' . $extensionKey . '/'
1603 } elseif (@is_dir
(PATH_typo3
. 'ext/' . $extensionKey . '/')) {
1605 $loadedExtensionInformation[$extensionKey] = array(
1607 'siteRelPath' => TYPO3_mainDir
. 'ext/' . $extensionKey . '/',
1608 'typo3RelPath' => 'ext/' . $extensionKey . '/'
1610 } elseif (@is_dir
(PATH_typo3
. 'sysext/' . $extensionKey . '/')) {
1612 $loadedExtensionInformation[$extensionKey] = array(
1614 'siteRelPath' => TYPO3_mainDir
. 'sysext/' . $extensionKey . '/',
1615 'typo3RelPath' => 'sysext/' . $extensionKey . '/'
1619 // Register found files in extension array if extension was found
1620 if (isset($loadedExtensionInformation[$extensionKey])) {
1621 foreach ($extensionFilesToCheckFor as $fileName) {
1622 $absolutePathToFile = PATH_site
. $loadedExtensionInformation[$extensionKey]['siteRelPath'] . $fileName;
1623 if (@is_file
($absolutePathToFile)) {
1624 $loadedExtensionInformation[$extensionKey][$fileName] = $absolutePathToFile;
1628 // Register found extension icon
1629 $loadedExtensionInformation[$extensionKey]['ext_icon'] = self
::getExtensionIcon(PATH_site
. $loadedExtensionInformation[$extensionKey]['siteRelPath']);
1632 return $loadedExtensionInformation;
1636 * Find extension icon
1638 * @param string $extensionPath Path to extension directory.
1639 * @param string $returnFullPath Return full path of file.
1641 * @throws BadFunctionCallException
1643 public static function getExtensionIcon($extensionPath, $returnFullPath = FALSE){
1645 $iconFileTypesToCheckFor = array(
1650 foreach ($iconFileTypesToCheckFor as $fileType){
1651 if (@is_file
($extensionPath . 'ext_icon.' . $fileType)) {
1652 $icon = 'ext_icon.' . $fileType;
1657 return $returnFullPath ?
$extensionPath . $icon : $icon;
1661 * Cache identifier of cached Typo3LoadedExtensionInformation array
1665 protected static function getTypo3LoadedExtensionInformationCacheIdentifier() {
1666 return 'loaded_extensions_' . sha1(TYPO3_version
. PATH_site
. 'loadedExtensions');
1670 * Execute all ext_localconf.php files of loaded extensions.
1671 * The method implements an optionally used caching mechanism that concatenates all
1672 * ext_localconf.php files in one file.
1674 * This is an internal method. It is only used during bootstrap and
1675 * extensions should not use it!
1677 * @param boolean $allowCaching Whether or not to load / create concatenated cache file
1681 public static function loadExtLocalconf($allowCaching = TRUE) {
1682 if ($allowCaching) {
1683 $cacheIdentifier = self
::getExtLocalconfCacheIdentifier();
1684 /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
1685 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1686 if ($codeCache->has($cacheIdentifier)) {
1687 $codeCache->requireOnce($cacheIdentifier);
1689 self
::loadSingleExtLocalconfFiles();
1690 self
::createExtLocalconfCacheEntry();
1693 self
::loadSingleExtLocalconfFiles();
1698 * Execute ext_localconf.php files from extensions
1702 protected static function loadSingleExtLocalconfFiles() {
1703 // This is the main array meant to be manipulated in the ext_localconf.php files
1704 // In general it is recommended to not rely on it to be globally defined in that
1705 // scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
1706 // Nevertheless we define it here as global for backwards compatibility.
1707 global $TYPO3_CONF_VARS;
1709 // These globals for internal use only. Manipulating them directly is highly discouraged!
1710 // We set them here as global for backwards compatibility, but this will change in
1712 // @deprecated since 6.0 Will be removed in two versions.
1713 global $T3_SERVICES, $T3_VAR;
1715 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $_EXTKEY => $extensionInformation) {
1716 if (is_array($extensionInformation) && $extensionInformation['ext_localconf.php']) {
1717 // $_EXTKEY and $_EXTCONF are available in ext_localconf.php
1718 // and are explicitly set in cached file as well
1719 $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
1720 require($extensionInformation['ext_localconf.php']);
1726 * Create cache entry for concatenated ext_localconf.php files
1730 protected static function createExtLocalconfCacheEntry() {
1731 $extensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
1732 $phpCodeToCache = array();
1734 // Set same globals as in loadSingleExtLocalconfFiles()
1735 $phpCodeToCache[] = '/**';
1736 $phpCodeToCache[] = ' * Compiled ext_localconf.php cache file';
1737 $phpCodeToCache[] = ' */';
1738 $phpCodeToCache[] = '';
1739 $phpCodeToCache[] = 'global $TYPO3_CONF_VARS, $T3_SERVICES, $T3_VAR;';
1740 $phpCodeToCache[] = '';
1742 // Iterate through loaded extensions and add ext_localconf content
1743 foreach ($extensionInformation as $extensionKey => $extensionDetails) {
1744 // Include a header per extension to make the cache file more readable
1745 $phpCodeToCache[] = '/**';
1746 $phpCodeToCache[] = ' * Extension: ' . $extensionKey;
1747 $phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_localconf.php'];
1748 $phpCodeToCache[] = ' */';
1749 $phpCodeToCache[] = '';
1751 // Set $_EXTKEY and $_EXTCONF for this extension
1752 $phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
1753 $phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];';
1754 $phpCodeToCache[] = '';
1756 // Add ext_localconf.php content of extension
1757 $phpCodeToCache[] = trim(t3lib_div
::getUrl($extensionDetails['ext_localconf.php']));
1758 $phpCodeToCache[] = '';
1759 $phpCodeToCache[] = '';
1762 $phpCodeToCache = implode(LF
, $phpCodeToCache);
1763 // Remove all start and ending php tags from content
1764 $phpCodeToCache = preg_replace('/<\?php|\?>/is', '', $phpCodeToCache);
1766 $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(
1767 self
::getExtLocalconfCacheIdentifier(),
1773 * Cache identifier of concatenated ext_localconf file
1777 protected static function getExtLocalconfCacheIdentifier() {
1778 return 'ext_localconf_' . sha1(TYPO3_version
. PATH_site
. 'extLocalconf');
1782 * Execute all ext_tables.php files of loaded extensions.
1783 * The method implements an optionally used caching mechanism that concatenates all
1784 * ext_tables.php files in one file.
1786 * This is an internal method. It is only used during bootstrap and
1787 * extensions should not use it!
1789 * @param boolean $allowCaching Whether to load / create concatenated cache file
1793 public static function loadExtTables($allowCaching = TRUE) {
1794 if ($allowCaching && !self
::$extTablesWasReadFromCacheOnce) {
1795 self
::$extTablesWasReadFromCacheOnce = TRUE;
1796 $cacheIdentifier = self
::getExtTablesCacheIdentifier();
1797 /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
1798 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1799 if ($codeCache->has($cacheIdentifier)) {
1800 $codeCache->requireOnce($cacheIdentifier);
1802 self
::loadSingleExtTablesFiles();
1803 self
::createExtTablesCacheEntry();
1806 self
::loadSingleExtTablesFiles();
1811 * Load ext_tables.php as single files
1815 protected static function loadSingleExtTablesFiles() {
1816 // In general it is recommended to not rely on it to be globally defined in that
1817 // scope, but we can not prohibit this without breaking backwards compatibility
1818 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
1819 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
1820 global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
1823 // Load each ext_tables.php file of loaded extensions
1824 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $_EXTKEY => $extensionInformation) {
1825 if (is_array($extensionInformation) && $extensionInformation['ext_tables.php']) {
1826 // $_EXTKEY and $_EXTCONF are available in ext_tables.php
1827 // and are explicitly set in cached file as well
1828 $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
1829 require($extensionInformation['ext_tables.php']);
1835 * Create concatenated ext_tables.php cache file
1839 protected static function createExtTablesCacheEntry() {
1840 $extensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
1841 $phpCodeToCache = array();
1843 // Set same globals as in loadSingleExtTablesFiles()
1844 $phpCodeToCache[] = '/**';
1845 $phpCodeToCache[] = ' * Compiled ext_tables.php cache file';
1846 $phpCodeToCache[] = ' */';
1847 $phpCodeToCache[] = '';
1848 $phpCodeToCache[] = 'global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;';
1849 $phpCodeToCache[] = 'global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;';
1850 $phpCodeToCache[] = 'global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;';
1851 $phpCodeToCache[] = 'global $_EXTKEY;';
1852 $phpCodeToCache[] = '';
1854 // Iterate through loaded extensions and add ext_tables content
1855 foreach ($extensionInformation as $extensionKey => $extensionDetails) {
1856 // Include a header per extension to make the cache file more readable
1857 $phpCodeToCache[] = '/**';
1858 $phpCodeToCache[] = ' * Extension: ' . $extensionKey;
1859 $phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_tables.php'];
1860 $phpCodeToCache[] = ' */';
1861 $phpCodeToCache[] = '';
1863 // Set $_EXTKEY and $_EXTCONF for this extension
1864 $phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
1865 $phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];';
1866 $phpCodeToCache[] = '';
1868 // Add ext_tables.php content of extension
1869 $phpCodeToCache[] = trim(t3lib_div
::getUrl($extensionDetails['ext_tables.php']));
1870 $phpCodeToCache[] = '';
1871 $phpCodeToCache[] = '';
1874 $phpCodeToCache = implode(LF
, $phpCodeToCache);
1875 // Remove all start and ending php tags from content
1876 $phpCodeToCache = preg_replace('/<\?php|\?>/is', '', $phpCodeToCache);
1878 $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(
1879 self
::getExtTablesCacheIdentifier(),
1885 * Cache identifier for concatenated ext_tables.php files
1889 protected static function getExtTablesCacheIdentifier() {
1890 return 'ext_tables_' . sha1(TYPO3_version
. PATH_site
. 'extTables');
1894 * Loading extensions configured in $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray']
1896 * Usages of this function can be seen in bootstrap
1897 * Extensions are always detected in the order local - global - system.
1899 * @return array Extension Array
1901 * @deprecated since 6.0, will be removed in two versions
1903 public static function typo3_loadExtensions() {
1904 t3lib_div
::logDeprecatedFunction();
1905 return self
::loadTypo3LoadedExtensionInformation(TRUE);
1909 * Returns the section headers for the compiled cache-files.
1911 * @param string $key Is the extension key
1912 * @param string $file Is the filename (only informative for comment)
1915 * @deprecated since 6.0, will be removed in two versions
1917 public static function _makeIncludeHeader($key, $file) {
1918 t3lib_div
::logDeprecatedFunction();
1923 * Returns TRUE if both the localconf and tables cache file exists
1924 * (with $cacheFilePrefix) and if they are not empty
1926 * @param $cacheFilePrefix string Prefix of the cache file to check
1928 * @deprecated since 6.0, will be removed in two versions
1930 public static function isCacheFilesAvailable($cacheFilePrefix) {
1931 t3lib_div
::logDeprecatedFunction();
1936 * Returns TRUE if configuration files in typo3conf/ are writable
1938 * @return boolean TRUE if at least one configuration file in typo3conf/ is writable
1941 public static function isLocalconfWritable() {
1943 if (!@is_writable
(PATH_typo3conf
)) {
1947 !@is_writable
(PATH_site
. t3lib_Configuration
::LOCALCONF_FILE
)
1948 && !@is_writable
(PATH_site
. t3lib_Configuration
::LOCAL_CONFIGURATION_FILE
)
1956 * Returns an error string if typo3conf/ or cache-files with $cacheFilePrefix are NOT writable
1957 * Returns FALSE if no problem.
1959 * @param string $cacheFilePrefix Prefix of the cache file to check
1962 * @deprecated since 6.0, will be removed in two versions
1964 public static function cannotCacheFilesWritable($cacheFilePrefix) {
1965 t3lib_div
::logDeprecatedFunction();
1970 * Returns an array with the two cache-files (0=>localconf, 1=>tables)
1971 * from typo3conf/ if they (both) exist. Otherwise FALSE.
1972 * Evaluation relies on $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE']
1974 * @param string $cacheFilePrefix Cache file prefix to be used (optional)
1977 * @deprecated since 6.0, will be removed in versions
1979 public static function currentCacheFiles($cacheFilePrefix = NULL) {
1980 t3lib_div
::logDeprecatedFunction();
1985 * Compiles/Creates the two cache-files in typo3conf/ based on $cacheFilePrefix
1986 * Returns a array with the key "_CACHEFILE" set to the $cacheFilePrefix value
1988 * @param array $extensions Extension information array
1989 * @param string $cacheFilePrefix Prefix for the cache files
1992 * @deprecated since 6.0, will be removed in two versions
1994 public static function writeCacheFiles($extensions, $cacheFilePrefix) {
1995 t3lib_div
::logDeprecatedFunction();
2000 * Remove cache files from php code cache, tagged with 'core'
2002 * This removes the following cache entries:
2003 * - autoloader cache registry
2004 * - cache loaded extension array
2005 * - ext_localconf concatenation
2006 * - ext_tables concatenation
2008 * This method is usually only used by extension that fiddle
2009 * with the loaded extensions. An example is the extension
2010 * manager and the install tool.
2014 public static function removeCacheFiles() {
2015 /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
2016 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
2017 $codeCache->flush();
2021 * Gets the behaviour for caching ext_tables.php and ext_localconf.php files
2022 * (see $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache'] setting in the install tool).
2024 * @param boolean $usePlainValue Whether to use the value as it is without modifications
2026 * @deprecated since 6.0, will be removed two versions later
2028 public static function getExtensionCacheBehaviour($usePlainValue = FALSE) {
2029 t3lib_div
::logDeprecatedFunction();
2034 * Gets the prefix used for the ext_tables.php and ext_localconf.php cached files.
2037 * @deprecated since 6.0, will be removed two versions later
2039 public static function getCacheFilePrefix() {
2040 t3lib_div
::logDeprecatedFunction();
2044 * Gets the list of enabled extensions
2047 * @deprecated since 6.0, will be removed two versions later
2049 public static function getEnabledExtensionList() {
2050 t3lib_div
::logDeprecatedFunction();
2051 return implode(',', self
::getLoadedExtensionListArray());
2055 * Gets the list of required extensions.
2058 * @deprecated since 6.0, will be removed two versions later
2060 public static function getRequiredExtensionList() {
2061 t3lib_div
::logDeprecatedFunction();
2062 return implode(',', self
::getRequiredExtensionListArray());
2066 * Get list of extensions to be ignored (not to be loaded).
2069 * @deprecated since 6.0, will be removed two versions later
2071 public static function getIgnoredExtensionList() {
2072 t3lib_div
::logDeprecatedFunction();
2077 * Gets an array of loaded extension keys
2079 * @return array Loaded extensions
2081 public static function getLoadedExtensionListArray() {
2082 // Extensions in extListArray
2083 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'])) {
2084 $loadedExtensions = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'];
2086 // Fallback handling if extlist is still a string and not an array
2087 $loadedExtensions = t3lib_div
::trimExplode(
2089 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']
2093 // Add required extensions
2094 $loadedExtensions = array_merge(
2095 static::getRequiredExtensionListArray(),
2098 $loadedExtensions = array_unique($loadedExtensions);
2100 return $loadedExtensions;
2104 * Gets list of required extensions.
2105 * This is the list of extensions from constant REQUIRED_EXTENSIONS defined
2106 * in bootstrap, together with a possible additional list of extensions from
2107 * local configuration
2109 * @return array List of required extensions
2111 public static function getRequiredExtensionListArray() {
2112 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'])) {
2113 $requiredExtensions = $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'];
2115 $requiredExtensions = t3lib_div
::trimExplode(
2117 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt']
2121 $requiredExtensions = array_merge(
2122 t3lib_div
::trimExplode(',', REQUIRED_EXTENSIONS
),
2125 $requiredExtensions = array_unique($requiredExtensions);
2127 return $requiredExtensions;
2131 * Loads given extension
2133 * Warning: This method only works if the ugrade wizard to transform
2134 * localconf.php to LocalConfiguration.php was already run
2136 * @param string $extensionKey Extension key to load
2138 * @throws RuntimeException
2140 public static function loadExtension($extensionKey) {
2141 if (static::isLoaded($extensionKey)) {
2142 throw new RuntimeException(
2143 'Extension already loaded',
2147 $extList = t3lib_Configuration
::getLocalConfigurationValueByPath('EXT/extListArray');
2148 $extList[] = $extensionKey;
2149 static::writeNewExtensionList($extList);
2153 * Unloads given extension
2155 * Warning: This method only works if the ugrade wizard to transform
2156 * localconf.php to LocalConfiguration.php was already run
2158 * @param string $extensionKey Extension key to remove
2160 * @throws RuntimeException
2162 public static function unloadExtension($extensionKey) {
2163 if (!static::isLoaded($extensionKey)) {
2164 throw new RuntimeException(
2165 'Extension not loaded',
2169 if (in_array($extensionKey, static::getRequiredExtensionListArray())) {
2170 throw new RuntimeException(
2171 'Can not unload required extension',
2175 $extList = t3lib_Configuration
::getLocalConfigurationValueByPath('EXT/extListArray');
2176 $extList = array_diff(
2178 array($extensionKey)
2180 static::writeNewExtensionList($extList);
2184 * Writes extension list and clear cache files.
2186 * @TODO: This method should be protected, but with current em it is hard to do so,
2187 * so it is public for now, but will be made protected as soon as the em is fixed.
2189 * @param array Extension array to load, loader order is kept
2193 public static function writeNewExtensionList(array $newExtensionList) {
2194 $extensionList = array_unique($newExtensionList);
2195 t3lib_Configuration
::setLocalConfigurationValueByPath('EXT/extListArray', $extensionList);
2196 // @deprecated: extList as string is deprecated, the handling will be removed with 6.2
2197 // For now, this value is still set for better backwards compatibility
2198 t3lib_Configuration
::setLocalConfigurationValueByPath('EXT/extList', implode(',', $extensionList));
2199 static::removeCacheFiles();
2203 * Makes a table categorizable by extending its TCA.
2205 * @param string $extensionKey Extension key to be used
2206 * @param string $tableName Name of the table to be categoriezed
2207 * @param string $fieldName Name of the field to be used to store categories
2208 * @param array $options Additional configuration options
2209 * + fieldList: field configuration to be added to showitems
2210 * + typesList: list of types that shall visualize the categories field
2211 * + position: insert position of the categories field
2212 * + fieldConfiguration: TCA field config array to override defaults
2213 * @see addTCAcolumns
2214 * @see addToAllTCAtypes
2216 public static function makeCategorizable($extensionKey, $tableName, $fieldName = 'categories', array $options = array()) {
2218 t3lib_div
::loadTCA($tableName);
2220 // Update the category registry
2221 $result = t3lib_category_Registry
::getInstance()->add($extensionKey, $tableName, $fieldName);
2223 if ($result === FALSE) {
2224 $message = 't3lib_categoryRegistry: no category registered for table "%s". Double check if there is a TCA configured';
2225 t3lib_div
::devLog(sprintf($message, $tableName), 'Core', 2);
2228 // Makes sure to add more TCA to an existing structure
2229 if (isset($GLOBALS['TCA'][$tableName]['columns'])) {
2230 // Forges a new field, default name is "categories"
2231 $fieldConfiguration = array(
2233 'foreign_table' => 'sys_category',
2234 'foreign_table_where' => ' ORDER BY sys_category.title ASC',
2235 'MM' => 'sys_category_record_mm',
2236 'MM_opposite_field' => 'items',
2237 'MM_match_fields' => array('tablenames' => $tableName),
2239 'autoSizeMax' => 50,
2241 'renderMode' => 'tree',
2242 'treeConfig' => array(
2243 'parentField' => 'parent',
2244 'appearance' => array(
2245 'expandAll' => TRUE,
2246 'showHeader' => TRUE,
2255 'script' => 'wizard_edit.php',
2256 'icon' => 'edit2.gif',
2257 'popup_onlyOpenIfSelected' => 1,
2258 'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
2262 'title' => 'Create new',
2263 'icon' => 'add.gif',
2265 'table' => 'sys_category',
2266 'pid' => '###CURRENT_PID###',
2267 'setValue' => 'prepend'
2269 'script' => 'wizard_add.php',
2274 if (!empty($options['fieldConfiguration'])) {
2275 $fieldConfiguration = t3lib_div
::array_merge_recursive_overrule(
2276 $fieldConfiguration,
2277 $options['fieldConfiguration']
2282 $fieldName => array(
2284 'label' => 'LLL:EXT:lang/locallang_tca.xlf:sys_category.categories',
2285 'config' => $fieldConfiguration,
2289 // Adding fields to an existing table definition
2290 self
::addTCAcolumns($tableName, $columns);
2292 $fieldList = '--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category, ' . $fieldName;
2293 if (!empty($options['fieldList'])) {
2294 $fieldList = $options['fieldList'];
2298 if (!empty($options['typesList'])) {
2299 $typesList = $options['typesList'];
2303 if (!empty($options['position'])) {
2304 $position = $options['position'];
2307 // Makes the new "categories" field to be visible in TSFE.
2308 self
::addToAllTCAtypes($tableName, $fieldList, $typesList, $position);