From f94ee6b5e12989cc9921c5f874b1692bb8ff9f0a Mon Sep 17 00:00:00 2001
From: aymm
Date: Mon, 5 Apr 2021 10:56:15 +0200
Subject: [PATCH] Fixed #1 Added posting about new polls
---
composer.json | 4 +++
composer.lock | 4 +--
new_poll.php | 2 +-
post_poll.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++++
styles/style.css | 8 +++--
view_poll.php | 3 +-
6 files changed, 97 insertions(+), 7 deletions(-)
create mode 100644 post_poll.php
diff --git a/composer.json b/composer.json
index 7c2cf7a..711d799 100644
--- a/composer.json
+++ b/composer.json
@@ -9,6 +9,10 @@
{
"type": "path",
"url": "../APnutI"
+ },
+ {
+ "type": "vcs",
+ "url": "git@phlaym.net:phlaym/APnutI.git"
}
]
}
diff --git a/composer.lock b/composer.lock
index 42831e3..888be64 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "225cc22652f4252bb94d4e0317ca2af6",
+ "content-hash": "6a288e0d98c0c9d9a6ab51583c757345",
"packages": [
{
"name": "hutattedonmyarm/apnuti",
@@ -12,7 +12,7 @@
"dist": {
"type": "path",
"url": "../APnutI",
- "reference": "9f0c8ba3c6bda4f58dd6dcd488172cb354c15745"
+ "reference": "2b45c9fdd0df6a6b6186c1afb1075ae5a0b69bbe"
},
"require": {
"ext-curl": "*",
diff --git a/new_poll.php b/new_poll.php
index 630d236..38e7cff 100644
--- a/new_poll.php
+++ b/new_poll.php
@@ -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('view_poll.php?poll_created=1&id='.$poll->id); #TODO: Add posting about poll after creation
+ 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());
}
diff --git a/post_poll.php b/post_poll.php
new file mode 100644
index 0000000..65169b2
--- /dev/null
+++ b/post_poll.php
@@ -0,0 +1,83 @@
+getMessage().'"' . get_page_footer());
+}
+
+if (!$api->isAuthenticated(false, true)) {
+ die('You need to be logged in to create a new post!' . get_page_footer());
+}
+
+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());
+ }
+ if (empty($_POST['poll_token'])) {
+ die('Invalid poll token'.get_page_footer());
+ }
+ if (empty($_POST['post_text'])) {
+ die('Invalid text'.get_page_footer());
+ }
+ try {
+ $params = [
+ 'raw' => Poll::makePollNoticeRaw($_POST['poll_id'], $_POST['poll_token'])
+ ];
+ $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());
+ }
+}
+
+if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
+ die('Invalid poll ID'.get_page_footer());
+}
+
+if (empty($_GET['poll_token'])) {
+ die('Invalid poll token'.get_page_footer());
+}
+if (empty($_GET['prompt'])) {
+ die('Invalid prompt'.get_page_footer());
+}
+
+$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
+ . '://'
+ . $_SERVER['HTTP_HOST']
+ . $dir_name
+ . '/view_poll.php?id='
+ . $poll_id;
+?>
+Do you want to post about your poll?
+
+Take me straight to the poll
+
+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:
+
= $poll_token ?>
+
+= get_page_footer() ?>
\ No newline at end of file
diff --git a/styles/style.css b/styles/style.css
index 724d9e4..fe12d26 100644
--- a/styles/style.css
+++ b/styles/style.css
@@ -7,6 +7,7 @@
--disabled-color: gray;
--green: green;
--default-shadow: 3px 3px 10px 1px var(--secondary-bg-color);
+ --error-color: rgba(255, 0, 0, 0.3);
}
@supports (color: color(display-p3 1 1 1)) {
:root {
@@ -236,15 +237,18 @@ datewrapper time {
.create-poll button[type=submit] {
grid-row: 8;
}
-
.create-poll .error {
grid-column: 1/3;
grid-row: 7;
- background-color: rgba(255, 0, 0, 0.3);
+ background-color: var(--error-color);
}
.create-poll .error:not(:empty) {
margin: 8px;
}
+.post-poll textarea {
+ background-color: var(--secondary-bg-color);
+ color: var(--main-text-color);
+}
/* Footer */
footer {
diff --git a/view_poll.php b/view_poll.php
index 8e7a6dc..0bb1931 100644
--- a/view_poll.php
+++ b/view_poll.php
@@ -43,7 +43,6 @@ try {
} catch (\Exception $e) {
die('Something went wrong :( "'.$e->getMessage().'"' . get_page_footer());
}
-jslog($poll);
$user_avatar_url = $poll->user->getAvatarUrl(50);
$user_avatar_url_srcset = get_source_set($poll->user, 50);
@@ -69,7 +68,7 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
-
✓ Your poll has been created, thank you!
+
✓ Your poll and post have been created, thank you!