[BUGFIX] Use strict comparison for EXT:mediace arrays
[Packages/TYPO3.CMS.git] / typo3 / sysext / mediace / Classes / ContentObject / ShockwaveFlashObjectContentObject.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 SWFOBJECT content object.
21 *
22 * @author Xavier Perseguers <typo3@perseguers.ch>
23 * @author Steffen Kamper <steffen@typo3.org>
24 */
25 class ShockwaveFlashObjectContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
26
27 /**
28 * Rendering the cObject, SWFOBJECT
29 *
30 * @param array $conf Array of TypoScript properties
31 * @return string Output
32 */
33 public function render($conf = array()) {
34 $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 $typeConf = $conf[$type . '.'];
43 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
44 $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
45
46 // Add SWFobject js-file
47 $pageRenderer->addJsFile($this->getPathToLibrary('flashmedia/swfobject/swfobject.js'));
48 $player = isset($typeConf['player.']) ? $this->cObj->stdWrap($typeConf['player'], $typeConf['player.']) : $typeConf['player'];
49 $installUrl = isset($conf['installUrl.']) ? $this->cObj->stdWrap($conf['installUrl'], $conf['installUrl.']) : $conf['installUrl'];
50 if (!$installUrl) {
51 $installUrl = $prefix . $this->getPathToLibrary('flashmedia/swfobject/expressInstall.swf');
52 }
53 // If file is audio and an explicit path has not been set,
54 // take path from audio fallback property
55 if ($type == 'audio' && empty($conf['file'])) {
56 $conf['file'] = $conf['audioFallback'];
57 }
58 $filename = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
59 $forcePlayer = isset($conf['forcePlayer.']) ? $this->cObj->stdWrap($conf['forcePlayer'], $conf['forcePlayer.']) : $conf['forcePlayer'];
60 if ($filename && $forcePlayer) {
61 if (strpos($filename, '://') !== FALSE) {
62 $conf['flashvars.']['file'] = $filename;
63 } else {
64 if ($prefix) {
65 $conf['flashvars.']['file'] = $prefix . $filename;
66 } else {
67 $conf['flashvars.']['file'] = str_repeat('../', substr_count($player, '/')) . $filename;
68 }
69 }
70 } else {
71 $player = $filename;
72 }
73 // Write calculated values in conf for the hook
74 $conf['player'] = $player;
75 $conf['installUrl'] = $installUrl;
76 $conf['filename'] = $filename;
77 $conf['prefix'] = $prefix;
78 // Merge with default parameters
79 $conf['flashvars.'] = array_merge((array)$typeConf['default.']['flashvars.'], (array)$conf['flashvars.']);
80 $conf['params.'] = array_merge((array)$typeConf['default.']['params.'], (array)$conf['params.']);
81 $conf['attributes.'] = array_merge((array)$typeConf['default.']['attributes.'], (array)$conf['attributes.']);
82 $conf['embedParams'] = 'flashvars, params, attributes';
83 // Hook for manipulating the conf array, it's needed for some players like flowplayer
84 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'])) {
85 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'] as $classRef) {
86 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($classRef, $conf, $this);
87 }
88 }
89 if (is_array($conf['flashvars.']) && is_array($typeConf['mapping.']['flashvars.'])) {
90 ArrayUtility::remapArrayKeys($conf['flashvars.'], $typeConf['mapping.']['flashvars.']);
91 }
92 $flashvars = 'var flashvars = ' . (count($conf['flashvars.']) ? json_encode($conf['flashvars.']) : '{}') . ';';
93 if (is_array($conf['params.']) && is_array($typeConf['mapping.']['params.'])) {
94 ArrayUtility::remapArrayKeys($conf['params.'], $typeConf['mapping.']['params.']);
95 }
96 $params = 'var params = ' . (count($conf['params.']) ? json_encode($conf['params.']) : '{}') . ';';
97 if (is_array($conf['attributes.']) && is_array($typeConf['attributes.']['params.'])) {
98 ArrayUtility::remapArrayKeys($conf['attributes.'], $typeConf['attributes.']['params.']);
99 }
100 $attributes = 'var attributes = ' . (count($conf['attributes.']) ? json_encode($conf['attributes.']) : '{}') . ';';
101 $flashVersion = isset($conf['flashVersion.']) ? $this->cObj->stdWrap($conf['flashVersion'], $conf['flashVersion.']) : $conf['flashVersion'];
102 if (!$flashVersion) {
103 $flashVersion = '9';
104 }
105 $replaceElementIdString = str_replace('.', '', uniqid('mmswf', TRUE));
106 $GLOBALS['TSFE']->register['MMSWFID'] = $replaceElementIdString;
107 $alternativeContent = isset($conf['alternativeContent.']) ? $this->cObj->stdWrap($conf['alternativeContent'], $conf['alternativeContent.']) : $conf['alternativeContent'];
108 $layout = isset($conf['layout.']) ? $this->cObj->stdWrap($conf['layout'], $conf['layout.']) : $conf['layout'];
109 $content = str_replace('###ID###', $replaceElementIdString, $layout);
110 $content = str_replace('###SWFOBJECT###', '<div id="' . $replaceElementIdString . '">' . $alternativeContent . '</div>', $content);
111 $width = isset($conf['width.']) ? $this->cObj->stdWrap($conf['width'], $conf['width.']) : $conf['width'];
112 if (!$width) {
113 $width = $conf[$type . '.']['defaultWidth'];
114 }
115 $height = isset($conf['height.']) ? $this->cObj->stdWrap($conf['height'], $conf['height.']) : $conf['height'];
116 if (!$height) {
117 $height = $conf[$type . '.']['defaultHeight'];
118 }
119 $embed = 'swfobject.embedSWF("' . $conf['player'] . '", "' . $replaceElementIdString . '", "' . $width . '", "' . $height . '",
120 "' . $flashVersion . '", "' . $installUrl . '", ' . $conf['embedParams'] . ');';
121 $script = $flashvars . $params . $attributes . $embed;
122 $pageRenderer->addJsInlineCode($replaceElementIdString, $script);
123 if (isset($conf['stdWrap.'])) {
124 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
125 }
126 return $content;
127 }
128
129 /**
130 * resolves the path to the extensions' Contrib directory
131 *
132 * @param string $fileAndFolderName the file to be located
133 * @return string
134 */
135 protected function getPathToLibrary($fileAndFolderName) {
136 return $GLOBALS['TSFE']->tmpl->getFileName('EXT:mediace/Resources/Contrib/' . $fileAndFolderName);
137 }
138 }