TYPO3 CMS  TYPO3_7-6
TemplateContentObject.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
32  public function render($conf = [])
33  {
34  $subparts = [];
35  $marks = [];
36  $wraps = [];
37  $markerWrap = isset($conf['markerWrap.']) ? $this->cObj->stdWrap($conf['markerWrap'], $conf['markerWrap.']) : $conf['markerWrap'];
38  if (!$markerWrap) {
39  $markerWrap = '### | ###';
40  }
41  list($PRE, $POST) = explode('|', $markerWrap);
42  $POST = trim($POST);
43  $PRE = trim($PRE);
44  // Getting the content
45  $content = $this->cObj->cObjGetSingle($conf['template'], $conf['template.'], 'template');
46  $workOnSubpart = isset($conf['workOnSubpart.']) ? $this->cObj->stdWrap($conf['workOnSubpart'], $conf['workOnSubpart.']) : $conf['workOnSubpart'];
47  if ($workOnSubpart) {
48  $content = $this->cObj->getSubpart($content, $PRE . $workOnSubpart . $POST);
49  }
50  // Fixing all relative paths found:
51  if ($conf['relPathPrefix']) {
52  $htmlParser = GeneralUtility::makeInstance(HtmlParser::class);
53  $content = $htmlParser->prefixResourcePath($conf['relPathPrefix'], $content, $conf['relPathPrefix.']);
54  }
55  if ($content) {
56  $nonCachedSubst = isset($conf['nonCachedSubst.']) ? $this->cObj->stdWrap($conf['nonCachedSubst'], $conf['nonCachedSubst.']) : $conf['nonCachedSubst'];
57  // NON-CACHED:
58  if ($nonCachedSubst) {
59  // Getting marks
60  if (is_array($conf['marks.'])) {
61  foreach ($conf['marks.'] as $theKey => $theValue) {
62  if (!strstr($theKey, '.')) {
63  $content = str_replace($PRE . $theKey . $POST, $this->cObj->cObjGetSingle($theValue, $conf['marks.'][$theKey . '.'], 'marks.' . $theKey), $content);
64  }
65  }
66  }
67  // Getting subparts.
68  if (is_array($conf['subparts.'])) {
69  foreach ($conf['subparts.'] as $theKey => $theValue) {
70  if (!strstr($theKey, '.')) {
71  $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
72  if ($subpart) {
73  $this->cObj->setCurrentVal($subpart);
74  $content = $this->cObj->substituteSubpart($content, $PRE . $theKey . $POST, $this->cObj->cObjGetSingle($theValue, $conf['subparts.'][$theKey . '.'], 'subparts.' . $theKey), true);
75  }
76  }
77  }
78  }
79  // Getting subpart wraps
80  if (is_array($conf['wraps.'])) {
81  foreach ($conf['wraps.'] as $theKey => $theValue) {
82  if (!strstr($theKey, '.')) {
83  $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
84  if ($subpart) {
85  $this->cObj->setCurrentVal($subpart);
86  $content = $this->cObj->substituteSubpart($content, $PRE . $theKey . $POST, explode('|', $this->cObj->cObjGetSingle($theValue, $conf['wraps.'][$theKey . '.'], 'wraps.' . $theKey)), true);
87  }
88  }
89  }
90  }
91  } else {
92  // CACHED
93  // Getting subparts.
94  if (is_array($conf['subparts.'])) {
95  foreach ($conf['subparts.'] as $theKey => $theValue) {
96  if (!strstr($theKey, '.')) {
97  $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
98  if ($subpart) {
99  $GLOBALS['TSFE']->register['SUBPART_' . $theKey] = $subpart;
100  $subparts[$theKey]['name'] = $theValue;
101  $subparts[$theKey]['conf'] = $conf['subparts.'][$theKey . '.'];
102  }
103  }
104  }
105  }
106  // Getting marks
107  if (is_array($conf['marks.'])) {
108  foreach ($conf['marks.'] as $theKey => $theValue) {
109  if (!strstr($theKey, '.')) {
110  $marks[$theKey]['name'] = $theValue;
111  $marks[$theKey]['conf'] = $conf['marks.'][$theKey . '.'];
112  }
113  }
114  }
115  // Getting subpart wraps
116  if (is_array($conf['wraps.'])) {
117  foreach ($conf['wraps.'] as $theKey => $theValue) {
118  if (!strstr($theKey, '.')) {
119  $wraps[$theKey]['name'] = $theValue;
120  $wraps[$theKey]['conf'] = $conf['wraps.'][$theKey . '.'];
121  }
122  }
123  }
124  // Getting subparts
125  $subpartArray = [];
126  foreach ($subparts as $theKey => $theValue) {
127  // Set current with the content of the subpart...
128  $this->cObj->data[$this->cObj->currentValKey] = $GLOBALS['TSFE']->register['SUBPART_' . $theKey];
129  // Get subpart cObject and substitute it!
130  $subpartArray[$PRE . $theKey . $POST] = $this->cObj->cObjGetSingle($theValue['name'], $theValue['conf'], 'subparts.' . $theKey);
131  }
132  // Reset current to empty
133  $this->cObj->data[$this->cObj->currentValKey] = '';
134  // Getting marks
135  $markerArray = [];
136  foreach ($marks as $theKey => $theValue) {
137  $markerArray[$PRE . $theKey . $POST] = $this->cObj->cObjGetSingle($theValue['name'], $theValue['conf'], 'marks.' . $theKey);
138  }
139  // Getting wraps
140  $subpartWraps = [];
141  foreach ($wraps as $theKey => $theValue) {
142  $subpartWraps[$PRE . $theKey . $POST] = explode('|', $this->cObj->cObjGetSingle($theValue['name'], $theValue['conf'], 'wraps.' . $theKey));
143  }
144  // Substitution
145  $substMarksSeparately = isset($conf['substMarksSeparately.']) ? $this->cObj->stdWrap($conf['substMarksSeparately'], $conf['substMarksSeparately.']) : $conf['substMarksSeparately'];
146  if ($substMarksSeparately) {
147  $content = $this->cObj->substituteMarkerArrayCached($content, [], $subpartArray, $subpartWraps);
148  $content = $this->cObj->substituteMarkerArray($content, $markerArray);
149  } else {
150  $content = $this->cObj->substituteMarkerArrayCached($content, $markerArray, $subpartArray, $subpartWraps);
151  }
152  }
153  }
154  if (isset($conf['stdWrap.'])) {
155  $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
156  }
157  return $content;
158  }
159 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']