TYPO3 CMS  TYPO3_7-6
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)) {
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 }
transformMediaIdToFile($mediaId, Folder $targetFolder, $fileExtension)
findExistingFileByOnlineMediaId($onlineMediaId, Folder $targetFolder, $fileExtension)
static getUrl($url, $includeHeader=0, $requestHeaders=false, &$report=null)