[TASK] Introduce Enum constants for t3ver_state
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / ShockwaveFlashObjectContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Xavier Perseguers <typo3@perseguers.ch>
8 * (c) 2010-2013 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 ShockwaveFlashObjectContentObject 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 // If file is audio and an explicit path has not been set,
62 // take path from audio fallback property
63 if ($type == 'audio' && empty($conf['file'])) {
64 $conf['file'] = $conf['audioFallback'];
65 }
66 $filename = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
67 $forcePlayer = isset($conf['forcePlayer.']) ? $this->cObj->stdWrap($conf['forcePlayer'], $conf['forcePlayer.']) : $conf['forcePlayer'];
68 if ($filename && $forcePlayer) {
69 if (strpos($filename, '://') !== FALSE) {
70 $conf['flashvars.']['file'] = $filename;
71 } else {
72 if ($prefix) {
73 $conf['flashvars.']['file'] = $prefix . $filename;
74 } else {
75 $conf['flashvars.']['file'] = str_repeat('../', substr_count($player, '/')) . $filename;
76 }
77 }
78 } else {
79 $player = $filename;
80 }
81 // Write calculated values in conf for the hook
82 $conf['player'] = $player;
83 $conf['installUrl'] = $installUrl;
84 $conf['filename'] = $filename;
85 $conf['prefix'] = $prefix;
86 // Merge with default parameters
87 $conf['flashvars.'] = array_merge((array) $typeConf['default.']['flashvars.'], (array) $conf['flashvars.']);
88 $conf['params.'] = array_merge((array) $typeConf['default.']['params.'], (array) $conf['params.']);
89 $conf['attributes.'] = array_merge((array) $typeConf['default.']['attributes.'], (array) $conf['attributes.']);
90 $conf['embedParams'] = 'flashvars, params, attributes';
91 // Hook for manipulating the conf array, it's needed for some players like flowplayer
92 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'])) {
93 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'] as $classRef) {
94 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($classRef, $conf, $this);
95 }
96 }
97 if (is_array($conf['flashvars.'])) {
98 \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['flashvars.'], $typeConf['mapping.']['flashvars.']);
99 }
100 $flashvars = 'var flashvars = ' . (count($conf['flashvars.']) ? json_encode($conf['flashvars.']) : '{}') . ';';
101 if (is_array($conf['params.'])) {
102 \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['params.'], $typeConf['mapping.']['params.']);
103 }
104 $params = 'var params = ' . (count($conf['params.']) ? json_encode($conf['params.']) : '{}') . ';';
105 if (is_array($conf['attributes.'])) {
106 \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['attributes.'], $typeConf['attributes.']['params.']);
107 }
108 $attributes = 'var attributes = ' . (count($conf['attributes.']) ? json_encode($conf['attributes.']) : '{}') . ';';
109 $flashVersion = isset($conf['flashVersion.']) ? $this->cObj->stdWrap($conf['flashVersion'], $conf['flashVersion.']) : $conf['flashVersion'];
110 if (!$flashVersion) {
111 $flashVersion = '9';
112 }
113 $replaceElementIdString = uniqid('mmswf');
114 $GLOBALS['TSFE']->register['MMSWFID'] = $replaceElementIdString;
115 $alternativeContent = isset($conf['alternativeContent.']) ? $this->cObj->stdWrap($conf['alternativeContent'], $conf['alternativeContent.']) : $conf['alternativeContent'];
116 $layout = isset($conf['layout.']) ? $this->cObj->stdWrap($conf['layout'], $conf['layout.']) : $conf['layout'];
117 $content = str_replace('###ID###', $replaceElementIdString, $layout);
118 $content = str_replace('###SWFOBJECT###', '<div id="' . $replaceElementIdString . '">' . $alternativeContent . '</div>', $content);
119 $width = isset($conf['width.']) ? $this->cObj->stdWrap($conf['width'], $conf['width.']) : $conf['width'];
120 if (!$width) {
121 $width = $conf[$type . '.']['defaultWidth'];
122 }
123 $height = isset($conf['height.']) ? $this->cObj->stdWrap($conf['height'], $conf['height.']) : $conf['height'];
124 if (!$height) {
125 $height = $conf[$type . '.']['defaultHeight'];
126 }
127 $embed = 'swfobject.embedSWF("' . $conf['player'] . '", "' . $replaceElementIdString . '", "' . $width . '", "' . $height . '",
128 "' . $flashVersion . '", "' . $installUrl . '", ' . $conf['embedParams'] . ');';
129 $script = $flashvars . $params . $attributes . $embed;
130 $GLOBALS['TSFE']->getPageRenderer()->addJsInlineCode($replaceElementIdString, $script);
131 if (isset($conf['stdWrap.'])) {
132 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
133 }
134 return $content;
135 }
136
137 }