Index: t3lib/class.t3lib_extmgm.php =================================================================== --- t3lib/class.t3lib_extmgm.php (revision 10289) +++ t3lib/class.t3lib_extmgm.php (revision ) @@ -312,8 +312,8 @@ $positionArray = t3lib_div::trimExplode(':', $position); if ($positionArray[0] == 'replace') { foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) { - if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0 - && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) { + if (preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0 + && preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0) { self::addFieldsToPalette($table, $palette, $str, $position); $fieldExists = TRUE; } @@ -323,8 +323,8 @@ $fieldExists = TRUE; } else { foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) { - if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0 - && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) { + if (preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0 + && preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0) { $position = $positionArray[0] . ':--palette--;;' . $palette; } } @@ -335,8 +335,8 @@ $fieldExists = TRUE; } else if(is_array($GLOBALS['TCA'][$table]['palettes'])) { foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) { - if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0 - && strpos($paletteDetails['showitem'], $str) !== FALSE) { + if (strpos($paletteDetails['showitem'], $str) !== FALSE + && preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0) { $fieldExists = TRUE; } } @@ -433,10 +433,12 @@ ); // If it's a new palette, just set the data: } else { + if($addFields) { - $paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields); - } - } - } + $paletteData['showitem'] = self::removeDuplicatesForInsertion($addFields); + } + } + } + } /** * Adds a list of new fields to the TYPO3 USER SETTINGS configuration "showitem" list, the array with @@ -472,7 +474,10 @@ */ protected static function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') { $list = trim($list); + + if($insertionList) { - $insertionList = self::removeDuplicatesForInsertion($insertionList, $list); + $insertionList = self::removeDuplicatesForInsertion($insertionList, $list); + } if ($insertionList) { // Append data to the end (default): @@ -480,15 +485,14 @@ $list .= ($list ? ', ' : '') . $insertionList; // Insert data before or after insertion points: } else { - $positions = t3lib_div::trimExplode(',', $insertionPosition, TRUE); $items = self::explodeItemList($list); $isInserted = FALSE; - // Iterate through all fields an check whether it's possible to inserte there: + // Iterate through all fields and check whether it's possible to insert there: foreach ($items as $item => &$itemDetails) { $needles = self::getInsertionNeedles($item, $itemDetails['details']); // Insert data before: foreach ($needles['before'] as $needle) { - if (in_array($needle, $positions)) { + if (strpos($needle, $insertionPosition) !== FALSE) { $itemDetails['rawData'] = $insertionList . ', ' . $itemDetails['rawData']; $isInserted = TRUE; break; @@ -496,7 +500,7 @@ } // Insert data after: foreach ($needles['after'] as $needle) { - if (in_array($needle, $positions)) { + if (strpos($needle, $insertionPosition) !== FALSE) { $itemDetails['rawData'] .= ', ' . $insertionList; $isInserted = TRUE; break; @@ -504,7 +508,7 @@ } // Replace with data: foreach ($needles['replace'] as $needle) { - if (in_array($needle, $positions)) { + if (strpos($needle, $insertionPosition) !== FALSE) { $itemDetails['rawData'] = $insertionList; $isInserted = TRUE; break; @@ -550,23 +554,18 @@ } if ($insertionList && preg_match_all($pattern, $insertionList, $insertionListMatches)) { - $insertionItems = array(); - $insertionDuplicates = FALSE; - - foreach ($insertionListMatches[2] as $insertionIndex => $insertionItem) { - if (!isset($insertionItems[$insertionItem]) && !in_array($insertionItem, $listItems)) { - $insertionItems[$insertionItem] = TRUE; + $insertionList = ''; + $insertionListMatches[2] = array_flip(array_flip($insertionListMatches[2])); + $listItems = array_diff($insertionListMatches[2], $listItems); + if (count($listItems) > 0) { + $insertionListMatches[2] = array_intersect_key($listItems, $insertionListMatches[0]); - } else { + } else { - unset($insertionListMatches[0][$insertionIndex]); - $insertionDuplicates = TRUE; + $insertionListMatches[2] = $insertionListMatches[0]; - } + } + if (count($insertionListMatches[2]) > 0) { + $insertionList = implode(',',$insertionListMatches[2]); } - - if ($insertionDuplicates) { - $insertionList = implode('', $insertionListMatches[0]); - } + } - } - return $insertionList; } @@ -580,9 +579,10 @@ * @return array The needled to be used for inserting content before or after existing fields/items */ protected static function getInsertionNeedles($item, array $itemDetails) { - if (strstr($item, '--')) { + - // 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. + // 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. - $item = preg_replace('/[0-9]+$/', '', $item); + if ($item{0} === '-') { + $item = rtrim($item, '0123456789'); } $needles = array( @@ -616,7 +616,7 @@ foreach ($itemParts as $itemPart) { $itemDetails = t3lib_div::trimExplode(';', $itemPart, FALSE, 5); $key = $itemDetails[0]; - if (strstr($key, '--')) { + if ($key{0} === '-') { // 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! $key .= count($items); } @@ -651,9 +651,10 @@ $itemParts = array(); foreach ($items as $item => $itemDetails) { - if (strstr($item, '--')) { + - // 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. + // 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. - $item = preg_replace('/[0-9]+$/', '', $item); + if ($item{0} === '-') { + $item = rtrim($item, '0123456789'); } if ($useRawData) {