[TASK] Remove superfluous parenthesis in sysext frontend
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / ShockwaveFlashContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
8 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Contains SWFOBJECT class object.
32 *
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class ShockwaveFlashContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
37
38 /**
39 * Rendering the cObject, SWFOBJECT
40 *
41 * @param array $conf Array of TypoScript properties
42 * @return string Output
43 */
44 public function render($conf = array()) {
45 $prefix = '';
46 if ($GLOBALS['TSFE']->baseUrl) {
47 $prefix = $GLOBALS['TSFE']->baseUrl;
48 }
49 if ($GLOBALS['TSFE']->absRefPrefix) {
50 $prefix = $GLOBALS['TSFE']->absRefPrefix;
51 }
52 $type = isset($conf['type.']) ? $this->cObj->stdWrap($conf['type'], $conf['type.']) : $conf['type'];
53 $typeConf = $conf[$type . '.'];
54 // Add SWFobject js-file
55 $GLOBALS['TSFE']->getPageRenderer()->addJsFile(TYPO3_mainDir . 'contrib/flashmedia/swfobject/swfobject.js');
56 $player = isset($typeConf['player.']) ? $this->cObj->stdWrap($typeConf['player'], $typeConf['player.']) : $typeConf['player'];
57 $installUrl = isset($conf['installUrl.']) ? $this->cObj->stdWrap($conf['installUrl'], $conf['installUrl.']) : $conf['installUrl'];
58 if (!$installUrl) {
59 $installUrl = $prefix . TYPO3_mainDir . 'contrib/flashmedia/swfobject/expressInstall.swf';
60 }
61 $filename = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
62 $forcePlayer = isset($conf['forcePlayer.']) ? $this->cObj->stdWrap($conf['forcePlayer'], $conf['forcePlayer.']) : $conf['forcePlayer'];
63 if ($filename && $forcePlayer) {
64 if (strpos($filename, '://') !== FALSE) {
65 $conf['flashvars.']['file'] = $filename;
66 } else {
67 if ($prefix) {
68 $conf['flashvars.']['file'] = $prefix . $filename;
69 } else {
70 $conf['flashvars.']['file'] = str_repeat('../', substr_count($player, '/')) . $filename;
71 }
72 }
73 } else {
74 $player = $filename;
75 }
76 // Write calculated values in conf for the hook
77 $conf['player'] = $player;
78 $conf['installUrl'] = $installUrl;
79 $conf['filename'] = $filename;
80 $conf['prefix'] = $prefix;
81 // Merge with default parameters
82 $conf['flashvars.'] = array_merge((array) $typeConf['default.']['flashvars.'], (array) $conf['flashvars.']);
83 $conf['params.'] = array_merge((array) $typeConf['default.']['params.'], (array) $conf['params.']);
84 $conf['attributes.'] = array_merge((array) $typeConf['default.']['attributes.'], (array) $conf['attributes.']);
85 $conf['embedParams'] = 'flashvars, params, attributes';
86 // Hook for manipulating the conf array, it's needed for some players like flowplayer
87 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'])) {
88 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'] as $classRef) {
89 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($classRef, $conf, $this);
90 }
91 }
92 if (is_array($conf['flashvars.'])) {
93 \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['flashvars.'], $typeConf['mapping.']['flashvars.']);
94 }
95 $flashvars = 'var flashvars = ' . (count($conf['flashvars.']) ? json_encode($conf['flashvars.']) : '{}') . ';';
96 if (is_array($conf['params.'])) {
97 \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['params.'], $typeConf['mapping.']['params.']);
98 }
99 $params = 'var params = ' . (count($conf['params.']) ? json_encode($conf['params.']) : '{}') . ';';
100 if (is_array($conf['attributes.'])) {
101 \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['attributes.'], $typeConf['attributes.']['params.']);
102 }
103 $attributes = 'var attributes = ' . (count($conf['attributes.']) ? json_encode($conf['attributes.']) : '{}') . ';';
104 $flashVersion = isset($conf['flashVersion.']) ? $this->cObj->stdWrap($conf['flashVersion'], $conf['flashVersion.']) : $conf['flashVersion'];
105 if (!$flashVersion) {
106 $flashVersion = '9';
107 }
108 $replaceElementIdString = uniqid('mmswf');
109 $GLOBALS['TSFE']->register['MMSWFID'] = $replaceElementIdString;
110 $alternativeContent = isset($conf['alternativeContent.']) ? $this->cObj->stdWrap($conf['alternativeContent'], $conf['alternativeContent.']) : $conf['alternativeContent'];
111 $layout = isset($conf['layout.']) ? $this->cObj->stdWrap($conf['layout'], $conf['layout.']) : $conf['layout'];
112 $content = str_replace('###ID###', $replaceElementIdString, $layout);
113 $content = str_replace('###SWFOBJECT###', '<div id="' . $replaceElementIdString . '">' . $alternativeContent . '</div>', $content);
114 $width = isset($conf['width.']) ? $this->cObj->stdWrap($conf['width'], $conf['width.']) : $conf['width'];
115 if (!$width) {
116 $width = $conf[$type . '.']['defaultWidth'];
117 }
118 $height = isset($conf['height.']) ? $this->cObj->stdWrap($conf['height'], $conf['height.']) : $conf['height'];
119 if (!$height) {
120 $height = $conf[$type . '.']['defaultHeight'];
121 }
122 $embed = 'swfobject.embedSWF("' . $conf['player'] . '", "' . $replaceElementIdString . '", "' . $width . '", "' . $height . '",
123 "' . $flashVersion . '", "' . $installUrl . '", ' . $conf['embedParams'] . ');';
124 $script = $flashvars . $params . $attributes . $embed;
125 $GLOBALS['TSFE']->getPageRenderer()->addJsInlineCode($replaceElementIdString, $script);
126 if (isset($conf['stdWrap.'])) {
127 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
128 }
129 return $content;
130 }
131
132 }
133
134
135 ?>