[BUGFIX] Use strict comparison for EXT:mediace arrays
[Packages/TYPO3.CMS.git] / typo3 / sysext / mediace / Classes / ContentObject / QuicktimeObjectContentObject.php
1 <?php
2 namespace TYPO3\CMS\Mediace\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 use TYPO3\CMS\Core\Utility\ArrayUtility;
18
19 /**
20 * Contains QTOBJECT content object.
21 *
22 * @author Xavier Perseguers <typo3@perseguers.ch>
23 * @author Steffen Kamper <steffen@typo3.org>
24 */
25 class QuicktimeObjectContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
26
27 /**
28 * Rendering the cObject, QTOBJECT
29 *
30 * @param array $conf Array of TypoScript properties
31 * @return string Output
32 */
33 public function render($conf = array()) {
34 $params = ($prefix = '');
35 if ($GLOBALS['TSFE']->baseUrl) {
36 $prefix = $GLOBALS['TSFE']->baseUrl;
37 }
38 if ($GLOBALS['TSFE']->absRefPrefix) {
39 $prefix = $GLOBALS['TSFE']->absRefPrefix;
40 }
41 $type = isset($conf['type.']) ? $this->cObj->stdWrap($conf['type'], $conf['type.']) : $conf['type'];
42
43 // If file is audio and an explicit path has not been set,
44 // take path from audio fallback property
45 if ($type == 'audio' && empty($conf['file'])) {
46 $conf['file'] = $conf['audioFallback'];
47 }
48 $filename = isset( $conf['file.'])
49 ? $this->cObj->stdWrap($conf['file'], $conf['file.'])
50 : $conf['file'];
51
52 $typeConf = $conf[$type . '.'];
53 // Add QTobject js-file
54 $GLOBALS['TSFE']->getPageRenderer()->addJsFile($this->getPathToLibrary('flashmedia/qtobject/qtobject.js'));
55 $replaceElementIdString = str_replace('.', '', uniqid('mmqt', TRUE));
56 $GLOBALS['TSFE']->register['MMQTID'] = $replaceElementIdString;
57 $qtObject = 'QTObject' . $replaceElementIdString;
58 // Merge with default parameters
59 $conf['params.'] = array_merge((array)$typeConf['default.']['params.'], (array)$conf['params.']);
60 if (is_array($conf['params.']) && is_array($typeConf['mapping.']['params.'])) {
61 ArrayUtility::remapArrayKeys($conf['params.'], $typeConf['mapping.']['params.']);
62 foreach ($conf['params.'] as $key => $value) {
63 $params .= $qtObject . '.addParam("' . $key . '", "' . $value . '");' . LF;
64 }
65 }
66 $params = ($params ? substr($params, 0, -2) : '') . LF . $qtObject . '.write("' . $replaceElementIdString . '");';
67 $alternativeContent = isset($conf['alternativeContent.']) ? $this->cObj->stdWrap($conf['alternativeContent'], $conf['alternativeContent.']) : $conf['alternativeContent'];
68 $layout = str_replace(
69 array(
70 '###ID###',
71 '###QTOBJECT###'
72 ),
73 array(
74 $replaceElementIdString,
75 '<div id="' . $replaceElementIdString . '">' . $alternativeContent . '</div>'
76 ),
77 isset($conf['layout.']) ? $this->cObj->stdWrap($conf['layout'], $conf['layout.']) : $conf['layout']
78 );
79 $width = isset($conf['width.']) ? $this->cObj->stdWrap($conf['width'], $conf['width.']) : $conf['width'];
80 if (!$width) {
81 $width = $conf[$type . '.']['defaultWidth'];
82 }
83 $height = isset($conf['height.']) ? $this->cObj->stdWrap($conf['height'], $conf['height.']) : $conf['height'];
84 if (!$height) {
85 $height = $conf[$type . '.']['defaultHeight'];
86 }
87 $fullFilename = $filename;
88 // If the file name doesn't contain a scheme, prefix with appropriate data
89 if (strpos($filename, '://') === FALSE && !empty($prefix)) {
90 $fullFilename = $prefix . $filename;
91 }
92 $embed = 'var ' . $qtObject . ' = new QTObject("' . $fullFilename . '", "' . $replaceElementIdString . '", "' . $width . '", "' . $height . '");';
93 $content = $layout . '
94 <script type="text/javascript">
95 ' . $embed . '
96 ' . $params . '
97 </script>';
98 if (isset($conf['stdWrap.'])) {
99 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
100 }
101 return $content;
102 }
103
104 /**
105 * resolves the path to the extensions' Contrib directory
106 *
107 * @param string $fileAndFolderName the file to be located
108 * @return string
109 */
110 protected function getPathToLibrary($fileAndFolderName) {
111 return $GLOBALS['TSFE']->tmpl->getFileName('EXT:mediace/Resources/Contrib/' . $fileAndFolderName);
112 }
113 }