<?php

// parametro: tomada de mlog 1.1 (de Jacobo Tarrío, http://tarrio.org)
function parametro ($_clave)
{
  $clave = $_clave;
  $valor = "";

  if (array_key_exists ($clave, $_GET))
  {
    $valor = $_GET[$clave];
  }

  if (array_key_exists ($clave, $_POST))
  {
    $valor = $_POST[$clave];
  }

  return $valor;
}

function lastmod($file,$lang,$format,$admin=NULL)
{
  global $locale_dir;
  global $admin_dir;

  $file = $admin ? "$admin_dir/$file" : "$locale_dir/$lang/$file";
  setlocale (LC_TIME, $cod[$lang]);
  if(! file_exists($file)) { $file = basename($_SERVER[SCRIPT_NAME]); }
  $tmstamp = filemtime($file);

  return getCurrentDate($lang,$format,$tmstamp);
}

function getCurrentDate($lang,$format,$tmstamp=NULL)
{
  $long = array( "es" => "%A, %e de %B de %Y",
                 "gl" => "%A, %e de %B de %Y",
                 "pt" => "%A, %e de %B de %Y",
                 "en" => "%A, %B %e, %Y"
               );
  $short = array( "es" => "%d/%m/%Y",
                  "gl" => "%d/%m/%Y",
                  "pt" => "%d/%m/%Y",
                  "en" => "%d/%m/%Y"
                );

  $cod = array( "es" => "es_ES@euro",
                "gl" => "gl_ES@euro",
                "pt" => "pt_PT@euro",
                "en" => "en_US" );

  setlocale (LC_TIME, $cod[$lang]);
  if(! $tmstamp) { $tmstamp = time(); }
  if($format == "long") { return(strftime ($long[$lang], $tmstamp)); }
  else { return(strftime ($short[$lang], $tmstamp)); }
}

function myaddslashes($string)
{
  if(strstr($string, '\'')) { $string = str_replace('\'', '"', $string); }

  return addslashes($string);
}

?>
