‪TYPO3CMS  ‪main
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 {
33  public function ‪getPublicUrl(‪File $file)
34  {
35  $videoId = $this->‪getOnlineMediaId($file);
36  return sprintf('https://vimeo.com/%s', rawurlencode($videoId));
37  }
38 
44  public function ‪getPreviewImage(‪File $file)
45  {
46  $videoId = $this->‪getOnlineMediaId($file);
47  $temporaryFileName = $this->‪getTempFolderPath() . 'vimeo_' . md5($videoId) . '.jpg';
48  if (!file_exists($temporaryFileName)) {
49  $oEmbedData = $this->‪getOEmbedData($videoId);
50  if (!empty($oEmbedData['thumbnail_url'])) {
51  $previewImage = ‪GeneralUtility::getUrl($oEmbedData['thumbnail_url']);
52  if ($previewImage !== false) {
53  file_put_contents($temporaryFileName, $previewImage);
54  ‪GeneralUtility::fixPermissions($temporaryFileName);
55  }
56  }
57  }
58  return $temporaryFileName;
59  }
60 
67  public function ‪transformUrlToFile(‪$url, ‪Folder $targetFolder)
68  {
69  $videoId = null;
70  // Try to get the Vimeo code from given url.
71  // Next formats are supported with and without http(s)://
72  // - vimeo.com/<code>/<optionalPrivateCode> # Share URL
73  // - vimeo.com/event/<code>
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\/|event\/)?([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\AbstractOnlineMediaHelper\getTempFolderPath
‪string getTempFolderPath()
Definition: AbstractOnlineMediaHelper.php:128
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper\getOnlineMediaId
‪string getOnlineMediaId(File $file)
Definition: AbstractOnlineMediaHelper.php:60
‪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:67
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper\transformMediaIdToFile
‪File transformMediaIdToFile($mediaId, Folder $targetFolder, $fileExtension)
Definition: AbstractOEmbedHelper.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility\getUrl
‪static string false getUrl(string $url)
Definition: GeneralUtility.php:1439
‪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:38
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\getPublicUrl
‪string null getPublicUrl(File $file)
Definition: VimeoHelper.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions
‪static bool fixPermissions(string $path, bool $recursive=false)
Definition: GeneralUtility.php:1491
‪TYPO3\CMS\Webhooks\Message\$url
‪identifier readonly UriInterface $url
Definition: LoginErrorOccurredMessage.php:36
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper
Definition: VimeoHelper.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper\getPreviewImage
‪string getPreviewImage(File $file)
Definition: VimeoHelper.php:44
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers
Definition: AbstractOEmbedHelper.php:16
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper
Definition: AbstractOEmbedHelper.php:28