first commit
This commit is contained in:
commit
e81864e683
2984 files changed
+267797
No files matched your search
@@ -0,0 +1,140 @@
|
||||
<?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\Icons;
|
||||
|
||||
/**
|
||||
* AbstractIcon
|
||||
*/
|
||||
abstract class AbstractIcon implements IconInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $identifier;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $previewImage;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $height = 16;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $width = 16;
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @return self
|
||||
*/
|
||||
public function setIdentifier(string $identifier)
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return self
|
||||
*/
|
||||
public function setName(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $previewImage
|
||||
* @return self
|
||||
*/
|
||||
public function setPreviewImage(string $previewImage)
|
||||
{
|
||||
$this->previewImage = $previewImage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPreviewImage(): string
|
||||
{
|
||||
return $this->previewImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $height
|
||||
* @return self
|
||||
*/
|
||||
public function setHeight(int $height)
|
||||
{
|
||||
$this->height = $height;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight(): int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $width
|
||||
* @return self
|
||||
*/
|
||||
public function setWidth(int $width)
|
||||
{
|
||||
$this->width = $width;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth(): int
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?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\Icons;
|
||||
|
||||
use BK2K\BootstrapPackage\Utility\SvgUtility;
|
||||
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
|
||||
use TYPO3\CMS\Core\Resource\FileInterface;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
/**
|
||||
* FileIcon
|
||||
*/
|
||||
class FileIcon extends AbstractIcon
|
||||
{
|
||||
/**
|
||||
* @var FileInterface
|
||||
*/
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* @param FileInterface $file
|
||||
* @return self
|
||||
*/
|
||||
public function setFile(FileInterface $file): self
|
||||
{
|
||||
$this->file = $file;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FileInterface
|
||||
*/
|
||||
public function getFile(): FileInterface
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render(): string
|
||||
{
|
||||
try {
|
||||
$imageService = GeneralUtility::makeInstance(ImageService::class);
|
||||
$image = $imageService->getImage('', $this->file, false);
|
||||
$height = $this->getHeight();
|
||||
$width = $this->getWidth();
|
||||
|
||||
if ($image->getExtension() === 'svg') {
|
||||
return SvgUtility::getInlineSvg('', $image, $width, $height);
|
||||
}
|
||||
|
||||
$processingInstructions = [
|
||||
'width' => $width . 'c',
|
||||
'height' => $height . 'c'
|
||||
];
|
||||
$processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
|
||||
$imageUri = $imageService->getImageUri($processedImage);
|
||||
|
||||
return '<img loading="lazy" src="' . $imageUri . '" height="' . $height . '" width="' . $width . '" />';
|
||||
} catch (ResourceDoesNotExistException $e) {
|
||||
// thrown if file does not exist
|
||||
throw new \Exception($e->getMessage(), 1628773040, $e);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
// thrown if a file has been replaced with a folder
|
||||
throw new \Exception($e->getMessage(), 1628773041, $e);
|
||||
} catch (\RuntimeException $e) {
|
||||
// RuntimeException thrown if a file is outside of a storage
|
||||
throw new \Exception($e->getMessage(), 1628773042, $e);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// thrown if file storage does not exist
|
||||
throw new \Exception($e->getMessage(), 1628773043, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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\Icons;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* GlyphiconsProvider
|
||||
*/
|
||||
class GlyphiconsProvider implements IconProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return 'EXT:bootstrap_package/Resources/Public/Images/Icons/Glyphicons/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Glyphicons';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @return bool
|
||||
*/
|
||||
public function supports(string $identifier): bool
|
||||
{
|
||||
return 'EXT:bootstrap_package/Resources/Public/Images/Icons/Glyphicons/' === $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IconList
|
||||
*/
|
||||
public function getIconList(): IconList
|
||||
{
|
||||
$icons = new IconList();
|
||||
|
||||
$directory = 'EXT:bootstrap_package/Resources/Public/Images/Icons/Glyphicons/';
|
||||
$path = GeneralUtility::getFileAbsFileName($directory);
|
||||
$files = iterator_to_array(new \FilesystemIterator($path, \FilesystemIterator::KEY_AS_PATHNAME));
|
||||
ksort($files);
|
||||
|
||||
foreach ($files as $key => $fileinfo) {
|
||||
if ($fileinfo instanceof \SplFileInfo
|
||||
&& $fileinfo->isFile()
|
||||
&& strtolower($fileinfo->getExtension()) === 'svg'
|
||||
) {
|
||||
$icons->addIcon(
|
||||
(new SvgIcon())
|
||||
->setSrc($directory . $fileinfo->getFilename())
|
||||
->setIdentifier($directory . $fileinfo->getFilename())
|
||||
->setName($fileinfo->getBasename('.' . $fileinfo->getExtension()))
|
||||
->setPreviewImage($directory . $fileinfo->getFilename())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $icons;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?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\Icons;
|
||||
|
||||
/**
|
||||
* IconInterface
|
||||
*/
|
||||
interface IconInterface
|
||||
{
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @return self
|
||||
*/
|
||||
public function setIdentifier(string $identifier);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier(): string;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return self
|
||||
*/
|
||||
public function setName(string $name);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* @param string $previewImage
|
||||
* @return self
|
||||
*/
|
||||
public function setPreviewImage(string $previewImage);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPreviewImage(): string;
|
||||
|
||||
/**
|
||||
* @param int $width
|
||||
* @return self
|
||||
*/
|
||||
public function setWidth(int $width);
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth(): int;
|
||||
|
||||
/**
|
||||
* @param int $height
|
||||
* @return self
|
||||
*/
|
||||
public function setHeight(int $height);
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight(): int;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render(): string;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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\Icons;
|
||||
|
||||
/**
|
||||
* IconList
|
||||
*/
|
||||
class IconList
|
||||
{
|
||||
/**
|
||||
* @var IconInterface[] $icons
|
||||
*/
|
||||
protected $icons = [];
|
||||
|
||||
/**
|
||||
* @return IconInterface[]
|
||||
*/
|
||||
public function getIcons(): array
|
||||
{
|
||||
return $this->icons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IconInterface $icon
|
||||
* @return self
|
||||
*/
|
||||
public function addIcon(IconInterface $icon): self
|
||||
{
|
||||
$this->icons[$icon->getIdentifier()] = $icon;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IconInterface $icon
|
||||
* @return self
|
||||
*/
|
||||
public function removeIcon(IconInterface $icon): self
|
||||
{
|
||||
if (isset($this->icons[$icon->getIdentifier()])) {
|
||||
unset($this->icons[$icon->getIdentifier()]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @return IconInterface|null
|
||||
*/
|
||||
public function getIcon(string $identifier): ?IconInterface
|
||||
{
|
||||
return $this->icons[$identifier] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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\Icons;
|
||||
|
||||
/**
|
||||
* IconProviderInterface
|
||||
*/
|
||||
interface IconProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @return bool
|
||||
*/
|
||||
public function supports(string $identifier): bool;
|
||||
|
||||
/**
|
||||
* @return IconList
|
||||
*/
|
||||
public function getIconList(): IconList;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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\Icons;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* IoniconsProvider
|
||||
*/
|
||||
class IoniconsProvider implements IconProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return 'EXT:bootstrap_package/Resources/Public/Images/Icons/Ionicons/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Ionicons';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @return bool
|
||||
*/
|
||||
public function supports(string $identifier): bool
|
||||
{
|
||||
return 'EXT:bootstrap_package/Resources/Public/Images/Icons/Ionicons/' === $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IconList
|
||||
*/
|
||||
public function getIconList(): IconList
|
||||
{
|
||||
$icons = new IconList();
|
||||
|
||||
$directory = 'EXT:bootstrap_package/Resources/Public/Images/Icons/Ionicons/';
|
||||
$path = GeneralUtility::getFileAbsFileName($directory);
|
||||
$files = iterator_to_array(new \FilesystemIterator($path, \FilesystemIterator::KEY_AS_PATHNAME));
|
||||
ksort($files);
|
||||
|
||||
foreach ($files as $key => $fileinfo) {
|
||||
if ($fileinfo instanceof \SplFileInfo
|
||||
&& $fileinfo->isFile()
|
||||
&& strtolower($fileinfo->getExtension()) === 'svg'
|
||||
) {
|
||||
$icons->addIcon(
|
||||
(new SvgIcon())
|
||||
->setSrc($directory . $fileinfo->getFilename())
|
||||
->setIdentifier($directory . $fileinfo->getFilename())
|
||||
->setName($fileinfo->getBasename('.' . $fileinfo->getExtension()))
|
||||
->setPreviewImage($directory . $fileinfo->getFilename())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $icons;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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\Icons;
|
||||
|
||||
use BK2K\BootstrapPackage\Utility\SvgUtility;
|
||||
|
||||
/**
|
||||
* SvgIcon
|
||||
*/
|
||||
class SvgIcon extends AbstractIcon
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $src;
|
||||
|
||||
/**
|
||||
* @param string $src
|
||||
* @return self
|
||||
*/
|
||||
public function setSrc(string $src): self
|
||||
{
|
||||
$this->src = $src;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSrc(): string
|
||||
{
|
||||
return $this->src;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render(): string
|
||||
{
|
||||
$src = $this->getSrc();
|
||||
$height = $this->getHeight();
|
||||
$width = $this->getWidth();
|
||||
|
||||
return SvgUtility::getInlineSvg($src, null, $width, $height);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user