mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-03 08:17:48 +02:00
73 lines
1.3 KiB
PHP
73 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace SilverStripe\View\Parsers;
|
||
|
|
||
|
use SilverStripe\Core\Object;
|
||
|
|
||
|
/**
|
||
|
* Base class for HTML cleaning implementations.
|
||
|
*/
|
||
|
abstract class HTMLCleaner extends Object {
|
||
|
|
||
|
/**
|
||
|
* @var array
|
||
|
*/
|
||
|
protected $defaultConfig = array();
|
||
|
|
||
|
/**
|
||
|
* Configuration variables for HTMLCleaners that support configuration (like Tidy)
|
||
|
*
|
||
|
* @var array
|
||
|
*/
|
||
|
public $config;
|
||
|
|
||
|
/**
|
||
|
* @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);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param array
|
||
|
*/
|
||
|
public function setConfig($config) {
|
||
|
$this->config = $config;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getConfig() {
|
||
|
return $this->config;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Passed a string, return HTML that has been tidied.
|
||
|
*
|
||
|
* @param string $content
|
||
|
* @return string HTML, tidied
|
||
|
*/
|
||
|
abstract public function cleanHTML($content);
|
||
|
|
||
|
/**
|
||
|
* 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;
|
||
|
}
|
||
|
}
|