‪TYPO3CMS  10.4
TemplateContentObject.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
26 {
30  protected ‪$templateService;
31 
38  {
39  $this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
40  parent::__construct(‪$cObj);
41  }
42 
50  public function ‪render($conf = [])
51  {
52  $subparts = [];
53  $marks = [];
54  $wraps = [];
55  $markerWrap = isset($conf['markerWrap.']) ? $this->cObj->stdWrap($conf['markerWrap'], $conf['markerWrap.']) : $conf['markerWrap'];
56  if (!$markerWrap) {
57  $markerWrap = '### | ###';
58  }
59  [$PRE, $POST] = explode('|', $markerWrap);
60  $POST = trim($POST);
61  $PRE = trim($PRE);
62  // Getting the content
63  $content = $this->cObj->cObjGetSingle($conf['template'], $conf['template.'], 'template');
64  $workOnSubpart = isset($conf['workOnSubpart.']) ? $this->cObj->stdWrap($conf['workOnSubpart'], $conf['workOnSubpart.']) : $conf['workOnSubpart'];
65  if ($workOnSubpart) {
66  $content = $this->templateService->getSubpart($content, $PRE . $workOnSubpart . $POST);
67  }
68  // Fixing all relative paths found:
69  if ($conf['relPathPrefix']) {
70  $htmlParser = GeneralUtility::makeInstance(HtmlParser::class);
71  $content = $htmlParser->prefixResourcePath($conf['relPathPrefix'], $content, $conf['relPathPrefix.']);
72  }
73  if ($content) {
74  $nonCachedSubst = isset($conf['nonCachedSubst.']) ? $this->cObj->stdWrap($conf['nonCachedSubst'], $conf['nonCachedSubst.']) : $conf['nonCachedSubst'];
75  // NON-CACHED:
76  if ($nonCachedSubst) {
77  // Getting marks
78  if (is_array($conf['marks.'])) {
79  foreach ($conf['marks.'] as $theKey => $theValue) {
80  if (strpos($theKey, '.') === false) {
81  $content = str_replace($PRE . $theKey . $POST, $this->cObj->cObjGetSingle($theValue, $conf['marks.'][$theKey . '.'], 'marks.' . $theKey), $content);
82  }
83  }
84  }
85  // Getting subparts.
86  if (is_array($conf['subparts.'])) {
87  foreach ($conf['subparts.'] as $theKey => $theValue) {
88  if (strpos($theKey, '.') === false) {
89  $subpart = $this->templateService->getSubpart($content, $PRE . $theKey . $POST);
90  if ($subpart) {
91  $this->cObj->setCurrentVal($subpart);
92  $content = $this->templateService->substituteSubpart($content, $PRE . $theKey . $POST, $this->cObj->cObjGetSingle($theValue, $conf['subparts.'][$theKey . '.'], 'subparts.' . $theKey), true);
93  }
94  }
95  }
96  }
97  // Getting subpart wraps
98  if (is_array($conf['wraps.'])) {
99  foreach ($conf['wraps.'] as $theKey => $theValue) {
100  if (strpos($theKey, '.') === false) {
101  $subpart = $this->templateService->getSubpart($content, $PRE . $theKey . $POST);
102  if ($subpart) {
103  $this->cObj->setCurrentVal($subpart);
104  $content = $this->templateService->substituteSubpart($content, $PRE . $theKey . $POST, explode('|', $this->cObj->cObjGetSingle($theValue, $conf['wraps.'][$theKey . '.'], 'wraps.' . $theKey)), true);
105  }
106  }
107  }
108  }
109  } else {
110  // CACHED
111  // Getting subparts.
112  if (is_array($conf['subparts.'])) {
113  foreach ($conf['subparts.'] as $theKey => $theValue) {
114  if (strpos($theKey, '.') === false) {
115  $subpart = $this->templateService->getSubpart($content, $PRE . $theKey . $POST);
116  if ($subpart) {
117  ‪$GLOBALS['TSFE']->register['SUBPART_' . $theKey] = $subpart;
118  $subparts[$theKey]['name'] = $theValue;
119  $subparts[$theKey]['conf'] = $conf['subparts.'][$theKey . '.'];
120  }
121  }
122  }
123  }
124  // Getting marks
125  if (is_array($conf['marks.'])) {
126  foreach ($conf['marks.'] as $theKey => $theValue) {
127  if (strpos($theKey, '.') === false) {
128  $marks[$theKey]['name'] = $theValue;
129  $marks[$theKey]['conf'] = $conf['marks.'][$theKey . '.'];
130  }
131  }
132  }
133  // Getting subpart wraps
134  if (is_array($conf['wraps.'])) {
135  foreach ($conf['wraps.'] as $theKey => $theValue) {
136  if (strpos($theKey, '.') === false) {
137  $wraps[$theKey]['name'] = $theValue;
138  $wraps[$theKey]['conf'] = $conf['wraps.'][$theKey . '.'];
139  }
140  }
141  }
142  // Getting subparts
143  $subpartArray = [];
144  foreach ($subparts as $theKey => $theValue) {
145  // Set current with the content of the subpart...
146  $this->cObj->data[$this->cObj->currentValKey] = ‪$GLOBALS['TSFE']->register['SUBPART_' . $theKey];
147  // Get subpart cObject and substitute it!
148  $subpartArray[$PRE . $theKey . $POST] = $this->cObj->cObjGetSingle($theValue['name'], $theValue['conf'], 'subparts.' . $theKey);
149  }
150  // Reset current to empty
151  $this->cObj->data[$this->cObj->currentValKey] = '';
152  // Getting marks
153  $markerArray = [];
154  foreach ($marks as $theKey => $theValue) {
155  $markerArray[$PRE . $theKey . $POST] = $this->cObj->cObjGetSingle($theValue['name'], $theValue['conf'], 'marks.' . $theKey);
156  }
157  // Getting wraps
158  $subpartWraps = [];
159  foreach ($wraps as $theKey => $theValue) {
160  $subpartWraps[$PRE . $theKey . $POST] = explode('|', $this->cObj->cObjGetSingle($theValue['name'], $theValue['conf'], 'wraps.' . $theKey));
161  }
162  // Substitution
163  $substMarksSeparately = isset($conf['substMarksSeparately.']) ? $this->cObj->stdWrap($conf['substMarksSeparately'], $conf['substMarksSeparately.']) : $conf['substMarksSeparately'];
164  if ($substMarksSeparately) {
165  $content = $this->templateService->substituteMarkerArrayCached($content, [], $subpartArray, $subpartWraps);
166  $content = $this->templateService->substituteMarkerArray($content, $markerArray);
167  } else {
168  $content = $this->templateService->substituteMarkerArrayCached($content, $markerArray, $subpartArray, $subpartWraps);
169  }
170  }
171  }
172  if (isset($conf['stdWrap.'])) {
173  $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
174  }
175  return $content;
176  }
177 }
‪TYPO3\CMS\Core\Html\HtmlParser
Definition: HtmlParser.php:27
‪TYPO3\CMS\Frontend\ContentObject\TemplateContentObject\render
‪string render($conf=[])
Definition: TemplateContentObject.php:49
‪TYPO3\CMS\Frontend\ContentObject
Definition: AbstractContentObject.php:16
‪TYPO3\CMS\Frontend\ContentObject\TemplateContentObject\$templateService
‪MarkerBasedTemplateService $templateService
Definition: TemplateContentObject.php:29
‪TYPO3\CMS\Frontend\ContentObject\TemplateContentObject\__construct
‪__construct(ContentObjectRenderer $cObj)
Definition: TemplateContentObject.php:36
‪TYPO3\CMS\Frontend\ContentObject\TemplateContentObject
Definition: TemplateContentObject.php:26
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject
Definition: AbstractContentObject.php:25
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\$cObj
‪ContentObjectRenderer $cObj
Definition: AbstractContentObject.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Core\Service\MarkerBasedTemplateService
Definition: MarkerBasedTemplateService.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46