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