[!!!][TASK] Make TimeTracker a singleton
[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 {
35 if (!empty($conf['if.']) && !$this->cObj->checkIf($conf['if.'])) {
36 return '';
37 }
38
39 $frontendController = $this->getFrontendController();
40 $theValue = '';
41 $originalRec = $frontendController->currentRecord;
42 // If the currentRecord is set, we register, that this record has invoked this function.
43 // It's should not be allowed to do this again then!!
44 if ($originalRec) {
45 ++$frontendController->recordRegister[$originalRec];
46 }
47 $conf['table'] = isset($conf['table.']) ? trim($this->cObj->stdWrap($conf['table'], $conf['table.'])) : trim($conf['table']);
48 $conf['select.'] = !empty($conf['select.']) ? $conf['select.'] : array();
49 $renderObjName = $conf['renderObj'] ?: '<' . $conf['table'];
50 $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
51 $renderObjConf = $conf['renderObj.'];
52 $slide = isset($conf['slide.']) ? (int)$this->cObj->stdWrap($conf['slide'], $conf['slide.']) : (int)$conf['slide'];
53 if (!$slide) {
54 $slide = 0;
55 }
56 $slideCollect = isset($conf['slide.']['collect.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collect'], $conf['slide.']['collect.']) : (int)$conf['slide.']['collect'];
57 if (!$slideCollect) {
58 $slideCollect = 0;
59 }
60 $slideCollectReverse = isset($conf['slide.']['collectReverse.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collectReverse'], $conf['slide.']['collectReverse.']) : (int)$conf['slide.']['collectReverse'];
61 $slideCollectReverse = (bool)$slideCollectReverse;
62 $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.'])
63 ? (bool)$this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.'])
64 : (bool)$conf['slide.']['collectFuzzy'];
65 if (!$slideCollect) {
66 $slideCollectFuzzy = true;
67 }
68 $again = false;
69 $tmpValue = '';
70 $cobjValue = '';
71
72 do {
73 $records = $this->cObj->getRecords($conf['table'], $conf['select.']);
74 if (!empty($records)) {
75 $this->cObj->currentRecordTotal = count($records);
76 $this->getTimeTracker()->setTSlogMessage('NUMROWS: ' . count($records));
77
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
84 foreach ($records as $row) {
85 // Call hook for possible manipulation of database row for cObj->data
86 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
87 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
88 $_procObj = GeneralUtility::getUserObj($_classRef);
89 $_procObj->modifyDBRow($row, $conf['table']);
90 }
91 }
92 if (!$frontendController->recordRegister[$conf['table'] . ':' . $row['uid']]) {
93 $this->cObj->currentRecordNumber++;
94 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
95 $frontendController->currentRecord = $conf['table'] . ':' . $row['uid'];
96 $this->cObj->lastChanged($row['tstamp']);
97 $cObj->start($row, $conf['table']);
98 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
99 $cobjValue .= $tmpValue;
100 }
101 }
102 }
103 if ($slideCollectReverse) {
104 $theValue = $cobjValue . $theValue;
105 } else {
106 $theValue .= $cobjValue;
107 }
108 if ($slideCollect > 0) {
109 $slideCollect--;
110 }
111 if ($slide) {
112 if ($slide > 0) {
113 $slide--;
114 }
115 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
116 if (isset($conf['select.']['pidInList.'])) {
117 unset($conf['select.']['pidInList.']);
118 }
119 $again = (string)$conf['select.']['pidInList'] !== '';
120 }
121 } while ($again && $slide && ((string)$tmpValue === '' && $slideCollectFuzzy || $slideCollect));
122
123 $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
124 if ($wrap) {
125 $theValue = $this->cObj->wrap($theValue, $wrap);
126 }
127 if (isset($conf['stdWrap.'])) {
128 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
129 }
130 // Restore
131 $frontendController->currentRecord = $originalRec;
132 if ($originalRec) {
133 --$frontendController->recordRegister[$originalRec];
134 }
135 return $theValue;
136 }
137
138 /**
139 * Returns the database connection
140 *
141 * @return DatabaseConnection
142 */
143 protected function getDatabaseConnection()
144 {
145 return $GLOBALS['TYPO3_DB'];
146 }
147
148 /**
149 * Returns the frontend controller
150 *
151 * @return TypoScriptFrontendController
152 */
153 protected function getFrontendController()
154 {
155 return $GLOBALS['TSFE'];
156 }
157
158 /**
159 * Returns Time Tracker
160 *
161 * @return TimeTracker
162 */
163 protected function getTimeTracker()
164 {
165 return GeneralUtility::makeInstance(TimeTracker::class);
166 }
167 }