144 lines
3.6 KiB
PHP
144 lines
3.6 KiB
PHP
<?php
|
|
require_once 'log.php';
|
|
if ( !isset($site) )
|
|
{
|
|
require_once( "config.inc.php" );
|
|
header( 'Location: ' . $accueil );
|
|
}
|
|
// $var clef à rechercher dans $_POST, $_GET, et $_SESSION (si $session=true)
|
|
// $default valeur retournée si aucune valeur n'est trouvée
|
|
// $session: si true, rechercher aussi dans $_SESSION
|
|
|
|
function getpost( $var )
|
|
{
|
|
//echo '$var =>' . $var . "<br />";
|
|
if ( isset($_GET[$var]) )
|
|
{
|
|
//echo '$_get -> $var =>' . $var . "<br />";
|
|
return $_GET[$var];
|
|
}
|
|
elseif ( isset($_POST[$var]) )
|
|
{
|
|
//echo '$_POST -> $var =>' . $var . "<br />";
|
|
return $_POST[$var];
|
|
}else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
// MET LA PREMIÈRE LETTRE D'UN MOT EN MAJUSCULE ( utf8 compliant )
|
|
|
|
function mb_ucfirst($str)
|
|
{
|
|
$char = mb_substr($str,0,1,"UTF8");
|
|
$str = mb_substr( $str, 1, NULL, "UTF8");
|
|
$char = mb_strtoupper( $char, "UTF8");
|
|
return $char . $str;
|
|
}
|
|
|
|
function getLang( $lang, $gestion=false )
|
|
{
|
|
$dico = array();
|
|
if ( empty($lang) )
|
|
{
|
|
$lang="en";
|
|
}
|
|
$langPath ='lang/'.$lang;
|
|
if ($gestion)
|
|
$langPath = "../" . $langPath;
|
|
if (($fh = fopen($langPath, 'r') ))
|
|
{
|
|
$str = fgets($fh);
|
|
fclose($fh);
|
|
$dico = json_decode($str, true);
|
|
return $dico;
|
|
}else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function formatteDate($locale, $date, $tz)
|
|
{
|
|
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $tz, IntlDateFormatter::GREGORIAN );
|
|
if ($formatter == null)
|
|
{
|
|
log_write(__FILE__ . EOLH . __LINE__ . EOLH . "Formatter error : locale = " . $locale . "tz = " . $tz . "Formatter = " . print_r($formatter, true) . InvalidConfigException(intl_get_error_message()),ERROR);
|
|
}
|
|
return $formatter->format($date);
|
|
}
|
|
|
|
/* Remplace les variables dans les textes
|
|
|
|
*/
|
|
function replaceVariables($db, $text, $dico) :array
|
|
{
|
|
$variables = array( 'expediteur' => 'expeMail', 'destinataire' => 'destMail', 'date_depart' => 'startTimeRFC822', 'date_arrivee' => 'deliveryTimeRFC822', 'new_date_arrivee' => 'datePeripetie', 'message' => 'message', 'onglet_apropos' => 'onglet_apropos', 'NB_avion_poeme' => 'avionJournalier', "url_avion" => "urlAvion");
|
|
$posVar = 0 ;
|
|
$x =0;
|
|
$result = array();
|
|
// si contient la variable '$message' alors le text est en html
|
|
if (strpos($text, '$message') === false)
|
|
{
|
|
$html = false;
|
|
}else
|
|
{
|
|
$html = true;
|
|
}
|
|
|
|
while( 1 )
|
|
{
|
|
// Recherche les variables dans le texte
|
|
if ($x++ >10 ) break; // empêche une boucle sans fin, il n'y a pas plus de 10 variables par texte
|
|
$posVar = strpos( $text, "$", $posVar);
|
|
if ($posVar !== false)
|
|
{
|
|
// une variable a été trouvée
|
|
$posEsp = strpos( $text, " ", $posVar);
|
|
if ($posEsp === false)
|
|
{
|
|
$var = substr($text, $posVar+1, strlen($text)-$posVar);
|
|
}else
|
|
{
|
|
if ($posEsp == $posVar+1)
|
|
{
|
|
$var = "";
|
|
}else
|
|
{
|
|
$var = substr($text, $posVar+1, $posEsp-$posVar-1);
|
|
}
|
|
}
|
|
$posVar = $posEsp+1;
|
|
if ($var != "")
|
|
{
|
|
$var = trim($var, " .\n\r)");
|
|
$varReplace = "$" . $var;
|
|
if ( isset ($variables[$var]) )
|
|
{
|
|
$dbVar = $variables[$var];
|
|
$varText = $db->$dbVar;
|
|
//$text = str_replace($varReplace, $db->$dbVar, $text);
|
|
}elseif ( isset ($dico[$var]) )
|
|
{
|
|
$varText = $dico[$var];
|
|
//$text = str_replace($varReplace, $dico[$var], $text);
|
|
}else
|
|
{
|
|
log_error( "La variable => " . $var . "n'est pas reconnue<br />" . __file__ . ' ligne ' . __line__ . "\n" , true, false);
|
|
}
|
|
if ($html and (strpos($var, "url") !== false))
|
|
{
|
|
$varText = '<a href="' . $varText .'">' . $varText . "</a>";
|
|
}
|
|
$text = str_replace($varReplace, $varText, $text); //remplace la variable dans le texte
|
|
}
|
|
}else {
|
|
break;
|
|
}
|
|
}
|
|
$result['html'] = $html;
|
|
$result['text'] = $text;
|
|
return $result;
|
|
}
|