* @copyright Public Domain * @license http://bluefoxstudio.ca/release.html * * @access public * @param string or array $dirty_html A string (or array of strings) to be cleaned. * @param string $config The name of the configuration (switch case) to use. * @return string or array The cleaned string (or array of strings). */ if (! function_exists('html_purify')) { function html_purify($dirty_html, $config = FALSE) { if (is_array($dirty_html)) { foreach ($dirty_html as $key => $val) { $clean_html[$key] = html_purify($val, $config); } } else { $ci =& get_instance(); switch ($config) { case 'comment': $config = \HTMLPurifier_Config::createDefault(); $config->set('Core.Encoding', $ci->config->item('charset')); $config->set('HTML.Doctype', 'XHTML 1.0 Strict'); $config->set('HTML.Trusted', true); $config->set('HTML.SafeObject', true); $config->set('Core.EscapeInvalidTags', true); $config->set('HTML.Allowed', 'h1,h2,h3,h4,h5,h6,br,b,i,strong,em,a,pre,a[href|title],span,div,code,img,tt,div,ins,del,sup,sub,p,ol,ul,table,thead,tbody,tfoot,blockquote,dl,dt,dd,kbd,q,samp,var,hr,li,tr,td,th,s,strike,abbr[title]'); $config->set('HTML.AllowedAttributes', 'img.src,*.style,*.class, code.class,a.href,*.target'); $config->set('Attr.AllowedFrameTargets', ['_blank', '_self', '_target', '_top']); $config->set('HTML.TargetBlank', true); $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', $ci->config->item('charset')); $config->set('Core.EscapeInvalidTags', true); $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 */