simpleWordsCloud/create.php

82 lines
2.2 KiB
PHP
Raw Normal View History

2020-11-15 21:51:28 +01:00
<?php
include('templates/header.php');
include('db.php');
2020-11-16 21:31:59 +01:00
if (empty($_POST)) {
?>
<div id="cloud_create">
<form method="post" action="create.php">
<label for="ftext">Description du nuage</label>
<input type="text" id="ftext" name="ftext" placeholder="Votre texte ici">
<label for="fduration">Durée de vie du nuage</label>
<select id="fduration" name="fduration">
<?php
foreach (DataBase::OPTIONS_DURATION as $name => $duration) {
echo sprintf('<option valu="%s">%s</option>', $name, $name);
}
?>
</select>
<label for="fsize">Nombre de mots par entrée (entre 1 et 9)</label>
<input type="number" id="fsize" name="fsize" min="1" max="9">
<input type="submit" value="Créer">
</form>
</div>
<?php
} else {
2020-11-15 21:51:28 +01:00
$db = new DataBase();
if (!$db->isInit()) {
echo 'Error db init';
return;
}
$db->cleanCloud();
$length = 6;
$token = bin2hex(random_bytes($length));
2020-11-16 21:31:59 +01:00
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
$size = $_POST['fsize'];
} else {
$size = 3;
}
if (isset($_POST['ftext'])) {
$text = $_POST['ftext'];
} else {
$text = '';
}
if (isset($_POST['fduration']) && in_array($_POST['fduration'], DataBase::OPTIONS_DURATION)) {
$duration = $_POST['fduration'];
} else {
$duration = DataBase::DEFAULT_DURATION;
}
$cpt = 0;
while (!$db->createCloud($token, $text, $size, $duration) && $cpt < 10) {
2020-11-15 21:51:28 +01:00
$token = bin2hex(random_bytes($length));
2020-11-16 21:31:59 +01:00
$cpt++;
2020-11-15 21:51:28 +01:00
}
2020-11-22 15:53:29 +01:00
$viewUrl = 'result.php?id=' . $token;
$viewName = $_SERVER['HTTP_ORIGIN'] . '/'. $viewUrl;
$voteUrl = 'index.php?id=' . $token;
$voteName = $_SERVER['HTTP_ORIGIN'] . '/' . $voteUrl;
2020-11-15 21:51:28 +01:00
?>
2020-11-22 15:53:29 +01:00
<h2>Attention, il n'y a aucun moyen de retrouver ces liens par la suite.</h2>
2020-11-15 21:51:28 +01:00
<div id="cloud_links">
<div id="cloud_links_results" class="cloud_link">
2020-11-22 15:53:29 +01:00
<div class="label">Voici le lien pour <b>visualiser</b> le nuage de mots, il permet de voir le résultat.</div>
<div class="link">
<a href="<?php echo $viewUrl ?>"><?php echo $viewName ?></a>
</div>
2020-11-15 21:51:28 +01:00
</div>
<div id="cloud_links_vote" class="cloud_link">
2020-11-22 15:53:29 +01:00
<div class="label">Voici le lien pour <b>participer</b> au nuage, c'est le lien à partager avec les autres personnes.</div>
<div class="link">
<a href="<?php echo $voteUrl ?>"><?php echo $voteName ?></a>
</div>
2020-11-15 21:51:28 +01:00
</div>
</div>
<?php
2020-11-16 21:31:59 +01:00
}
2020-11-15 21:51:28 +01:00
include('templates/footer.php');