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
This commit is contained in:
Elime1 2019-01-26 03:42:03 +01:00 committed by Stefan A. Brannfjell
parent f79a48fc06
commit 9404c902f5
3 changed files with 31 additions and 26 deletions

View File

@ -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!

View File

@ -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';

View File

@ -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>';