PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/fonctions/fct_chaines.php

http://malleo-cms.googlecode.com/
PHP | 141 lines | 71 code | 8 blank | 62 comment | 9 complexity | a0a8ec1ce74e032e74df4457baf1db8f MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. |------------------------------------------------------------------------------------------------------------
  4. | Software: Malleo ( CMS )
  5. | Contact: SP - http://www.malleo-cms.com
  6. | Support: http://www.malleo-cms.com?module=forum
  7. | Documentation : Support: http://www.malleo-cms.com?module=wiki
  8. |------------------------------------------------------------------------------------------------------------
  9. | Author: Stephane RAJALU
  10. | Copyright (c) 2008-2009, Stephane RAJALU All Rights Reserved
  11. |------------------------------------------------------------------------------------------------------------
  12. | License: Distributed under the CECILL V2 License
  13. | This program is distributed in the hope that it will be useful - WITHOUT
  14. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. | FITNESS FOR A PARTICULAR PURPOSE.
  16. |
  17. | Please read Licence_CeCILL_V2-en.txt
  18. | SVP lisez Licence_CeCILL_V2-fr.txt
  19. |------------------------------------------------------------------------------------------------------------
  20. */
  21. if ( !defined('PROTECT') )
  22. {
  23. die("Tentative de Hacking");
  24. }
  25. //
  26. // supprime les entites HTML incompletes
  27. function clean_amp($chaine){
  28. return str_replace('amp;','',$chaine);
  29. }
  30. //
  31. // Protection des quotes si la propriete magic_quotes n'est pas activee
  32. // Nettoyage des clefs si des &amp; apparaissent
  33. function protection_variables()
  34. {
  35. foreach ($_GET as $key=>$val){
  36. $key = clean_amp($key);
  37. if (!is_array($val)) $_GET[$key] = (!get_magic_quotes_gpc())? addslashes($val):$val;
  38. }
  39. foreach ($_POST as $key=>$val){
  40. $key = clean_amp($key);
  41. if (!is_array($val)) $_POST[$key] = (!get_magic_quotes_gpc())? addslashes($val):$val;
  42. }
  43. }
  44. //
  45. // Fonction nettoyant les saisies de tous les caracteres non imprimables et des codes pouvant
  46. // Porter atteinte ? l'intégrité du code.
  47. // SOURCE de la fonction : http://ha.ckers.org/xss.html
  48. function RemoveXSS($val) {
  49. return $val;
  50. /*return htmlspecialchars($val);
  51. // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
  52. // this prevents some character re-spacing such as <java\0script>
  53. // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
  54. // $val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);
  55. // straight replacements, the user should never need these since they're normal characters
  56. // this prevents like <IMG SRC=&#X40&#X61&#X76&#X61&#X73&#X63&#X72&#X69&#X70&#X74&#X3A&#X61&#X6C&#X65&#X72&#X74&#X28&#X27&#X58&#X53&#X53&#X27&#X29>
  57. $search = 'abcdefghijklmnopqrstuvwxyz';
  58. $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  59. $search .= '1234567890!@#$%^&*()';
  60. $search .= '~`";:,?+/={}[]-_|\'\\';
  61. for ($i = 0; $i < strlen($search); $i++){
  62. // ;? matches the ;, which is optional
  63. // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
  64. // &#x0040 @ search for the hex values
  65. $val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
  66. // &#00064 @ 0{0,7} matches '0' zero to seven times
  67. $val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
  68. }
  69. return $val;*/
  70. }
  71. //
  72. // REMPLACEMENT des caracteres accentues par leur equivalent HTML
  73. function str_to_html($chaine,$blocage_conversion=false)
  74. {
  75. global $cf;
  76. if ($blocage_conversion == false){
  77. $chaine = mb_convert_encoding($chaine, $cf->config['charset'], mb_detect_encoding($chaine));
  78. }
  79. return str_replace(array('á','?','â','?','ä','é','?','?','ë','ç','?','ó','?','ô','?','ö','?','í','î','?','ú','?','?','ü'),
  80. array( '&aacute;','&agrave;','&acirc;','&atilde;','&auml;','&eacute;','&egrave;','&ecirc;','&euml;','&ccedil;','&ntilde;',
  81. '&oacute;','&ograve;','&ocirc;','&otilde;','&ouml;','&iacute;','&igrave;','&icirc;','&iuml;','&uacute;','&ugrave;','&ucirc;','&uuml;'),$chaine);
  82. }
  83. // fonction inverse a la precedente
  84. function html_to_str($chaine,$blocage_conversion=false)
  85. {
  86. global $cf;
  87. if ($blocage_conversion == true){
  88. $chaine = mb_convert_encoding($chaine, $cf->config['charset'], mb_detect_encoding($chaine));
  89. }
  90. return str_replace(array('&aacute;','&agrave;','&acirc;','&atilde;','&auml;','&eacute;','&egrave;','&ecirc;','&euml;','&ccedil;','&ntilde;',
  91. '&oacute;','&ograve;','&ocirc;','&otilde;','&ouml;','&iacute;','&igrave;','&icirc;','&iuml;','&uacute;','&ugrave;','&ucirc;','&uuml;'),
  92. array('á','?','â','?','ä','é','?','?','ë','ç','?','ó','?','ô','?','ö','?','í','î','?','ú','?','?','ü'),$chaine);
  93. }
  94. function conversion_charset($chaine){
  95. global $cf;
  96. $chaine = mb_convert_encoding($chaine, $cf->config['charset'], "auto");
  97. return $chaine;
  98. }
  99. //
  100. // REMPLACEMENT des caracteres Accentues par leur equivalent sans accent
  101. function supprimer_accents($chaine)
  102. {
  103. global $cf;
  104. $chaine = strtr($chaine,array(
  105. '?'=>'Y','?'=>'s','?'=>'A','?'=>'a','?'=>'A','?'=>'a','?'=>'o','?'=>'a','á'=>'a','â'=>'a','?'=>'a','ä'=>'a','ç'=>'c',
  106. '?'=>'e','é'=>'e','?'=>'e','ë'=>'e','?'=>'i','í'=>'i','î'=>'i','?'=>'i','?'=>'n','?'=>'o','ó'=>'o','ô'=>'o','?'=>'o',
  107. 'ö'=>'o','?'=>'u','ú'=>'u','?'=>'u','ü'=>'u','ý'=>'y','?'=>'y','?'=>'A','Á'=>'A','Â'=>'A','?'=>'A','Ä'=>'A','Ç'=>'C',
  108. '?'=>'E','É'=>'E','?'=>'E','Ë'=>'E','?'=>'I','Í'=>'I','Î'=>'I','?'=>'I','?'=>'N','?'=>'O','Ó'=>'O','Ô'=>'O','?'=>'O',
  109. 'Ö'=>'O','?'=>'U','Ú'=>'U','?'=>'U','Ü'=>'U','Ý'=>'Y'));
  110. //$chaine = strtr($chaine, '?áâ?äç?é?ë?íî???óô?ö?ú?üý??ÁÂ?ÄÇ?É?Ë?ÍÎ???ÓÔ?Ö?Ú?ÜÝ', 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
  111. return $chaine;
  112. }
  113. //
  114. // fonctions de nettoyage de saisies(
  115. function nettoyage_nom($username){
  116. return protection_chaine(substr(trim($username), 0, 30));
  117. }
  118. function nettoyage_mail($mail){ return htmlentities(trim($mail));}
  119. function nettoyage_pass($pass){ return htmlspecialchars(trim($pass));}
  120. function protection_chaine($chaine){
  121. global $cf;
  122. if (!is_string($chaine)) return $chaine;
  123. if (!isset($cf->config)) $cf->config['charset'] = 'UTF-8';
  124. //if (mb_detect_encoding($chaine) != "ISO-8859-1"){ $chaine = mb_convert_encoding($chaine,"ISO-8859-1","auto"); }
  125. $chaine = htmlentities($chaine,ENT_QUOTES,$cf->config['charset']);
  126. //$chaine = mb_convert_encoding($chaine,$cf->config['charset'],"ISO-8859-1");
  127. return $chaine;
  128. }
  129. //
  130. // Rend les URL cliquables
  131. function url_cliquable($chaine){ return preg_replace("/([[:alnum:]]+):\/\/([^[:space:]]*)([[:alnum:]#?\/&=])/i",'<a href="\\1://\\2\\3">\\2\\3</a>',$chaine);}