Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="sidebar"> | ||
<h2>Vote for us!</h2> | ||
<div class="inner"> | ||
<form type="submit" action="voting.php" method="GET"> | ||
Get points by voting at OTServers.eu | ||
<input type="submit" value="Vote"> | ||
</form> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php require_once 'engine/init.php'; | ||
protect_page(); | ||
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>"; | ||
} else { | ||
echo '<p>It does not seem like you have voted.</p>'; | ||
} | ||
} else { | ||
echo '<p>Could not verify that you have voted.</p>'; | ||
} | ||
} | ||
} else { | ||
echo '<p>Voting is not enabled.</p>'; | ||
} | ||
|
||
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; | ||
} |