Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / content / class.tslib_content_template.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
6 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Contains TEMPLATE class object.
31 *
32 * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class tslib_content_Template extends tslib_content_Abstract {
37
38 /**
39 * Rendering the cObject, TEMPLATE
40 *
41 * @param array Array of TypoScript properties
42 * @return string Output
43 * @see substituteMarkerArrayCached()
44 */
45 public function render($conf = array()) {
46 $subparts = array();
47 $marks = array();
48 $wraps = array();
49
50 $markerWrap = isset($conf['markerWrap.'])
51 ? $this->cObj->stdWrap($conf['markerWrap'], $conf['markerWrap.'])
52 : $conf['markerWrap'];
53 if(!$markerWrap) {
54 $markerWrap = '### | ###';
55 }
56
57 list ($PRE, $POST) = explode('|', $markerWrap);
58 $POST = trim($POST);
59 $PRE = trim($PRE);
60
61 // Getting the content
62 $content = $this->cObj->cObjGetSingle($conf['template'], $conf['template.'], 'template');
63 $workOnSubpart = isset($conf['workOnSubpart.'])
64 ? $this->cObj->stdWrap($conf['workOnSubpart'], $conf['workOnSubpart.'])
65 : $conf['workOnSubpart'];
66 if ($workOnSubpart) {
67 $content = $this->cObj->getSubpart($content, $PRE . $workOnSubpart . $POST);
68 }
69
70 // Fixing all relative paths found:
71 if ($conf['relPathPrefix']) {
72 $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
73 $content = $htmlParser->prefixResourcePath($conf['relPathPrefix'], $content, $conf['relPathPrefix.']);
74 }
75
76 if ($content) {
77 $nonCachedSubst = isset($conf['nonCachedSubst.'])
78 ? $this->cObj->stdWrap($conf['nonCachedSubst'], $conf['nonCachedSubst.'])
79 : $conf['nonCachedSubst'];
80 if ($nonCachedSubst) { // NON-CACHED:
81 // Getting marks
82 if (is_array($conf['marks.'])) {
83 foreach ($conf['marks.'] as $theKey => $theValue) {
84 if (!strstr($theKey, '.')) {
85 $content = str_replace(
86 $PRE . $theKey . $POST,
87 $this->cObj->cObjGetSingle(
88 $theValue, $conf['marks.'][$theKey . '.'],
89 'marks.' . $theKey
90 ),
91 $content);
92 }
93 }
94 }
95
96 // Getting subparts.
97 if (is_array($conf['subparts.'])) {
98 foreach ($conf['subparts.'] as $theKey => $theValue) {
99 if (!strstr($theKey, '.')) {
100 $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
101 if ($subpart) {
102 $this->cObj->setCurrentVal($subpart);
103 $content = $this->cObj->substituteSubpart(
104 $content,
105 $PRE . $theKey . $POST,
106 $this->cObj->cObjGetSingle(
107 $theValue,
108 $conf['subparts.'][$theKey . '.'],
109 'subparts.' . $theKey),
110 TRUE
111 );
112 }
113 }
114 }
115 }
116 // Getting subpart wraps
117 if (is_array($conf['wraps.'])) {
118 foreach ($conf['wraps.'] as $theKey => $theValue) {
119 if (!strstr($theKey, '.')) {
120 $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
121 if ($subpart) {
122 $this->cObj->setCurrentVal($subpart);
123 $content = $this->cObj->substituteSubpart(
124 $content,
125 $PRE . $theKey . $POST,
126 explode('|', $this->cObj->cObjGetSingle(
127 $theValue, $conf['wraps.'][$theKey . '.'],
128 'wraps.' . $theKey)
129 ),
130 TRUE
131 );
132 }
133 }
134 }
135 }
136 } else { // CACHED
137 // Getting subparts.
138 if (is_array($conf['subparts.'])) {
139 foreach ($conf['subparts.'] as $theKey => $theValue) {
140 if (!strstr($theKey, '.')) {
141 $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
142 if ($subpart) {
143 $GLOBALS['TSFE']->register['SUBPART_' . $theKey] = $subpart;
144 $subparts[$theKey]['name'] = $theValue;
145 $subparts[$theKey]['conf'] = $conf['subparts.'][$theKey . '.'];
146 }
147 }
148 }
149 }
150 // Getting marks
151 if (is_array($conf['marks.'])) {
152 foreach ($conf['marks.'] as $theKey => $theValue) {
153 if (!strstr($theKey, '.')) {
154 $marks[$theKey]['name'] = $theValue;
155 $marks[$theKey]['conf'] = $conf['marks.'][$theKey . '.'];
156 }
157 }
158 }
159 // Getting subpart wraps
160 if (is_array($conf['wraps.'])) {
161 foreach ($conf['wraps.'] as $theKey => $theValue) {
162 if (!strstr($theKey, '.')) {
163 $wraps[$theKey]['name'] = $theValue;
164 $wraps[$theKey]['conf'] = $conf['wraps.'][$theKey . '.'];
165 }
166 }
167 }
168 // Getting subparts
169 $subpartArray = array();
170 foreach ($subparts as $theKey => $theValue) {
171 // Set current with the content of the subpart...
172 $this->cObj->data[$this->cObj->currentValKey] = $GLOBALS['TSFE']->register['SUBPART_' . $theKey];
173 // Get subpart cObject and substitute it!
174 $subpartArray[$PRE . $theKey . $POST] = $this->cObj->cObjGetSingle(
175 $theValue['name'],
176 $theValue['conf'],
177 'subparts.' . $theKey
178 );
179 }
180 $this->cObj->data[$this->cObj->currentValKey] = ''; // Reset current to empty
181
182
183 // Getting marks
184 $markerArray = array();
185 foreach ($marks as $theKey => $theValue) {
186 $markerArray[$PRE . $theKey . $POST] = $this->cObj->cObjGetSingle(
187 $theValue['name'],
188 $theValue['conf'],
189 'marks.' . $theKey
190 );
191 }
192 // Getting wraps
193 $subpartWraps = array();
194 foreach ($wraps as $theKey => $theValue) {
195 $subpartWraps[$PRE . $theKey . $POST] = explode(
196 '|',
197 $this->cObj->cObjGetSingle(
198 $theValue['name'],
199 $theValue['conf'],
200 'wraps.' . $theKey
201 )
202 );
203 }
204
205 // Substitution
206 $substMarksSeparately = isset($conf['substMarksSeparately.'])
207 ? $this->cObj->stdWrap($conf['substMarksSeparately'], $conf['substMarksSeparately.'])
208 : $conf['substMarksSeparately'];
209 if ($substMarksSeparately) {
210 $content = $this->cObj->substituteMarkerArrayCached($content, array(), $subpartArray, $subpartWraps);
211 $content = $this->cObj->substituteMarkerArray($content, $markerArray);
212 } else {
213 $content = $this->cObj->substituteMarkerArrayCached($content, $markerArray, $subpartArray, $subpartWraps);
214 }
215 }
216 }
217
218 if (isset($conf['stdWrap.'])) {
219 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
220 }
221
222 return $content;
223 }
224
225 }
226
227
228 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_template.php'])) {
229 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_template.php']);
230 }
231
232 ?>