From 9404c902f5110db6e0ec6d06e901cd6fa2dedb84 Mon Sep 17 00:00:00 2001 From: Elime1 <Elime1@users.noreply.github.com> Date: Sat, 26 Jan 2019 03:42:03 +0100 Subject: [PATCH] Small voting box improvement (#337) * Add OTServers.eu voting * Hide voting by default and use simple vote url if the user isn't logged in * Fix indentation * Convert to tabs * Convert to tabs --- config.php | 7 ++++--- layout/aside.php | 2 +- voting.php | 48 ++++++++++++++++++++++++++---------------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/config.php b/config.php index afef684..8e466ce 100644 --- a/config.php +++ b/config.php @@ -30,7 +30,7 @@ // ------------------------ \\ if ($config['ServerEngine'] !== 'OTHIRE') { - + // TFS DATABASE CONFIGS // phpmyadmin username for OT server: (DONT USE "root" if ur hosting to public.). $config['sqlUser'] = 'tfs13'; @@ -44,7 +44,7 @@ // Hostname is usually localhost or 127.0.0.1. $config['sqlHost'] = '127.0.0.1'; } else { - + // OTHIRE DATABASE CONFIG // phpmyadmin username for OT server: (DONT USE "root" if ur hosting to public.). $config['sql_user'] = 'tfs13'; @@ -56,7 +56,7 @@ $config['sql_db'] = 'tfs13'; // Hostname is usually localhost or 127.0.0.1. - $config['sql_host'] = '127.0.0.1'; + $config['sql_host'] = '127.0.0.1'; } // QR code authenticator Only works with TFS 1.2+ @@ -1027,6 +1027,7 @@ // 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, + 'simpleVoteUrl' => '', //This url is used if the player isn't logged in. '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! diff --git a/layout/aside.php b/layout/aside.php index de36910..a3f3dba 100644 --- a/layout/aside.php +++ b/layout/aside.php @@ -6,7 +6,7 @@ include 'layout/widgets/login.php'; } if (user_logged_in() && is_admin($user_data)) include 'layout/widgets/Wadmin.php'; - if (user_logged_in()) include 'layout/widgets/vote.php'; + if ($config['otservers_eu_voting']['enabled']) include 'layout/widgets/vote.php'; include 'layout/widgets/charactersearch.php'; include 'layout/widgets/topplayers.php'; include 'layout/widgets/highscore.php'; diff --git a/voting.php b/voting.php index 4234f3b..231c763 100644 --- a/voting.php +++ b/voting.php @@ -1,34 +1,38 @@ -<?php require_once 'engine/init.php'; -protect_page(); +<?php +require_once 'engine/init.php'; include 'layout/overall/header.php'; $otservers_eu_voting = $config['otservers_eu_voting']; if ($otservers_eu_voting['enabled']) { - $isRewardRequest = isset($_GET['action']) && $_GET['action'] === 'reward'; - - if (!$isRewardRequest) { - $result = vote($user_data['id'], $otservers_eu_voting); - if ($result === false) { - echo '<p>Something went wrong! Could not make a vote request.</p>'; - } 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 "<p>Thank you for voting! You have been rewarded with $points $pointsText!</p>"; + if (user_logged_in()) { + $isRewardRequest = isset($_GET['action']) && $_GET['action'] === 'reward'; + if (!$isRewardRequest) { + $result = vote($user_data['id'], $otservers_eu_voting); + if ($result === false) { + echo '<p>Something went wrong! Could not make a vote request.</p>'; } else { - echo '<p>It does not seem like you have voted.</p>'; + header('Location: ' . $result['voteLink']); + die; } } else { - echo '<p>Could not verify that you have voted.</p>'; + $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 "<p>Thank you for voting! You have been rewarded with $points $pointsText!</p>"; + } else { + echo '<p>It does not seem like you have voted.</p>'; + } + } else { + echo '<p>Could not verify that you have voted.</p>'; + } } + } else { + header('Location: ' . $otservers_eu_voting['simpleVoteUrl']); + die; } } else { echo '<p>Voting is not enabled.</p>';