Fixed #12, posting about polls reworked

This commit is contained in:
aymm 2021-05-10 21:04:46 +02:00
parent f8ea91a7d4
commit 6c93583f32
Signed by: phlaym
GPG Key ID: A06651BAB6777237
2 changed files with 25 additions and 11 deletions

View File

@ -32,7 +32,7 @@ if (!empty($_POST['submit'])) {
$duration_total_minutes = $duration_days*60*24 + $duration_hours * 60 + $duration_minutes; $duration_total_minutes = $duration_days*60*24 + $duration_hours * 60 + $duration_minutes;
try { try {
$poll = Poll::create($api, $prompt, $options, $max_options, $duration_total_minutes, $is_anonymous, $is_public); $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) { } catch (\Exception $e) {
quit('Something went wrong creating the poll: "' . $e->getMessage() . '"'); quit('Something went wrong creating the poll: "' . $e->getMessage() . '"');
} }

View File

@ -68,22 +68,34 @@ if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
quit('Invalid poll ID'); 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'); quit('Invalid poll token');
} }
if (empty($_GET['prompt'])) { if (empty($prompt)) {
quit('Invalid prompt'); quit('Invalid prompt');
} }
$poll_id = (int)$_GET['id']; $poll_id = (int)$_GET['id'];
$poll_token = $_GET['poll_token'];
$prompt = $_GET['prompt'];
$dir_name = dirname($_SERVER['SCRIPT_NAME']); $dir_name = dirname($_SERVER['SCRIPT_NAME']);
if ($dir_name === '.' || $dir_name === '/') { if ($dir_name === '.' || $dir_name === '/') {
$dir_name = ''; $dir_name = '';
} }
$scheme = empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME']; $scheme = empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME'];
$url = $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> <button type="submit" name="submit" value="submit">Post to pnut</button>
</form> </form>
<a href="/view_poll.php?id=<?= $poll_id ?>">Take me straight to the poll</a> <a href="/view_poll.php?id=<?= $poll_id ?>">Take me straight to the poll</a>
<?php if (!$is_public) { ?>
<p> <p>
Note, that if your poll is set to private, you will either need to share your poll with a post, 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: 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> <pre><?= $poll_token ?></pre>
</p> </p>
<?php } ?>
<?= get_page_footer() ?> <?= get_page_footer() ?>