[BUGFIX] Untrusted GP data is unserialized in wizard_colorpicker.php and view_help.php
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_extmgm.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34
35
36 /**
37 * Extension Management functions
38 *
39 * This class is never instantiated, rather the methods inside is called as functions like
40 * t3lib_extMgm::isLoaded('my_extension');
41 *
42 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
43 * @package TYPO3
44 * @subpackage t3lib
45 */
46 final class t3lib_extMgm {
47 protected static $extensionKeyMap;
48
49
50 /**************************************
51 *
52 * PATHS and other evaluation
53 *
54 ***************************************/
55
56 /**
57 * Returns TRUE if the extension with extension key $key is loaded.
58 * Usage: 109
59 *
60 * @param string Extension key to test
61 * @param boolean If $exitOnError is TRUE and the extension is not loaded the function will die with an error message
62 * @return boolean
63 */
64 public static function isLoaded($key, $exitOnError = 0) {
65 if ($exitOnError && !isset($GLOBALS['TYPO3_LOADED_EXT'][$key])) {
66 throw new BadFunctionCallException(
67 'TYPO3 Fatal Error: Extension "' . $key . '" was not loaded!',
68 1270853910
69 );
70 }
71 return isset($GLOBALS['TYPO3_LOADED_EXT'][$key]);
72 }
73
74 /**
75 * Returns the absolute path to the extension with extension key $key
76 * If the extension is not loaded the function will die with an error message
77 * Useful for internal fileoperations
78 * Usage: 136
79 *
80 * @param $key string Extension key
81 * @param $script string $script is appended to the output if set.
82 * @throws BadFunctionCallException
83 * @return string
84 */
85 public static function extPath($key, $script = '') {
86 if (isset($GLOBALS['TYPO3_LOADED_EXT'])) {
87 if (!isset($GLOBALS['TYPO3_LOADED_EXT'][$key])) {
88 throw new BadFunctionCallException(
89 'TYPO3 Fatal Error: Extension key "' . $key . '" was NOT loaded!',
90 1270853878
91 );
92 }
93
94 $extensionPath = PATH_site . $GLOBALS['TYPO3_LOADED_EXT'][$key]['siteRelPath'];
95 } else {
96 $extensionList = self::getRequiredExtensionList() . ',' . $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'];
97 $loadedExtensions = array_flip(array_unique(t3lib_div::trimExplode(',', $extensionList, TRUE)));
98
99 if (!isset($loadedExtensions[$key])) {
100 throw new BadFunctionCallException(
101 'TYPO3 Fatal Error: Extension key "' . $key . '" was NOT loaded!',
102 1294430950
103 );
104 }
105
106 if (@is_dir(PATH_typo3conf . 'ext/' . $key . '/')) {
107 $extensionPath = PATH_typo3conf . 'ext/' . $key . '/';
108 } elseif (@is_dir(PATH_typo3 . 'ext/' . $key . '/')) {
109 $extensionPath = PATH_typo3 . 'ext/' . $key . '/';
110 } elseif (@is_dir(PATH_typo3 . 'sysext/' . $key . '/')) {
111 $extensionPath = PATH_typo3 . 'sysext/' . $key . '/';
112 } else {
113 throw new BadFunctionCallException(
114 'TYPO3 Fatal Error: Extension "' . $key . '" was NOT found!',
115 1294430951
116 );
117 }
118 }
119
120 return $extensionPath . $script;
121 }
122
123 /**
124 * Returns the relative path to the extension as measured from from the TYPO3_mainDir
125 * If the extension is not loaded the function will die with an error message
126 * Useful for images and links from backend
127 * Usage: 54
128 *
129 * @param string Extension key
130 * @return string
131 */
132 public static function extRelPath($key) {
133 if (!isset($GLOBALS['TYPO3_LOADED_EXT'][$key])) {
134 throw new BadFunctionCallException(
135 'TYPO3 Fatal Error: Extension key "' . $key . '" was NOT loaded!',
136 1270853879
137 );
138 }
139 return $GLOBALS['TYPO3_LOADED_EXT'][$key]['typo3RelPath'];
140 }
141
142 /**
143 * Returns the relative path to the extension as measured from the PATH_site (frontend)
144 * If the extension is not loaded the function will die with an error message
145 * Useful for images and links from the frontend
146 * Usage: 6
147 *
148 * @param string Extension key
149 * @return string
150 */
151 public static function siteRelPath($key) {
152 return substr(self::extPath($key), strlen(PATH_site));
153 }
154
155 /**
156 * Returns the correct class name prefix for the extension key $key
157 * Usage: 3
158 *
159 * @param string Extension key
160 * @return string
161 * @internal
162 */
163 public static function getCN($key) {
164 return substr($key, 0, 5) == 'user_' ? 'user_' . str_replace('_', '', substr($key, 5)) : 'tx_' . str_replace('_', '', $key);
165 }
166
167 /**
168 * Returns the real extension key like 'tt_news' from an extension prefix like 'tx_ttnews'.
169 *
170 * @param string $prefix: The extension prefix (e.g. 'tx_ttnews')
171 * @return mixed Real extension key (string) or FALSE (boolean) if something went wrong
172 */
173 public static function getExtensionKeyByPrefix($prefix) {
174 $result = FALSE;
175 // Build map of short keys referencing to real keys:
176 if (!isset(self::$extensionKeyMap)) {
177 self::$extensionKeyMap = array();
178 foreach (array_keys($GLOBALS['TYPO3_LOADED_EXT']) as $extensionKey) {
179 $shortKey = str_replace('_', '', $extensionKey);
180 self::$extensionKeyMap[$shortKey] = $extensionKey;
181 }
182 }
183 // Lookup by the given short key:
184 $parts = explode('_', $prefix);
185 if (isset(self::$extensionKeyMap[$parts[1]])) {
186 $result = self::$extensionKeyMap[$parts[1]];
187 }
188 return $result;
189 }
190
191 /**
192 * Clears the extension key map.
193 *
194 * @return void
195 */
196 public static function clearExtensionKeyMap() {
197 self::$extensionKeyMap = NULL;
198 }
199
200 /**
201 * Retrieves the version of an installed extension.
202 * If the extension is not installed, this function returns an empty string.
203 *
204 * @param string $key the key of the extension to look up, must not be empty
205 * @return string the extension version as a string in the format "x.y.z",
206 * will be an empty string if the extension is not loaded
207 */
208 public static function getExtensionVersion($key) {
209 if (!is_string($key) || empty($key)) {
210 throw new InvalidArgumentException('Extension key must be a non-empty string.', 1294586096);
211 }
212 if (!self::isLoaded($key)) {
213 return '';
214 }
215 $runtimeCache = $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
216 $cacheIdentifier = 'extMgmExtVersion-' . $key;
217
218 if (!($extensionVersion = $runtimeCache->get($cacheIdentifier))) {
219
220 $EM_CONF = array();
221 $_EXTKEY = $key;
222 include(self::extPath($key) . 'ext_emconf.php');
223 $extensionVersion = $EM_CONF[$key]['version'];
224 $runtimeCache->set($cacheIdentifier, $extensionVersion);
225 }
226 return $extensionVersion;
227 }
228
229
230 /**************************************
231 *
232 * Adding BACKEND features
233 * (related to core features)
234 *
235 ***************************************/
236
237 /**
238 * Adding fields to an existing table definition in $GLOBALS['TCA']
239 * Adds an array with $GLOBALS['TCA'] column-configuration to the $GLOBALS['TCA']-entry for that table.
240 * 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!
241 * So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list.
242 * FOR USE IN ext_tables.php FILES
243 * Usage: 4
244 *
245 * @param string $table is the table name of a table already present in $GLOBALS['TCA'] with a columns section
246 * @param array $columnArray is the array with the additional columns (typical some fields an extension wants to add)
247 * @param boolean If $addTofeInterface is TRUE the list of fields are also added to the fe_admin_fieldList.
248 * @return void
249 */
250 public static function addTCAcolumns($table, $columnArray, $addTofeInterface = 0) {
251 t3lib_div::loadTCA($table);
252 if (is_array($columnArray) && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'])) {
253 // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
254 $GLOBALS['TCA'][$table]['columns'] = array_merge($GLOBALS['TCA'][$table]['columns'], $columnArray);
255 if ($addTofeInterface) {
256 $GLOBALS['TCA'][$table]['feInterface']['fe_admin_fieldList'] .= ',' . implode(',', array_keys($columnArray));
257 }
258 }
259 }
260
261 /**
262 * Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
263 *
264 * Adds a string $str (comma list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $specificTypesList)
265 * This is needed to have new fields shown automatically in the TCEFORMS of a record from $table.
266 * Typically this function is called after having added new columns (database fields) with the addTCAcolumns function
267 * FOR USE IN ext_tables.php FILES
268 * Usage: 1
269 *
270 * @param string Table name
271 * @param string Field list to add.
272 * @param string List of specific types to add the field list to. (If empty, all type entries are affected)
273 * @param string Insert fields before (default) or after one
274 * of this fields (commalist with "before:", "after:" or "replace:" commands).
275 * Example: "before:keywords,--palette--;;4,after:description".
276 * Palettes must be passed like in the example no matter how the palette definition looks like in TCA.
277 * It will add the list of new fields before or after a palette or replace the field inside the palette,
278 * when the field given in $position is found inside a palette used by the type.
279 * @return void
280 */
281 public static function addToAllTCAtypes($table, $str, $specificTypesList = '', $position = '') {
282 t3lib_div::loadTCA($table);
283 $str = trim($str);
284 $palettesChanged = array();
285 if ($str && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['types'])) {
286 foreach ($GLOBALS['TCA'][$table]['types'] as $type => &$typeDetails) {
287 if ($specificTypesList === '' || t3lib_div::inList($specificTypesList, $type)) {
288 $fieldExists = FALSE;
289 if ($position != '' && is_array($GLOBALS['TCA'][$table]['palettes'])) {
290 $positionArray = t3lib_div::trimExplode(':', $position);
291 if ($positionArray[0] == 'replace') {
292 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
293 if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
294 && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) {
295 self::addFieldsToPalette($table, $palette, $str, $position);
296 // save that palette in case other types use it
297 $palettesChanged[] = $palette;
298 $fieldExists = TRUE;
299 } elseif (in_array($palette, $palettesChanged)) {
300 $fieldExists = TRUE;
301 }
302 }
303 } else {
304 if (strpos($typeDetails['showitem'], $str) !== FALSE) {
305 $fieldExists = TRUE;
306 } else {
307 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
308 if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
309 && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) {
310 $position = $positionArray[0] . ':--palette--;;' . $palette;
311 }
312 }
313 }
314 }
315 } else {
316 if (strpos($typeDetails['showitem'], $str) !== FALSE) {
317 $fieldExists = TRUE;
318 } elseif (is_array($GLOBALS['TCA'][$table]['palettes'])) {
319 foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
320 if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
321 && strpos($paletteDetails['showitem'], $str) !== FALSE) {
322 $fieldExists = TRUE;
323 }
324 }
325 }
326 }
327 if ($fieldExists === FALSE) {
328 $typeDetails['showitem'] = self::executePositionedStringInsertion(
329 $typeDetails['showitem'],
330 $str,
331 $position
332 );
333 }
334 }
335 }
336 unset($typeDetails);
337 }
338 }
339
340 /**
341 * Adds new fields to all palettes of an existing field.
342 * If the field does not have a palette yet, it's created automatically and
343 * gets called "generatedFor-$field".
344 *
345 * @param string $table: Name of the table
346 * @param string $field: Name of the field that has 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:", "after:" or "replace:" 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 addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
356 $generatedPalette = '';
357 $processedPalettes = array();
358 t3lib_div::loadTCA($table);
359
360 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
361 $types =& $GLOBALS['TCA'][$table]['types'];
362 if (is_array($types)) {
363 // Iterate through all types and search for the field that defines the palette to be extended:
364 foreach (array_keys($types) as $type) {
365 $items = self::explodeItemList($types[$type]['showitem']);
366 if (isset($items[$field])) {
367 // If the field already has a palette, extend it:
368 if ($items[$field]['details']['palette']) {
369 $palette = $items[$field]['details']['palette'];
370 if (!isset($processedPalettes[$palette])) {
371 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
372 $processedPalettes[$palette] = TRUE;
373 }
374 // If there's not palette yet, create one:
375 } else {
376 if ($generatedPalette) {
377 $palette = $generatedPalette;
378 } else {
379 $palette = $generatedPalette = 'generatedFor-' . $field;
380 self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
381 }
382 $items[$field]['details']['palette'] = $palette;
383 $types[$type]['showitem'] = self::generateItemList($items);
384 }
385 }
386 }
387 }
388 }
389 }
390
391 /**
392 * Adds new fields to a palette.
393 * If the palette does not exist yet, it's created automatically.
394 *
395 * @param string $table: Name of the table
396 * @param string $palette: Name of the palette to be extended
397 * @param string $addFields: List of fields to be added to the palette
398 * @param string $insertionPosition: Insert fields before (default) or after one
399 * of this fields (commalist with "before:", "after:" or "replace:" commands).
400 * Example: "before:keywords,--palette--;;4,after:description".
401 * Palettes must be passed like in the example no matter how the
402 * palette definition looks like in TCA.
403 * @return void
404 */
405 public static function addFieldsToPalette($table, $palette, $addFields, $insertionPosition = '') {
406 t3lib_div::loadTCA($table);
407
408 if (isset($GLOBALS['TCA'][$table])) {
409 $paletteData =& $GLOBALS['TCA'][$table]['palettes'][$palette];
410 // If palette already exists, merge the data:
411 if (is_array($paletteData)) {
412 $paletteData['showitem'] = self::executePositionedStringInsertion(
413 $paletteData['showitem'],
414 $addFields,
415 $insertionPosition
416 );
417 // If it's a new palette, just set the data:
418 } else {
419 $paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields);
420 }
421 }
422 }
423
424 /**
425 * Add an item to a select field item list.
426 *
427 * Warning: Do not use this method for radio or check types, especially not
428 * with $relativeToField and $relativePosition parameters. This would shift
429 * existing database data 'off by one'.
430 *
431 * As an example, this can be used to add an item to tt_content CType select
432 * drop-down after the existing 'mailform' field with these parameters:
433 * - $table = 'tt_content'
434 * - $field = 'CType'
435 * - $item = array(
436 * 'LLL:EXT:cms/locallang_ttc.xml:CType.I.10',
437 * 'login',
438 * 'i/tt_content_login.gif',
439 * ),
440 * - $relativeToField = mailform
441 * - $relativePosition = after
442 *
443 * @throws InvalidArgumentException If given paramenters are not of correct
444 * type or out of bounds
445 * @throws RuntimeException If reference to related position fields can not
446 * be found or if select field is not defined
447 *
448 * @param string $table Name of TCA table
449 * @param string $field Name of TCA field
450 * @param array $item New item to add
451 * @param string $relativeToField Add item relative to existing field
452 * @param string $relativePosition Valid keywords: 'before', 'after'
453 * or 'replace' to relativeToField field
454 */
455 public static function addTcaSelectItem($table, $field, array $item, $relativeToField = '', $relativePosition = '') {
456 if (!is_string($table)) {
457 throw new InvalidArgumentException(
458 'Given table is of type "' . gettype($table) . '" but a string is expected.',
459 1303236963
460 );
461 }
462 if (!is_string($field)) {
463 throw new InvalidArgumentException(
464 'Given field is of type "' . gettype($field) . '" but a string is expected.',
465 1303236964
466 );
467 }
468 if (!is_string($relativeToField)) {
469 throw new InvalidArgumentException(
470 'Given relative field is of type "' . gettype($relativeToField) . '" but a string is expected.',
471 1303236965
472 );
473 }
474 if (!is_string($relativePosition)) {
475 throw new InvalidArgumentException(
476 'Given relative position is of type "' . gettype($relativePosition) . '" but a string is expected.',
477 1303236966
478 );
479 }
480 if ($relativePosition !== '' && $relativePosition !== 'before' && $relativePosition !== 'after' && $relativePosition !== 'replace') {
481 throw new InvalidArgumentException(
482 'Relative position must be either empty or one of "before", "after", "replace".',
483 1303236967
484 );
485 }
486
487 t3lib_div::loadTCA($table);
488
489 if (!is_array($GLOBALS['TCA'][$table]['columns'][$field]['config']['items'])) {
490 throw new RuntimeException(
491 'Given select field item list was not found.',
492 1303237468
493 );
494 }
495
496 // Make sure item keys are integers
497 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'] = array_values($GLOBALS['TCA'][$table]['columns'][$field]['config']['items']);
498
499 if (strlen($relativePosition) > 0) {
500 // Insert at specified position
501 $matchedPosition = t3lib_utility_Array::filterByValueRecursive(
502 $relativeToField,
503 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items']
504 );
505 if (count($matchedPosition) > 0) {
506 $relativeItemKey = key($matchedPosition);
507 if ($relativePosition === 'replace') {
508 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][$relativeItemKey] = $item;
509 } else {
510 if ($relativePosition === 'before') {
511 $offset = $relativeItemKey;
512 } else {
513 $offset = $relativeItemKey + 1;
514 }
515 array_splice($GLOBALS['TCA'][$table]['columns'][$field]['config']['items'], $offset, 0, array(0 => $item));
516 }
517 } else {
518 // Insert at new item at the end of the array if relative position was not found
519 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][] = $item;
520 }
521 } else {
522 // Insert at new item at the end of the array
523 $GLOBALS['TCA'][$table]['columns'][$field]['config']['items'][] = $item;
524 }
525 }
526
527 /**
528 * Adds a list of new fields to the TYPO3 USER SETTINGS configuration "showitem" list, the array with
529 * the new fields itself needs to be added additionally to show up in the user setup, like
530 * $GLOBALS['TYPO3_USER_SETTINGS']['columns'] += $tempColumns
531 *
532 * @param string $addFields: List of fields to be added to the user settings
533 * @param string $insertionPosition: Insert fields before (default) or after one
534 * of this fields (commalist with "before:", "after:" or "replace:" commands).
535 * Example: "before:password,after:email".
536 * @return void
537 */
538 public function addFieldsToUserSettings($addFields, $insertionPosition = '') {
539 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'] = self::executePositionedStringInsertion(
540 $GLOBALS['TYPO3_USER_SETTINGS']['showitem'],
541 $addFields,
542 $insertionPosition
543 );
544 }
545
546 /**
547 * Inserts as list of data into an existing list.
548 * The insertion position can be defined accordant before of after existing list items.
549 *
550 * @param string $list: The list of items to be extended
551 * @param string $insertionList: The list of items to inserted
552 * @param string $insertionPosition: Insert fields before (default) or after one
553 * of this fields (commalist with "before:" or "after:" commands).
554 * Example: "before:keywords,--palette--;;4,after:description".
555 * Palettes must be passed like in the example no matter how the
556 * palette definition looks like in TCA.
557 * @return string The extended list
558 */
559 protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
560 $list = trim($list);
561 $insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
562
563 if ($insertionList) {
564 // Append data to the end (default):
565 if ($insertionPosition === '') {
566 $list .= ($list ? ', ' : '') . $insertionList;
567 // Insert data before or after insertion points:
568 } else {
569 $positions = t3lib_div::trimExplode(',', $insertionPosition, TRUE);
570 $items = self::explodeItemList($list);
571 $isInserted = FALSE;
572 // Iterate through all fields an check whether it's possible to inserte there:
573 foreach ($items as $item => &$itemDetails) {
574 $needles = self::getInsertionNeedles($item, $itemDetails['details']);
575 // Insert data before:
576 foreach ($needles['before'] as $needle) {
577 if (in_array($needle, $positions)) {
578 $itemDetails['rawData'] = $insertionList . ', ' . $itemDetails['rawData'];
579 $isInserted = TRUE;
580 break;
581 }
582 }
583 // Insert data after:
584 foreach ($needles['after'] as $needle) {
585 if (in_array($needle, $positions)) {
586 $itemDetails['rawData'] .= ', ' . $insertionList;
587 $isInserted = TRUE;
588 break;
589 }
590 }
591 // Replace with data:
592 foreach ($needles['replace'] as $needle) {
593 if (in_array($needle, $positions)) {
594 $itemDetails['rawData'] = $insertionList;
595 $isInserted = TRUE;
596 break;
597 }
598 }
599 // Break if insertion was already done:
600 if ($isInserted) {
601 break;
602 }
603 }
604 // If insertion point could not be determined, append the data:
605 if (!$isInserted) {
606 $list .= ($list ? ', ' : '') . $insertionList;
607 // If data was correctly inserted before or after existing items, recreate the list:
608 } else {
609 $list = self::generateItemList($items, TRUE);
610 }
611 }
612 }
613
614 return $list;
615 }
616
617 /**
618 * Compares an existing list of items and a list of items to be inserted
619 * and returns a duplicate-free variant of that insertion list.
620 *
621 * Example:
622 * + list: 'field_a, field_b;;;;2-2-2, field_c;;;;3-3-3'
623 * + insertion: 'field_b, field_d, field_c;;;4-4-4'
624 * -> new insertion: 'field_d'
625 *
626 * @param string $insertionList: The list of items to inserted
627 * @param string $list: The list of items to be extended (default: '')
628 * @return string Duplicate-free list of items to be inserted
629 */
630 protected static function removeDuplicatesForInsertion($insertionList, $list = '') {
631 $pattern = '/(^|,)\s*\b([^;,]+)\b[^,]*/';
632 $listItems = array();
633
634 if ($list && preg_match_all($pattern, $list, $listMatches)) {
635 $listItems = $listMatches[2];
636 }
637
638 if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
639 $insertionItems = array();
640 $insertionDuplicates = FALSE;
641
642 foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) {
643 if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) {
644 $insertionItems[$insertionItem] = TRUE;
645 } else {
646 unset($insertionListMatches[0][$insertionIndex]);
647 $insertionDuplicates = TRUE;
648 }
649 }
650
651 if ($insertionDuplicates) {
652 $insertionList = implode('', $insertionListMatches[0]);
653 }
654 }
655
656 return $insertionList;
657 }
658
659 /**
660 * Generates search needles that are used for inserting fields/items into an existing list.
661 *
662 * @see executePositionedStringInsertion
663 * @param string $item: The name of the field/item
664 * @param array $itemDetails: Additional details of the field/item like e.g. palette information
665 * (this array gets created by the function explodeItemList())
666 * @return array The needled to be used for inserting content before or after existing fields/items
667 */
668 protected static function getInsertionNeedles($item, array $itemDetails) {
669 if (strstr($item, '--')) {
670 // 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.
671 $item = preg_replace('/[0-9]+$/', '', $item);
672 }
673
674 $needles = array(
675 'before' => array($item, 'before:' . $item),
676 'after' => array('after:' . $item),
677 'replace' => array('replace:' . $item),
678 );
679
680 if ($itemDetails['palette']) {
681 $palette = $item . ';;' . $itemDetails['palette'];
682 $needles['before'][] = $palette;
683 $needles['before'][] = 'before:' . $palette;
684 $needles['after'][] = 'after:' . $palette;
685 $needles['replace'][] = 'replace:' . $palette;
686 }
687
688 return $needles;
689 }
690
691 /**
692 * Generates an array of fields/items with additional information such as e.g. the name of the palette.
693 *
694 * @param string $itemList: List of fields/items to be splitted up
695 * (this mostly reflects the data in $GLOBALS['TCA'][<table>]['types'][<type>]['showitem'])
696 * @return array An array with the names of the fields/items as keys and additional information
697 */
698 protected static function explodeItemList($itemList) {
699 $items = array();
700 $itemParts = t3lib_div::trimExplode(',', $itemList, TRUE);
701
702 foreach ($itemParts as $itemPart) {
703 $itemDetails = t3lib_div::trimExplode(';', $itemPart, FALSE, 5);
704 $key = $itemDetails[0];
705 if (strstr($key, '--')) {
706 // 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!
707 $key .= count($items);
708 }
709
710 if (!isset($items[$key])) {
711 $items[$key] = array(
712 'rawData' => $itemPart,
713 'details' => array(
714 'field' => $itemDetails[0],
715 'label' => $itemDetails[1],
716 'palette' => $itemDetails[2],
717 'special' => $itemDetails[3],
718 'styles' => $itemDetails[4],
719 ),
720 );
721 }
722 }
723
724 return $items;
725 }
726
727 /**
728 * Generates a list of fields/items out of an array provided by the function getFieldsOfFieldList().
729 *
730 * @see explodeItemList
731 * @param array $items: The array of fields/items with optional additional information
732 * @param boolean $useRawData: Use raw data instead of building by using the details (default: FALSE)
733 * @return string The list of fields/items which gets used for $GLOBALS['TCA'][<table>]['types'][<type>]['showitem']
734 * or $GLOBALS['TCA'][<table>]['palettes'][<palette>]['showitem'] in most cases
735 */
736 protected static function generateItemList(array $items, $useRawData = FALSE) {
737 $itemParts = array();
738
739 foreach ($items as $item => $itemDetails) {
740 if (strstr($item, '--')) {
741 // 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.
742 $item = preg_replace('/[0-9]+$/', '', $item);
743 }
744
745 if ($useRawData) {
746 $itemParts[] = $itemDetails['rawData'];
747 } else {
748 $itemParts[] = (count($itemDetails['details']) > 1 ? implode(';', $itemDetails['details']) : $item);
749 }
750 }
751
752 return implode(', ', $itemParts);
753 }
754
755 /**
756 * Add tablename to default list of allowed tables on pages (in $PAGES_TYPES)
757 * Will add the $table to the list of tables allowed by default on pages as setup by $PAGES_TYPES['default']['allowedTables']
758 * FOR USE IN ext_tables.php FILES
759 * Usage: 11
760 *
761 * @param string Table name
762 * @return void
763 */
764 public static function allowTableOnStandardPages($table) {
765 $GLOBALS['PAGES_TYPES']['default']['allowedTables'] .= ',' . $table;
766 }
767
768 /**
769 * Adds a module (main or sub) to the backend interface
770 * FOR USE IN ext_tables.php FILES
771 * Usage: 18
772 *
773 * @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.
774 * @param string $sub is the submodule key. If $sub is not set a blank $main module is created.
775 * @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.
776 * @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.
777 * @return void
778 */
779 public static function addModule($main, $sub = '', $position = '', $path = '') {
780 if (isset($GLOBALS['TBE_MODULES'][$main]) && $sub) {
781 // if there is already a main module by this name:
782
783 // Adding the submodule to the correct position:
784 list($place, $modRef) = t3lib_div::trimExplode(':', $position, 1);
785 $mods = t3lib_div::trimExplode(',', $GLOBALS['TBE_MODULES'][$main], 1);
786 if (!in_array($sub, $mods)) {
787 switch (strtolower($place)) {
788 case 'after':
789 case 'before':
790 $pointer = 0;
791 $found = FALSE;
792 foreach ($mods as $k => $m) {
793 if (!strcmp($m, $modRef)) {
794 $pointer = strtolower($place) == 'after' ? $k + 1 : $k;
795 $found = TRUE;
796 }
797 }
798 if ($found) {
799 array_splice(
800 $mods, // The modules array
801 $pointer, // To insert one position from the end of the list
802 0, // Don't remove any items, just insert
803 $sub // Module to insert
804 );
805 } else {
806 // If requested module is not found: Add at the end
807 array_push($mods, $sub);
808 }
809 break;
810 default:
811 if (strtolower($place) == 'top') {
812 array_unshift($mods, $sub);
813 } else {
814 array_push($mods, $sub);
815 }
816 break;
817 }
818 }
819 // Re-inserting the submodule list:
820 $GLOBALS['TBE_MODULES'][$main] = implode(',', $mods);
821 } else { // Create new main modules with only one submodule, $sub (or none if $sub is blank)
822 $GLOBALS['TBE_MODULES'][$main] = $sub;
823 }
824
825 // Adding path:
826 if ($path) {
827 $GLOBALS['TBE_MODULES']['_PATHS'][$main . ($sub ? '_' . $sub : '')] = $path;
828 }
829 }
830
831 /**
832 * Adds a module path to $GLOBALS['TBE_MODULES'] for used with the module dispatcher, mod.php
833 * Used only for modules that are not placed in the main/sub menu hierarchy by the traditional mechanism of addModule()
834 * Examples for this is context menu functionality (like import/export) which runs as an independent module through mod.php
835 * FOR USE IN ext_tables.php FILES
836 * Example: t3lib_extMgm::addModulePath('xMOD_tximpexp', t3lib_extMgm::extPath($_EXTKEY).'app/');
837 *
838 * @param string $name is the name of the module, refer to conf.php of the module.
839 * @param string $path is the absolute path to the module directory inside of which "index.php" and "conf.php" is found.
840 * @return void
841 */
842 public static function addModulePath($name, $path) {
843 $GLOBALS['TBE_MODULES']['_PATHS'][$name] = $path;
844 }
845
846 /**
847 * Adds a "Function menu module" ('third level module') to an existing function menu for some other backend module
848 * The arguments values are generally determined by which function menu this is supposed to interact with
849 * See Inside TYPO3 for information on how to use this function.
850 * FOR USE IN ext_tables.php FILES
851 * Usage: 26
852 *
853 * @param string Module name
854 * @param string Class name
855 * @param string Class path
856 * @param string Title of module
857 * @param string Menu array key - default is "function"
858 * @param string Workspace conditions. Blank means all workspaces, any other string can be a comma list of "online", "offline" and "custom"
859 * @return void
860 * @see t3lib_SCbase::mergeExternalItems()
861 */
862 public static function insertModuleFunction($modname, $className, $classPath, $title, $MM_key = 'function', $WS = '') {
863 $GLOBALS['TBE_MODULES_EXT'][$modname]['MOD_MENU'][$MM_key][$className] = array(
864 'name' => $className,
865 'path' => $classPath,
866 'title' => $title,
867 'ws' => $WS
868 );
869 }
870
871 /**
872 * Adds $content to the default Page TSconfig as set in $GLOBALS['TYPO3_CONF_VARS'][BE]['defaultPageTSconfig']
873 * Prefixed with a [GLOBAL] line
874 * FOR USE IN ext_tables.php/ext_localconf.php FILES
875 * Usage: 5
876 *
877 * @param string Page TSconfig content
878 * @return void
879 */
880 public static function addPageTSConfig($content) {
881 $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'] .= "\n[GLOBAL]\n" . $content;
882 }
883
884 /**
885 * Adds $content to the default User TSconfig as set in $GLOBALS['TYPO3_CONF_VARS'][BE]['defaultUserTSconfig']
886 * Prefixed with a [GLOBAL] line
887 * FOR USE IN ext_tables.php/ext_localconf.php FILES
888 * Usage: 3
889 *
890 * @param string User TSconfig content
891 * @return void
892 */
893 public static function addUserTSConfig($content) {
894 $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] .= "\n[GLOBAL]\n" . $content;
895 }
896
897 /**
898 * Adds a reference to a locallang file with $GLOBALS['TCA_DESCR'] labels
899 * FOR USE IN ext_tables.php FILES
900 * 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.
901 * Usage: 31
902 *
903 * @param string Description key. Typically a database table (like "pages") but for applications can be other strings, but prefixed with "_MOD_")
904 * @param string File reference to locallang file, eg. "EXT:lang/locallang_csh_pages.php" (or ".xml")
905 * @return void
906 */
907 public static function addLLrefForTCAdescr($tca_descr_key, $file_ref) {
908 if ($tca_descr_key) {
909 if (!is_array($GLOBALS['TCA_DESCR'][$tca_descr_key])) {
910 $GLOBALS['TCA_DESCR'][$tca_descr_key] = array();
911 }
912 if (!is_array($GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'])) {
913 $GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'] = array();
914 }
915 $GLOBALS['TCA_DESCR'][$tca_descr_key]['refs'][] = $file_ref;
916 }
917 }
918
919 /**
920 * Registers a navigation component
921 *
922 * @param string $module
923 * @param string $componentId
924 * @return void
925 */
926 public static function addNavigationComponent($module, $componentId) {
927 $GLOBALS['TBE_MODULES']['_navigationComponents'][$module] = array(
928 'componentId' => $componentId,
929 'extKey' => $GLOBALS['_EXTKEY'],
930 'isCoreComponent' => FALSE,
931 );
932 }
933
934 /**
935 * Registers a core navigation component
936 *
937 * @param string $module
938 * @param string $componentId
939 * @return void
940 */
941 public static function addCoreNavigationComponent($module, $componentId) {
942 self::addNavigationComponent($module, $componentId);
943 $GLOBALS['TBE_MODULES']['_navigationComponents'][$module]['isCoreComponent'] = TRUE;
944 }
945
946
947 /**************************************
948 *
949 * Adding SERVICES features
950 *
951 * @author René Fritz <r.fritz@colorcube.de>
952 *
953 ***************************************/
954
955 /**
956 * Adds a service to the global services array
957 *
958 * @param string Extension key
959 * @param string Service type, must not be prefixed "tx_" or "Tx_"
960 * @param string Service key, must be prefixed "tx_", "Tx_" or "user_"
961 * @param array Service description array
962 * @return void
963 * @author René Fritz <r.fritz@colorcube.de>
964 */
965 public static function addService($extKey, $serviceType, $serviceKey, $info) {
966 // even not available services will be included to make it possible to give the admin a feedback of non-available services.
967 // but maybe it's better to move non-available services to a different array??
968
969 if ($serviceType &&
970 !t3lib_div::hasValidClassPrefix($serviceType) &&
971 t3lib_div::hasValidClassPrefix($serviceKey, array('user_')) &&
972 is_array($info)) {
973
974 $info['priority'] = max(0, min(100, $info['priority']));
975
976 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey] = $info;
977
978 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['extKey'] = $extKey;
979 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceKey'] = $serviceKey;
980 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceType'] = $serviceType;
981
982
983 // mapping a service key to a service type
984 // all service keys begin with tx_ or Tx_ - service types don't
985 // this way a selection of a special service key as service type is easy
986 $GLOBALS['T3_SERVICES'][$serviceKey][$serviceKey] = &$GLOBALS['T3_SERVICES'][$serviceType][$serviceKey];
987
988
989 // change the priority (and other values) from $GLOBALS['TYPO3_CONF_VARS']
990 // $GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey]['priority']
991 // even the activation is possible (a unix service might be possible on windows for some reasons)
992 if (is_array($GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey])) {
993
994 // no check is done here - there might be configuration values only the service type knows about, so
995 // we pass everything
996 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey] = array_merge(
997 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey],
998 $GLOBALS['TYPO3_CONF_VARS']['T3_SERVICES'][$serviceType][$serviceKey]
999 );
1000 }
1001
1002
1003 // OS check
1004 // empty $os means 'not limited to one OS', therefore a check is not needed
1005 if ($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['available']
1006 && $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['os'] != '') {
1007
1008 // TYPO3_OS is not yet defined
1009 $os_type = stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin') ? 'WIN' : 'UNIX';
1010
1011 $os = t3lib_div::trimExplode(',', strtoupper($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['os']));
1012
1013 if (!in_array($os_type, $os)) {
1014 self::deactivateService($serviceType, $serviceKey);
1015 }
1016 }
1017
1018 // convert subtype list to array for quicker access
1019 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceSubTypes'] = array();
1020 $serviceSubTypes = t3lib_div::trimExplode(',', $info['subtype']);
1021 foreach ($serviceSubTypes as $subtype) {
1022 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['serviceSubTypes'][$subtype] = $subtype;
1023 }
1024 }
1025 }
1026
1027 /**
1028 * Find the available service with highest priority
1029 *
1030 * @param string Service type
1031 * @param string Service sub type
1032 * @param mixed Service keys that should be excluded in the search for a service. Array or comma list.
1033 * @return mixed Service info array if a service was found, FLASE otherwise
1034 * @author René Fritz <r.fritz@colorcube.de>
1035 */
1036 public static function findService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) {
1037 $serviceKey = FALSE;
1038 $serviceInfo = FALSE;
1039 $priority = 0;
1040 $quality = 0;
1041
1042 if (!is_array($excludeServiceKeys)) {
1043 $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
1044 }
1045
1046 if (is_array($GLOBALS['T3_SERVICES'][$serviceType])) {
1047 foreach ($GLOBALS['T3_SERVICES'][$serviceType] as $key => $info) {
1048
1049 if (in_array($key, $excludeServiceKeys)) {
1050 continue;
1051 }
1052
1053 // select a subtype randomly
1054 // usefull to start a service by service key without knowing his subtypes - for testing purposes
1055 if ($serviceSubType == '*') {
1056 $serviceSubType = key($info['serviceSubTypes']);
1057 }
1058
1059 // this matches empty subtype too
1060 if ($info['available'] && ($info['subtype'] == $serviceSubType || $info['serviceSubTypes'][$serviceSubType]) && $info['priority'] >= $priority) {
1061
1062 // has a lower quality than the already found, therefore we skip this service
1063 if ($info['priority'] == $priority && $info['quality'] < $quality) {
1064 continue;
1065 }
1066
1067 // service depends on external programs - check if they exists
1068 if (trim($info['exec'])) {
1069 $executables = t3lib_div::trimExplode(',', $info['exec'], 1);
1070 foreach ($executables as $executable) {
1071 if (!t3lib_exec::checkCommand($executable)) {
1072 self::deactivateService($serviceType, $key);
1073 $info['available'] = FALSE;
1074 break;
1075 }
1076 }
1077 }
1078
1079 // still available after exec check?
1080 if ($info['available']) {
1081 $serviceKey = $key;
1082 $priority = $info['priority'];
1083 $quality = $info['quality'];
1084 }
1085 }
1086 }
1087 }
1088
1089 if ($serviceKey) {
1090 $serviceInfo = $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey];
1091 }
1092 return $serviceInfo;
1093 }
1094
1095 /**
1096 * Deactivate a service
1097 *
1098 * @param string Service type
1099 * @param string Service key
1100 * @return void
1101 * @author René Fritz <r.fritz@colorcube.de>
1102 */
1103 public static function deactivateService($serviceType, $serviceKey) {
1104 // ... maybe it's better to move non-available services to a different array??
1105 $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['available'] = FALSE;
1106 }
1107
1108
1109 /**************************************
1110 *
1111 * Adding FRONTEND features
1112 * (related specifically to "cms" extension)
1113 *
1114 ***************************************/
1115
1116 /**
1117 * Adds an entry to the list of plugins in content elements of type "Insert plugin"
1118 * Takes the $itemArray (label, value[,icon]) and adds to the items-array of $GLOBALS['TCA'][tt_content] elements with CType "listtype" (or another field if $type points to another fieldname)
1119 * 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.
1120 * 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
1121 * FOR USE IN ext_tables.php FILES
1122 * Usage: 13
1123 *
1124 * @param array Item Array
1125 * @param string Type (eg. "list_type") - basically a field from "tt_content" table
1126 * @return void
1127 */
1128 public static function addPlugin($itemArray, $type = 'list_type') {
1129 $_EXTKEY = $GLOBALS['_EXTKEY'];
1130 if ($_EXTKEY && !$itemArray[2]) {
1131 $itemArray[2] = self::extRelPath($_EXTKEY) . 'ext_icon.gif';
1132 }
1133
1134 t3lib_div::loadTCA('tt_content');
1135 if (is_array($GLOBALS['TCA']['tt_content']['columns']) && is_array($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'])) {
1136 foreach ($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'] as $k => $v) {
1137 if (!strcmp($v[1], $itemArray[1])) {
1138 $GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'][$k] = $itemArray;
1139 return;
1140 }
1141 }
1142 $GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'][] = $itemArray;
1143 }
1144 }
1145
1146 /**
1147 * Adds an entry to the "ds" array of the tt_content field "pi_flexform".
1148 * This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin or content element.
1149 * Usage: 0
1150 *
1151 * @param string Plugin key as used in the list_type field. Use the asterisk * to match all list_type values.
1152 * @param string Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
1153 * @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.
1154 * @return void
1155 * @see addPlugin()
1156 */
1157 public static function addPiFlexFormValue($piKeyToMatch, $value, $CTypeToMatch = 'list') {
1158 t3lib_div::loadTCA('tt_content');
1159
1160 if (is_array($GLOBALS['TCA']['tt_content']['columns']) && is_array($GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds'])) {
1161 $GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds'][$piKeyToMatch . ',' . $CTypeToMatch] = $value;
1162 }
1163 }
1164
1165 /**
1166 * Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records"
1167 * By using $content_table and $content_field you can also use the function for other tables.
1168 * FOR USE IN ext_tables.php FILES
1169 * Usage: 9
1170 *
1171 * @param string Table name to allow for "insert record"
1172 * @param string Table name TO WHICH the $table name is applied. See $content_field as well.
1173 * @param string Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
1174 * @return void
1175 */
1176 public static function addToInsertRecords($table, $content_table = 'tt_content', $content_field = 'records') {
1177 t3lib_div::loadTCA($content_table);
1178 if (is_array($GLOBALS['TCA'][$content_table]['columns']) && isset($GLOBALS['TCA'][$content_table]['columns'][$content_field]['config']['allowed'])) {
1179 $GLOBALS['TCA'][$content_table]['columns'][$content_field]['config']['allowed'] .= ',' . $table;
1180 }
1181 }
1182
1183 /**
1184 * Add PlugIn to Static Template #43
1185 *
1186 * 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.
1187 * 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"
1188 * $type determines the type of frontend plugin:
1189 * "list_type" (default) - the good old "Insert plugin" entry
1190 * "menu_type" - a "Menu/Sitemap" entry
1191 * "splash_layout" - a "Textbox" entry
1192 * "CType" - a new content element type
1193 * "header_layout" - an additional header type (added to the selection of layout1-5)
1194 * "includeLib" - just includes the library for manual use somewhere in TypoScript.
1195 * (Remember that your $type definition should correspond to the column/items array in $GLOBALS['TCA'][tt_content] where you added the selector item for the element! See addPlugin() function)
1196 * FOR USE IN ext_localconf.php FILES
1197 * Usage: 2
1198 *
1199 * @param string $key is the extension key
1200 * @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.
1201 * @param string $prefix is used as a - yes, suffix - of the class name (fx. "_pi1")
1202 * @param string $type, see description above
1203 * @param boolean If $cached is set as USER content object (cObject) is created - otherwise a USER_INT object is created.
1204 * @return void
1205 */
1206 public static function addPItoST43($key, $classFile = '', $prefix = '', $type = 'list_type', $cached = 0) {
1207 $classFile = $classFile ? $classFile : 'pi/class.tx_' . str_replace('_', '', $key) . $prefix . '.php';
1208 $cN = self::getCN($key);
1209
1210 // General plugin:
1211 $pluginContent = trim('
1212 plugin.' . $cN . $prefix . ' = USER' . ($cached ? '' : '_INT') . '
1213 plugin.' . $cN . $prefix . ' {
1214 includeLibs = ' . $GLOBALS['TYPO3_LOADED_EXT'][$key]['siteRelPath'] . $classFile . '
1215 userFunc = ' . $cN . $prefix . '->main
1216 }');
1217 self::addTypoScript($key, 'setup', '
1218 # Setting ' . $key . ' plugin TypoScript
1219 ' . $pluginContent);
1220
1221 // After ST43:
1222 switch ($type) {
1223 case 'list_type':
1224 $addLine = 'tt_content.list.20.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1225 break;
1226 case 'menu_type':
1227 $addLine = 'tt_content.menu.20.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1228 break;
1229 case 'splash_layout':
1230 $addLine = 'tt_content.splash.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1231 break;
1232 case 'CType':
1233 $addLine = trim('
1234 tt_content.' . $key . $prefix . ' = COA
1235 tt_content.' . $key . $prefix . ' {
1236 10 = < lib.stdheader
1237 20 = < plugin.' . $cN . $prefix . '
1238 }
1239 ');
1240 break;
1241 case 'header_layout':
1242 $addLine = 'lib.stdheader.10.' . $key . $prefix . ' = < plugin.' . $cN . $prefix;
1243 break;
1244 case 'includeLib':
1245 $addLine = 'page.1000 = < plugin.' . $cN . $prefix;
1246 break;
1247 default:
1248 $addLine = '';
1249 break;
1250 }
1251 if ($addLine) {
1252 self::addTypoScript($key, 'setup', '
1253 # Setting ' . $key . ' plugin TypoScript
1254 ' . $addLine . '
1255 ', 43);
1256 }
1257 }
1258
1259 /**
1260 * Call this method to add an entry in the static template list found in sys_templates
1261 * "static template files" are the modern equivalent (provided from extensions) to the traditional records in "static_templates"
1262 * FOR USE IN ext_localconf.php FILES
1263 * Usage: 3
1264 *
1265 * @param string $extKey is of course the extension key
1266 * @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/
1267 * @param string $title is the title in the selector box.
1268 * @return void
1269 * @see addTypoScript()
1270 */
1271 public static function addStaticFile($extKey, $path, $title) {
1272 t3lib_div::loadTCA('sys_template');
1273 if ($extKey && $path && is_array($GLOBALS['TCA']['sys_template']['columns'])) {
1274 $value = str_replace(',', '', 'EXT:' . $extKey . '/' . $path);
1275 $itemArray = array(trim($title . ' (' . $extKey . ')'), $value);
1276 $GLOBALS['TCA']['sys_template']['columns']['include_static_file']['config']['items'][] = $itemArray;
1277 }
1278 }
1279
1280 /**
1281 * Adds $content to the default TypoScript setup code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_setup']
1282 * Prefixed with a [GLOBAL] line
1283 * FOR USE IN ext_localconf.php FILES
1284 * Usage: 6
1285 *
1286 * @param string TypoScript Setup string
1287 * @return void
1288 */
1289 public static function addTypoScriptSetup($content) {
1290 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'] .= "\n[GLOBAL]\n" . $content;
1291 }
1292
1293 /**
1294 * Adds $content to the default TypoScript constants code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_constants']
1295 * Prefixed with a [GLOBAL] line
1296 * FOR USE IN ext_localconf.php FILES
1297 * Usage: 0
1298 *
1299 * @param string TypoScript Constants string
1300 * @return void
1301 */
1302 public static function addTypoScriptConstants($content) {
1303 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'] .= "\n[GLOBAL]\n" . $content;
1304 }
1305
1306 /**
1307 * Adds $content to the default TypoScript code for either setup, constants or editorcfg as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_*']
1308 * (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!)
1309 * FOR USE IN ext_localconf.php FILES
1310 * Usage: 7
1311 *
1312 * @param string $key is the extension key (informative only).
1313 * @param string $type is either "setup", "constants" or "editorcfg" and obviously determines which kind of TypoScript code we are adding.
1314 * @param string $content is the TS content, prefixed with a [GLOBAL] line and a comment-header.
1315 * @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.
1316 * @return void
1317 */
1318 public static function addTypoScript($key, $type, $content, $afterStaticUid = 0) {
1319 if ($type == 'setup' || $type == 'editorcfg' || $type == 'constants') {
1320 $content = '
1321
1322 [GLOBAL]
1323 #############################################
1324 ## TypoScript added by extension "' . $key . '"
1325 #############################################
1326
1327 ' . $content;
1328 if ($afterStaticUid) {
1329 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type . '.'][$afterStaticUid] .= $content;
1330 // If 'content (default)' is targeted, also add to other 'content rendering templates', eg. css_styled_content
1331 if ($afterStaticUid == 43 && is_array($GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'])) {
1332 foreach ($GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'] as $templateName) {
1333 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type . '.'][$templateName] .= $content;
1334 }
1335 }
1336 } else {
1337 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type] .= $content;
1338 }
1339 }
1340 }
1341
1342
1343 /**************************************
1344 *
1345 * INTERNAL EXTENSION MANAGEMENT:
1346 *
1347 ***************************************/
1348
1349 /**
1350 * Loading extensions configured in $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']
1351 *
1352 * CACHING ON: ($GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache'] = 1)
1353 * 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.
1354 * If cachefiles are not found they will be generated
1355 * CACHING OFF: ($GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache'] = 0)
1356 * 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.
1357 * This array will later be set in the global var $GLOBALS['TYPO3_LOADED_EXT']
1358 *
1359 * Usages of this function can be seen in config_default.php
1360 * Extensions are always detected in the order local - global - system.
1361 * Usage: 1
1362 *
1363 * @return array Extension Array
1364 * @internal
1365 */
1366 public static function typo3_loadExtensions() {
1367
1368 // Caching behaviour of ext_tables.php and ext_localconf.php files:
1369 $extensionCacheBehaviour = self::getExtensionCacheBehaviour();
1370 // Full list of extensions includes both required and extList:
1371 $rawExtList = self::getEnabledExtensionList();
1372
1373 // Empty array as a start.
1374 $extensions = array();
1375
1376 //
1377 if ($rawExtList) {
1378 // The cached File prefix.
1379 $cacheFilePrefix = self::getCacheFilePrefix();
1380
1381 // If cache files available, set cache file prefix and return:
1382 if ($extensionCacheBehaviour && self::isCacheFilesAvailable($cacheFilePrefix)) {
1383 // Return cache file prefix:
1384 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1385 } else { // ... but if not, configure...
1386
1387 // Prepare reserved filenames:
1388 $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');
1389 // Traverse extensions and check their existence:
1390 clearstatcache(); // Clear file state cache to make sure we get good results from is_dir()
1391 $temp_extensions = array_unique(t3lib_div::trimExplode(',', $rawExtList, 1));
1392 foreach ($temp_extensions as $temp_extKey) {
1393 // Check local, global and system locations:
1394 if (@is_dir(PATH_typo3conf . 'ext/' . $temp_extKey . '/')) {
1395 $extensions[$temp_extKey] = array('type' => 'L', 'siteRelPath' => 'typo3conf/ext/' . $temp_extKey . '/', 'typo3RelPath' => '../typo3conf/ext/' . $temp_extKey . '/');
1396 } elseif (@is_dir(PATH_typo3 . 'ext/' . $temp_extKey . '/')) {
1397 $extensions[$temp_extKey] = array('type' => 'G', 'siteRelPath' => TYPO3_mainDir . 'ext/' . $temp_extKey . '/', 'typo3RelPath' => 'ext/' . $temp_extKey . '/');
1398 } elseif (@is_dir(PATH_typo3 . 'sysext/' . $temp_extKey . '/')) {
1399 $extensions[$temp_extKey] = array('type' => 'S', 'siteRelPath' => TYPO3_mainDir . 'sysext/' . $temp_extKey . '/', 'typo3RelPath' => 'sysext/' . $temp_extKey . '/');
1400 }
1401
1402 // If extension was found, check for reserved filenames:
1403 if (isset($extensions[$temp_extKey])) {
1404 foreach ($files as $fName) {
1405 $temp_filename = PATH_site . $extensions[$temp_extKey]['siteRelPath'] . trim($fName);
1406 if (is_array($extensions[$temp_extKey]) && @is_file($temp_filename)) {
1407 $extensions[$temp_extKey][$fName] = $temp_filename;
1408 }
1409 }
1410 }
1411 }
1412 unset($extensions['_CACHEFILE']);
1413
1414 // write cache?
1415 if ($extensionCacheBehaviour &&
1416 @is_dir(PATH_typo3 . 'sysext/') &&
1417 @is_dir(PATH_typo3 . 'ext/')) { // Must also find global and system extension directories to exist, otherwise caching cannot be allowed (since it is most likely a temporary server problem). This might fix a rare, unrepeatable bug where global/system extensions are not loaded resulting in fatal errors if that is cached!
1418 $wrError = self::cannotCacheFilesWritable($cacheFilePrefix);
1419 if ($wrError) {
1420 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache'] = 0;
1421 } else {
1422 // Write cache files:
1423 $extensions = self::writeCacheFiles($extensions, $cacheFilePrefix);
1424 }
1425 }
1426 }
1427 }
1428
1429 return $extensions;
1430 }
1431
1432 /**
1433 * Returns the section headers for the compiled cache-files.
1434 *
1435 * @param string $key is the extension key
1436 * @param string $file is the filename (only informative for comment)
1437 * @return string
1438 * @internal
1439 */
1440 public static function _makeIncludeHeader($key, $file) {
1441 return '<?php
1442 ###########################
1443 ## EXTENSION: ' . $key . '
1444 ## FILE: ' . $file . '
1445 ###########################
1446
1447 $_EXTKEY = \'' . $key . '\';
1448 $_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];
1449
1450 ?>';
1451 }
1452
1453 /**
1454 * Returns TRUE if both the localconf and tables cache file exists (with $cacheFilePrefix)
1455 * Usage: 2
1456 *
1457 * @param string Prefix of the cache file to check
1458 * @return boolean
1459 * @internal
1460 */
1461 public static function isCacheFilesAvailable($cacheFilePrefix) {
1462 return
1463 @is_file(PATH_typo3conf . $cacheFilePrefix . '_ext_localconf.php') &&
1464 @is_file(PATH_typo3conf . $cacheFilePrefix . '_ext_tables.php');
1465 }
1466
1467 /**
1468 * Returns TRUE if the "localconf.php" file in "typo3conf/" is writable
1469 * Usage: 1
1470 *
1471 * @return boolean
1472 * @internal
1473 */
1474 public static function isLocalconfWritable() {
1475 return @is_writable(PATH_typo3conf) && @is_writable(PATH_typo3conf . 'localconf.php');
1476 }
1477
1478 /**
1479 * Returns an error string if typo3conf/ or cache-files with $cacheFilePrefix are NOT writable
1480 * Returns FALSE if no problem.
1481 * Usage: 1
1482 *
1483 * @param string Prefix of the cache file to check
1484 * @return string
1485 * @internal
1486 */
1487 public static function cannotCacheFilesWritable($cacheFilePrefix) {
1488 $error = array();
1489 if (!@is_writable(PATH_typo3conf)) {
1490 $error[] = PATH_typo3conf;
1491 }
1492 if (@is_file(PATH_typo3conf . $cacheFilePrefix . '_ext_localconf.php') &&
1493 !@is_writable(PATH_typo3conf . $cacheFilePrefix . '_ext_localconf.php')) {
1494 $error[] = PATH_typo3conf . $cacheFilePrefix . '_ext_localconf.php';
1495 }
1496 if (@is_file(PATH_typo3conf . $cacheFilePrefix . '_ext_tables.php') &&
1497 !@is_writable(PATH_typo3conf . $cacheFilePrefix . '_ext_tables.php')) {
1498 $error[] = PATH_typo3conf . $cacheFilePrefix . '_ext_tables.php';
1499 }
1500 return implode(', ', $error);
1501 }
1502
1503 /**
1504 * Returns an array with the two cache-files (0=>localconf, 1=>tables) from typo3conf/ if they (both) exist. Otherwise FALSE.
1505 * Evaluation relies on $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE']
1506 * Usage: 2
1507 *
1508 * @param string $cacheFilePrefix Cache file prefix to be used (optional)
1509 * @return array
1510 * @internal
1511 */
1512 public static function currentCacheFiles($cacheFilePrefix = NULL) {
1513 if (is_null($cacheFilePrefix)) {
1514 $cacheFilePrefix = $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'];
1515 }
1516
1517 if ($cacheFilePrefix) {
1518 $cacheFilePrefixFE = str_replace('temp_CACHED', 'temp_CACHED_FE', $cacheFilePrefix);
1519 $files = array();
1520 if (self::isCacheFilesAvailable($cacheFilePrefix)) {
1521 $files[] = PATH_typo3conf . $cacheFilePrefix . '_ext_localconf.php';
1522 $files[] = PATH_typo3conf . $cacheFilePrefix . '_ext_tables.php';
1523 }
1524 if (self::isCacheFilesAvailable($cacheFilePrefixFE)) {
1525 $files[] = PATH_typo3conf . $cacheFilePrefixFE . '_ext_localconf.php';
1526 $files[] = PATH_typo3conf . $cacheFilePrefixFE . '_ext_tables.php';
1527 }
1528 if (!empty($files)) {
1529 return $files;
1530 }
1531 }
1532 }
1533
1534 /**
1535 * Compiles/Creates the two cache-files in typo3conf/ based on $cacheFilePrefix
1536 * Returns a array with the key "_CACHEFILE" set to the $cacheFilePrefix value
1537 * Usage: 1
1538 *
1539 * @param array Extension information array
1540 * @param string Prefix for the cache files
1541 * @return array
1542 * @internal
1543 */
1544 public static function writeCacheFiles($extensions, $cacheFilePrefix) {
1545 // Making cache files:
1546 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1547 $cFiles = array();
1548 $cFiles['ext_localconf'] .= '<?php
1549
1550 $GLOBALS[\'TYPO3_LOADED_EXT\'] = unserialize(stripslashes(\'' . addslashes(serialize($extensions)) . '\'));
1551
1552 ?>';
1553
1554 foreach ($extensions as $key => $conf) {
1555 if (is_array($conf)) {
1556 if ($conf['ext_localconf.php']) {
1557 $cFiles['ext_localconf'] .= self::_makeIncludeHeader($key, $conf['ext_localconf.php']);
1558 $cFiles['ext_localconf'] .= trim(t3lib_div::getUrl($conf['ext_localconf.php']));
1559 }
1560 if ($conf['ext_tables.php']) {
1561 $cFiles['ext_tables'] .= self::_makeIncludeHeader($key, $conf['ext_tables.php']);
1562 $cFiles['ext_tables'] .= trim(t3lib_div::getUrl($conf['ext_tables.php']));
1563 }
1564 }
1565 }
1566
1567 $cFiles['ext_localconf'] = "<?php\n" . preg_replace('/<\?php|\?>/is', '', $cFiles['ext_localconf']) . "?>\n";
1568 $cFiles['ext_tables'] = "<?php\n" . preg_replace('/<\?php|\?>/is', '', $cFiles['ext_tables']) . "?>\n";
1569
1570 t3lib_div::writeFile(PATH_typo3conf . $cacheFilePrefix . '_ext_localconf.php', $cFiles['ext_localconf']);
1571 t3lib_div::writeFile(PATH_typo3conf . $cacheFilePrefix . '_ext_tables.php', $cFiles['ext_tables']);
1572
1573 $extensions = array();
1574 $extensions['_CACHEFILE'] = $cacheFilePrefix;
1575
1576 return $extensions;
1577 }
1578
1579 /**
1580 * Unlink (delete) cache files
1581 *
1582 * @param string $cacheFilePrefix Cache file prefix to be used (optional)
1583 * @return integer Number of deleted files.
1584 */
1585 public static function removeCacheFiles($cacheFilePrefix = NULL) {
1586 $cacheFiles = self::currentCacheFiles($cacheFilePrefix);
1587
1588 $out = 0;
1589 if (is_array($cacheFiles)) {
1590 foreach ($cacheFiles as $cfile) {
1591 @unlink($cfile);
1592 clearstatcache();
1593 $out++;
1594 }
1595 }
1596 return $out;
1597 }
1598
1599 /**
1600 * Gets the behaviour for caching ext_tables.php and ext_localconf.php files
1601 * (see $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache'] setting in the install tool).
1602 *
1603 * @param boolean $usePlainValue Whether to use the value as it is without modifications
1604 * @return integer
1605 */
1606 public static function getExtensionCacheBehaviour($usePlainValue = FALSE) {
1607 $extensionCacheBehaviour = intval($GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']);
1608
1609 // Caching of extensions is disabled when install tool is used:
1610 if (!$usePlainValue && defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript) {
1611 $extensionCacheBehaviour = 0;
1612 }
1613
1614 return $extensionCacheBehaviour;
1615 }
1616
1617 /**
1618 * Gets the prefix used for the ext_tables.php and ext_localconf.php cached files.
1619 *
1620 * @return string
1621 */
1622 public static function getCacheFilePrefix() {
1623 $extensionCacheBehaviour = self::getExtensionCacheBehaviour(TRUE);
1624
1625 $cacheFileSuffix = (TYPO3_MODE == 'FE' ? '_FE' : '');
1626 $cacheFilePrefix = 'temp_CACHED' . $cacheFileSuffix;
1627
1628 if ($extensionCacheBehaviour) {
1629 $cacheFilePrefix .= '_ps' . substr(t3lib_div::shortMD5(PATH_site . '|' . $GLOBALS['TYPO_VERSION']), 0, 4);
1630 }
1631
1632 return $cacheFilePrefix;
1633 }
1634
1635 /**
1636 * Gets the list of enabled extensions for the accordant context (frontend or backend).
1637 *
1638 * @return string
1639 */
1640 public static function getEnabledExtensionList() {
1641 // Select mode how to load extensions in order to speed up the FE
1642 if (TYPO3_MODE == 'FE') {
1643 if (!($extLoadInContext = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList_FE'])) {
1644 // fall back to standard 'extList' if 'extList_FE' is not (yet) set
1645 $extLoadInContext = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'];
1646 }
1647 } else {
1648 $extLoadInContext = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'];
1649 }
1650
1651 $extensionList = self::getRequiredExtensionList() . ',' . $extLoadInContext;
1652 $ignoredExtensionList = self::getIgnoredExtensionList();
1653
1654 // Remove the extensions to be ignored:
1655 if ($ignoredExtensionList && (defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript) === FALSE) {
1656 $extensions = array_diff(
1657 explode(',', $extensionList),
1658 explode(',', $ignoredExtensionList)
1659 );
1660 $extensionList = implode(',', $extensions);
1661 }
1662
1663 return $extensionList;
1664 }
1665
1666 /**
1667 * Gets the list of required extensions.
1668 *
1669 * @return string
1670 */
1671 public static function getRequiredExtensionList() {
1672 $requiredExtensionList = t3lib_div::uniqueList(
1673 REQUIRED_EXTENSIONS . ',' . $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt']
1674 );
1675
1676 return $requiredExtensionList;
1677 }
1678
1679 /**
1680 * Gets the list of extensions to be ignored (not to be loaded).
1681 *
1682 * @return string
1683 */
1684 public static function getIgnoredExtensionList() {
1685 $ignoredExtensionList = t3lib_div::uniqueList(
1686 $GLOBALS['TYPO3_CONF_VARS']['EXT']['ignoredExt']
1687 );
1688
1689 return $ignoredExtensionList;
1690 }
1691 }
1692
1693 ?>