2a75bc1d1df60733a8fd045078318c04807fe78b
[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 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 $frontendController = $this->getFrontendController();
39 $theValue = '';
40 $originalRec = $frontendController->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 ++$frontendController->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 = (bool)$slideCollectReverse;
60 $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.'])
61 ? (bool)$this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.'])
62 : (bool)$conf['slide.']['collectFuzzy'];
63 if (!$slideCollect) {
64 $slideCollectFuzzy = TRUE;
65 }
66 $again = FALSE;
67 $tmpValue = '';
68 $cobjValue = '';
69 $databaseConnection = $this->getDatabaseConnection();
70 do {
71 $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
72 if ($error = $databaseConnection->sql_error()) {
73 $this->getTimeTracker()->setTSlogMessage($error, 3);
74 } else {
75 $this->cObj->currentRecordTotal = $databaseConnection->sql_num_rows($res);
76 $this->getTimeTracker()->setTSlogMessage('NUMROWS: ' . $databaseConnection->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 = $databaseConnection->sql_fetch_assoc($res)) !== FALSE) {
83 // Versioning preview:
84 $frontendController->sys_page->versionOL($conf['table'], $row, TRUE);
85 // Language overlay:
86 if (is_array($row) && $frontendController->sys_language_contentOL) {
87 if ($conf['table'] == 'pages') {
88 $row = $frontendController->sys_page->getPageOverlay($row);
89 } else {
90 $row = $frontendController->sys_page->getRecordOverlay(
91 $conf['table'],
92 $row,
93 $frontendController->sys_language_content,
94 $frontendController->sys_language_contentOL
95 );
96 }
97 }
98 // Might be unset in the sys_language_contentOL
99 if (is_array($row)) {
100 // Call hook for possible manipulation of database row for cObj->data
101 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
102 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
103 $_procObj = GeneralUtility::getUserObj($_classRef);
104 $_procObj->modifyDBRow($row, $conf['table']);
105 }
106 }
107 if (!$frontendController->recordRegister[($conf['table'] . ':' . $row['uid'])]) {
108 $this->cObj->currentRecordNumber++;
109 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
110 $frontendController->currentRecord = $conf['table'] . ':' . $row['uid'];
111 $this->cObj->lastChanged($row['tstamp']);
112 $cObj->start($row, $conf['table']);
113 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
114 $cobjValue .= $tmpValue;
115 }
116 }
117 }
118 $databaseConnection->sql_free_result($res);
119 }
120 if ($slideCollectReverse) {
121 $theValue = $cobjValue . $theValue;
122 } else {
123 $theValue .= $cobjValue;
124 }
125 if ($slideCollect > 0) {
126 $slideCollect--;
127 }
128 if ($slide) {
129 if ($slide > 0) {
130 $slide--;
131 }
132 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
133 if (isset($conf['select.']['pidInList.'])) {
134 unset($conf['select.']['pidInList.']);
135 }
136 $again = (string)$conf['select.']['pidInList'] !== '';
137 }
138 } while ($again && $slide && ((string)$tmpValue === '' && $slideCollectFuzzy || $slideCollect));
139
140 $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
141 if ($wrap) {
142 $theValue = $this->cObj->wrap($theValue, $wrap);
143 }
144 if (isset($conf['stdWrap.'])) {
145 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
146 }
147 // Restore
148 $frontendController->currentRecord = $originalRec;
149 if ($originalRec) {
150 --$frontendController->recordRegister[$originalRec];
151 }
152 return $theValue;
153 }
154
155 /**
156 * Returns the database connection
157 *
158 * @return DatabaseConnection
159 */
160 protected function getDatabaseConnection() {
161 return $GLOBALS['TYPO3_DB'];
162 }
163
164 /**
165 * Returns the frontend controller
166 *
167 * @return TypoScriptFrontendController
168 */
169 protected function getFrontendController() {
170 return $GLOBALS['TSFE'];
171 }
172
173 /**
174 * Returns Time Tracker
175 *
176 * @return TimeTracker
177 */
178 protected function getTimeTracker() {
179 return $GLOBALS['TT'];
180 }
181
182 }