‪TYPO3CMS  10.4
VimeoHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
26 {
35  public function ‪getPublicUrl(‪File $file, $relativeToCurrentScript = false)
36  {
37  $videoId = $this->‪getOnlineMediaId($file);
38  return sprintf('https://vimeo.com/%s', rawurlencode($videoId));
39  }
40 
47  public function ‪getPreviewImage(‪File $file)
48  {
49  $videoId = $this->‪getOnlineMediaId($file);
50  $temporaryFileName = $this->‪getTempFolderPath() . 'vimeo_' . md5($videoId) . '.jpg';
51  if (!file_exists($temporaryFileName)) {
52  $oEmbedData = $this->‪getOEmbedData($videoId);
53  $previewImage = ‪GeneralUtility::getUrl($oEmbedData['thumbnail_url']);
54  if ($previewImage !== false) {
55  file_put_contents($temporaryFileName, $previewImage);
56  ‪GeneralUtility::fixPermissions($temporaryFileName);
57  }
58  }
59  return $temporaryFileName;
60  }
61 
69  public function ‪transformUrlToFile($url, ‪Folder $targetFolder)
70  {
71  $videoId = null;
72  // Try to get the Vimeo code from given url.
73  // Next formats are supported with and without http(s)://
74  // - vimeo.com/<code>/<optionalPrivateCode> # Share URL
75  // - vimeo.com/event/<code>
76  // - player.vimeo.com/video/<code>/<optionalPrivateCode> # URL form iframe embed code, can also get code from full iframe snippet
77  if (preg_match('/vimeo\.com\/(?:video\/|event\/)?([0-9a-z\/]+)/i', $url, $matches)) {
78  $videoId = $matches[1];
79  }
80  if (empty($videoId)) {
81  return null;
82  }
83  return $this->‪transformMediaIdToFile($videoId, $targetFolder, $this->extension);
84  }
85 
93  protected function ‪getOEmbedUrl($mediaId, $format = 'json')
94  {
95  return sprintf(
96  'https://vimeo.com/api/oembed.%s?width=2048&url=%s',
97  rawurlencode($format),
98  rawurlencode(sprintf('https://vimeo.com/%s', rawurlencode($mediaId)))
99  );
100  }
101 }
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\getPublicUrl
‪string null getPublicUrl(File $file, $relativeToCurrentScript=false)
Definition: VimeoHelper.php:35
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper\getTempFolderPath
‪string getTempFolderPath()
Definition: AbstractOnlineMediaHelper.php:124
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper\getOnlineMediaId
‪string getOnlineMediaId(File $file)
Definition: AbstractOnlineMediaHelper.php:59
‪TYPO3\CMS\Core\Utility\GeneralUtility\getUrl
‪static mixed getUrl($url, $includeHeader=0, $requestHeaders=null, &$report=null)
Definition: GeneralUtility.php:1748
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper\getOEmbedData
‪array null getOEmbedData($mediaId)
Definition: AbstractOEmbedHelper.php:66
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\transformUrlToFile
‪File null transformUrlToFile($url, Folder $targetFolder)
Definition: VimeoHelper.php:69
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper\transformMediaIdToFile
‪File transformMediaIdToFile($mediaId, Folder $targetFolder, $fileExtension)
Definition: AbstractOEmbedHelper.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions
‪static mixed fixPermissions($path, $recursive=false)
Definition: GeneralUtility.php:1863
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\getOEmbedUrl
‪string getOEmbedUrl($mediaId, $format='json')
Definition: VimeoHelper.php:93
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper
Definition: VimeoHelper.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\getPreviewImage
‪string getPreviewImage(File $file)
Definition: VimeoHelper.php:47
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers
Definition: AbstractOEmbedHelper.php:16
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper
Definition: AbstractOEmbedHelper.php:27