From 0d51f87c76d0714a6e7002fe8466a33d609cd7c7 Mon Sep 17 00:00:00 2001
From: Elime1
Date: Mon, 6 Aug 2018 11:01:52 +0200
Subject: [PATCH] Add OTServers.eu voting (#326)
---
config.php | 15 ++++++++-
layout/aside.php | 9 +++---
layout/widgets/vote.php | 9 ++++++
voting.php | 69 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 97 insertions(+), 5 deletions(-)
create mode 100644 layout/widgets/vote.php
create mode 100644 voting.php
diff --git a/config.php b/config.php
index 7ba8c72..0847b2f 100644
--- a/config.php
+++ b/config.php
@@ -1000,4 +1000,17 @@
'points' => 20,
),
);
-?>
+
+ //////////////////////////
+ /// OTServers.eu voting
+ //
+ // Start by creating an account at OTServers.eu and add your server.
+ // You can find your secret token by logging in on OTServers.eu and go to 'MY SERVER' then 'Encourage players to vote'.
+ $config['otservers_eu_voting'] = [
+ 'enabled' => false,
+ 'voteUrl' => 'https://api.otservers.eu/vote_link.php',
+ 'voteCheckUrl' => 'https://api.otservers.eu/vote_check.php',
+ 'secretToken' => '', //Enter your secret token. Do not share with anyone!
+ 'landingPage' => '/voting.php?action=reward', //The user will be redirected to this page after voting
+ 'points' => '1' //Amount of points to give as reward
+ ];
diff --git a/layout/aside.php b/layout/aside.php
index 5a26050..d018098 100644
--- a/layout/aside.php
+++ b/layout/aside.php
@@ -1,11 +1,12 @@
diff --git a/voting.php b/voting.php
new file mode 100644
index 0000000..4234f3b
--- /dev/null
+++ b/voting.php
@@ -0,0 +1,69 @@
+Something went wrong! Could not make a vote request.
';
+ } else {
+ header('Location: ' . $result['voteLink']);
+ die;
+ }
+ } else {
+ $result = checkHasVoted($user_data['id'], $otservers_eu_voting);
+ if ($result !== false) {
+ if ($result['voted'] === true) {
+ $points = $otservers_eu_voting['points'];
+ $pointsText = $points === '1' ? 'point' : 'points';
+ mysql_update("UPDATE `znote_accounts` SET `points` = `points` + '$points' WHERE `account_id`=" . $user_data['id']);
+ echo "Thank you for voting! You have been rewarded with $points $pointsText!
";
+ } else {
+ echo 'It does not seem like you have voted.
';
+ }
+ } else {
+ echo 'Could not verify that you have voted.
';
+ }
+ }
+} else {
+ echo 'Voting is not enabled.
';
+}
+
+include 'layout/overall/footer.php';
+
+function vote($otUserId, $otservers_eu_voting) {
+ $context = stream_context_create([
+ 'http' => [
+ 'header' => "Content-type: application/json",
+ 'method' => 'POST',
+ 'content' => json_encode([
+ 'otUserId' => $otUserId,
+ 'secretToken' => $otservers_eu_voting['secretToken'],
+ 'landingPage' => $otservers_eu_voting['landingPage']
+ ])
+ ]
+ ]);
+ $result = file_get_contents($otservers_eu_voting['voteUrl'], false, $context);
+ return $result !== false ? json_decode($result, true) : false;
+}
+
+function checkHasVoted($otUserId, $otservers_eu_voting) {
+ $context = stream_context_create([
+ 'http' => [
+ 'header' => "Content-type: application/json",
+ 'method' => 'POST',
+ 'content' => json_encode([
+ 'otUserId' => $otUserId,
+ 'secretToken' => $otservers_eu_voting['secretToken'],
+ 'consume' => true
+ ])
+ ]
+ ]);
+ $result = file_get_contents($otservers_eu_voting['voteCheckUrl'], false, $context);
+ return $result !== false ? json_decode($result, true) : false;
+}