|
@@ -15,7 +15,7 @@ function app_autoloader($class_name) {
|
|
|
}
|
|
|
}
|
|
|
function errorToException( $errno, $errstr, $errfile, $errline, $errcontext) {
|
|
|
- throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
|
|
+ throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
|
|
}
|
|
|
|
|
|
function unhandledException($ex){
|
|
@@ -23,7 +23,7 @@ function unhandledException($ex){
|
|
|
$source = 'ui';
|
|
|
if(isset($_SERVER['SCRIPT_NAME']) && $_SERVER['SCRIPT_NAME'] == '/action.php') $source = 'action';
|
|
|
if(php_sapi_name()=='cli') $source = 'shell';
|
|
|
-
|
|
|
+
|
|
|
$error = array();
|
|
|
$error['code'] = $ex->getCode();
|
|
|
$error['message'] = $ex->getMessage();
|
|
@@ -49,13 +49,11 @@ function unhandledException($ex){
|
|
|
echo '<br> Pour vous connecter, cliquez sur le menu "Connexion" en haut à droite de cet écran';
|
|
|
echo '</span></div>';
|
|
|
break;
|
|
|
- default:
|
|
|
- $response = '<div "id="message" class="d-block alert alert-danger m-3">';
|
|
|
+ default:
|
|
|
+ $response = '<div "id="message" class="d-block alert alert-danger m-3">';
|
|
|
$response .= '<a style="color:inherit;text-decoration:none;" class="d-block" href="'.$debugLink.'">';
|
|
|
-
|
|
|
-
|
|
|
if($advanced && isset($_['action'])) $response .= '<strong>Action : </strong><span>'.$_['action'].'</span><br>';
|
|
|
-
|
|
|
+
|
|
|
$response .= '<strong>Erreur : </strong><span>'.$error['message'].'</span>';
|
|
|
$response .= '</a>';
|
|
|
if($advanced){
|
|
@@ -132,7 +130,7 @@ function exception_link($ex,$type = 'exception'){
|
|
|
'arguments'=>$filePath.'":'.$line
|
|
|
)
|
|
|
)
|
|
|
- );
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
function exception_trace($ex){
|
|
@@ -162,7 +160,7 @@ function ip(){
|
|
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
elseif(isset($_SERVER['HTTP_CLIENT_IP']))
|
|
|
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
|
|
- else
|
|
|
+ else
|
|
|
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] :'';
|
|
|
return $ip;
|
|
|
}
|
|
@@ -222,8 +220,8 @@ function slugify($text,$allowChars = '', $separator='-') {
|
|
|
setlocale(LC_CTYPE, 'fr_FR.UTF-8');
|
|
|
try{
|
|
|
$encoding = mb_detect_encoding($text, mb_detect_order(), false);
|
|
|
- if($encoding == "UTF-8") $text = mb_convert_encoding($text, 'UTF-8', 'UTF-8');
|
|
|
-
|
|
|
+ if($encoding == "UTF-8") $text = mb_convert_encoding($text, 'UTF-8', 'UTF-8');
|
|
|
+
|
|
|
$clean = iconv(mb_detect_encoding($text, mb_detect_order(), false), 'ASCII//TRANSLIT', $text);
|
|
|
}catch(Exception $e){
|
|
|
$clean = $text;
|
|
@@ -238,7 +236,7 @@ function slugify($text,$allowChars = '', $separator='-') {
|
|
|
}
|
|
|
|
|
|
if(!function_exists('glob_recursive')) {
|
|
|
- // Does not support flag GLOB_BRACE
|
|
|
+ // Does not support flag GLOB_BRACE
|
|
|
function glob_recursive($pattern, $flags = 0,$forbiddenPathes = array(),$root = null){
|
|
|
$files = glob($pattern, $flags);
|
|
|
foreach (glob(dirname($pattern).SLASH.'*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
|
|
@@ -273,11 +271,11 @@ if(!function_exists('array_key_first')) {
|
|
|
function array_flatten($array) {
|
|
|
$return = array();
|
|
|
foreach($array as $key => $value) {
|
|
|
- if(is_array($value)){
|
|
|
+ if(is_array($value)){
|
|
|
$return = array_merge($return, array_flatten($value));
|
|
|
} else {
|
|
|
$return[$key] = $value;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
return $return;
|
|
|
}
|
|
@@ -325,11 +323,11 @@ function secure_user_vars($var){
|
|
|
}
|
|
|
|
|
|
function base64_to_image($base64_string, $output_file) {
|
|
|
- $ifp = fopen($output_file, "wb");
|
|
|
+ $ifp = fopen($output_file, "wb");
|
|
|
$data = explode(',', $base64_string);
|
|
|
- fwrite($ifp, base64_decode($data[1]));
|
|
|
- fclose($ifp);
|
|
|
- return $output_file;
|
|
|
+ fwrite($ifp, base64_decode($data[1]));
|
|
|
+ fclose($ifp);
|
|
|
+ return $output_file;
|
|
|
}
|
|
|
|
|
|
function getExt($file){
|
|
@@ -350,7 +348,7 @@ function getExtIcon($ext){
|
|
|
case 'zip':
|
|
|
$icon = 'far fa-file-archive text-warning';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'php':
|
|
|
case 'js':
|
|
|
case 'py':
|
|
@@ -365,14 +363,14 @@ function getExtIcon($ext){
|
|
|
case 'jsp':
|
|
|
$icon = 'fas fa-file-code text-secondary text-warning';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'xls':
|
|
|
case 'xlsx':
|
|
|
case 'xlsb':
|
|
|
case 'csv':
|
|
|
$icon = 'far fa-file-excel text-success';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'bmp':
|
|
|
case 'jpg':
|
|
|
case 'jfif':
|
|
@@ -383,7 +381,7 @@ function getExtIcon($ext){
|
|
|
case 'svg':
|
|
|
$icon = 'far fa-file-image text-info';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'pdf':
|
|
|
$icon = 'far fa-file-pdf text-danger';
|
|
|
break;
|
|
@@ -391,19 +389,19 @@ function getExtIcon($ext){
|
|
|
case 'pptx':
|
|
|
$icon = 'fa-file-powerpoint-o text-warning' ;
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'txt':
|
|
|
case 'htaccess':
|
|
|
case 'md':
|
|
|
$icon = 'far fa-file-alt';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'doc':
|
|
|
case 'docx':
|
|
|
case 'word':
|
|
|
$icon = 'far fa-file-word text-primary';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'avi':
|
|
|
case 'wmv':
|
|
|
case 'mov':
|
|
@@ -417,7 +415,7 @@ function getExtIcon($ext){
|
|
|
case 'mp4':
|
|
|
$icon = 'far fa-file-video text-secondary';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'wav':
|
|
|
case 'ogg':
|
|
|
case 'ogv':
|
|
@@ -485,7 +483,7 @@ function getExtContentType($ext){
|
|
|
case 'txt':
|
|
|
$cType = 'text/plain';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'doc':
|
|
|
case 'word':
|
|
|
$cType = 'application/msword';
|
|
@@ -493,7 +491,7 @@ function getExtContentType($ext){
|
|
|
case 'docx':
|
|
|
$cType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case 'aac':
|
|
|
case 'wav':
|
|
|
$cType = 'audio/'.$ext;
|
|
@@ -590,7 +588,7 @@ function arand($array){
|
|
|
return $array[array_rand($array)];
|
|
|
}
|
|
|
|
|
|
-//Convertis une date en timestamp
|
|
|
+//Convertis une date en timestamp
|
|
|
//(format possible dd-mm-yyyy ou dd/mm/yyyy)
|
|
|
function timestamp_date($date){
|
|
|
$date = explode('/',str_replace('-', '/', $date));
|
|
@@ -621,16 +619,16 @@ function timestamp_hour($hour){
|
|
|
function format_date_diff($date1, $date2, $format='%a'){
|
|
|
$datetime1 = date_create($date1);
|
|
|
$datetime2 = date_create($date2);
|
|
|
-
|
|
|
+
|
|
|
$interval = $datetime1->diff($datetime2);
|
|
|
-
|
|
|
+
|
|
|
return $interval->format($format);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Normalise un tableau de filtres pour le composant Filter
|
|
|
- *
|
|
|
+ *
|
|
|
* $filters : Array => tableau des paramètres avancés au format
|
|
|
* array(
|
|
|
* "jean", //Mot clé de la recherche simple
|
|
@@ -685,7 +683,7 @@ function filters_default($filters){
|
|
|
/**
|
|
|
* Normalise et contrôles sur un tableau
|
|
|
* de filtres pour le composant Filter.
|
|
|
- *
|
|
|
+ *
|
|
|
* $filters : Array => tableau des paramètres avancés au format
|
|
|
* array(
|
|
|
* "jean", //Mot clé de la recherche simple, peut aussi être nommée 'keyword' => "jean"
|
|
@@ -727,15 +725,15 @@ function filters_set($filters){
|
|
|
}
|
|
|
|
|
|
if(!isset($filter['column']) || !isset($filter['value'])) continue;
|
|
|
-
|
|
|
+
|
|
|
$filter['operator'] = isset($filter['operator']) ? $filter['operator'] : '=';
|
|
|
$filter['operator'] = html_entity_decode($filter['operator']);
|
|
|
if(!in_array(strtolower($filter['operator']), array('<','>','=','!=','like','not like','between','is null','is not null'))) continue;
|
|
|
|
|
|
$tempFilter = array(
|
|
|
- "c" => $filter['column'],
|
|
|
- "o" => $filter['operator'],
|
|
|
- "v" => is_array($filter['value']) ? $filter['value'] : array($filter['value']),
|
|
|
+ "c" => $filter['column'],
|
|
|
+ "o" => $filter['operator'],
|
|
|
+ "v" => is_array($filter['value']) ? $filter['value'] : array($filter['value']),
|
|
|
);
|
|
|
if(isset($filter['subcolumn'])) $tempFilter['s'] = $filter['subcolumn'];
|
|
|
|
|
@@ -782,7 +780,7 @@ function filter_alteration($filters,$index,$mutator){
|
|
|
// Construit une requete sécurisée pour le composant filtre
|
|
|
function filter_secure_query($filters,$allowedColumns,&$query,&$data,$iteration = 0,$columnEscape="`"){
|
|
|
if($iteration==0 && !empty($filters)) $query .= ' AND (';
|
|
|
-
|
|
|
+
|
|
|
|
|
|
global $databases_credentials;
|
|
|
$connector = $databases_credentials['local']['connector'];
|
|
@@ -801,7 +799,7 @@ function filter_secure_query($filters,$allowedColumns,&$query,&$data,$iteration
|
|
|
if(isset($filter['join']) && !in_array(strtolower($filter['join']), array('and','or'))) return;
|
|
|
if(!preg_match("/.*\..*/i", $filter['column']))
|
|
|
$filter['column'] = $columnEscape.$filter['column'].$columnEscape;
|
|
|
-
|
|
|
+
|
|
|
if(strtolower($filter['type']) == 'date' && isset($filter['value'])){
|
|
|
$filter['column'] = 'UNIX_TIMESTAMP(STR_TO_DATE(DATE_FORMAT(FROM_UNIXTIME('.$filter['column'].'),"%d/%m/%Y"), "%d/%m/%Y"))';
|
|
|
if(is_array($filter['value'])){
|
|
@@ -825,7 +823,7 @@ function filter_secure_query($filters,$allowedColumns,&$query,&$data,$iteration
|
|
|
$query.=' ( ';
|
|
|
$method($filter['column'],isset($filter['value'])?$filter['value']:null,$query,$data);
|
|
|
$query.=' ) ';
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
if(isset($filter['join'])) $query .= ' '.$filter['join'].' ';
|
|
|
}
|
|
@@ -972,7 +970,7 @@ function mb_ucfirst($string,$encoding = 'UTF-8'){
|
|
|
return mb_strtoupper($firstChar, $encoding).$rest;
|
|
|
}
|
|
|
|
|
|
-// Permet de mettre au bon format le n° de
|
|
|
+// Permet de mettre au bon format le n° de
|
|
|
// téléphone fourni dans le formulaire
|
|
|
function normalize_phone_number($number){
|
|
|
$nb = str_replace(array(' ', '.', ',', '-'), '', $number);
|
|
@@ -1014,7 +1012,7 @@ function utf8_to_extended_ascii($str, &$map) {
|
|
|
$matches = array();
|
|
|
if (!preg_match_all('/[\xC0-\xF7][\x80-\xBF]+/', $str, $matches))
|
|
|
return $str; // plain ascii string
|
|
|
-
|
|
|
+
|
|
|
// update the encoding map with the characters not already met
|
|
|
foreach ($matches[0] as $mbc)
|
|
|
if (!isset($map[$mbc]))
|
|
@@ -1034,8 +1032,8 @@ function levenshtein_utf8($s1, $s2) {
|
|
|
return levenshtein($s1, $s2);
|
|
|
}
|
|
|
|
|
|
-// Méthode qui retourne sous forme de tableau
|
|
|
-// les metaphones // des différents mots d'une
|
|
|
+// Méthode qui retourne sous forme de tableau
|
|
|
+// les metaphones // des différents mots d'une
|
|
|
// phrase.
|
|
|
function get_metaphones($sentence) {
|
|
|
$metaphones = array();
|
|
@@ -1082,7 +1080,7 @@ function numbers_to_letters($num){
|
|
|
$num = intval(($num - $p) / 26);
|
|
|
$letter = chr(65 + $p) . $letter;
|
|
|
}
|
|
|
- return $letter;
|
|
|
+ return $letter;
|
|
|
}
|
|
|
//Convertit lettres en nombres (utile pour Excel)
|
|
|
function letters_to_numbers($col){
|
|
@@ -1102,7 +1100,7 @@ function is_date($date){
|
|
|
$date = str_replace(array('-',' ','\\'),'/',trim($date));
|
|
|
if(trim($date)=='') return false;
|
|
|
if (count(explode('/',$date)) < 3) return false;
|
|
|
- list($d,$m,$y) = explode('/',$date);
|
|
|
+ list($d,$m,$y) = explode('/',$date);
|
|
|
if( !is_numeric($d) || !is_numeric($m) || !is_numeric($y) ) return false;
|
|
|
return checkdate ( $m , $d , $y );
|
|
|
}
|
|
@@ -1121,13 +1119,13 @@ function strpos_array($haystack, $needles=array(), $offset=0) {
|
|
|
}
|
|
|
|
|
|
//Supprime un dossier et son contenu
|
|
|
-//de manière récursive
|
|
|
-function delete_folder_tree($dir, $selfDestroy=false) {
|
|
|
+//de manière récursive
|
|
|
+function delete_folder_tree($dir, $selfDestroy=false) {
|
|
|
if(!file_exists($dir)) return;
|
|
|
- $files = array_diff(scandir($dir), array('.','..'));
|
|
|
- foreach ($files as $file)
|
|
|
- (is_dir("$dir/$file")) ? delete_folder_tree("$dir/$file") : unlink("$dir/$file");
|
|
|
- if($selfDestroy) return rmdir($dir);
|
|
|
+ $files = array_diff(scandir($dir), array('.','..'));
|
|
|
+ foreach ($files as $file)
|
|
|
+ (is_dir("$dir/$file")) ? delete_folder_tree("$dir/$file") : unlink("$dir/$file");
|
|
|
+ if($selfDestroy) return rmdir($dir);
|
|
|
}
|
|
|
|
|
|
//Normalise les caractères un peu spéciaux
|
|
@@ -1137,8 +1135,8 @@ function normalize_chars($string, $mask=array()) {
|
|
|
'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
|
|
|
'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
|
|
|
'Ï'=>'I', 'Ñ'=>'N', 'Ń'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
|
|
|
- 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a',
|
|
|
- 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i',
|
|
|
+ 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a',
|
|
|
+ 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i',
|
|
|
'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ń'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o',
|
|
|
'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ü'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f',
|
|
|
'ă'=>'a', 'î'=>'i', 'â'=>'a', 'ș'=>'s', 'ț'=>'t', 'Ă'=>'A', 'Î'=>'I', 'Â'=>'A', 'Ș'=>'S', 'Ț'=>'T',
|
|
@@ -1194,7 +1192,7 @@ function number_to_words($number, $feminine=false) {
|
|
|
|
|
|
if (!is_numeric($number)) return false;
|
|
|
if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) throw new Exception('number_to_words accepte uniquement des nombres compris entre -'.PHP_INT_MAX.' et '.PHP_INT_MAX);
|
|
|
-
|
|
|
+
|
|
|
if ($number < 0) return $negative.number_to_words(abs($number));
|
|
|
|
|
|
$string = $fraction = null;
|
|
@@ -1208,28 +1206,28 @@ function number_to_words($number, $feminine=false) {
|
|
|
break;
|
|
|
case $number == 21:
|
|
|
$string = $dictionary[20].$conjunction.$dictionary[1];
|
|
|
- break;
|
|
|
+ break;
|
|
|
case $number == 31:
|
|
|
$string = $dictionary[30].$conjunction.$dictionary[1];
|
|
|
- break;
|
|
|
+ break;
|
|
|
case $number == 41:
|
|
|
$string = $dictionary[40].$conjunction.$dictionary[1];
|
|
|
- break;
|
|
|
+ break;
|
|
|
case $number == 51:
|
|
|
$string = $dictionary[50].$conjunction.$dictionary[1];
|
|
|
- break;
|
|
|
+ break;
|
|
|
case $number == 61:
|
|
|
$string = $dictionary[60].$conjunction.$dictionary[1];
|
|
|
- break;
|
|
|
+ break;
|
|
|
case $number == 71:
|
|
|
$string = $dictionary[60].$conjunction.$dictionary[11];
|
|
|
- break;
|
|
|
+ break;
|
|
|
case $number == 81:
|
|
|
$string = $dictionary[80].$hyphen.$dictionary[1];
|
|
|
- break;
|
|
|
+ break;
|
|
|
case $number == 91:
|
|
|
$string = $dictionary[80].$hyphen.$dictionary[11];
|
|
|
- break;
|
|
|
+ break;
|
|
|
case $number < 100:
|
|
|
$tens = ((int) ($number / 10)) * 10;
|
|
|
$units = $number % 10;
|
|
@@ -1275,8 +1273,8 @@ function number_to_words($number, $feminine=false) {
|
|
|
/**
|
|
|
* Retrourne le numéral ordinal compact
|
|
|
* d'un nombre passé en paramètre.
|
|
|
- * eg:
|
|
|
- * 1 --> 1er,
|
|
|
+ * eg:
|
|
|
+ * 1 --> 1er,
|
|
|
* 2 --> 2ème, etc..
|
|
|
* Les nombres ordinaux sont définis par un
|
|
|
* l'ensemble des entiers naturels non nuls
|
|
@@ -1287,7 +1285,7 @@ function number_to_ordinal($number, $feminine=false){
|
|
|
//Aucun ordinal pour le rang 0
|
|
|
if($number == 0) return;
|
|
|
|
|
|
- if($number == 1)
|
|
|
+ if($number == 1)
|
|
|
return $number.($feminine?'ère':'er');
|
|
|
return $number.'ème';
|
|
|
}
|
|
@@ -1340,7 +1338,7 @@ function forbidden_macro($source){
|
|
|
);
|
|
|
|
|
|
foreach($tokens as $token){
|
|
|
- if(is_string($token)) continue;
|
|
|
+ if(is_string($token)) continue;
|
|
|
list($id, $text,$line) = $token;
|
|
|
|
|
|
if(in_array($id, array(T_FUNCTION,T_FUNC_C,T_EVAL,T_STRING))){
|
|
@@ -1377,7 +1375,7 @@ function forbidden_macro($source){
|
|
|
//Fonction respectant la syntaxe mustache (prototype a roder)
|
|
|
function mustache_template($stream,$data){
|
|
|
//blocks (loop, if, else)
|
|
|
-
|
|
|
+
|
|
|
$stream = preg_replace_callback('/\{\{(#|\^)?([^\}]*)\}\}(.*?)\{\{\/\2\}\}/is',function($matches) use ($data) {
|
|
|
$stream = '';
|
|
|
$expression = $matches[0];
|
|
@@ -1400,7 +1398,7 @@ function mustache_template($stream,$data){
|
|
|
// syntaxe : {{;}}mon texte partout sauf derniere occurence{{/;}}
|
|
|
$lastOccurenceReplace = $i!=$length-1 ? '$1' : '';
|
|
|
$lineTemplate = preg_replace('/\{\{;\}\}(.*)\{\{\/;\}\}/isU', $lastOccurenceReplace, $template);
|
|
|
-
|
|
|
+
|
|
|
$localData = is_array($value2) ? array_merge($data,$value2) : $data;
|
|
|
$stream.= mustache_template($lineTemplate,$localData);
|
|
|
$i++;
|
|
@@ -1418,7 +1416,7 @@ function mustache_template($stream,$data){
|
|
|
}else if($matches[1] == '^'){
|
|
|
if(!$value) return mustache_template($template,$data);
|
|
|
return '';
|
|
|
-
|
|
|
+
|
|
|
//cas de block non gérés car sans char operateur # ou ^ ex : {{expression}}{{/expression}}
|
|
|
}else{
|
|
|
$stream = $expression;
|
|
@@ -1489,18 +1487,18 @@ function template($stream,$data,$mustacheTemplate = false){
|
|
|
$value = $current;
|
|
|
}
|
|
|
return $value;
|
|
|
- },$stream);
|
|
|
-
|
|
|
+ },$stream);
|
|
|
+
|
|
|
return $stream;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Auteur: Anonymous
|
|
|
* Lien: https://www.php.net/manual/en/features.file-upload.post-method.php#120686
|
|
|
- *
|
|
|
+ *
|
|
|
* Normalise le tableau de fichier récupérés
|
|
|
* pour une utilisation plus efficace et intuitive
|
|
|
- *
|
|
|
+ *
|
|
|
* Exemple de format initial pour 2 fichiers dans $_FILES :
|
|
|
* Array (
|
|
|
[name] => Array (
|
|
@@ -1524,7 +1522,7 @@ function template($stream,$data,$mustacheTemplate = false){
|
|
|
[1] => 456
|
|
|
)
|
|
|
* )
|
|
|
- *
|
|
|
+ *
|
|
|
* Exemple de format de retour pour 2 fichiers :
|
|
|
* Array(
|
|
|
[0] => Array(
|
|
@@ -1550,14 +1548,14 @@ function normalize_php_files() {
|
|
|
foreach ($files as $key => $value) {
|
|
|
$temp = $path;
|
|
|
$temp[] = $key;
|
|
|
-
|
|
|
+
|
|
|
if(is_array($value)) {
|
|
|
$fixedFiles = $function($value, $fixedFiles, $temp);
|
|
|
} else {
|
|
|
$next = array_splice($temp, 1, 1);
|
|
|
$temp = array_merge($temp, $next);
|
|
|
$new = &$fixedFiles;
|
|
|
-
|
|
|
+
|
|
|
foreach ($temp as $key)
|
|
|
$new = &$new[$key];
|
|
|
|
|
@@ -1583,7 +1581,7 @@ function autoincrement_filename($extension, $folder, $filename){
|
|
|
|
|
|
$fileNb = count(glob(FILE_PATH.$folder.$filename));
|
|
|
$filenameProps = explode('.', $filename);
|
|
|
-
|
|
|
+
|
|
|
unset($filenameProps[count($filenameProps)-1]);
|
|
|
$finalFilename = implode('.', $filenameProps);
|
|
|
|
|
@@ -1605,7 +1603,7 @@ function relative_path($absolutePath,$reference = __ROOT__){
|
|
|
//ou sombre en fonction d'un seuil de luminosité
|
|
|
function get_light($hexcode,$treshold = 510.0) {
|
|
|
$rgb = to_rgb($hexcode);
|
|
|
- return (max($rgb[0], $rgb[1], $rgb[2]) + min($rgb[0], $rgb[1], $rgb[2])) / $treshold;
|
|
|
+ return (max($rgb[0], $rgb[1], $rgb[2]) + min($rgb[0], $rgb[1], $rgb[2])) / $treshold;
|
|
|
}
|
|
|
|
|
|
//Génère une couleur hexadécimale aléatoire
|
|
@@ -1613,7 +1611,7 @@ function random_hex_color() {
|
|
|
return '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
|
|
|
}
|
|
|
|
|
|
-//Génère une couleur pastel basé sur
|
|
|
+//Génère une couleur pastel basé sur
|
|
|
//le hash md5 du mot passé en paramètre
|
|
|
function random_hex_pastel_color($name) {
|
|
|
$hash = md5($name);
|
|
@@ -1630,10 +1628,10 @@ function random_hex_pastel_color($name) {
|
|
|
|
|
|
//Convertit un code hexadecimal en code RGB
|
|
|
function to_rgb($hexcode) {
|
|
|
- $hexcode = substr($hexcode, 1);
|
|
|
+ $hexcode = substr($hexcode, 1);
|
|
|
return array(hexdec($hexcode[0] . $hexcode[1]),
|
|
|
hexdec($hexcode[2] . $hexcode[3]),
|
|
|
- hexdec($hexcode[4] . $hexcode[5]));
|
|
|
+ hexdec($hexcode[4] . $hexcode[5]));
|
|
|
}
|
|
|
|
|
|
//Retourne le nom complet d'un mois en fonction de son numéro
|
|
@@ -1648,7 +1646,7 @@ function day_name($day){
|
|
|
return isset($translates[$day-1])? $translates[$day-1]:$day;
|
|
|
}
|
|
|
|
|
|
-//Convertit un timestamp dans un format
|
|
|
+//Convertit un timestamp dans un format
|
|
|
//agréable et complet : ex Mardi 18 Avril 2019
|
|
|
function complete_date($time=null){
|
|
|
if(!isset($time)) $time = time();
|
|
@@ -1687,7 +1685,7 @@ function get_not_workable($date=null){
|
|
|
return $holidays;
|
|
|
}
|
|
|
|
|
|
-//Retourne le chemin web d'un fichier en fonction de son chemin
|
|
|
+//Retourne le chemin web d'un fichier en fonction de son chemin
|
|
|
//physique (ex : /img/logo.png pour /var/www/erp-core/img/logo.png)
|
|
|
function webpath($path){
|
|
|
$url = ROOT_URL.str_replace(array(__DIR__.SLASH,"\\","/"),array('','/','/'),$path);
|
|
@@ -1702,7 +1700,7 @@ function array_not_unique($array=array()){
|
|
|
}
|
|
|
|
|
|
//Retourne true si aucune valeur du tableau passé
|
|
|
-//en paramètre a un doublon, false sinon.
|
|
|
+//en paramètre a un doublon, false sinon.
|
|
|
function is_array_unique($array=array()){
|
|
|
return empty(array_not_unique($array));
|
|
|
}
|
|
@@ -1794,9 +1792,9 @@ function mt_basename($path){
|
|
|
return end($nameSplit);
|
|
|
}
|
|
|
|
|
|
-//filtre les balises dangeureuses (script,link..) dans les contenus wysiwyg
|
|
|
+//filtre les balises dangeureuses (script,link..) dans les contenus wysiwyg
|
|
|
function wysiwyg_filter($html){
|
|
|
-
|
|
|
+
|
|
|
$html = preg_replace('#<(script|link)(.*?)>(.*?)</(script|link)>#is', '', $html);
|
|
|
$html = preg_replace('#<(script|link)([^>]*?)>#is', '', $html);
|
|
|
return $html;
|
|
@@ -1809,9 +1807,9 @@ function display_format_price($price) {
|
|
|
function unzip($zipPath,$destination,$options = array()){
|
|
|
$zip = new ZipArchive();
|
|
|
if(!$zip->open($zipPath)) throw new Exception("Impossible d'ouvrir l'archive");
|
|
|
- for( $u = 0; $u < $zip->numFiles; $u++ ){
|
|
|
+ for( $u = 0; $u < $zip->numFiles; $u++ ){
|
|
|
$infos = $zip->statIndex( $u );
|
|
|
-
|
|
|
+
|
|
|
//dossier
|
|
|
if(substr($infos['name'],-1,1)=='/'){
|
|
|
$infos['name'] = str_replace('..','.',$infos['name']);
|
|
@@ -1826,7 +1824,7 @@ function unzip($zipPath,$destination,$options = array()){
|
|
|
file_put_contents($destination.SLASH.$infos['name'], $zip->getFromName($infos['name']));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1870,7 +1868,7 @@ function value_encapsulate($value, $char = ',') {
|
|
|
/*
|
|
|
Donne le differentiel en heures/jours entre deux dates en prenant en compte les horaires ouvrés et de la pause déjeuner
|
|
|
$start : timestamp de début
|
|
|
- $end : timestamp de fin
|
|
|
+ $end : timestamp de fin
|
|
|
$openStartHour : heure ouvrée de début de journée
|
|
|
$openEndHour : heure ouvrée de fin de journée
|
|
|
$lunchHour : temps de pause déjeuner (en heure)
|
|
@@ -1878,7 +1876,7 @@ Donne le differentiel en heures/jours entre deux dates en prenant en compte les
|
|
|
/*
|
|
|
Donne le differentiel en heures/jours entre deux dates en prenant en compte les horaires ouvrés et de la pause déjeuner
|
|
|
$start : timestamp de début
|
|
|
-$end : timestamp de fin
|
|
|
+$end : timestamp de fin
|
|
|
$openStartHour : heure ouvrée de début de journée
|
|
|
$openEndHour : heure ouvrée de fin de journée
|
|
|
$lunchHour : temps de pause déjeuner (en heure)
|
|
@@ -1886,7 +1884,7 @@ $lunchHour : temps de pause déjeuner (en heure)
|
|
|
function date_workable_diff($start,$end,$openStartHour = 9,$openEndHour = 18,$lunchHour = 1){
|
|
|
$startTime = (new DateTime())->setTimestamp($start)->setTime(0,0,0);
|
|
|
$endTime = (new DateTime())->setTimestamp($end)->setTime(0,0,0);
|
|
|
-
|
|
|
+
|
|
|
$maxHours = $openEndHour - $openStartHour - $lunchHour;
|
|
|
|
|
|
$days = array();
|
|
@@ -1915,20 +1913,20 @@ function date_workable_diff($start,$end,$openStartHour = 9,$openEndHour = 18,$lu
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
$deltaHours = 0;
|
|
|
foreach($days as $day){
|
|
|
$hours = $day['end']->format('H') - $day['start']->format("H");
|
|
|
|
|
|
//On enleve $lunchHour de pause déjeuner (12h-13h) dans les cas ou le temps pietine sur la pause
|
|
|
- if( ($day['end']->format('H') < 13 && $day['end']->format('H') > 12) ||
|
|
|
- ($day['start']->format('H') < 13 && $day['start']->format('H') > 12) ||
|
|
|
+ if( ($day['end']->format('H') < 13 && $day['end']->format('H') > 12) ||
|
|
|
+ ($day['start']->format('H') < 13 && $day['start']->format('H') > 12) ||
|
|
|
($day['start']->format('H') <12 && $day['end']->format('H') > 13)
|
|
|
) $hours-= $lunchHour;
|
|
|
|
|
|
$deltaHours += $hours;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$deltaDays = round($deltaHours / $maxHours,2);
|
|
|
return array(
|
|
|
'hours' => $deltaHours,
|