[BUGFIX] Hook call modifyDBRow in ContentContentObject
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / content / class.tslib_content_content.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 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 $slideCollect = isset($conf['slide.']['collect.'])
74 ? intval($this->cObj->stdWrap($conf['slide.']['collect'], $conf['slide.']['collect.']))
75 : intval($conf['slide.']['collect']);
76 if (!$slideCollect) {
77 $slideCollect = 0;
78 }
79
80 $slideCollectReverse = isset($conf['slide.']['collectReverse.'])
81 ? intval($this->cObj->stdWrap($conf['slide.']['collectReverse'], $conf['slide.']['collectReverse.']))
82 : intval($conf['slide.']['collectReverse']);
83 $slideCollectReverse = $slideCollectReverse ? TRUE : FALSE;
84
85 $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.'])
86 ? intval($this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.']))
87 : intval($conf['slide.']['collectFuzzy']);
88
89 if ($slideCollectFuzzy) {
90 $slideCollectFuzzy = TRUE;
91 } else {
92 $slideCollectFuzzy = FALSE;
93 }
94
95 if (!$slideCollect) {
96 $slideCollectFuzzy = TRUE;
97 };
98
99 $again = FALSE;
100
101 do {
102 $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
103 if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
104 $GLOBALS['TT']->setTSlogMessage($error, 3);
105 } else {
106 $this->cObj->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
107 $GLOBALS['TT']->setTSlogMessage('NUMROWS: ' . $GLOBALS['TYPO3_DB']->sql_num_rows($res));
108 $cObj = t3lib_div::makeInstance('tslib_cObj');
109 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
110 $this->cObj->currentRecordNumber = 0;
111 $cobjValue = '';
112 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
113
114 // Versioning preview:
115 $GLOBALS['TSFE']->sys_page->versionOL($conf['table'], $row, TRUE);
116
117 // Language overlay:
118 if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
119 if ($conf['table'] == 'pages') {
120 $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
121 } else {
122 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
123 }
124 }
125
126 if (is_array($row)) { // Might be unset in the sys_language_contentOL
127 // Call hook for possible manipulation of database row for cObj->data
128 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
129 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
130 $_procObj = t3lib_div::getUserObj($_classRef);
131 $_procObj->modifyDBRow($row, $conf['table']);
132 }
133 }
134
135 if (!$GLOBALS['TSFE']->recordRegister[$conf['table'] . ':' . $row['uid']]) {
136 $this->cObj->currentRecordNumber++;
137 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
138 $GLOBALS['TSFE']->currentRecord = $conf['table'] . ':' . $row['uid'];
139 $this->cObj->lastChanged($row['tstamp']);
140 $cObj->start($row, $conf['table']);
141 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
142 $cobjValue .= $tmpValue;
143 }
144 }
145 }
146 $GLOBALS['TYPO3_DB']->sql_free_result($res);
147 }
148
149 if ($slideCollectReverse) {
150 $theValue = $cobjValue . $theValue;
151 } else {
152 $theValue .= $cobjValue;
153 }
154 if ($slideCollect > 0) {
155 $slideCollect--;
156 }
157 if ($slide) {
158 if ($slide > 0) {
159 $slide--;
160 }
161 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
162 if (isset($conf['select.']['pidInList.'])) {
163 unset($conf['select.']['pidInList.']);
164 }
165 $again = strlen($conf['select.']['pidInList']) ? TRUE : FALSE;
166 }
167 } while ($again && (($slide && !strlen($tmpValue) && $slideCollectFuzzy) || ($slide && $slideCollect)));
168
169 }
170
171 $wrap = isset($conf['wrap.'])
172 ? $this->cObj->stdWrap($conf['wrap'],$conf['wrap.'])
173 : $conf['wrap'];
174 if ($wrap) {
175 $theValue = $this->cObj->wrap($theValue, $wrap);
176 }
177
178 if (isset($conf['stdWrap.'])) {
179 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
180 }
181
182 $GLOBALS['TSFE']->currentRecord = $originalRec; // Restore
183
184 return $theValue;
185
186 }
187
188 }
189
190
191 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_content.php'])) {
192 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_content.php']);
193 }
194
195 ?>