0011834_v2.patch

Administrator Admin, 2009-08-31 19:39

Download (6.19 KB)

View differences:

t3lib/class.t3lib_extmgm.php (Arbeitskopie)
308 308
	 */
309 309
	public static function addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition = '') {
310 310
		$generatedPalette = '';
311
		$processedPalettes = array();
311 312
		t3lib_div::loadTCA($table);
312 313

  
313 314
		if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
......
320 321
							// If the field already has a palette, extend it:
321 322
						if ($items[$field]['details']['palette']) {
322 323
							$palette = $items[$field]['details']['palette'];
323
							self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
324
							if (!isset($processedPalettes[$palette])) {
325
								self::addFieldsToPalette($table, $palette, $addFields, $insertionPosition);
326
								$processedPalettes[$palette] = true;
327
							}
324 328
							// If there's not palette yet, create one:
325 329
						} else {
326 330
							if ($generatedPalette) {
......
366 370
				);
367 371
				// If it's a new palette, just set the data:
368 372
			} else {
369
				$paletteData['showitem'] = $addFields;
373
				$paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields);
370 374
			}
371 375
		}
372 376
	}
......
386 390
	 */
387 391
	protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
388 392
		$list = trim($list);
389
		$insertionList = self::removeDuplicatesForInsertion($list, $insertionList);
393
		$insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
390 394

  
391
			// Append data to the end (default):
392
		if ($insertionPosition === '') {
393
			$list.= ($list ? ', ' : '') . $insertionList;
394
			// Insert data before or after insertion points:
395
		} else {
396
			$positions = t3lib_div::trimExplode(',', $insertionPosition, true);
397
			$items = self::explodeItemList($list);
398
			$isInserted = false;
399
				// Iterate through all fields an check whether it's possible to inserte there:
400
			foreach ($items as $item => &$itemDetails) {
401
				$needles = self::getInsertionNeedles($item, $itemDetails['details']);
402
					// Insert data before:
403
				foreach ($needles['before'] as $needle) {
404
					if (in_array($needle, $positions)) {
405
						$itemDetails['rawData'] = $insertionList . ', '  . $itemDetails['rawData'];
406
						$isInserted = true;
407
						break;
395
		if ($insertionList) {
396
				// Append data to the end (default):
397
			if ($insertionPosition === '') {
398
				$list.= ($list ? ', ' : '') . $insertionList;
399
				// Insert data before or after insertion points:
400
			} else {
401
				$positions = t3lib_div::trimExplode(',', $insertionPosition, true);
402
				$items = self::explodeItemList($list);
403
				$isInserted = false;
404
					// Iterate through all fields an check whether it's possible to inserte there:
405
				foreach ($items as $item => &$itemDetails) {
406
					$needles = self::getInsertionNeedles($item, $itemDetails['details']);
407
						// Insert data before:
408
					foreach ($needles['before'] as $needle) {
409
						if (in_array($needle, $positions)) {
410
							$itemDetails['rawData'] = $insertionList . ', '  . $itemDetails['rawData'];
411
							$isInserted = true;
412
							break;
413
						}
408 414
					}
409
				}
410
					// Insert data after:
411
				foreach ($needles['after'] as $needle) {
412
					if (in_array($needle, $positions)) {
413
						$itemDetails['rawData'] .= ', ' . $insertionList;
414
						$isInserted = true;
415
						// Insert data after:
416
					foreach ($needles['after'] as $needle) {
417
						if (in_array($needle, $positions)) {
418
							$itemDetails['rawData'] .= ', ' . $insertionList;
419
							$isInserted = true;
420
							break;
421
						}
422
					}
423
						// Break if insertion was already done:
424
					if ($isInserted) {
415 425
						break;
416 426
					}
417 427
				}
418
					// Break if insertion was already done:
419
				if ($isInserted) {
420
					break;
428
					// If insertion point could not be determined, append the data:
429
				if (!$isInserted) {
430
					$list.= ($list ? ', ' : '') . $insertionList;
431
					// If data was correctly inserted before or after existing items, recreate the list:
432
				} else {
433
					$list = self::generateItemList($items, true);
421 434
				}
422 435
			}
423
				// If insertion point could not be determined, append the data:
424
			if (!$isInserted) {
425
				$list.= ($list ? ', ' : '') . $insertionList;
426
				// If data was correctly inserted before or after existing items, recreate the list:
427
			} else {
428
				$list = self::generateItemList($items, true);
429
			}
430 436
		}
431 437

  
432 438
		return $list;
......
441 447
	 *  + insertion: 'field_b, field_d, field_c;;;4-4-4'
442 448
	 * -> new insertion: 'field_d'
443 449
	 *
444
	 * @param	string		$list: The list of items to be extended
445 450
	 * @param	string		$insertionList: The list of items to inserted
451
	 * @param	string		$list: The list of items to be extended (default: '')
446 452
	 * @return	string		Duplicate-free list of items to be inserted
447 453
	 */
448
	protected static function removeDuplicatesForInsertion($list, $insertionList) {
454
	protected static function removeDuplicatesForInsertion($insertionList, $list = '') {
449 455
		$pattern = '/(^|,)\s*\b([^;,]+)\b[^,]*/';
456
		$listItems = array();
450 457

  
451 458
		if ($list && preg_match_all($pattern, $list, $listMatches)) {
452
			if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
453
				$duplicates = array_intersect($listMatches[2], $insertionListMatches[2]);
454
				if ($duplicates) {
455
					foreach ($duplicates as &$duplicate) {
456
						$duplicate = preg_quote($duplicate, '/');
457
					}
458
					$insertionList = preg_replace(
459
						array('/(^|,)\s*\b(' . implode('|', $duplicates) . ')\b[^,]*(,|$)/', '/,$/'),
460
						array('\3', ''),
461
						$insertionList
462
					);
459
			$listItems = $listMatches[2];
460
		}
461

  
462
		if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) {
463
			$insertionItems = array();
464
			$insertionDuplicates = false;
465

  
466
			foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) {
467
				if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) {
468
					$insertionItems[$insertionItem] = true;
469
				} else {
470
					unset($insertionListMatches[0][$insertionIndex]);
471
					$insertionDuplicates = true;
463 472
				}
464 473
			}
474

  
475
			if ($insertionDuplicates) {
476
				$insertionList = implode('', $insertionListMatches[0]);
477
			}
465 478
		}
466 479

  
467 480
		return $insertionList;