$v) if(!in_array(trim($v), array("",")","("))) console_log($v, $recursive); // ChromePhp::groupEnd(); } else ChromePhp::table($var); } else{ $var = str_replace("\r\n", " ", $var);//firefox 58.0.2 non mostra il multilinea ChromePhp::_log("", array($var), $recursive+1); } } //funzione time globale richiamata nell' index1.1 function indi_time() { global $_indi_time; //la prima volta imposto var globale if(!$_indi_time) { $indi_time_tmp=microtime(); $_indi_time=substr($indi_time_tmp,11).substr($indi_time_tmp,1,9); return 0; } $time_tmp=microtime(); $time=substr($time_tmp,11).substr($time_tmp,1,9); $time_diff = substr($time-$_indi_time,0,6); return $time_diff; } //funzione memoria globale //funzione memoria globale function indi_memory() { global $_indi_memory; if(!$_indi_memory) { $_indi_memory=memory_get_usage(); return 0; } return (int) memory_get_usage() - $_indi_memory; } //funzione time function indi_debug_time($ref="debug") { global $PERFORMANCE; if(!$PERFORMANCE[$ref]['time']['start']) { $PERFORMANCE[$ref]['time']['start'] = indi_time(); //die(indi_time()); } else { $PERFORMANCE[$ref]['time']['lap'] = indi_time() - $PERFORMANCE[$ref]['time']['last']; $PERFORMANCE[$ref]['time']['last'] = indi_time() - $PERFORMANCE[$ref]['time']['start']; d_info($PERFORMANCE[$ref]['time']['last'],"performance indi_debug_time($ref)"); return (float) $PERFORMANCE[$ref]['time']['last']; } return NULL; } //funzione time function indi_debug_memory($ref="debug") { global $PERFORMANCE; if(!$PERFORMANCE[$ref]['mem']['start']) $PERFORMANCE[$ref]['mem']['start'] = indi_memory(); else { $PERFORMANCE[$ref]['mem']['lap'] = indi_memory() - $PERFORMANCE[$ref]['mem']['last']; $PERFORMANCE[$ref]['mem']['last'] = indi_memory() - $PERFORMANCE[$ref]['mem']['start']; d_info($PERFORMANCE[$ref]['mem']['last'],"performance indi_debug_memory($ref)"); return (int) $PERFORMANCE[$ref]['mem']['last']; } return NULL; } //funzione time function indi_debug_performance($ref="debug") { $time = indi_debug_time($ref); $memory = indi_debug_memory($ref); if($time or $memory) return array('time' => $time,'memory' => $memory); } //FUNZIONE GENERICA DI DEBUG CHE MANDA ANCHE UNA MAIL ALL' INDIRIZZO GIUSTO, e salva nei log function indi_debug($ARR=NULL,$email=null) { //usata solo su alcuni vecchi siti quando scatta controlli FORM_ANTISPAM (viene chiamata se non supera il controllo) //9/11/2023 $plainText = ["http".(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 's' : '')."://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']]; $debugBacktrace = debug_backtrace(); array_unshift($debugBacktrace, array('file'=>__FILE__, 'line'=>__LINE__, 'function'=>'debugTnx')); foreach($debugBacktrace as $debugLine) $plainText[] = $debugLine['file'].":".$debugLine['line']." ".$debugLine['function']."()"; mailtnx("c@localhost", "Non in uso", __FILE__.":".__LINE__."\n".implode("\n", $plainText)."\n".print_r(array($_REQUEST, $_SERVER), true)); if(!is_array($ARR)){ $ARR2['messaggio'] = $ARR; if($email != "") $ARR2['to'] = $email; $ARR = $ARR2; } if($ARR['to'] == "") $ARR['to'] = $GLOBALS[DATI]['email_debug']; //statistiche $STAT = stat_dati_aggiuntivi(); //dati base $msg = "\n\n ############################################################################## \n BASE SERVER -------------------- - URL: $_SERVER[REQUEST_URI] - REF: $_SERVER[HTTP_REFERER] - TIM: ".strftime("%D - %T")." - UAG: $_SERVER[HTTP_USER_AGENT] - ADD: $_SERVER[REMOTE_ADDR] - LAN: $_SERVER[HTTP_ACCEPT_LANGUAGE] BASE INDI -------------------- - Pagina: $GLOBALS[pagina] - Lingua: $GLOBALS[lang] - Agg: $GLOBALS[agg] "; //compongo debug $msg .= indi_debug_array("_GET",$_GET); $msg .= indi_debug_array("_POST",$_POST); $msg .= indi_debug_array("_SESSION",$_SESSION); $msg .= indi_debug_array("_SERVER",$_SERVER); $msg .= indi_debug_array("_COOKIE",$_SERVER); $msg .= indi_debug_array("AUTH",$GLOBALS[AUTH]); //$msg .= indi_debug_array("DATI",$GLOBALS[DATI]); $oggetto = "[INDI] DEBUG - (".$GLOBALS[CONF][sito]." ".$GLOBALS[CONF][pagina].":".$GLOBALS[CONF][lang].") ".$ARR['oggetto']; mailtnx($ARR['to'],$oggetto,$ARR['messaggio'].$msg.$STAT); indi_log("indi_debug($ARR[to]) - $oggetto"); return TRUE; } //DEPRECATA, funzione debug campix forza l'indirizzo che si vole function indi_debug_email($achi = NULL, $oggetto = NULL, $messaggio = ""){ if(!$achi) $achi = $GLOBALS["DATI"]["email_debug"]; if(!$oggetto) $oggetto = " - ".$GLOBALS[CONF][sito].":".$GLOBALS[CONF][pagina]." -> (".$GLOBALS[CONF][baseurl].")"; if(strpos($achi, "@") === false || strpos($achi, " ") !== false){ indi_debug_email($GLOBALS['_dev_email'], "[INDI] DEBUG".$oggetto, 'Questo sito non ha $GLOBALS[DATI][email_debug] oppure la funzione indi_debug_email viene chiamata con il testo errore come primo parametro'); $achi = $GLOBALS['_dev_email']; } $mydata = array('$_GET'=>$_GET, '$_POST'=>$_POST, '$_SESSION'=>$_SESSION, '$_SERVER'=>$_SERVER); $messaggio = print_r($messaggio, true); $messaggio .= "\nhttp://$_SERVER[SERVER_NAME]$_SERVER[REQUEST_URI]"; foreach($mydata as $name=>$d){ $messaggio .= "\n\n*".$name."*:\n".var_export($d, true); } $messaggio .= stat_dati_aggiuntivi(); indi_log("indi_debug_email($achi) - $oggetto",$messaggio); mailtnx($achi, $oggetto, $messaggio); } //per vis array (usata anche in visualizzazione) function indi_debug_array($nome,$ARRA,$cspazio=0) { if($cspazio) for($cc=0; $cc<$cspazio; $cc++) $spazio .= " "; $cspazio++; $ARRAY = $ARRA; @reset($ARRAY); if(count($ARRAY) > 0) { if(cspazio <= 1) $msg .= "\n\n$spazio --------------------- $nome ---------------------\n\n"; while(list($k, $v)=@each($ARRAY)) { $s = (strlen($k)); $tab = "\t=>\t"; if($s < 22) $tab = "\t=>\t"; if($s < 14) $tab = "\t\t=>\t"; if($s < 6) $tab = "\t\t\t=>\t"; $msg .= $spazio."[$k]".$tab."[".print_r($v, true)."]\n"; if(is_array($v)) $msg .= indi_debug_array($k,$v,$cspazio); } @reset($ARRAY); $msg .= "\n$spazio --------------------------------------------------\n\n"; } return $msg; } //per vis query function indi_debug_query($query, $tableFeatures="") { if(1==1) {?> \n\n"; $table .= "\n\n"; $noFields = mysql_tnx_num_fields($result); $table .= "\n"; for ($i = 0; $i < $noFields; $i++) { $field = mysql_tnx_field_name($result, $i); $table .= "\t\n"; } while ($r = mysql_tnx_fetch_row($result)) { $class_tr = $nr++ % 2 ? "colore1" : "colore2"; $table .= "\n"; foreach ($r as $column) { if($column == "") $column = ""; $table .= "\t\n"; } $table .= "\n"; } $table .= "\n\n"; $table .= "
$field
".$column."
Righe del risultato: ".mysql_tnx_num_rows($result)."
\n\n"; $table .= "\n\n"; return encode($table); } function obj2xml($v, $indent='') { indi_debug_email(NULL, "obj2xml", 'obj2xml'); while (list($key, $val) = each($v)) { if ($key == '__attr') continue; // Check for __attr if (is_object($val->__attr)) { while (list($key2, $val2) = each($val->__attr)) { $attr .= " $key2=\"$val2\""; } } else $attr = ''; if (is_array($val) || is_object($val)) { print("$indent<$key$attr>\n"); obj2xml($val, $indent.' '); print("$indent\n"); } else print("$indent<$key$attr>$val\n"); } } //debug online function d_online($D) { $GLOBALS['CONF']['force_no_redirect'] = "SI"; print indi_var_dump($D); } //Logg e debugga function d_log($val,$nome=NULL) { d_err("DA FARE"); } //debug info non indispensabili function d_info($D,$nome=NULL,$gruppo=NULL) { d_main($D,$nome,"inf",$gruppo); return $D; } //debug errori function d_err($D,$nome=NULL,$gruppo=NULL) { d_main($D,$nome,"err",$gruppo); if($gruppo == "") $gruppo = $GLOBALS["CONF"]["debug_gruppo_def"]; if($nome == "") $nome = "E_USER_WARNING"; //prendo solo gli errori se sono in locale e li setto come errori php //sopprimo i redirect //$GLOBALS['CONF']['force_no_redirect'] = "SI"; trigger_error(serialize(array("errore"=>$D,"nome"=>$nome,"gruppo"=>$gruppo)), E_USER_WARNING); return $D; } //debug standard function d($D,$nome=NULL,$gruppo=NULL) { d_main($D,$nome,"dbg",$gruppo); return $D; } //funzione principale di debug non usare direttamente function d_main($D,$nome=NULL,$tipo=NULL,$gruppo=NULL) { global $CONF, $DATI, $DEBUG, $time_diff, $lastDebugCallTime, $lastDebugMsg, $NO_INDI_RENDER; if ($NO_INDI_RENDER) return; //cecca per far scattare subito la cattura al primo click su debug da popup sadmin //e comunque salta le prime 10 righe, non capisco dove viene azzerato... if($_SESSION["amministrazioneIndi"] == "1" or $_REQUEST["amministrazioneIndi"] == "1" || is_array($CONF['indi_debug_pagina_lenta'])) { $CONF["DEBUG"] = "SI"; $GLOBALS["CONF"]["DEBUG"] = "SI"; } // if($lastDebugCallTime){ // $limit = 60*5; // $diff = time()-$lastDebugCallTime; // if($diff > $limit){ // trigger_error("Sono passati $diff secondi dalla chiamata di debug precedente ($lastDebugMsg <> $D)"); // } // } // $lastDebugCallTime = time(); // $lastDebugMsg = $D; //se sono in locale e sono nel sito e non nel core if($GLOBALS["CONF"]["DEBUG"] == "SI") { $indice = sizeof($DEBUG)+1; if($gruppo == "") $gruppo = $CONF["debug_gruppo_def"]; if($tipo == "") $tipo = $CONF["debug_tipo_def"]; $DEBUG[$indice]["vari"] = $D; $DEBUG[$indice]["nome"] = $nome; $DEBUG[$indice]["tipo"] = $tipo; //o livello, dbg? (per inserimento manuali nel sito con funzione d() per debug, info e err $DEBUG[$indice]["gruppo"] = $gruppo; //log, sito, cake, indi, database? $DEBUG[$indice]["contesto"] = $CONF["debug_contesto"]; //usato solo per dividere dall' amministrazione o no //tolti carlo, sostituiti con reali non formattati //$DEBUG[$indice][tempo] = indi_time(); //incrementale con il tempo del sito //$DEBUG[$indice][mem] = number_format(indi_memory()); $DEBUG[$indice]["tempo"] = microtime(true); //incrementale con il tempo del sito if (is_array($CONF['indi_debug_pagina_lenta'])) { $bt = debug_backtrace(); if ($indice > 1 && ($DEBUG[$indice]["tempo"] - $DEBUG[$indice-1]["tempo"] > 1)) { $DEBUG[$indice]["stack"] = $bt; $stack = ""; array_shift($bt); foreach($bt as $k=>$caller) { $stack .= "\n" . $caller['file'] . ":" . $caller['line']; } $DEBUG[$indice]["stack_info"] = $stack; } else { //valutare quale fa più comodo di livelo di stack trace ma non posso mettere tutto per velocità /* $caller = $bt[1]; if (substr($caller['file'], -11) == "/db.inc.php") $caller = $bt[2]; if (substr($caller['file'], -11) == "/db.inc.php") $caller = $bt[3]; */ $caller = $bt[sizeof($bt)-4]; $DEBUG[$indice]["stack_info"] = $caller['file'] . ":" . $caller['line']; } } else { $DEBUG[$indice]["mem"] = memory_get_usage(); $DEBUG[$indice]["stack"] = debug_backtrace(); } } return $D; } //funzione di visualizzazione che usa la funzione passata per fare quello che si vuole function d_vis($D,$f_vis="d_vis_default") { //cicolo il mio debug while(list($k,$v) = each($D)) { $f_vis($v); } } function d_vis_default($D) { global $DATI; //if($DATI[debug] == "SI") { //funzione di debug if(is_array($D[vari])) { print "
";
			print ("$D[tipo] : $D[nome] :");
			print_r($D[vari]);
			print "
"; } else { print ("$D[tipo] : $D[nome] : $D[vari]
"); } //} } function trova_var_array($target, $where = null, $exact = false){ if(is_object($target) || is_array($target)) die("non testato per cercare oggetti complessi"); if(!(is_array($where) || is_object($where))) $where = array($where); foreach($where as $nome=>$data){ if($nome == "GLOBALS") continue; if($trovato = trova_var_array($target, $data, $exact)){ $result[$nome] = $trovato; } else if(!$exact && ((strstr((string)$nome,(string)$target)!==false) || (strstr((string)$data,(string)$target)!==false))){//trovato nel nome o nel contenuto $result[$nome] = $data; } else if($exact && (($nome === $target) || ($data === $target))){//trovato nel nome o nel contenuto $result[$nome] = $data; } } return $result; } function trova_var($target, $where = null, $exact = false){ if($risultati = trova_var_array($target, $where?$where:$GLOBALS, $exact)){ echo '
Variabili '.(!$exact?"che contengono":"uguali a").' '.$target.':
'; echo html_r($risultati); echo '
'; } else{ echo '
Sembra che nessuna variabile definita '.(!$exact?"contenga":"sia uguale a").' '.$target.'
'; } echo '
RICORDA: se chiami trova_var() da dentro una funzione non posso cercare nelle varibili locali a meno che non chiami
trova_var("'.$target.'", get_defined_vars());
'; } ?>