37 $start = strpos($content, $marker);
38 if ($start ===
false) {
41 $start += strlen($marker);
42 $stop = strpos($content, $marker, $start);
45 if ($stop ===
false) {
48 $content = substr($content, $start, $stop - $start);
50 if (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $content, $matches) === 1) {
55 if (preg_match(
'/(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $content, $matches) === 1) {
60 if (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)$/s', $content, $matches) === 1) {
78 public function substituteSubpart($content, $marker, $subpartContent, $recursive =
true, $keepMarker =
false)
80 $start = strpos($content, $marker);
81 if ($start ===
false) {
84 $startAM = $start + strlen($marker);
85 $stop = strpos($content, $marker, $startAM);
86 if ($stop ===
false) {
89 $stopAM = $stop + strlen($marker);
90 $before = substr($content, 0, $start);
91 $after = substr($content, $stopAM);
92 $between = substr($content, $startAM, $stop - $startAM);
94 $after = $this->
substituteSubpart($after, $marker, $subpartContent, $recursive, $keepMarker);
98 if (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $between, $matches) === 1) {
99 $before .= $marker . $matches[1];
100 $between = $matches[2];
101 $after = $matches[3] . $marker . $after;
102 } elseif (preg_match(
'/^(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $between, $matches) === 1) {
104 $between = $matches[1];
105 $after = $matches[2] . $marker . $after;
106 } elseif (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)$/s', $between, $matches) === 1) {
107 $before .= $marker . $matches[1];
108 $between = $matches[2];
109 $after = $marker . $after;
112 $after = $marker . $after;
116 if (preg_match(
'/^(.*)\\<\\!\\-\\-[^\\>]*$/s', $before, $matches) === 1) {
117 $before = $matches[1];
119 if (is_array($subpartContent)) {
121 if (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $between, $matches) === 1) {
122 $between = $matches[2];
123 } elseif (preg_match(
'/^(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $between, $matches) === 1) {
124 $between = $matches[1];
125 } elseif (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)$/s', $between, $matches) === 1) {
126 $between = $matches[2];
131 if (preg_match(
'/^[^\\<]*\\-\\-\\>(.*)$/s', $after, $matches) === 1) {
132 $after = $matches[1];
135 if (is_array($subpartContent)) {
136 $between = $subpartContent[0] . $between . $subpartContent[1];
138 $between = $subpartContent;
141 return $before . $between . $after;
154 foreach ($subpartsContent as $subpartMarker => $subpartContent) {
174 return str_replace($marker, $markContent, $content);
196 public function substituteMarkerArray($content, $markContentArray, $wrap =
'', $uppercase =
false, $deleteUnused =
false)
198 if (is_array($markContentArray)) {
199 $wrapArr = GeneralUtility::trimExplode(
'|', $wrap);
202 foreach ($markContentArray as $marker => $markContent) {
205 $marker = strtr($marker,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
207 if (isset($wrapArr[0], $wrapArr[1])) {
208 $marker = $wrapArr[0] . $marker . $wrapArr[1];
211 $replace[] = $markContent;
213 $content = str_replace($search, $replace, $content);
214 unset($search, $replace);
217 $wrapArr = [
'###',
'###'];
219 $content = preg_replace(
'/' . preg_quote($wrapArr[0],
'/') .
'([A-Z0-9_|\\-]*)' . preg_quote($wrapArr[1],
'/') .
'/is',
'', $content);
263 $wraps = GeneralUtility::trimExplode(
'|', $wrap);
267 foreach ($markersAndSubparts as $markerName => $markerContent) {
268 if (is_array($markerContent)) {
269 $compoundItems[] = $markerName;
271 $singleItems[$markerName] = $markerContent;
275 $subpartSubstitutes = [];
277 foreach ($compoundItems as $subpartMarker) {
280 $subpartMarker = strtr($subpartMarker,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
282 if (isset($wraps[0], $wraps[1])) {
283 $subpartMarker = $wraps[0] . $subpartMarker . $wraps[1];
285 $subTemplates[$subpartMarker] = $this->
getSubpart($content, $subpartMarker);
288 foreach ($compoundItems as $subpartMarker) {
289 $completeMarker = $subpartMarker;
292 $completeMarker = strtr($completeMarker,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
294 if (isset($wraps[0], $wraps[1])) {
295 $completeMarker = $wraps[0] . $completeMarker . $wraps[1];
297 if (!empty($markersAndSubparts[$subpartMarker])) {
298 $subpartSubstitutes[$completeMarker] =
'';
299 foreach ($markersAndSubparts[$subpartMarker] as $partialMarkersAndSubparts) {
301 $subTemplates[$completeMarker],
302 $partialMarkersAndSubparts,
309 $subpartSubstitutes[$completeMarker] =
'';
351 public function substituteMarkerArrayCached($content, array $markContentArray =
null, array $subpartContentArray =
null, array $wrappedSubpartContentArray =
null)
355 if ($markContentArray ===
null) {
357 $markContentArray = [];
359 if ($subpartContentArray ===
null) {
361 $subpartContentArray = [];
363 if ($wrappedSubpartContentArray ===
null) {
365 $wrappedSubpartContentArray = [];
368 $sPkeys = array_keys($subpartContentArray);
369 $wPkeys = array_keys($wrappedSubpartContentArray);
370 $keysToReplace = array_merge(array_keys($markContentArray), $sPkeys, $wPkeys);
371 if (empty($keysToReplace)) {
374 asort($keysToReplace);
375 $storeKey = md5(
'substituteMarkerArrayCached_storeKey:' . serialize([$content, $keysToReplace]));
376 $fromCache = $runtimeCache->get($storeKey);
378 $storeArr = $fromCache;
381 $storeArrDat = $cache->get($storeKey);
382 if (is_array($storeArrDat)) {
383 $storeArr = $storeArrDat;
385 $runtimeCache->set($storeKey, $storeArr);
388 foreach ($sPkeys as $sPK) {
392 foreach ($wPkeys as $wPK) {
401 $result = preg_match_all(
'/###([^#](?:[^#]*+|#{1,2}[^#])+)###/', $content, $markersInContent);
402 if ($result !==
false && !empty($markersInContent[1])) {
403 $keysToReplaceFlipped = array_flip($keysToReplace);
407 foreach ($markersInContent[1] as $key) {
408 if (isset($keysToReplaceFlipped[
'###' . $key .
'###'])) {
409 $regexKeys[] = preg_quote($key,
'/');
410 $wrappedKeys[] =
'###' . $key .
'###';
413 $regex =
'/###(?:' . implode(
'|', $regexKeys) .
')###/';
414 $storeArr[
'c'] = preg_split($regex, $content);
415 $storeArr[
'k'] = $wrappedKeys;
417 $runtimeCache->set($storeKey, $storeArr);
419 $cache->set($storeKey, $storeArr, [
'substMarkArrayCached'], 0);
423 if (!empty($storeArr[
'k']) && is_array($storeArr[
'k'])) {
426 $valueArr = array_merge($markContentArray, $subpartContentArray, $wrappedSubpartContentArray);
430 foreach ($storeArr[
'k'] as $n => $keyN) {
432 $content .= $storeArr[
'c'][$n];
433 if (!is_array($valueArr[$keyN])) {
435 $content .= $valueArr[$keyN];
437 if (!isset($wSCA_reg[$keyN])) {
438 $wSCA_reg[$keyN] = 0;
441 $content .= $valueArr[$keyN][$wSCA_reg[$keyN] % 2];
446 $content .= $storeArr[
'c'][count($storeArr[
'k'])];
461 if (is_array($tree)) {
462 foreach ($tree as $key => $value) {
484 public function fillInMarkerArray(array $markContentArray, array $row, $fieldList =
'', $nl2br =
true, $prefix =
'FIELD_', $htmlSpecialCharsValue =
false, $respectXhtml =
false)
487 $fArr = GeneralUtility::trimExplode(
',', $fieldList,
true);
488 foreach ($fArr as $field) {
489 $markContentArray[
'###' . $prefix . $field .
'###'] = $nl2br ? nl2br($row[$field], $respectXhtml) : $row[$field];
492 if (is_array($row)) {
493 foreach ($row as $field => $value) {
495 if ($htmlSpecialCharsValue) {
496 $value = htmlspecialchars($value);
498 $markContentArray[
'###' . $prefix . $field .
'###'] = $nl2br ? nl2br($value, $respectXhtml) : $value;
503 return $markContentArray;
513 return GeneralUtility::makeInstance(CacheManager::class)->getCache(
'cache_hash');
523 return GeneralUtility::makeInstance(CacheManager::class)->getCache(
'cache_runtime');