TYPO3 CMS  TYPO3_6-2
ShockwaveFlashObjectContentObject.php
Go to the documentation of this file.
1 <?php
3 
18 
26 
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 . '.'];
44  $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
45 
46  // Add SWFobject js-file
47  $pageRenderer->addJsFile(TYPO3_mainDir . 'contrib/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 . TYPO3_mainDir . 'contrib/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  if (isset($conf['flashvars.']['file'])) {
84  $conf['flashvars.']['fileHash'] = GeneralUtility::hmac($conf['flashvars.']['file'], 'flashvars');
85  $conf['flashvars.']['fileAuthPrefix'] = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
86  }
87  // Hook for manipulating the conf array, it's needed for some players like flowplayer
88  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'])) {
89  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['swfParamTransform'] as $classRef) {
91  }
92  }
93  if (is_array($conf['flashvars.'])) {
94  \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['flashvars.'], $typeConf['mapping.']['flashvars.']);
95  }
96  $flashvars = 'var flashvars = ' . (count($conf['flashvars.']) ? json_encode($conf['flashvars.']) : '{}') . ';';
97  if (is_array($conf['params.'])) {
98  \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['params.'], $typeConf['mapping.']['params.']);
99  }
100  $params = 'var params = ' . (count($conf['params.']) ? json_encode($conf['params.']) : '{}') . ';';
101  if (is_array($conf['attributes.'])) {
102  \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['attributes.'], $typeConf['attributes.']['params.']);
103  }
104  $attributes = 'var attributes = ' . (count($conf['attributes.']) ? json_encode($conf['attributes.']) : '{}') . ';';
105  $flashVersion = isset($conf['flashVersion.']) ? $this->cObj->stdWrap($conf['flashVersion'], $conf['flashVersion.']) : $conf['flashVersion'];
106  if (!$flashVersion) {
107  $flashVersion = '9';
108  }
109  $replaceElementIdString = str_replace('.', '', uniqid('mmswf', TRUE));
110  $GLOBALS['TSFE']->register['MMSWFID'] = $replaceElementIdString;
111  $alternativeContent = isset($conf['alternativeContent.']) ? $this->cObj->stdWrap($conf['alternativeContent'], $conf['alternativeContent.']) : $conf['alternativeContent'];
112  $layout = isset($conf['layout.']) ? $this->cObj->stdWrap($conf['layout'], $conf['layout.']) : $conf['layout'];
113  $content = str_replace('###ID###', $replaceElementIdString, $layout);
114  $content = str_replace('###SWFOBJECT###', '<div id="' . $replaceElementIdString . '">' . $alternativeContent . '</div>', $content);
115  $width = isset($conf['width.']) ? $this->cObj->stdWrap($conf['width'], $conf['width.']) : $conf['width'];
116  if (!$width) {
117  $width = $conf[$type . '.']['defaultWidth'];
118  }
119  $height = isset($conf['height.']) ? $this->cObj->stdWrap($conf['height'], $conf['height.']) : $conf['height'];
120  if (!$height) {
121  $height = $conf[$type . '.']['defaultHeight'];
122  }
123  $embed = 'swfobject.embedSWF("' . $conf['player'] . '", "' . $replaceElementIdString . '", "' . $width . '", "' . $height . '",
124  "' . $flashVersion . '", "' . $installUrl . '", ' . $conf['embedParams'] . ');';
125  $script = $flashvars . $params . $attributes . $embed;
126  $pageRenderer->addJsInlineCode($replaceElementIdString, $script);
127  if (isset($conf['stdWrap.'])) {
128  $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
129  }
130  return $content;
131  }
132 
133 }
static hmac($input, $additionalSecret='')
static remapArrayKeys(&$array, $mappingTable)
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]