blob: eec04015d5d29d2b76548734553eff57bb37670b [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, EllisLab, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter Security Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
24 * @author Rick Ellis
25 * @link http://www.codeigniter.com/user_guide/helpers/security_helper.html
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * XSS Filtering
32 *
33 * @access public
34 * @param string
35 * @param string the character set of your data
36 * @return string
37 */
38function xss_clean($str, $charset = 'ISO-8859-1')
39{
40 $CI =& get_instance();
41 return $CI->input->xss_clean($str, $charset);
42}
43
44// --------------------------------------------------------------------
45
46/**
47 * Hash encode a string
48 *
49 * @access public
50 * @param string
51 * @return string
52 */
53function dohash($str, $type = 'sha1')
54{
55 if ($type == 'sha1')
56 {
57 if ( ! function_exists('sha1'))
58 {
59 if ( ! function_exists('mhash'))
60 {
61 require_once(BASEPATH.'libraries/Sha1'.EXT);
62 $SH = new CI_SHA;
63 return $SH->generate($str);
64 }
65 else
66 {
67 return bin2hex(mhash(MHASH_SHA1, $str));
68 }
69 }
70 else
71 {
72 return sha1($str);
73 }
74 }
75 else
76 {
77 return md5($str);
78 }
79}
80
81// ------------------------------------------------------------------------
82
83/**
84 * Strip Image Tags
85 *
86 * @access public
87 * @param string
88 * @return string
89 */
90function strip_image_tags($str)
91{
92 $str = preg_replace("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "\\1", $str);
93 $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?\>#", "\\1", $str);
94
95 return $str;
96}
97
98// ------------------------------------------------------------------------
99
100/**
101 * Convert PHP tags to entities
102 *
103 * @access public
104 * @param string
105 * @return string
106 */
107function encode_php_tags($str)
108{
109 return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
110}
111
adminb0dd10f2006-08-25 17:25:49 +0000112?>