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