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