[TASK] Release installation procedure from LocalConfiguration file
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Utility / ExtensionManagementUtility.php
1 <?php
2 namespace TYPO3\CMS\Core\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Extension Management functions
31 *
32 * This class is never instantiated, rather the methods inside is called as functions like
33 * \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('my_extension');
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 class ExtensionManagementUtility {
38
39 static protected $extensionKeyMap;
40
41 /**
42 * TRUE, if ext_tables file was read from cache for this script run.
43 * The frontend tends to do that multiple times, but the caching framework does
44 * not allow this (via a require_once call). This variable is used to track
45 * the access to the cache file to read the single ext_tables.php if it was
46 * already read from cache
47 *
48 * @TODO : See if we can get rid of the 'load multiple times' scenario in fe
49 * @var boolean
50 */
51 static protected $extTablesWasReadFromCacheOnce = FALSE;
52
53 /**************************************
54 *
55 * PATHS and other evaluation
56 *
57 ***************************************/
58 /**
59 * Returns TRUE if the extension with extension key $key is loaded.
60 *
61 * @param string $key Extension key to test
62 * @param boolean $exitOnError If $exitOnError is TRUE and the extension is not loaded the function will die with an error message
63 * @return boolean
64 * @throws \BadFunctionCallException
65 */
66 static public function isLoaded($key, $exitOnError = FALSE) {
67 $isLoaded = in_array($key, static::getLoadedExtensionListArray());
68 if ($exitOnError && !$isLoaded) {
69 throw new \BadFunctionCallException('TYPO3 Fatal Error: Extension "' . $key . '" is not loaded!', 1270853910);
70 }
71 return $isLoaded;
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 *
79 * @param $key string Extension key
80 * @param $script string $script is appended to the output if set.
81 * @throws \BadFunctionCallException
82 * @return string
83 */
84 static public function extPath($key, $script = '') {
85 if (isset($GLOBALS['TYPO3_LOADED_EXT'])) {
86 if (!isset($GLOBALS['TYPO3_LOADED_EXT'][$key])) {
87 throw new \BadFunctionCallException('TYPO3 Fatal Error: Extension key "' . $key . '" is NOT loaded!', 1270853878);
88 }
89 $extensionPath = PATH_site . $GLOBALS['TYPO3_LOADED_EXT'][$key]['siteRelPath'];
90 } else {
91 $loadedExtensions = array_flip(static::getLoadedExtensionListArray());
92 if (!isset($loadedExtensions[$key])) {
93 throw new \BadFunctionCallException('TYPO3 Fatal Error: Extension key "' . $key . '" is NOT loaded!', 1294430950);
94 }
95 if (@is_dir((PATH_typo3conf . 'ext/' . $key . '/'))) {
96 $extensionPath = PATH_typo3conf . 'ext/' . $key . '/';
97 } elseif (@is_dir((PATH_typo3 . 'ext/' . $key . '/'))) {
98 $extensionPath = PATH_typo3 . 'ext/' . $key . '/';
99 } elseif (@is_dir((PATH_typo3 . 'sysext/' . $key . '/'))) {
100 $extensionPath = PATH_typo3 . 'sysext/' . $key . '/';
101 } else {
102 throw new \BadFunctionCallException('TYPO3 Fatal Error: Extension "' . $key . '" NOT found!', 1294430951);
103 }
104 }
105 return $extensionPath . $script;
106 }
107
108 /**
109 * Returns the relative path to the extension as measured from from the TYPO3_mainDir
110 * If the extension is not loaded the function will die with an error message
111 * Useful for images and links from backend
112 *
113 * @param string $key Extension key
114 * @return string
115 */
116 static public function extRelPath($key) {
117 if (!isset($GLOBALS['TYPO3_LOADED_EXT'][$key])) {
118 throw new \BadFunctionCallException('TYPO3 Fatal Error: Extension key "' . $key . '" is NOT loaded!', 1270853879);
119 }
120 return $GLOBALS['TYPO3_LOADED_EXT'][$key]['typo3RelPath'];
121 }
122
123 /**
124 * Returns the relative path to the extension as measured from the PATH_site (frontend)
125 * If the extension is not loaded the function will die with an error message
126 * Useful for images and links from the frontend
127 *
128 * @param string $key Extension key
129 * @return string
130 */
131 static public function siteRelPath($key) {
132 return substr(self::extPath($key), strlen(PATH_site));
133 }
134
135 /**
136 * Returns the correct class name prefix for the extension key $key
137 *
138 * @param string $key Extension key
139 * @return string
140 * @internal
141 */
142 static public function getCN($key) {
143 return substr($key, 0, 5) == 'user_' ? 'user_' . str_replace('_', '', substr($key, 5)) : 'tx_' . str_replace('_', '', $key);
144 }
145
146 /**
147 * Returns the real extension key like 'tt_news' from an extension prefix like 'tx_ttnews'.
148 *
149 * @param string $prefix The extension prefix (e.g. 'tx_ttnews')
150 * @return mixed Real extension key (string) or FALSE (boolean) if something went wrong
151 */
152 static public function getExtensionKeyByPrefix($prefix) {
153 $result = FALSE;
154 // Build map of short keys referencing to real keys:
155 if (!isset(self::$extensionKeyMap)) {
156 self::$extensionKeyMap = array();
157 foreach (array_keys($GLOBALS['TYPO3_LOADED_EXT']) as $extensionKey) {
158 $shortKey = str_replace('_', '', $extensionKey);
159 self::$extensionKeyMap[$shortKey] = $extensionKey;
160 }
161 }
162 // Lookup by the given short key:
163 $parts = explode('_', $prefix);
164 if (isset(self::$extensionKeyMap[$parts[1]])) {
165 $result = self::$extensionKeyMap[$parts[1]];
166 }
167 return $result;
168 }
169
170 /**
171 * Clears the extension key map.
172 *
173 * @return void
174 */
175 static public function clearExtensionKeyMap() {
176 self::$extensionKeyMap = NULL;
177 }
178
179 /**
180 * Retrieves the version of an installed extension.
181 * If the extension is not installed, this function returns an empty string.
182 *
183 * @param string $key The key of the extension to look up, must not be empty
184 * @return string The extension version as a string in the format "x.y.z",
185 */
186 static public function getExtensionVersion($key) {
187 if (!is_string($key) || empty($key)) {
188 throw new \InvalidArgumentException('Extension key must be a non-empty string.', 1294586096);
189 }
190 if (!static::isLoaded($key)) {
191 return '';
192 }
193 $runtimeCache = $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
194 $cacheIdentifier = 'extMgmExtVersion-' . $key;
195 if (!($extensionVersion = $runtimeCache->get($cacheIdentifier))) {
196 $EM_CONF = array();
197 $_EXTKEY = $key;
198 include self::extPath($key) . 'ext_emconf.php';
199 $extensionVersion = $EM_CONF[$key]['version'];
200 $runtimeCache->set($cacheIdentifier, $extensionVersion);
201 }
202 return $extensionVersion;
203 }
204
205 /**************************************
206 *
207 * Adding BACKEND features
208 * (related to core features)
209 *
210 ***************************************/
211 /**
212 * Adding fields to an existing table definition in $GLOBALS['TCA']
213 * Adds an array with $GLOBALS['TCA'] column-configuration to the $GLOBALS['TCA']-entry for that table.
214 * 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!
215 * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
216 * FOR USE IN ext_tables.php FILES
217 *
218 * @param string $table The table name of a table already present in $GLOBALS['TCA'] with a columns section
219 * @param array $columnArray The array with the additional columns (typical some fields an extension wants to add)
220 * @param boolean $addTofeInterface If $addTofeInterface is TRUE the list of fields are also added to the fe_admin_fieldList.
221 * @return void
222 */
223 static public function addTCAcolumns($table, $columnArray, $addTofeInterface = 0) {
224 if (is_array($columnArray) && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'])) {
225 // Candidate for \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge() if integer-keys will some day make trouble...
226 $GLOBALS['TCA'][$table]['columns'] = array_merge($GLOBALS['TCA'][$table]['columns'], $columnArray);
227 if ($addTofeInterface) {
228 $GLOBALS['TCA'][$table]['feInterface']['fe_admin_fieldList'] .= ',' . implode(',', array_keys($columnArray));
229 }
230 }
231 }
232
233 /**
234 * Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
235 *
236 * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
237 * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
238 * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
239 * FOR USE IN ext_tables.php FILES
240 *
241 * @param string $table Table name
242 * @param string $str Field list to add.
243 * @param string $specificTypesList List of specific types to add the field list to. (If empty, all type entries are affected)
244 * @param string $position Insert fields before (default) or after one
245 * @return void
246 */
247 static public function addToAllTCAtypes($table, $str, $specificTypesList = '', $position = '') {
248 $str = trim($str);
249 $palettesChanged = array();
250 if ($str && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['types'])) {
251 foreach ($GLOBALS['TCA'][$table]['types'] as $type => &$typeDetails) {
252 if ($specificTypesList === '' || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($specificTypesList, $type)) {
253 $fieldExists = FALSE;
254 if ($position != '' && is_array($GLOBALS['TCA'][$table]['palettes'])) {
255 $positionArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $position);
256 if ($positionArray[0] == 'replace') {
257 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
258 if (preg_match('/\\b' . $palette . '\\b/', $typeDetails['showitem']) > 0 && preg_match('/\\b' . $positionArray[1] . '\\b/', $paletteDetails['showitem']) > 0) {
259 self::addFieldsToPalette($table, $palette, $str, $position);
260 // Save that palette in case other types use it
261 $palettesChanged[] = $palette;
262 $fieldExists = TRUE;
263 } elseif (in_array($palette, $palettesChanged)) {
264 $fieldExists = TRUE;
265 }
266 }
267 } else {
268 if (strpos($typeDetails['showitem'], $str) !== FALSE) {
269 $fieldExists = TRUE;
270 } else {
271 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
272 if (preg_match('/\\b' . $palette . '\\b/', $typeDetails['showitem']) > 0 && preg_match('/\\b' . $positionArray[1] . '\\b/', $paletteDetails['showitem']) > 0) {
273 $position = $positionArray[0] . ':--palette--;;' . $palette;
274 }
275 }
276 }
277 }
278 } else {
279 if (strpos($typeDetails['showitem'], $str) !== FALSE) {
280 $fieldExists = TRUE;
281 } elseif (is_array($GLOBALS['TCA'][$table]['palettes'])) {
282 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
283 if (preg_match('/\\b' . $palette . '\\b/', $typeDetails['showitem']) > 0 && strpos($paletteDetails['showitem'], $str) !== FALSE) {
284 $fieldExists = TRUE;
285 }
286 }
287 }
288 }
289 if ($fieldExists === FALSE) {
290 $typeDetails['showitem'] = self::executePositionedStringInsertion($typeDetails['showitem'], $str, $position);
291 }
292 }
293 }
294 unset($typeDetails);
295 }
296 }
297
298 /**
299 * Adds new fields to all palettes of an existing field.
300 * If the field does not have a palette yet, it's created automatically and
301 * gets called "generatedFor-$field".
302 *
303 * @param string $table Name of the table
304 * @param string $field Name of the field that has the palette to be extended
305 * @param string $addFields List of fields to be added to the palette
306 * @param string $insertionPosition Insert fields before (default) or after one
307 * @return void
308 */
309 static public function addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
310 $generatedPalette = '';
311 $processedPalettes = array();
312 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
313 $types = &$GLOBALS['TCA'][$table]['types'];
314 if (is_array($types)) {
315 // Iterate through all types and search for the field that defines the palette to be extended:
316 foreach (array_keys($types) as $type) {
317 $items = self::explodeItemList($types[$type]['showitem']);
318 if (isset($items[$field])) {
319 // If the field already has a palette, extend it:
320 if ($items[$field]['details']['palette']) {
321 $palette = $items[$field]['details']['palette'];
322 if (!isset($processedPalettes[$palette])) {
323 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
324 $processedPalettes[$palette] = TRUE;
325 }
326 } else {
327 if ($generatedPalette) {
328 $palette = $generatedPalette;
329 } else {
330 $palette = ($generatedPalette = 'generatedFor-' . $field);
331 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
332 }
333 $items[$field]['details']['palette'] = $palette;
334 $types[$type]['showitem'] = self::generateItemList($items);
335 }
336 }
337 }
338 }
339 }
340 }
341
342 /**
343 * Adds new fields to a palette.
344 * If the palette does not exist yet, it's created automatically.
345 *
346 * @param string $table Name of the table
347 * @param string $palette Name of the palette to be extended
348 * @param string $addFields List of fields to be added to the palette
349 * @param string $insertionPosition Insert fields before (default) or after one
350 * @return void
351 */
352 static public function addFieldsToPalette($table, $palette, $addFields, $insertionPosition = '') {
353 if (isset($GLOBALS['TCA'][$table])) {
354 $paletteData = &$GLOBALS['TCA'][$table]['palettes'][$palette];
355 // If palette already exists, merge the data:
356 if (is_array($paletteData)) {
357 $paletteData['showitem'] = self::executePositionedStringInsertion($paletteData['showitem'], $addFields, $insertionPosition);
358 } else {
359 $paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields);
360 }
361 }
362 }
363
364 /**
365 * Add an item to a select field item list.
366 *
367 * Warning: Do not use this method for radio or check types, especially not
368 * with $relativeToField and $relativePosition parameters. This would shift
369 * existing database data 'off by one'.
370 *
371 * As an example, this can be used to add an item to tt_content CType select
372 * drop-down after the existing 'mailform' field with these parameters:
373 * - $table = 'tt_content'
374 * - $field = 'CType'
375 * - $item = array(
376 * 'LLL:EXT:cms/locallang_ttc.xml:CType.I.10',
377 * 'login',
378 * 'i/tt_content_login.gif',
379 * ),
380 * - $relativeToField = mailform
381 * - $relativePosition = after
382 *
383 * @throws \InvalidArgumentException If given parameters are not of correct
384 * @throws \RuntimeException If reference to related position fields can not
385 * @param string $table Name of TCA table
386 * @param string $field Name of TCA field
387 * @param array $item New item to add
388 * @param string $relativeToField Add item relative to existing field
389 * @param string $relativePosition Valid keywords: 'before', 'after'
390 * @return void
391 */
392 static public function addTcaSelectItem($table, $field, array $item, $relativeToField = '', $relativePosition = '') {
393 if (!is_string($table)) {
394 throw new \InvalidArgumentException('Given table is of type "' . gettype($table) . '" but a string is expected.', 1303236963);
395 }
396 if (!is_string($field)) {
397 throw new \InvalidArgumentException('Given field is of type "' . gettype($field) . '" but a string is expected.', 1303236964);
398 }
399 if (!is_string($relativeToField)) {
400 throw new \InvalidArgumentException('Given relative field is of type "' . gettype($relativeToField) . '" but a string is expected.', 1303236965);
401 }
402 if (!is_string($relativePosition)) {
403 throw new \InvalidArgumentException('Given relative position is of type "' . gettype($relativePosition) . '" but a string is expected.', 1303236966);
404 }
405 if ($relativePosition !== '' && $relativePosition !== 'before' && $relativePosition !== 'after' && $relativePosition !== 'replace') {
406 throw new \InvalidArgumentException('Relative position must be either empty or one of "before", "after", "replace".', 1303236967);
407 }
408 if (!is_array($GLOBALS['TCA'][$table]['columns'][$field]['config']['items'])) {
409 throw new \RuntimeException('Given select field item list was not found.', 1303237468);
410 }
411 // Make sure item keys are integers
412 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'] = array_values($GLOBALS['TCA'][$table]['columns'][$field]['config']['items']);
413 if (strlen($relativePosition) > 0) {
414 // Insert at specified position
415 $matchedPosition = \TYPO3\CMS\Core\Utility\ArrayUtility::filterByValueRecursive($relativeToField, $GLOBALS['TCA'][$table]['columns'][$field]['config']['items']);
416 if (count($matchedPosition) > 0) {
417 $relativeItemKey = key($matchedPosition);
418 if ($relativePosition === 'replace') {
419 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][$relativeItemKey] = $item;
420 } else {
421 if ($relativePosition === 'before') {
422 $offset = $relativeItemKey;
423 } else {
424 $offset = $relativeItemKey + 1;
425 }
426 array_splice($GLOBALS['TCA'][$table]['columns'][$field]['config']['items'], $offset, 0, array(0 => $item));
427 }
428 } else {
429 // Insert at new item at the end of the array if relative position was not found
430 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][] = $item;
431 }
432 } else {
433 // Insert at new item at the end of the array
434 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][] = $item;
435 }
436 }
437
438 /**
439 * Gets the TCA configuration for a field handling (FAL) files.
440 *
441 * @param string $fieldName Name of the field to be used
442 * @param array $customSettingOverride Custom field settings overriding the basics
443 * @param string $allowedFileExtensions Comma list of allowed file extensions (e.g. "jpg,gif,pdf")
444 * @return array
445 */
446 static public function getFileFieldTCAConfig($fieldName, array $customSettingOverride = array(), $allowedFileExtensions = '', $disallowedFileExtensions = '') {
447 $fileFieldTCAConfig = array(
448 'type' => 'inline',
449 'foreign_table' => 'sys_file_reference',
450 'foreign_field' => 'uid_foreign',
451 'foreign_sortby' => 'sorting_foreign',
452 'foreign_table_field' => 'tablenames',
453 'foreign_match_fields' => array(
454 'fieldname' => $fieldName
455 ),
456 'foreign_label' => 'uid_local',
457 'foreign_selector' => 'uid_local',
458 'foreign_selector_fieldTcaOverride' => array(
459 'config' => array(
460 'appearance' => array(
461 'elementBrowserType' => 'file',
462 'elementBrowserAllowed' => $allowedFileExtensions
463 )
464 )
465 ),
466 'filter' => array(
467 array(
468 'userFunc' => 'TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter->filterInlineChildren',
469 'parameters' => array(
470 'allowedFileExtensions' => $allowedFileExtensions,
471 'disallowedFileExtensions' => $disallowedFileExtensions
472 )
473 )
474 ),
475 'appearance' => array(
476 'useSortable' => TRUE,
477 'headerThumbnail' => array(
478 'field' => 'uid_local',
479 'width' => '64',
480 'height' => '64',
481 ),
482 'showPossibleLocalizationRecords' => TRUE,
483 'showRemovedLocalizationRecords' => TRUE,
484 'showSynchronizationLink' => TRUE,
485
486 'enabledControls' => array(
487 'info' => FALSE,
488 'new' => FALSE,
489 'dragdrop' => TRUE,
490 'sort' => FALSE,
491 'hide' => TRUE,
492 'delete' => TRUE,
493 'localize' => TRUE,
494 ),
495 ),
496 'behaviour' => array(
497 'localizationMode' => 'select',
498 'localizeChildrenAtParentLocalization' => TRUE,
499 ),
500 );
501 return \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($fileFieldTCAConfig, $customSettingOverride);
502 }
503
504 /**
505 * Adds a list of new fields to the TYPO3 USER SETTINGS configuration "showitem" list, the array with
506 * the new fields itself needs to be added additionally to show up in the user setup, like
507 * $GLOBALS['TYPO3_USER_SETTINGS']['columns'] += $tempColumns
508 *
509 * @param string $addFields List of fields to be added to the user settings
510 * @param string $insertionPosition Insert fields before (default) or after one
511 * @return void
512 */
513 static public function addFieldsToUserSettings($addFields, $insertionPosition = '') {
514 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'] = self::executePositionedStringInsertion($GLOBALS['TYPO3_USER_SETTINGS']['showitem'], $addFields, $insertionPosition);
515 }
516
517 /**
518 * Inserts as list of data into an existing list.
519 * The insertion position can be defined accordant before of after existing list items.
520 *
521 * @param string $list The list of items to be extended
522 * @param string $insertionList The list of items to inserted
523 * @param string $insertionPosition Insert fields before (default) or after one
524 * @return string The extended list
525 */
526 static protected function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
527 $list = trim($list);
528 $insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
529 if ($insertionList) {
530 // Append data to the end (default):
531 if ($insertionPosition === '') {
532 $list .= ($list ? ', ' : '') . $insertionList;
533 } else {
534 $positions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $insertionPosition, TRUE);
535 $items = self::explodeItemList($list);
536 $isInserted = FALSE;
537 // Iterate through all fields an check whether it's possible to inserte there:
538 foreach ($items as $item => &$itemDetails) {
539 $needles = self::getInsertionNeedles($item, $itemDetails['details']);
540 // Insert data before:
541 foreach ($needles['before'] as $needle) {
542 if (in_array($needle, $positions)) {
543 $itemDetails['rawData'] = $insertionList . ', ' . $itemDetails['rawData'];
544 $isInserted = TRUE;
545 break;
546 }
547 }
548 // Insert data after:
549 foreach ($needles['after'] as $needle) {
550 if (in_array($needle, $positions)) {
551 $itemDetails['rawData'] .= ', ' . $insertionList;
552 $isInserted = TRUE;
553 break;
554 }
555 }
556 // Replace with data:
557 foreach ($needles['replace'] as $needle) {
558 if (in_array($needle, $positions)) {
559 $itemDetails['rawData'] = $insertionList;
560 $isInserted = TRUE;
561 break;
562 }
563 }
564 // Break if insertion was already done:
565 if ($isInserted) {
566 break;
567 }
568 }
569 // If insertion point could not be determined, append the data:
570 if (!$isInserted) {
571 $list .= ($list ? ', ' : '') . $insertionList;
572 } else {
573 $list = self::generateItemList($items, TRUE);
574 }
575 }
576 }
577 return $list;
578 }
579
580 /**
581 * Compares an existing list of items and a list of items to be inserted
582 * and returns a duplicate-free variant of that insertion list.
583 *
584 * Example:
585 * + list: 'field_a, field_b;;;;2-2-2, field_c;;;;3-3-3'
586 * + insertion: 'field_b, field_d, field_c;;;4-4-4'
587 * -> new insertion: 'field_d'
588 *
589 * @param string $insertionList The list of items to inserted
590 * @param string $list The list of items to be extended (default: '')
591 * @return string Duplicate-free list of items to be inserted
592 */
593 static protected function removeDuplicatesForInsertion($insertionList, $list = '') {
594 $pattern = '/(^|,)\\s*\\b([^;,]+)\\b[^,]*/';
595 $listItems = array();
596 if ($list && preg_match_all($pattern, $list, $listMatches)) {
597 $listItems = $listMatches[2];
598 }
599 if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
600 $insertionItems = array();
601 $insertionDuplicates = FALSE;
602 foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) {
603 if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) {
604 $insertionItems[$insertionItem] = TRUE;
605 } else {
606 unset($insertionListMatches[0][$insertionIndex]);
607 $insertionDuplicates = TRUE;
608 }
609 }
610 if ($insertionDuplicates) {
611 $insertionList = implode('', $insertionListMatches[0]);
612 }
613 }
614 return $insertionList;
615 }
616
617 /**
618 * Generates search needles that are used for inserting fields/items into an existing list.
619 *
620 * @see executePositionedStringInsertion
621 * @param string $item The name of the field/item
622 * @param array $itemDetails Additional details of the field/item like e.g. palette information
623 * @return array The needled to be used for inserting content before or after existing fields/items
624 */
625 static protected function getInsertionNeedles($item, array $itemDetails) {
626 if (strstr($item, '--')) {
627 // 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.
628 $item = preg_replace('/[0-9]+$/', '', $item);
629 }
630 $needles = array(
631 'before' => array($item, 'before:' . $item),
632 'after' => array('after:' . $item),
633 'replace' => array('replace:' . $item)
634 );
635 if ($itemDetails['palette']) {
636 $palette = $item . ';;' . $itemDetails['palette'];
637 $needles['before'][] = $palette;
638 $needles['before'][] = 'before:' . $palette;
639 $needles['after'][] = 'after:' . $palette;
640 $needles['replace'][] = 'replace:' . $palette;
641 }
642 return $needles;
643 }
644
645 /**
646 * Generates an array of fields/items with additional information such as e.g. the name of the palette.
647 *
648 * @param string $itemList List of fields/items to be splitted up
649 * @return array An array with the names of the fields/items as keys and additional information
650 */
651 static protected function explodeItemList($itemList) {
652 $items = array();
653 $itemParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $itemList, TRUE);
654 foreach ($itemParts as $itemPart) {
655 $itemDetails = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';', $itemPart, FALSE, 5);
656 $key = $itemDetails[0];
657 if (strstr($key, '--')) {
658 // 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!
659 $key .= count($items);
660 }
661 if (!isset($items[$key])) {
662 $items[$key] = array(
663 'rawData' => $itemPart,
664 'details' => array(
665 'field' => $itemDetails[0],
666 'label' => $itemDetails[1],
667 'palette' => $itemDetails[2],
668 'special' => $itemDetails[3],
669 'styles' => $itemDetails[4]
670 )
671 );
672 }
673 }
674 return $items;
675 }
676
677 /**
678 * Generates a list of fields/items out of an array provided by the function getFieldsOfFieldList().
679 *
680 * @see explodeItemList
681 * @param array $items The array of fields/items with optional additional information
682 * @param boolean $useRawData Use raw data instead of building by using the details (default: FALSE)
683 * @return string The list of fields/items which gets used for $GLOBALS['TCA'][<table>]['types'][<type>]['showitem']
684 */
685 static protected function generateItemList(array $items, $useRawData = FALSE) {
686 $itemParts = array();
687 foreach ($items as $item => $itemDetails) {
688 if (strstr($item, '--')) {
689 // 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.
690 $item = preg_replace('/[0-9]+$/', '', $item);
691 }
692 if ($useRawData) {
693 $itemParts[] = $itemDetails['rawData'];
694 } else {
695 $itemParts[] = count($itemDetails['details']) > 1 ? implode(';', $itemDetails['details']) : $item;
696 }
697 }
698 return implode(', ', $itemParts);
699 }
700
701 /**
702 * Add tablename to default list of allowed tables on pages (in $PAGES_TYPES)
703 * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
704 * FOR USE IN ext_tables.php FILES
705 *
706 * @param string $table Table name
707 * @return void
708 */
709 static public function allowTableOnStandardPages($table) {
710 $GLOBALS['PAGES_TYPES']['default']['allowedTables'] .= ',' . $table;
711 }
712
713 /**
714 * Adds a ExtJS module (main or sub) to the backend interface
715 * FOR USE IN ext_tables.php FILES
716 *
717 * @static
718 * @param string $extensionName
719 * @param string $mainModuleName Is the main module key
720 * @param string $subModuleName Is the submodule key, if blank a plain main module is generated
721 * @param string $position Passed to \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule, see reference there
722 * @param array $moduleConfiguration Icon with array keys: access, icon, labels to configure the module
723 * @throws \InvalidArgumentException
724 */
725 static public function addExtJSModule($extensionName, $mainModuleName, $subModuleName = '', $position = '', array $moduleConfiguration = array()) {
726 if (empty($extensionName)) {
727 throw new \InvalidArgumentException('The extension name must not be empty', 1325938973);
728 }
729 $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName);
730 $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
731 $defaultModuleConfiguration = array(
732 'access' => 'admin',
733 'icon' => 'gfx/typo3.png',
734 'labels' => '',
735 'extRelPath' => self::extRelPath($extensionKey) . 'Classes/'
736 );
737 // Add mandatory parameter to use new pagetree
738 if ($mainModuleName === 'web') {
739 $defaultModuleConfiguration['navigationComponentId'] = 'typo3-pagetree';
740 }
741 $moduleConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($defaultModuleConfiguration, $moduleConfiguration);
742 if (strlen($subModuleName) > 0) {
743 $moduleSignature = $mainModuleName . '_' . $subModuleName;
744 } else {
745 $moduleSignature = $mainModuleName;
746 }
747 $moduleConfiguration['name'] = $moduleSignature;
748 $moduleConfiguration['script'] = 'extjspaneldummy.html';
749 $moduleConfiguration['extensionName'] = $extensionName;
750 $moduleConfiguration['configureModuleFunction'] = array('TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility', 'configureModule');
751 $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature] = $moduleConfiguration;
752 self::addModule($mainModuleName, $subModuleName, $position);
753 }
754
755 /**
756 * This method is called from t3lib_loadModules::checkMod and it replaces old conf.php.
757 *
758 * The original function for is called
759 * Tx_Extbase_Utility_Extension::configureModule, the refered function can
760 * be deprecated now
761 *
762 * @param string $moduleSignature The module name
763 * @param string $modulePath Absolute path to module (not used by Extbase currently)
764 * @return array Configuration of the module
765 */
766 static public function configureModule($moduleSignature, $modulePath) {
767 $moduleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature];
768 $iconPathAndFilename = $moduleConfiguration['icon'];
769 if (substr($iconPathAndFilename, 0, 4) === 'EXT:') {
770 list($extensionKey, $relativePath) = explode('/', substr($iconPathAndFilename, 4), 2);
771 $iconPathAndFilename = self::extPath($extensionKey) . $relativePath;
772 }
773 // TODO: skin support
774 $moduleLabels = array(
775 'tabs_images' => array(
776 'tab' => $iconPathAndFilename
777 ),
778 'labels' => array(
779 'tablabel' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_labels_tablabel'),
780 'tabdescr' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_labels_tabdescr')
781 ),
782 'tabs' => array(
783 'tab' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_tabs_tab')
784 )
785 );
786 $GLOBALS['LANG']->addModuleLabels($moduleLabels, $moduleSignature . '_');
787 return $moduleConfiguration;
788 }
789
790 /**
791 * Adds a module (main or sub) to the backend interface
792 * FOR USE IN ext_tables.php FILES
793 *
794 * @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.
795 * @param string $sub The submodule key. If $sub is not set a blank $main module is created.
796 * @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.
797 * @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.
798 * @return void
799 */
800 static public function addModule($main, $sub = '', $position = '', $path = '') {
801 if (isset($GLOBALS['TBE_MODULES'][$main]) && $sub) {
802 // If there is already a main module by this name:
803 // Adding the submodule to the correct position:
804 list($place, $modRef) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $position, 1);
805 $mods = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TBE_MODULES'][$main], 1);
806 if (!in_array($sub, $mods)) {
807 switch (strtolower($place)) {
808 case 'after':
809
810 case 'before':
811 $pointer = 0;
812 $found = FALSE;
813 foreach ($mods as $k => $m) {
814 if (!strcmp($m, $modRef)) {
815 $pointer = strtolower($place) == 'after' ? $k + 1 : $k;
816 $found = TRUE;
817 }
818 }
819 if ($found) {
820 array_splice($mods, $pointer, 0, $sub);
821 } else {
822 // If requested module is not found: Add at the end
823 array_push($mods, $sub);
824 }
825 break;
826 default:
827 if (strtolower($place) == 'top') {
828 array_unshift($mods, $sub);
829 } else {
830 array_push($mods, $sub);
831 }
832 break;
833 }
834 }
835 // Re-inserting the submodule list:
836 $GLOBALS['TBE_MODULES'][$main] = implode(',', $mods);
837 } else {
838 // Create new main modules with only one submodule, $sub (or none if $sub is blank)
839 $GLOBALS['TBE_MODULES'][$main] = $sub;
840 }
841 // Adding path:
842 if ($path) {
843 $GLOBALS['TBE_MODULES']['_PATHS'][$main . ($sub ? '_' . $sub : '')] = $path;
844 }
845 }
846
847 /**
848 * Registers an Ext.Direct component with access restrictions.
849 *
850 * @param string $endpointName
851 * @param string $callbackClass
852 * @param string $moduleName Optional: must be <mainmodule> or <mainmodule>_<submodule>
853 * @param string $accessLevel Optional: can be 'admin' or 'user,group'
854 * @return void
855 */
856 static public function registerExtDirectComponent($endpointName, $callbackClass, $moduleName = NULL, $accessLevel = NULL) {
857 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'][$endpointName] = array(
858 'callbackClass' => $callbackClass,
859 'moduleName' => $moduleName,
860 'accessLevel' => $accessLevel
861 );
862 }
863
864 /**
865 * Adds a module path to $GLOBALS['TBE_MODULES'] for used with the module dispatcher, mod.php
866 * Used only for modules that are not placed in the main/sub menu hierarchy by the traditional mechanism of addModule()
867 * Examples for this is context menu functionality (like import/export) which runs as an independent module through mod.php
868 * FOR USE IN ext_tables.php FILES
869 * Example: \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModulePath('xMOD_tximpexp', \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY).'app/');
870 *
871 * @param string $name The name of the module, refer to conf.php of the module.
872 * @param string $path The absolute path to the module directory inside of which "index.php" and "conf.php" is found.
873 * @return void
874 */
875 static public function addModulePath($name, $path) {
876 $GLOBALS['TBE_MODULES']['_PATHS'][$name] = $path;
877 }
878
879 /**
880 * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
881 * The arguments values are generally determined by which function menu this is supposed to interact with
882 * See Inside TYPO3 for information on how to use this function.
883 * FOR USE IN ext_tables.php FILES
884 *
885 * @param string $modname Module name
886 * @param string $className Class name
887 * @param string $classPath Class path
888 * @param string $title Title of module
889 * @param string $MM_key Menu array key - default is "function
890 * @param string $WS Workspace conditions. Blank means all workspaces, any other string can be a comma list of "online", "offline" and "custom
891 * @return void
892 * @see t3lib_SCbase::mergeExternalItems()
893 */
894 static public function insertModuleFunction($modname, $className, $classPath, $title, $MM_key = 'function', $WS = '') {
895 $GLOBALS['TBE_MODULES_EXT'][$modname]['MOD_MENU'][$MM_key][$className] = array(
896 'name' => $className,
897 'path' => $classPath,
898 'title' => $title,
899 'ws' => $WS
900 );
901 }
902
903 /**
904 * Adds some more content to a key of TYPO3_CONF_VARS array.
905 *
906 * This also tracks which content was added by extensions (in TYPO3_CONF_VARS_extensionAdded)
907 * so that they cannot be editted again through the Install Tool.
908 *
909 * @static
910 * @param string $group The group ('FE', 'BE', 'SYS' ...)
911 * @param string $key The key of this setting within the group
912 * @param string $content The text to add (include leading "\n" in case of multi-line entries)
913 * @return void
914 */
915 static public function appendToTypoConfVars($group, $key, $content) {
916 $GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$group][$key] .= $content;
917 $GLOBALS['TYPO3_CONF_VARS'][$group][$key] .= $content;
918 }
919
920 /**
921 * Adds $content to the default Page TSconfig as set in $GLOBALS['TYPO3_CONF_VARS'][BE]['defaultPageTSconfig']
922 * Prefixed with a [GLOBAL] line
923 * FOR USE IN ext_tables.php/ext_localconf.php FILES
924 *
925 * @param string $content Page TSconfig content
926 * @return void
927 */
928 static public function addPageTSConfig($content) {
929 self::appendToTypoConfVars('BE', 'defaultPageTSconfig', '
930 [GLOBAL]
931 ' . $content);
932 }
933
934 /**
935 * Adds $content to the default User TSconfig as set in $GLOBALS['TYPO3_CONF_VARS'][BE]['defaultUserTSconfig']
936 * Prefixed with a [GLOBAL] line
937 * FOR USE IN ext_tables.php/ext_localconf.php FILES
938 *
939 * @param string $content User TSconfig content
940 * @return void
941 */
942 static public function addUserTSConfig($content) {
943 self::appendToTypoConfVars('BE', 'defaultUserTSconfig', '
944 [GLOBAL]
945 ' . $content);
946 }
947
948 /**
949 * Adds a reference to a locallang file with $GLOBALS['TCA_DESCR'] labels
950 * FOR USE IN ext_tables.php FILES
951 * eg. \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('pages', 'EXT:lang/locallang_csh_pages.xml'); for the pages table or \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('_MOD_web_layout', 'EXT:cms/locallang_csh_weblayout.php'); for the Web > Page module.
952 *
953 * @param string $tca_descr_key Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
954 * @param string $file_ref File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
955 * @return void
956 */
957 static public function addLLrefForTCAdescr($tca_descr_key, $file_ref) {
958 if ($tca_descr_key) {
959 if (!is_array($GLOBALS['TCA_DESCR'][$tca_descr_key])) {
960 $GLOBALS['TCA_DESCR'][$tca_descr_key] = array();
961 }
962 if (!is_array($GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'])) {
963 $GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'] = array();
964 }
965 $GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'][] = $file_ref;
966 }
967 }
968
969 /**
970 * Registers a navigation component
971 *
972 * @param string $module
973 * @param string $componentId
974 * @return void
975 */
976 static public function addNavigationComponent($module, $componentId) {
977 $GLOBALS['TBE_MODULES']['_navigationComponents'][$module] = array(
978 'componentId' => $componentId,
979 'extKey' => $GLOBALS['_EXTKEY'],
980 'isCoreComponent' => FALSE
981 );
982 }
983
984 /**
985 * Registers a core navigation component
986 *
987 * @param string $module
988 * @param string $componentId
989 * @return void
990 */
991 static public function addCoreNavigationComponent($module, $componentId) {
992 self::addNavigationComponent($module, $componentId);
993 $GLOBALS['TBE_MODULES']['_navigationComponents'][$module]['isCoreComponent'] = TRUE;
994 }
995
996 /**************************************
997 *
998 * Adding SERVICES features
999 *
1000 ***************************************/
1001 /**
1002 * Adds a service to the global services array
1003 *
1004 * @param string $extKey Extension key
1005 * @param string $serviceType Service type, must not be prefixed "tx_" or "Tx_
1006 * @param string $serviceKey Service key, must be prefixed "tx_", "Tx_" or "user_
1007 * @param array $info Service description array
1008 * @return void
1009 */
1010 static public function addService($extKey, $serviceType, $serviceKey, $info) {
1011 if ($serviceType && is_array($info)) {
1012 $info['priority'] = max(0, min(100, $info['priority']));
1013 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey] = $info;
1014 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['extKey'] = $extKey;
1015 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
1016 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceType'] = $serviceType;
1017 // Change the priority (and other values) from $GLOBALS['TYPO3_CONF_VARS']
1018 // $GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey]['priority']
1019 // even the activation is possible (a unix service might be possible on windows for some reasons)
1020 if (is_array($GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey])) {
1021 // No check is done here - there might be configuration values only the service type knows about, so
1022 // we pass everything
1023 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey] = array_merge($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey], $GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey]);
1024 }
1025 // OS check
1026 // Empty $os means 'not limited to one OS', therefore a check is not needed
1027 if ($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['available'] && $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['os'] != '') {
1028 // TYPO3_OS is not yet defined
1029 $os_type = stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin') ? 'WIN' : 'UNIX';
1030 $os = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', strtoupper($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['os']));
1031 if (!in_array($os_type, $os)) {
1032 self::deactivateService($serviceType, $serviceKey);
1033 }
1034 }
1035 // Convert subtype list to array for quicker access
1036 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceSubTypes'] = array();
1037 $serviceSubTypes = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $info['subtype']);
1038 foreach ($serviceSubTypes as $subtype) {
1039 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
1040 }
1041 }
1042 }
1043
1044 /**
1045 * Find the available service with highest priority
1046 *
1047 * @param string $serviceType Service type
1048 * @param string $serviceSubType Service sub type
1049 * @param mixed $excludeServiceKeys Service keys that should be excluded in the search for a service. Array or comma list.
1050 * @return mixed Service info array if a service was found, FALSE otherwise
1051 */
1052 static public function findService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) {
1053 $serviceKey = FALSE;
1054 $serviceInfo = FALSE;
1055 $priority = 0;
1056 $quality = 0;
1057 if (!is_array($excludeServiceKeys)) {
1058 $excludeServiceKeys = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $excludeServiceKeys, 1);
1059 }
1060 if (is_array($GLOBALS['T3_SERVICES'][$serviceType])) {
1061 foreach ($GLOBALS['T3_SERVICES'][$serviceType] as $key => $info) {
1062 if (in_array($key, $excludeServiceKeys)) {
1063 continue;
1064 }
1065 // Select a subtype randomly
1066 // Useful to start a service by service key without knowing his subtypes - for testing purposes
1067 if ($serviceSubType == '*') {
1068 $serviceSubType = key($info['serviceSubTypes']);
1069 }
1070 // This matches empty subtype too
1071 if ($info['available'] && ($info['subtype'] == $serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority'] >= $priority) {
1072 // Has a lower quality than the already found, therefore we skip this service
1073 if ($info['priority'] == $priority && $info['quality'] < $quality) {
1074 continue;
1075 }
1076 // Check if the service is available
1077 $info['available'] = self::isServiceAvailable($serviceType, $key, $info);
1078 // Still available after exec check?
1079 if ($info['available']) {
1080 $serviceKey = $key;
1081 $priority = $info['priority'];
1082 $quality = $info['quality'];
1083 }
1084 }
1085 }
1086 }
1087 if ($serviceKey) {
1088 $serviceInfo = $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey];
1089 }
1090 return $serviceInfo;
1091 }
1092
1093 /**
1094 * Find a specific service identified by its key
1095 * Note that this completely bypasses the notions of priority and quality
1096 *
1097 * @param string $serviceKey Service key
1098 * @return array Service info array if a service was found
1099 * @throws \TYPO3\CMS\Core\Exception
1100 */
1101 static public function findServiceByKey($serviceKey) {
1102 if (is_array($GLOBALS['T3_SERVICES'])) {
1103 // Loop on all service types
1104 // NOTE: we don't care about the actual type, we are looking for a specific key
1105 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $servicesPerType) {
1106 if (isset($servicesPerType[$serviceKey])) {
1107 $serviceDetails = $servicesPerType[$serviceKey];
1108 // Test if service is available
1109 if (self::isServiceAvailable($serviceType, $serviceKey, $serviceDetails)) {
1110 // We have found the right service, return its information
1111 return $serviceDetails;
1112 }
1113 }
1114 }
1115 }
1116 throw new \TYPO3\CMS\Core\Exception('Service not found for key: ' . $serviceKey, 1319217244);
1117 }
1118
1119 /**
1120 * Check if a given service is available, based on the executable files it depends on
1121 *
1122 * @param string $serviceType Type of service
1123 * @param string $serviceKey Specific key of the service
1124 * @param array $serviceDetails Information about the service
1125 * @return boolean Service availability
1126 */
1127 static public function isServiceAvailable($serviceType, $serviceKey, $serviceDetails) {
1128 // If the service depends on external programs - check if they exists
1129 if (trim($serviceDetails['exec'])) {
1130 $executables = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $serviceDetails['exec'], 1);
1131 foreach ($executables as $executable) {
1132 // If at least one executable file is not available, exit early returning FALSE
1133 if (!\TYPO3\CMS\Core\Utility\CommandUtility::checkCommand($executable)) {
1134 self::deactivateService($serviceType, $serviceKey);
1135 return FALSE;
1136 }
1137 }
1138 }
1139 // The service is available
1140 return TRUE;
1141 }
1142
1143 /**
1144 * Deactivate a service
1145 *
1146 * @param string $serviceType Service type
1147 * @param string $serviceKey Service key
1148 * @return void
1149 */
1150 static public function deactivateService($serviceType, $serviceKey) {
1151 // ... maybe it's better to move non-available services to a different array??
1152 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['available'] = FALSE;
1153 }
1154
1155 /**************************************
1156 *
1157 * Adding FRONTEND features
1158 * (related specifically to "cms" extension)
1159 *
1160 ***************************************/
1161 /**
1162 * Adds an entry to the list of plugins in content elements of type "Insert plugin"
1163 * 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)
1164 * 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.
1165 * 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
1166 * FOR USE IN ext_tables.php FILES
1167 *
1168 * @param array $itemArray Item Array
1169 * @param string $type Type (eg. "list_type") - basically a field from "tt_content" table
1170 * @return void
1171 */
1172 static public function addPlugin($itemArray, $type = 'list_type') {
1173 $_EXTKEY = $GLOBALS['_EXTKEY'];
1174 if ($_EXTKEY && !$itemArray[2]) {
1175 $itemArray[2] = self::extRelPath($_EXTKEY) . $GLOBALS['TYPO3_LOADED_EXT'][$_EXTKEY]['ext_icon'];
1176 }
1177 if (is_array($GLOBALS['TCA']['tt_content']['columns']) && is_array($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'])) {
1178 foreach ($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'] as $k => $v) {
1179 if (!strcmp($v[1], $itemArray[1])) {
1180 $GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'][$k] = $itemArray;
1181 return;
1182 }
1183 }
1184 $GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'][] = $itemArray;
1185 }
1186 }
1187
1188 /**
1189 * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
1190 * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin or content element.
1191 *
1192 * @param string $piKeyToMatch Plugin key as used in the list_type field. Use the asterisk * to match all list_type values.
1193 * @param string $value Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
1194 * @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.
1195 * @return void
1196 * @see addPlugin()
1197 */
1198 static public function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch = 'list') {
1199 if (is_array($GLOBALS['TCA']['tt_content']['columns']) && is_array($GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds'])) {
1200 $GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch . ',' . $CTypeToMatch] = $value;
1201 }
1202 }
1203
1204 /**
1205 * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
1206 * By using $content_table and $content_field you can also use the function for other tables.
1207 * FOR USE IN ext_tables.php FILES
1208 *
1209 * @param string $table Table name to allow for "insert record
1210 * @param string $content_table Table name TO WHICH the $table name is applied. See $content_field as well.
1211 * @param string $content_field Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
1212 * @return void
1213 */
1214 static public function addToInsertRecords($table, $content_table = 'tt_content', $content_field = 'records') {
1215 if (is_array($GLOBALS['TCA'][$content_table]['columns']) && isset($GLOBALS['TCA'][$content_table]['columns'][$content_field]['config']['allowed'])) {
1216 $GLOBALS['TCA'][$content_table]['columns'][$content_field]['config']['allowed'] .= ',' . $table;
1217 }
1218 }
1219
1220 /**
1221 * Add PlugIn to Static Template #43
1222 *
1223 * 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.
1224 * 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"
1225 * $type determines the type of frontend plugin:
1226 * "list_type" (default) - the good old "Insert plugin" entry
1227 * "menu_type" - a "Menu/Sitemap" entry
1228 * "CType" - a new content element type
1229 * "header_layout" - an additional header type (added to the selection of layout1-5)
1230 * "includeLib" - just includes the library for manual use somewhere in TypoScript.
1231 * (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)
1232 * FOR USE IN ext_localconf.php FILES
1233 *
1234 * @param string $key The extension key
1235 * @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.
1236 * @param string $prefix Is used as a - yes, suffix - of the class name (fx. "_pi1")
1237 * @param string $type See description above
1238 * @param boolean $cached If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
1239 * @return void
1240 */
1241 static public function addPItoST43($key, $classFile = '', $prefix = '', $type = 'list_type', $cached = 0) {
1242 $classFile = $classFile ? $classFile : 'pi/class.tx_' . str_replace('_', '', $key) . $prefix . '.php';
1243 $cN = self::getCN($key);
1244 // General plugin
1245 $pluginContent = trim('
1246 plugin.' . $cN . $prefix . ' = USER' . ($cached ? '' : '_INT') . '
1247 plugin.' . $cN . $prefix . ' {
1248 includeLibs = ' . $GLOBALS['TYPO3_LOADED_EXT'][$key]['siteRelPath'] . $classFile . '
1249 userFunc = ' . $cN . $prefix . '->main
1250 }');
1251 self::addTypoScript($key, 'setup', '
1252 # Setting ' . $key . ' plugin TypoScript
1253 ' . $pluginContent);
1254 // After ST43
1255 switch ($type) {
1256 case 'list_type':
1257 $addLine = 'tt_content.list.20.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1258 break;
1259 case 'menu_type':
1260 $addLine = 'tt_content.menu.20.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1261 break;
1262 case 'CType':
1263 $addLine = trim('
1264 tt_content.' . $key . $prefix . ' = COA
1265 tt_content.' . $key . $prefix . ' {
1266 10 = < lib.stdheader
1267 20 = < plugin.' . $cN . $prefix . '
1268 }
1269 ');
1270 break;
1271 case 'header_layout':
1272 $addLine = 'lib.stdheader.10.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1273 break;
1274 case 'includeLib':
1275 $addLine = 'page.1000 = < plugin.' . $cN . $prefix;
1276 break;
1277 default:
1278 $addLine = '';
1279 break;
1280 }
1281 if ($addLine) {
1282 self::addTypoScript($key, 'setup', '
1283 # Setting ' . $key . ' plugin TypoScript
1284 ' . $addLine . '
1285 ', 43);
1286 }
1287 }
1288
1289 /**
1290 * Call this method to add an entry in the static template list found in sys_templates
1291 * FOR USE IN ext_localconf.php FILES
1292 *
1293 * @param string $extKey Is of course the extension key
1294 * @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/
1295 * @param string $title Is the title in the selector box.
1296 * @return void
1297 * @see addTypoScript()
1298 */
1299 static public function addStaticFile($extKey, $path, $title) {
1300 if ($extKey && $path && is_array($GLOBALS['TCA']['sys_template']['columns'])) {
1301 $value = str_replace(',', '', 'EXT:' . $extKey . '/' . $path);
1302 $itemArray = array(trim($title . ' (' . $extKey . ')'), $value);
1303 $GLOBALS['TCA']['sys_template']['columns']['include_static_file']['config']['items'][] = $itemArray;
1304 }
1305 }
1306
1307 /**
1308 * Adds $content to the default TypoScript setup code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_setup']
1309 * Prefixed with a [GLOBAL] line
1310 * FOR USE IN ext_localconf.php FILES
1311 *
1312 * @param string $content TypoScript Setup string
1313 * @return void
1314 */
1315 static public function addTypoScriptSetup($content) {
1316 self::appendToTypoConfVars('FE', 'defaultTypoScript_setup', '
1317 [GLOBAL]
1318 ' . $content);
1319 }
1320
1321 /**
1322 * Adds $content to the default TypoScript constants code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_constants']
1323 * Prefixed with a [GLOBAL] line
1324 * FOR USE IN ext_localconf.php FILES
1325 *
1326 * @param string $content TypoScript Constants string
1327 * @return void
1328 */
1329 static public function addTypoScriptConstants($content) {
1330 self::appendToTypoConfVars('FE', 'defaultTypoScript_constants', '
1331 [GLOBAL]
1332 ' . $content);
1333 }
1334
1335 /**
1336 * Adds $content to the default TypoScript code for either setup or constants as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_*']
1337 * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
1338 * FOR USE IN ext_localconf.php FILES
1339 *
1340 * @param string $key Is the extension key (informative only).
1341 * @param string $type Is either "setup" or "constants" and obviously determines which kind of TypoScript code we are adding.
1342 * @param string $content Is the TS content, prefixed with a [GLOBAL] line and a comment-header.
1343 * @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.
1344 * @return void
1345 */
1346 static public function addTypoScript($key, $type, $content, $afterStaticUid = 0) {
1347 if ($type == 'setup' || $type == 'constants') {
1348 $content = '
1349
1350 [GLOBAL]
1351 #############################################
1352 ## TypoScript added by extension "' . $key . '"
1353 #############################################
1354
1355 ' . $content;
1356 if ($afterStaticUid) {
1357 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type . '.'][$afterStaticUid] .= $content;
1358 // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
1359 if ($afterStaticUid == 43 && is_array($GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'])) {
1360 foreach ($GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'] as $templateName) {
1361 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type . '.'][$templateName] .= $content;
1362 }
1363 }
1364 } else {
1365 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type] .= $content;
1366 }
1367 }
1368 }
1369
1370 /***************************************
1371 *
1372 * Internal extension management methods
1373 *
1374 ***************************************/
1375 /**
1376 * Load the extension information array. This array is set as
1377 * $GLOBALS['TYPO3_LOADED_EXT'] in bootstrap. It contains basic information
1378 * about every loaded extension.
1379 *
1380 * This is an internal method. It is only used during bootstrap and
1381 * extensions should not use it!
1382 *
1383 * @param boolean $allowCaching If FALSE, the array will not be read / created from cache
1384 * @return array Result array that will be set as $GLOBALS['TYPO3_LOADED_EXT']
1385 * @access private
1386 * @see createTypo3LoadedExtensionInformationArray
1387 */
1388 static public function loadTypo3LoadedExtensionInformation($allowCaching = TRUE) {
1389 if ($allowCaching) {
1390 $cacheIdentifier = self::getTypo3LoadedExtensionInformationCacheIdentifier();
1391 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
1392 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1393 if ($codeCache->has($cacheIdentifier)) {
1394 $typo3LoadedExtensionArray = $codeCache->requireOnce($cacheIdentifier);
1395 } else {
1396 $typo3LoadedExtensionArray = self::createTypo3LoadedExtensionInformationArray();
1397 $codeCache->set($cacheIdentifier, 'return ' . var_export($typo3LoadedExtensionArray, TRUE) . ';');
1398 }
1399 } else {
1400 $typo3LoadedExtensionArray = self::createTypo3LoadedExtensionInformationArray();
1401 }
1402 return $typo3LoadedExtensionArray;
1403 }
1404
1405 /**
1406 * Set up array with basic information about loaded extension:
1407 *
1408 * array(
1409 * 'extensionKey' => array(
1410 * 'type' => Either S, L or G, inidicating if the extension is a system, a local or a global extension
1411 * 'siteRelPath' => Relative path to the extension from document root
1412 * 'typo3RelPath' => Relative path to extension from typo3/ subdirectory
1413 * 'ext_localconf.php' => Absolute path to ext_localconf.php file of extension
1414 * 'ext_...' => Further absolute path of extension files, see $extensionFilesToCheckFor var for details
1415 * ),
1416 * );
1417 *
1418 * @return array Result array that will be set as $GLOBALS['TYPO3_LOADED_EXT']
1419 */
1420 static protected function createTypo3LoadedExtensionInformationArray() {
1421 $loadedExtensions = static::getLoadedExtensionListArray();
1422 $loadedExtensionInformation = array();
1423 $extensionFilesToCheckFor = array(
1424 'ext_localconf.php',
1425 'ext_tables.php',
1426 'ext_tables.sql',
1427 'ext_tables_static+adt.sql',
1428 'ext_typoscript_constants.txt',
1429 'ext_typoscript_setup.txt'
1430 );
1431 // Clear file status cache to make sure we get good results from is_dir()
1432 clearstatcache();
1433 foreach ($loadedExtensions as $extensionKey) {
1434 // Determine if extension is installed locally, globally or system (in this order)
1435 if (@is_dir((PATH_typo3conf . 'ext/' . $extensionKey . '/'))) {
1436 // local
1437 $loadedExtensionInformation[$extensionKey] = array(
1438 'type' => 'L',
1439 'siteRelPath' => 'typo3conf/ext/' . $extensionKey . '/',
1440 'typo3RelPath' => '../typo3conf/ext/' . $extensionKey . '/'
1441 );
1442 } elseif (@is_dir((PATH_typo3 . 'ext/' . $extensionKey . '/'))) {
1443 // global
1444 $loadedExtensionInformation[$extensionKey] = array(
1445 'type' => 'G',
1446 'siteRelPath' => TYPO3_mainDir . 'ext/' . $extensionKey . '/',
1447 'typo3RelPath' => 'ext/' . $extensionKey . '/'
1448 );
1449 } elseif (@is_dir((PATH_typo3 . 'sysext/' . $extensionKey . '/'))) {
1450 // system
1451 $loadedExtensionInformation[$extensionKey] = array(
1452 'type' => 'S',
1453 'siteRelPath' => TYPO3_mainDir . 'sysext/' . $extensionKey . '/',
1454 'typo3RelPath' => 'sysext/' . $extensionKey . '/'
1455 );
1456 }
1457 // Register found files in extension array if extension was found
1458 if (isset($loadedExtensionInformation[$extensionKey])) {
1459 foreach ($extensionFilesToCheckFor as $fileName) {
1460 $absolutePathToFile = PATH_site . $loadedExtensionInformation[$extensionKey]['siteRelPath'] . $fileName;
1461 if (@is_file($absolutePathToFile)) {
1462 $loadedExtensionInformation[$extensionKey][$fileName] = $absolutePathToFile;
1463 }
1464 }
1465 }
1466 // Register found extension icon
1467 $loadedExtensionInformation[$extensionKey]['ext_icon'] = self::getExtensionIcon(PATH_site . $loadedExtensionInformation[$extensionKey]['siteRelPath']);
1468 }
1469 return $loadedExtensionInformation;
1470 }
1471
1472 /**
1473 * Find extension icon
1474 *
1475 * @param string $extensionPath Path to extension directory.
1476 * @param string $returnFullPath Return full path of file.
1477 * @return string
1478 * @throws \BadFunctionCallException
1479 */
1480 static public function getExtensionIcon($extensionPath, $returnFullPath = FALSE) {
1481 $icon = '';
1482 $iconFileTypesToCheckFor = array('png', 'gif');
1483 foreach ($iconFileTypesToCheckFor as $fileType) {
1484 if (file_exists($extensionPath . 'ext_icon.' . $fileType)) {
1485 $icon = 'ext_icon.' . $fileType;
1486 break;
1487 }
1488 }
1489 return $returnFullPath ? $extensionPath . $icon : $icon;
1490 }
1491
1492 /**
1493 * Cache identifier of cached Typo3LoadedExtensionInformation array
1494 *
1495 * @return string
1496 */
1497 static protected function getTypo3LoadedExtensionInformationCacheIdentifier() {
1498 return 'loaded_extensions_' . sha1((TYPO3_version . PATH_site . 'loadedExtensions'));
1499 }
1500
1501 /**
1502 * Execute all ext_localconf.php files of loaded extensions.
1503 * The method implements an optionally used caching mechanism that concatenates all
1504 * ext_localconf.php files in one file.
1505 *
1506 * This is an internal method. It is only used during bootstrap and
1507 * extensions should not use it!
1508 *
1509 * @param boolean $allowCaching Whether or not to load / create concatenated cache file
1510 * @return void
1511 * @access private
1512 */
1513 static public function loadExtLocalconf($allowCaching = TRUE) {
1514 if ($allowCaching) {
1515 $cacheIdentifier = self::getExtLocalconfCacheIdentifier();
1516 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
1517 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1518 if ($codeCache->has($cacheIdentifier)) {
1519 $codeCache->requireOnce($cacheIdentifier);
1520 } else {
1521 self::loadSingleExtLocalconfFiles();
1522 self::createExtLocalconfCacheEntry();
1523 }
1524 } else {
1525 self::loadSingleExtLocalconfFiles();
1526 }
1527 }
1528
1529 /**
1530 * Execute ext_localconf.php files from extensions
1531 *
1532 * @return void
1533 */
1534 static protected function loadSingleExtLocalconfFiles() {
1535 // This is the main array meant to be manipulated in the ext_localconf.php files
1536 // In general it is recommended to not rely on it to be globally defined in that
1537 // scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
1538 // Nevertheless we define it here as global for backwards compatibility.
1539 global $TYPO3_CONF_VARS;
1540 // These globals for internal use only. Manipulating them directly is highly discouraged!
1541 // We set them here as global for backwards compatibility, but this will change in
1542 // future versions.
1543 // @deprecated since 6.0 Will be removed in two versions.
1544 global $T3_SERVICES, $T3_VAR;
1545 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $_EXTKEY => $extensionInformation) {
1546 if (is_array($extensionInformation) && $extensionInformation['ext_localconf.php']) {
1547 // $_EXTKEY and $_EXTCONF are available in ext_localconf.php
1548 // and are explicitly set in cached file as well
1549 $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
1550 require $extensionInformation['ext_localconf.php'];
1551 }
1552 }
1553 }
1554
1555 /**
1556 * Create cache entry for concatenated ext_localconf.php files
1557 *
1558 * @return void
1559 */
1560 static protected function createExtLocalconfCacheEntry() {
1561 $extensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
1562 $phpCodeToCache = array();
1563 // Set same globals as in loadSingleExtLocalconfFiles()
1564 $phpCodeToCache[] = '/**';
1565 $phpCodeToCache[] = ' * Compiled ext_localconf.php cache file';
1566 $phpCodeToCache[] = ' */';
1567 $phpCodeToCache[] = '';
1568 $phpCodeToCache[] = 'global $TYPO3_CONF_VARS, $T3_SERVICES, $T3_VAR;';
1569 $phpCodeToCache[] = '';
1570 // Iterate through loaded extensions and add ext_localconf content
1571 foreach ($extensionInformation as $extensionKey => $extensionDetails) {
1572 if (isset($extensionDetails['ext_localconf.php']) && $extensionDetails['ext_localconf.php']) {
1573 // Include a header per extension to make the cache file more readable
1574 $phpCodeToCache[] = '/**';
1575 $phpCodeToCache[] = ' * Extension: ' . $extensionKey;
1576 $phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_localconf.php'];
1577 $phpCodeToCache[] = ' */';
1578 $phpCodeToCache[] = '';
1579 // Set $_EXTKEY and $_EXTCONF for this extension
1580 $phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
1581 $phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];';
1582 $phpCodeToCache[] = '';
1583 // Add ext_localconf.php content of extension
1584 $phpCodeToCache[] = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extensionDetails['ext_localconf.php']));
1585 $phpCodeToCache[] = '';
1586 $phpCodeToCache[] = '';
1587 }
1588 }
1589 $phpCodeToCache = implode(LF, $phpCodeToCache);
1590 // Remove all start and ending php tags from content
1591 $phpCodeToCache = preg_replace('/<\\?php|\\?>/is', '', $phpCodeToCache);
1592 $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(self::getExtLocalconfCacheIdentifier(), $phpCodeToCache);
1593 }
1594
1595 /**
1596 * Cache identifier of concatenated ext_localconf file
1597 *
1598 * @return string
1599 */
1600 static protected function getExtLocalconfCacheIdentifier() {
1601 return 'ext_localconf_' . sha1((TYPO3_version . PATH_site . 'extLocalconf'));
1602 }
1603
1604 /**
1605 * Wrapper for buildBaseTcaFromSingleFiles handling caching.
1606 *
1607 * This builds 'base' TCA that is later overloaded by ext_tables.php.
1608 *
1609 * Use a cache file if exists and caching is allowed.
1610 *
1611 * This is an internal method. It is only used during bootstrap and
1612 * extensions should not use it!
1613 *
1614 * @param boolean $allowCaching Whether or not to load / create concatenated cache file
1615 * @return void
1616 * @access private
1617 */
1618 static public function loadBaseTca($allowCaching = TRUE) {
1619 if ($allowCaching) {
1620 $cacheIdentifier = static::getBaseTcaCacheIdentifier();
1621 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
1622 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1623 if ($codeCache->has($cacheIdentifier)) {
1624 $codeCache->requireOnce($cacheIdentifier);
1625 } else {
1626 self::buildBaseTcaFromSingleFiles();
1627 self::createBaseTcaCacheFile();
1628 }
1629 } else {
1630 self::buildBaseTcaFromSingleFiles();
1631 }
1632 }
1633
1634 /**
1635 * Find all Configuration/TCA/* files of extensions and create base TCA from it.
1636 * The filename must be the table name in $GLOBALS['TCA'], and the content of
1637 * the file should return an array with content of a specific table.
1638 *
1639 * @return void
1640 * @see Extension core, cms, extensionmanager and others for examples.
1641 */
1642 static protected function buildBaseTcaFromSingleFiles() {
1643 $GLOBALS['TCA'] = array();
1644 foreach (self::getLoadedExtensionListArray() as $extensionName) {
1645 $tcaConfigurationDirectory = self::extPath($extensionName) . 'Configuration/TCA';
1646 if (is_dir($tcaConfigurationDirectory)) {
1647 $files = scandir($tcaConfigurationDirectory);
1648 foreach ($files as $file) {
1649 if (
1650 is_file($tcaConfigurationDirectory . '/' . $file)
1651 && ($file !== '.')
1652 && ($file !== '..')
1653 && (substr($file, -4, 4) === '.php')
1654 ) {
1655 $tcaOfTable = require($tcaConfigurationDirectory . '/' . $file);
1656 if (is_array($tcaOfTable)) {
1657 // TCA table name is filename without .php suffix, eg 'sys_notes', not 'sys_notes.php'
1658 $tcaTableName = substr($file, 0, -4);
1659 $GLOBALS['TCA'][$tcaTableName] = $tcaOfTable;
1660 }
1661 }
1662 }
1663 }
1664 }
1665 }
1666
1667 /**
1668 * Cache base $GLOBALS['TCA'] to cache file to require the whole thing in one
1669 * file for next access instead of cycling through all extensions again.
1670 *
1671 * @return void
1672 */
1673 static protected function createBaseTcaCacheFile() {
1674 $phpCodeToCache = '$GLOBALS[\'TCA\'] = ';
1675 $phpCodeToCache .= ArrayUtility::arrayExport($GLOBALS['TCA']);
1676 $phpCodeToCache .= ';';
1677 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
1678 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1679 $codeCache->set(static::getBaseTcaCacheIdentifier(), $phpCodeToCache);
1680 }
1681
1682 /**
1683 * Cache identifier of base TCA cache entry.
1684 *
1685 * @return string
1686 */
1687 static protected function getBaseTcaCacheIdentifier() {
1688 return 'tca_base_' . sha1((TYPO3_version . PATH_site . 'tca'));
1689 }
1690
1691 /**
1692 * Execute all ext_tables.php files of loaded extensions.
1693 * The method implements an optionally used caching mechanism that concatenates all
1694 * ext_tables.php files in one file.
1695 *
1696 * This is an internal method. It is only used during bootstrap and
1697 * extensions should not use it!
1698 *
1699 * @param boolean $allowCaching Whether to load / create concatenated cache file
1700 * @return void
1701 * @access private
1702 */
1703 static public function loadExtTables($allowCaching = TRUE) {
1704 if ($allowCaching && !self::$extTablesWasReadFromCacheOnce) {
1705 self::$extTablesWasReadFromCacheOnce = TRUE;
1706 $cacheIdentifier = self::getExtTablesCacheIdentifier();
1707 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
1708 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1709 if ($codeCache->has($cacheIdentifier)) {
1710 $codeCache->requireOnce($cacheIdentifier);
1711 } else {
1712 self::loadSingleExtTablesFiles();
1713 self::createExtTablesCacheEntry();
1714 }
1715 } else {
1716 self::loadSingleExtTablesFiles();
1717 }
1718 }
1719
1720 /**
1721 * Load ext_tables.php as single files
1722 *
1723 * @return void
1724 */
1725 static protected function loadSingleExtTablesFiles() {
1726 // In general it is recommended to not rely on it to be globally defined in that
1727 // scope, but we can not prohibit this without breaking backwards compatibility
1728 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
1729 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
1730 global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
1731 global $_EXTKEY;
1732 // Load each ext_tables.php file of loaded extensions
1733 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $_EXTKEY => $extensionInformation) {
1734 if (is_array($extensionInformation) && $extensionInformation['ext_tables.php']) {
1735 // $_EXTKEY and $_EXTCONF are available in ext_tables.php
1736 // and are explicitly set in cached file as well
1737 $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
1738 require $extensionInformation['ext_tables.php'];
1739 static::loadNewTcaColumnsConfigFiles();
1740 }
1741 }
1742 }
1743
1744 /**
1745 * Create concatenated ext_tables.php cache file
1746 *
1747 * @return void
1748 */
1749 static protected function createExtTablesCacheEntry() {
1750 $extensionInformation = $GLOBALS['TYPO3_LOADED_EXT'];
1751 $phpCodeToCache = array();
1752 // Set same globals as in loadSingleExtTablesFiles()
1753 $phpCodeToCache[] = '/**';
1754 $phpCodeToCache[] = ' * Compiled ext_tables.php cache file';
1755 $phpCodeToCache[] = ' */';
1756 $phpCodeToCache[] = '';
1757 $phpCodeToCache[] = 'global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;';
1758 $phpCodeToCache[] = 'global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;';
1759 $phpCodeToCache[] = 'global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;';
1760 $phpCodeToCache[] = 'global $_EXTKEY;';
1761 $phpCodeToCache[] = '';
1762 // Iterate through loaded extensions and add ext_tables content
1763 foreach ($extensionInformation as $extensionKey => $extensionDetails) {
1764 if (isset($extensionDetails['ext_tables.php']) && $extensionDetails['ext_tables.php']) {
1765 // Include a header per extension to make the cache file more readable
1766 $phpCodeToCache[] = '/**';
1767 $phpCodeToCache[] = ' * Extension: ' . $extensionKey;
1768 $phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_tables.php'];
1769 $phpCodeToCache[] = ' */';
1770 $phpCodeToCache[] = '';
1771 // Set $_EXTKEY and $_EXTCONF for this extension
1772 $phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
1773 $phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];';
1774 $phpCodeToCache[] = '';
1775 // Add ext_tables.php content of extension
1776 $phpCodeToCache[] = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extensionDetails['ext_tables.php']));
1777 $phpCodeToCache[] = '';
1778 $phpCodeToCache[] = '\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();';
1779 $phpCodeToCache[] = '';
1780 }
1781 }
1782 $phpCodeToCache = implode(LF, $phpCodeToCache);
1783 // Remove all start and ending php tags from content
1784 $phpCodeToCache = preg_replace('/<\\?php|\\?>/is', '', $phpCodeToCache);
1785 $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(self::getExtTablesCacheIdentifier(), $phpCodeToCache);
1786 }
1787
1788 /**
1789 * Loads "columns" of a $TCA table definition if extracted
1790 * to a "dynamicConfigFile". This method is called after each
1791 * single ext_tables.php files was included to immediately have
1792 * the full $TCA ready for the next extension.
1793 *
1794 * $TCA[$tableName]['ctrl']['dynamicConfigFile'] must be the
1795 * absolute path to a file.
1796 *
1797 * Be aware that 'dynamicConfigFile' is obsolete, and all TCA
1798 * table definitions should be moved to Configuration/TCA/tablename.php
1799 * to be fully loaded automatically.
1800 *
1801 * Example:
1802 * dynamicConfigFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'SysNote.php',
1803 *
1804 * @return void
1805 * @throws \RuntimeException
1806 * @internal Internal use ONLY. It is called by cache files and can not be protected. Do not call yourself!
1807 */
1808 static public function loadNewTcaColumnsConfigFiles() {
1809 global $TCA;
1810
1811 foreach (array_keys($TCA) as $tableName) {
1812 if (!isset($TCA[$tableName]['columns'])) {
1813 $columnsConfigFile = $TCA[$tableName]['ctrl']['dynamicConfigFile'];
1814 if ($columnsConfigFile) {
1815 if (GeneralUtility::isAbsPath($columnsConfigFile)) {
1816 include($columnsConfigFile);
1817 } else {
1818 throw new \RuntimeException(
1819 'Columns configuration file not found',
1820 1341151261
1821 );
1822 }
1823 }
1824 }
1825 }
1826 }
1827
1828 /**
1829 * Cache identifier for concatenated ext_tables.php files
1830 *
1831 * @return string
1832 */
1833 static protected function getExtTablesCacheIdentifier() {
1834 return 'ext_tables_' . sha1((TYPO3_version . PATH_site . 'extTables'));
1835 }
1836
1837 /**
1838 * Loading extensions configured in $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray']
1839 *
1840 * Usages of this function can be seen in bootstrap
1841 * Extensions are always detected in the order local - global - system.
1842 *
1843 * @return array Extension Array
1844 * @internal
1845 * @deprecated since 6.0, will be removed in two versions
1846 */
1847 static public function typo3_loadExtensions() {
1848 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1849 return self::loadTypo3LoadedExtensionInformation(TRUE);
1850 }
1851
1852 /**
1853 * Returns the section headers for the compiled cache-files.
1854 *
1855 * @param string $key Is the extension key
1856 * @param string $file Is the filename (only informative for comment)
1857 * @return string
1858 * @internal
1859 * @deprecated since 6.0, will be removed in two versions
1860 */
1861 static public function _makeIncludeHeader($key, $file) {
1862 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1863 return '';
1864 }
1865
1866 /**
1867 * Returns TRUE if both the localconf and tables cache file exists
1868 * (with $cacheFilePrefix) and if they are not empty
1869 *
1870 * @param $cacheFilePrefix string Prefix of the cache file to check
1871 * @return boolean
1872 * @deprecated since 6.0, will be removed in two versions
1873 */
1874 static public function isCacheFilesAvailable($cacheFilePrefix) {
1875 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1876 return FALSE;
1877 }
1878
1879 /**
1880 * Returns TRUE if configuration files in typo3conf/ are writable
1881 *
1882 * @return boolean TRUE if at least one configuration file in typo3conf/ is writable
1883 * @internal
1884 * @deprecated since 6.1, will be removed in two versions
1885 */
1886 static public function isLocalconfWritable() {
1887 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1888 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')
1889 ->canWriteConfiguration();
1890 }
1891
1892 /**
1893 * Returns an error string if typo3conf/ or cache-files with $cacheFilePrefix are NOT writable
1894 * Returns FALSE if no problem.
1895 *
1896 * @param string $cacheFilePrefix Prefix of the cache file to check
1897 * @return string
1898 * @internal
1899 * @deprecated since 6.0, will be removed in two versions
1900 */
1901 static public function cannotCacheFilesWritable($cacheFilePrefix) {
1902 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1903 return '';
1904 }
1905
1906 /**
1907 * Returns an array with the two cache-files (0=>localconf, 1=>tables)
1908 * from typo3conf/ if they (both) exist. Otherwise FALSE.
1909 * Evaluation relies on $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE']
1910 *
1911 * @param string $cacheFilePrefix Cache file prefix to be used (optional)
1912 * @return array
1913 * @internal
1914 * @deprecated since 6.0, will be removed in versions
1915 */
1916 static public function currentCacheFiles($cacheFilePrefix = NULL) {
1917 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1918 return array();
1919 }
1920
1921 /**
1922 * Compiles/Creates the two cache-files in typo3conf/ based on $cacheFilePrefix
1923 * Returns a array with the key "_CACHEFILE" set to the $cacheFilePrefix value
1924 *
1925 * @param array $extensions Extension information array
1926 * @param string $cacheFilePrefix Prefix for the cache files
1927 * @return array
1928 * @internal
1929 * @deprecated since 6.0, will be removed in two versions
1930 */
1931 static public function writeCacheFiles($extensions, $cacheFilePrefix) {
1932 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1933 return array();
1934 }
1935
1936 /**
1937 * Remove cache files from php code cache, tagged with 'core'
1938 *
1939 * This removes the following cache entries:
1940 * - autoloader cache registry
1941 * - cache loaded extension array
1942 * - ext_localconf concatenation
1943 * - ext_tables concatenation
1944 *
1945 * This method is usually only used by extension that fiddle
1946 * with the loaded extensions. An example is the extension
1947 * manager and the install tool.
1948 *
1949 * @return void
1950 */
1951 static public function removeCacheFiles() {
1952 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
1953 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
1954 $codeCache->flush();
1955 }
1956
1957 /**
1958 * Gets the behaviour for caching ext_tables.php and ext_localconf.php files
1959 * (see $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache'] setting in the install tool).
1960 *
1961 * @param boolean $usePlainValue Whether to use the value as it is without modifications
1962 * @return integer
1963 * @deprecated since 6.0, will be removed two versions later
1964 */
1965 static public function getExtensionCacheBehaviour($usePlainValue = FALSE) {
1966 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1967 return 1;
1968 }
1969
1970 /**
1971 * Gets the prefix used for the ext_tables.php and ext_localconf.php cached files.
1972 *
1973 * @return string
1974 * @deprecated since 6.0, will be removed two versions later
1975 */
1976 static public function getCacheFilePrefix() {
1977 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1978 }
1979
1980 /**
1981 * Gets the list of enabled extensions
1982 *
1983 * @return string
1984 * @deprecated since 6.0, will be removed two versions later
1985 */
1986 static public function getEnabledExtensionList() {
1987 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1988 return implode(',', self::getLoadedExtensionListArray());
1989 }
1990
1991 /**
1992 * Gets the list of required extensions.
1993 *
1994 * @return string
1995 * @deprecated since 6.0, will be removed two versions later
1996 */
1997 static public function getRequiredExtensionList() {
1998 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1999 return implode(',', self::getRequiredExtensionListArray());
2000 }
2001
2002 /**
2003 * Get list of extensions to be ignored (not to be loaded).
2004 *
2005 * @return string
2006 * @deprecated since 6.0, will be removed two versions later
2007 */
2008 static public function getIgnoredExtensionList() {
2009 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
2010 return '';
2011 }
2012
2013 /**
2014 * Gets an array of loaded extension keys
2015 *
2016 * @return array Loaded extensions
2017 */
2018 static public function getLoadedExtensionListArray() {
2019 // Extensions in extListArray
2020 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'])) {
2021 $loadedExtensions = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'];
2022 } else {
2023 // Fallback handling if extlist is still a string and not an array
2024 // @deprecated since 6.0, will be removed in 6.2
2025 $loadedExtensions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']);
2026 }
2027 // Add required extensions
2028 $loadedExtensions = array_merge(static::getRequiredExtensionListArray(), $loadedExtensions);
2029 $loadedExtensions = array_unique($loadedExtensions);
2030 return $loadedExtensions;
2031 }
2032
2033 /**
2034 * Gets list of required extensions.
2035 * This is the list of extensions from constant REQUIRED_EXTENSIONS defined
2036 * in bootstrap, together with a possible additional list of extensions from
2037 * local configuration
2038 *
2039 * @return array List of required extensions
2040 */
2041 static public function getRequiredExtensionListArray() {
2042 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'])) {
2043 $requiredExtensions = $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'];
2044 } else {
2045 $requiredExtensions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt']);
2046 }
2047 $requiredExtensions = array_merge(\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', REQUIRED_EXTENSIONS), $requiredExtensions);
2048 $requiredExtensions = array_unique($requiredExtensions);
2049 return $requiredExtensions;
2050 }
2051
2052 /**
2053 * Loads given extension
2054 *
2055 * Warning: This method only works if the ugrade wizard to transform
2056 * localconf.php to LocalConfiguration.php was already run
2057 *
2058 * @param string $extensionKey Extension key to load
2059 * @return void
2060 * @throws \RuntimeException
2061 */
2062 static public function loadExtension($extensionKey) {
2063 if (static::isLoaded($extensionKey)) {
2064 throw new \RuntimeException('Extension already loaded', 1342345486);
2065 }
2066 $extList = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->getLocalConfigurationValueByPath('EXT/extListArray');
2067 $extList[] = $extensionKey;
2068 static::writeNewExtensionList($extList);
2069 }
2070
2071 /**
2072 * Unloads given extension
2073 *
2074 * Warning: This method only works if the ugrade wizard to transform
2075 * localconf.php to LocalConfiguration.php was already run
2076 *
2077 * @param string $extensionKey Extension key to remove
2078 * @return void
2079 * @throws \RuntimeException
2080 */
2081 static public function unloadExtension($extensionKey) {
2082 if (!static::isLoaded($extensionKey)) {
2083 throw new \RuntimeException('Extension not loaded', 1342345487);
2084 }
2085 if (in_array($extensionKey, static::getRequiredExtensionListArray())) {
2086 throw new \RuntimeException('Can not unload required extension', 1342348167);
2087 }
2088 $extList = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->getLocalConfigurationValueByPath('EXT/extListArray');
2089 $extList = array_diff($extList, array($extensionKey));
2090 static::writeNewExtensionList($extList);
2091 }
2092
2093 /**
2094 * Writes extension list and clear cache files.
2095 *
2096 * @TODO : This method should be protected, but with current em it is hard to do so,
2097 * @param array Extension array to load, loader order is kept
2098 * @return void
2099 * @internal
2100 */
2101 static public function writeNewExtensionList(array $newExtensionList) {
2102 $extensionList = array_unique($newExtensionList);
2103 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->setLocalConfigurationValueByPath('EXT/extListArray', $extensionList);
2104 static::removeCacheFiles();
2105 }
2106
2107 /**
2108 * Makes a table categorizable by extending its TCA.
2109 *
2110 * @param string $extensionKey Extension key to be used
2111 * @param string $tableName Name of the table to be categoriezed
2112 * @param string $fieldName Name of the field to be used to store categories
2113 * @param array $options Additional configuration options
2114 * @see addTCAcolumns
2115 * @see addToAllTCAtypes
2116 */
2117 static public function makeCategorizable($extensionKey, $tableName, $fieldName = 'categories', array $options = array()) {
2118 // Update the category registry
2119 $result = \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->add($extensionKey, $tableName, $fieldName);
2120 if ($result === FALSE) {
2121 $message = 't3lib_categoryRegistry: no category registered for table "%s". Double check if there is a TCA configured';
2122 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog(sprintf($message, $tableName), 'Core', 2);
2123 }
2124 // Makes sure to add more TCA to an existing structure
2125 if (isset($GLOBALS['TCA'][$tableName]['columns'])) {
2126 // Forges a new field, default name is "categories"
2127 $fieldConfiguration = array(
2128 'type' => 'select',
2129 'foreign_table' => 'sys_category',
2130 'foreign_table_where' => ' ORDER BY sys_category.title ASC',
2131 'MM' => 'sys_category_record_mm',
2132 'MM_opposite_field' => 'items',
2133 'MM_match_fields' => array('tablenames' => $tableName),
2134 'size' => 10,
2135 'autoSizeMax' => 50,
2136 'maxitems' => 9999,
2137 'renderMode' => 'tree',
2138 'treeConfig' => array(
2139 'parentField' => 'parent',
2140 'appearance' => array(
2141 'expandAll' => TRUE,
2142 'showHeader' => TRUE
2143 )
2144 ),
2145 'wizards' => array(
2146 '_PADDING' => 1,
2147 '_VERTICAL' => 1,
2148 'edit' => array(
2149 'type' => 'popup',
2150 'title' => 'Edit',
2151 'script' => 'wizard_edit.php',
2152 'icon' => 'edit2.gif',
2153 'popup_onlyOpenIfSelected' => 1,
2154 'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1'
2155 ),
2156 'add' => array(
2157 'type' => 'script',
2158 'title' => 'Create new',
2159 'icon' => 'add.gif',
2160 'params' => array(
2161 'table' => 'sys_category',
2162 'pid' => '###CURRENT_PID###',
2163 'setValue' => 'prepend'
2164 ),
2165 'script' => 'wizard_add.php'
2166 )
2167 )
2168 );
2169 if (!empty($options['fieldConfiguration'])) {
2170 $fieldConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($fieldConfiguration, $options['fieldConfiguration']);
2171 }
2172 $columns = array(
2173 $fieldName => array(
2174 'exclude' => 0,
2175 'label' => 'LLL:EXT:lang/locallang_tca.xlf:sys_category.categories',
2176 'config' => $fieldConfiguration
2177 )
2178 );
2179 // Adding fields to an existing table definition
2180 self::addTCAcolumns($tableName, $columns);
2181 $fieldList = '--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category, ' . $fieldName;
2182 if (!empty($options['fieldList'])) {
2183 $fieldList = $options['fieldList'];
2184 }
2185 $typesList = '';
2186 if (!empty($options['typesList'])) {
2187 $typesList = $options['typesList'];
2188 }
2189 $position = '';
2190 if (!empty($options['position'])) {
2191 $position = $options['position'];
2192 }
2193 // Makes the new "categories" field to be visible in TSFE.
2194 self::addToAllTCAtypes($tableName, $fieldList, $typesList, $position);
2195 }
2196 }
2197
2198 }
2199 ?>