‪TYPO3CMS  10.4
AbstractOEmbedHelper.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 
27 {
33  abstract protected function ‪getOEmbedUrl($mediaId, $format = 'json');
34 
43  protected function ‪transformMediaIdToFile($mediaId, ‪Folder $targetFolder, $fileExtension)
44  {
45  $file = $this->‪findExistingFileByOnlineMediaId($mediaId, $targetFolder, $fileExtension);
46 
47  // no existing file create new
48  if ($file === null) {
49  $oEmbed = $this->‪getOEmbedData($mediaId);
50  if (!empty($oEmbed['title'])) {
51  $fileName = $oEmbed['title'] . '.' . $fileExtension;
52  } else {
53  $fileName = $mediaId . '.' . $fileExtension;
54  }
55  $file = $this->‪createNewFile($targetFolder, $fileName, $mediaId);
56  }
57  return $file;
58  }
59 
66  protected function ‪getOEmbedData($mediaId)
67  {
68  $oEmbed = ‪GeneralUtility::getUrl(
69  $this->‪getOEmbedUrl($mediaId)
70  );
71  if ($oEmbed) {
72  $oEmbed = json_decode($oEmbed, true);
73  }
74  return $oEmbed;
75  }
76 
84  public function ‪getMetaData(‪File $file)
85  {
86  $metadata = [];
87 
88  $oEmbed = $this->‪getOEmbedData($this->‪getOnlineMediaId($file));
89 
90  if ($oEmbed) {
91  $metadata['width'] = (int)$oEmbed['width'];
92  $metadata['height'] = (int)$oEmbed['height'];
93  if (empty($file->‪getProperty('title'))) {
94  $metadata['title'] = strip_tags($oEmbed['title']);
95  }
96  $metadata['author'] = $oEmbed['author_name'];
97  }
98 
99  return $metadata;
100  }
101 }
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper\findExistingFileByOnlineMediaId
‪File null findExistingFileByOnlineMediaId($onlineMediaId, Folder $targetFolder, $fileExtension)
Definition: AbstractOnlineMediaHelper.php:80
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper\getOEmbedUrl
‪string getOEmbedUrl($mediaId, $format='json')
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper\getOnlineMediaId
‪string getOnlineMediaId(File $file)
Definition: AbstractOnlineMediaHelper.php:59
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper\getMetaData
‪array getMetaData(File $file)
Definition: AbstractOEmbedHelper.php:84
‪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\AbstractOEmbedHelper\transformMediaIdToFile
‪File transformMediaIdToFile($mediaId, Folder $targetFolder, $fileExtension)
Definition: AbstractOEmbedHelper.php:43
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper
Definition: AbstractOnlineMediaHelper.php:30
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper\createNewFile
‪File createNewFile(Folder $targetFolder, $fileName, $onlineMediaId)
Definition: AbstractOnlineMediaHelper.php:109
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Resource\File\getProperty
‪mixed getProperty($key)
Definition: File.php:65
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers
Definition: AbstractOEmbedHelper.php:16
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOEmbedHelper
Definition: AbstractOEmbedHelper.php:27