From 64b2e9e68571a1d1b3dff8c63989f08b102cfcc6 Mon Sep 17 00:00:00 2001 From: aymm Date: Sat, 27 Mar 2021 11:46:31 +0100 Subject: [PATCH] Added poll output --- view_poll.php | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/view_poll.php b/view_poll.php index 2a3d43a..bf62e74 100644 --- a/view_poll.php +++ b/view_poll.php @@ -5,6 +5,8 @@ require_once __DIR__ .'/bootstrap.php'; use APnutI\Exceptions\NotFoundException; use APnutI\Exceptions\HttpPnutForbiddenException; use APnutI\Exceptions\NotSupportedPollException; +use APnutI\Exceptions\NotAuthorizedException; +use APnutI\Exceptions\PollAccessRestrictedException; use APnutI\Entities\Poll; if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) { @@ -12,19 +14,55 @@ if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) { } $poll_id = (int)$_GET['id']; $poll = null; + +if ($api->isAuthenticated()) { + $user = $api->getAuthorizedUser(); + echo 'Welcome ' . ($user->name ?? $user->username) . '
'; +} + try { - $poll = $api->getPoll($poll_id); + $poll_token = array_key_exists('polltoken', $_GET) ? $_GET['polltoken'] : null; + $poll = $api->getPoll($poll_id, $poll_token); } catch (NotFoundException $nfe) { die('Poll not found'); -} catch (HttpPnutForbiddenException $fe) { - die('Poll token required!'); } catch (NotSupportedPollException $nspe) { die('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 + . '
' + . '
' + ); } #echo json_encode($poll); #$user_avatar_url = $api->getAvatarUrl($poll->user->id, 50); $user_avatar_url = $poll->user->getAvatarUrl(50); -$prompt = '@' . $poll->user->username . ' asks: ' . $poll->prompt; -echo ''; -echo $prompt; +#$prompt = '@' . $poll->user->username . ' asks: ' . $poll->prompt; +$username = '@' . $poll->user->username; +#echo ''; +#echo $prompt; +$disabled = $poll->canVote() ? '' : 'disabled'; +?> +
+
+ + asks: + prompt ?> +
+ options as $option) { + $checked = $option->is_your_response ? 'checked' : ''; ?> +
+ /> + text ?> +
+ +
+
+
+