Skip to content

Instantly share code, notes, and snippets.

@RafaelKa
Forked from bwaidelich/PurifyViewHelper.php
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RafaelKa/d4d967f131ad41cc4a03 to your computer and use it in GitHub Desktop.
Save RafaelKa/d4d967f131ad41cc4a03 to your computer and use it in GitHub Desktop.
{
"name": "your/package",
"type": "typo3-flow-package",
"description": "<some description>",
"require": {
"typo3/flow": "~2.3",
"ezyang/htmlpurifier": "~4.6"
},
"autoload": {
"psr-0": {
"Your\\Package": "Classes"
}
}
}
<?php
namespace Your\Package\ViewHelpers\Format;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper rendering the given HTML string through HTMLPurifier
*/
class PurifyViewHelper extends AbstractViewHelper {
/**
* @var boolean
*/
protected $escapeChildren = FALSE;
/**
* @var boolean
*/
protected $escapeOutput = FALSE;
/**
* @param string $value The HTML string to purify. If NULL the child nodes will be used as value
* @return string The purified HTML string
*/
public function render($value = NULL) {
if ($value === NULL) {
$value = $this->renderChildren();
}
$purifierConfiguration = \HTMLPurifier_Config::createDefault();
// TODO adjust purifier configuration (possibly from settings, to make configurable)
$purifier = new \HTMLPurifier($purifierConfiguration);
return $purifier->purify($value);
}
}
{someHtml -> your.package:format.purify()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment