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