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