TYPO3 CMS  TYPO3_6-2
MediaContentObject.php
Go to the documentation of this file.
1 <?php
3 
23 
30  public function render($conf = array()) {
31  $content = '';
32  // Add flex parameters to configuration
33  $flexParams = isset($conf['flexParams.']) ? $this->cObj->stdWrap($conf['flexParams'], $conf['flexParams.']) : $conf['flexParams'];
34  if ($flexParams[0] === '<') {
35  // It is a content element rather a TS object
36  $flexParams = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flexParams, 'T3');
37  foreach ($flexParams['data'] as $sheetData) {
38  $this->cObj->readFlexformIntoConf($sheetData['lDEF'], $conf['parameter.'], TRUE);
39  }
40  }
41  // Type is video or audio
42  $conf['type'] = $this->doFlexFormOverlay($conf, 'type');
43  // Video sources
44  $sources = $this->doFlexFormOverlay($conf, 'sources', 'mmSourcesContainer');
45  if (is_array($sources) && count($sources)) {
46  $conf['sources'] = array();
47  foreach ($sources as $key => $source) {
48  if (isset($source['mmSource'])) {
49  $source = $source['mmSource'];
50  $conf['sources'][$key] = $this->retrieveMediaUrl($source);
51  }
52  }
53  } else {
54  unset($conf['sources']);
55  }
56  // Video fallback and backward compatibility file
57  $videoFallback = $this->doFlexFormOverlay($conf, 'file');
58 
59  // Backward compatibility file
60  if ($videoFallback !== NULL) {
61  $conf['file'] = $this->retrieveMediaUrl($videoFallback);
62  } else {
63  unset($conf['file']);
64  }
65  // Audio sources
66  $audioSources = $this->doFlexFormOverlay($conf, 'audioSources', 'mmAudioSourcesContainer');
67  if (is_array($audioSources) && count($audioSources)) {
68  $conf['audioSources'] = array();
69  foreach ($audioSources as $key => $source) {
70  if (isset($source['mmAudioSource'])) {
71  $source = $source['mmAudioSource'];
72  $conf['audioSources'][$key] = $this->retrieveMediaUrl($source);
73  }
74  }
75  } else {
76  unset($conf['audioSources']);
77  }
78  // Audio fallback
79  $audioFallback = $this->doFlexFormOverlay($conf, 'audioFallback');
80  if ($audioFallback) {
81  $conf['audioFallback'] = $this->retrieveMediaUrl($audioFallback);
82  } else {
83  unset($conf['audioFallback']);
84  }
85  // Caption file
86  $caption = $this->doFlexFormOverlay($conf, 'caption');
87  if ($caption) {
88  $conf['caption'] = $this->retrieveMediaUrl($caption);
89  } else {
90  unset($conf['caption']);
91  }
92  // Establish render type
93  $renderType = $this->doFlexFormOverlay($conf, 'renderType');
94  $conf['preferFlashOverHtml5'] = 0;
95  if ($renderType === 'preferFlashOverHtml5') {
96  $renderType = 'auto';
97  }
98  if ($renderType === 'auto') {
99  // Default renderType is swf
100  $renderType = 'swf';
101  $handler = array_keys($conf['fileExtHandler.']);
102  if ($conf['type'] === 'video') {
104  } else {
105  $fileinfo = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($conf['audioFallback']);
106  }
107  if (in_array($fileinfo['fileext'], $handler)) {
108  $renderType = strtolower($conf['fileExtHandler.'][$fileinfo['fileext']]);
109  }
110  }
111  $mime = $renderType . 'object';
112  $typeConf = $conf['mimeConf.'][$mime . '.'][$conf['type'] . '.'] ?: array();
113  $conf['predefined'] = array();
114  // Width and height
115  $conf['width'] = (int)$this->doFlexFormOverlay($conf, 'width');
116  $conf['height'] = (int)$this->doFlexFormOverlay($conf, 'height');
117  if (is_array($conf['parameter.']['mmMediaOptions'])) {
118  foreach ($conf['parameter.']['mmMediaOptions'] as $key => $value) {
119  if ($key == 'mmMediaCustomParameterContainer') {
120  foreach ($value as $val) {
121  // Custom parameter entry
122  $rawTS = $val['mmParamCustomEntry'];
123  // Read and merge
125  if (count($tmp)) {
126  foreach ($tmp as $tsLine) {
127  if ($tsLine[0] !== '#' && ($pos = strpos($tsLine, '.'))) {
128  $parts[0] = substr($tsLine, 0, $pos);
129  $parts[1] = substr($tsLine, $pos + 1);
130  $valueParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('=', $parts[1], TRUE);
131  switch (strtolower($parts[0])) {
132  case 'flashvars':
133  $conf['flashvars.'][$valueParts[0]] = $valueParts[1];
134  break;
135  case 'params':
136  $conf['params.'][$valueParts[0]] = $valueParts[1];
137  break;
138  case 'attributes':
139  $conf['attributes.'][$valueParts[0]] = $valueParts[1];
140  break;
141  }
142  }
143  }
144  }
145  }
146  } elseif ($key == 'mmMediaOptionsContainer') {
147  foreach ($value as $val) {
148  if (isset($val['mmParamSet'])) {
149  $pName = $val['mmParamName'];
150  $pSet = $val['mmParamSet'];
151  $pValue = $pSet == 2 ? $val['mmParamValue'] : ($pSet == 0 ? 'false' : 'true');
152  $conf['predefined'][$pName] = $pValue;
153  }
154  }
155  }
156  }
157  }
158  if ($renderType === 'swf' && $this->doFlexFormOverlay($conf, 'useHTML5')) {
159  $renderType = 'flowplayer';
160  }
161  if ($conf['type'] === 'audio' && !isset($conf['audioSources'])) {
162  $renderType = 'swf';
163  }
164  if ($renderType !== 'qt' && $renderType !== 'embed' && $conf['type'] == 'video') {
165  if (isset($conf['file']) && (strpos($conf['file'], '.swf') !== FALSE || strpos($conf['file'], '://') !== FALSE && strpos(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($conf['file'], 2), 'application/x-shockwave-flash') !== FALSE)) {
166  $conf = array_merge((array) $conf['mimeConf.']['swfobject.'], $conf);
167  $conf[$conf['type'] . '.']['player'] = strpos($conf['file'], '://') === FALSE ? 'http://' . $conf['file'] : $conf['file'];
168  $conf['installUrl'] = 'null';
169  $conf['forcePlayer'] = 0;
170  $renderType = 'swf';
171  } elseif (isset($conf['file']) && strpos($conf['file'], '://') !== FALSE) {
172  $mediaWizard = \TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($conf['file']);
173  if ($mediaWizard !== NULL) {
174  $conf['installUrl'] = 'null';
175  $conf['forcePlayer'] = 0;
176  $renderType = 'swf';
177  }
178  } elseif (isset($conf['file']) && !isset($conf['caption']) && !isset($conf['sources'])) {
179  $renderType = 'swf';
180  $conf['forcePlayer'] = 1;
181  }
182  }
183  switch ($renderType) {
184  case 'flowplayer':
185  $conf[$conf['type'] . '.'] = array_merge((array) $conf['mimeConf.']['flowplayer.'][($conf['type'] . '.')], $typeConf);
186  $conf = array_merge((array) $conf['mimeConf.']['flowplayer.'], $conf);
187  unset($conf['mimeConf.']);
188  $conf['attributes.'] = array_merge((array) $conf['attributes.'], $conf['predefined']);
189  $conf['params.'] = array_merge((array) $conf['params.'], $conf['predefined']);
190  $conf['flashvars.'] = array_merge((array) $conf['flashvars.'], $conf['predefined']);
191  $content = $this->cObj->FLOWPLAYER($conf);
192  break;
193  case 'swf':
194  $conf[$conf['type'] . '.'] = array_merge((array) $conf['mimeConf.']['swfobject.'][($conf['type'] . '.')], $typeConf);
195  $conf = array_merge((array) $conf['mimeConf.']['swfobject.'], $conf);
196  unset($conf['mimeConf.']);
197  $conf['flashvars.'] = array_merge((array) $conf['flashvars.'], $conf['predefined']);
198  $content = $this->cObj->SWFOBJECT($conf);
199  break;
200  case 'qt':
201  $conf[$conf['type'] . '.'] = array_merge($conf['mimeConf.']['swfobject.'][$conf['type'] . '.'], $typeConf);
202  $conf = array_merge($conf['mimeConf.']['qtobject.'], $conf);
203  unset($conf['mimeConf.']);
204  $conf['params.'] = array_merge((array) $conf['params.'], $conf['predefined']);
205  $content = $this->cObj->QTOBJECT($conf);
206  break;
207  case 'embed':
208  $paramsArray = array_merge((array) $typeConf['default.']['params.'], (array) $conf['params.'], $conf['predefined']);
209  $conf['params'] = '';
210  foreach ($paramsArray as $key => $value) {
211  $conf['params'] .= $key . '=' . $value . LF;
212  }
213  $content = $this->cObj->MULTIMEDIA($conf);
214  break;
215  default:
216  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['customMediaRender'])) {
217  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['customMediaRender'] as $classRef) {
219  $conf['file'] = $videoFallback;
220  $conf['mode'] = is_file(PATH_site . $videoFallback) ? 'file' : 'url';
221  if (method_exists($hookObj, 'customMediaRender')) {
222  $content = $hookObj->customMediaRender($renderType, $conf, $this);
223  }
224  }
225  }
226  if (isset($conf['stdWrap.'])) {
227  $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
228  }
229  }
230  return $content;
231  }
232 
239  protected function retrieveMediaUrl($file) {
240  $returnValue = NULL;
241 
242  // because the file value can possibly have link parameters, use explode to split all values
243  $fileParts = explode(' ', $file);
244 
246  $mediaWizard = \TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($fileParts[0]);
247  // Get the path relative to the page currently outputted
248  if (substr($fileParts[0], 0, 5) === 'file:') {
249  $fileUid = substr($fileParts[0], 5);
250 
251  if (!empty($fileUid) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($fileUid)) {
252  $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject($fileUid);
253 
254  if ($fileObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
255  $returnValue = $fileObject->getPublicUrl();
256  }
257  }
258  } elseif (is_file(PATH_site . $fileParts[0])) {
259  $returnValue = $GLOBALS['TSFE']->tmpl->getFileName($fileParts[0]);
260  } elseif ($mediaWizard !== NULL) {
261  $jumpUrlEnabled = $GLOBALS['TSFE']->config['config']['jumpurl_enable'];
262  $GLOBALS['TSFE']->config['config']['jumpurl_enable'] = 0;
263  $returnValue = $this->cObj->typoLink_URL(array(
264  'parameter' => $mediaWizard->rewriteUrl($fileParts[0])
265  ));
266  $GLOBALS['TSFE']->config['config']['jumpurl_enable'] = $jumpUrlEnabled;
267  } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($fileParts[0])) {
268  $returnValue = $fileParts[0];
269  }
270 
271  return $returnValue;
272  }
273 
284  protected function doFlexFormOverlay(array &$confArray, $key, $sectionKey = NULL) {
285  $flexValue = NULL;
286  $flexKey = 'mm' . ucfirst($key);
287  if ($sectionKey === NULL) {
288  if (isset($confArray['parameter.'][$flexKey])) {
289  $flexValue = $confArray['parameter.'][$flexKey];
290  }
291  } else {
292  if (isset($confArray['parameter.'][$flexKey][$sectionKey])) {
293  $flexValue = $confArray['parameter.'][$flexKey][$sectionKey];
294  }
295  }
296  if ($flexValue === NULL) {
297  $flexValue = isset($confArray[$key . '.']) ? $this->cObj->stdWrap($confArray[$key], $confArray[$key . '.']) : $confArray[$key];
298  }
299  return $flexValue;
300  }
301 
302 }
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static split_fileref($fileNameWithPath)
static getUrl($url, $includeHeader=0, $requestHeaders=FALSE, &$report=NULL)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static xml2array($string, $NSprefix='', $reportDocTag=FALSE)
doFlexFormOverlay(array &$confArray, $key, $sectionKey=NULL)