[BUGFIX] Allow to render the same TS object twice
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / ContentContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Xavier Perseguers <typo3@perseguers.ch>
8 * (c) 2010-2013 Steffen Kamper <steffen@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the text file GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Contains CONTENT class object.
32 *
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class ContentContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
37
38 /**
39 * Rendering the cObject, CONTENT
40 *
41 * @param array $conf Array of TypoScript properties
42 * @return string Output
43 */
44 public function render($conf = array()) {
45 $theValue = '';
46 $originalRec = $GLOBALS['TSFE']->currentRecord;
47 // If the currentRecord is set, we register, that this record has invoked this function.
48 // It's should not be allowed to do this again then!!
49 if ($originalRec) {
50 ++$GLOBALS['TSFE']->recordRegister[$originalRec];
51 }
52 $conf['table'] = isset($conf['table.']) ? trim($this->cObj->stdWrap($conf['table'], $conf['table.'])) : trim($conf['table']);
53 $renderObjName = $conf['renderObj'] ?: '<' . $conf['table'];
54 $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
55 $renderObjConf = $conf['renderObj.'];
56 $slide = isset($conf['slide.']) ? (int)$this->cObj->stdWrap($conf['slide'], $conf['slide.']) : (int)$conf['slide'];
57 if (!$slide) {
58 $slide = 0;
59 }
60 $slideCollect = isset($conf['slide.']['collect.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collect'], $conf['slide.']['collect.']) : (int)$conf['slide.']['collect'];
61 if (!$slideCollect) {
62 $slideCollect = 0;
63 }
64 $slideCollectReverse = isset($conf['slide.']['collectReverse.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collectReverse'], $conf['slide.']['collectReverse.']) : (int)$conf['slide.']['collectReverse'];
65 $slideCollectReverse = $slideCollectReverse ? TRUE : FALSE;
66 $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.']) : (int)$conf['slide.']['collectFuzzy'];
67 if ($slideCollectFuzzy) {
68 $slideCollectFuzzy = TRUE;
69 } else {
70 $slideCollectFuzzy = FALSE;
71 }
72 if (!$slideCollect) {
73 $slideCollectFuzzy = TRUE;
74 }
75 $again = FALSE;
76 do {
77 $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
78 if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
79 $GLOBALS['TT']->setTSlogMessage($error, 3);
80 } else {
81 $this->cObj->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
82 $GLOBALS['TT']->setTSlogMessage('NUMROWS: ' . $GLOBALS['TYPO3_DB']->sql_num_rows($res));
83 /** @var $cObj \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
84 $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
85 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
86 $this->cObj->currentRecordNumber = 0;
87 $cobjValue = '';
88 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
89 // Versioning preview:
90 $GLOBALS['TSFE']->sys_page->versionOL($conf['table'], $row, TRUE);
91 // Language overlay:
92 if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
93 if ($conf['table'] == 'pages') {
94 $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
95 } else {
96 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
97 }
98 }
99 // Might be unset in the sys_language_contentOL
100 if (is_array($row)) {
101 // Call hook for possible manipulation of database row for cObj->data
102 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
103 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
104 $_procObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
105 $_procObj->modifyDBRow($row, $conf['table']);
106 }
107 }
108 \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($row, $conf['table']);
109 if (!$GLOBALS['TSFE']->recordRegister[($conf['table'] . ':' . $row['uid'])]) {
110 $this->cObj->currentRecordNumber++;
111 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
112 $GLOBALS['TSFE']->currentRecord = $conf['table'] . ':' . $row['uid'];
113 $this->cObj->lastChanged($row['tstamp']);
114 $cObj->start($row, $conf['table']);
115 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
116 $cobjValue .= $tmpValue;
117 }
118 }
119 }
120 $GLOBALS['TYPO3_DB']->sql_free_result($res);
121 }
122 if ($slideCollectReverse) {
123 $theValue = $cobjValue . $theValue;
124 } else {
125 $theValue .= $cobjValue;
126 }
127 if ($slideCollect > 0) {
128 $slideCollect--;
129 }
130 if ($slide) {
131 if ($slide > 0) {
132 $slide--;
133 }
134 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
135 if (isset($conf['select.']['pidInList.'])) {
136 unset($conf['select.']['pidInList.']);
137 }
138 $again = strlen($conf['select.']['pidInList']) ? TRUE : FALSE;
139 }
140 } while ($again && ($slide && !strlen($tmpValue) && $slideCollectFuzzy || $slide && $slideCollect));
141
142 $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
143 if ($wrap) {
144 $theValue = $this->cObj->wrap($theValue, $wrap);
145 }
146 if (isset($conf['stdWrap.'])) {
147 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
148 }
149 // Restore
150 $GLOBALS['TSFE']->currentRecord = $originalRec;
151 if ($originalRec) {
152 --$GLOBALS['TSFE']->recordRegister[$originalRec];
153 }
154 return $theValue;
155 }
156
157 }