v1.2.0
aymm 1 year ago
parent 8e6b0d3687
commit 52ee54f5f9
Signed by: phlaym
GPG Key ID: A06651BAB6777237
  1. 4
      auth_callback.php
  2. 15
      globals.php
  3. 6
      new_poll.php
  4. 18
      post_poll.php
  5. 9
      styles/style.css
  6. 66
      view_poll.php
  7. 7
      vote_poll.php

@ -8,8 +8,8 @@ if (isset($_GET['code'])) {
if ($success) {
redirect('index.php');
} else {
die('Echo error authenticating');
quit(get_page_header().'Echo error authenticating');
}
} else {
die('error authenticating: ' . $_GET['error_message']);
quit(get_page_header().'Echo error authenticating: '. $_GET['error_message']);
}

@ -81,12 +81,23 @@ function get_source_set($user, int $base_size, int $max_scale = 3): string
return implode(', ', $srcset_entries);
}
function make_banner(string $type, string $content): string
function make_banner(string $type, string $content, string $custom_symbol = null): string
{
if (empty($custom_symbol)) {
$custom_symbol = $type === 'success' ? '✓' : '𐄂';
}
return '<div class="banner-wrapper">'
. ' <div class="'
. $type
. ' banner"><span></span>'
. ' banner"><span>'
. $custom_symbol
. '</span>'
. $content
. '</div></div>';
}
function quit(string $error, string $error_details = '')
{
die(make_banner('error', $error) . $error_details . get_page_footer());
}

@ -13,11 +13,11 @@ use APnutI\Entities\User;
try {
echo get_page_header('New Poll', true, ['new_poll']);
} catch (\Exception $e) {
die('Something went wrong :( "'.$e->getMessage().'"' . get_page_footer());
quit('Something went wrong :( "'.$e->getMessage().'"');
}
if (!$api->isAuthenticated(false, true)) {
die('You need to be logged in to create a new poll!' . get_page_footer());
quit('You need to be logged in to create a new poll!');
}
if (!empty($_POST['submit'])) {
@ -34,7 +34,7 @@ if (!empty($_POST['submit'])) {
$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));
} catch (\Exception $e) {
die('Something went wrong creating the poll: "' . $e->getMessage() . '"' . get_page_footer());
quit('Something went wrong creating the poll: "' . $e->getMessage() . '"');
}
}
?>

@ -7,22 +7,22 @@ use APnutI\Entities\Poll;
try {
echo get_page_header('Post Poll', true, []);
} catch (\Exception $e) {
die('Something went wrong :( "'.$e->getMessage().'"' . get_page_footer());
quit('Something went wrong :( "'.$e->getMessage().'"');
}
if (!$api->isAuthenticated(false, true)) {
die('You need to be logged in to create a new post!' . get_page_footer());
quit('You need to be logged in to create a new post!');
}
if (!empty($_POST['submit'])) {
if (empty($_POST['poll_id']) || !is_numeric($_POST['poll_id']) || $_POST['poll_id'] <= 0) {
die('Invalid poll ID'.get_page_footer());
quit('Invalid poll ID');
}
if (empty($_POST['poll_token'])) {
die('Invalid poll token'.get_page_footer());
quit('Invalid poll token');
}
if (empty($_POST['post_text'])) {
die('Invalid text'.get_page_footer());
quit('Invalid text');
}
try {
$params = [
@ -31,19 +31,19 @@ if (!empty($_POST['submit'])) {
$api->createPostWithParameters($_POST['post_text'], $params);
redirect('view_poll.php?poll_created=1&id=' . $_POST['poll_id']);
} catch (\Exception $e) {
die('Something went wrong creating your post: "' . $e->getMessage() . '"'.get_page_footer());
quit('Something went wrong creating your post: "' . $e->getMessage() . '"');
}
}
if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
die('Invalid poll ID'.get_page_footer());
quit('Invalid poll ID');
}
if (empty($_GET['poll_token'])) {
die('Invalid poll token'.get_page_footer());
quit('Invalid poll token');
}
if (empty($_GET['prompt'])) {
die('Invalid prompt'.get_page_footer());
quit('Invalid prompt');
}
$poll_id = (int)$_GET['id'];

@ -186,8 +186,9 @@ datewrapper time {
padding: 0px;
}
.success-banner span {
.banner span {
font-size: x-large;
margin-right: 8px;
}
/* Poll creation */
@ -269,4 +270,10 @@ footer {
footer .sourcecode svg {
stroke-width: 1.5em;
}
/* Other */
form.polltoken-input {
margin-top: 8px;
}

@ -10,14 +10,16 @@ use APnutI\Exceptions\PollAccessRestrictedException;
use APnutI\Entities\Poll;
use APnutI\Entities\User;
$die = null;
try {
echo get_page_header('Poll', true, ['poll']);
} catch (\Exception $e) {
die('Something went wrong :( "' . $e->getMessage() . '"' . get_page_footer());
quit('Something went wrong :( "' . $e->getMessage());
}
if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
die('Invalid poll ID'.get_page_footer());
quit('Invalid poll ID');
}
$poll_id = (int)$_GET['id'];
$poll = null;
@ -26,43 +28,47 @@ try {
$poll_token = array_key_exists('polltoken', $_GET) ? $_GET['polltoken'] : null;
$poll = $api->getPoll($poll_id, $poll_token);
} catch (NotFoundException $nfe) {
die('Poll not found'.get_page_footer());
die('Poll not found');
} catch (NotSupportedPollException $nspe) {
die('Sorry, this poll has a not yet supported type: ' . $nspe->getMessage() . get_page_footer());
quit('Sorry, this poll has a not yet supported type: ' . $nspe->getMessage());
} catch (PollAccessRestrictedException $are) {
$message = array_key_exists('polltoken', $_GET)
? 'Sorry, your poll token is invalid! Please enter a valid token: '
: ('Sorry, this poll is private! If you have found this poll on a post, '
. 'please enter a link to the post, the post ID or the access token for the poll: ');
die(
$message
. '<form><input type="text" name="polltoken">'
. '<input type="hidden" name="id" value="'.$poll_id.'"><button type="submit">Access poll</button></form>'
. get_page_footer()
);
$message_header = array_key_exists('polltoken', $_GET)
? 'Sorry, your poll token is invalid! Please enter a valid token: '
: 'Sorry, this poll is private!';
$message_text = array_key_exists('polltoken', $_GET)
? 'Please enter a valid token: '
: ('If you have found this poll on a post, '
. 'please enter a link to the post, the post ID or the access token for the poll:');
$form = '<form class="polltoken-input"><input type="text" name="polltoken">'
. '<input type="hidden" name="id" value="'.$poll_id.'"><button type="submit">Access poll</button></form>';
quit($message_header, $message_text . $form);
} catch (\Exception $e) {
die('Something went wrong :( "'.$e->getMessage().'"' . get_page_footer());
quit('Something went wrong :( "' . $e->getMessage(). '"');
}
$user_avatar_url = $poll->user->getAvatarUrl(50);
$user_avatar_url_srcset = get_source_set($poll->user, 50);
try {
$user_avatar_url = $poll->user->getAvatarUrl(50);
$user_avatar_url_srcset = get_source_set($poll->user, 50);
$username = '@' . $poll->user->username;
$disabled = $poll->canVote() ? '' : 'disabled';
$user_name = $poll->user->name ?? '';
$created_at = $poll->created_at;
$closed_at = $poll->closed_at;
$user_votes = $poll->getMyVotes();
$username = '@' . $poll->user->username;
$disabled = $poll->canVote() ? '' : 'disabled';
$user_name = $poll->user->name ?? '';
$created_at = $poll->created_at;
$closed_at = $poll->closed_at;
$user_votes = $poll->getMyVotes();
$votes_remaining = $poll->max_options - count($user_votes);
$votes_remaining_plural = $votes_remaining === 1 ? '' : 's';
$votes_remaining_text = "$votes_remaining Vote$votes_remaining_plural remaining";
$votes_remaining_hidden = $poll->canVote() ? '' : ' hidden';
$data_can_vote = $poll->canVote() ? 'true' : 'false';
$disabled_button = ($poll->canVote() && count($user_votes) > 0) ? '' : 'disabled';
$votes_remaining = $poll->max_options - count($user_votes);
$votes_remaining_plural = $votes_remaining === 1 ? '' : 's';
$votes_remaining_text = "$votes_remaining Vote$votes_remaining_plural remaining";
$votes_remaining_hidden = $poll->canVote() ? '' : ' hidden';
$data_can_vote = $poll->canVote() ? 'true' : 'false';
$disabled_button = ($poll->canVote() && count($user_votes) > 0) ? '' : 'disabled';
} catch (\Exception $e) {
quit('Something went wrong :( "' . $e->getMessage(). '"');
}
if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
<?= make_banner('success', 'Your vote has been saved, thank you!') ?>
<?= make_banner('success', 'Your vote has been saved, thank you!') ?>
<?php }
if (array_key_exists('poll_created', $_GET) && $_GET['poll_created'] == 1) { ?>
<?= make_banner('success', 'Your poll and post have been created, thank you!') ?>

@ -12,11 +12,12 @@ if (is_array($_POST['options'])) {
try {
$res = $api->voteInPoll((int)$_POST['pollid'], $voted_options, $_POST['polltoken']);
} catch (\Exception $e) {
get_page_header('Voting error');
$str = 'Sorry, something went wrong while voting! "'
$header = get_page_header('Voting error');
$str = $header
. 'Sorry, something went wrong while voting! "'
. $e->getMessage()
. '"<br>Please yell at <a href="https://pnut.io/@hutattedonmyarm">@hutattedonmyarm</a><br>'
. '<a href="view_poll.php?id='.$_POST['pollid'].'"s>Go back to the poll</a>';
die($str);
quit($str);
}
redirect('view_poll.php?id='.$_POST['pollid'].'&success=1');

Loading…
Cancel
Save