PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Sources/Functions/variablesTreatment.functions.php

http://bideew.googlecode.com/
PHP | 158 lines | 99 code | 27 blank | 32 comment | 17 complexity | 22f642bbece568dbc8446cda2132149d MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2008 Bideew. All rights reserved.
  4. * @license GNU/GPL
  5. * This file is part of Bideew.
  6. * Bideew is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. * Bideew is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. * You should have received a copy of the GNU General Public License
  15. * along with Bideew; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. //Fonction de sécurité ? l'affichage des champs de la base de données
  19. function secureToDisplay($var){
  20. return htmlspecialchars($var);
  21. }
  22. //Fonction de sécurité pour l'insertion dans la base de données
  23. function secureToInsert($var){
  24. //Si la base n'est pas installée, ca ne sert ? rien de sécuriser les données...
  25. if (!DB_INSTALL){
  26. return $var;
  27. }
  28. return mysql_real_escape_string($var);
  29. }
  30. function copyGlobals(){
  31. $array = array();
  32. while (list($clef, $valeur)=each($GLOBALS)){
  33. //suppression de la référence ? $GLOBALS ($GLOBALS poss?de une référence ? lui- m?me)
  34. if($clef != 'GLOBALS'){
  35. $array[$clef] = copyWithoutRef($valeur);
  36. }
  37. }
  38. reset($GLOBALS);
  39. return $array;
  40. }
  41. function copyWithoutRef($var){
  42. $res = null;
  43. if(is_array($var)){
  44. $res = array();
  45. while (list($clef, $valeur)=each($var)){
  46. $res[$clef] = copyWithoutRef($valeur);
  47. }
  48. }
  49. else{
  50. $res = $var;
  51. }
  52. return $res;
  53. }
  54. //retourne les données d'une classe (nom, attributs public, protected et private)
  55. //La fonction récup?re les données par traitement de la chaine print_r
  56. function parseObject($obj){
  57. $obj_dump = print_r($obj, 1);
  58. $ret_list = array();
  59. $ret_map = array();
  60. $ret_name = '';
  61. $dump_lines = preg_split('/[\r\n]+/',$obj_dump);
  62. $ARR_NAME = 'arr_name';
  63. $ARR_LIST = 'arr_list';
  64. $arr_index = -1;
  65. // get the object type...
  66. $matches = array();
  67. preg_match('/^\s*(\S+)\s+\bObject\b/i',$obj_dump,$matches);
  68. if(isset($matches[1])){ $ret_name = $matches[1]; }//if
  69. foreach($dump_lines as &$line){
  70. $matches = array();
  71. //load up var and values...
  72. if(preg_match('/^\s*\[\s*(\S+)\s*\]\s+=>\s+(.*)$/', $line, $matches)){
  73. if(mb_stripos($matches[2],'array') !== false){
  74. $arr_map = array();
  75. $arr_map[$ARR_NAME] = $matches[1];
  76. $arr_map[$ARR_LIST] = array();
  77. $arr_list[++$arr_index] = $arr_map;
  78. }else{
  79. // save normal variables and arrays differently...
  80. if($arr_index >= 0){
  81. $arr_list[$arr_index][$ARR_LIST][$matches[1]] = $matches[2];
  82. }else{
  83. $ret_list[$matches[1]] = $matches[2];
  84. }//if/else
  85. }//if/else
  86. }else{
  87. // save the current array to the return list...
  88. if(mb_stripos($line,')') !== false){
  89. if($arr_index >= 0){
  90. $arr_map = array_pop($arr_list);
  91. // if there is more than one array then this array belongs to the earlier array...
  92. if($arr_index > 0){
  93. $arr_list[($arr_index-1)][$ARR_LIST][$arr_map[$ARR_NAME]] = $arr_map[$ARR_LIST];
  94. }else{
  95. $ret_list[$arr_map[$ARR_NAME]] = $arr_map[$ARR_LIST];
  96. }//if/else
  97. $arr_index--;
  98. }//if
  99. }//if
  100. }//if/else
  101. }//foreach
  102. $ret_map['name'] = $ret_name;
  103. $ret_map['variables'] = $ret_list;
  104. return $ret_map;
  105. }//method
  106. //fonction d'affichage de variable php en Javascript
  107. function php2js($var){
  108. if (is_array($var)){
  109. $res = "[";
  110. $array = array();
  111. foreach ($var as $a_var){
  112. $array[] = Debug::php2js($a_var);
  113. }
  114. return "[" . join(",", $array) . "]";
  115. }
  116. elseif (is_bool($var)){
  117. return $var ? "true" : "false";
  118. }
  119. elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)){
  120. return $var;
  121. }
  122. elseif (is_string($var)){
  123. return "\"".addslashes(stripslashes($var))."\"";
  124. }
  125. // autres cas: objets, on ne les g?re pas
  126. return false;
  127. }
  128. ?>