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