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