‪TYPO3CMS  11.5
HtmlViewHelper.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 
23 use TYPO3\HtmlSanitizer\Builder\BuilderInterface;
24 use TYPO3\HtmlSanitizer\Sanitizer;
25 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
27 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
28 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
29 
59 class ‪HtmlViewHelper extends AbstractViewHelper
60 {
61  use CompileWithRenderStatic;
62 
66  protected ‪$escapeChildren = false;
67 
71  protected ‪$escapeOutput = false;
72 
76  public function ‪initializeArguments()
77  {
78  $this->registerArgument(
79  'build',
80  'string',
81  'preset name or class-like name of sanitization builder',
82  false,
83  'default'
84  );
85  }
86 
94  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
95  {
96  $value = $renderChildrenClosure();
97  $build = $arguments['build'] ?? 'default';
98  return static::createSanitizer($build)->sanitize((string)$value, self::createInitiator());
99  }
100 
101  protected static function ‪createInitiator(): ‪SanitizerInitiator
102  {
103  return GeneralUtility::makeInstance(SanitizerInitiator::class, self::class);
104  }
105 
106  protected static function ‪createSanitizer(string $build): Sanitizer
107  {
108  if (class_exists($build) && is_a($build, BuilderInterface::class, true)) {
109  $builder = GeneralUtility::makeInstance($build);
110  } else {
111  $factory = GeneralUtility::makeInstance(SanitizerBuilderFactory::class);
112  $builder = $factory->build($build);
113  }
114  return $builder->build();
115  }
116 }
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\$escapeChildren
‪bool $escapeChildren
Definition: HtmlViewHelper.php:64
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: HtmlViewHelper.php:91
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper
Definition: HtmlViewHelper.php:60
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\createInitiator
‪static createInitiator()
Definition: HtmlViewHelper.php:98
‪TYPO3\CMS\Core\Html\SanitizerInitiator
Definition: SanitizerInitiator.php:25
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\createSanitizer
‪static createSanitizer(string $build)
Definition: HtmlViewHelper.php:103
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\initializeArguments
‪initializeArguments()
Definition: HtmlViewHelper.php:73
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize
Definition: HtmlViewHelper.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Fluid\ViewHelpers\Sanitize\HtmlViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: HtmlViewHelper.php:68
‪TYPO3\CMS\Core\Html\SanitizerBuilderFactory
Definition: SanitizerBuilderFactory.php:35