| Current Path : /home/happyrenas/find.myreco.online/includes/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/happyrenas/find.myreco.online/includes/fonctions_email.php |
<?
function renderTemplate($tpl, array $vars){
// Remplace {$key} par la valeur
foreach ($vars as $k => $v){
$tpl = str_replace('{$'.$k.'}', (string)$v, $tpl);
}
return $tpl;
}
/* Helper escape (ezSQL) */
$esc = function($v) use ($db){
// ezSQL_mysqli a normalement escape()
return "'" . $db->escape($v) . "'";
};
/*********************************************************************
* SIGNATURE
*********************************************************************/
function make_sig($action, $action_token){
return hash_hmac('sha256', $action.'|'.$action_token, ACTION_SECRET);
}
function make_sig1($action_token){ return hash_hmac('sha256', 'accept|'.$action_token, ACTION_SECRET); }
function h($s){
return htmlspecialchars((string)$s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
function tpl_if_blocks($tpl, array $vars){
// supprime les blocs <!-- IF:key --> ... <!-- ENDIF:key --> si vide
foreach ($vars as $k => $v) {
$isEmpty = trim((string)$v) === '';
$pattern = '/<!--\s*IF:'.preg_quote($k,'/').'\s*-->(.*?)<!--\s*ENDIF:'.preg_quote($k,'/').'\s*-->/si';
if ($isEmpty) {
$tpl = preg_replace($pattern, '', $tpl);
} else {
// si non vide : on enlève juste les marqueurs IF/ENDIF
$tpl = preg_replace($pattern, '$1', $tpl);
}
}
return $tpl;
}
function tpl_vars($tpl, array $vars){
foreach ($vars as $k => $v){
$tpl = str_replace('{$'.$k.'}', (string)$v, $tpl);
}
// optionnel : nettoyer les variables non remplacées
// $tpl = preg_replace('/\{\$[a-zA-Z0-9_]+\}/', '', $tpl);
return $tpl;
}
function render_modele_html($modele_id, array $vars){
$path = __DIR__ . '/../matrice/modele_acceptation.html';
if (!is_file($path)) return [false, "Template introuvable ($path)"];
$tpl = file_get_contents($path);
if (!$tpl) return [false, "Template vide ($path)"];
$tpl = tpl_if_blocks($tpl, $vars);
$tpl = tpl_vars($tpl, $vars);
return [true, $tpl];
}
function render_modele($modele_id, array $vars){
$path = __DIR__ . '/../matrice/modele_acceptation.html';
if (!is_file($path)) return [false, "Template introuvable ($path)"];
$tpl = file_get_contents($path);
if (!$tpl) return [false, "Template vide ($path)"];
$tpl = tpl_if_blocks($tpl, $vars);
$tpl = tpl_vars($tpl, $vars);
return [true, $tpl];
}
function json_out($arr){
header('Content-Type: application/json; charset=utf-8');
echo json_encode($arr, JSON_UNESCAPED_UNICODE);
exit;
}
function json_list_to_string($json, $sep = ', '){
$arr = json_decode((string)$json, true);
if (!is_array($arr)) return '';
$out = [];
foreach ($arr as $v){
$v = trim((string)$v);
if ($v === '') continue;
$out[] = $v;
}
$out = array_values(array_unique($out));
return implode($sep, $out);
}
function json_list_to_string_html($json, $sep = ', '){
$s = json_list_to_string($json, $sep);
return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
function date_fr($dt){
$dt = trim((string)$dt);
if ($dt === '' || $dt === '0000-00-00 00:00:00') return '';
$ts = strtotime($dt);
if (!$ts) return '';
return date('d/m/Y H:i', $ts); // ex: 21/12/2025 14:07
}
function date_fr_auto($s){
$s = trim((string)$s);
if ($s === '' || $s === '0000-00-00' || $s === '0000-00-00 00:00:00') return '';
// détecte si c'est un datetime
if (preg_match('/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/', $s)) {
$dt = DateTime::createFromFormat('Y-m-d H:i:s', $s);
return $dt ? $dt->format('d/m/Y H:i') : '';
}
// sinon date simple
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $s)) {
$dt = DateTime::createFromFormat('Y-m-d', $s);
return $dt ? $dt->format('d/m/Y') : '';
}
return '';
}
?>