Skip to content

Instantly share code, notes, and snippets.

@wernerkrauss
Last active March 20, 2018 13:30
Show Gist options
  • Save wernerkrauss/e244c7be9c095fe519c69bd574badf07 to your computer and use it in GitHub Desktop.
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
<?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