Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from ErHaWeb/main
[FEATURE] Add structured data for videos
- Loading branch information
Showing
4 changed files
with
259 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/video-shariff. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\VideoShariff\ViewHelpers\Format; | ||
|
||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
|
||
/** | ||
* Class SecondsToISO8601ViewHelper | ||
*/ | ||
class SecondsToISO8601ViewHelper extends AbstractViewHelper | ||
{ | ||
/** | ||
* Returns the absolute web path to the preview image. | ||
* | ||
* @param array $arguments | ||
* @param \Closure $renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext | ||
* @return string | ||
* @throws \UnexpectedValueException | ||
*/ | ||
public static function renderStatic( | ||
array $arguments, | ||
\Closure $renderChildrenClosure, | ||
RenderingContextInterface $renderingContext | ||
): string { | ||
$seconds = (int)$renderChildrenClosure(); | ||
$intervals = [ | ||
'D' => 60 * 60 * 24, | ||
'H' => 60 * 60, | ||
'M' => 60, | ||
'S' => 1, | ||
]; | ||
|
||
$pt = 'P'; | ||
$result = ''; | ||
foreach ($intervals as $tag => $divisor) { | ||
$qty = floor($seconds / $divisor); | ||
if (!$qty && $result === '') { | ||
$pt = 'T'; | ||
continue; | ||
} | ||
$seconds -= $qty * $divisor; | ||
$result .= $qty . $tag; | ||
} | ||
|
||
if ($result === '') { | ||
$result = '0S'; | ||
} | ||
|
||
return $pt . $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/video-shariff. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\VideoShariff\ViewHelpers; | ||
|
||
use TYPO3\CMS\Core\Resource\FileInterface; | ||
use TYPO3\CMS\Core\Resource\FileReference; | ||
use TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder; | ||
use TYPO3\CMS\Extbase\Domain\Model\FileReference as ExtbaseFileReference; | ||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
|
||
/** | ||
* Class VideoCreationDateViewHelper | ||
*/ | ||
class VideoCreationDateViewHelper extends AbstractViewHelper | ||
{ | ||
/** | ||
* Initialize arguments | ||
*/ | ||
public function initializeArguments(): void | ||
{ | ||
$this->registerArgument( | ||
'fileReference', | ||
'object', | ||
'FileReference to be used for creating the preview image' | ||
); | ||
} | ||
|
||
/** | ||
* Returns the absolute web path to the preview image. | ||
* | ||
* @param array $arguments | ||
* @param \Closure $renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext | ||
* @return int | ||
* @throws \UnexpectedValueException | ||
*/ | ||
public static function renderStatic( | ||
array $arguments, | ||
\Closure $renderChildrenClosure, | ||
RenderingContextInterface $renderingContext | ||
): int { | ||
/** @var FileReference|ExtbaseFileReference $fileReference */ | ||
$fileReference = $arguments['fileReference']; | ||
|
||
// get Resource Object (non ExtBase version) | ||
if (is_callable([$fileReference, 'getOriginalResource'])) { | ||
// We have a domain model, so we need to fetch the FAL resource object from there | ||
$fileReference = $fileReference->getOriginalResource(); | ||
} | ||
if (!($fileReference instanceof FileInterface || $fileReference instanceof AbstractFileFolder)) { | ||
throw new \UnexpectedValueException('Supplied file object type ' . get_class($fileReference) . ' must be FileInterface or AbstractFileFolder.', 1454252193); | ||
} | ||
$file = $fileReference->getOriginalFile(); | ||
if ($file->getProperty('content_creation_date')) { | ||
return $file->getProperty('content_creation_date'); | ||
} | ||
if ($file->getProperty('creation_date')) { | ||
return $file->getProperty('creation_date'); | ||
} | ||
if ($file->getProperty('crdate')) { | ||
return $file->getProperty('crdate'); | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/video-shariff. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\VideoShariff\ViewHelpers; | ||
|
||
use TYPO3\CMS\Core\Resource\FileInterface; | ||
use TYPO3\CMS\Core\Resource\FileReference; | ||
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry; | ||
use TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder; | ||
use TYPO3\CMS\Extbase\Domain\Model\FileReference as ExtbaseFileReference; | ||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
|
||
/** | ||
* Class VideoPublicUrlViewHelper | ||
*/ | ||
class VideoPublicUrlViewHelper extends AbstractViewHelper | ||
{ | ||
/** | ||
* Initialize arguments | ||
*/ | ||
public function initializeArguments(): void | ||
{ | ||
$this->registerArgument( | ||
'fileReference', | ||
'object', | ||
'FileReference to be used for creating the preview image' | ||
); | ||
} | ||
|
||
/** | ||
* Returns the absolute web path to the preview image. | ||
* | ||
* @param array $arguments | ||
* @param \Closure $renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext | ||
* @return string | ||
* @throws \UnexpectedValueException | ||
*/ | ||
public static function renderStatic( | ||
array $arguments, | ||
\Closure $renderChildrenClosure, | ||
RenderingContextInterface $renderingContext | ||
): string { | ||
/** @var FileReference|ExtbaseFileReference $fileReference */ | ||
$fileReference = $arguments['fileReference']; | ||
|
||
// get Resource Object (non ExtBase version) | ||
if (is_callable([$fileReference, 'getOriginalResource'])) { | ||
// We have a domain model, so we need to fetch the FAL resource object from there | ||
$fileReference = $fileReference->getOriginalResource(); | ||
} | ||
if (!($fileReference instanceof FileInterface || $fileReference instanceof AbstractFileFolder)) { | ||
throw new \UnexpectedValueException('Supplied file object type ' . get_class($fileReference) . ' must be FileInterface or AbstractFileFolder.', 1454252193); | ||
} | ||
$file = $fileReference->getOriginalFile(); | ||
$helper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($file); | ||
if ($helper) { | ||
$publicUrl = $helper->getPublicUrl($file); | ||
} else { | ||
$publicUrl = ''; | ||
} | ||
return $publicUrl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters