‪TYPO3CMS  ‪main
AbstractSvgIconProvider.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 
31 {
32  public const ‪MARKUP_IDENTIFIER_INLINE = 'inline';
33 
34  abstract protected function ‪generateMarkup(‪Icon $icon, array $options): string;
35  abstract protected function ‪generateInlineMarkup(array $options): string;
36 
37  public function ‪prepareIconMarkup(‪Icon $icon, array $options = []): void
38  {
39  $icon->‪setMarkup($this->‪generateMarkup($icon, $options));
40  $icon->‪setAlternativeMarkup(self::MARKUP_IDENTIFIER_INLINE, $this->‪generateInlineMarkup($options));
41  }
42 
46  protected function ‪getPublicPath(string $source): string
47  {
48  if (‪PathUtility::isExtensionPath($source)) {
50  }
51  // TODO: deprecate non extension resources in icon API
52  return ‪PathUtility::getAbsoluteWebPath(‪PathUtility::isAbsolutePath($source) ? $source : GeneralUtility::getFileAbsFileName($source));
53  }
54 
55  protected function ‪getInlineSvg(string $source): string
56  {
57  if (!file_exists($source)) {
58  return '';
59  }
60 
61  $svgContent = file_get_contents($source);
62  if ($svgContent === false) {
63  return '';
64  }
65  $svgContent = (string)preg_replace('/<script[\s\S]*?>[\s\S]*?<\/script>/i', '', $svgContent);
66  $svgElement = simplexml_load_string($svgContent);
67  if ($svgElement === false) {
68  return '';
69  }
70 
71  // remove xml version tag
72  $domXml = dom_import_simplexml($svgElement);
73  return $domXml->ownerDocument->saveXML($domXml->ownerDocument->documentElement);
74  }
75 }
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\generateMarkup
‪generateMarkup(Icon $icon, array $options)
‪TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath
‪static isExtensionPath(string $path)
Definition: PathUtility.php:117
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Imaging\Icon\setAlternativeMarkup
‪$this setAlternativeMarkup(string $markupIdentifier, string $markup)
Definition: Icon.php:135
‪TYPO3\CMS\Core\Utility\PathUtility\isAbsolutePath
‪static isAbsolutePath(string $path)
Definition: PathUtility.php:286
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\MARKUP_IDENTIFIER_INLINE
‪const MARKUP_IDENTIFIER_INLINE
Definition: AbstractSvgIconProvider.php:32
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\getInlineSvg
‪getInlineSvg(string $source)
Definition: AbstractSvgIconProvider.php:55
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider
Definition: AbstractSvgIconProvider.php:31
‪TYPO3\CMS\Core\Imaging\IconProvider
Definition: AbstractSvgIconProvider.php:18
‪TYPO3\CMS\Core\Imaging\IconProviderInterface
Definition: IconProviderInterface.php:22
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath(string $targetPath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:52
‪TYPO3\CMS\Core\Utility\PathUtility\getPublicResourceWebPath
‪static getPublicResourceWebPath(string $resourcePath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:97
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\getPublicPath
‪getPublicPath(string $source)
Definition: AbstractSvgIconProvider.php:46
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\generateInlineMarkup
‪generateInlineMarkup(array $options)
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\prepareIconMarkup
‪prepareIconMarkup(Icon $icon, array $options=[])
Definition: AbstractSvgIconProvider.php:37
‪TYPO3\CMS\Core\Imaging\Icon\setMarkup
‪$this setMarkup(string $markup)
Definition: Icon.php:121
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52