[!!!][TASK] Drop ContentAdapter
[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\Utility\GeneralUtility;
18
19 /**
20 * Contains CONTENT class object.
21 *
22 * @author Xavier Perseguers <typo3@perseguers.ch>
23 * @author Steffen Kamper <steffen@typo3.org>
24 */
25 class ContentContentObject extends AbstractContentObject {
26
27 /**
28 * Rendering the cObject, CONTENT
29 *
30 * @param array $conf Array of TypoScript properties
31 * @return string Output
32 */
33 public function render($conf = array()) {
34 if (!empty($conf['if.']) && !$this->cObj->checkIf($conf['if.'])) {
35 return '';
36 }
37
38 $theValue = '';
39 $originalRec = $GLOBALS['TSFE']->currentRecord;
40 // If the currentRecord is set, we register, that this record has invoked this function.
41 // It's should not be allowed to do this again then!!
42 if ($originalRec) {
43 ++$GLOBALS['TSFE']->recordRegister[$originalRec];
44 }
45 $conf['table'] = isset($conf['table.']) ? trim($this->cObj->stdWrap($conf['table'], $conf['table.'])) : trim($conf['table']);
46 $renderObjName = $conf['renderObj'] ?: '<' . $conf['table'];
47 $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
48 $renderObjConf = $conf['renderObj.'];
49 $slide = isset($conf['slide.']) ? (int)$this->cObj->stdWrap($conf['slide'], $conf['slide.']) : (int)$conf['slide'];
50 if (!$slide) {
51 $slide = 0;
52 }
53 $slideCollect = isset($conf['slide.']['collect.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collect'], $conf['slide.']['collect.']) : (int)$conf['slide.']['collect'];
54 if (!$slideCollect) {
55 $slideCollect = 0;
56 }
57 $slideCollectReverse = isset($conf['slide.']['collectReverse.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collectReverse'], $conf['slide.']['collectReverse.']) : (int)$conf['slide.']['collectReverse'];
58 $slideCollectReverse = $slideCollectReverse ? TRUE : FALSE;
59 $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.']) : (int)$conf['slide.']['collectFuzzy'];
60 if ($slideCollectFuzzy) {
61 $slideCollectFuzzy = TRUE;
62 } else {
63 $slideCollectFuzzy = FALSE;
64 }
65 if (!$slideCollect) {
66 $slideCollectFuzzy = TRUE;
67 }
68 $again = FALSE;
69 $tmpValue = '';
70 do {
71 $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
72 if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
73 $GLOBALS['TT']->setTSlogMessage($error, 3);
74 } else {
75 $this->cObj->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
76 $GLOBALS['TT']->setTSlogMessage('NUMROWS: ' . $GLOBALS['TYPO3_DB']->sql_num_rows($res));
77 /** @var $cObj ContentObjectRenderer */
78 $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
79 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
80 $this->cObj->currentRecordNumber = 0;
81 $cobjValue = '';
82 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
83 // Versioning preview:
84 $GLOBALS['TSFE']->sys_page->versionOL($conf['table'], $row, TRUE);
85 // Language overlay:
86 if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
87 if ($conf['table'] == 'pages') {
88 $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
89 } else {
90 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
91 }
92 }
93 // Might be unset in the sys_language_contentOL
94 if (is_array($row)) {
95 // Call hook for possible manipulation of database row for cObj->data
96 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
97 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
98 $_procObj = GeneralUtility::getUserObj($_classRef);
99 $_procObj->modifyDBRow($row, $conf['table']);
100 }
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 = (string)$conf['select.']['pidInList'] !== '';
132 }
133 } while ($again && $slide && (string)$tmpValue === '' && $slideCollectFuzzy || $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 }