Retour modules/fonctions.php

<?php
/*===== Fonctions =====*/
$protocol = 'https';
$host = $_SERVER['HTTP_HOST'];

function site($alias = '')
{
  global $protocol;
  global $host;
  if ($alias == '') {
    return $protocol . '://' . $host;
  } else {
    return $protocol . '://' . $host . '/' . $alias;
  }
}

function site_r($alias = '')
{
  global $host;
  if ($alias == '') {
    return $host;
  } else {
    return $host . '/' . $alias;
  }
}

function adr()
{
  global $host;
  $script = $_SERVER['SCRIPT_NAME'];
  return $host . $script;
}

function redirection($url)
{
  global $protocol;
  if (headers_sent()) {
    print ('<meta http-equiv="refresh" content="0;URL=' . $protocol . '://' . $url . '">');
  } else {
    header("Location: $url");
  }
}
;

function require_safe($path)
{
  global $debug;
  global $mysqli;
  global $DBparam;
  $args = func_get_args();
  if (file_exists($path)) {
    require $path;
  } else {
    redirection(site_r() . '/erreur-404');
    exit;
  }
}

function getURI()
{
  $adresse = $_SERVER['PHP_SELF'];
  $i = 0;
  foreach ($_GET as $cle => $valeur) {
    $adresse .= ($i == 0 ? '?' : '&') . $cle . ($valeur ? '=' . $valeur : '');
    $i++;
  }
  return $adresse;
}

function callAPI($method, $url, $data)
{
  $curl = curl_init();
  switch ($method) {
    case "POST":
      curl_setopt($curl, CURLOPT_POST, 1);
      if ($data)
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
      break;
    case "PUT":
      curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
      if ($data)
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
      break;
    default:
      if ($data)
        $url = sprintf("%s?%s", $url, http_build_query($data));
  }
  // OPTIONS:
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'APIKEY: 111111111111111111111',
    'Content-Type: application/json',
  ));
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  // EXECUTE:
  $result = curl_exec($curl);
  if (!$result) {
    return ("Connection Failure");
  }
  curl_close($curl);
  return $result;
}

function popup($color, $title, $msg)
{
  $popup = '
  <div class="container">
    <div class="content is-medium">
      <div class="alert ' . $color . ' flex-center-vertical fd-row" style="color: black; margin: 0 0 20px 0; border-radius: 20px; justify-content: space-between;">
        <strong class="dark is-hidden-mobile">' . $title . '</strong>
        <span class="dark">' . $msg . '</span>
        <span class="closebtn">&times;</span>
      </div>
      <script>
      var close = document.getElementsByClassName("closebtn");
      var i;

      for (i = 0; i < close.length; i++) {
        close[i].onclick = function(){
          var div = this.parentElement;
          div.style.opacity = "0";
          setTimeout(function(){ div.style.display = "none"; }, 600);
        }
      }
      </script>
    </div>
  </div>';
  return $popup;
}

function DateUStoFR($dateUS)
{
  $dateTab = explode("-", $dateUS);
  $dateMois = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
  return $dateTab[2] . ' ' . $dateMois[intval($dateTab[1]) - 1] . ' ' . $dateTab[0];
}

?>```