|
HTML Purifer - Codeigniter Plugin February 28, 2009 06:33AM |
Registered: 1 year ago Posts: 2 |
I was thinking that since the Codeigniter Plugin link on the home page doesn't work (Page not Found), I'd write one.
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;
}
// to prevent further processing of 'nothing'...
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);
}
Save the file in your plugins folder located in the application folder ('application/plugins/'). If it doesn't exist. Create one. Save htmlpurifier_pi.php in that folder.
Now, to use the plugin, you will need to load it using the controller.
function save()
{
$this->load->plugin(’htmlpurifier’);
$clean_html = purify($this->input->post(’html_content’));
$this->content_model->save($clean_html);
}
Happy coding :P
From: HTMLPurifier Plugin for CodeIgniter by Thorpe Obazee
Edit: Added support for arrays.
Pinoy Tech: Web Development and CodeIgniter
Edited 4 time(s). Last edit at 02/28/2009 10:33PM by Chamyto.
|
Re: HTML Purifer - Codeigniter Plugin February 28, 2009 01:09PM |
Admin Registered: 3 years ago Posts: 1,819 |
Good catch. I probably should update the link.
HTML Purifier, Standards-Compliant HTML Filtering
|
ci newbie
Re: HTML Purifer - Codeigniter PluginOctober 09, 2009 06:17AM |
|
Re: HTML Purifer - Codeigniter Plugin November 12, 2009 07:16PM |
Registered: 1 year ago Posts: 2 |
@ ci newbie. Nice catch. I sure hope the link an updated tutorial is updated on the homepage though..