‪TYPO3CMS  9.5
VimeoHelper.php
Go to the documentation of this file.
1 <?php
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 
20 
25 {
34  public function ‪getPublicUrl(‪File $file, $relativeToCurrentScript = false)
35  {
36  $videoId = $this->‪getOnlineMediaId($file);
37  return sprintf('https://vimeo.com/%s', rawurlencode($videoId));
38  }
39 
46  public function ‪getPreviewImage(‪File $file)
47  {
48  $videoId = $this->‪getOnlineMediaId($file);
49  $temporaryFileName = $this->‪getTempFolderPath() . 'vimeo_' . md5($videoId) . '.jpg';
50  if (!file_exists($temporaryFileName)) {
51  $oEmbedData = $this->‪getOEmbedData($videoId);
52  $previewImage = GeneralUtility::getUrl($oEmbedData['thumbnail_url']);
53  if ($previewImage !== false) {
54  file_put_contents($temporaryFileName, $previewImage);
55  GeneralUtility::fixPermissions($temporaryFileName);
56  }
57  }
58  return $temporaryFileName;
59  }
60 
68  public function ‪transformUrlToFile($url, ‪Folder $targetFolder)
69  {
70  $videoId = null;
71  // Try to get the Vimeo code from given url.
72  // Next formats are supported with and without http(s)://
73  // - vimeo.com/<code>/<optionalPrivateCode> # Share URL
74  // - player.vimeo.com/video/<code>/<optionalPrivateCode> # URL form iframe embed code, can also get code from full iframe snippet
75  if (preg_match('/vimeo\.com\/(?:video\/)?([0-9a-z\/]+)/i', $url, $matches)) {
76  $videoId = $matches[1];
77  }
78  if (empty($videoId)) {
79  return null;
80  }
81  return $this->‪transformMediaIdToFile($videoId, $targetFolder, $this->extension);
82  }
83 
91  protected function ‪getOEmbedUrl($mediaId, $format = 'json')
92  {
93  return sprintf(
94  'https://vimeo.com/api/oembed.%s?width=2048&url=%s',
95  rawurlencode($format),
96  rawurlencode(sprintf('https://vimeo.com/%s', rawurlencode($mediaId)))
97  );
98  }
99 }
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\getPublicUrl
‪string null getPublicUrl(File $file, $relativeToCurrentScript=false)
Definition: VimeoHelper.php:34
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper\getTempFolderPath
‪string getTempFolderPath()
Definition: AbstractOnlineMediaHelper.php:121
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper\getOnlineMediaId
‪string getOnlineMediaId(File $file)
Definition: AbstractOnlineMediaHelper.php:58
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper\getOEmbedData
‪array null getOEmbedData($mediaId)
Definition: AbstractOEmbedHelper.php:65
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\transformUrlToFile
‪File null transformUrlToFile($url, Folder $targetFolder)
Definition: VimeoHelper.php:68
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper\transformMediaIdToFile
‪File transformMediaIdToFile($mediaId, Folder $targetFolder, $fileExtension)
Definition: AbstractOEmbedHelper.php:42
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\getOEmbedUrl
‪string getOEmbedUrl($mediaId, $format='json')
Definition: VimeoHelper.php:91
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper
Definition: VimeoHelper.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\getPreviewImage
‪string getPreviewImage(File $file)
Definition: VimeoHelper.php:46
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers
Definition: AbstractOEmbedHelper.php:2
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper
Definition: AbstractOEmbedHelper.php:26