0a28fc70583228184e5d7a518eaeb70bd03852a1
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / content / class.tslib_content_media.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Xavier Perseguers <typo3@perseguers.ch>
6 * (c) 2010 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 * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class tslib_content_Media extends tslib_content_Abstract {
37
38 /**
39 * Rendering the cObject, MEDIA
40 *
41 * @param array Array of TypoScript properties
42 * @return string Output
43 */
44 public function render($conf = array()) {
45 $content = '';
46 $flexParams = isset($conf['flexParams.'])
47 ? $this->cObj->stdWrap($conf['flexParams'], $conf['flexParams.'])
48 : $conf['flexParams'];
49 if (substr($flexParams, 0, 1) === '<') {
50 // it is a content element
51 $this->cObj->readFlexformIntoConf($flexParams, $conf['parameter.']);
52 $url = isset($conf['file.'])
53 ? $this->cObj->stdWrap($conf['parameter.']['mmFile'], $conf['file.'])
54 : $conf['parameter.']['mmFile'];
55 $mmFile = $url;
56 } else {
57 // it is a TS object
58 $url = isset($conf['file.'])
59 ? $this->cObj->stdWrap($conf['file'], $conf['file.'])
60 : $conf['file'];
61 }
62
63 $mode = is_file(PATH_site . $url) ? 'file' : 'url';
64 if ($mode === 'file') {
65 // render FILE
66 $filename = $GLOBALS['TSFE']->tmpl->getFileName($url);
67 $fileinfo = t3lib_div::split_fileref($filename);
68 $conf['file'] = $filename;
69 } else {
70 // render URL
71 // use media wizard to extract video from URL
72 $mediaWizard = tslib_mediaWizardManager::getValidMediaWizardProvider($url);
73 if ($mediaWizard !== NULL) {
74 $url = $mediaWizard->rewriteUrl($url);
75 }
76 $conf['file'] = $this->cObj->typoLink_URL(array(
77 'parameter' => $url
78 ));
79 }
80
81 $renderType = isset($conf['renderType.'])
82 ? $this->cObj->stdWrap($conf['renderType'], $conf['renderType.'])
83 : $conf['renderType'];
84 $mmRenderType = isset($conf['parameter.']['mmRenderType.'])
85 ? $this->cObj->stdWrap($conf['parameter.']['mmRenderType'], $conf['parameter.']['mmRenderType.'])
86 : $conf['parameter.']['mmRenderType'];
87 if ($mmRenderType) {
88 $renderType = $mmRenderType;
89 }
90 if ($renderType === 'auto') {
91 // default renderType is swf
92 $renderType = 'swf';
93 $handler = array_keys($conf['fileExtHandler.']);
94 if (in_array($fileinfo['fileext'], $handler)) {
95 $renderType = strtolower($conf['fileExtHandler.'][$fileinfo['fileext']]);
96 }
97 }
98
99 $mmForcePlayer = isset($conf['parameter.']['mmforcePlayer.'])
100 ? $this->cObj->stdWrap($conf['parameter.']['mmforcePlayer'], $conf['parameter.']['mmforcePlayer.'])
101 : $conf['parameter.']['mmforcePlayer'];
102
103 $forcePlayer = $mmFile ? intval($mmForcePlayer) : $conf['forcePlayer'];
104 $conf['forcePlayer'] = isset($conf['forcePlayer.'])
105 ? $this->cObj->stdWrap($forcePlayer, $conf['forcePlayer.'])
106 : $forcePlayer;
107
108 $mmType = isset($conf['parameter.']['mmType.'])
109 ? $this->cObj->stdWrap($conf['parameter.']['mmType'], $conf['parameter.']['mmType.'])
110 : $conf['parameter.']['mmType'];
111
112 $type = isset($conf['type.'])
113 ? $this->cObj->stdWrap($conf['type'], $conf['type.'])
114 : $conf['type'];
115
116 $conf['type'] = $mmType ? $mmType : $type;
117 $mime = $renderType . 'object';
118 $typeConf = $conf['mimeConf.'][$mime . '.'][$conf['type'] . '.'] ? $conf['mimeConf.'][$mime . '.'][$conf['type'] . '.'] : array();
119 $conf['predefined'] = array();
120
121 $width = isset($conf['parameter.']['mmWidth.'])
122 ? intval($this->cObj->stdWrap($conf['parameter.']['mmWidth'], $conf['parameter.']['mmWidth.']))
123 : intval($conf['parameter.']['mmWidth']);
124 $height = isset($conf['parameter.']['mmHeight.'])
125 ? intval($this->cObj->stdWrap($conf['parameter.']['mmHeight'], $conf['parameter.']['mmHeight.']))
126 : intval($conf['parameter.']['mmHeight']);
127 if ($width) {
128 $conf['width'] = $width;
129 } else {
130 $width = isset($conf['width.'])
131 ? intval($this->cObj->stdWrap($conf['width'], $conf['width.']))
132 : intval($conf['width']);
133 $conf['width'] = $width ? $width : $typeConf['defaultWidth'];
134 }
135 if ($height) {
136 $conf['height'] = $height;
137 } else {
138 $height = isset($conf['height.'])
139 ? intval($this->cObj->stdWrap($conf['height'], $conf['height.']))
140 : intval($conf['width']);
141 $conf['height'] = $height ? $height : $typeConf['defaultHeight'];
142 }
143
144 if (is_array($conf['parameter.']['mmMediaOptions'])) {
145 $params = array();
146 foreach ($conf['parameter.']['mmMediaOptions'] as $key => $value) {
147 if ($key == 'mmMediaCustomParameterContainer') {
148 foreach ($value as $val) {
149 //custom parameter entry
150 $rawTS = $val['mmParamCustomEntry'];
151 //read and merge
152 $tmp = t3lib_div::trimExplode(LF, $rawTS);
153 if (count($tmp)) {
154 foreach ($tmp as $tsLine) {
155 if (substr($tsLine, 0, 1) != '#' && $pos = strpos($tsLine, '.')) {
156 $parts[0] = substr($tsLine, 0, $pos);
157 $parts[1] = substr($tsLine, $pos + 1);
158 $valueParts = t3lib_div::trimExplode('=', $parts[1], TRUE);
159
160 switch (strtolower($parts[0])) {
161 case 'flashvars' :
162 $conf['flashvars.'][$valueParts[0]] = $valueParts[1];
163 break;
164 case 'params' :
165 $conf['params.'][$valueParts[0]] = $valueParts[1];
166 break;
167 case 'attributes' :
168 $conf['attributes.'][$valueParts[0]] = $valueParts[1];
169 break;
170 }
171 }
172 }
173 }
174 }
175 } elseif ($key == 'mmMediaOptionsContainer') {
176 foreach ($value as $val) {
177 if (isset($val['mmParamSet'])) {
178 $pName = $val['mmParamName'];
179 $pSet = $val['mmParamSet'];
180 $pValue = $pSet == 2 ? $val['mmParamValue'] : ($pSet == 0 ? 'false' : 'true');
181 $conf['predefined'][$pName] = $pValue;
182 }
183 }
184 }
185 }
186 }
187
188 // render MEDIA
189 if ($mode == 'url' && !$forcePlayer) {
190 // url is called direct, not with player
191 if ($url == '' && !$conf['allowEmptyUrl']) {
192 return '<p style="background-color: yellow;">' . $GLOBALS['TSFE']->sL('LLL:EXT:cms/locallang_ttc.xml:media.noFile', TRUE) . '</p>';
193 }
194 $conf = array_merge($conf['mimeConf.']['swfobject.'], $conf);
195 $conf[$conf['type'] . '.']['player'] = strpos($url, '://') === FALSE ? 'http://' . $url : $url;
196 $conf['installUrl'] = 'null';
197 $conf['flashvars'] = array_merge((array) $conf['flashvars'], $conf['predefined']);
198 }
199
200 switch ($renderType) {
201 case 'swf' :
202 $conf[$conf['type'] . '.'] = array_merge($conf['mimeConf.']['swfobject.'][$conf['type'] . '.'], $typeConf);
203 $conf = array_merge($conf['mimeConf.']['swfobject.'], $conf);
204 unset($conf['mimeConf.']);
205 $conf['flashvars.'] = array_merge((array) $conf['flashvars.'], $conf['predefined']);
206 $content = $this->cObj->SWFOBJECT($conf);
207 break;
208 case 'qt' :
209 $conf[$conf['type'] . '.'] = array_merge($conf['mimeConf.']['swfobject.'][$conf['type'] . '.'], $typeConf);
210 $conf = array_merge($conf['mimeConf.']['qtobject.'], $conf);
211 unset($conf['mimeConf.']);
212 $conf['params.'] = array_merge((array) $conf['params.'], $conf['predefined']);
213 $content = $this->cObj->QTOBJECT($conf);
214 break;
215 case 'embed' :
216 $paramsArray = array_merge((array) $typeConf['default.']['params.'], (array) $conf['params.'], $conf['predefined']);
217 $conf['params'] = '';
218 foreach ($paramsArray as $key => $value) {
219 $conf['params'] .= $key . '=' . $value . LF;
220 }
221 $content = $this->cObj->MULTIMEDIA($conf);
222 break;
223 default :
224 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['customMediaRender'])) {
225 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['customMediaRender'] as $classRef) {
226 $hookObj = t3lib_div::getUserObj($classRef);
227 $conf['file'] = $url;
228 $conf['mode'] = $mode;
229 $content = $hookObj->customMediaRender($renderType, $conf, $this);
230 }
231 }
232 }
233
234 if (isset($conf['stdWrap.'])) {
235 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
236 }
237
238 return $content;
239 }
240
241 }
242
243
244 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_media.php'])) {
245 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_media.php']);
246 }
247
248 ?>