TYPO3  7.6
VimeoRenderer.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Rendering;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
27 {
31  protected $onlineMediaHelper;
32 
42  public function getPriority()
43  {
44  return 1;
45  }
46 
53  public function canRender(FileInterface $file)
54  {
55  return ($file->getMimeType() === 'video/vimeo' || $file->getExtension() === 'vimeo') && $this->getOnlineMediaHelper($file) !== false;
56  }
57 
64  protected function getOnlineMediaHelper(FileInterface $file)
65  {
66  if ($this->onlineMediaHelper === null) {
67  $orgFile = $file;
68  if ($orgFile instanceof FileReference) {
69  $orgFile = $orgFile->getOriginalFile();
70  }
71  if ($orgFile instanceof File) {
72  $this->onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($orgFile);
73  } else {
74  $this->onlineMediaHelper = false;
75  }
76  }
78  }
79 
90  public function render(FileInterface $file, $width, $height, array $options = null, $usedPathsRelativeToCurrentScript = false)
91  {
92  if ($file instanceof FileReference) {
93  $autoplay = $file->getProperty('autoplay');
94  if ($autoplay !== null) {
95  $options['autoplay'] = $autoplay;
96  }
97  }
98 
99  $urlParams = array();
100  if (!empty($options['autoplay'])) {
101  $urlParams[] = 'autoplay=1';
102  }
103  if (!empty($options['loop'])) {
104  $urlParams[] = 'loop=1';
105  }
106  $urlParams[] = 'title=' . (int)!empty($options['showinfo']);
107  $urlParams[] = 'byline=' . (int)!empty($options['showinfo']);
108  $urlParams[] = 'portrait=0';
109 
110  if ($file instanceof FileReference) {
111  $orgFile = $file->getOriginalFile();
112  } else {
113  $orgFile = $file;
114  }
115 
116  $videoId = $this->getOnlineMediaHelper($file)->getOnlineMediaId($orgFile);
117  $src = sprintf('//player.vimeo.com/video/%s?%s', $videoId, implode('&amp;', $urlParams));
118 
119  $attributes = ['allowfullscreen'];
120  if ((int)$width > 0) {
121  $attributes[] = 'width="' . (int)$width . '"';
122  }
123  if ((int)$height > 0) {
124  $attributes[] = 'height="' . (int)$height . '"';
125  }
126  if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->config['config']['doctype'] !== 'html5') {
127  $attributes[] = 'frameborder="0"';
128  }
129  foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) {
130  if (!empty($options[$key])) {
131  $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
132  }
133  }
134 
135  return sprintf(
136  '<iframe src="%s"%s></iframe>',
137  $src,
138  empty($attributes) ? '' : ' ' . implode(' ', $attributes)
139  );
140  }
141 }