HTMLPurifier Plugin for CodeIgniter
This plugin was created due to a need to use a wysiwyg and I didn’t trust it to validate.
First, you will need download the HTMLPurifier class. Extract and and rename the folder, ‘library’ which contain the main files to htmlpurifier.
Create a file. Name it htmlpurifier_pi.php and insert the code below.
function purify($dirty_html)
{
if (is_array($dirty_html))
{
foreach ($dirty_html as $key => $val)
{
$dirty_html[$key] = purify($val);
}
return $dirty_html;
}
if (trim($dirty_html) === ”)
{
return $dirty_html;
}
require_once(APPPATH.”plugins/htmlpurifier/HTMLPurifier.auto.php”);
require_once(APPPATH.”plugins/htmlpurifier/HTMLPurifier.func.php”);
$config = HTMLPurifier_Config::createDefault();
$config->set(’HTML’, ‘Doctype’, ‘XHTML 1.0 Strict’);
return HTMLPurifier($dirty_html, $config);
}
?>
Now, to use the plugin, you will need to load it using the controller.
{
$this->load->plugin(’htmlpurifier’);
$clean_html = purify($this->input->post(’html_content’));
$this->content_model->save($clean_html);
}
?>
Happy coding
I have also posted this on the codeigniter wiki: HTMLPurifier plugin for Codeigniter
