Fixed #12, posting about polls reworked
This commit is contained in:
parent
f8ea91a7d4
commit
6c93583f32
@ -32,7 +32,7 @@ if (!empty($_POST['submit'])) {
|
||||
$duration_total_minutes = $duration_days*60*24 + $duration_hours * 60 + $duration_minutes;
|
||||
try {
|
||||
$poll = Poll::create($api, $prompt, $options, $max_options, $duration_total_minutes, $is_anonymous, $is_public);
|
||||
redirect('post_poll.php?poll_token='.$poll->token.'&id='.$poll->id.'&prompt='.urlencode($prompt));
|
||||
redirect('post_poll.php?poll_token='.$poll->token.'&id='.$poll->id);
|
||||
} catch (\Exception $e) {
|
||||
quit('Something went wrong creating the poll: "' . $e->getMessage() . '"');
|
||||
}
|
||||
|
@ -68,22 +68,34 @@ if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
|
||||
quit('Invalid poll ID');
|
||||
}
|
||||
|
||||
if (empty($_GET['poll_token'])) {
|
||||
$poll_token = empty($_GET['poll_token']) ? null : $_GET['poll_token'];
|
||||
$prompt = empty($_GET['prompt']) ? null : $_GET['prompt'];
|
||||
$poll_id = (int)$_GET['id'];
|
||||
$poll = null;
|
||||
$is_public = false;
|
||||
try {
|
||||
$poll = $api->getPoll($poll_id, $poll_token);
|
||||
$poll_token = $poll->token;
|
||||
$prompt = $poll->prompt;
|
||||
$is_public = $poll->is_public;
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing, check for token and prompt later
|
||||
}
|
||||
|
||||
|
||||
if (empty($poll_token)) {
|
||||
quit('Invalid poll token');
|
||||
}
|
||||
if (empty($_GET['prompt'])) {
|
||||
if (empty($prompt)) {
|
||||
quit('Invalid prompt');
|
||||
}
|
||||
|
||||
$poll_id = (int)$_GET['id'];
|
||||
$poll_token = $_GET['poll_token'];
|
||||
$prompt = $_GET['prompt'];
|
||||
$dir_name = dirname($_SERVER['SCRIPT_NAME']);
|
||||
if ($dir_name === '.' || $dir_name === '/') {
|
||||
$dir_name = '';
|
||||
}
|
||||
|
||||
|
||||
$scheme = empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME'];
|
||||
$url = $scheme
|
||||
. '://'
|
||||
@ -126,9 +138,11 @@ Do you want to post about your poll?
|
||||
<button type="submit" name="submit" value="submit">Post to pnut</button>
|
||||
</form>
|
||||
<a href="/view_poll.php?id=<?= $poll_id ?>">Take me straight to the poll</a>
|
||||
<p>
|
||||
Note, that if your poll is set to private, you will either need to share your poll with a post,
|
||||
or give the poll's access token to everyone who should be able to vote in your poll. Your access token is:
|
||||
<pre><?= $poll_token ?></pre>
|
||||
</p>
|
||||
<?php if (!$is_public) { ?>
|
||||
<p>
|
||||
Note, that your poll is set to private. You will either need to share your poll with a post,
|
||||
or give the poll's access token to everyone who should be able to vote in your poll. Your access token is:
|
||||
<pre><?= $poll_token ?></pre>
|
||||
</p>
|
||||
<?php } ?>
|
||||
<?= get_page_footer() ?>
|
Loading…
Reference in New Issue
Block a user