Clean functions.php

This commit is contained in:
nemunaire 2015-01-14 10:56:27 +01:00 committed by Nemunaire
parent ec33842949
commit 1c7c45ea56
3 changed files with 31 additions and 124 deletions

View File

@ -8,7 +8,7 @@ if (empty($sess->values["connected"]) && !defined("xCSRF"))
if (!empty($VAR["development"]))
define("DEBUG", true);
require_once("functions.php"); //Inclusion des principales fonctions
require_once("functions.php");
require_once("common/Exercice.class.php");
require_once("common/Member.class.php");
@ -26,25 +26,6 @@ if (is_file($VAR["misc_dir"]."/shared/challenge_started"))
$template->assign("END", $VAR['end_challenge']);
}
function pipe_backend_scheduler($instruct)
{
global $VAR;
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
if (is_writable($VAR["scheduler_socket"]) && socket_connect($socket, $VAR["scheduler_socket"]))
{
socket_write($socket, $instruct."\r\n") or die(socket_strerror(socket_last_error()));
sleep(1);
socket_shutdown($socket);
socket_close($socket);
}
else if(defined("DEBUG") && DEBUG)
{
print("Socket '".$VAR["scheduler_socket"]."' is not writable by ".$_SERVER["USER"]." user!");
exit(1);
}
}
if (!empty($VAR['misc_dir']))
$template->assign("MISC_DIR", $VAR['misc_dir']);
if (!empty($LANG))

View File

@ -1,25 +1,5 @@
<?php
function mdp($username, $mdp)
{
return hash('whirlpool', strtoupper($username).'#'.$mdp);
}
function ip()
{
return $_SERVER["REMOTE_ADDR"];
}
function send_mail($to, $subject, $body)
{
$mail = new Mailer();
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
return $mail->Send();
}
function erreur($message, $color="danger")
{
global $template;
@ -28,69 +8,21 @@ function erreur($message, $color="danger")
$template->assign('ERRcolor', $color);
}
function format_url($string)
function pipe_backend_scheduler($instruct)
{
$string = trim($string);
global $VAR;
if ( ctype_digit($string) )
{
return $string;
}
else
{
// replace accented chars
$accents = '/&([A-Za-z]{1,2})(grave|acute|circ|cedil|uml|lig);/';
$string_encoded = htmlentities($string,ENT_NOQUOTES,'UTF-8');
$string = preg_replace($accents,'$1',$string_encoded);
// clean out the rest
$replace = array('([\40\'/])','([^a-zA-Z0-9-])','(-{2,})');
$with = array('-','','-');
$string = preg_replace($replace,$with,$string);
}
return strtolower($string);
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
if (is_writable($VAR["scheduler_socket"]) && socket_connect($socket, $VAR["scheduler_socket"]))
{
socket_write($socket, $instruct."\r\n") or die(socket_strerror(socket_last_error()));
sleep(1);
socket_shutdown($socket);
socket_close($socket);
}
else if(defined("DEBUG") && DEBUG)
{
print("Socket '".$VAR["scheduler_socket"]."' is not writable by ".$_SERVER["USER"]." user!");
exit(1);
}
}
function pagination($nbPages, $page, $link = "documents-recents-")
{
$nbPages++;
$cntPages = array();
if ($nbPages < 10)
{
for ($i = 1 ; $i <= $nbPages ; $i++)
$cntPages[] = $i;
}
else
{
for ($i = 1 ; $i <= 4 ; $i++)
$cntPages[] = $i;
if (6 != max(6, $page))
$cntPages[] = "...";
for ($i = max(6, $page) - 1 ; $i < min(max(6, $page) + 3, $nbPages - 2) ; $i++)
$cntPages[] = $i;
if ($nbPages - 2 != max(6, $page) + 3 && $nbPages - 2 != $i)
$cntPages[] = "...";
for ($i = $nbPages - 2 ; $i <= $nbPages ; $i++)
$cntPages[] = $i;
}
$out = "";
foreach($cntPages as $p)
{
if ($p == "...")
$out .= "<span class=\"etc\"><span> ... </span></span>";
else
$out .= ' <a href="'.$link.$p.'" class="page'.($p==$page+1?" hilight":"").'">'.$p.'</a> ';
}
return '<a href="'.$link.($page>1?$page:1).'" class="moins"><span>&lt;&lt;</span></a>'.$out.'<a href="'.$link.($page+1<$nbPages?$page+2:$nbPages).'" class="plus"><span>&gt;&gt;</span></a>';
}
function eregmenu($pattern, $string)
{
return preg_match("#".$pattern."#ui", $string);
}
?>

View File

@ -20,29 +20,23 @@
*/
function smarty_modifier_url($string)
{
$string = trim($string);
if ( ctype_digit($string) )
$string = trim($string);
if (!ctype_digit($string))
{
return $string;
// replace accented chars
$accents = '/&([A-Za-z]{1,2})(grave|acute|circ|cedil|uml|lig);/';
$string_encoded = htmlentities($string,ENT_NOQUOTES,'UTF-8');
$string = preg_replace($accents, '$1', $string_encoded);
// clean out the rest
$replace = array('([\40\'/])','([^a-zA-Z0-9-])','(-{2,})');
$with = array('-','','-');
$string = preg_replace($replace, $with, $string);
}
else
{
// replace accented chars
$accents = '/&([A-Za-z]{1,2})(grave|acute|circ|cedil|uml|lig);/';
$string_encoded = htmlentities($string,ENT_NOQUOTES,'UTF-8');
$string = preg_replace($accents,'$1',$string_encoded);
// clean out the rest
$replace = array('([\40\'/])','([^a-zA-Z0-9-])','(-{2,})');
$with = array('-','','-');
$string = preg_replace($replace,$with,$string);
}
return strtolower($string);
return strtolower($string);
}
/* vim: set expandtab: */
?>