00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 final class t3lib_extMgm {
00115 protected static $extensionKeyMap;
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 public static function isLoaded($key, $exitOnError = 0) {
00133 global $TYPO3_LOADED_EXT;
00134 if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key])) {
00135 throw new BadFunctionCallException(
00136 'TYPO3 Fatal Error: Extension "' . $key . '" was not loaded!',
00137 1270853910
00138 );
00139 }
00140 return isset($TYPO3_LOADED_EXT[$key]);
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 public static function extPath($key, $script = '') {
00154 global $TYPO3_LOADED_EXT;
00155 if (!isset($TYPO3_LOADED_EXT[$key])) {
00156 throw new BadFunctionCallException(
00157 'TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!',
00158 1270853878
00159 );
00160 }
00161 return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 public static function extRelPath($key) {
00174 global $TYPO3_LOADED_EXT;
00175 if (!isset($TYPO3_LOADED_EXT[$key])) {
00176 throw new BadFunctionCallException(
00177 'TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!',
00178 1270853879
00179 );
00180 }
00181 return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 public static function siteRelPath($key) {
00194 return substr(self::extPath($key), strlen(PATH_site));
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 public static function getCN($key) {
00206 return substr($key, 0, 5)=='user_' ? 'user_'.str_replace('_', '', substr($key, 5)) : 'tx_'.str_replace('_', '', $key);
00207 }
00208
00209
00210
00211
00212
00213
00214
00215 public static function getExtensionKeyByPrefix($prefix) {
00216 $result = false;
00217
00218 if (!isset(self::$extensionKeyMap)) {
00219 self::$extensionKeyMap = array();
00220 foreach (array_keys($GLOBALS['TYPO3_LOADED_EXT']) as $extensionKey) {
00221 $shortKey = str_replace('_', '', $extensionKey);
00222 self::$extensionKeyMap[$shortKey] = $extensionKey;
00223 }
00224 }
00225
00226 $parts = explode('_', $prefix);
00227 if (isset(self::$extensionKeyMap[$parts[1]])) {
00228 $result = self::$extensionKeyMap[$parts[1]];
00229 }
00230 return $result;
00231 }
00232
00233
00234
00235
00236
00237
00238 public static function clearExtensionKeyMap() {
00239 self::$extensionKeyMap = NULL;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 public static function getExtensionVersion($key) {
00251 if (!is_string($key) || empty($key)) {
00252 throw new InvalidArgumentException('Extension key must be a non-empty string.');
00253 }
00254 if (!self::isLoaded($key)) {
00255 return '';
00256 }
00257
00258 $_EXTKEY = $key;
00259 include(self::extPath($key) . 'ext_emconf.php');
00260
00261 return $EM_CONF[$key]['version'];
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 public static function addTCAcolumns($table, $columnArray, $addTofeInterface = 0) {
00292 global $TCA;
00293 t3lib_div::loadTCA($table);
00294 if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
00295 $TCA[$table]['columns'] = array_merge($TCA[$table]['columns'], $columnArray);
00296 if ($addTofeInterface) $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',', array_keys($columnArray));
00297 }
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 public static function addToAllTCAtypes($table, $str, $specificTypesList = '', $position = '') {
00316 t3lib_div::loadTCA($table);
00317 $str = trim($str);
00318
00319 if ($str && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['types'])) {
00320 foreach($GLOBALS['TCA'][$table]['types'] as $type => &$typeDetails) {
00321 if ($specificTypesList === '' || t3lib_div::inList($specificTypesList, $type)) {
00322 $typeDetails['showitem'] = self::executePositionedStringInsertion(
00323 $typeDetails['showitem'],
00324 $str,
00325 $position
00326 );
00327 }
00328 }
00329 }
00330 }
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 public static function addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
00348 $generatedPalette = '';
00349 $processedPalettes = array();
00350 t3lib_div::loadTCA($table);
00351
00352 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
00353 $types =& $GLOBALS['TCA'][$table]['types'];
00354 if (is_array($types)) {
00355
00356 foreach (array_keys($types) as $type) {
00357 $items = self::explodeItemList($types[$type]['showitem']);
00358 if (isset($items[$field])) {
00359
00360 if ($items[$field]['details']['palette']) {
00361 $palette = $items[$field]['details']['palette'];
00362 if (!isset($processedPalettes[$palette])) {
00363 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
00364 $processedPalettes[$palette] = true;
00365 }
00366
00367 } else {
00368 if ($generatedPalette) {
00369 $palette = $generatedPalette;
00370 } else {
00371 $palette = $generatedPalette = 'generatedFor-' . $field;
00372 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
00373 }
00374 $items[$field]['details']['palette'] = $palette;
00375 $types[$type]['showitem'] = self::generateItemList($items);
00376 }
00377 }
00378 }
00379 }
00380 }
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 public static function addFieldsToPalette($table, $palette, $addFields, $insertionPosition = '') {
00398 t3lib_div::loadTCA($table);
00399
00400 if (isset($GLOBALS['TCA'][$table])) {
00401 $paletteData =& $GLOBALS['TCA'][$table]['palettes'][$palette];
00402
00403 if (is_array($paletteData)) {
00404 $paletteData['showitem'] = self::executePositionedStringInsertion(
00405 $paletteData['showitem'],
00406 $addFields,
00407 $insertionPosition
00408 );
00409
00410 } else {
00411 $paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields);
00412 }
00413 }
00414 }
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 public function addFieldsToUserSettings($addFields, $insertionPosition = '') {
00428 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'] = self::executePositionedStringInsertion(
00429 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'],
00430 $addFields,
00431 $insertionPosition
00432 );
00433 }
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
00449 $list = trim($list);
00450 $insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
00451
00452 if ($insertionList) {
00453
00454 if ($insertionPosition === '') {
00455 $list.= ($list ? ', ' : '') . $insertionList;
00456
00457 } else {
00458 $positions = t3lib_div::trimExplode(',', $insertionPosition, true);
00459 $items = self::explodeItemList($list);
00460 $isInserted = false;
00461
00462 foreach ($items as $item => &$itemDetails) {
00463 $needles = self::getInsertionNeedles($item, $itemDetails['details']);
00464
00465 foreach ($needles['before'] as $needle) {
00466 if (in_array($needle, $positions)) {
00467 $itemDetails['rawData'] = $insertionList . ', ' . $itemDetails['rawData'];
00468 $isInserted = true;
00469 break;
00470 }
00471 }
00472
00473 foreach ($needles['after'] as $needle) {
00474 if (in_array($needle, $positions)) {
00475 $itemDetails['rawData'] .= ', ' . $insertionList;
00476 $isInserted = true;
00477 break;
00478 }
00479 }
00480
00481 if ($isInserted) {
00482 break;
00483 }
00484 }
00485
00486 if (!$isInserted) {
00487 $list.= ($list ? ', ' : '') . $insertionList;
00488
00489 } else {
00490 $list = self::generateItemList($items, true);
00491 }
00492 }
00493 }
00494
00495 return $list;
00496 }
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 protected static function removeDuplicatesForInsertion($insertionList, $list = '') {
00512 $pattern = '/(^|,)\s*\b([^;,]+)\b[^,]*/';
00513 $listItems = array();
00514
00515 if ($list && preg_match_all($pattern, $list, $listMatches)) {
00516 $listItems = $listMatches[2];
00517 }
00518
00519 if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
00520 $insertionItems = array();
00521 $insertionDuplicates = false;
00522
00523 foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) {
00524 if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) {
00525 $insertionItems[$insertionItem] = true;
00526 } else {
00527 unset($insertionListMatches[0][$insertionIndex]);
00528 $insertionDuplicates = true;
00529 }
00530 }
00531
00532 if ($insertionDuplicates) {
00533 $insertionList = implode('', $insertionListMatches[0]);
00534 }
00535 }
00536
00537 return $insertionList;
00538 }
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 protected static function getInsertionNeedles($item, array $itemDetails) {
00550 if (strstr($item, '--')) {
00551
00552 $item = preg_replace('/[0-9]+$/', '', $item);
00553 }
00554
00555 $needles = array(
00556 'before' => array($item, 'before:' . $item),
00557 'after' => array('after:' . $item),
00558 );
00559
00560 if ($itemDetails['palette']) {
00561 $palette = $item . ';;' . $itemDetails['palette'];
00562 $needles['before'][] = $palette;
00563 $needles['before'][] = 'before:' . $palette;
00564 $needles['after'][] = 'after:' . $palette;
00565 }
00566
00567 return $needles;
00568 }
00569
00570
00571
00572
00573
00574
00575
00576
00577 protected static function explodeItemList($itemList) {
00578 $items = array();
00579 $itemParts = t3lib_div::trimExplode(',', $itemList, true);
00580
00581 foreach ($itemParts as $itemPart) {
00582 $itemDetails = t3lib_div::trimExplode(';', $itemPart, false, 5);
00583 $key = $itemDetails[0];
00584 if (strstr($key, '--')) {
00585
00586 $key.= count($items);
00587 }
00588
00589 if (!isset($items[$key])) {
00590 $items[$key] = array(
00591 'rawData' => $itemPart,
00592 'details' => array(
00593 'field' => $itemDetails[0],
00594 'label' => $itemDetails[1],
00595 'palette' => $itemDetails[2],
00596 'special' => $itemDetails[3],
00597 'styles' => $itemDetails[4],
00598 ),
00599 );
00600 }
00601 }
00602
00603 return $items;
00604 }
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615 protected static function generateItemList(array $items, $useRawData = false) {
00616 $itemParts = array();
00617
00618 foreach ($items as $item => $itemDetails) {
00619 if (strstr($item, '--')) {
00620
00621 $item = preg_replace('/[0-9]+$/', '', $item);
00622 }
00623
00624 if ($useRawData) {
00625 $itemParts[] = $itemDetails['rawData'];
00626 } else {
00627 $itemParts[] = (count($itemDetails['details']) > 1 ? implode(';', $itemDetails['details']) : $item);
00628 }
00629 }
00630
00631 return implode(', ', $itemParts);
00632 }
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643 public static function allowTableOnStandardPages($table) {
00644 global $PAGES_TYPES;
00645
00646 $PAGES_TYPES['default']['allowedTables'].=','.$table;
00647 }
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 public static function addModule($main, $sub = '', $position = '', $path = '') {
00661 global $TBE_MODULES;
00662
00663 if (isset($TBE_MODULES[$main]) && $sub) {
00664
00665
00666 list($place, $modRef) = t3lib_div::trimExplode(':', $position, 1);
00667 $mods = t3lib_div::trimExplode(',', $TBE_MODULES[$main], 1);
00668 if (!in_array($sub, $mods)) {
00669 switch(strtolower($place)) {
00670 case 'after':
00671 case 'before':
00672 $pointer = 0;
00673 foreach ($mods as $k => $m) {
00674 if (!strcmp($m, $modRef)) {
00675 $pointer = strtolower($place)=='after'?$k+1:$k;
00676 }
00677 }
00678 array_splice(
00679 $mods,
00680 $pointer,
00681 0,
00682 $sub
00683 );
00684 break;
00685 default:
00686 if (strtolower($place)=='top') {
00687 array_unshift($mods, $sub);
00688 } else {
00689 array_push($mods, $sub);
00690 }
00691 break;
00692 }
00693 }
00694
00695 $TBE_MODULES[$main] = implode(',', $mods);
00696 } else {
00697 $TBE_MODULES[$main] = $sub;
00698 }
00699
00700
00701 if ($path) {
00702 $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')] = $path;
00703 }
00704 }
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717 public static function addModulePath($name, $path) {
00718 global $TBE_MODULES;
00719
00720 $TBE_MODULES['_PATHS'][$name] = $path;
00721 }
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739 public static function insertModuleFunction($modname, $className, $classPath, $title, $MM_key = 'function', $WS = '') {
00740 global $TBE_MODULES_EXT;
00741 $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className] = array(
00742 'name' => $className,
00743 'path' => $classPath,
00744 'title' => $title,
00745 'ws' => $WS
00746 );
00747 }
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758 public static function addPageTSConfig($content) {
00759 global $TYPO3_CONF_VARS;
00760 $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
00761 }
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772 public static function addUserTSConfig($content) {
00773 global $TYPO3_CONF_VARS;
00774 $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
00775 }
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787 public static function addLLrefForTCAdescr($tca_descr_key, $file_ref) {
00788 global $TCA_DESCR;
00789 if ($tca_descr_key) {
00790 if (!is_array($TCA_DESCR[$tca_descr_key])) {
00791 $TCA_DESCR[$tca_descr_key] = array();
00792 }
00793 if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
00794 $TCA_DESCR[$tca_descr_key]['refs'] = array();
00795 }
00796 $TCA_DESCR[$tca_descr_key]['refs'][] = $file_ref;
00797 }
00798 }
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829 public static function addService($extKey, $serviceType, $serviceKey, $info) {
00830 global $T3_SERVICES, $TYPO3_CONF_VARS;
00831
00832
00833
00834
00835 if ($serviceType &&
00836 !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') &&
00837 (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') || t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) &&
00838 is_array($info)) {
00839
00840 $info['priority'] = max(0, min(100, $info['priority']));
00841
00842 $T3_SERVICES[$serviceType][$serviceKey] = $info;
00843
00844 $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
00845 $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
00846 $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
00847
00848
00849
00850
00851
00852 $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
00853
00854
00855
00856
00857
00858 if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
00859
00860
00861 $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey], $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
00862 }
00863
00864
00865
00866
00867 if ($T3_SERVICES[$serviceType][$serviceKey]['available'] && $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
00868
00869
00870 $os_type = stristr(PHP_OS, 'win')&&!stristr(PHP_OS, 'darwin')?'WIN':'UNIX';
00871
00872 $os = t3lib_div::trimExplode(',', strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
00873
00874 if (!in_array($os_type, $os)) {
00875 self::deactivateService($serviceType, $serviceKey);
00876 }
00877 }
00878
00879
00880 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
00881 $serviceSubTypes = t3lib_div::trimExplode(',', $info['subtype']);
00882 foreach ($serviceSubTypes as $subtype) {
00883 $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
00884 }
00885 }
00886 }
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897 public static function findService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) {
00898 global $T3_SERVICES, $TYPO3_CONF_VARS;
00899
00900 $serviceKey = FALSE;
00901 $serviceInfo = FALSE;
00902 $priority = 0;
00903 $quality = 0;
00904
00905 if (!is_array($excludeServiceKeys) ) {
00906 $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
00907 }
00908
00909 if (is_array($T3_SERVICES[$serviceType])) {
00910 foreach($T3_SERVICES[$serviceType] as $key => $info) {
00911
00912 if (in_array($key, $excludeServiceKeys)) {
00913 continue;
00914 }
00915
00916
00917
00918 if ($serviceSubType=='*') {
00919 $serviceSubType = key($info['serviceSubTypes']);
00920 }
00921
00922
00923 if ($info['available'] && ($info['subtype']==$serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority']>=$priority ) {
00924
00925
00926 if($info['priority']==$priority && $info['quality']<$quality) {
00927 continue;
00928 }
00929
00930
00931 if(trim($info['exec'])) {
00932 $executables = t3lib_div::trimExplode(',', $info['exec'], 1);
00933 foreach($executables as $executable) {
00934 if(!t3lib_exec::checkCommand($executable)) {
00935 self::deactivateService($serviceType, $key);
00936 $info['available'] = FALSE;
00937 break;
00938 }
00939 }
00940 }
00941
00942
00943 if($info['available']) {
00944 $serviceKey = $key;
00945 $priority = $info['priority'];
00946 $quality = $info['quality'];
00947 }
00948 }
00949 }
00950 }
00951
00952 if ($serviceKey) {
00953 $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
00954 }
00955 return $serviceInfo;
00956 }
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966 public static function deactivateService($serviceType, $serviceKey) {
00967 global $T3_SERVICES;
00968
00969
00970 $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
00971 }
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005 public static function addPlugin($itemArray, $type = 'list_type') {
01006 global $TCA;
01007
01008 $_EXTKEY = $GLOBALS['_EXTKEY'];
01009 if ($_EXTKEY && !$itemArray[2]) {
01010 $itemArray[2] = self::extRelPath($_EXTKEY) . 'ext_icon.gif';
01011 }
01012
01013 t3lib_div::loadTCA('tt_content');
01014 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
01015 foreach ($TCA['tt_content']['columns'][$type]['config']['items'] as $k => $v) {
01016 if (!strcmp($v[1], $itemArray[1])) {
01017 $TCA['tt_content']['columns'][$type]['config']['items'][$k] = $itemArray;
01018 return;
01019 }
01020 }
01021 $TCA['tt_content']['columns'][$type]['config']['items'][] = $itemArray;
01022 }
01023 }
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036 public static function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch = 'list') {
01037 global $TCA;
01038 t3lib_div::loadTCA('tt_content');
01039
01040 if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
01041 $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch.','.$CTypeToMatch] = $value;
01042 }
01043 }
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 public static function addToInsertRecords($table, $content_table = 'tt_content', $content_field = 'records') {
01057 global $TCA;
01058 t3lib_div::loadTCA($content_table);
01059 if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
01060 $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
01061 }
01062 }
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087 public static function addPItoST43($key, $classFile = '', $prefix = '', $type = 'list_type', $cached = 0) {
01088 global $TYPO3_LOADED_EXT;
01089 $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_', '', $key).$prefix.'.php';
01090 $cN = self::getCN($key);
01091
01092
01093 $pluginContent = trim('
01094 plugin.'.$cN.$prefix.' = USER' . ($cached ? '' : '_INT') . '
01095 plugin.'.$cN.$prefix.' {
01096 includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
01097 userFunc = '.$cN.$prefix.'->main
01098 }');
01099 self::addTypoScript($key, 'setup', '
01100 # Setting '.$key.' plugin TypoScript
01101 '.$pluginContent);
01102
01103
01104 switch($type) {
01105 case 'list_type':
01106 $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
01107 break;
01108 case 'menu_type':
01109 $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
01110 break;
01111 case 'splash_layout':
01112 $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
01113 break;
01114 case 'CType':
01115 $addLine = trim('
01116 tt_content.'.$key.$prefix.' = COA
01117 tt_content.'.$key.$prefix.' {
01118 10 = < lib.stdheader
01119 20 = < plugin.'.$cN.$prefix.'
01120 }
01121 ');
01122 break;
01123 case 'header_layout':
01124 $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
01125 break;
01126 case 'includeLib':
01127 $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
01128 break;
01129 default:
01130 $addLine = '';
01131 break;
01132 }
01133 if ($addLine) {
01134 self::addTypoScript($key, 'setup', '
01135 # Setting '.$key.' plugin TypoScript
01136 '.$addLine.'
01137 ', 43);
01138 }
01139 }
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153 public static function addStaticFile($extKey, $path, $title) {
01154 global $TCA;
01155 t3lib_div::loadTCA('sys_template');
01156 if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
01157 $value = str_replace(',', '', 'EXT:'.$extKey.'/'.$path);
01158 $itemArray = array(trim($title.' ('.$extKey.')'), $value);
01159 $TCA['sys_template']['columns']['include_static_file']['config']['items'][] = $itemArray;
01160 }
01161 }
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172 public static function addTypoScriptSetup($content) {
01173 global $TYPO3_CONF_VARS;
01174 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
01175 }
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186 public static function addTypoScriptConstants($content) {
01187 global $TYPO3_CONF_VARS;
01188 $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
01189 }
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203 public static function addTypoScript($key, $type, $content, $afterStaticUid = 0) {
01204 global $TYPO3_CONF_VARS;
01205
01206 if ($type=='setup' || $type=='editorcfg' || $type=='constants') {
01207 $content = '
01208
01209 [GLOBAL]
01210 #############################################
01211 ## TypoScript added by extension "'.$key.'"
01212 #############################################
01213
01214 '.$content;
01215 if ($afterStaticUid) {
01216 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
01217
01218 if ($afterStaticUid==43 && is_array($TYPO3_CONF_VARS['FE']['contentRenderingTemplates'])) {
01219 foreach ($TYPO3_CONF_VARS['FE']['contentRenderingTemplates'] as $templateName) {
01220 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$templateName] .= $content;
01221 }
01222 }
01223 } else {
01224 $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
01225 }
01226 }
01227 }
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269 public static function typo3_loadExtensions() {
01270 global $TYPO3_CONF_VARS;
01271
01272
01273 if (TYPO3_MODE == 'FE') {
01274 if (!($extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList_FE'])) {
01275
01276 $extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList'];
01277 }
01278 $cacheFileSuffix = '_FE';
01279 } else {
01280 $extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList'];
01281
01282 $cacheFileSuffix = '';
01283 }
01284
01285 $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'] . ',' . $extLoadInContext;
01286
01287
01288 $extensions = array();
01289
01290
01291 if ($rawExtList) {
01292
01293 $cacheFilePrefix = 'temp_CACHED' . $cacheFileSuffix;
01294
01295 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1) $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']), 0, 4);
01296 if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
01297
01298
01299 if ($TYPO3_CONF_VARS['EXT']['extCache'] && self::isCacheFilesAvailable($cacheFilePrefix)) {
01300
01301 $extensions['_CACHEFILE'] = $cacheFilePrefix;
01302 } else {
01303
01304
01305 $files = array('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');
01306
01307 clearstatcache();
01308 $temp_extensions = array_unique(t3lib_div::trimExplode(',', $rawExtList, 1));
01309 foreach($temp_extensions as $temp_extKey) {
01310
01311 if (@is_dir(PATH_typo3conf.'ext/'.$temp_extKey.'/')) {
01312 $extensions[$temp_extKey] = array('type'=>'L', 'siteRelPath'=>'typo3conf/ext/'.$temp_extKey.'/', 'typo3RelPath'=>'../typo3conf/ext/'.$temp_extKey.'/');
01313 } elseif (@is_dir(PATH_typo3.'ext/'.$temp_extKey.'/')) {
01314 $extensions[$temp_extKey] = array('type'=>'G', 'siteRelPath'=>TYPO3_mainDir.'ext/'.$temp_extKey.'/', 'typo3RelPath'=>'ext/'.$temp_extKey.'/');
01315 } elseif (@is_dir(PATH_typo3.'sysext/'.$temp_extKey.'/')) {
01316 $extensions[$temp_extKey] = array('type'=>'S', 'siteRelPath'=>TYPO3_mainDir.'sysext/'.$temp_extKey.'/', 'typo3RelPath'=>'sysext/'.$temp_extKey.'/');
01317 }
01318
01319
01320 if (isset($extensions[$temp_extKey])) {
01321 foreach($files as $fName) {
01322 $temp_filename = PATH_site.$extensions[$temp_extKey]['siteRelPath'].trim($fName);
01323 if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
01324 $extensions[$temp_extKey][$fName] = $temp_filename;
01325 }
01326 }
01327 }
01328 }
01329 unset($extensions['_CACHEFILE']);
01330
01331
01332 if ($TYPO3_CONF_VARS['EXT']['extCache'] &&
01333 @is_dir(PATH_typo3.'sysext/') &&
01334 @is_dir(PATH_typo3.'ext/')) {
01335 $wrError = self::cannotCacheFilesWritable($cacheFilePrefix);
01336 if ($wrError) {
01337 $TYPO3_CONF_VARS['EXT']['extCache'] = 0;
01338 } else {
01339
01340 $extensions = self::writeCacheFiles($extensions, $cacheFilePrefix);
01341 }
01342 }
01343 }
01344 }
01345
01346 return $extensions;
01347 }
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357 public static function _makeIncludeHeader($key, $file) {
01358 return '<?php
01359 ###########################
01360 ## EXTENSION: '.$key.'
01361 ## FILE: '.$file.'
01362 ###########################
01363
01364 $_EXTKEY = \''.$key.'\';
01365 $_EXTCONF = $TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][$_EXTKEY];
01366
01367 ?>';
01368 }
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378 public static function isCacheFilesAvailable($cacheFilePrefix) {
01379 return
01380 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
01381 @is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php');
01382 }
01383
01384
01385
01386
01387
01388
01389
01390
01391 public static function isLocalconfWritable() {
01392 return @is_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf.'localconf.php');
01393 }
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404 public static function cannotCacheFilesWritable($cacheFilePrefix) {
01405 $error = array();
01406 if (!@is_writable(PATH_typo3conf)) {
01407 $error[] = PATH_typo3conf;
01408 }
01409 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php') &&
01410 !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php')) {
01411 $error[] = PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
01412 }
01413 if (@is_file(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php') &&
01414 !@is_writable(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php')) {
01415 $error[] = PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
01416 }
01417 return implode(', ', $error);
01418 }
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428 public static function currentCacheFiles() {
01429 if (($cacheFilePrefix = $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'])) {
01430 $cacheFilePrefixFE = str_replace('temp_CACHED','temp_CACHED_FE',$cacheFilePrefix);
01431 $files = array();
01432 if (self::isCacheFilesAvailable($cacheFilePrefix)) {
01433 $files[] = PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php';
01434 $files[] = PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php';
01435 }
01436 if (self::isCacheFilesAvailable($cacheFilePrefixFE)) {
01437 $files[] = PATH_typo3conf.$cacheFilePrefixFE.'_ext_localconf.php';
01438 $files[] = PATH_typo3conf.$cacheFilePrefixFE.'_ext_tables.php';
01439 }
01440 if (!empty($files)) {
01441 return $files;
01442 }
01443 }
01444 }
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456 public static function writeCacheFiles($extensions, $cacheFilePrefix) {
01457
01458 $extensions['_CACHEFILE'] = $cacheFilePrefix;
01459 $cFiles = array();
01460 $cFiles['ext_localconf'].='<?php
01461
01462 $TYPO3_LOADED_EXT = unserialize(stripslashes(\''.addslashes(serialize($extensions)).'\'));
01463
01464 ?>';
01465
01466 foreach ($extensions as $key => $conf) {
01467 if (is_array($conf)) {
01468 if ($conf['ext_localconf.php']) {
01469 $cFiles['ext_localconf'] .= self::_makeIncludeHeader($key, $conf['ext_localconf.php']);
01470 $cFiles['ext_localconf'] .= trim(t3lib_div::getUrl($conf['ext_localconf.php']));
01471 }
01472 if ($conf['ext_tables.php']) {
01473 $cFiles['ext_tables'] .= self::_makeIncludeHeader($key, $conf['ext_tables.php']);
01474 $cFiles['ext_tables'] .= trim(t3lib_div::getUrl($conf['ext_tables.php']));
01475 }
01476 }
01477 }
01478
01479 $cFiles['ext_localconf'] = "<?php\n" . preg_replace('/<\?php|\?>/is', '', $cFiles['ext_localconf']) . "?>\n";
01480 $cFiles['ext_tables'] = "<?php\n" . preg_replace('/<\?php|\?>/is', '', $cFiles['ext_tables']) . "?>\n";
01481
01482 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_localconf.php', $cFiles['ext_localconf']);
01483 t3lib_div::writeFile(PATH_typo3conf.$cacheFilePrefix.'_ext_tables.php', $cFiles['ext_tables']);
01484
01485 $extensions = array();
01486 $extensions['_CACHEFILE'] = $cacheFilePrefix;
01487
01488 return $extensions;
01489 }
01490
01491
01492
01493
01494
01495
01496 public static function removeCacheFiles() {
01497 $cacheFiles = self::currentCacheFiles();
01498 $out = 0;
01499 if (is_array($cacheFiles)) {
01500 reset($cacheFiles);
01501 foreach($cacheFiles as $cfile) {
01502 @unlink($cfile);
01503 clearstatcache();
01504 $out++;
01505 }
01506 }
01507 return $out;
01508 }
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520 public function createListViewLink($id, $additionalParams = '', $linkTitle = '', $linkText = '', $linkOnly = FALSE) {
01521 if (!self::isLoaded('list') || !$GLOBALS['BE_USER']->check('modules', 'web_list')) {
01522 return '';
01523 }
01524 $href = $GLOBALS['BACK_PATH'] . self::extRelPath('list') . 'mod1/db_list.php?id=' .
01525 $id . $additionalParams;
01526 if ($linkOnly) {
01527 return $href;
01528 } else {
01529 return '<a href="' . htmlspecialchars($href) . '" title="' . htmlspecialchars($linkTitle) . '">' .
01530 t3lib_iconWorks::getSpriteIcon('actions-system-list-open') .
01531 $linkText .
01532 '</a>';
01533 }
01534 }
01535 }
01536
01537 ?>