Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / content / class.tslib_content_shockwaveflashobject.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
6 * (c) 2010-2011 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 SWFOBJECT 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_ShockwaveFlashObject extends tslib_content_Abstract {
37
38 /**
39 * Rendering the cObject, SWFOBJECT
40 *
41 * @param array 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 ;
53
54 $type = isset($conf['type.'])
55 ? $this->cObj->stdWrap($conf['type'], $conf['type.'])
56 : $conf['type'];
57 $typeConf = $conf[$type . '.'];
58
59 //add SWFobject js-file
60 $GLOBALS['TSFE']->getPageRenderer()->addJsFile(TYPO3_mainDir . 'contrib/flashmedia/swfobject/swfobject.js');
61
62 $player = isset($typeConf['player.'])
63 ? $this->cObj->stdWrap($typeConf['player'], $typeConf['player.'])
64 : $typeConf['player'];
65
66 $installUrl = isset($conf['installUrl.'])
67 ? $this->cObj->stdWrap($conf['installUrl'], $conf['installUrl.'])
68 : $conf['installUrl'];
69 if(!$installUrl) {
70 $installUrl = $prefix . TYPO3_mainDir . 'contrib/flashmedia/swfobject/expressInstall.swf';
71 }
72
73 $filename = isset($conf['file.'])
74 ? $this->cObj->stdWrap($conf['file'], $conf['file.'])
75 : $conf['file'];
76 $forcePlayer = isset($conf['forcePlayer.'])
77 ? $this->cObj->stdWrap($conf['forcePlayer'], $conf['forcePlayer.'])
78 : $conf['forcePlayer'];
79
80 if ($filename && $forcePlayer) {
81 if (strpos($filename, '://') !== FALSE) {
82 $conf['flashvars.']['file'] = $filename;
83 } else {
84 if ($prefix) {
85 $conf['flashvars.']['file'] = $prefix . $filename;
86 } else {
87 $conf['flashvars.']['file'] = str_repeat('../', substr_count($player, '/')) . $filename;
88 }
89
90 }
91 } else {
92 $player = $filename;
93 }
94 // Write calculated values in conf for the hook
95 $conf['player'] = $player;
96 $conf['installUrl'] = $installUrl;
97 $conf['filename'] = $filename;
98 $conf['prefix'] = $prefix;
99
100 // merge with default parameters
101 $conf['flashvars.'] = array_merge((array) $typeConf['default.']['flashvars.'], (array) $conf['flashvars.']);
102 $conf['params.'] = array_merge((array) $typeConf['default.']['params.'], (array) $conf['params.']);
103 $conf['attributes.'] = array_merge((array) $typeConf['default.']['attributes.'], (array) $conf['attributes.']);
104 $conf['embedParams'] = 'flashvars, params, attributes';
105
106 // Hook for manipulating the conf array, it's needed for some players like flowplayer
107 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'])) {
108 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'] as $classRef) {
109 t3lib_div::callUserFunction($classRef, $conf, $this);
110 }
111 }
112 if (is_array($conf['flashvars.'])) {
113 t3lib_div::remapArrayKeys($conf['flashvars.'], $typeConf['mapping.']['flashvars.']);
114 }
115 $flashvars = 'var flashvars = ' . (count($conf['flashvars.']) ? json_encode($conf['flashvars.']) : '{}') . ';';
116
117 if (is_array($conf['params.'])) {
118 t3lib_div::remapArrayKeys($conf['params.'], $typeConf['mapping.']['params.']);
119 }
120 $params = 'var params = ' . (count($conf['params.']) ? json_encode($conf['params.']) : '{}') . ';';
121
122 if (is_array($conf['attributes.'])) {
123 t3lib_div::remapArrayKeys($conf['attributes.'], $typeConf['attributes.']['params.']);
124 }
125 $attributes = 'var attributes = ' . (count($conf['attributes.']) ? json_encode($conf['attributes.']) : '{}') . ';';
126
127 $flashVersion = isset($conf['flashVersion.'])
128 ? $this->cObj->stdWrap($conf['flashVersion'], $conf['flashVersion.'])
129 : $conf['flashVersion'];
130
131 if (!$flashVersion) {
132 $flashVersion = '9';
133 }
134
135 $replaceElementIdString = uniqid('mmswf');
136 $GLOBALS['TSFE']->register['MMSWFID'] = $replaceElementIdString;
137
138 $alternativeContent = isset($conf['alternativeContent.'])
139 ? $this->cObj->stdWrap($conf['alternativeContent'], $conf['alternativeContent.'])
140 : $conf['alternativeContent'];
141
142 $layout = isset($conf['layout.'])
143 ? $this->cObj->stdWrap($conf['layout'], $conf['layout.'])
144 : $conf['layout'];
145 $layout = str_replace('###ID###', $replaceElementIdString, $layout);
146 $layout = str_replace('###SWFOBJECT###', '<div id="' . $replaceElementIdString . '">' . $alternativeContent . '</div>', $layout);
147
148 $width = isset($conf['width.'])
149 ? $this->cObj->stdWrap($conf['width'], $conf['width.'])
150 : $conf['width'];
151 if(!$width) {
152 $width = $conf[$type . '.']['defaultWidth'];
153 }
154
155 $height = isset($conf['height.'])
156 ? $this->cObj->stdWrap($conf['height'], $conf['height.'])
157 : $conf['height'];
158 if(!$height) {
159 $height = $conf[$type . '.']['defaultHeight'];
160 }
161
162
163 $embed = 'swfobject.embedSWF("' . $conf['player'] . '", "' . $replaceElementIdString . '", "' . $width . '", "' . $height . '",
164 "' . $flashVersion . '", "' . $installUrl . '", ' . $conf['embedParams'] . ');';
165
166 $content = $layout . '
167 <script type="text/javascript">
168 ' . $flashvars . '
169 ' . $params . '
170 ' . $attributes . '
171 ' . $embed . '
172 </script>';
173
174 if (isset($conf['stdWrap.'])) {
175 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
176 }
177
178 return $content;
179 }
180
181 }
182
183
184 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_shockwaveflashobject.php'])) {
185 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_shockwaveflashobject.php']);
186 }
187
188 ?>