Fixed bug #5918: No language overlay with TS select on table pages (Thanks to Fabrizi...
[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 if ($conf['table'] == 'pages') {
118 $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
119 } else {
120 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
121 }
122 }
123
124 if (is_array($row)) { // Might be unset in the sys_language_contentOL
125 // Call hook for possible manipulation of database row for cObj->data
126 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
127 foreach($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
128 $_procObj = t3lib_div::getUserObj($_classRef);
129 $_procObj->modifyDBRow($row, $conf['table']);
130 }
131 }
132
133 if (!$GLOBALS['TSFE']->recordRegister[$conf['table'] . ':' . $row['uid']]) {
134 $this->cObj->currentRecordNumber++;
135 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
136 $GLOBALS['TSFE']->currentRecord = $conf['table'] . ':' . $row['uid'];
137 $this->cObj->lastChanged($row['tstamp']);
138 $cObj->start($row, $conf['table']);
139 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
140 $cobjValue .= $tmpValue;
141 }
142 }
143 }
144 $GLOBALS['TYPO3_DB']->sql_free_result($res);
145 }
146
147 if ($slideCollectReverse) {
148 $theValue = $cobjValue . $theValue;
149 } else {
150 $theValue .= $cobjValue;
151 }
152 if ($slideCollect > 0) {
153 $slideCollect--;
154 }
155 if ($slide) {
156 if ($slide > 0) {
157 $slide--;
158 }
159 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
160 $again = strlen($conf['select.']['pidInList']) ? TRUE : FALSE;
161 }
162 } while ($again && (($slide && !strlen($tmpValue) && $slideCollectFuzzy) || ($slide && $slideCollect)));
163
164 }
165
166 $wrap = isset($conf['wrap.'])
167 ? $this->cObj->stdWrap($conf['wrap'],$conf['wrap.'])
168 : $conf['wrap'];
169 if($wrap) {
170 $theValue = $this->cObj->wrap($theValue, $wrap);
171 }
172
173 if (isset($conf['stdWrap.'])) {
174 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
175 }
176
177 $GLOBALS['TSFE']->currentRecord = $originalRec; // Restore
178
179 return $theValue;
180
181 }
182
183 }
184
185
186 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_content.php']) {
187 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_content.php']);
188 }
189
190 ?>