/halogy/helpers/security_helper.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 126 lines · 55 code · 13 blank · 58 comment · 9 complexity · ad31d583dbee52fc18cfecf2cc7393bb 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 4.3.2 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2009, 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->input->xss_clean($str, $is_image);
  40. }
  41. }
  42. // --------------------------------------------------------------------
  43. /**
  44. * Hash encode a string
  45. *
  46. * @access public
  47. * @param string
  48. * @return string
  49. */
  50. if ( ! function_exists('dohash'))
  51. {
  52. function dohash($str, $type = 'sha1')
  53. {
  54. if ($type == 'sha1')
  55. {
  56. if ( ! function_exists('sha1'))
  57. {
  58. if ( ! function_exists('mhash'))
  59. {
  60. require_once(BASEPATH.'libraries/Sha1'.EXT);
  61. $SH = new CI_SHA;
  62. return $SH->generate($str);
  63. }
  64. else
  65. {
  66. return bin2hex(mhash(MHASH_SHA1, $str));
  67. }
  68. }
  69. else
  70. {
  71. return sha1($str);
  72. }
  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 */