bc1e9c8831382e2d8bc64db820977349c00e4a16
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / QuicktimeObjectContentObject.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 QTOBJECT class object.
32 *
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class QuicktimeObjectContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
37
38 /**
39 * Rendering the cObject, QTOBJECT
40 *
41 * @param array $conf Array of TypoScript properties
42 * @return string Output
43 */
44 public function render($conf = array()) {
45 $params = ($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
54 // If file is audio and an explicit path has not been set,
55 // take path from audio fallback property
56 if ($type == 'audio' && empty($conf['file'])) {
57 $conf['file'] = $conf['audioFallback'];
58 }
59 $filename = isset( $conf['file.'])
60 ? $this->cObj->stdWrap($conf['file'], $conf['file.'])
61 : $conf['file'];
62
63 $typeConf = $conf[$type . '.'];
64 // Add QTobject js-file
65 $GLOBALS['TSFE']->getPageRenderer()->addJsFile(TYPO3_mainDir . 'contrib/flashmedia/qtobject/qtobject.js');
66 $replaceElementIdString = uniqid('mmqt');
67 $GLOBALS['TSFE']->register['MMQTID'] = $replaceElementIdString;
68 $qtObject = 'QTObject' . $replaceElementIdString;
69 // Merge with default parameters
70 $conf['params.'] = array_merge((array) $typeConf['default.']['params.'], (array) $conf['params.']);
71 if (is_array($conf['params.'])) {
72 \TYPO3\CMS\Core\Utility\GeneralUtility::remapArrayKeys($conf['params.'], $typeConf['mapping.']['params.']);
73 foreach ($conf['params.'] as $key => $value) {
74 $params .= $qtObject . '.addParam("' . $key . '", "' . $value . '");' . LF;
75 }
76 }
77 $params = ($params ? substr($params, 0, -2) : '') . LF . $qtObject . '.write("' . $replaceElementIdString . '");';
78 $alternativeContent = isset($conf['alternativeContent.']) ? $this->cObj->stdWrap($conf['alternativeContent'], $conf['alternativeContent.']) : $conf['alternativeContent'];
79 $layout = isset($conf['layout.']) ? $this->cObj->stdWrap($conf['layout'], $conf['layout.']) : $conf['layout'];
80 $layout = str_replace('###ID###', $replaceElementIdString, $layout);
81 $layout = str_replace('###QTOBJECT###', '<div id="' . $replaceElementIdString . '">' . $alternativeContent . '</div>', $layout);
82 $width = isset($conf['width.']) ? $this->cObj->stdWrap($conf['width'], $conf['width.']) : $conf['width'];
83 if (!$width) {
84 $width = $conf[$type . '.']['defaultWidth'];
85 }
86 $height = isset($conf['height.']) ? $this->cObj->stdWrap($conf['height'], $conf['height.']) : $conf['height'];
87 if (!$height) {
88 $height = $conf[$type . '.']['defaultHeight'];
89 }
90 $fullFilename = $filename;
91 // If the file name doesn't contain a scheme, prefix with appropriate data
92 if (strpos($filename, '://') === FALSE && !empty($prefix)) {
93 $fullFilename = $prefix . $filename;
94 }
95 $embed = 'var ' . $qtObject . ' = new QTObject("' . $fullFilename . '", "' . $replaceElementIdString . '", "' . $width . '", "' . $height . '");';
96 $content = $layout . '
97 <script type="text/javascript">
98 ' . $embed . '
99 ' . $params . '
100 </script>';
101 if (isset($conf['stdWrap.'])) {
102 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
103 }
104 return $content;
105 }
106
107 }