simpleWordsCloud/create.php

79 lines
2.5 KiB
PHP
Raw Normal View History

2020-11-15 21:51:28 +01:00
<?php
2020-11-23 11:01:37 +01:00
include('init.php');
2020-11-15 21:51:28 +01:00
include('templates/header.php');
2020-11-16 21:31:59 +01:00
if (empty($_POST)) {
?>
<div id="cloud_create">
<form method="post" action="create.php">
2020-11-22 16:05:54 +01:00
<div class="cloud_create_element">
2020-11-23 11:01:37 +01:00
<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>
2020-11-22 16:05:54 +01:00
</div>
<div class="cloud_create_element">
2020-11-23 11:01:37 +01:00
<label for="fduration"><span title="<?php echo L::cloud_duration_tooltip ?>"><?php echo L::cloud_duration ?></span></label>
2020-11-22 16:05:54 +01:00
<select id="fduration" name="fduration">
2020-11-16 21:31:59 +01:00
<?php
foreach (DataBase::OPTIONS_DURATION as $name => $duration) {
2020-11-23 11:01:37 +01:00
echo sprintf('<option value="%s">%s</option>', $name, constant('L::duration_' . $name));
2020-11-16 21:31:59 +01:00
}
?>
2020-11-22 16:05:54 +01:00
</select>
</div>
<div class="cloud_create_element">
2020-11-23 11:01:37 +01:00
<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 ?>>
2020-11-22 16:05:54 +01:00
</div>
2020-11-23 11:01:37 +01:00
<input type="submit" id="cloud_create_submit" value="<?php echo L::create ?>">
2020-11-16 21:31:59 +01:00
</form>
</div>
<?php
} else {
2020-11-23 11:01:37 +01:00
$length = 6;
2020-11-15 21:51:28 +01:00
$token = bin2hex(random_bytes($length));
2020-11-23 11:01:37 +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) {
$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;
2020-11-15 21:51:28 +01:00
?>
2020-11-23 11:01:37 +01:00
<h2><?php echo L::cloud_links_warning ?></h2>
2020-11-15 21:51:28 +01:00
<div id="cloud_links">
<div id="cloud_links_results" class="cloud_link">
2020-11-23 11:01:37 +01:00
<div class="label"><?php echo L::cloud_link_view_title ?></div>
2020-11-22 15:53:29 +01:00
<div class="link">
2020-11-23 11:01:37 +01:00
<a href="<?php echo $viewUrl ?>" title="<?php echo L::cloud_link_view_tooltip ?>"><?php echo $viewName ?></a>
2020-11-22 15:53:29 +01:00
</div>
2020-11-15 21:51:28 +01:00
</div>
<div id="cloud_links_vote" class="cloud_link">
2020-11-23 11:01:37 +01:00
<div class="label"><?php echo L::cloud_link_vote_title ?></div>
2020-11-22 15:53:29 +01:00
<div class="link">
2020-11-23 11:01:37 +01:00
<a href="<?php echo $voteUrl ?>" title="<?php echo L::cloud_link_vote_tooltip ?>"><?php echo $voteName ?></a>
2020-11-22 15:53:29 +01:00
</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');