Fixed bug #16191: Optimize stdWrap usage for TypoScript content element CONTENT ...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / content / class.tslib_content_content.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Xavier Perseguers <typo3@perseguers.ch>
6 * (c) 2010 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 CONTENT 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_Content extends tslib_content_Abstract {
37
38 /**
39 * Rendering the cObject, CONTENT
40 *
41 * @param array Array of TypoScript properties
42 * @return string Output
43 */
44 public function render($conf = array()) {
45 $theValue = '';
46
47 $originalRec = $GLOBALS['TSFE']->currentRecord;
48 if ($originalRec) { // If the currentRecord is set, we register, that this record has invoked this function. It's should not be allowed to do this again then!!
49 $GLOBALS['TSFE']->recordRegister[$originalRec]++;
50 }
51
52 $conf['table'] = isset($conf['table.'])
53 ? trim($this->cObj->stdWrap($conf['table'], $conf['table.']))
54 : trim($conf['table']);
55 $tablePrefix = t3lib_div::trimExplode('_', $conf['table'], TRUE);
56 if (t3lib_div::inList('pages,tt,fe,tx,ttx,user,static', $tablePrefix[0])) {
57
58 $renderObjName = $conf['renderObj']
59 ? $conf['renderObj']
60 : '<' . $conf['table'];
61 $renderObjKey = $conf['renderObj']
62 ? 'renderObj'
63 : '';
64 $renderObjConf = $conf['renderObj.'];
65
66 $slide = isset($conf['slide.'])
67 ? intval($this->cObj->stdWrap($conf['slide'], $conf['slide.']))
68 : intval($conf['slide']);
69 if(!$slide) {
70 $slide = 0;
71 }
72
73 if(isset($conf['slide.'])) {
74 $slideCollect = isset($conf['slide.']['collect.'])
75 ? intval($this->cObj->stdWrap($conf['slide.']['collect'], $conf['slide.']['collect.']))
76 : intval($conf['slide.']['collect']);
77 if(!$slideCollect) {
78 $slideCollect = 0;
79 }
80
81 $slideCollectReverse = isset($conf['slide.']['collectReverse.'])
82 ? intval($this->cObj->stdWrap($conf['slide.']['collectReverse'], $conf['slide.']['collectReverse.']))
83 : intval($conf['slide.']['collectReverse']);
84 $slideCollectReverse = $slideCollectReverse ? TRUE : FALSE;
85
86 $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.'])
87 ? intval($this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.']))
88 : intval($conf['slide.']['collectFuzzy']);
89
90 if(!$slideCollectFuzzy) {
91 $slideCollectFuzzy = FALSE;
92 } else if ($slideCollect) {
93 $slideCollectFuzzy = TRUE;
94 };
95 }
96
97 $again = FALSE;
98
99 do {
100 $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
101 if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
102 $GLOBALS['TT']->setTSlogMessage($error, 3);
103 } else {
104 $this->cObj->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
105 $GLOBALS['TT']->setTSlogMessage('NUMROWS: ' . $GLOBALS['TYPO3_DB']->sql_num_rows($res));
106 $cObj = t3lib_div::makeInstance('tslib_cObj');
107 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
108 $this->cObj->currentRecordNumber = 0;
109 $cobjValue = '';
110 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
111
112 // Versioning preview:
113 $GLOBALS['TSFE']->sys_page->versionOL($conf['table'], $row, TRUE);
114
115 // Language overlay:
116 if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
117 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
118 }
119
120 if (is_array($row)) { // Might be unset in the sys_language_contentOL
121 if (!$GLOBALS['TSFE']->recordRegister[$conf['table'] . ':' . $row['uid']]) {
122 $this->cObj->currentRecordNumber++;
123 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
124 $GLOBALS['TSFE']->currentRecord = $conf['table'] . ':' . $row['uid'];
125 $this->cObj->lastChanged($row['tstamp']);
126 $cObj->start($row, $conf['table']);
127 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
128 $cobjValue .= $tmpValue;
129 }
130 }
131 }
132 $GLOBALS['TYPO3_DB']->sql_free_result($res);
133 }
134
135 if ($slideCollectReverse) {
136 $theValue = $cobjValue . $theValue;
137 } else {
138 $theValue .= $cobjValue;
139 }
140 if ($slideCollect > 0) {
141 $slideCollect--;
142 }
143 if ($slide) {
144 if ($slide > 0) {
145 $slide--;
146 }
147 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
148 $again = strlen($conf['select.']['pidInList']) ? TRUE : FALSE;
149 }
150 } while ($again && (($slide && !strlen($tmpValue) && $slideCollectFuzzy) || ($slide && $slideCollect)));
151
152 }
153
154 $wrap = isset($conf['wrap.'])
155 ? $this->cObj->stdWrap($conf['wrap'],$conf['wrap.'])
156 : $conf['wrap'];
157 if($wrap) {
158 $theValue = $this->cObj->wrap($theValue, $wrap);
159 }
160
161 if (isset($conf['stdWrap.'])) {
162 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
163 }
164
165 $GLOBALS['TSFE']->currentRecord = $originalRec; // Restore
166
167 return $theValue;
168
169 }
170
171 }
172
173
174 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_content.php']) {
175 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_content.php']);
176 }
177
178 ?>