2 namespace TYPO3\CMS\Core\Service;
35 $start = strpos($content, $marker);
36 if ($start ===
false) {
39 $start += strlen($marker);
40 $stop = strpos($content, $marker, $start);
43 if ($stop ===
false) {
46 $content = substr($content, $start, $stop - $start);
48 if (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $content, $matches) === 1) {
53 if (preg_match(
'/(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $content, $matches) === 1) {
58 if (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)$/s', $content, $matches) === 1) {
76 public function substituteSubpart($content, $marker, $subpartContent, $recursive =
true, $keepMarker =
false)
78 $start = strpos($content, $marker);
79 if ($start ===
false) {
82 $startAM = $start + strlen($marker);
83 $stop = strpos($content, $marker, $startAM);
84 if ($stop ===
false) {
87 $stopAM = $stop + strlen($marker);
88 $before = substr($content, 0, $start);
89 $after = substr($content, $stopAM);
90 $between = substr($content, $startAM, $stop - $startAM);
92 $after = $this->
substituteSubpart($after, $marker, $subpartContent, $recursive, $keepMarker);
96 if (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $between, $matches) === 1) {
97 $before .= $marker . $matches[1];
98 $between = $matches[2];
99 $after = $matches[3] . $marker . $after;
100 }
elseif (preg_match(
'/^(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $between, $matches) === 1) {
102 $between = $matches[1];
103 $after = $matches[2] . $marker . $after;
104 }
elseif (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)$/s', $between, $matches) === 1) {
105 $before .= $marker . $matches[1];
106 $between = $matches[2];
107 $after = $marker . $after;
110 $after = $marker . $after;
114 if (preg_match(
'/^(.*)\\<\\!\\-\\-[^\\>]*$/s', $before, $matches) === 1) {
115 $before = $matches[1];
117 if (is_array($subpartContent)) {
119 if (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $between, $matches) === 1) {
120 $between = $matches[2];
121 }
elseif (preg_match(
'/^(.*)(\\<\\!\\-\\-[^\\>]*)$/s', $between, $matches) === 1) {
122 $between = $matches[1];
123 }
elseif (preg_match(
'/^([^\\<]*\\-\\-\\>)(.*)$/s', $between, $matches) === 1) {
124 $between = $matches[2];
129 if (preg_match(
'/^[^\\<]*\\-\\-\\>(.*)$/s', $after, $matches) === 1) {
130 $after = $matches[1];
133 if (is_array($subpartContent)) {
134 $between = $subpartContent[0] . $between . $subpartContent[1];
136 $between = $subpartContent;
139 return $before . $between . $after;
152 foreach ($subpartsContent as $subpartMarker => $subpartContent) {
172 return str_replace($marker, $markContent, $content);
194 public function substituteMarkerArray($content, $markContentArray, $wrap =
'', $uppercase =
false, $deleteUnused =
false)
196 if (is_array($markContentArray)) {
200 foreach ($markContentArray as $marker => $markContent) {
203 $marker = strtr($marker,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
205 if (!empty($wrapArr)) {
206 $marker = $wrapArr[0] . $marker . $wrapArr[1];
209 $replace[] = $markContent;
211 $content = str_replace($search, $replace, $content);
212 unset($search, $replace);
215 $wrapArr = array(
'###',
'###');
217 $content = preg_replace(
'/' . preg_quote($wrapArr[0],
'/') .
'([A-Z0-9_|\\-]*)' . preg_quote($wrapArr[1],
'/') .
'/is',
'', $content);
264 $singleItems = array();
265 $compoundItems = array();
267 foreach ($markersAndSubparts as $markerName => $markerContent) {
268 if (is_array($markerContent)) {
269 $compoundItems[] = $markerName;
271 $singleItems[$markerName] = $markerContent;
274 $subTemplates = array();
275 $subpartSubstitutes = array();
277 foreach ($compoundItems as $subpartMarker) {
280 $subpartMarker = strtr($subpartMarker,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
282 if (!empty($wraps)) {
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 (!empty($wraps)) {
295 $completeMarker = $wraps[0] . $completeMarker . $wraps[1];
297 if (!empty($markersAndSubparts[$subpartMarker])) {
298 foreach ($markersAndSubparts[$subpartMarker] as $partialMarkersAndSubparts) {
300 $partialMarkersAndSubparts, $wrap, $uppercase, $deleteUnused);
303 $subpartSubstitutes[$completeMarker] =
'';