/Sources/Functions/variablesTreatment.functions.php
PHP | 158 lines | 99 code | 27 blank | 32 comment | 17 complexity | 22f642bbece568dbc8446cda2132149d MD5 | raw file
Possible License(s): GPL-3.0
- <?php
- /**
- * @copyright Copyright (C) 2008 Bideew. All rights reserved.
- * @license GNU/GPL
- * This file is part of Bideew.
-
- * Bideew is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
-
- * Bideew is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with Bideew; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
- //Fonction de sécurité ? l'affichage des champs de la base de données
- function secureToDisplay($var){
- return htmlspecialchars($var);
- }
-
- //Fonction de sécurité pour l'insertion dans la base de données
- function secureToInsert($var){
- //Si la base n'est pas installée, ca ne sert ? rien de sécuriser les données...
- if (!DB_INSTALL){
- return $var;
- }
- return mysql_real_escape_string($var);
- }
-
- function copyGlobals(){
- $array = array();
- while (list($clef, $valeur)=each($GLOBALS)){
- //suppression de la référence ? $GLOBALS ($GLOBALS poss?de une référence ? lui- m?me)
- if($clef != 'GLOBALS'){
- $array[$clef] = copyWithoutRef($valeur);
- }
- }
- reset($GLOBALS);
- return $array;
- }
-
- function copyWithoutRef($var){
- $res = null;
- if(is_array($var)){
- $res = array();
- while (list($clef, $valeur)=each($var)){
- $res[$clef] = copyWithoutRef($valeur);
- }
- }
- else{
- $res = $var;
- }
- return $res;
- }
-
- //retourne les données d'une classe (nom, attributs public, protected et private)
- //La fonction récup?re les données par traitement de la chaine print_r
- function parseObject($obj){
-
- $obj_dump = print_r($obj, 1);
- $ret_list = array();
- $ret_map = array();
- $ret_name = '';
- $dump_lines = preg_split('/[\r\n]+/',$obj_dump);
- $ARR_NAME = 'arr_name';
- $ARR_LIST = 'arr_list';
- $arr_index = -1;
-
- // get the object type...
- $matches = array();
- preg_match('/^\s*(\S+)\s+\bObject\b/i',$obj_dump,$matches);
- if(isset($matches[1])){ $ret_name = $matches[1]; }//if
-
- foreach($dump_lines as &$line){
-
- $matches = array();
-
- //load up var and values...
- if(preg_match('/^\s*\[\s*(\S+)\s*\]\s+=>\s+(.*)$/', $line, $matches)){
-
- if(mb_stripos($matches[2],'array') !== false){
-
- $arr_map = array();
- $arr_map[$ARR_NAME] = $matches[1];
- $arr_map[$ARR_LIST] = array();
- $arr_list[++$arr_index] = $arr_map;
-
- }else{
-
- // save normal variables and arrays differently...
- if($arr_index >= 0){
- $arr_list[$arr_index][$ARR_LIST][$matches[1]] = $matches[2];
- }else{
- $ret_list[$matches[1]] = $matches[2];
- }//if/else
-
- }//if/else
-
- }else{
-
- // save the current array to the return list...
- if(mb_stripos($line,')') !== false){
-
- if($arr_index >= 0){
-
- $arr_map = array_pop($arr_list);
-
- // if there is more than one array then this array belongs to the earlier array...
- if($arr_index > 0){
- $arr_list[($arr_index-1)][$ARR_LIST][$arr_map[$ARR_NAME]] = $arr_map[$ARR_LIST];
- }else{
- $ret_list[$arr_map[$ARR_NAME]] = $arr_map[$ARR_LIST];
- }//if/else
-
- $arr_index--;
-
- }//if
-
- }//if
-
- }//if/else
-
- }//foreach
-
- $ret_map['name'] = $ret_name;
- $ret_map['variables'] = $ret_list;
- return $ret_map;
- }//method
-
- //fonction d'affichage de variable php en Javascript
- function php2js($var){
- if (is_array($var)){
- $res = "[";
- $array = array();
- foreach ($var as $a_var){
- $array[] = Debug::php2js($a_var);
- }
- return "[" . join(",", $array) . "]";
- }
- elseif (is_bool($var)){
- return $var ? "true" : "false";
- }
- elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)){
- return $var;
- }
- elseif (is_string($var)){
- return "\"".addslashes(stripslashes($var))."\"";
- }
- // autres cas: objets, on ne les g?re pas
- return false;
- }
- ?>