Merge branch 'Utils' into 'master'

Minor modifications to Utils.php

See merge request !24
This commit is contained in:
JosephK 2014-12-03 11:24:55 +01:00
commit a04ce7ab7b

View File

@ -20,16 +20,22 @@ namespace Framadate;
class Utils
{
/**
* @return string Server name
*/
public static function get_server_name()
{
$scheme = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https' : 'http';
$scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$port = in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '/' : ':' . $_SERVER['SERVER_PORT'] . '/';
$server_name = $_SERVER['SERVER_NAME'] . $port . dirname($_SERVER['SCRIPT_NAME']) . '/';
return $scheme . '://' . str_replace('/admin','',str_replace('//','/',str_replace('///','/',$server_name)));
return $scheme . '://' . str_replace('/admin', '', str_replace('//', '/', str_replace('///', '/', $server_name)));
}
public static function get_sondage_from_id($id)
/**
* Returns a poll or false if it fails
*/
public static function get_poll_from_id($id)
{
global $connect;
@ -40,13 +46,13 @@ class Utils
WHERE sondage.id_sondage = ' . $connect->Param('id_sondage');
$sql = $connect->Prepare($sql);
$sondage = $connect->Execute($sql, [$id]);
$poll = $connect->Execute($sql, [$id]);
if ($sondage === false) {
if ($poll === false) {
return false;
}
$psondage = $sondage->FetchObject(false);
$psondage = $poll->FetchObject(false);
$psondage->date_fin = strtotime($psondage->date_fin);
return $psondage;
@ -55,6 +61,15 @@ class Utils
return false;
}
/**
* Use get_poll_from_id that is fully english name
* @deprecated
*/
public static function get_sondage_from_id($id)
{
return get_poll_from_id($id);
}
public static function is_error($cerr)
{
global $err;
@ -77,20 +92,20 @@ class Utils
echo '<!DOCTYPE html>
<html lang="'.$lang.'">
<head>
<meta charset="utf-8">';
<meta charset="utf-8" />';
echo '<title>';
if (! empty($title)) {
echo '<title>' . stripslashes($title) . ' - ' . NOMAPPLICATION . '</title>';
} else {
echo '<title>' . NOMAPPLICATION . '</title>';
echo stripslashes($title) . ' - ';
}
echo NOMAPPLICATION . '</title>';
echo '
<link rel="stylesheet" href="' . self::get_server_name() . 'css/bootstrap.min.css">
<link rel="stylesheet" href="' . self::get_server_name() . 'css/datepicker3.css">
<link rel="stylesheet" href="' . self::get_server_name() . 'css/style.css">
<link rel="stylesheet" href="' . self::get_server_name() . 'css/frama.css">
<link rel="stylesheet" href="' . self::get_server_name() . 'css/print.css" media="print">
<link rel="stylesheet" href="' . self::get_server_name() . 'css/bootstrap.min.css" />
<link rel="stylesheet" href="' . self::get_server_name() . 'css/datepicker3.css" />
<link rel="stylesheet" href="' . self::get_server_name() . 'css/style.css" />
<link rel="stylesheet" href="' . self::get_server_name() . 'css/frama.css" />
<link rel="stylesheet" href="' . self::get_server_name() . 'css/print.css" media="print" />
<script type="text/javascript" src="' . self::get_server_name() . 'js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="' . self::get_server_name() . 'js/bootstrap.min.js"></script>
<script type="text/javascript" src="' . self::get_server_name() . 'js/bootstrap-datepicker.js"></script>
@ -104,18 +119,12 @@ class Utils
</head>
<body>
<div class="container ombre">';
}
public static function check_table_sondage()
{
global $connect;
if (in_array('sondage', $connect->MetaTables('TABLES'))) {
return true;
}
return false;
return in_array('sondage', $connect->MetaTables('TABLES'));
}
/**
@ -132,11 +141,9 @@ class Utils
/**
* Envoi un courrier avec un codage correct de To et Subject
* Les en-têtes complémentaires ne sont pas gérés
*
*/
public static function sendEmail( $to, $subject, $body, $headers='', $param='')
{
mb_internal_encoding('UTF-8');
$subject = mb_encode_mimeheader(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'), 'UTF-8', 'B', "\n", 9);
@ -175,9 +182,9 @@ class Utils
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Auto-Submitted:auto-generated\n";
$headers .= "Return-Path: <>";
$headers .= 'Return-Path: <>';
$body = html_entity_decode($body, ENT_QUOTES, 'UTF-8')._("\n--\n\n« La route est longue, mais la voie est libre… »\nFramasoft ne vit que par vos dons (déductibles des impôts).\nMerci d'avance pour votre soutien http://soutenir.framasoft.org.");
$body = html_entity_decode($body, ENT_QUOTES, 'UTF-8'). "\n--\n\n" _('« La route est longue, mais la voie est libre… »') ."\n" . _('Framasoft ne vit que par vos dons (déductibles des impôts).') ."\n". _('Merci d\'avance pour votre soutien http://soutenir.framasoft.org.');
mail($to, $subject, $body, $headers, $param);
}
@ -185,16 +192,16 @@ class Utils
/**
* Fonction vérifiant l'existance et la valeur non vide d'une clé d'un tableau
* @param string $name La clé à tester
* @param array $tableau Le tableau rechercher la clé ($_POST par défaut)
* @param array $table Le tableau rechercher la clé ($_POST par défaut)
* @return bool Vrai si la clé existe et renvoie une valeur non vide
*/
public static function issetAndNoEmpty($name, $tableau = null)
public static function issetAndNoEmpty($name, $table = null)
{
if (is_null($tableau)) {
$tableau = $_POST;
if (is_null($table)) {
$table = $_POST;
}
return isset($tableau[$name]) && ! empty($tableau[$name]);
return isset($table[$name]) && ! empty($table[$name]);
}
/**
@ -207,19 +214,17 @@ class Utils
{
if (URL_PROPRE) {
if ($admin === true) {
$url = str_replace('/admin', '', self::get_server_name()) . $id . '/admin';
return str_replace('/admin', '', self::get_server_name()) . $id . '/admin';
} else {
$url = str_replace('/admin', '', self::get_server_name()) . $id;
return str_replace('/admin', '', self::get_server_name()) . $id;
}
} else {
if ($admin === true) {
$url = str_replace('/admin', '', self::get_server_name()) . 'adminstuds.php?sondage=' . $id;
return str_replace('/admin', '', self::get_server_name()) . 'adminstuds.php?sondage=' . $id;
} else {
$url = str_replace('/admin', '', self::get_server_name()) . 'studs.php?sondage=' . $id;
return str_replace('/admin', '', self::get_server_name()) . 'studs.php?sondage=' . $id;
}
}
return $url;
}
public static function remove_sondage($connect, $numsondage)
@ -248,6 +253,11 @@ class Utils
return $suppression_OK ;
}
/**
* @param $connect
* @param $log_txt
* @return void
*/
public static function cleaning_polls($connect, $log_txt) {
$connect->StartTrans();
$req = 'SELECT * FROM sondage WHERE date_fin < NOW() LIMIT 20';