2 namespace TYPO3\CMS\Frontend\ContentObject
;
4 /***************************************************************
7 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
8 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
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.
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.
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.
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
31 * Contains SWFOBJECT class object.
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
36 class ShockwaveFlashContentObject
extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject
{
39 * Rendering the cObject, SWFOBJECT
41 * @param array $conf Array of TypoScript properties
42 * @return string Output
44 public function render($conf = array()) {
46 if ($GLOBALS['TSFE']->baseUrl
) {
47 $prefix = $GLOBALS['TSFE']->baseUrl
;
49 if ($GLOBALS['TSFE']->absRefPrefix
) {
50 $prefix = $GLOBALS['TSFE']->absRefPrefix
;
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'];
59 $installUrl = $prefix . TYPO3_mainDir
. 'contrib/flashmedia/swfobject/expressInstall.swf';
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;
68 $conf['flashvars.']['file'] = $prefix . $filename;
70 $conf['flashvars.']['file'] = str_repeat('../', substr_count($player, '/')) . $filename;
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);
92 if (is_array($conf['flashvars.'])) {
93 \TYPO3\CMS\Core\Utility\GeneralUtility
::remapArrayKeys($conf['flashvars.'], $typeConf['mapping.']['flashvars.']);
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.']);
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.']);
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) {
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'];
116 $width = $conf[$type . '.']['defaultWidth'];
118 $height = isset($conf['height.']) ?
$this->cObj
->stdWrap($conf['height'], $conf['height.']) : $conf['height'];
120 $height = $conf[$type . '.']['defaultHeight'];
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.']);