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