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