PageRenderTime 67ms CodeModel.GetById 42ms RepoModel.GetById 0ms app.codeStats 0ms

/system/helpers/security_helper.php

https://bitbucket.org/siriusdely/codeigniter-reactor
PHP | 128 lines | 47 code | 15 blank | 66 comment | 8 complexity | 3124a30890a64f09740dd2b148bd008d MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter Security Helpers
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Helpers
  21. * @category Helpers
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/helpers/security_helper.html
  24. */
  25. // ------------------------------------------------------------------------
  26. /**
  27. * XSS Filtering
  28. *
  29. * @access public
  30. * @param string
  31. * @param bool whether or not the content is an image file
  32. * @return string
  33. */
  34. if ( ! function_exists('xss_clean'))
  35. {
  36. function xss_clean($str, $is_image = FALSE)
  37. {
  38. $CI =& get_instance();
  39. return $CI->security->xss_clean($str, $is_image);
  40. }
  41. }
  42. // ------------------------------------------------------------------------
  43. /**
  44. * Sanitize Filename
  45. *
  46. * @access public
  47. * @param string
  48. * @return string
  49. */
  50. if ( ! function_exists('sanitize_filename'))
  51. {
  52. function sanitize_filename($filename)
  53. {
  54. $CI =& get_instance();
  55. return $CI->security->sanitize_filename($filename);
  56. }
  57. }
  58. // --------------------------------------------------------------------
  59. /**
  60. * Hash encode a string
  61. *
  62. * @access public
  63. * @param string
  64. * @return string
  65. */
  66. if ( ! function_exists('do_hash'))
  67. {
  68. function do_hash($str, $type = 'sha1')
  69. {
  70. if ($type == 'sha1')
  71. {
  72. return sha1($str);
  73. }
  74. else
  75. {
  76. return md5($str);
  77. }
  78. }
  79. }
  80. // ------------------------------------------------------------------------
  81. /**
  82. * Strip Image Tags
  83. *
  84. * @access public
  85. * @param string
  86. * @return string
  87. */
  88. if ( ! function_exists('strip_image_tags'))
  89. {
  90. function 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. return $str;
  95. }
  96. }
  97. // ------------------------------------------------------------------------
  98. /**
  99. * Convert PHP tags to entities
  100. *
  101. * @access public
  102. * @param string
  103. * @return string
  104. */
  105. if ( ! function_exists('encode_php_tags'))
  106. {
  107. function encode_php_tags($str)
  108. {
  109. return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
  110. }
  111. }
  112. /* End of file security_helper.php */
  113. /* Location: ./system/helpers/security_helper.php */