4fa1dcffeae385a7b875b14b9a63813489d15ede
[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'] = trim($this->cObj->stdWrap($conf['table'], $conf['table.']));
53 if ($conf['table'] == 'pages' || substr($conf['table'], 0, 3) == 'tt_' || substr($conf['table'], 0, 3) == 'fe_' || substr($conf['table'], 0, 3) == 'tx_' || substr($conf['table'], 0, 4) == 'ttx_' || substr($conf['table'], 0, 5) == 'user_' || substr($conf['table'], 0, 7) == 'static_') {
54
55 $renderObjName = $conf['renderObj'] ? $conf['renderObj'] : '<' . $conf['table'];
56 $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
57 $renderObjConf = $conf['renderObj.'];
58
59 $slide = intval($conf['slide']) ? intval($conf['slide']) : 0;
60 $slideCollect = intval($conf['slide.']['collect']) ? intval($conf['slide.']['collect']) : 0;
61 $slideCollectReverse = intval($conf['slide.']['collectReverse']) ? TRUE : FALSE;
62 $slideCollectFuzzy = $slideCollect ? (intval($conf['slide.']['collectFuzzy']) ? TRUE : FALSE) : TRUE;
63 $again = FALSE;
64
65 do {
66 $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
67 if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
68 $GLOBALS['TT']->setTSlogMessage($error, 3);
69 } else {
70 $this->cObj->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
71 $GLOBALS['TT']->setTSlogMessage('NUMROWS: ' . $GLOBALS['TYPO3_DB']->sql_num_rows($res));
72 $cObj = t3lib_div::makeInstance('tslib_cObj');
73 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
74 $this->cObj->currentRecordNumber = 0;
75 $cobjValue = '';
76 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
77
78 // Versioning preview:
79 $GLOBALS['TSFE']->sys_page->versionOL($conf['table'], $row, TRUE);
80
81 // Language overlay:
82 if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
83 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
84 }
85
86 if (is_array($row)) { // Might be unset in the sys_language_contentOL
87 if (!$GLOBALS['TSFE']->recordRegister[$conf['table'] . ':' . $row['uid']]) {
88 $this->cObj->currentRecordNumber++;
89 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
90 $GLOBALS['TSFE']->currentRecord = $conf['table'] . ':' . $row['uid'];
91 $this->cObj->lastChanged($row['tstamp']);
92 $cObj->start($row, $conf['table']);
93 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
94 $cobjValue .= $tmpValue;
95 }
96 }
97 }
98 $GLOBALS['TYPO3_DB']->sql_free_result($res);
99 }
100 if ($slideCollectReverse) {
101 $theValue = $cobjValue . $theValue;
102 } else {
103 $theValue .= $cobjValue;
104 }
105 if ($slideCollect > 0) {
106 $slideCollect--;
107 }
108 if ($slide) {
109 if ($slide > 0) {
110 $slide--;
111 }
112 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
113 $again = strlen($conf['select.']['pidInList']) ? TRUE : FALSE;
114 }
115 } while ($again && (($slide && !strlen($tmpValue) && $slideCollectFuzzy) || ($slide && $slideCollect)));
116 }
117
118 $theValue = $this->cObj->wrap($theValue, $conf['wrap']);
119 if ($conf['stdWrap.'])
120 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
121
122 $GLOBALS['TSFE']->currentRecord = $originalRec; // Restore
123 return $theValue;
124 }
125
126 }
127
128
129 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_content.php']) {
130 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_content.php']);
131 }
132
133 ?>