first commit

This commit is contained in:
salam committed 2026-10-19 08:18:39 +02:00
commit 1218dd1517
12716 files changed
+989233

No files matched your search

@@ -0,0 +1,143 @@
<?php
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\Utility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* ExternalMediaUtility
*/
class ExternalMediaUtility
{
/**
* @var array Provider that can be handled, the provider is equal the hostname and needs a process function
*/
protected $mediaProvider = [
'youtube',
'youtu',
'vimeo'
];
/**
* Get the embed code for the given url if possible
* and add a css class on the iframe
*
* @param string $url
* @param string $class
* @return string
*/
public function getEmbedCode($url, $class)
{
// Prepare url
$url = $this->setProtocolToHttps($url);
// Get method
$method = $this->getMethod($url);
if ($method !== null) {
$embedUrl = $this->{$method}($url);
if ($embedUrl) {
return '<iframe ' . GeneralUtility::implodeAttributes([
'class' => $class,
'src' => $embedUrl,
'frameborder' => 0
], true) . ' allowfullscreen></iframe>';
}
}
return null;
}
/**
* Resolves if possible a method name to process the url
*
* @param string $url
* @return string|null
*/
protected function getMethod($url)
{
$urlInformation = @parse_url($url);
if ($urlInformation) {
$hostName = GeneralUtility::trimExplode('.', $urlInformation['host'], true);
foreach ($this->mediaProvider as $provider) {
$functionName = 'process' . ucfirst($provider);
if (in_array($provider, $hostName) && is_callable([$this, $functionName])) {
return $functionName;
}
}
}
return null;
}
/**
* Processes YouTube url
*
* @param string $url
* @return string
*/
protected function processYoutube($url)
{
$firstMatches = [];
$pattern = '%^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=))([^"&?/ ]{11})(?:.+)?$%xs';
if (preg_match($pattern, $url, $firstMatches)) {
$toEmbed = $firstMatches[1];
$patternForAdditionalParams = '%^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=))(?:[^"&?\/ ]{11})(.+)?(?:.+)?$%xs';
$secondMatches = [];
if (preg_match($patternForAdditionalParams, $url, $secondMatches) > 1) {
$toEmbed .= '?' . substr($secondMatches[1], 1);
}
return 'https://www.youtube-nocookie.com/embed/' . $toEmbed;
}
return null;
}
/**
* Process YouTube short url
*
* @param string $url
* @return string
*/
protected function processYoutu($url)
{
return $this->processYoutube($url);
}
/**
* Processes Vimeo url
*
* @param string $url
* @return string
*/
protected function processVimeo($url)
{
$matches = [];
if (preg_match('/[\\/#](\\d+)$/', $url, $matches)) {
return 'https://player.vimeo.com/video/' . $matches[1];
}
return null;
}
/**
* Change every protocol to https and add it if missing
*
* @param string $url URL
* @return string
*/
protected function setProtocolToHttps($url)
{
$processUrl = trim($url);
if (strpos($url, 'http://') === 0) {
$processUrl = substr($processUrl, 7);
} elseif (strpos($processUrl, 'https://') === 0) {
$processUrl = substr($processUrl, 8);
} elseif (strpos($processUrl, '//') === 0) {
$processUrl = substr($processUrl, 2);
}
return 'https://' . $processUrl;
}
}
@@ -0,0 +1,228 @@
<?php
declare(strict_types = 1);
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\Utility;
/**
* Calculate image variants
*/
class ImageVariantsUtility
{
/**
* @var array
*/
protected static $allowedVariantProperties = [
'breakpoint',
'width',
'sizes',
];
/**
* @var array
*/
protected static $defaultVariants = [
'default' => [
'breakpoint' => 1200,
'width' => 1100
],
'large' => [
'breakpoint' => 992,
'width' => 920
],
'medium' => [
'breakpoint' => 768,
'width' => 680
],
'small' => [
'breakpoint' => 576,
'width' => 500
],
'extrasmall' => [
'width' => 374
]
];
/**
* @param array $variants
* @param array $multiplier
* @param array $gutters
* @param array $corrections
* @return array
*/
public static function getImageVariants($variants = [], $multiplier = [], $gutters = [], $corrections = []): array
{
$variants = self::processVariants($variants);
$variants = self::processResolutions($variants);
$variants = self::addGutters($variants, $gutters);
$variants = self::processMultiplier($variants, $multiplier);
$variants = self::removeGutters($variants, $gutters);
$variants = self::processCorrections($variants, $corrections);
return $variants;
}
/**
* @param array $variants
* @return array
*/
protected static function processResolutions($variants): array
{
foreach ($variants as $variant => $properties) {
if (!array_key_exists('sizes', $properties)) {
$properties['sizes'] = [];
}
$properties['sizes'] = self::processSizes($properties['sizes']);
$variants[$variant] = $properties;
}
return $variants;
}
/**
* @param array $sizes
* @return array
*/
protected static function processSizes($sizes): array
{
$resultSizes = [];
$workingSizes = [];
foreach ($sizes as $key => $settings) {
if (!array_key_exists('multiplier', $settings) ||
!is_numeric($settings['multiplier']) ||
$settings['multiplier'] < 1 ||
!self::isValidSizeKey($key)
) {
continue;
}
$workingSizes[substr($key, 0, -1) . ''] = [
'multiplier' => 1 * $settings['multiplier'],
];
}
if (!array_key_exists(1, $workingSizes)) {
$workingSizes[(float) 1 . ''] = ['multiplier' => 1];
}
ksort($workingSizes);
foreach ($workingSizes as $workingKey => $workingSettings) {
$resultSizes[$workingKey . 'x'] = $workingSettings;
}
return $resultSizes;
}
/**
* @param array $variants
* @return array
*/
protected static function processVariants($variants): array
{
$variants = is_array($variants) && !empty($variants) ? $variants : self::$defaultVariants;
foreach ($variants as $variant => $properties) {
if (!is_array($properties)) {
unset($variants[$variant]);
continue;
}
foreach ($properties as $key => $value) {
if (!in_array($key, self::$allowedVariantProperties, true)) {
unset($variants[$variant][$key]);
continue;
}
if ($key === 'sizes') {
continue;
} elseif (is_numeric($value) && $value > 0) {
$variants[$variant][$key] = (int) $value;
} else {
unset($variants[$variant][$key]);
}
}
if (empty($variants[$variant]) || !isset($variants[$variant]['width'])) {
unset($variants[$variant]);
}
}
return $variants;
}
/**
* @param array $variants
* @param array $gutters
* @return array
*/
protected static function addGutters($variants, $gutters): array
{
$gutters = is_array($gutters) ? $gutters : [];
foreach ($gutters as $variant => $value) {
if (is_numeric($value) && $value > 0 && isset($variants[$variant]['width'])) {
$variants[$variant]['width'] = (int) ceil($variants[$variant]['width'] + $value);
}
}
return $variants;
}
/**
* @param array $variants
* @param array $gutters
* @return array
*/
protected static function removeGutters($variants, $gutters): array
{
$gutters = is_array($gutters) ? $gutters : [];
foreach ($gutters as $variant => $value) {
if (is_numeric($value) && $value > 0 && isset($variants[$variant]['width'])) {
$variants[$variant]['width'] = (int) ceil($variants[$variant]['width'] - $value);
}
}
return $variants;
}
/**
* @param array $variants
* @param array $multiplier
* @return array
*/
protected static function processMultiplier($variants, $multiplier): array
{
$multiplier = is_array($multiplier) ? $multiplier : [];
foreach ($multiplier as $variant => $value) {
if (is_numeric($value) && $value > 0 && isset($variants[$variant]['width'])) {
$variants[$variant]['width'] = (int) ceil($variants[$variant]['width'] * $value);
}
}
return $variants;
}
/**
* @param array $variants
* @param array $corrections
* @return array
*/
protected static function processCorrections($variants, $corrections): array
{
$corrections = is_array($corrections) ? $corrections : [];
foreach ($corrections as $variant => $value) {
if (is_numeric($value) && $value > 0 && isset($variants[$variant]['width'])) {
$variants[$variant]['width'] -= $value;
}
}
return $variants;
}
/**
* @param mixed $key
* @return bool
*/
public static function isValidSizeKey($key): bool
{
return !(
!is_string($key) ||
substr($key, -1, 1) !== 'x' ||
!is_numeric(substr($key, 0, -1)) ||
(float) substr($key, 0, -1) < 1 ||
(float) substr($key, 0, -1) !== round((float) substr($key, 0, -1), 1)
);
}
}
@@ -0,0 +1,66 @@
<?php
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\Utility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* TextIconUtility
*/
class TextIconUtility
{
/**
* @param array $parameters
*/
public function addIconItems(array $parameters)
{
$directory = $parameters['row']['icon_set'][0];
if ($directory !== '') {
$icons = $this->getIcons($directory);
if ($icons) {
$parameters['items'] = array_merge($parameters['items'], $icons);
}
}
}
/**
* @param string $directory
* @return array|bool
*/
protected function getIcons($directory)
{
$icons = [];
if (strpos($directory, 'EXT:') !== 0 || !strpos($directory, 'Resources/Public')) {
return false;
}
$path = GeneralUtility::getFileAbsFileName($directory);
if (!is_dir($path)) {
return false;
}
$files = iterator_to_array(
new \FilesystemIterator(
$path,
\FilesystemIterator::KEY_AS_PATHNAME
)
);
ksort($files);
foreach ($files as $key => $fileinfo) {
if ($fileinfo->isFile() && in_array($fileinfo->getExtension(), ['svg', 'png', 'gif'])) {
$icons[] = [
$fileinfo->getBasename('.' . $fileinfo->getExtension()),
$directory . $fileinfo->getFilename(),
$directory . $fileinfo->getFilename()
];
}
}
return $icons;
}
}