Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
6880b8221b
|
|||
52ee54f5f9
|
|||
8e6b0d3687
|
@ -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']);
|
||||
}
|
||||
|
67
globals.php
67
globals.php
@ -39,29 +39,57 @@ function get_page_header(
|
||||
$script_str .= '<script src="scripts/' . $script . '.js"></script>';
|
||||
}
|
||||
|
||||
$home_link = get_icon_link(
|
||||
'index.php',
|
||||
'Home',
|
||||
'home',
|
||||
'homelink'
|
||||
);
|
||||
$new_poll_link = get_icon_link(
|
||||
'new_poll.php',
|
||||
'New Poll',
|
||||
'plus',
|
||||
'newpolllink'
|
||||
);
|
||||
|
||||
return '<html><head><meta charset="utf-8"><title>'.$title.'</title><link rel="stylesheet" href="styles/style.css">'
|
||||
. $script_str
|
||||
. '</head><body><header>'
|
||||
. '<a href="index.php" class="homelink" title="Home"><div class="linkcontents">'
|
||||
. file_get_contents(__DIR__.'/icons/home.svg')
|
||||
. '<span class="linklabel">Home</span></div></a>'
|
||||
. '<a href="new_poll.php" class="newpolllink '.$newpoll_class.'" title="New Poll"><div class="linkcontents">'
|
||||
. file_get_contents(__DIR__.'/icons/plus.svg')
|
||||
. '<span class="linklabel">New Poll</span></div></a>'
|
||||
. $home_link
|
||||
. $new_poll_link
|
||||
. $greeting
|
||||
. '<div class="spacer"></div>'
|
||||
. $logout_link
|
||||
. '</header><main>';
|
||||
}
|
||||
|
||||
function get_icon_link(string $href, string $label, string $icon, string $class)
|
||||
{
|
||||
return '<a href="'.$href.'" title="'.$label.'" class="'.$class.'">'
|
||||
. '<div class="linkcontents">'
|
||||
. file_get_contents(__DIR__.'/icons/'.$icon.'.svg')
|
||||
. '<span class="linklabel">'.$label.'</span></div></a>';
|
||||
}
|
||||
|
||||
function get_page_footer()
|
||||
{
|
||||
$version = json_decode(file_get_contents(__DIR__ . '/composer.json'), true)['version'];
|
||||
$repo_link = get_icon_link(
|
||||
'https://phlaym.net/git/phlaym/Dragonpolls',
|
||||
'Source Code',
|
||||
'src',
|
||||
'sourcecode'
|
||||
);
|
||||
$issues_link = get_icon_link(
|
||||
'https://github.com/hutattedonmyarm/Dragonpolls/issues',
|
||||
'Issues',
|
||||
'issues',
|
||||
'issues'
|
||||
);
|
||||
return '</main><footer>'
|
||||
. '<a href="https://phlaym.net/git/phlaym/Dragonpolls/releases/tag/'.$version.'">Version ' . $version . '</a>'
|
||||
. '<a href="https://phlaym.net/git/phlaym/Dragonpolls" title="Source" class="sourcecode"><div class="linkcontents">'
|
||||
. file_get_contents(__DIR__.'/icons/src.svg')
|
||||
. '<span class="linklabel">Source Code</span></div></a>'
|
||||
. $repo_link
|
||||
. $issues_link
|
||||
. '</footer></body></html>';
|
||||
}
|
||||
|
||||
@ -80,3 +108,24 @@ 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 $custom_symbol = null): string
|
||||
{
|
||||
if (empty($custom_symbol)) {
|
||||
$custom_symbol = $type === 'success' ? '✓' : '𐄂';
|
||||
}
|
||||
|
||||
return '<div class="banner-wrapper">'
|
||||
. ' <div class="'
|
||||
. $type
|
||||
. ' 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());
|
||||
}
|
||||
|
15
icons/issues.svg
Normal file
15
icons/issues.svg
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
|
||||
<g transform="matrix(1.35206,0,0,1.35206,-74.2829,-59.7839)">
|
||||
<circle cx="128.901" cy="118.178" r="66.565" style="fill:none;"/>
|
||||
</g>
|
||||
<g transform="matrix(1,0,0,1,0,3.53095)" class="filled">
|
||||
<g transform="matrix(-0.903127,1.10601e-16,-1.10601e-16,-0.903127,192.517,175.685)">
|
||||
<path d="M102.441,58.588C102.441,58.588 91.63,125.231 91.63,153.793C91.63,159.759 96.475,164.603 102.441,164.603C108.408,164.603 113.252,159.759 113.252,153.793C113.252,125.231 102.441,58.588 102.441,58.588Z"/>
|
||||
</g>
|
||||
<g transform="matrix(0.762846,0,0,0.762846,23.9482,35.356)">
|
||||
<circle cx="99.695" cy="160.113" r="11.029"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
@ -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'];
|
||||
|
@ -3,7 +3,7 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
for (const el of document.querySelectorAll('.option input[type=checkbox], .option input[type=radio]')) {
|
||||
el.onclick = updateVotesRemaining;
|
||||
}
|
||||
const banner = document.querySelector('.success-banner');
|
||||
const banner = document.querySelector('.banner');
|
||||
if (banner) {
|
||||
banner.onclick = hideBanner;
|
||||
}
|
||||
|
@ -7,7 +7,8 @@
|
||||
--disabled-color: gray;
|
||||
--green: green;
|
||||
--default-shadow: 3px 3px 10px 1px var(--secondary-bg-color);
|
||||
--error-color: rgba(255, 0, 0, 0.3);
|
||||
--error-color-translucent: rgba(255, 0, 0, 0.3);
|
||||
--error-color: rgba(255, 0, 0);
|
||||
}
|
||||
@supports (color: color(display-p3 1 1 1)) {
|
||||
:root {
|
||||
@ -26,6 +27,10 @@ a svg {
|
||||
stroke-width: 0.5em;
|
||||
}
|
||||
|
||||
a svg .filled {
|
||||
fill: var(--main-accent-color);
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--main-bg-color);
|
||||
color: var(--main-fg-color);
|
||||
@ -161,14 +166,20 @@ datewrapper time {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.success-banner {
|
||||
background-color: var(--green);
|
||||
.banner {
|
||||
padding: 8px;
|
||||
display: inline-block;
|
||||
margin-bottom: 8px;
|
||||
box-shadow: var(--default-shadow);
|
||||
}
|
||||
|
||||
.banner.success {
|
||||
background-color: var(--green);
|
||||
}
|
||||
.banner.error {
|
||||
background-color: var(--error-color);
|
||||
}
|
||||
|
||||
.banner-wrapper.hiding {
|
||||
transform: translateX(-200%);
|
||||
}
|
||||
@ -179,8 +190,9 @@ datewrapper time {
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.success-banner span {
|
||||
.banner span {
|
||||
font-size: x-large;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
/* Poll creation */
|
||||
@ -240,7 +252,7 @@ datewrapper time {
|
||||
.create-poll .error {
|
||||
grid-column: 1/3;
|
||||
grid-row: 7;
|
||||
background-color: var(--error-color);
|
||||
background-color: var(--error-color-translucent);
|
||||
}
|
||||
.create-poll .error:not(:empty) {
|
||||
margin: 8px;
|
||||
@ -262,4 +274,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,50 +28,50 @@ 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) { ?>
|
||||
<div class="banner-wrapper">
|
||||
<div class="success-banner"><span>✓</span> Your vote has been saved, thank you!</div>
|
||||
</div>
|
||||
<?= make_banner('success', 'Your vote has been saved, thank you!') ?>
|
||||
<?php }
|
||||
if (array_key_exists('poll_created', $_GET) && $_GET['poll_created'] == 1) { ?>
|
||||
<div class="banner-wrapper">
|
||||
<div class="success-banner"><span>✓</span> Your poll and post have been created, thank you!</div>
|
||||
</div>
|
||||
<?= make_banner('success', 'Your poll and post have been created, thank you!') ?>
|
||||
<?php } ?>
|
||||
<div class="poll">
|
||||
<div class="header">
|
||||
|
@ -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');
|
||||
|
Reference in New Issue
Block a user