TYPO3 CMS  TYPO3_7-6
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> # Share URL
74  // - player.vimeo.com/video/<code> # URL form iframe embed code, can also get code from full iframe snippet
75  if (preg_match('/vimeo\.com\/(video\/)*([0-9]+)/i', $url, $matches)) {
76  $videoId = $matches[2];
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?url=%s',
95  rawurlencode($format),
96  rawurlencode(sprintf('https://vimeo.com/%s', rawurlencode($mediaId)))
97  );
98  }
99 }
getPublicUrl(File $file, $relativeToCurrentScript=false)
Definition: VimeoHelper.php:34
transformMediaIdToFile($mediaId, Folder $targetFolder, $fileExtension)
static fixPermissions($path, $recursive=false)
static getUrl($url, $includeHeader=0, $requestHeaders=false, &$report=null)