Last active
March 20, 2018 13:30
-
-
Save wernerkrauss/e244c7be9c095fe519c69bd574badf07 to your computer and use it in GitHub Desktop.
Method to cleanup SilverStripe $Content from old installations on-the-fly using HTMLPurifyer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* cleans up $Content using HTMLPurifyer | |
* | |
* @return \SilverStripe\ORM\FieldType\DBHTMLText | |
*/ | |
public function getContent() | |
{ | |
$content = $this->dbObject('Content'); | |
$config = HTMLPurifier_Config::createDefault(); | |
$config->set('CSS.AllowedProperties', []); | |
$config->set('AutoFormat.RemoveEmpty', true); | |
$config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true); | |
$config->set('AutoFormat.RemoveSpansWithoutAttributes', true); | |
$purifier = new HTMLPurifier($config); | |
$clean_html = $purifier->purify($content); | |
return \SilverStripe\ORM\FieldType\DBHTMLText::create()->setValue($clean_html); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment