silverstripe-framework/src/View/Parsers/HTMLCleaner.php

78 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\View\Parsers;
use SilverStripe\Core\Object;
/**
* Base class for HTML cleaning implementations.
*/
2016-11-29 00:31:16 +01:00
abstract class HTMLCleaner extends Object
{
2016-11-29 00:31:16 +01:00
/**
* @var array
*/
protected $defaultConfig = array();
2016-11-29 00:31:16 +01:00
/**
* Configuration variables for HTMLCleaners that support configuration (like Tidy)
*
* @var array
*/
public $config;
2016-11-29 00:31:16 +01:00
/**
* @param array $config The configuration for the cleaner, if necessary
*/
public function __construct($config = null)
{
parent::__construct();
if ($config) {
$config = array_merge($this->defaultConfig, $config);
} else {
$config = $this->defaultConfig;
}
$this->setConfig($config);
}
2016-11-29 00:31:16 +01:00
/**
* @param array
*/
public function setConfig($config)
{
$this->config = $config;
}
2016-11-29 00:31:16 +01:00
/**
* @return array
*/
public function getConfig()
{
return $this->config;
}
2016-11-29 00:31:16 +01:00
/**
* Passed a string, return HTML that has been tidied.
*
* @param string $content
* @return string HTML, tidied
*/
abstract public function cleanHTML($content);
2016-11-29 00:31:16 +01:00
/**
* Experimental inst class to create a default html cleaner class
*
* @return static
*/
public static function inst()
{
if (class_exists('HTMLPurifier')) {
return new PurifierHTMLCleaner();
} elseif (class_exists('tidy')) {
return new TidyHTMLCleaner();
}
return null;
}
}