PageRenderTime 63ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/t3lib/class.t3lib_extmgm.php

https://bitbucket.org/linxpinx/mercurial
PHP | 1511 lines | 683 code | 187 blank | 641 comment | 132 complexity | 7c3a1037be63b71d5ed8091937a2a6b5 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. * A copy is found in the textfile GPL.txt and important notices to the license
  17. * from the author is found in LICENSE.txt distributed with these scripts.
  18. *
  19. *
  20. * This script is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * This copyright notice MUST APPEAR in all copies of the script!
  26. ***************************************************************/
  27. /**
  28. * Contains a class with Extension Management functions
  29. *
  30. * $Id: class.t3lib_extmgm.php 7905 2010-06-13 14:42:33Z ohader $
  31. * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
  32. *
  33. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  34. */
  35. /**
  36. * [CLASS/FUNCTION INDEX of SCRIPT]
  37. *
  38. *
  39. *
  40. * 114: class t3lib_extMgm
  41. *
  42. * SECTION: PATHS and other evaluation
  43. * 131: function isLoaded($key,$exitOnError = 0)
  44. * 147: function extPath($key,$script='')
  45. * 165: function extRelPath($key)
  46. * 182: function siteRelPath($key)
  47. * 194: function getCN($key)
  48. *
  49. * SECTION: Adding BACKEND features
  50. * 227: function addTCAcolumns($table,$columnArray,$addTofeInterface=0)
  51. * 251: function addToAllTCAtypes($table,$str,$specificTypesList='',$position='')
  52. * 309: function allowTableOnStandardPages($table)
  53. * 326: function addModule($main,$sub='',$position='',$path='')
  54. * 389: function insertModuleFunction($modname,$className,$classPath,$title,$MM_key='function',$WS='')
  55. * 408: function addPageTSConfig($content)
  56. * 422: function addUserTSConfig($content)
  57. * 437: function addLLrefForTCAdescr($tca_descr_key,$file_ref)
  58. *
  59. * SECTION: Adding SERVICES features
  60. * 479: function addService($extKey, $serviceType, $serviceKey, $info)
  61. * 547: function findService($serviceType, $serviceSubType='', $excludeServiceKeys=array())
  62. * 618: function deactivateService($serviceType, $serviceKey)
  63. *
  64. * SECTION: Adding FRONTEND features
  65. * 657: function addPlugin($itemArray,$type='list_type')
  66. * 682: function addPiFlexFormValue($piKeyToMatch,$value)
  67. * 702: function addToInsertRecords($table,$content_table='tt_content',$content_field='records')
  68. * 733: function addPItoST43($key,$classFile='',$prefix='',$type='list_type',$cached=0)
  69. * 808: function addStaticFile($extKey,$path,$title)
  70. * 827: function addTypoScriptSetup($content)
  71. * 841: function addTypoScriptConstants($content)
  72. * 858: function addTypoScript($key,$type,$content,$afterStaticUid=0)
  73. *
  74. * SECTION: INTERNAL EXTENSION MANAGEMENT:
  75. * 921: function typo3_loadExtensions()
  76. * 998: function _makeIncludeHeader($key,$file)
  77. * 1019: function isCacheFilesAvailable($cacheFilePrefix)
  78. * 1032: function isLocalconfWritable()
  79. * 1045: function cannotCacheFilesWritable($cacheFilePrefix)
  80. * 1069: function currentCacheFiles()
  81. * 1092: function writeCacheFiles($extensions,$cacheFilePrefix)
  82. * 1130: function removeCacheFiles()
  83. *
  84. * TOTAL FUNCTIONS: 32
  85. * (This index is automatically created/updated by the extension "extdeveval")
  86. *
  87. */
  88. /**
  89. * Extension Management functions
  90. *
  91. * This class is never instantiated, rather the methods inside is called as functions like
  92. * t3lib_extMgm::isLoaded('my_extension');
  93. *
  94. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  95. * @package TYPO3
  96. * @subpackage t3lib
  97. */
  98. final class t3lib_extMgm {
  99. protected static $extensionKeyMap;
  100. /**************************************
  101. *
  102. * PATHS and other evaluation
  103. *
  104. ***************************************/
  105. /**
  106. * Returns true if the extension with extension key $key is loaded.
  107. * Usage: 109
  108. *
  109. * @param string Extension key to test
  110. * @param boolean If $exitOnError is true and the extension is not loaded the function will die with an error message
  111. * @return boolean
  112. */
  113. public static function isLoaded($key, $exitOnError = 0) {
  114. global $TYPO3_LOADED_EXT;
  115. if ($exitOnError && !isset($TYPO3_LOADED_EXT[$key])) {
  116. throw new BadFunctionCallException(
  117. 'TYPO3 Fatal Error: Extension "' . $key . '" was not loaded!',
  118. 1270853910
  119. );
  120. }
  121. return isset($TYPO3_LOADED_EXT[$key]);
  122. }
  123. /**
  124. * Returns the absolute path to the extension with extension key $key
  125. * If the extension is not loaded the function will die with an error message
  126. * Useful for internal fileoperations
  127. * Usage: 136
  128. *
  129. * @param string Extension key
  130. * @param string $script is appended to the output if set.
  131. * @return string
  132. */
  133. public static function extPath($key, $script = '') {
  134. global $TYPO3_LOADED_EXT;
  135. if (!isset($TYPO3_LOADED_EXT[$key])) {
  136. throw new BadFunctionCallException(
  137. 'TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!',
  138. 1270853878
  139. );
  140. }
  141. return PATH_site.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$script;
  142. }
  143. /**
  144. * Returns the relative path to the extension as measured from from the TYPO3_mainDir
  145. * If the extension is not loaded the function will die with an error message
  146. * Useful for images and links from backend
  147. * Usage: 54
  148. *
  149. * @param string Extension key
  150. * @return string
  151. */
  152. public static function extRelPath($key) {
  153. global $TYPO3_LOADED_EXT;
  154. if (!isset($TYPO3_LOADED_EXT[$key])) {
  155. throw new BadFunctionCallException(
  156. 'TYPO3 Fatal Error: Extension key "'.$key.'" was NOT loaded!',
  157. 1270853879
  158. );
  159. }
  160. return $TYPO3_LOADED_EXT[$key]['typo3RelPath'];
  161. }
  162. /**
  163. * Returns the relative path to the extension as measured from the PATH_site (frontend)
  164. * If the extension is not loaded the function will die with an error message
  165. * Useful for images and links from the frontend
  166. * Usage: 6
  167. *
  168. * @param string Extension key
  169. * @return string
  170. */
  171. public static function siteRelPath($key) {
  172. return substr(self::extPath($key), strlen(PATH_site));
  173. }
  174. /**
  175. * Returns the correct class name prefix for the extension key $key
  176. * Usage: 3
  177. *
  178. * @param string Extension key
  179. * @return string
  180. * @internal
  181. */
  182. public static function getCN($key) {
  183. return substr($key, 0, 5)=='user_' ? 'user_'.str_replace('_', '', substr($key, 5)) : 'tx_'.str_replace('_', '', $key);
  184. }
  185. /**
  186. * Returns the real extension key like 'tt_news' from an extension prefix like 'tx_ttnews'.
  187. *
  188. * @param string $prefix: The extension prefix (e.g. 'tx_ttnews')
  189. * @return mixed Real extension key (string) or false (boolean) if something went wrong
  190. */
  191. public static function getExtensionKeyByPrefix($prefix) {
  192. $result = false;
  193. // Build map of short keys referencing to real keys:
  194. if (!isset(self::$extensionKeyMap)) {
  195. self::$extensionKeyMap = array();
  196. foreach (array_keys($GLOBALS['TYPO3_LOADED_EXT']) as $extensionKey) {
  197. $shortKey = str_replace('_', '', $extensionKey);
  198. self::$extensionKeyMap[$shortKey] = $extensionKey;
  199. }
  200. }
  201. // Lookup by the given short key:
  202. $parts = explode('_', $prefix);
  203. if (isset(self::$extensionKeyMap[$parts[1]])) {
  204. $result = self::$extensionKeyMap[$parts[1]];
  205. }
  206. return $result;
  207. }
  208. /**
  209. * Clears the extension key map.
  210. *
  211. * @return void
  212. */
  213. public static function clearExtensionKeyMap() {
  214. self::$extensionKeyMap = NULL;
  215. }
  216. /**
  217. * Retrieves the version of an installed extension.
  218. * If the extension is not installed, this function returns an empty string.
  219. *
  220. * @param string $key the key of the extension to look up, must not be empty
  221. * @return string the extension version as a string in the format "x.y.z",
  222. * will be an empty string if the extension is not loaded
  223. */
  224. public static function getExtensionVersion($key) {
  225. if (!is_string($key) || empty($key)) {
  226. throw new InvalidArgumentException('Extension key must be a non-empty string.');
  227. }
  228. if (!self::isLoaded($key)) {
  229. return '';
  230. }
  231. $_EXTKEY = $key;
  232. include(self::extPath($key) . 'ext_emconf.php');
  233. return $EM_CONF[$key]['version'];
  234. }
  235. /**************************************
  236. *
  237. * Adding BACKEND features
  238. * (related to core features)
  239. *
  240. ***************************************/
  241. /**
  242. * Adding fields to an existing table definition in $TCA
  243. * Adds an array with $TCA column-configuration to the $TCA-entry for that table.
  244. * 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!
  245. * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
  246. * FOR USE IN ext_tables.php FILES
  247. * Usage: 4
  248. *
  249. * @param string $table is the table name of a table already present in $TCA with a columns section
  250. * @param array $columnArray is the array with the additional columns (typical some fields an extension wants to add)
  251. * @param boolean If $addTofeInterface is true the list of fields are also added to the fe_admin_fieldList.
  252. * @return void
  253. */
  254. public static function addTCAcolumns($table, $columnArray, $addTofeInterface = 0) {
  255. global $TCA;
  256. t3lib_div::loadTCA($table);
  257. if (is_array($columnArray) && is_array($TCA[$table]) && is_array($TCA[$table]['columns'])) {
  258. $TCA[$table]['columns'] = array_merge($TCA[$table]['columns'], $columnArray); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
  259. if ($addTofeInterface) $TCA[$table]['feInterface']['fe_admin_fieldList'].=','.implode(',', array_keys($columnArray));
  260. }
  261. }
  262. /**
  263. * Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
  264. *
  265. * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
  266. * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
  267. * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
  268. * FOR USE IN ext_tables.php FILES
  269. * Usage: 1
  270. *
  271. * @param string Table name
  272. * @param string Field list to add.
  273. * @param string List of specific types to add the field list to. (If empty, all type entries are affected)
  274. * @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.
  275. * @return void
  276. */
  277. public static function addToAllTCAtypes($table, $str, $specificTypesList = '', $position = '') {
  278. t3lib_div::loadTCA($table);
  279. $str = trim($str);
  280. if ($str && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['types'])) {
  281. foreach($GLOBALS['TCA'][$table]['types'] as $type => &$typeDetails) {
  282. if ($specificTypesList === '' || t3lib_div::inList($specificTypesList, $type)) {
  283. $typeDetails['showitem'] = self::executePositionedStringInsertion(
  284. $typeDetails['showitem'],
  285. $str,
  286. $position
  287. );
  288. }
  289. }
  290. }
  291. }
  292. /**
  293. * Adds new fields to all palettes of an existing field.
  294. * If the field does not have a palette yet, it's created automatically and
  295. * gets called "generatedFor-$field".
  296. *
  297. * @param string $table: Name of the table
  298. * @param string $field: Name of the field that has the palette to be extended
  299. * @param string $addFields: List of fields to be added to the palette
  300. * @param string $insertionPosition: Insert fields before (default) or after one
  301. * of this fields (commalist with "before:" or "after:" commands).
  302. * Example: "before:keywords,--palette--;;4,after:description".
  303. * Palettes must be passed like in the example no matter how the
  304. * palette definition looks like in TCA.
  305. * @return void
  306. */
  307. public static function addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
  308. $generatedPalette = '';
  309. $processedPalettes = array();
  310. t3lib_div::loadTCA($table);
  311. if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
  312. $types =& $GLOBALS['TCA'][$table]['types'];
  313. if (is_array($types)) {
  314. // Iterate through all types and search for the field that defines the palette to be extended:
  315. foreach (array_keys($types) as $type) {
  316. $items = self::explodeItemList($types[$type]['showitem']);
  317. if (isset($items[$field])) {
  318. // If the field already has a palette, extend it:
  319. if ($items[$field]['details']['palette']) {
  320. $palette = $items[$field]['details']['palette'];
  321. if (!isset($processedPalettes[$palette])) {
  322. self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
  323. $processedPalettes[$palette] = true;
  324. }
  325. // If there's not palette yet, create one:
  326. } else {
  327. if ($generatedPalette) {
  328. $palette = $generatedPalette;
  329. } else {
  330. $palette = $generatedPalette = 'generatedFor-' . $field;
  331. self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
  332. }
  333. $items[$field]['details']['palette'] = $palette;
  334. $types[$type]['showitem'] = self::generateItemList($items);
  335. }
  336. }
  337. }
  338. }
  339. }
  340. }
  341. /**
  342. * Adds new fields to a palette.
  343. * If the palette does not exist yet, it's created automatically.
  344. *
  345. * @param string $table: Name of the table
  346. * @param string $palette: Name of the palette to be extended
  347. * @param string $addFields: List of fields to be added to the palette
  348. * @param string $insertionPosition: Insert fields before (default) or after one
  349. * of this fields (commalist with "before:" or "after:" commands).
  350. * Example: "before:keywords,--palette--;;4,after:description".
  351. * Palettes must be passed like in the example no matter how the
  352. * palette definition looks like in TCA.
  353. * @return void
  354. */
  355. public static function addFieldsToPalette($table, $palette, $addFields, $insertionPosition = '') {
  356. t3lib_div::loadTCA($table);
  357. if (isset($GLOBALS['TCA'][$table])) {
  358. $paletteData =& $GLOBALS['TCA'][$table]['palettes'][$palette];
  359. // If palette already exists, merge the data:
  360. if (is_array($paletteData)) {
  361. $paletteData['showitem'] = self::executePositionedStringInsertion(
  362. $paletteData['showitem'],
  363. $addFields,
  364. $insertionPosition
  365. );
  366. // If it's a new palette, just set the data:
  367. } else {
  368. $paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields);
  369. }
  370. }
  371. }
  372. /**
  373. * Adds a list of new fields to the TYPO3 USER SETTINGS configuration "showitem" list, the array with
  374. * the new fields itself needs to be added additionally to show up in the user setup, like
  375. * $GLOBALS['TYPO3_USER_SETTINGS']['columns'] += $tempColumns
  376. *
  377. * @param string $addFields: List of fields to be added to the user settings
  378. * @param string $insertionPosition: Insert fields before (default) or after one
  379. * of this fields (commalist with "before:" or "after:" commands).
  380. * Example: "before:password,after:email".
  381. * @return void
  382. */
  383. public function addFieldsToUserSettings($addFields, $insertionPosition = '') {
  384. $GLOBALS['TYPO3_USER_SETTINGS']['showitem'] = self::executePositionedStringInsertion(
  385. $GLOBALS['TYPO3_USER_SETTINGS']['showitem'],
  386. $addFields,
  387. $insertionPosition
  388. );
  389. }
  390. /**
  391. * Inserts as list of data into an existing list.
  392. * The insertion position can be defined accordant before of after existing list items.
  393. *
  394. * @param string $list: The list of items to be extended
  395. * @param string $insertionList: The list of items to inserted
  396. * @param string $insertionPosition: Insert fields before (default) or after one
  397. * of this fields (commalist with "before:" or "after:" commands).
  398. * Example: "before:keywords,--palette--;;4,after:description".
  399. * Palettes must be passed like in the example no matter how the
  400. * palette definition looks like in TCA.
  401. * @return string The extended list
  402. */
  403. protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
  404. $list = trim($list);
  405. $insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
  406. if ($insertionList) {
  407. // Append data to the end (default):
  408. if ($insertionPosition === '') {
  409. $list.= ($list ? ', ' : '') . $insertionList;
  410. // Insert data before or after insertion points:
  411. } else {
  412. $positions = t3lib_div::trimExplode(',', $insertionPosition, true);
  413. $items = self::explodeItemList($list);
  414. $isInserted = false;
  415. // Iterate through all fields an check whether it's possible to inserte there:
  416. foreach ($items as $item => &$itemDetails) {
  417. $needles = self::getInsertionNeedles($item, $itemDetails['details']);
  418. // Insert data before:
  419. foreach ($needles['before'] as $needle) {
  420. if (in_array($needle, $positions)) {
  421. $itemDetails['rawData'] = $insertionList . ', ' . $itemDetails['rawData'];
  422. $isInserted = true;
  423. break;
  424. }
  425. }
  426. // Insert data after:
  427. foreach ($needles['after'] as $needle) {
  428. if (in_array($needle, $positions)) {
  429. $itemDetails['rawData'] .= ', ' . $insertionList;
  430. $isInserted = true;
  431. break;
  432. }
  433. }
  434. // Break if insertion was already done:
  435. if ($isInserted) {
  436. break;
  437. }
  438. }
  439. // If insertion point could not be determined, append the data:
  440. if (!$isInserted) {
  441. $list.= ($list ? ', ' : '') . $insertionList;
  442. // If data was correctly inserted before or after existing items, recreate the list:
  443. } else {
  444. $list = self::generateItemList($items, true);
  445. }
  446. }
  447. }
  448. return $list;
  449. }
  450. /**
  451. * Compares an existing list of items and a list of items to be inserted
  452. * and returns a duplicate-free variant of that insertion list.
  453. *
  454. * Example:
  455. * + list: 'field_a, field_b;;;;2-2-2, field_c;;;;3-3-3'
  456. * + insertion: 'field_b, field_d, field_c;;;4-4-4'
  457. * -> new insertion: 'field_d'
  458. *
  459. * @param string $insertionList: The list of items to inserted
  460. * @param string $list: The list of items to be extended (default: '')
  461. * @return string Duplicate-free list of items to be inserted
  462. */
  463. protected static function removeDuplicatesForInsertion($insertionList, $list = '') {
  464. $pattern = '/(^|,)\s*\b([^;,]+)\b[^,]*/';
  465. $listItems = array();
  466. if ($list && preg_match_all($pattern, $list, $listMatches)) {
  467. $listItems = $listMatches[2];
  468. }
  469. if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
  470. $insertionItems = array();
  471. $insertionDuplicates = false;
  472. foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) {
  473. if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) {
  474. $insertionItems[$insertionItem] = true;
  475. } else {
  476. unset($insertionListMatches[0][$insertionIndex]);
  477. $insertionDuplicates = true;
  478. }
  479. }
  480. if ($insertionDuplicates) {
  481. $insertionList = implode('', $insertionListMatches[0]);
  482. }
  483. }
  484. return $insertionList;
  485. }
  486. /**
  487. * Generates search needles that are used for inserting fields/items into an existing list.
  488. *
  489. * @see executePositionedStringInsertion
  490. * @param string $item: The name of the field/item
  491. * @param array $itemDetails: Additional details of the field/item like e.g. palette information
  492. * (this array gets created by the function explodeItemList())
  493. * @return array The needled to be used for inserting content before or after existing fields/items
  494. */
  495. protected static function getInsertionNeedles($item, array $itemDetails) {
  496. if (strstr($item, '--')) {
  497. // If $item is a separator (--div--) or palette (--palette--) then it may have been appended by a unique number. This must be stripped away here.
  498. $item = preg_replace('/[0-9]+$/', '', $item);
  499. }
  500. $needles = array(
  501. 'before' => array($item, 'before:' . $item),
  502. 'after' => array('after:' . $item),
  503. );
  504. if ($itemDetails['palette']) {
  505. $palette = $item . ';;' . $itemDetails['palette'];
  506. $needles['before'][] = $palette;
  507. $needles['before'][] = 'before:' . $palette;
  508. $needles['after'][] = 'after:' . $palette;
  509. }
  510. return $needles;
  511. }
  512. /**
  513. * Generates an array of fields/items with additional information such as e.g. the name of the palette.
  514. *
  515. * @param string $itemList: List of fields/items to be splitted up
  516. * (this mostly reflects the data in $TCA[<table>]['types'][<type>]['showitem'])
  517. * @return array An array with the names of the fields/items as keys and additional information
  518. */
  519. protected static function explodeItemList($itemList) {
  520. $items = array();
  521. $itemParts = t3lib_div::trimExplode(',', $itemList, true);
  522. foreach ($itemParts as $itemPart) {
  523. $itemDetails = t3lib_div::trimExplode(';', $itemPart, false, 5);
  524. $key = $itemDetails[0];
  525. if (strstr($key, '--')) {
  526. // If $key is a separator (--div--) or palette (--palette--) then it will be appended by a unique number. This must be removed again when using this value!
  527. $key.= count($items);
  528. }
  529. if (!isset($items[$key])) {
  530. $items[$key] = array(
  531. 'rawData' => $itemPart,
  532. 'details' => array(
  533. 'field' => $itemDetails[0],
  534. 'label' => $itemDetails[1],
  535. 'palette' => $itemDetails[2],
  536. 'special' => $itemDetails[3],
  537. 'styles' => $itemDetails[4],
  538. ),
  539. );
  540. }
  541. }
  542. return $items;
  543. }
  544. /**
  545. * Generates a list of fields/items out of an array provided by the function getFieldsOfFieldList().
  546. *
  547. * @see explodeItemList
  548. * @param array $items: The array of fields/items with optional additional information
  549. * @param boolean $useRawData: Use raw data instead of building by using the details (default: false)
  550. * @return string The list of fields/items which gets used for $TCA[<table>]['types'][<type>]['showitem']
  551. * or $TCA[<table>]['palettes'][<palette>]['showitem'] in most cases
  552. */
  553. protected static function generateItemList(array $items, $useRawData = false) {
  554. $itemParts = array();
  555. foreach ($items as $item => $itemDetails) {
  556. if (strstr($item, '--')) {
  557. // If $item is a separator (--div--) or palette (--palette--) then it may have been appended by a unique number. This must be stripped away here.
  558. $item = preg_replace('/[0-9]+$/', '', $item);
  559. }
  560. if ($useRawData) {
  561. $itemParts[] = $itemDetails['rawData'];
  562. } else {
  563. $itemParts[] = (count($itemDetails['details']) > 1 ? implode(';', $itemDetails['details']) : $item);
  564. }
  565. }
  566. return implode(', ', $itemParts);
  567. }
  568. /**
  569. * Add tablename to default list of allowed tables on pages (in $PAGES_TYPES)
  570. * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
  571. * FOR USE IN ext_tables.php FILES
  572. * Usage: 11
  573. *
  574. * @param string Table name
  575. * @return void
  576. */
  577. public static function allowTableOnStandardPages($table) {
  578. global $PAGES_TYPES;
  579. $PAGES_TYPES['default']['allowedTables'].=','.$table;
  580. }
  581. /**
  582. * Adds a module (main or sub) to the backend interface
  583. * FOR USE IN ext_tables.php FILES
  584. * Usage: 18
  585. *
  586. * @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.
  587. * @param string $sub is the submodule key. If $sub is not set a blank $main module is created.
  588. * @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.
  589. * @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.
  590. * @return void
  591. */
  592. public static function addModule($main, $sub = '', $position = '', $path = '') {
  593. global $TBE_MODULES;
  594. if (isset($TBE_MODULES[$main]) && $sub) { // If there is already a main module by this name:
  595. // Adding the submodule to the correct position:
  596. list($place, $modRef) = t3lib_div::trimExplode(':', $position, 1);
  597. $mods = t3lib_div::trimExplode(',', $TBE_MODULES[$main], 1);
  598. if (!in_array($sub, $mods)) {
  599. switch(strtolower($place)) {
  600. case 'after':
  601. case 'before':
  602. $pointer = 0;
  603. foreach ($mods as $k => $m) {
  604. if (!strcmp($m, $modRef)) {
  605. $pointer = strtolower($place)=='after'?$k+1:$k;
  606. }
  607. }
  608. array_splice(
  609. $mods, // The modules array
  610. $pointer, // To insert one position from the end of the list
  611. 0, // Don't remove any items, just insert
  612. $sub // Module to insert
  613. );
  614. break;
  615. default:
  616. if (strtolower($place)=='top') {
  617. array_unshift($mods, $sub);
  618. } else {
  619. array_push($mods, $sub);
  620. }
  621. break;
  622. }
  623. }
  624. // Re-inserting the submodule list:
  625. $TBE_MODULES[$main] = implode(',', $mods);
  626. } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank)
  627. $TBE_MODULES[$main] = $sub;
  628. }
  629. // Adding path:
  630. if ($path) {
  631. $TBE_MODULES['_PATHS'][$main.($sub?'_'.$sub:'')] = $path;
  632. }
  633. }
  634. /**
  635. * Adds a module path to TBE_MODULES for used with the module dispatcher, mod.php
  636. * Used only for modules that are not placed in the main/sub menu hierarchy by the traditional mechanism of addModule()
  637. * Examples for this is context menu functionality (like import/export) which runs as an independent module through mod.php
  638. * FOR USE IN ext_tables.php FILES
  639. * Example: t3lib_extMgm::addModulePath('xMOD_tximpexp', t3lib_extMgm::extPath($_EXTKEY).'app/');
  640. *
  641. * @param string $name is the name of the module, refer to conf.php of the module.
  642. * @param string $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
  643. * @return void
  644. */
  645. public static function addModulePath($name, $path) {
  646. global $TBE_MODULES;
  647. $TBE_MODULES['_PATHS'][$name] = $path;
  648. }
  649. /**
  650. * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
  651. * The arguments values are generally determined by which function menu this is supposed to interact with
  652. * See Inside TYPO3 for information on how to use this function.
  653. * FOR USE IN ext_tables.php FILES
  654. * Usage: 26
  655. *
  656. * @param string Module name
  657. * @param string Class name
  658. * @param string Class path
  659. * @param string Title of module
  660. * @param string Menu array key - default is "function"
  661. * @param string Workspace conditions. Blank means all workspaces, any other string can be a comma list of "online", "offline" and "custom"
  662. * @return void
  663. * @see t3lib_SCbase::mergeExternalItems()
  664. */
  665. public static function insertModuleFunction($modname, $className, $classPath, $title, $MM_key = 'function', $WS = '') {
  666. global $TBE_MODULES_EXT;
  667. $TBE_MODULES_EXT[$modname]['MOD_MENU'][$MM_key][$className] = array(
  668. 'name' => $className,
  669. 'path' => $classPath,
  670. 'title' => $title,
  671. 'ws' => $WS
  672. );
  673. }
  674. /**
  675. * Adds $content to the default Page TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultPageTSconfig']
  676. * Prefixed with a [GLOBAL] line
  677. * FOR USE IN ext_tables.php/ext_localconf.php FILES
  678. * Usage: 5
  679. *
  680. * @param string Page TSconfig content
  681. * @return void
  682. */
  683. public static function addPageTSConfig($content) {
  684. global $TYPO3_CONF_VARS;
  685. $TYPO3_CONF_VARS['BE']['defaultPageTSconfig'].="\n[GLOBAL]\n".$content;
  686. }
  687. /**
  688. * Adds $content to the default User TSconfig as set in $TYPO3_CONF_VARS[BE]['defaultUserTSconfig']
  689. * Prefixed with a [GLOBAL] line
  690. * FOR USE IN ext_tables.php/ext_localconf.php FILES
  691. * Usage: 3
  692. *
  693. * @param string User TSconfig content
  694. * @return void
  695. */
  696. public static function addUserTSConfig($content) {
  697. global $TYPO3_CONF_VARS;
  698. $TYPO3_CONF_VARS['BE']['defaultUserTSconfig'].="\n[GLOBAL]\n".$content;
  699. }
  700. /**
  701. * Adds a reference to a locallang file with TCA_DESCR labels
  702. * FOR USE IN ext_tables.php FILES
  703. * 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.
  704. * Usage: 31
  705. *
  706. * @param string Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
  707. * @param string File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
  708. * @return void
  709. */
  710. public static function addLLrefForTCAdescr($tca_descr_key, $file_ref) {
  711. global $TCA_DESCR;
  712. if ($tca_descr_key) {
  713. if (!is_array($TCA_DESCR[$tca_descr_key])) {
  714. $TCA_DESCR[$tca_descr_key] = array();
  715. }
  716. if (!is_array($TCA_DESCR[$tca_descr_key]['refs'])) {
  717. $TCA_DESCR[$tca_descr_key]['refs'] = array();
  718. }
  719. $TCA_DESCR[$tca_descr_key]['refs'][] = $file_ref;
  720. }
  721. }
  722. /**************************************
  723. *
  724. * Adding SERVICES features
  725. *
  726. * @author Rene Fritz <r.fritz@colorcube.de>
  727. *
  728. ***************************************/
  729. /**
  730. * Adds a service to the global services array
  731. *
  732. * @param string Extension key
  733. * @param string Service type, cannot be prefixed "tx_"
  734. * @param string Service key, must be prefixed "tx_" or "user_"
  735. * @param array Service description array
  736. * @return void
  737. * @author Rene Fritz <r.fritz@colorcube.de>
  738. */
  739. public static function addService($extKey, $serviceType, $serviceKey, $info) {
  740. global $T3_SERVICES, $TYPO3_CONF_VARS;
  741. // even not available services will be included to make it possible to give the admin a feedback of non-available services.
  742. // but maybe it's better to move non-available services to a different array??
  743. if ($serviceType &&
  744. !t3lib_div::isFirstPartOfStr($serviceType, 'tx_') &&
  745. (t3lib_div::isFirstPartOfStr($serviceKey, 'tx_') || t3lib_div::isFirstPartOfStr($serviceKey, 'user_')) &&
  746. is_array($info)) {
  747. $info['priority'] = max(0, min(100, $info['priority']));
  748. $T3_SERVICES[$serviceType][$serviceKey] = $info;
  749. $T3_SERVICES[$serviceType][$serviceKey]['extKey'] = $extKey;
  750. $T3_SERVICES[$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
  751. $T3_SERVICES[$serviceType][$serviceKey]['serviceType'] = $serviceType;
  752. // mapping a service key to a service type
  753. // all service keys begin with tx_ - service types don't
  754. // this way a selection of a special service key as service type is easy
  755. $T3_SERVICES[$serviceKey][$serviceKey] = &$T3_SERVICES[$serviceType][$serviceKey];
  756. // change the priority (and other values) from TYPO3_CONF_VARS
  757. // $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]['priority']
  758. // even the activation is possible (a unix service might be possible on windows for some reasons)
  759. if (is_array($TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey])) {
  760. // no check is done here - there might be configuration values only the service type knows about, so we pass everything
  761. $T3_SERVICES[$serviceType][$serviceKey] = array_merge ($T3_SERVICES[$serviceType][$serviceKey], $TYPO3_CONF_VARS['T3_SERVICES'][$serviceType][$serviceKey]);
  762. }
  763. // OS check
  764. // empty $os means 'not limited to one OS', therefore a check is not needed
  765. if ($T3_SERVICES[$serviceType][$serviceKey]['available'] && $T3_SERVICES[$serviceType][$serviceKey]['os']!='') {
  766. // TYPO3_OS is not yet defined
  767. $os_type = stristr(PHP_OS, 'win')&&!stristr(PHP_OS, 'darwin')?'WIN':'UNIX';
  768. $os = t3lib_div::trimExplode(',', strtoupper($T3_SERVICES[$serviceType][$serviceKey]['os']));
  769. if (!in_array($os_type, $os)) {
  770. self::deactivateService($serviceType, $serviceKey);
  771. }
  772. }
  773. // convert subtype list to array for quicker access
  774. $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'] = array();
  775. $serviceSubTypes = t3lib_div::trimExplode(',', $info['subtype']);
  776. foreach ($serviceSubTypes as $subtype) {
  777. $T3_SERVICES[$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
  778. }
  779. }
  780. }
  781. /**
  782. * Find the available service with highest priority
  783. *
  784. * @param string Service type
  785. * @param string Service sub type
  786. * @param mixed Service keys that should be excluded in the search for a service. Array or comma list.
  787. * @return mixed Service info array if a service was found, FLASE otherwise
  788. * @author Rene Fritz <r.fritz@colorcube.de>
  789. */
  790. public static function findService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) {
  791. global $T3_SERVICES, $TYPO3_CONF_VARS;
  792. $serviceKey = FALSE;
  793. $serviceInfo = FALSE;
  794. $priority = 0;
  795. $quality = 0;
  796. if (!is_array($excludeServiceKeys) ) {
  797. $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
  798. }
  799. if (is_array($T3_SERVICES[$serviceType])) {
  800. foreach($T3_SERVICES[$serviceType] as $key => $info) {
  801. if (in_array($key, $excludeServiceKeys)) {
  802. continue;
  803. }
  804. // select a subtype randomly
  805. // usefull to start a service by service key without knowing his subtypes - for testing purposes
  806. if ($serviceSubType=='*') {
  807. $serviceSubType = key($info['serviceSubTypes']);
  808. }
  809. // this matches empty subtype too
  810. if ($info['available'] && ($info['subtype']==$serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority']>=$priority ) {
  811. // has a lower quality than the already found, therefore we skip this service
  812. if($info['priority']==$priority && $info['quality']<$quality) {
  813. continue;
  814. }
  815. // service depends on external programs - check if they exists
  816. if(trim($info['exec'])) {
  817. $executables = t3lib_div::trimExplode(',', $info['exec'], 1);
  818. foreach($executables as $executable) {
  819. if(!t3lib_exec::checkCommand($executable)) {
  820. self::deactivateService($serviceType, $key);
  821. $info['available'] = FALSE;
  822. break;
  823. }
  824. }
  825. }
  826. // still available after exec check?
  827. if($info['available']) {
  828. $serviceKey = $key;
  829. $priority = $info['priority'];
  830. $quality = $info['quality'];
  831. }
  832. }
  833. }
  834. }
  835. if ($serviceKey) {
  836. $serviceInfo = $T3_SERVICES[$serviceType][$serviceKey];
  837. }
  838. return $serviceInfo;
  839. }
  840. /**
  841. * Deactivate a service
  842. *
  843. * @param string Service type
  844. * @param string Service key
  845. * @return void
  846. * @author Rene Fritz <r.fritz@colorcube.de>
  847. */
  848. public static function deactivateService($serviceType, $serviceKey) {
  849. global $T3_SERVICES;
  850. // ... maybe it's better to move non-available services to a different array??
  851. $T3_SERVICES[$serviceType][$serviceKey]['available'] = FALSE;
  852. }
  853. /**************************************
  854. *
  855. * Adding FRONTEND features
  856. * (related specifically to "cms" extension)
  857. *
  858. ***************************************/
  859. /**
  860. * Adds an entry to the list of plugins in content elements of type "Insert plugin"
  861. * 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)
  862. * 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.
  863. * 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
  864. * FOR USE IN ext_tables.php FILES
  865. * Usage: 13
  866. *
  867. * @param array Item Array
  868. * @param string Type (eg. "list_type") - basically a field from "tt_content" table
  869. * @return void
  870. */
  871. public static function addPlugin($itemArray, $type = 'list_type') {
  872. global $TCA;
  873. $_EXTKEY = $GLOBALS['_EXTKEY'];
  874. if ($_EXTKEY && !$itemArray[2]) {
  875. $itemArray[2] = self::extRelPath($_EXTKEY) . 'ext_icon.gif';
  876. }
  877. t3lib_div::loadTCA('tt_content');
  878. if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns'][$type]['config']['items'])) {
  879. foreach ($TCA['tt_content']['columns'][$type]['config']['items'] as $k => $v) {
  880. if (!strcmp($v[1], $itemArray[1])) {
  881. $TCA['tt_content']['columns'][$type]['config']['items'][$k] = $itemArray;
  882. return;
  883. }
  884. }
  885. $TCA['tt_content']['columns'][$type]['config']['items'][] = $itemArray;
  886. }
  887. }
  888. /**
  889. * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
  890. * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin or content element.
  891. * Usage: 0
  892. *
  893. * @param string Plugin key as used in the list_type field. Use the asterisk * to match all list_type values.
  894. * @param string Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
  895. * @param string Value of tt_content.CType (Content Type) to match. The default is "list" which corresponds to the "Insert Plugin" content element. Use the asterisk * to match all CType values.
  896. * @return void
  897. * @see addPlugin()
  898. */
  899. public static function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch = 'list') {
  900. global $TCA;
  901. t3lib_div::loadTCA('tt_content');
  902. if (is_array($TCA['tt_content']['columns']) && is_array($TCA['tt_content']['columns']['pi_flexform']['config']['ds'])) {
  903. $TCA['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch.','.$CTypeToMatch] = $value;
  904. }
  905. }
  906. /**
  907. * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
  908. * By using $content_table and $content_field you can also use the function for other tables.
  909. * FOR USE IN ext_tables.php FILES
  910. * Usage: 9
  911. *
  912. * @param string Table name to allow for "insert record"
  913. * @param string Table name TO WHICH the $table name is applied. See $content_field as well.
  914. * @param string Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
  915. * @return void
  916. */
  917. public static function addToInsertRecords($table, $content_table = 'tt_content', $content_field = 'records') {
  918. global $TCA;
  919. t3lib_div::loadTCA($content_table);
  920. if (is_array($TCA[$content_table]['columns']) && isset($TCA[$content_table]['columns'][$content_field]['config']['allowed'])) {
  921. $TCA[$content_table]['columns'][$content_field]['config']['allowed'].=','.$table;
  922. }
  923. }
  924. /**
  925. * Add PlugIn to Static Template #43
  926. *
  927. * 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.
  928. * 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"
  929. * $type determines the type of frontend plugin:
  930. * "list_type" (default) - the good old "Insert plugin" entry
  931. * "menu_type" - a "Menu/Sitemap" entry
  932. * "splash_layout" - a "Textbox" entry
  933. * "CType" - a new content element type
  934. * "header_layout" - an additional header type (added to the selection of layout1-5)
  935. * "includeLib" - just includes the library for manual use somewhere in TypoScript.
  936. * (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)
  937. * FOR USE IN ext_localconf.php FILES
  938. * Usage: 2
  939. *
  940. * @param string $key is the extension key
  941. * @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.
  942. * @param string $prefix is used as a - yes, suffix - of the class name (fx. "_pi1")
  943. * @param string $type, see description above
  944. * @param boolean If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
  945. * @return void
  946. */
  947. public static function addPItoST43($key, $classFile = '', $prefix = '', $type = 'list_type', $cached = 0) {
  948. global $TYPO3_LOADED_EXT;
  949. $classFile = $classFile ? $classFile : 'pi/class.tx_'.str_replace('_', '', $key).$prefix.'.php';
  950. $cN = self::getCN($key);
  951. // General plugin:
  952. $pluginContent = trim('
  953. plugin.'.$cN.$prefix.' = USER' . ($cached ? '' : '_INT') . '
  954. plugin.'.$cN.$prefix.' {
  955. includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
  956. userFunc = '.$cN.$prefix.'->main
  957. }');
  958. self::addTypoScript($key, 'setup', '
  959. # Setting '.$key.' plugin TypoScript
  960. '.$pluginContent);
  961. // After ST43:
  962. switch($type) {
  963. case 'list_type':
  964. $addLine = 'tt_content.list.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
  965. break;
  966. case 'menu_type':
  967. $addLine = 'tt_content.menu.20.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
  968. break;
  969. case 'splash_layout':
  970. $addLine = 'tt_content.splash.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
  971. break;
  972. case 'CType':
  973. $addLine = trim('
  974. tt_content.'.$key.$prefix.' = COA
  975. tt_content.'.$key.$prefix.' {
  976. 10 = < lib.stdheader
  977. 20 = < plugin.'.$cN.$prefix.'
  978. }
  979. ');
  980. break;
  981. case 'header_layout':
  982. $addLine = 'lib.stdheader.10.'.$key.$prefix.' = < plugin.'.$cN.$prefix;
  983. break;
  984. case 'includeLib':
  985. $addLine = 'page.1000 = < plugin.'.$cN.$prefix;
  986. break;
  987. default:
  988. $addLine = '';
  989. break;
  990. }
  991. if ($addLine) {
  992. self::addTypoScript($key, 'setup', '
  993. # Setting '.$key.' plugin TypoScript
  994. '.$addLine.'
  995. ', 43);
  996. }
  997. }
  998. /**
  999. * Call this method to add an entry in the static template list found in sys_templates
  1000. * "static template files" are the modern equalent (provided from extensions) to the traditional records in "static_templates"
  1001. * FOR USE IN ext_localconf.php FILES
  1002. * Usage: 3
  1003. *
  1004. * @param string $extKey is of course the extension key
  1005. * @param string $path is the path where the template files (fixed names) include_static.txt (integer list of uids from the table "static_templates"), constants.txt, setup.txt, editorcfg.txt, and include_static_file.txt is found (relative to extPath, eg. 'static/'). The file include_static_file.txt, allows you to include other static templates defined in files, from your static template, and thus corresponds to the field 'include_static_file' in the sys_template table. The syntax for this is a commaseperated list of static templates to include, like: EXT:css_styled_content/static/,EXT:da_newsletter_subscription/static/,EXT:cc_random_image/pi2/static/
  1006. * @param string $title is the title in the selector box.
  1007. * @return void
  1008. * @see addTypoScript()
  1009. */
  1010. public static function addStaticFile($extKey, $path, $title) {
  1011. global $TCA;
  1012. t3lib_div::loadTCA('sys_template');
  1013. if ($extKey && $path && is_array($TCA['sys_template']['columns'])) {
  1014. $value = str_replace(',', '', 'EXT:'.$extKey.'/'.$path);
  1015. $itemArray = array(trim($title.' ('.$extKey.')'), $value);
  1016. $TCA['sys_template']['columns']['include_static_file']['config']['items'][] = $itemArray;
  1017. }
  1018. }
  1019. /**
  1020. * Adds $content to the default TypoScript setup code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_setup']
  1021. * Prefixed with a [GLOBAL] line
  1022. * FOR USE IN ext_localconf.php FILES
  1023. * Usage: 6
  1024. *
  1025. * @param string TypoScript Setup string
  1026. * @return void
  1027. */
  1028. public static function addTypoScriptSetup($content) {
  1029. global $TYPO3_CONF_VARS;
  1030. $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'].="\n[GLOBAL]\n".$content;
  1031. }
  1032. /**
  1033. * Adds $content to the default TypoScript constants code as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_constants']
  1034. * Prefixed with a [GLOBAL] line
  1035. * FOR USE IN ext_localconf.php FILES
  1036. * Usage: 0
  1037. *
  1038. * @param string TypoScript Constants string
  1039. * @return void
  1040. */
  1041. public static function addTypoScriptConstants($content) {
  1042. global $TYPO3_CONF_VARS;
  1043. $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'].="\n[GLOBAL]\n".$content;
  1044. }
  1045. /**
  1046. * Adds $content to the default TypoScript code for either setup, constants or editorcfg as set in $TYPO3_CONF_VARS[FE]['defaultTypoScript_*']
  1047. * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
  1048. * FOR USE IN ext_localconf.php FILES
  1049. * Usage: 7
  1050. *
  1051. * @param string $key is the extension key (informative only).
  1052. * @param string $type is either "setup", "constants" or "editorcfg" and obviously determines which kind of TypoScript code we are adding.
  1053. * @param string $content is the TS content, prefixed with a [GLOBAL] line and a comment-header.
  1054. * @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.
  1055. * @return void
  1056. */
  1057. public static function addTypoScript($key, $type, $content, $afterStaticUid = 0) {
  1058. global $TYPO3_CONF_VARS;
  1059. if ($type=='setup' || $type=='editorcfg' || $type=='constants') {
  1060. $content = '
  1061. [GLOBAL]
  1062. #############################################
  1063. ## TypoScript added by extension "'.$key.'"
  1064. #############################################
  1065. '.$content;
  1066. if ($afterStaticUid) {
  1067. $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$afterStaticUid].=$content;
  1068. // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
  1069. if ($afterStaticUid==43 && is_array($TYPO3_CONF_VARS['FE']['contentRenderingTemplates'])) {
  1070. foreach ($TYPO3_CONF_VARS['FE']['contentRenderingTemplates'] as $templateName) {
  1071. $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type.'.'][$templateName] .= $content;
  1072. }
  1073. }
  1074. } else {
  1075. $TYPO3_CONF_VARS['FE']['defaultTypoScript_'.$type].=$content;
  1076. }
  1077. }
  1078. }
  1079. /**************************************
  1080. *
  1081. * INTERNAL EXTENSION MANAGEMENT:
  1082. *
  1083. ***************************************/
  1084. /**
  1085. * Loading extensions configured in $TYPO3_CONF_VARS['EXT']['extList']
  1086. *
  1087. * CACHING ON: ($TYPO3_CONF_VARS['EXT']['extCache'] = 1 or 2)
  1088. * 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.
  1089. * If cachefiles are not found they will be generated
  1090. * CACHING OFF: ($TYPO3_CONF_VARS['EXT']['extCache'] = 0)
  1091. * 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.
  1092. * This array will later be set in the global var $TYPO3_LOADED_EXT
  1093. *
  1094. * Usages of this function can be seen in config_default.php
  1095. * Extensions are always detected in the order local - global - system.
  1096. * Usage: 1
  1097. *
  1098. * @return array Extension Array
  1099. * @internal
  1100. */
  1101. public static function typo3_loadExtensions() {
  1102. global $TYPO3_CONF_VARS;
  1103. // Select mode how to load extensions in order to speed up the FE
  1104. if (TYPO3_MODE == 'FE') {
  1105. if (!($extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList_FE'])) {
  1106. // fall back to standard 'extList' if 'extList_FE' is not (yet) set
  1107. $extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList'];
  1108. }
  1109. $cacheFileSuffix = '_FE';
  1110. } else {
  1111. $extLoadInContext = $TYPO3_CONF_VARS['EXT']['extList'];
  1112. // Works as before
  1113. $cacheFileSuffix = '';
  1114. }
  1115. // Full list of extensions includes both required and extList:
  1116. $rawExtList = $TYPO3_CONF_VARS['EXT']['requiredExt'] . ',' . $extLoadInContext;
  1117. // Empty array as a start.
  1118. $extensions = array();
  1119. //
  1120. if ($rawExtList) {
  1121. // The cached File prefix.
  1122. $cacheFilePrefix = 'temp_CACHED' . $cacheFileSuffix;
  1123. // Setting the name for the cache files:
  1124. if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==1) $cacheFilePrefix.= '_ps'.substr(t3lib_div::shortMD5(PATH_site.'|'.$GLOBALS['TYPO_VERSION']), 0, 4);
  1125. if (intval($TYPO3_CONF_VARS['EXT']['extCache'])==2) $cacheFilePrefix.= '_'.t3lib_div::shortMD5($rawExtList);
  1126. // If cache files available, set cache file prefix and return:
  1127. if ($TYPO3_CONF_VARS['EXT']['extCache'] && self::isCacheFilesAvailable($cacheFilePrefix)) {
  1128. // Return cache file prefix:
  1129. $extensions['_CACHEFILE'] = $cacheFilePrefix;
  1130. } else { // ... but if not, configure...
  1131. // Prepare reserved filenames:
  1132. $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');
  1133. // Traverse extensions and check their existence:
  1134. clearstatcache(); // Clear file state cache to make sure we get good results from is_dir()
  1135. $temp_extensions = array_unique(t3lib_div::trimExplode(',', $rawExtList, 1));
  1136. foreach($temp_extensions as $temp_ext

Large files files are truncated, but you can click here to view the full file