[BUGFIX] Prevent duplicate stdWrap for media content
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / content / class.tslib_content_media.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
6 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Contains MEDIA class object.
31 *
32 * @author Xavier Perseguers <typo3@perseguers.ch>
33 * @author Steffen Kamper <steffen@typo3.org>
34 */
35 class tslib_content_Media extends tslib_content_Abstract {
36
37 /**
38 * Rendering the cObject, MEDIA
39 *
40 * @param $conf array Array of TypoScript properties
41 * @return string Output
42 */
43 public function render($conf = array()) {
44 $content = '';
45 $flexParams = isset($conf['flexParams.'])
46 ? $this->cObj->stdWrap($conf['flexParams'], $conf['flexParams.'])
47 : $conf['flexParams'];
48 if (substr($flexParams, 0, 1) === '<') {
49 // it is a content element
50 $this->cObj->readFlexformIntoConf($flexParams, $conf['parameter.']);
51 $url = isset($conf['file.'])
52 ? $this->cObj->stdWrap($conf['parameter.']['mmFile'], $conf['file.'])
53 : $conf['parameter.']['mmFile'];
54 $mmFile = $url;
55 } else {
56 // it is a TS object
57 $url = isset($conf['file.'])
58 ? $this->cObj->stdWrap($conf['file'], $conf['file.'])
59 : $conf['file'];
60 }
61
62 $mode = is_file(PATH_site . $url) ? 'file' : 'url';
63 if ($mode === 'file') {
64 // render FILE
65 $filename = $GLOBALS['TSFE']->tmpl->getFileName($url);
66 $fileinfo = t3lib_div::split_fileref($filename);
67 $conf['file'] = $filename;
68 } else {
69 // render URL
70 // use media wizard to extract video from URL
71 $mediaWizard = tslib_mediaWizardManager::getValidMediaWizardProvider($url);
72 if ($mediaWizard !== NULL) {
73 $url = $mediaWizard->rewriteUrl($url);
74 }
75 $conf['file'] = $this->cObj->typoLink_URL(array(
76 'parameter' => $url
77 ));
78 }
79
80 $renderType = isset($conf['renderType.'])
81 ? $this->cObj->stdWrap($conf['renderType'], $conf['renderType.'])
82 : $conf['renderType'];
83 $mmRenderType = isset($conf['parameter.']['mmRenderType.'])
84 ? $this->cObj->stdWrap($conf['parameter.']['mmRenderType'], $conf['parameter.']['mmRenderType.'])
85 : $conf['parameter.']['mmRenderType'];
86 if ($mmRenderType) {
87 $renderType = $mmRenderType;
88 }
89 if ($renderType === 'auto') {
90 // default renderType is swf
91 $renderType = 'swf';
92 $handler = array_keys($conf['fileExtHandler.']);
93 if (in_array($fileinfo['fileext'], $handler)) {
94 $renderType = strtolower($conf['fileExtHandler.'][$fileinfo['fileext']]);
95 }
96 }
97
98 $mmForcePlayer = isset($conf['parameter.']['mmforcePlayer.'])
99 ? $this->cObj->stdWrap($conf['parameter.']['mmforcePlayer'], $conf['parameter.']['mmforcePlayer.'])
100 : $conf['parameter.']['mmforcePlayer'];
101
102 $forcePlayer = $mmFile ? intval($mmForcePlayer) : $conf['forcePlayer'];
103 $conf['forcePlayer'] = isset($conf['forcePlayer.'])
104 ? $this->cObj->stdWrap($forcePlayer, $conf['forcePlayer.'])
105 : $forcePlayer;
106
107 $mmType = isset($conf['parameter.']['mmType.'])
108 ? $this->cObj->stdWrap($conf['parameter.']['mmType'], $conf['parameter.']['mmType.'])
109 : $conf['parameter.']['mmType'];
110
111 $type = isset($conf['type.'])
112 ? $this->cObj->stdWrap($conf['type'], $conf['type.'])
113 : $conf['type'];
114
115 $conf['type'] = $mmType ? $mmType : $type;
116 $mime = $renderType . 'object';
117 $typeConf = $conf['mimeConf.'][$mime . '.'][$conf['type'] . '.'] ? $conf['mimeConf.'][$mime . '.'][$conf['type'] . '.'] : array();
118 $conf['predefined'] = array();
119
120 $width = isset($conf['parameter.']['mmWidth.'])
121 ? intval($this->cObj->stdWrap($conf['parameter.']['mmWidth'], $conf['parameter.']['mmWidth.']))
122 : intval($conf['parameter.']['mmWidth']);
123 $height = isset($conf['parameter.']['mmHeight.'])
124 ? intval($this->cObj->stdWrap($conf['parameter.']['mmHeight'], $conf['parameter.']['mmHeight.']))
125 : intval($conf['parameter.']['mmHeight']);
126 if ($width) {
127 $conf['width'] = $width;
128 } else {
129 $width = isset($conf['width.'])
130 ? intval($this->cObj->stdWrap($conf['width'], $conf['width.']))
131 : intval($conf['width']);
132 $conf['width'] = $width ? $width : $typeConf['defaultWidth'];
133 }
134 if ($height) {
135 $conf['height'] = $height;
136 } else {
137 $height = isset($conf['height.'])
138 ? intval($this->cObj->stdWrap($conf['height'], $conf['height.']))
139 : intval($conf['height']);
140 $conf['height'] = $height ? $height : $typeConf['defaultHeight'];
141 }
142
143 if (is_array($conf['parameter.']['mmMediaOptions'])) {
144 $params = array();
145 foreach ($conf['parameter.']['mmMediaOptions'] as $key => $value) {
146 if ($key == 'mmMediaCustomParameterContainer') {
147 foreach ($value as $val) {
148 //custom parameter entry
149 $rawTS = $val['mmParamCustomEntry'];
150 //read and merge
151 $tmp = t3lib_div::trimExplode(LF, $rawTS);
152 if (count($tmp)) {
153 foreach ($tmp as $tsLine) {
154 if (substr($tsLine, 0, 1) != '#' && $pos = strpos($tsLine, '.')) {
155 $parts[0] = substr($tsLine, 0, $pos);
156 $parts[1] = substr($tsLine, $pos + 1);
157 $valueParts = t3lib_div::trimExplode('=', $parts[1], TRUE);
158
159 switch (strtolower($parts[0])) {
160 case 'flashvars' :
161 $conf['flashvars.'][$valueParts[0]] = $valueParts[1];
162 break;
163 case 'params' :
164 $conf['params.'][$valueParts[0]] = $valueParts[1];
165 break;
166 case 'attributes' :
167 $conf['attributes.'][$valueParts[0]] = $valueParts[1];
168 break;
169 }
170 }
171 }
172 }
173 }
174 } elseif ($key == 'mmMediaOptionsContainer') {
175 foreach ($value as $val) {
176 if (isset($val['mmParamSet'])) {
177 $pName = $val['mmParamName'];
178 $pSet = $val['mmParamSet'];
179 $pValue = $pSet == 2 ? $val['mmParamValue'] : ($pSet == 0 ? 'false' : 'true');
180 $conf['predefined'][$pName] = $pValue;
181 }
182 }
183 }
184 }
185 }
186
187 // render MEDIA
188 if ($mode == 'url' && !$forcePlayer) {
189 // url is called direct, not with player
190 if ($url == '' && !$conf['allowEmptyUrl']) {
191 return '<p style="background-color: yellow;">' . $GLOBALS['TSFE']->sL('LLL:EXT:cms/locallang_ttc.xml:media.noFile', TRUE) . '</p>';
192 }
193 $conf = array_merge((array) $conf['mimeConf.']['swfobject.'], $conf);
194 $conf[$conf['type'] . '.']['player'] = strpos($url, '://') === FALSE ? 'http://' . $url : $url;
195 $conf['installUrl'] = 'null';
196 $conf['flashvars'] = array_merge((array) $conf['flashvars'], $conf['predefined']);
197 }
198
199 switch ($renderType) {
200 case 'swf' :
201 $conf[$conf['type'] . '.'] = array_merge((array) $conf['mimeConf.']['swfobject.'][$conf['type'] . '.'], $typeConf);
202 $conf = array_merge((array) $conf['mimeConf.']['swfobject.'], $conf);
203 unset($conf['mimeConf.']);
204 $conf['flashvars.'] = array_merge((array) $conf['flashvars.'], $conf['predefined']);
205 $content = $this->cObj->SWFOBJECT($conf);
206 break;
207 case 'qt' :
208 $conf[$conf['type'] . '.'] = array_merge($conf['mimeConf.']['swfobject.'][$conf['type'] . '.'], $typeConf);
209 $conf = array_merge($conf['mimeConf.']['qtobject.'], $conf);
210 unset($conf['mimeConf.']);
211 $conf['params.'] = array_merge((array) $conf['params.'], $conf['predefined']);
212 $content = $this->cObj->QTOBJECT($conf);
213 break;
214 case 'embed' :
215 $paramsArray = array_merge((array) $typeConf['default.']['params.'], (array) $conf['params.'], $conf['predefined']);
216 $conf['params'] = '';
217 foreach ($paramsArray as $key => $value) {
218 $conf['params'] .= $key . '=' . $value . LF;
219 }
220 $content = $this->cObj->MULTIMEDIA($conf);
221 break;
222 default :
223 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['customMediaRender'])) {
224 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['customMediaRender'] as $classRef) {
225 $hookObj = t3lib_div::getUserObj($classRef);
226 $conf['file'] = $url;
227 $conf['mode'] = $mode;
228 $content = $hookObj->customMediaRender($renderType, $conf, $this);
229 }
230 }
231 if (isset($conf['stdWrap.'])) {
232 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
233 }
234 }
235
236 return $content;
237 }
238
239 }
240
241
242 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_media.php'])) {
243 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_media.php']);
244 }
245
246 ?>