From e6d171a4b033aabe525f39dd463b5a686fb2d247 Mon Sep 17 00:00:00 2001 From: "Spanti Nicola (RyDroid)" Date: Thu, 27 Nov 2014 01:15:01 +0100 Subject: [PATCH] Minor modifications to Utils.php --- app/classes/Framadate/Utils.php | 86 ++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/app/classes/Framadate/Utils.php b/app/classes/Framadate/Utils.php index 7dfd953..03efeb0 100644 --- a/app/classes/Framadate/Utils.php +++ b/app/classes/Framadate/Utils.php @@ -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; @@ -54,6 +60,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) { @@ -77,20 +92,20 @@ class Utils echo ' - '; + '; + echo ''; if (! empty($title)) { - echo '<title>' . stripslashes($title) . ' - ' . NOMAPPLICATION . ''; - } else { - echo '' . NOMAPPLICATION . ''; + echo stripslashes($title) . ' - '; } + echo NOMAPPLICATION . ''; echo ' - - - - - + + + + + @@ -104,18 +119,12 @@ class Utils
'; - } 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 où rechercher la clé ($_POST par défaut) + * @param array $table Le tableau où 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) @@ -247,7 +252,12 @@ 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';