simpleWordsCloud/create.php

78 lines
2.5 KiB
PHP

<?php
include('init.php');
include('templates/header.php');
if (empty($_POST)) {
?>
<div id="cloud_create">
<form method="post" action="create.php">
<div class="cloud_create_element">
<label id="ftext_l" for="ftext"><?php echo L::cloud_description ?></label>
<textarea id="ftext" name="ftext" rows="3" cols="50" placeholder="<?php echo L::cloud_description_message ?>"></textarea>
</div>
<div class="cloud_create_element">
<label for="fduration"><span title="<?php echo L::cloud_duration_tooltip ?>"><?php echo L::cloud_duration ?></span></label>
<select id="fduration" name="fduration">
<?php
foreach (DataBase::OPTIONS_DURATION as $name => $duration) {
echo sprintf('<option value="%s">%s</option>', $name, constant('L::duration_' . $name));
}
?>
</select>
</div>
<div class="cloud_create_element">
<label for="fsize"><?php echo L::cloud_size ?></label>
<input type="number" id="fsize" name="fsize" min="1" max="9" value=<?php echo DataBase::DEFAULT_SIZE ?>>
</div>
<input type="submit" id="cloud_create_submit" value="<?php echo L::create ?>">
</form>
</div>
<?php
} else {
$length = 6;
$token = bin2hex(random_bytes($length));
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) {
$token = bin2hex(random_bytes($length));
$cpt++;
}
$viewUrl = 'result.php?id=' . $token;
$viewName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $viewUrl;
$voteUrl = 'index.php?id=' . $token;
$voteName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $voteUrl;
?>
<h2><?php echo L::cloud_links_warning ?></h2>
<div id="cloud_links">
<div id="cloud_links_results" class="cloud_link">
<div class="label"><?php echo L::cloud_link_view_title ?></div>
<div class="link">
<a href="<?php echo $viewUrl ?>" title="<?php echo L::cloud_link_view_tooltip ?>"><?php echo $viewName ?></a>
</div>
</div>
<div id="cloud_links_vote" class="cloud_link">
<div class="label"><?php echo L::cloud_link_vote_title ?></div>
<div class="link">
<a href="<?php echo $voteUrl ?>" title="<?php echo L::cloud_link_vote_tooltip ?>"><?php echo $voteName ?></a>
</div>
</div>
</div>
<?php
}
include('templates/footer.php');