web/fourmiliere.php

635 lines
21 KiB
PHP
Executable File

<?php include "inc/debut.php";
head("fourmiliere.php"); ?>
<?php include "inc/codefourmie.php";
include "inc/loginsbdd.php";
// ------------------------- Enregistrer un commentaire dans la BDD -------------------------
if (isset($_POST['commentaire']) AND isset($_GET['articlecommenté'])) {
include "inc/loginsbdd.php";
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$req = $bdd->prepare('INSERT INTO commentairesArticle(titre, pseudo, commentaire) VALUES(:titre, :pseudo, :commentaire)');
$req->execute(array(
'titre' => $_GET['articlecommenté'],
'pseudo' => $_SESSION['pseudo'],
'commentaire' => $_POST['commentaire']
));
$req->closeCursor();
}
// --------------------------------------------- Enregistrer un article dans la BDD ---------------------------------------------
if (isset($_GET['etape']) AND $_GET['etape'] == "publier" AND isset($_POST['article']) AND isset($_SESSION['pseudo'])) {
// ------------------------- Enregistrer la modification d'un article -------------------------
if (isset($_GET['modifier'])) {
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$reponse = $bdd->prepare('SELECT * FROM articles WHERE `articles`.`titre` = :titre');
$reponse->execute(array(
'titre' => $_GET['modifier']
));
while ($donnees = $reponse->fetch()) {
$createurDeLArticle = $donnees['pseudo'];
} $reponse->closeCursor();
if ($_SESSION['pseudo'] == $createurDeLArticle) {
include "inc/loginsbdd.php";
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$req = $bdd->prepare('UPDATE `articles` SET `article` = :article WHERE `articles`.`titre` = :titre');
$req->execute(array(
'titre' => htmlspecialchars($_GET['modifier']),
'article' => htmlspecialchars($_POST['article'])
));
$req->closeCursor();
} else {
echo "ERREUR : Vous n'avez pas créé cet article";
}
// ------------------------- Enregistrer un nouvel article -------------------------
} else if (isset($_POST['titre'])) {
include "inc/loginsbdd.php";
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$req = $bdd->prepare('INSERT INTO articles(pseudo, titre, article, moment) VALUES(:pseudo, :titre, :article, NOW())');
$req->execute(array(
'pseudo' => htmlspecialchars($_SESSION['pseudo']),
'titre' => htmlspecialchars($_POST['titre']),
'article' => htmlspecialchars($_POST['article'])
));
$req->closeCursor();
} else {
echo "ERREUR : Vous devez donner un titre à votre article";
}
}
// ------------------------- Afficher seulement un article -------------------------
if (isset($_GET['article'])) {
// Afficher un article déja créé
include "inc/loginsbdd.php";
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$reponse = $bdd->prepare('SELECT * FROM articles WHERE `articles`.`titre` = :titre');
$reponse->execute(array(
'titre' => $_GET['article']
));
while ($donnees = $reponse->fetch()) { ?>
<div>
<span class="pseudo"><?php echo htmlspecialchars($donnees['pseudo']); ?></span>
<br>
<br>
<span class="titreArticle"><?php echo htmlspecialchars($donnees['titre']); ?></span>
<br>
<br>
<div class="article"><?php echo compilerCodeFourmie($donnees['article']); ?></div>
<br>
<br>
<?php if (isset($_SESSION['pseudo'])) { ?>
<form method="post" action="fourmiliere.php?articlecommenté=<?php echo htmlspecialchars($donnees['titre']); ?>">
<input name="commentaire" class="champMoyen inline" placeholder="Commentez ici" type="text" title="255 caractères maximum" maxlength="255" required/>
<input class="inline small" type="submit" value="Publier" />
</form>
<?php } else { ?>
<input name="commentaire" class="champMoyen inline disabled" placeholder="Vous devez être connecté·e pour poster des commentaires." type="text" title="255 caractères maximum" maxlength="255" required/>
<input class="inline small disabled" title="Vous devez être connecté·e pour poster des commentaires." type="submit" value="Publier" />
<br>
<?php } ?>
<br>
<?php include "inc/loginsbdd.php";
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$repSQL = $bdd->prepare('SELECT * FROM commentairesArticle WHERE `commentairesArticle`.`titre` = :titre');
$repSQL->execute(array(
'titre' => htmlspecialchars($donnees['titre'])
));
while ($fourm = $repSQL->fetch()) { ?>
<div class="commentairePseudo">
<span title="Pseudo" class="pseudo"><?php echo htmlspecialchars($fourm['pseudo']); ?></span>
<br>
<div title='Commentaire posté par <?php echo htmlspecialchars($fourm['pseudo']); ?>.' class="commentaire">
<?php echo htmlspecialchars($fourm['commentaire']); ?>
</div>
<br>
</div>
<?php }
$repSQL->closeCursor(); ?>
</div>
<?php } $reponse->closeCursor(); ?>
<?php } else {
// ------------------------- Page d'accueil -------------------------
if (!isset($_GET['etape']) OR (isset($_GET['etape']) AND $_GET['etape'] == "publier")) { ?>
<div class="hautoto">
<?php if (isset($_SESSION['pseudo'])) { ?>
<div>
</div>
<div class="centre">
<a class="button special icon-plus" href="fourmiliere.php?etape=editer" title="Créer un nouvel article">Nouvelle page</a>
</div>
<div>
Vous êtes connecté·e en tant que <strong class="moyen"><?php echo $_SESSION['pseudo']; ?></strong>.
</div>
<?php } else { ?>
<div>
</div>
<div class="droite">
<a class="button special icon-user" href="connexion.php?depuis=fourmiliere.php" title="Se connecter à son compte Ant">Connexion</a>
</div>
<div>
<a class="button small icon-user-plus" href="signup.php" title="Créer un compte Ant">Devenir une fourmie</a>
</div>
<?php } ?>
</div>
<?php // ------------------------- Afficher les articles déja créés sur la page d'accueil -------------------------
include "inc/loginsbdd.php";
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$reponse = $bdd->query('SELECT titre, pseudo, article, DAY(moment) AS jour, MONTH(moment) AS mois, YEAR(moment) AS annee, HOUR(moment) AS heure, MINUTE(moment) AS minute, SECOND(moment) AS seconde FROM articles');
while ($donnees = $reponse->fetch()) { ?>
<div class="articlePseudo">
<div class="hautoto">
<span>Posté par <span class="pseudo"><?php echo htmlspecialchars($donnees['pseudo']); ?></span> le <?php echo $donnees['jour']; ?> <?php
switch ($donnees['mois']) {
case 1: echo "janvier"; break;
case 2: echo "février"; break;
case 3: echo "mars"; break;
case 4: echo "avril"; break;
case 5: echo "mai"; break;
case 6: echo "juin"; break;
case 7: echo "juillet"; break;
case 8: echo "aout"; break;
case 9: echo "septembre"; break;
case 10: echo "octobre"; break;
case 11: echo "novembre"; break;
case 12: echo "décembre"; break;
}
?> <?php echo $donnees['annee']; ?> à
<?php echo $donnees['heure']; ?>:<?php echo $donnees['minute']; ?></span>
<span><?php
try {
$bddMOD = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$reponseMOD = $bddMOD->prepare('SELECT * FROM articles WHERE `articles`.`titre` = :titre');
$reponseMOD->execute(array(
'titre' => $donnees['titre']
));
while ($donneesMOD = $reponseMOD->fetch()) {
$createurDeLArticle = $donneesMOD['pseudo'];
} $reponseMOD->closeCursor();
if (isset($_SESSION['pseudo']) AND $_SESSION['pseudo'] == $createurDeLArticle) { ?>
<a class="icon bouttonModifier fa-pencil" href="fourmiliere.php?modifier=<?php echo htmlspecialchars($donnees['titre']); ?>&etape=editer"> Modifier</a>
<?php } ?>
<a href="fourmiliere.php?article=<?php echo htmlspecialchars($donnees['titre']); ?>" class="icon-eye" title="Afficher uniquement cette page"> Afficher uniquement cet article</a>
</span>
</div>
<br>
<span class="titreArticle"><?php echo htmlspecialchars($donnees['titre']); ?></span>
<br>
<br>
<div class="article"><?php echo compilerCodeFourmie($donnees['article']); ?></div>
<br>
<br>
<?php if (isset($_SESSION['pseudo'])) { ?>
<form method="post" action="fourmiliere.php?articlecommenté=<?php echo htmlspecialchars($donnees['titre']); ?>">
<input name="commentaire" class="champMoyen inline" placeholder="Commentez ici, 250 caractères maximum" type="text" title="255 caractères maximum" maxlength="255" required/>
<input class="inline small" type="submit" value="Publier" />
</form>
<?php } else { ?>
<input disabled name="commentaire" class="champMoyen inline disabled" placeholder="Vous devez être connecté·e pour poster des commentaires." type="text" title="255 caractères maximum" maxlength="255" required/>
<input disabled class="inline small disabled" title="Vous devez être connecté·e pour poster des commentaires." type="submit" value="Publier" />
<br>
<?php }
include "inc/loginsbdd.php";
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$repSQL = $bdd->prepare('SELECT * FROM commentairesArticle WHERE `commentairesArticle`.`titre` = :titre');
$repSQL->execute(array(
'titre' => $donnees['titre']
));
while ($fourm = $repSQL->fetch()) { ?>
<br>
<div class="commentairePseudo">
<span title="Pseudo" class="pseudo"><?php echo htmlspecialchars($fourm['pseudo']); ?></span>
<br>
<div title='Commentaire posté par <?php echo htmlspecialchars($fourm['pseudo']); ?>.' class="commentaire"><?php echo htmlspecialchars($fourm['commentaire']); ?></div>
</div>
<?php }
$repSQL->closeCursor(); ?>
</div>
<?php } $reponse->closeCursor(); ?>
<?php // ------------------------- Créer / Modifier un article -------------------------
} else if (isset($_SESSION['pseudo']) AND isset($_GET['etape']) AND $_GET['etape'] == "editer") {
// Modifier un article déjà existant
if (isset($_GET['modifier'])) {
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$reponse = $bdd->prepare('SELECT * FROM articles WHERE `articles`.`titre` = :titre');
$reponse->execute(array(
'titre' => $_GET['modifier']
));
while ($donnees = $reponse->fetch()) {
$createurDeLArticle = $donnees['pseudo'];
} $reponse->closeCursor();
if (!isset($createurDeLArticle)) {
echo "YAPAS !";
}
if ($_SESSION['pseudo'] == $createurDeLArticle) { ?>
<form method="post" action="fourmiliere.php?<?php echo "modifier=" . $_GET['modifier'] . "&"; ?>etape=publier">
<strong><?php echo $_SESSION['pseudo']; ?></strong><br><br>
<input required class="champLarge disabled" type="text" value="<?php echo htmlspecialchars($_GET['modifier']); ?>" name="titre" maxlength="200" disabled title="Entrez ici le titre de votre article" placeholder="Le titre de votre article, 200 caractères maximum"/>
<br>
<br>
<textarea class="formArticle" name="article" type="text" maxlength="50000" placeholder="Votre article en code fourmie (voir plus bas)" title="50000 caractères maximum, les retours à la ligne ne sont pas pris en compte" rows="20" required><?php
try {
$bdd = new PDO('mysql:host=localhost;dbname=my_webapp;charset=utf8', $userBDD, $mdpBDD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e) {
die('Erreur PHP / MySQL : ' . $e->getMessage()); }
$reponse = $bdd->prepare('SELECT * FROM articles WHERE `articles`.`titre` = :titre');
$reponse->execute(array(
'titre' => $_GET['modifier']
));
while ($donnees = $reponse->fetch()) {
echo $donnees['article'];
} $reponse->closeCursor();
?>
</textarea>
<br>
<br>
<input type="submit" value="Publier" class="special" />
</form>
<?php } else {
echo "ERREUR : Vous n'avez pas créé cet article";
}
// Créer un nouvel article
} else {?>
<form method="post" action="fourmiliere.php?etape=publier">
<strong><?php echo $_SESSION['pseudo']; ?></strong><br><br>
<input required class="champLarge" type="text" name="titre" maxlength="200" title="Entrez ici le titre de votre article" placeholder="Le titre de votre article, 200 caractères maximum"/>
<br>
<br>
<textarea class="formArticle" name="article" type="text" maxlength="50000" placeholder="Votre article en code fourmie (voir plus bas)" title="50000 caractères maximum, les retours à la ligne ne sont pas pris en compte" rows="20" required></textarea>
<br>
<br>
<input type="submit" value="Publier" class="special" />
</form>
<?php } ?>
<br>
<h2>Code fourmie</h2>
<table class="alt">
<thead>
<tr>
<th>Code Source (tel que l'on doit l'écrire)</th>
<th>Code Compilé (tel qu'il sera affiché)</th>
</tr>
</thead>
<tbody>
<tr>
<?php $codeSource = "[grand]Voici le code fourmie ![/grand]
<br>[l] Ceci est un tableau avec à [rouge] gauche[/rouge], le code que vous devez écrire sur votre page pour afficher le résultat à [bleu] droite[/bleu].
<br>[l] que l'on peut [gras] afficher [/gras] dans [lien|https://anternet.pw/web/fourmiliere.php|] La fourmilière [/lien] avec du [italique] code fourmie [/italique] !
<br>[l] [boite] [rouge] [souligné] /!\[/souligné] [/rouge] Il ne faut pas oublier la balise pour faire les retours à la ligne ! [/boite]
<br>[l] Vous pouvez mettre un mot en [jaunefoncé] jaune foncé[/jaunefoncé], en [vert] vert[/vert], en [cyan] cyan[/cyan], en [rosefoncé] rose foncé[/rosefoncé] etc...
<br>[l]
<br>[l] Si vous ne voulez pas vous casser la tête, sachez que les balises suivantes ne sont qu'optionnelles, à l'exception de la lettre l entre crochets, indispensable pour créer une nouvelle ligne.
<br>[l]
<br>[l] Bonne chance :)"; ?>
<td width="50%"><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<td>[l]</td>
<td>(Les retours à la ligne ne sont pris en compte qu'avec cette balise)</td>
</tr>
<tr>
<?php $codeSource = "[grand]Texte en grand[/grand]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[boite]Texte emboité[/boite]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[gras]Texte en gras[/gras]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[italique]Texte en italique[/italique]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[souligné]Texte souligné[/souligné]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[lien|https://anternet.pw/web|]Lien vers le site de Ant[/lien]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?> (Doit commencer par http:// ou https://)</td>
</tr>
<tr>
<?php $codeSource = ":)"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[gris]Texte en gris[/gris]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[rougefoncé]Texte en rouge foncé[/rougefoncé]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[rouge]Texte en rouge[/rouge]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[orange]Texte en orange[/orange]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[rosefoncé]Texte en rose foncé[/rosefoncé]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[rose]Texte en rose[/rose]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[vertfoncé]Texte en vert foncé[/vertfoncé]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[vert]Texte en vert[/vert]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[jaunefoncé]Texte en jaune foncé[/jaunefoncé]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[bleufoncé]Texte en bleu foncé[/bleufoncé]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[bleu]Texte en bleu[/bleu]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[cyanfoncé]Texte en cyan foncé[/cyanfoncé]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
<tr>
<?php $codeSource = "[cyan]Texte en cyan[/cyan]"; ?>
<td><?php echo $codeSource; ?></td>
<td><?php echo compilerCodeFourmie($codeSource); ?></td>
</tr>
</tbody>
</table>
<?php
} else { ?>
Vous n'êtes pas connecté·e ou vous n'avez rien écrit
<br><br>
<a href="connexion.php" title="Se connecter à son compte Ant" class="button icon-user"> Se connecter</a>
<?php } } ?>
<?php include "inc/footer.php"; ?>