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