blob: 7968f9e9f97d2656fafbfe8d6358efe18b973ee1 [file] [log] [blame]
Andrey Andreeva381d172012-01-06 19:19:37 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreeva381d172012-01-06 19:19:37 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreeva381d172012-01-06 19:19:37 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * CodeIgniter Security Helpers
30 *
31 * @package CodeIgniter
32 * @subpackage Helpers
33 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/helpers/security_helper.html
36 */
37
38// ------------------------------------------------------------------------
39
Derek Allard2067d1a2008-11-13 22:59:24 +000040if ( ! function_exists('xss_clean'))
41{
Timothy Warrenb75faa12012-04-27 12:03:32 -040042 /**
43 * XSS Filtering
44 *
45 * @param string
46 * @param bool whether or not the content is an image file
47 * @return string
48 */
Derek Jonesf0bcb3c2009-02-10 18:40:21 +000049 function xss_clean($str, $is_image = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +000050 {
51 $CI =& get_instance();
Derek Jones11b1e512010-03-05 10:22:44 -060052 return $CI->security->xss_clean($str, $is_image);
Derek Allard2067d1a2008-11-13 22:59:24 +000053 }
54}
55
Derek Allard4433f422010-07-23 08:47:34 -040056// ------------------------------------------------------------------------
57
Derek Allard4433f422010-07-23 08:47:34 -040058if ( ! function_exists('sanitize_filename'))
59{
Timothy Warrenb75faa12012-04-27 12:03:32 -040060 /**
61 * Sanitize Filename
62 *
63 * @param string
64 * @return string
65 */
Derek Allard4433f422010-07-23 08:47:34 -040066 function sanitize_filename($filename)
67 {
68 $CI =& get_instance();
69 return $CI->security->sanitize_filename($filename);
70 }
71}
72
Derek Allard2067d1a2008-11-13 22:59:24 +000073// --------------------------------------------------------------------
74
Derek Allard8719a5c2009-10-08 16:42:59 +000075if ( ! function_exists('do_hash'))
Barry Mienydd671972010-10-04 16:33:58 +020076{
Timothy Warrenb75faa12012-04-27 12:03:32 -040077 /**
78 * Hash encode a string
79 *
Andrey Andreev0f0b7692012-06-07 14:57:04 +030080 * This function is DEPRECATED and should be removed in
81 * CodeIgniter 3.1+. Use hash() instead.
82 *
Andrey Andreevd1cace72012-06-17 03:01:00 +030083 * @deprecated
Timothy Warrenb75faa12012-04-27 12:03:32 -040084 * @param string
85 * @param string
86 * @return string
87 */
Derek Allard8719a5c2009-10-08 16:42:59 +000088 function do_hash($str, $type = 'sha1')
Derek Allard2067d1a2008-11-13 22:59:24 +000089 {
Andrey Andreev7eea3062012-03-19 12:58:45 +020090 if ( ! in_array(strtolower($type), hash_algos()))
Andrey Andreev50bff7c2012-03-19 12:16:38 +020091 {
92 $type = 'md5';
93 }
94
freewil8840c962012-03-18 15:23:09 -040095 return hash($type, $str);
Derek Allard2067d1a2008-11-13 22:59:24 +000096 }
97}
Barry Mienydd671972010-10-04 16:33:58 +020098
Derek Allard2067d1a2008-11-13 22:59:24 +000099// ------------------------------------------------------------------------
100
Derek Allard2067d1a2008-11-13 22:59:24 +0000101if ( ! function_exists('strip_image_tags'))
102{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400103 /**
104 * Strip Image Tags
105 *
106 * @param string
107 * @return string
108 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 function strip_image_tags($str)
110 {
Andrey Andreev50bff7c2012-03-19 12:16:38 +0200111 return preg_replace(array('#<img\s+.*?src\s*=\s*["\'](.+?)["\'].*?\>#', '#<img\s+.*?src\s*=\s*(.+?).*?\>#'), '\\1', $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 }
113}
Barry Mienydd671972010-10-04 16:33:58 +0200114
Derek Allard2067d1a2008-11-13 22:59:24 +0000115// ------------------------------------------------------------------------
116
Derek Allard2067d1a2008-11-13 22:59:24 +0000117if ( ! function_exists('encode_php_tags'))
118{
Timothy Warrenb75faa12012-04-27 12:03:32 -0400119 /**
120 * Convert PHP tags to entities
121 *
122 * @param string
123 * @return string
124 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000125 function encode_php_tags($str)
126 {
Andrey Andreeve446ad32012-06-15 15:23:41 +0300127 return str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 }
129}
130
Derek Allard2067d1a2008-11-13 22:59:24 +0000131/* End of file security_helper.php */
Andrey Andreeve92df332012-03-26 22:44:20 +0300132/* Location: ./system/helpers/security_helper.php */