forked from refringe/CodeIgniter-HTMLPurifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmlpurifier_helper.php
65 lines (57 loc) · 1.79 KB
/
htmlpurifier_helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Codeigniter HTMLPurifier Helper
*
* Purify input using the HTMLPurifier standalone class.
* Easily use multiple purifier configurations.
*
* @author Tyler Brownell
* @copyright Copyright © 2011 Blue Fox Studio
* @license http://bluefoxstudio.ca/license.html
*
* @access public
* @param string or array
* @param string
* @return string or array
*/
if (! function_exists('html_purify'))
{
function html_purify($dirty_html, $config = FALSE)
{
require_once APPPATH . 'third_party/htmlpurifier-4.3.0-standalone/HTMLPurifier.standalone.php';
if (is_array($dirty_html))
{
foreach ($dirty_html as $key => $val)
{
$clean_html[$key] = html_purify($val);
}
}
else
{
switch ($config)
{
case 'comment':
$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'utf-8');
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$config->set('HTML.Allowed', 'p,a[href|title],abbr[title],acronym[title],b,strong,blockquote[cite],code,em,i,strike');
$config->set('AutoFormat.AutoParagraph', TRUE);
$config->set('AutoFormat.Linkify', TRUE);
$config->set('AutoFormat.RemoveEmpty', TRUE);
break;
case FALSE:
$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'utf-8');
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
break;
default:
show_error('The HTMLPurifier configuration labeled "' . htmlentities($config, ENT_QUOTES, 'UTF-8') . '" could not be found.');
}
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
}
return $clean_html;
}
}
/* End of htmlpurifier_helper.php */
/* Location: ./application/helpers/htmlpurifier_helper.php */