Tons of changes made to the CORE. All scripts has more a less been modified. Primaril...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_extmgm.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 113: class t3lib_extMgm
41 *
42 * SECTION: PATHS and other evaluation
43 * 129: function isLoaded($key,$exitOnError=0)
44 * 144: function extPath($key,$script='')
45 * 158: function extRelPath($key)
46 * 172: function siteRelPath($key)
47 * 183: function getCN($key)
48 *
49 * SECTION: Adding BACKEND features
50 * 215: function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
51 * 237: function addToAllTCAtypes($table,$str,$specificTypesList='')
52 * 255: function allowTableOnStandardPages($table)
53 * 271: function addModule($main,$sub='',$position='',$path='')
54 * 332: function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function')
55 * 349: function addPageTSConfig($content)
56 * 362: function addUserTSConfig($content)
57 * 376: function addLLrefForTCAdescr($tca_descr_key,$file_ref)
58 *
59 * SECTION: Adding SERVICES features
60 * 418: function addService($extKey, $serviceType, $serviceKey, $info)
61 * 485: function findService($serviceType, $serviceSubType='', $excludeServiceKeys='')
62 * 549: function deactivateService($serviceType, $serviceKey)
63 *
64 * SECTION: Adding FRONTEND features
65 * 588: function addPlugin($itemArray,$type='list_type')
66 * 612: function addPiFlexFormValue($piKeyToMatch,$value)
67 * 631: function addToInsertRecords($table,$content_table='tt_content',$content_field='records')
68 * 661: function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
69 * 735: function addStaticFile($extKey,$path,$title)
70 * 753: function addTypoScriptSetup($content)
71 * 766: function addTypoScriptConstants($content)
72 * 782: function addTypoScript($key,$type,$content,$afterStaticUid=0)
73 *
74 * SECTION: INTERNAL EXTENSION MANAGEMENT:
75 * 844: function typo3_loadExtensions()
76 * 923: function _makeIncludeHeader($key,$file)
77 * 943: function isCacheFilesAvailable($cacheFilePrefix)
78 * 955: function isLocalconfWritable()
79 * 967: function cannotCacheFilesWritable($cacheFilePrefix)
80 * 990: function currentCacheFiles()
81 * 1012: function writeCacheFiles($extensions,$cacheFilePrefix)
82 *
83 * TOTAL FUNCTIONS: 31
84 * (This index is automatically created/updated by the extension "extdeveval")
85 *
86 */
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 /**
104 * Extension Management functions
105 *
106 * This class is never instantiated, rather the methods inside is called as functions like
107 * t3lib_extMgm::isLoaded('my_extension');
108 *
109 * @author Kasper Skaarhoj <kasper@typo3.com>
110 * @package TYPO3
111 * @subpackage t3lib
112 */
113 class t3lib_extMgm {
114
115
116 /**************************************
117 *
118 * PATHS and other evaluation
119 *
120 ***************************************/
121
122 /**
123 * Returns true if the extension with extension key $key is loaded.
124 *
125 * @param string Extension key to test
126 * @param boolean If $exitOnError is true and the extension is not loaded the function will die with an error message
127 * @return boolean
128 */
129 function isLoaded($key,$exitOnError=0) {
130 global $TYPO3_LOADED_EXT;
131 if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key])) die('Fatal Error: Extension "'.$key.'" was not loaded.');
132 return isset($TYPO3_LOADED_EXT[$key]);
133 }
134
135 /**
136 * Returns the absolute path to the extension with extension key $key
137 * If the extension is not loaded the function will die with an error message
138 * Useful for internal fileoperations
139 *
140 * @param string Extension key
141 * @param string $script is appended to the output if set.
142 * @return string
143 */
144 function extPath($key,$script='') {
145 global $TYPO3_LOADED_EXT;
146 if (!isset($TYPO3_LOADED_EXT[$key])) die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!');
147 return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
148 }
149
150 /**
151 * Returns the relative path to the extension as measured from from the TYPO3_mainDir
152 * If the extension is not loaded the function will die with an error message
153 * Useful for images and links from backend
154 *
155 * @param string Extension key
156 * @return string
157 */
158 function extRelPath($key) {
159 global $TYPO3_LOADED_EXT;
160 if (!isset($TYPO3_LOADED_EXT[$key])) die('TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!');
161 return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
162 }
163
164 /**
165 * Returns the relative path to the extension as measured from the PATH_site (frontend)
166 * If the extension is not loaded the function will die with an error message
167 * Useful for images and links from the frontend
168 *
169 * @param string Extension key
170 * @return string
171 */
172 function siteRelPath($key) {
173 return substr(t3lib_extMgm::extPath($key),strlen(PATH_site));
174 }
175
176 /**
177 * Returns the correct class name prefix for the extension key $key
178 *
179 * @param string Extension key
180 * @return string
181 * @internal
182 */
183 function getCN($key) {
184 return substr($key,0,5)=='user_' ? 'user_'.str_replace('_','',substr($key,5)) : 'tx_'.str_replace('_','',$key);
185 }
186
187
188
189
190
191
192
193
194
195
196 /**************************************
197 *
198 * Adding BACKEND features
199 * (related to core features)
200 *
201 ***************************************/
202
203 /**
204 * Adding fields to an existing table definition in $TCA
205 * Adds an array with $TCA column-configuration to the $TCA-entry for that table.
206 * 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!
207 * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
208 * FOR USE IN ext_tables.php FILES
209 *
210 * @param string $table is the table name of a table already present in $TCA with a columns section
211 * @param array $columnArray is the array with the additional columns (typical some fields an extension wants to add)
212 * @param boolean If $addTofeInterface is true the list of fields are also added to the fe_admin_fieldList.
213 * @return void
214 */
215 function addTCAcolumns($table,$columnArray,$addTofeInterface=0) {
216 global $TCA;
217 t3lib_div::loadTCA($table);
218 if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
219 $TCA[$table]['columns'] = array_merge($TCA[$table]['columns'],$columnArray); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
220 if ($addTofeInterface) $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',',array_keys($columnArray));
221 }
222 }
223
224 /**
225 * Makes fields visible on the form, adding them to the end.
226 *
227 * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
228 * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
229 * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
230 * FOR USE IN ext_tables.php FILES
231 *
232 * @param string Table name
233 * @param string Field list to add.
234 * @param string List of specific types to add the field list to. (If empty, all type entries are affected)
235 * @return void
236 */
237 function addToAllTCAtypes($table,$str,$specificTypesList='') {
238 global $TCA;
239 t3lib_div::loadTCA($table);
240 if (trim($str) && is_array($TCA[$table]) && is_array($TCA[$table]['types'])) {
241 foreach($TCA[$table]['types'] as $k => $v) {
242 if (!$specificTypesList || t3lib_div::inList($specificTypesList,$k)) $TCA[$table]['types'][$k]['showitem'].=', '.trim($str);
243 }
244 }
245 }
246
247 /**
248 * Add tablename to default list of allowed tables on pages.
249 * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
250 * FOR USE IN ext_tables.php FILES
251 *
252 * @param string Table name
253 * @return void
254 */
255 function allowTableOnStandardPages($table) {
256 global $PAGES_TYPES;
257
258 $PAGES_TYPES['default']['allowedTables'].=','.$table;
259 }
260
261 /**
262 * Adds a module (main or sub) to the backend interface
263 * FOR USE IN ext_tables.php FILES
264 *
265 * @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.
266 * @param string $sub is the submodule key. If $sub is not set a blank $main module is created.
267 * @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.
268 * @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.
269 * @return void
270 */
271 function addModule($main,$sub='',$position='',$path='') {
272 global $TBE_MODULES;
273
274 if (isset($TBE_MODULES[$main]) && $sub) { // If there is already a main module by this name:
275
276 // Adding the submodule to the correct position:
277 list($place,$modRef)=t3lib_div::trimExplode(':',$position,1);
278 $mods = t3lib_div::trimExplode(',',$TBE_MODULES[$main],1);
279 if (!in_array($sub,$mods)) {
280 switch(strtolower($place)) {
281 case 'after':
282 case 'before':
283 $pointer=0;
284 reset($mods);
285 while(list($k,$m)=each($mods)) {
286 if (!strcmp($m,$modRef)) {
287 $pointer=strtolower($place)=='after'?$k+1:$k;
288 }
289 }
290 array_splice(
291 $mods, // The modules array
292 $pointer, // To insert one position from the end of the list
293 0, // Don't remove any items, just insert
294 $sub // Module to insert
295 );
296 break;
297 default:
298 if (strtolower($place)=='top') {
299 array_unshift($mods,$sub);
300 } else {
301 array_push($mods,$sub);
302 }
303 break;
304 }
305 }
306 // Re-inserting the submodule list:
307 $TBE_MODULES[$main]=implode(',',$mods);
308 } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank)
309 $TBE_MODULES[$main]=$sub;
310 }
311
312 // Adding path:
313 if ($path) {
314 $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')]=$path;
315 }
316 }
317
318 /**
319 * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
320 * The arguments values are generally determined by which function menu this is supposed to interact with
321 * See Inside TYPO3 for information on how to use this function.
322 * FOR USE IN ext_tables.php FILES
323 *
324 * @param string Module name
325 * @param string Class name
326 * @param string Class path
327 * @param string Title of module
328 * @param string Menu array key - default is "function"
329 * @return void
330 * @see t3lib_SCbase::mergeExternalItems()
331 */
332 function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function') {
333 global $TBE_MODULES_EXT;
334 $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className]=array(
335 'name' => $className,
336 'path' => $classPath,
337 'title' => $title,
338 );
339 }
340
341 /**
342 * Adds $content to the default Page TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultPageTSconfig']
343 * Prefixed with a [GLOBAL] line
344 * FOR USE IN ext_tables.php/ext_locallang.php FILES
345 *
346 * @param string Page TSconfig content
347 * @return void
348 */
349 function addPageTSConfig($content) {
350 global $TYPO3_CONF_VARS;
351 $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
352 }
353
354 /**
355 * Adds $content to the default User TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultUserTSconfig']
356 * Prefixed with a [GLOBAL] line
357 * FOR USE IN ext_tables.php/ext_locallang.php FILES
358 *
359 * @param string User TSconfig content
360 * @return void
361 */
362 function addUserTSConfig($content) {
363 global $TYPO3_CONF_VARS;
364 $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
365 }
366
367 /**
368 * Adds a reference to a locallang file with TCA_DESCR labels
369 * FOR USE IN ext_tables.php FILES
370 * eg. t3lib_extMgm::addLLrefForTCAdescr('pages','EXT:lang/locallang_csh_pages.php'); for the pages table or t3lib_extMgm::addLLrefForTCAdescr('_MOD_web_layout','EXT:cms/locallang_csh_weblayout.php'); for the Web > Page module.
371 *
372 * @param string Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
373 * @param string File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php"
374 * @return void
375 */
376 function addLLrefForTCAdescr($tca_descr_key,$file_ref) {
377 global $TCA_DESCR;
378 if ($tca_descr_key) {
379 if (!is_array($TCA_DESCR[$tca_descr_key])) {
380 $TCA_DESCR[$tca_descr_key]=array();
381 }
382 if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
383 $TCA_DESCR[$tca_descr_key]['refs']=array();
384 }
385 $TCA_DESCR[$tca_descr_key]['refs'][]=$file_ref;
386 }
387 }
388
389
390
391
392
393
394
395
396
397
398
399
400 /**************************************
401 *
402 * Adding SERVICES features
403 *
404 * @author René Fritz <r.fritz@colorcube.de>
405 *
406 ***************************************/
407
408 /**
409 * Adds a service to the global services array
410 *
411 * @param string Extension key
412 * @param string Service type
413 * @param string Service key
414 * @param array Service description array
415 * @return void
416 * @author René Fritz <r.fritz@colorcube.de>
417 */
418 function addService($extKey, $serviceType, $serviceKey, $info) {
419 global $T3_SERVICES,$TYPO3_CONF_VARS;
420
421 // even not available services will be included to make it possible to give the admin a feedback of non-available services.
422 // but maybe it's better to move non-available services to a different array??
423 #debug($serviceType);
424 #debug($serviceKey);
425 #debug($info);
426 if ($serviceType AND substr($serviceType,0,3)!='tx_' AND substr($serviceKey,0,3)=='tx_' AND is_array($info)) {
427 #debug($extKey);
428 $info['priority'] = max(0,min(100,$info['priority']));
429
430 $T3_SERVICES[$serviceType][$serviceKey]=$info;
431
432 $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
433 $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
434 $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
435
436
437 // mapping a service key to a service type
438 // all service keys begin with tx_ - service types don't
439 // this way a selection of a special service key as service type is easy
440 $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
441
442
443 // change the priority (and other values) from TYPO3_CONF_VARS
444 // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
445 // even the activation is possible (a unix service might be possible on windows for some reasons)
446 if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
447
448 // no check is done here - there might be configuration values only the service type knows about, so we pass everything
449 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey],$TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
450 }
451
452
453 // OS check
454 // empty $os means 'not limited to one OS', therefore a check is not needed
455 if ($T3_SERVICES[$serviceType][$serviceKey]['available'] AND $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
456
457 // TYPO3_OS is not yet defined
458 $os_type = stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'UNIX';
459
460 $os = t3lib_div::trimExplode(',',strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
461
462 if (!in_array($os_type,$os)) {
463 t3lib_extMgm::deactivateService($serviceType, $serviceKey);
464 }
465 }
466
467 // convert subtype list to array for quicker access
468 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
469 $serviceSubTypes = t3lib_div::trimExplode(',',$info['subtype']);
470 foreach ($serviceSubTypes as $subtype) {
471 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
472 }
473 }
474 }
475
476 /**
477 * Find the available service with highest priority
478 *
479 * @param string Service type
480 * @param string Service sub type
481 * @param string Service key that should be excluded in the search for a service
482 * @return mixed Service info array if a service was found, FLASE otherwise
483 * @author René Fritz <r.fritz@colorcube.de>
484 */
485 function findService($serviceType, $serviceSubType='', $excludeServiceKeys='') {
486 global $T3_SERVICES;
487
488 $serviceKey = FALSE;
489 $serviceInfo = FALSE;
490 $priority = 0;
491 $quality = 0;
492
493 if (is_array($T3_SERVICES[$serviceType])) {
494 foreach($T3_SERVICES[$serviceType] as $key => $info) {
495 if (t3lib_div::inList($excludeServiceKeys,$key)) {
496 continue;
497 }
498
499 // select a subtype randomly
500 // usefull to start a service by service key without knowing his subtypes - for testing purposes
501 if ($serviceSubType=='*') {
502 $serviceSubType = key($info['serviceSubTypes']);
503 }
504
505 if( $info['available'] AND ($info['subtype']=='' XOR $info['serviceSubTypes'][$serviceSubType]) AND $info['priority']>=$priority ) {
506 // has a lower quality than the already found, therefore we skip this service
507 if($info['priority']==$priority AND $info['quality']<$quality) {
508 continue;
509 }
510
511 // service depends on external programs - check if they exists
512 if(trim($info['exec'])) {
513 require_once(PATH_t3lib.'class.t3lib_exec.php');
514
515 $executables = t3lib_div::trimExplode(',', $info['exec'],1);
516 foreach($executables as $executable) {
517 if(!t3lib_exec::checkCommand($executable)) {
518 t3lib_extMgm::deactivateService($serviceType, $key);
519 $info['available']=FALSE;
520 break;
521 }
522 }
523 }
524
525 // still available after exec check?
526 if($info['available']) {
527 $serviceKey = $key;
528 $priority = $info['priority'];
529 $quality = $info['quality'];
530 }
531 }
532 }
533 }
534
535 if ($serviceKey) {
536 $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
537 }
538 return $serviceInfo;
539 }
540
541 /**
542 * Deactivate a service
543 *
544 * @param string Service type
545 * @param string Service key
546 * @return void
547 * @author René Fritz <r.fritz@colorcube.de>
548 */
549 function deactivateService($serviceType, $serviceKey) {
550 global $T3_SERVICES;
551
552 // ... maybe it's better to move non-available services to a different array??
553 $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
554 }
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569 /**************************************
570 *
571 * Adding FRONTEND features
572 * (related specifically to "cms" extension)
573 *
574 ***************************************/
575
576 /**
577 * Adds an entry to the list of plugins in content elements of type "Insert plugin"
578 *
579 * 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)
580 * 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.
581 * 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
582 * FOR USE IN ext_tables.php FILES
583 *
584 * @param array Item Array
585 * @param string Type (eg. "list_type") - basically a field from "tt_content" table
586 * @return void
587 */
588 function addPlugin($itemArray,$type='list_type') {
589 global $TCA;
590 t3lib_div::loadTCA('tt_content');
591 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
592 reset($TCA['tt_content']['columns'][$type]['config']['items']);
593 while(list($k,$v)=each($TCA['tt_content']['columns'][$type]['config']['items'])) {
594 if (!strcmp($v[1],$itemArray[1])) {
595 $TCA['tt_content']['columns'][$type]['config']['items'][$k]=$itemArray;
596 return;
597 }
598 }
599 $TCA['tt_content']['columns'][$type]['config']['items'][]=$itemArray;
600 }
601 }
602
603 /**
604 * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
605 * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin.
606 *
607 * @param string The same value as the key for the plugin
608 * @param string Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
609 * @return void
610 * @see addPlugin()
611 */
612 function addPiFlexFormValue($piKeyToMatch,$value) {
613 global $TCA;
614 t3lib_div::loadTCA('tt_content');
615
616 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
617 $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch] = $value;
618 }
619 }
620
621 /**
622 * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
623 * By using $content_table and $content_field you can also use the function for other tables.
624 * FOR USE IN ext_tables.php FILES
625 *
626 * @param string Table name to allow for "insert record"
627 * @param string Table name TO WHICH the $table name is applied. See $content_field as well.
628 * @param string Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
629 * @return void
630 */
631 function addToInsertRecords($table,$content_table='tt_content',$content_field='records') {
632 global $TCA;
633 t3lib_div::loadTCA($content_table);
634 if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
635 $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
636 }
637 }
638
639 /**
640 * Add PlugIn to Static Template #43
641 *
642 * 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.
643 * 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.
644 * $type determines the type of frontend plugin:
645 * "list_type" (default) - the good old "Insert plugin" entry
646 * "menu_type" - a "Menu/Sitemap" entry
647 * "splash_layout" - a "Textbox" entry
648 * "CType" - a new content element type
649 * "header_layout" - an additional header type (added to the selection of layout1-5)
650 * "includeLib" - just includes the library for manual use somewhere in TypoScript.
651 * (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)
652 * FOR USE IN ext_locallang.php FILES
653 *
654 * @param string $key is the extension key
655 * @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.
656 * @param string $prefix is used as a - yes, suffix - of the class name (fx. "_pi1")
657 * @param string $type, see description above
658 * @param boolean If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
659 * @return void
660 */
661 function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0) {
662 global $TYPO3_LOADED_EXT;
663 $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_','',$key).$prefix.'.php';
664 $cN = t3lib_extMgm::getCN($key);
665
666 // General plugin:
667 if ($cached) {
668 $pluginContent = trim('
669 includeLibs.'.$cN.$prefix.' = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
670 plugin.'.$cN.$prefix.' = USER
671 plugin.'.$cN.$prefix.' {
672 userFunc = '.$cN.$prefix.'->main
673 }');
674 } else {
675 $pluginContent = trim('
676 plugin.'.$cN.$prefix.' = USER_INT
677 plugin.'.$cN.$prefix.' {
678 includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
679 userFunc = '.$cN.$prefix.'->main
680 }');
681 }
682 t3lib_extMgm::addTypoScript($key,'setup','
683 # Setting '.$key.' plugin TypoScript
684 '.$pluginContent);
685
686 // After ST43:
687 switch($type) {
688 case 'list_type':
689 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
690 break;
691 case 'menu_type':
692 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
693 break;
694 case 'splash_layout':
695 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
696 break;
697 case 'CType':
698 $addLine = trim('
699 tt_content.'.$key.$prefix.' = COA
700 tt_content.'.$key.$prefix.' {
701 10 = < lib.stdheader
702 20 = < plugin.'.$cN.$prefix.'
703 }
704 ');
705 break;
706 case 'header_layout':
707 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
708 break;
709 case 'includeLib':
710 $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
711 break;
712 default:
713 $addLine = '';
714 break;
715 }
716 if ($addLine) {
717 t3lib_extMgm::addTypoScript($key,'setup','
718 # Setting '.$key.' plugin TypoScript
719 '.$addLine.'
720 ',43);
721 }
722 }
723
724 /**
725 * Call this method to add an entry in the static template list found in sys_templates
726 * "static template files" are the modern equalent (provided from extensions) to the traditional records in "static_templates"
727 * FOR USE IN ext_locallang.php FILES
728 *
729 * @param string $extKey is of course the extension key
730 * @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 and editorcfg.txt is found (relative to extPath, eg. 'static/')
731 * @param string $title is the title in the selector box.
732 * @return void
733 * @see addTypoScript()
734 */
735 function addStaticFile($extKey,$path,$title) {
736 global $TCA;
737 t3lib_div::loadTCA('sys_template');
738 if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
739 $value = str_replace(',','','EXT:'.$extKey.'/'.$path);
740 $itemArray=array(trim($title.' ('.$extKey.')'),$value);
741 $TCA['sys_template']['columns']['include_static_file']['config']['items'][]=$itemArray;
742 }
743 }
744
745 /**
746 * Adds $content to the default TypoScript setup code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_setup']
747 * Prefixed with a [GLOBAL] line
748 * FOR USE IN ext_locallang.php FILES
749 *
750 * @param string TypoScript Setup string
751 * @return void
752 */
753 function addTypoScriptSetup($content) {
754 global $TYPO3_CONF_VARS;
755 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
756 }
757
758 /**
759 * Adds $content to the default TypoScript constants code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_constants']
760 * Prefixed with a [GLOBAL] line
761 * FOR USE IN ext_locallang.php FILES
762 *
763 * @param string TypoScript Constants string
764 * @return void
765 */
766 function addTypoScriptConstants($content) {
767 global $TYPO3_CONF_VARS;
768 $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
769 }
770
771 /**
772 * Adds $content to the default TypoScript code for either setup, constants or editorcfg as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_*']
773 * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
774 * FOR USE IN ext_locallang.php FILES
775 *
776 * @param string $key is the extension key (informative only).
777 * @param string $type is either "setup", "constants" or "editorcfg" and obviously determines which kind of TypoScript code we are adding.
778 * @param string $content is the TS content, prefixed with a [GLOBAL] line and a comment-header.
779 * @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.
780 * @return void
781 */
782 function addTypoScript($key,$type,$content,$afterStaticUid=0) {
783 global $TYPO3_CONF_VARS;
784
785 if ($type=='setup' || $type=='editorcfg' || $type=='constants') {
786 $content = '
787
788 [GLOBAL]
789 #############################################
790 ## TypoScript added by extension "'.$key.'"
791 #############################################
792
793 '.$content;
794 if ($afterStaticUid) {
795 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
796 if ($afterStaticUid==43) { // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
797 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.']['cssstyledcontent/static/'].=$content;
798 }
799 } else {
800 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
801 }
802 }
803 }
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822 /**************************************
823 *
824 * INTERNAL EXTENSION MANAGEMENT:
825 *
826 ***************************************/
827
828 /**
829 * Loading extensions configured in $TYPO3_CONF_VARS['EXT']['extList']
830 *
831 * CACHING ON: ($TYPO3_CONF_VARS['EXT']['extCache'] = 1 or 2)
832 * 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.
833 * If cachefiles are not found they will be generated
834 * CACHING OFF: ($TYPO3_CONF_VARS['EXT']['extCache'] = 0)
835 * 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.
836 * This array will later be set in the global var $TYPO3_LOADED_EXT
837 *
838 * Usages of this function can be see in config_default.php
839 * Extensions are always detected in the order local - global - system.
840 *
841 * @return array Extension Array
842 * @internal
843 */
844 function typo3_loadExtensions() {
845 global $TYPO3_CONF_VARS;
846
847 // Full list of extensions includes both required and extList:
848 $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'].','.$TYPO3_CONF_VARS['EXT']['extList'];
849
850 // Empty array as a start.
851 $extensions = array();
852
853 //
854 if ($rawExtList) {
855 // The cached File prefix.
856 $cacheFilePrefix = 'temp_CACHED';
857 // Setting the name for the cache files:
858 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1) $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']),0,4);
859 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
860
861 // If cache files available, set cache file prefix and return:
862 if ($TYPO3_CONF_VARS['EXT']['extCache'] && t3lib_extMgm::isCacheFilesAvailable($cacheFilePrefix)) {
863 // Return cache file prefix:
864 $extensions['_CACHEFILE'] = $cacheFilePrefix;
865 } else {
866 // ... but if not, configure...
867 $temp_extensions = array_unique(t3lib_div::trimExplode(',',$rawExtList,1));
868 while(list(,$temp_extKey)=each($temp_extensions)) {
869 if (@is_dir(PATH_site.'typo3conf/ext/'.$temp_extKey)) {
870 $extensions[$temp_extKey]=array('type'=>'L','siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/','typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
871 } elseif (@is_dir(PATH_site.TYPO3_mainDir.'ext/'.$temp_extKey)) {
872 $extensions[$temp_extKey]=array('type'=>'G','siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/','typo3RelPath'=>'ext/'.$temp_extKey.'/');
873 } elseif (@is_dir(PATH_site.TYPO3_mainDir.'sysext/'.$temp_extKey)) {
874 $extensions[$temp_extKey]=array('type'=>'S','siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/','typo3RelPath'=>'sysext/'.$temp_extKey.'/');
875 }
876
877 $files = t3lib_div::trimExplode(',','
878 ext_localconf.php,
879 ext_tables.php,
880 ext_tables.sql,
881 ext_tables_static+adt.sql,
882 ext_typoscript_constants.txt,
883 ext_typoscript_editorcfg.txt,
884 ext_typoscript_setup.txt
885 ',1);
886 reset($files);
887 while(list(,$fName)=each($files)) {
888 $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
889 if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
890 $extensions[$temp_extKey][$fName]=$temp_filename;
891 }
892 }
893 }
894 unset($extensions['_CACHEFILE']);
895
896
897 // write cache?
898 if ($TYPO3_CONF_VARS['EXT']['extCache']) {
899 $wrError = t3lib_extMgm::cannotCacheFilesWritable($cacheFilePrefix);
900 if ($wrError) {
901 //debug('Cannot write cache files: '.$wrError.'. Disabling the cache...');
902 $TYPO3_CONF_VARS['EXT']['extCache']=0;
903 } else {
904 // Write cache files:
905 $extensions = t3lib_extMgm::writeCacheFiles($extensions,$cacheFilePrefix);
906 }
907 }
908 }
909 }
910
911 #debug($extensions);
912 return $extensions;
913 }
914
915 /**
916 * Returns the section headers for the compiled cache-files.
917 *
918 * @param string $key is the extension key
919 * @param string $file is the filename (only informative for comment)
920 * @return string
921 * @internal
922 */
923 function _makeIncludeHeader($key,$file) {
924 return '<?php
925 ###########################
926 ## EXTENSION: '.$key.'
927 ## FILE: '.$file.'
928 ###########################
929
930 $_EXTKEY = \''.$key.'\';
931 $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
932
933 ?>';
934 }
935
936 /**
937 * Returns true if both the localconf and tables cache file exists (with $cacheFilePrefix)
938 *
939 * @param string Prefix of the cache file to check
940 * @return boolean
941 * @internal
942 */
943 function isCacheFilesAvailable($cacheFilePrefix) {
944 return
945 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
946 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php');
947 }
948
949 /**
950 * Returns true if the "localconf.php" file in "typo3conf/" is writable
951 *
952 * @return boolean
953 * @internal
954 */
955 function isLocalconfWritable() {
956 return is_writeable(PATH_typo3conf) && is_writeable(PATH_typo3conf.'localconf.php');
957 }
958
959 /**
960 * Returns an error string if typo3conf/ or cache-files with $cacheFilePrefix are NOT writable
961 * Returns false if no problem.
962 *
963 * @param string Prefix of the cache file to check
964 * @return string
965 * @internal
966 */
967 function cannotCacheFilesWritable($cacheFilePrefix) {
968 $error=array();
969 if (!@is_writeable(PATH_typo3conf)) {
970 $error[]=PATH_typo3conf;
971 }
972 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
973 !@is_writeable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php')) {
974 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
975 }
976 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
977 !@is_writeable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php')) {
978 $error[]=PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
979 }
980 return implode(', ',$error);
981 }
982
983 /**
984 * Returns an array with the two cache-files (0=>localconf, 1=>tables) from typo3conf/ if they (both) exist. Otherwise false.
985 * Evaluation relies on $TYPO3_LOADED_EXT['_CACHEFILE']
986 *
987 * @return array
988 * @internal
989 */
990 function currentCacheFiles() {
991 global $TYPO3_LOADED_EXT;
992
993 if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
994 if (t3lib_extMgm::isCacheFilesAvailable($TYPO3_LOADED_EXT['_CACHEFILE'])) {
995 return array(
996 PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php',
997 PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php'
998 );
999 }
1000 }
1001 }
1002
1003 /**
1004 * Compiles/Creates the two cache-files in typo3conf/ based on $cacheFilePrefix
1005 * Returns a array with the key "_CACHEFILE" set to the $cacheFilePrefix value
1006 *
1007 * @param array Extension information array
1008 * @param string Prefix for the cache files
1009 * @return array
1010 * @internal
1011 */
1012 function writeCacheFiles($extensions,$cacheFilePrefix) {
1013 // Making cache files:
1014 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1015 $cFiles=array();
1016 $cFiles['ext_localconf'].='<?php
1017
1018 $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extensions)).'\'));
1019
1020 ?>';
1021
1022 reset($extensions);
1023 while(list($key,$conf)=each($extensions)) {
1024 if (is_array($conf)) {
1025 if ($conf['ext_localconf.php']) {
1026 $cFiles['ext_localconf'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_localconf.php']);
1027 $cFiles['ext_localconf'].=trim(t3lib_div::getUrl($conf['ext_localconf.php']));
1028 }
1029 if ($conf['ext_tables.php']) {
1030 $cFiles['ext_tables'].=t3lib_extMgm::_makeIncludeHeader($key,$conf['ext_tables.php']);
1031 $cFiles['ext_tables'].=trim(t3lib_div::getUrl($conf['ext_tables.php']));
1032 }
1033 }
1034 }
1035
1036 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php',$cFiles['ext_localconf']);
1037 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php',$cFiles['ext_tables']);
1038
1039 $extensions=array();
1040 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1041
1042 return $extensions;
1043 }
1044 }
1045
1046 ?>