f5303d1ad72c930878a2489b2e17c4d5aca9595b
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / ContentContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
8 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Contains CONTENT class object.
32 *
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class ContentContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
37
38 /**
39 * Rendering the cObject, CONTENT
40 *
41 * @param array $conf Array of TypoScript properties
42 * @return string Output
43 */
44 public function render($conf = array()) {
45 $theValue = '';
46 $originalRec = $GLOBALS['TSFE']->currentRecord;
47 // If the currentRecord is set, we register, that this record has invoked this function.
48 // It's should not be allowed to do this again then!!
49 if ($originalRec) {
50 $GLOBALS['TSFE']->recordRegister[$originalRec]++;
51 }
52 $conf['table'] = isset($conf['table.']) ? trim($this->cObj->stdWrap($conf['table'], $conf['table.'])) : trim($conf['table']);
53 $tablePrefix = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('_', $conf['table'], TRUE);
54 if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('pages,tt,fe,tx,ttx,user,static', $tablePrefix[0])) {
55 $renderObjName = $conf['renderObj'] ? $conf['renderObj'] : '<' . $conf['table'];
56 $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
57 $renderObjConf = $conf['renderObj.'];
58 $slide = isset($conf['slide.']) ? intval($this->cObj->stdWrap($conf['slide'], $conf['slide.'])) : intval($conf['slide']);
59 if (!$slide) {
60 $slide = 0;
61 }
62 $slideCollect = isset($conf['slide.']['collect.']) ? intval($this->cObj->stdWrap($conf['slide.']['collect'], $conf['slide.']['collect.'])) : intval($conf['slide.']['collect']);
63 if (!$slideCollect) {
64 $slideCollect = 0;
65 }
66 $slideCollectReverse = isset($conf['slide.']['collectReverse.']) ? intval($this->cObj->stdWrap($conf['slide.']['collectReverse'], $conf['slide.']['collectReverse.'])) : intval($conf['slide.']['collectReverse']);
67 $slideCollectReverse = $slideCollectReverse ? TRUE : FALSE;
68 $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.']) ? intval($this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.'])) : intval($conf['slide.']['collectFuzzy']);
69 if ($slideCollectFuzzy) {
70 $slideCollectFuzzy = TRUE;
71 } else {
72 $slideCollectFuzzy = FALSE;
73 }
74 if (!$slideCollect) {
75 $slideCollectFuzzy = TRUE;
76 }
77 $again = FALSE;
78 do {
79 $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
80 if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
81 $GLOBALS['TT']->setTSlogMessage($error, 3);
82 } else {
83 $this->cObj->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
84 $GLOBALS['TT']->setTSlogMessage('NUMROWS: ' . $GLOBALS['TYPO3_DB']->sql_num_rows($res));
85 /** @var $cObj \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
86 $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
87 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
88 $this->cObj->currentRecordNumber = 0;
89 $cobjValue = '';
90 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
91 // Versioning preview:
92 $GLOBALS['TSFE']->sys_page->versionOL($conf['table'], $row, TRUE);
93 // Language overlay:
94 if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
95 if ($conf['table'] == 'pages') {
96 $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
97 } else {
98 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
99 }
100 }
101 // Might be unset in the sys_language_contentOL
102 if (is_array($row)) {
103 // Call hook for possible manipulation of database row for cObj->data
104 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
105 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
106 $_procObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
107 $_procObj->modifyDBRow($row, $conf['table']);
108 }
109 }
110 \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($row, $conf['table']);
111 if (!$GLOBALS['TSFE']->recordRegister[($conf['table'] . ':' . $row['uid'])]) {
112 $this->cObj->currentRecordNumber++;
113 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
114 $GLOBALS['TSFE']->currentRecord = $conf['table'] . ':' . $row['uid'];
115 $this->cObj->lastChanged($row['tstamp']);
116 $cObj->start($row, $conf['table']);
117 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
118 $cobjValue .= $tmpValue;
119 }
120 }
121 }
122 $GLOBALS['TYPO3_DB']->sql_free_result($res);
123 }
124 if ($slideCollectReverse) {
125 $theValue = $cobjValue . $theValue;
126 } else {
127 $theValue .= $cobjValue;
128 }
129 if ($slideCollect > 0) {
130 $slideCollect--;
131 }
132 if ($slide) {
133 if ($slide > 0) {
134 $slide--;
135 }
136 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
137 if (isset($conf['select.']['pidInList.'])) {
138 unset($conf['select.']['pidInList.']);
139 }
140 $again = strlen($conf['select.']['pidInList']) ? TRUE : FALSE;
141 }
142 } while ($again && ($slide && !strlen($tmpValue) && $slideCollectFuzzy || $slide && $slideCollect));
143 }
144 $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
145 if ($wrap) {
146 $theValue = $this->cObj->wrap($theValue, $wrap);
147 }
148 if (isset($conf['stdWrap.'])) {
149 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
150 }
151 // Restore
152 $GLOBALS['TSFE']->currentRecord = $originalRec;
153 return $theValue;
154 }
155
156 }
157
158
159 ?>