commit
5327ee6ddb
8
html/.htaccess
Normal file
8
html/.htaccess
Normal file
|
@ -0,0 +1,8 @@
|
|||
RewriteEngine On
|
||||
RewriteBase /
|
||||
RewriteRule ^([a-zA-Z]{1,})-([a-z]{2})$ index\.php?arena=$1&lang=$2 [L]
|
||||
RewriteRule ^([a-zA-Z]{1,})$ index\.php?arena=$1 [L]
|
||||
RewriteRule ^-([a-z]{2})$ index\.php?lang=$1 [L]
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^index.php$ index.php/ [L]
|
|
@ -18,19 +18,39 @@ require_once("../src/functions.php");
|
|||
|
||||
$arenas=get_arenas_list();
|
||||
$lang=get_language_array();
|
||||
|
||||
|
||||
if(isset($_GET['arena'])){
|
||||
//check if arena is list
|
||||
$currentArena = false;
|
||||
foreach($arenas as $arena){
|
||||
if($arena['id'] == $_GET['arena']){
|
||||
$currentArena = $_GET['arena'];
|
||||
$currentArenaArr=$arena;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$currentArena){
|
||||
error(404,"Wrong parameter");
|
||||
die;
|
||||
}
|
||||
}else{
|
||||
$currentArena = "";
|
||||
}
|
||||
|
||||
|
||||
//form submitting
|
||||
if (isset($_POST['xd_check']))
|
||||
{
|
||||
if (isset($_POST['xd_check'])){
|
||||
//vérifier le numero de formulaire
|
||||
if (($_SESSION['xd_check']!=$_POST['xd_check']) AND ($_POST['xd_check'] !="")){
|
||||
erreur ('Something wrong has appen');
|
||||
die;
|
||||
}
|
||||
//call the good act.php
|
||||
if((isset($arenas['current'])) && (file_exists("src/arenas/act.php"))){
|
||||
require_once("src/arenas/act.php");
|
||||
if(($currentArena <> "") && (file_exists("../src/arenas/".$currentArena."/act.php"))){
|
||||
require_once("../src/arenas/".$currentArena."/act.php");
|
||||
}else{
|
||||
require_once("src/default/act.php");
|
||||
require_once("../src/arenas/".$currentArena."/act.php");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,15 +71,37 @@ if (isset($_POST['xd_check']))
|
|||
<body>
|
||||
|
||||
<header>
|
||||
<nav id="languages"><a href="/fr">fr</a> <a href="/en">en</a></nav>
|
||||
<nav id="languages"><a href="-fr">fr</a> <a href="-en">en</a></nav>
|
||||
<nav id="menus"><a href="/"><?php echo $lang['HOME']; ?></a>
|
||||
<?php
|
||||
foreach($arenas as $arena){
|
||||
if( $arena['id'] == $currentArena){
|
||||
$class="selected";
|
||||
}else{
|
||||
$class="";
|
||||
}
|
||||
echo '<a href="'.$arena['url'].'" class="'.$class.'">'.$arena['title'].'</a>';
|
||||
}
|
||||
?>
|
||||
<h1><?php
|
||||
if(isset($arenas['current'])){
|
||||
echo $arenas['current']['title'];
|
||||
if($currentArena == ""){
|
||||
echo $lang['SITE_NAME'];
|
||||
|
||||
}else{
|
||||
echo $lang['SITE_NAME'];
|
||||
echo $currentArenaArr['title'];
|
||||
} ?></h1>
|
||||
</header>
|
||||
<section>
|
||||
<?php
|
||||
switch($currentArena){
|
||||
case "":
|
||||
echo "<h2>Accueil</h2>";
|
||||
break;
|
||||
default:
|
||||
include ("../src/arenas/".$currentArena."/public.php");
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</section>
|
||||
<footer>
|
||||
</footer>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
$lang=array(
|
||||
'SITE_NAME' => 'Artificials Intelligences\' arena',
|
||||
'SITE_DESCRIPTION' => 'blah blah blah but english'
|
||||
'SITE_DESCRIPTION' => 'blah blah blah but english',
|
||||
'HOME' => 'Home page'
|
||||
);
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
$lang=array(
|
||||
'SITE_NAME' => 'Arène pour intelligences (ou persque) artificielles',
|
||||
'SITE_DESCRIPTION' => 'blah blah blah mais en francais'
|
||||
'SITE_DESCRIPTION' => 'blah blah blah mais en francais',
|
||||
'HOME' => 'accueil'
|
||||
);
|
1
src/arenas/Battleship/public.php
Normal file
1
src/arenas/Battleship/public.php
Normal file
|
@ -0,0 +1 @@
|
|||
<h2>Battle ship</h2>
|
1
src/arenas/tictactoe/public.php
Normal file
1
src/arenas/tictactoe/public.php
Normal file
|
@ -0,0 +1 @@
|
|||
<h2> tic tac toe </h2>
|
|
@ -7,7 +7,7 @@ $arenas=array(
|
|||
),
|
||||
array(
|
||||
'id' => "Battleship",
|
||||
'url' => "/battleship",
|
||||
'url' => "/Battleship",
|
||||
'title' => "bataille Navale"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,16 +1,52 @@
|
|||
<?php
|
||||
function get_arenas_list(){
|
||||
include (__DIR__."/arenas_lists.php");
|
||||
if(isset($_GET['arena'])){
|
||||
foreach ($arenas as $arena){
|
||||
if($arena['id'] == $_GET['arena']){
|
||||
$arenas['current'] = $arena;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arenas;
|
||||
}
|
||||
function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'){
|
||||
|
||||
$chars_length = (strlen($chars) - 1);
|
||||
$string = $chars{rand(0, $chars_length)};
|
||||
|
||||
for ($i = 1; $i < $length; $i = strlen($string)){
|
||||
$r = $chars{rand(0, $chars_length)};
|
||||
if ($r != $string{$i - 1}) $string .= $r;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
function xd_check_input($id=1){
|
||||
/*
|
||||
*On génére un hash aléatoire qui sera
|
||||
*ajouté aux formulaires, afin d'ajouter
|
||||
*une vérification supplémentaire
|
||||
*lors du traitement de ce dernier
|
||||
*/
|
||||
/*
|
||||
* le parametre $id permet de selectionner le type de retour
|
||||
* 0=> un input type hidden sans id
|
||||
* 1=> un input type hidden avec id
|
||||
* 2=> juste la valeur
|
||||
*/
|
||||
if(!isset($_SESSION['xd_check'])){
|
||||
//le générer
|
||||
$_SESSION['xd_check']=rand_str(25);
|
||||
}
|
||||
switch($id){
|
||||
case 0:
|
||||
return "<input type=\"hidden\" name=\"xd_check\" value=\"".$_SESSION['xd_check']."\"/>";
|
||||
break;
|
||||
case 1:
|
||||
return "<input type=\"hidden\" name=\"xd_check\" id=\"xd_check\" value=\"".$_SESSION['xd_check']."\"/>";
|
||||
break;
|
||||
case 2:
|
||||
return $_SESSION['xd_check'];
|
||||
break;
|
||||
default:
|
||||
return "<input type=\"hidden\" name=\"xd_check\" id=\"xd_check\" value=\"".$_SESSION['xd_check']."\"/>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function get_language_array(){
|
||||
/*
|
||||
* Choisir la langue de l'utilisateur
|
||||
|
@ -43,4 +79,17 @@ function get_language_array(){
|
|||
|
||||
include (__DIR__."/../lang/".$language.".php");
|
||||
return $lang;
|
||||
}
|
||||
function error($code,$message){
|
||||
switch($code){
|
||||
case 404:
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
echo '<!DOCTYPE html><html lang="fr"><head><meta charset="UTF-8" /><title>Page Not found</title></head><body><p>'.$message.'</p></body></html>';
|
||||
die;
|
||||
default:
|
||||
|
||||
die;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user