1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__avion-poeme/include/fonctions.inc.php

106 lines
2.6 KiB
PHP
Raw Normal View History

2021-03-22 12:20:39 +01:00
<?php
2021-04-29 10:32:58 +02:00
require_once 'log.php';
2021-03-23 20:26:52 +01:00
if ( !isset($site) )
{
require_once( "config.inc.php" );
header( 'Location: ' . $accueil );
}
2021-03-22 12:20:39 +01:00
// $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
2021-04-07 21:08:08 +02:00
function getpost( $var )
2021-03-22 12:20:39 +01:00
{
//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
{
2021-04-07 21:08:08 +02:00
return;
2021-03-22 12:20:39 +01:00
}
}
// 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;
}
2021-04-29 10:32:58 +02:00
function getLang( $lang )
{
$dico = array();
if ( empty($lang) )
{
$lang="en";
}
if (($fh = fopen('lang/'.$lang, 'r') ))
{
$str = fgets($fh);
fclose($fh);
$dico = json_decode($str, true);
return $dico;
}
}
function formatteDate($locale, $date, $tz)
{
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $tz, IntlDateFormatter::GREGORIAN );
if ($formatter == null)
{
log_write(InvalidConfigException(intl_get_error_message()));
}
return $formatter->format($date);
}
function replaceVariables($db, $text, $dico)
{
$variables = array( 'expediteur' => 'expeMail', 'destinataire' => 'destMail', 'date_depart' => 'startTimeRFC822', 'date_arrivee' => 'deliveryTimeRFC822', 'new_date_arrivee' => 'datePeripetie', 'message' => 'message', 'url_avion' => 'url_avion', 'onglet_apropos' => 'onglet_apropos', 'NB_avion_poeme' => 'avionJournalier', "url_avion" => "urlAvion");
$posVar = 0 ;
$x =0;
while( 1 )
{
$posVar = strpos( $text, "$", $posVar);
if ($posVar !== false)
{
if ($x++ >10 ) break;
$posEsp = strpos( $text, " ", $posVar);
if ($posEsp === false)
{
$var = substr($text, $posVar+1, strlen($text)-$posVar);
}else
{
$var = substr($text, $posVar+1, $posEsp-$posVar-1);
}
$var = trim($var, " .\n\r");
$posVar = $posEsp+1;
$varReplace = "$" . $var;
if ( isset ($variables[$var]) )
{
$dbVar = $variables[$var];
$text = str_replace($varReplace, $db->$dbVar, $text);
}elseif ( isset ($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);
}
}else {
break;
}
}
return $text;
}