Ahhhh l'index.php est plus clair là. Plus qu'à déboguer

This commit is contained in:
gnieark 2015-12-08 22:58:17 +01:00
parent de4b6a4658
commit ccf2df8999
4 changed files with 137 additions and 91 deletions

View File

@ -17,8 +17,18 @@ $lnMysql=conn_bdd();
$arenas=get_arenas_list();
$lang=get_language_array();
//check type of page
//$_GET['arena'] -> an arena
//$_GET['doc'] -> arena documentation
//$_GET['page'] -> a simple page like about page, legals etc...
//Nothing -> home page
$permitIndex=true; //will be set to false for pages that google or other bot must not index
if(isset($_GET['arena'])){
//check if arena is list
//Arena
//check if arena exists
$currentArena = false;
foreach($arenas as $arena){
if($arena['id'] == $_GET['arena']){
@ -31,10 +41,103 @@ if(isset($_GET['arena'])){
error(404,"Wrong parameter");
die;
}
}else{
$currentArena = "";
$hist=get_battles_history($currentArena);
$siteTitle=$currentArenaArr['title']." - bots Arena";
$siteDescription=$currentArenaArr['metaDescription'];
$mainSectionScript="../src/arenas/".$currentArena."/public.php";
$asideSectionContent='<h2>infos:</h2><p>'.$lang['DEV-YOUR-OWN-BOT'].'<br/> <a href="/'.$currentArena.'/doc">'.$lang['DOC_SPECS_LINKS'].'</a></p>
<h2>Scores</h2>';
foreach($hist as $sc){
$asideSectionContent.='<h3>'.$sc['bot1'].' VS '.$sc['bot2'].'</h3>
<ul>
<li>'.$sc['bot1']." ".$lang['VICTORIES'].":".$sc['player1Wins'].'</li>
<li>'.$sc['bot2']." ".$lang['VICTORIES'].":".$sc['player2Wins'].'</li>
<li>'.$lang['DRAW'].":".$sc['draws'].'</li>
</ul>';
}
$cssAdditionalScript="";
if(isset($currentArenaArr['cssFile'])){
$cssAdditionalScript.='<style type="text/css"><!--'."\n".file_get_contents("../src/arenas/".$currentArena."/".$currentArenaArr['cssFile'])."\n--></style>";
}
//arena specific script js (if needed)
$jsAdditionalScript="";
if(isset($currentArenaArr['jsFile'])){
$jsAdditionalScript.='<script type="text/javascript"><!--'."\n".file_get_contents("../src/arenas/".$currentArena."/".$currentArenaArr['jsFile'])."\n--></script>";
}
}elseif(isset($_GET['doc'])){
//arena's documentation page
//check if arena exists
$currentArena = false;
foreach($arenas as $arena){
if($arena['id'] == $_GET['doc']){
$currentArena = $_GET['doc'];
$currentArenaArr=$arena;
break;
}
}
if(!$currentArena){
error(404,"Wrong parameter");
die;
}
$siteTitle="Specifications ".$currentArenaArr['title']." - bots Arena";
$siteDescription="documentation, faites votre propre bot pour ".$currentArenaArr['metaDescription'];
$mainSectionScript="../src/arenas/".$currentArenaArr['id']."/doc-".$lang['lang'].".html";
$asideSectionContent=''; //to do
$cssAdditionalScript="";
$jsAdditionalScript="";
}elseif(isset($_GET['page'])){
//simple page
switch($_GET['page']){
case "legals":
$siteTitle="Mentions légales - bots Arena";
$siteDescription="OSEF";
$mainSectionScript="../src/legals.html";
$asideSectionContent=''; //to do or not to do
$cssAdditionalScript="";
$jsAdditionalScript="";
break;
case "About":
$siteTitle="About - bots Arena";
$siteDescription="bots arena about page";
$mainSectionScript="../src/about.html";
$asideSectionContent=''; //to do or not to do
$cssAdditionalScript="";
$jsAdditionalScript="";
break;
case "addBot":
$siteTitle="Valider l'ajout d'une IA - bots Arena";
$siteDescription="bots arena about page";
$permitIndex=false;
$mainSectionScript="../src/addBot.php";
$asideSectionContent=''; //to do
$cssAdditionalScript="";
$jsAdditionalScript=""
break;
default:
error(404,"Not found");
break;
}
}else{
//home page
$siteTitle="Bots Arena";
$siteDescription="bots arena main page. Program your own artificiel intelligence and let it play here";
$mainSectionScript="../src/home.php";
$asideSectionContent=''; //to do
$cssAdditionalScript="";
$jsAdditionalScript=""
}
//form submitting
if (isset($_POST['xd_check'])){
//vérifier le numero de formulaire
@ -49,13 +152,7 @@ if (isset($_POST['xd_check'])){
require_once("../src/act.php");
}
}
//title
if($currentArena == ""){
$siteTitle = $lang['SITE_NAME'];
}else{
$siteTitle=$currentArenaArr['title'];
}
?>
<!DOCTYPE html>
@ -63,27 +160,15 @@ if($currentArena == ""){
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="ROBOTS" content="INDEX, FOLLOW" />
<meta name="ROBOTS" content="<?php if($permitIndex){ echo "INDEX, FOLLOW";}else{echo "noindex, nofollow";}?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="author" content="Gnieark" />
<meta name="description" content="<?php echo $siteDescription; ?>"/>
<title><?php echo $siteTitle; ?></title>
<style type="text/css">
@import url(/style.css);
</style>
<?php
//arena specific css script (if needed)
if(isset($currentArenaArr['cssFile'])){
echo '<style type="text/css"><!--'."\n";
echo file_get_contents("../src/arenas/".$currentArena."/".$currentArenaArr['cssFile']);
echo "\n--></style>";
}
//arena specific script js (if needed)
if(isset($currentArenaArr['jsFile'])){
echo '<script type="text/javascript"><!--'."\n";
echo file_get_contents("../src/arenas/".$currentArena."/".$currentArenaArr['jsFile']);
echo "\n--></script>";
}
?>
<?php echo $cssAdditionalScript."\n".$jsAdditionalScript; ?>
</head>
<body>
<header>
@ -104,51 +189,9 @@ if($currentArena == ""){
</header>
<section>
<?php
if(isset($_GET['doc'])){
//on affiche une page de doc.
$pageExists=false;
foreach($arenas as $arena){
if($arena['id'] == $_GET['doc']){
if(file_exists("../src/arenas/".$arena['id']."/doc-".$lang['lang'].".html")){
$pageExists=true;
echo file_get_contents("../src/arenas/".$arena['id']."/doc-".$lang['lang'].".html");
break;
}
}
}
if(!$pageExists){
error(404,"doc is missing");
die;
}
}else{
//on affiche une arene ou page d'accueil
switch($currentArena){
case "":
include ("../src/home.php");
break;
default:
//battle history for this arena
$hist=get_battles_history($currentArena);
echo '<aside id="history">
<h2>infos:</h2>
<p>'.$lang['DEV-YOUR-OWN-BOT'].'<br/> <a href="/'.$currentArena.'/doc">'.$lang['DOC_SPECS_LINKS'].'</a></p>
<h2>Scores</h2>';
foreach($hist as $sc){
echo '<h3>'.$sc['bot1'].' VS '.$sc['bot2'].'</h3>
<ul>
<li>'.$sc['bot1']." ".$lang['VICTORIES'].":".$sc['player1Wins'].'</li>
<li>'.$sc['bot2']." ".$lang['VICTORIES'].":".$sc['player2Wins'].'</li>
<li>'.$lang['DRAW'].":".$sc['draws'].'</li>
</ul>';
}
echo '</aside>';
include ("../src/arenas/".$currentArena."/public.php");
break;
}
}
include $mainSectionScript;
if($asideSectionContent <> ""){
echo "<aside>".$asideSectionContent."</aside>";
?>
</section>
<footer>

View File

@ -0,0 +1 @@
<h1>About</h1>

1
src/addBot.php Normal file
View File

@ -0,0 +1 @@
<h2>Add Bot</h2>

View File

@ -0,0 +1 @@
<h1>Mentions légales</h1>