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