Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions Classes/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);

namespace BTU\BtuVimp\Configuration;

use BTU\BtuVimp\Exception\InvalidConfigurationException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration as CoreExtensionConfiguration;
use TYPO3\CMS\Core\SingletonInterface;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

/**
* ExtensionConfiguration class
*
* @phpstan-type UrlParameters array<string,string|int|bool>
*/
class ExtensionConfiguration implements SingletonInterface
{
protected string $baseUrl;
/** @var UrlParameters */
protected array $urlParameters;

/**
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
* @throws InvalidConfigurationException
*/
public function __construct(
protected CoreExtensionConfiguration $extConf
) {
$baseUrl = $extConf->get('btu_vimp', 'baseUrl');
if (! is_string($baseUrl)) {
throw new InvalidConfigurationException('Configuration "baseUrl" must be a string', 1728910000);
}
$this->baseUrl = $baseUrl;

$urlParameters = $extConf->get('btu_vimp', 'urlParameters');
if (! is_array($urlParameters)) {
throw new InvalidConfigurationException('Configuration "urlParameters" must be an array', 1728910010);
}
$this->urlParameters = $urlParameters;
}

public function getBaseUrl(): string
{
return $this->baseUrl;
}

/**
* @return UrlParameters
*/
public function getUrlParameters(): array
{
return $this->urlParameters;
}
}
21 changes: 21 additions & 0 deletions Classes/Exception/GenericException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);

namespace BTU\BtuVimp\Exception;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Exception;

class GenericException extends Exception {}
19 changes: 19 additions & 0 deletions Classes/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace BTU\BtuVimp\Exception;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

class InvalidArgumentException extends LogicException {}
19 changes: 19 additions & 0 deletions Classes/Exception/InvalidConfigurationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace BTU\BtuVimp\Exception;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

class InvalidConfigurationException extends LogicException {}
19 changes: 19 additions & 0 deletions Classes/Exception/LogicException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace BTU\BtuVimp\Exception;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

class LogicException extends RuntimeException {}
19 changes: 19 additions & 0 deletions Classes/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace BTU\BtuVimp\Exception;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

class RuntimeException extends GenericException {}
26 changes: 9 additions & 17 deletions Classes/Helpers/VimpHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace BTU\BtuVimp\Helpers;

/*
Expand All @@ -14,24 +16,18 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use BTU\BtuVimp\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;

/**
* Vimp helper class
*/
class VimpHelper extends AbstractOnlineMediaHelper
{
/**
* Base URL for the ViMP instance
*
* @var string
*/
protected $baseUrl;
protected ExtensionConfiguration $extConf;

/**
* Constructor
Expand All @@ -41,9 +37,8 @@ class VimpHelper extends AbstractOnlineMediaHelper
public function __construct($extension)
{
parent::__construct($extension);
if (empty($this->baseUrl)) {
$this->baseUrl = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('btu_vimp', 'baseUrl');
}

$this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class);
}


Expand All @@ -61,10 +56,7 @@ public function transformUrlToFile($url, Folder $targetFolder)
{
$mediaId = null;

if (isset($this->baseUrl)
&& !empty($this->baseUrl)
&& StringUtility::beginsWith($url, $this->baseUrl)
) {
if (str_starts_with($url, $this->extConf->getBaseUrl())) {
if (preg_match('/\/(?:video)\/([0-9a-z\-]+)\/([0-9a-z]+)/i', $url, $matches)) {
$mediaTitle = $matches[1];
$mediaId = $matches[2];
Expand Down Expand Up @@ -118,8 +110,8 @@ public function getPreviewImage(File $file)
{
$videoId = $this->getOnlineMediaId($file);
$temporaryFileName = $this->getTempFolderPath() . 'vimp_' . md5($videoId) . '.jpg';
if (!file_exists($temporaryFileName)) {
$thumbnailUrl = $this->baseUrl . '/api/getPicture?type=medium&key=' . $videoId;
if (! file_exists($temporaryFileName)) {
$thumbnailUrl = $this->extConf->getBaseUrl() . '/api/getPicture?type=medium&key=' . $videoId;
$previewImage = GeneralUtility::getUrl($thumbnailUrl);
if ($previewImage !== false) {
file_put_contents($temporaryFileName, $previewImage);
Expand Down
43 changes: 23 additions & 20 deletions Classes/Rendering/VimpRenderer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace BTU\BtuVimp\Rendering;

/*
Expand All @@ -14,15 +16,14 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use BTU\BtuVimp\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperInterface;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
use TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;

/**
* Vimeo renderer class
Expand Down Expand Up @@ -73,7 +74,7 @@ protected function getOnlineMediaHelper(FileInterface $file)
$orgFile = $orgFile->getOriginalFile();
}
if ($orgFile instanceof File) {
$this->onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($orgFile);
$this->onlineMediaHelper = GeneralUtility::makeInstance(OnlineMediaHelperRegistry::class)->getOnlineMediaHelper($orgFile);
} else {
$this->onlineMediaHelper = false;
}
Expand Down Expand Up @@ -136,22 +137,24 @@ protected function collectOptions(array $options, FileInterface $file)
*/
protected function createVimpUrl(array $options, FileInterface $file)
{
$videoId = $this->getVideoIdFromFile($file);

$urlParams = [];
$urlParams[] = 'width=720';
$urlParams[] = 'height=405';
$urlParams[] = ((bool)$options['autoplay'] === true) ? 'autoplay=true' : 'autoplay=false';
$urlParams[] = 'autolightsoff=false';
$urlParams[] = 'loop=false';
$urlParams[] = 'chapters=false';
$urlParams[] = 'related=false';
$urlParams[] = 'responsive=false';
$urlParams[] = 't=0';

$baseUrl = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('btu_vimp', 'baseUrl');

return sprintf($baseUrl . 'media/embed?key=%s&%s', $videoId, implode('&', $urlParams));
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class);

$urlParameters = $extConf->getUrlParameters();
$urlParameters['key'] = $this->getVideoIdFromFile($file);
$urlParameters['autoplay'] = ($options['autoplay'] ?? false) === true;

array_walk($urlParameters, static function (&$value, $key) {
$value = match ($value) {
true => 'true',
false => 'false',
default => $value,
};
});

$urlParameters = http_build_query($urlParameters, '', '&');

$baseUrl = $extConf->getBaseUrl();
return sprintf($baseUrl . 'media/embed?%s', $urlParameters);
}

/**
Expand Down Expand Up @@ -214,7 +217,7 @@ protected function implodeAttributes(array $attributes): string
if ($value === true) {
$attributeList[] = $name;
} else {
$attributeList[] = $name . '="' . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . '"';
$attributeList[] = $name . '="' . htmlspecialchars((string)$value, ENT_QUOTES | ENT_HTML5) . '"';
}
}
return implode(' ', $attributeList);
Expand Down
8 changes: 8 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

BTU\BtuVimp\:
resource: '../Classes/*'
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"type": "typo3-cms-extension",
"license": "GPL-2.0-or-later",
"require": {
"typo3/cms-core": "^9.5|^10.4"
"php": "^8.0",
"typo3/cms-core": "^11.5|^12.4"
},
"replace": {
"btu/btu_vimp": "self.version",
Expand Down
21 changes: 20 additions & 1 deletion ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# cat=Settings/O; type=string; label= ViMP base url
baseUrl =


urlParameters {
# cat=urlParameters; type=int+; label=width of embedded videos
width = 720
# cat=urlParameters; type=int+; label=height of embedded videos
height = 405
# cat=urlParameters; type=boolean; label=autolightsoff of embedded videos
autolightsoff = false
# cat=urlParameters; type=boolean; label=show controls of embedded videos
controls = true
# cat=urlParameters; type=boolean; label=loop videos
loop = false
# cat=urlParameters; type=boolean; label=show chapters of embedded videos
chapters = false
# cat=urlParameters; type=boolean; label=show playlists of embedded videos
playlist = false
# cat=urlParameters; type=boolean; label=show related videos in embedded videos
related = false
# cat=urlParameters; type=boolean; label=responsive behavior
responsive = true
}
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'version' => '1.1.1',
'constraints' => [
'depends' => [
'typo3' => '9.5.0-10.4.99',
'typo3' => '11.5.99-12.4.99',
],
'conflicts' => [],
'suggests' => [],
Expand Down
Loading