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