Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
15.38% |
2 / 13 |
CRAP | |
21.95% |
18 / 82 |
| iaLib | |
0.00% |
0 / 1 |
|
15.38% |
2 / 13 |
1287.63 | |
21.95% |
18 / 82 |
| param | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 3 |
|||
| get_post_trim | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 10 |
|||
| get_request | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 1 |
|||
| get_request_raw | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 1 |
|||
| get_post_raw | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 1 |
|||
| constant2name | |
100.00% |
1 / 1 |
7 | |
100.00% |
9 / 9 |
|||
| exportTrimed | |
100.00% |
1 / 1 |
5 | |
100.00% |
9 / 9 |
|||
| logErrors | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 4 |
|||
| ls | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 10 |
|||
| redirect | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 15 |
|||
| is_ssl | |
0.00% |
0 / 1 |
72.00 | |
0.00% |
0 / 10 |
|||
| getLogIp | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 6 |
|||
| getCurrentWebPath | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| <?php | |
| namespace ia\Lib; | |
| use ia\Util\Str; | |
| use ia\Util; | |
| /** | |
| * @author Informática Asocaida SA de CV | |
| * @version 1.0.3 | |
| * @copyright 2017 | |
| */ | |
| /** | |
| * iaLib: Useful function for strings, numbers, milliseconds, xlsx | |
| * | |
| * @package ia | |
| * @author Raul Santos | |
| * @copyright 2015 | |
| * @version $Id$ | |
| */ | |
| class iaLib { | |
| ///////////////////////////////////// iaParameters? | |
| public static function param($key, $dflt='', $cleanNumber=false, $doStrim=true) { | |
| if($doStrim) { | |
| return isset($_REQUEST[$key]) ? Str::strim( $cleanNumber ? self::numberClean($_REQUEST[$key]) : $_REQUEST[$key]) : $dflt; | |
| } | |
| return isset($_REQUEST[$key]) ? trim( $cleanNumber ? self::numberClean($_REQUEST[$key]) : $_REQUEST[$key]) : $dflt; | |
| } | |
| public static function get_post_trim($key, $dflt='') { | |
| if(!isset($_POST[$key])) { | |
| return $dflt; | |
| } | |
| if(!is_array($_POST[$key])) { | |
| return Str::strim($_POST[$key]); | |
| } | |
| $ret=[]; | |
| foreach($_POST[$key] as $k=>$v) { | |
| if(is_array($v)) | |
| $ret[$k] = $v; | |
| else | |
| $ret[$k] = Str::strim($v); | |
| } | |
| return $ret; | |
| } | |
| public static function get_request($key, $dflt='') { | |
| return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $dflt; | |
| } | |
| public static function get_request_raw($key, $dflt='') { | |
| return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $dflt; | |
| } | |
| public static function get_post_raw($key, $dflt='') { | |
| return isset($_POST[$key]) ? $_POST[$key] : $dflt; | |
| } | |
| ///////////////////////////////////// | |
| //define('SD_SELECT_FILL_EXTENSION','html'); // definir extension txt ... | |
| // guarda el json que quedra el javascriptW | |
| //@TODO coordinated item guardar en db keys que regenerar? poner un regenarate all keys | |
| /* | |
| # DISABLE CACHING | |
| <IfModule mod_headers.c> | |
| Header set Cache-Control "no-Cache, no-store, must-revalidate" | |
| Header set Pragma "no-Cache" | |
| Header set Expires 0 | |
| </IfModule> | |
| */ | |
| /** | |
| * Returns the name of a php constant | |
| * | |
| * @param string $group | |
| * @param mixed $value string or number | |
| * @param string $tag | |
| * @return string | |
| */ | |
| public static function constant2name($group, $value, $tag='ERR') { | |
| static $constats; | |
| if(!isset($constants)) { | |
| $constants = get_defined_constants(true); | |
| } | |
| if(!isset($constants[$group])) { | |
| return "Unknown ($value)"; | |
| } | |
| foreach($constants[$group] as $c=>$n) { | |
| if( (empty($tag) || stripos($c,$tag)!==FALSE) && $n===$value) { | |
| return "$c ($value)"; | |
| } | |
| } | |
| return "Unknown ($value)"; | |
| } | |
| /** | |
| * Returns var_export($obj) as a one liner, no CR/LF | |
| * | |
| * @param mixed $obj | |
| * @return string returns var_export($obj) as a one liner, no CR/LF | |
| */ | |
| public static function exportTrimed($obj) { | |
| if($obj === null) | |
| return "null"; | |
| if($obj === '') | |
| return "''"; | |
| if($obj === true) | |
| return "true"; | |
| if($obj === false) | |
| return "false"; | |
| return Str::strim(str_replace(array("\r", "\n"), ' ', var_export($obj,true) )); | |
| } | |
| public static function logErrors($display=true) { | |
| global $gSqlClass,$gConfig; | |
| $rep = new iaErrorReporter($gSqlClass,$gConfig['mailErrorsTo'],false); | |
| $rep->process($display); | |
| } | |
| public static function ls($dir) { | |
| clearstatcache(); //@TODO (true, $dir); | |
| if(!is_dir($dir)) { | |
| return []; | |
| } | |
| $ret = []; | |
| if($dh = opendir($dir)){ | |
| while(($file = readdir($dh)) !== false) { | |
| if($file[0] != '.') { | |
| $ret[] = $file; | |
| } | |
| } | |
| closedir($dh); | |
| } | |
| return $ret; | |
| } | |
| public static function redirect($localPage, $params) { | |
| global $gConfig; | |
| $p = []; | |
| foreach($params as $key=>$v) { | |
| $p[] = $key . "=" . $v; //@TODO urlencode each | |
| } | |
| if(empty($p)) { | |
| $url = $localPage; | |
| } else { | |
| $url = $localPage."?".implode('&', $p); | |
| } | |
| $host = $_SERVER['HTTP_HOST']; | |
| $redirectTo = "https://".$_SERVER['HTTP_HOST'].$gConfig['WEB_ROOT']."/".$url; //@TODO https or http | |
| if(!headers_sent()) { | |
| header('Location: '.$redirectTo); | |
| } else { | |
| echo '<!DOCTYPE HTML><html lang="es-MX"><head><meta charset="utf-8"><title>Redireccionando</title> | |
| <meta http-equiv="refresh" content="0;url='.$redirectTo.'" /></head> | |
| <body><a href="'.$redirectTo.'">Redireccionando, paciencia!</a></body></html>'; | |
| } | |
| iaLib::logErrors(false); | |
| exit(); | |
| } | |
| public static function is_ssl() { | |
| if ( isset($_SERVER['HTTPS']) ) { | |
| if ( 'on' == strtolower($_SERVER['HTTPS']) ) | |
| return true; | |
| if ( '1' == $_SERVER['HTTPS'] ) | |
| return true; | |
| } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { | |
| return true; | |
| } | |
| if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO'])=='https') | |
| return true; | |
| return false; | |
| } | |
| public static function getLogIp() { | |
| $ip = []; | |
| $de = ["REMOTE_ADDR",'HTTP_X_FORWARDED_FOR',"HTTP_CLIENT_IP",'HTTP_X_CLUSTER_CLIENT_IP','HTTP_FORWARDED_FOR','HTTP_FORWARDED']; | |
| foreach($de as $key) { | |
| if(!empty($_SERVER[$key])) { | |
| $ip[] = "$key ".$_SERVER[$key]; | |
| } | |
| } | |
| return '<ul><li>'.implode("<li>", $ip).'</ul>'; | |
| } | |
| public static function getCurrentWebPath() { | |
| $path = explode('/', $_SERVER['SCRIPT_NAME']); | |
| array_pop($path); | |
| return implode('/', $path); | |
| } | |
| } |