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