Add vote system.

This commit is contained in:
Amin.MasterkinG
2020-04-03 14:51:23 +04:30
parent 0bf86a53d4
commit fd76734d9e
10 changed files with 427 additions and 46 deletions

View File

@@ -22,9 +22,13 @@ Support : [AzerothCore](http://azerothcore.org), [TrinityCore](http://TrinityCor
5. Contact us page.
6. Change Password (4/10/2019).
7. Restore Password (5/31/2019).
8. Vote System (4/03/2020).
## Changelogs
**1.9.4 (4/03/2020):**
1. Vote Added.
**1.9.3 (4/02/2020):**
1. Added a new template.

View File

@@ -50,7 +50,6 @@ $config['realmlists'] = array(
)
);
/*
**********************************
@@ -89,4 +88,23 @@ $config['realmlists'] = array( // Add your realmlist here
*/
$config['script_version'] = '1.9.3';
$config['vote_system'] = true; // Enable or disable vote system (Vote system is a simple and don't have postback or something like that to verify the votes.)
/**
If you use Cloudflare and you have issue with IPs and voting, Read this: https://support.cloudflare.com/hc/en-us/articles/200170786
*/
$config['vote_sites'] = array(
array(
'image' => 'http://www.top100arena.com/hit.asp?id=93137&c=WoW&t=2',
'site_url' => 'http://www.top100arena.com/in.asp?id=93137'
),
array(
'image' => 'https://topg.org/topg.gif',
'site_url' => 'https://topg.org/wow-private-servers/in-479394'
),
array(
'image' => 'http://www.xtremeTop100.com/votenew.jpg',
'site_url' => 'http://www.xtremetop100.com/in.php?site=1132364316'
)
);
$config['script_version'] = '1.9.4';

View File

@@ -11,6 +11,20 @@ use PHPMailer\PHPMailer\Exception;
$error_msg = "";
$success_msg = "";
function getIP(){
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
//ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
//ip pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function get_config($name)
{
global $config;

View File

@@ -0,0 +1,119 @@
<?php
/**
* @author Amin Mahmoudi (MasterkinG)
* @copyright Copyright (c) 2019 - 2022, MsaterkinG32 Team, Inc. (https://masterking32.com)
* @link https://masterking32.com
* @Description : It's not masterking32 framework
* @TODO: Add vote verify system.
**/
use Medoo\Medoo;
class vote
{
public static function post_handler()
{
if (get_config('vote_system') && !empty($_POST['account']) && !empty($_POST['siteid'])) {
self::do_vote($_POST['account'], $_POST['siteid']);
}
}
/**
* Validate account and do vote.
* @return bool
*/
public static function do_vote($account, $siteID)
{
global $antiXss;
$vote_sites = get_config('vote_sites');
if (!is_numeric($siteID) || empty($vote_sites[$siteID - 1])) {
error_msg('Vote site is not valid!');
return false;
}
if (get_config('battlenet_support')) {
if (!filter_var($account, FILTER_VALIDATE_EMAIL)) {
error_msg('Use valid email.');
return false;
}
$acc_data = user::get_user_by_email($account);
} else {
if (!preg_match('/^[0-9A-Z-_]+$/', strtoupper($account))) {
error_msg('Use valid characters for username.');
return false;
}
$acc_data = user::get_user_by_username($account);
}
if (empty($acc_data['id'])) {
error_msg('Account is not valid.');
return false;
}
if (!isset($acc_data['votePoints'])) {
self::setup_vote_table();
}
$siteID--;
database::$auth->delete('votes', ['votedate[<]' => date("Y-m-d H:i:s", time() - 43200)]);
if (!empty(self::get_vote_by_IP($siteID)) || !empty(self::get_vote_by_account($siteID, $acc_data['id']))) {
error_msg('You already voted on this website.');
return false;
}
database::$auth->insert('votes', [
'ip' => $antiXss->xss_clean(strtoupper(getIP())),
'vote_site' => $antiXss->xss_clean($siteID),
'accountid' => $antiXss->xss_clean($acc_data['id'])
]);
database::$auth->update('account', [
'votePoints' => $antiXss->xss_clean($acc_data['votePoints'] + 1)
], [
'id[=]' => $acc_data['id']
]);
header('location: ' . $vote_sites[$siteID]['site_url']);
exit();
}
public static function get_vote_by_IP($siteID)
{
$datas = database::$auth->select('votes', '*', ['ip' => Medoo::raw('UPPER(:ip)', [':ip' => getIP()]), 'vote_site[=]' => $siteID]);
if (!empty($datas[0]['id'])) {
return $datas;
}
return false;
}
public static function get_vote_by_account($siteID, $accountID)
{
$datas = database::$auth->select('votes', '*', ["AND" => ['accountid[=]' => $accountID, 'vote_site[=]' => $siteID]]);
if (!empty($datas[0]['id'])) {
return $datas;
}
return false;
}
public static function setup_vote_table()
{
database::$auth->query("ALTER TABLE `account` ADD COLUMN `votePoints` varchar(255) NULL DEFAULT '0';");
database::$auth->query("
CREATE TABLE `votes` (
`id` bigint(255) NOT NULL AUTO_INCREMENT,
`ip` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`vote_site` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`accountid` bigint(255) NULL DEFAULT 0,
`votedate` timestamp(0) NULL DEFAULT current_timestamp(0),
`done` int(10) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
");
return true;
}
}

View File

@@ -32,11 +32,12 @@ if (get_config('debug_mode')) {
require_once app_path . 'include/database.php';
require_once app_path . 'include/user.php';
require_once app_path . 'include/vote.php';
require_once app_path . 'include/status.php';
$antiXss = new AntiXSS();
if (!empty(get_config('script_version'))) {
/* @TODO Add online version check! */
if(version_compare(get_config('script_version'), '1.9.3', '<') )
if(version_compare(get_config('script_version'), '1.9.4', '<') )
{
echo 'Use last version of config.php file.';
exit();

View File

@@ -32,4 +32,5 @@ if (version_compare(PHP_VERSION, '7.0', '<')) {
require_once './application/loader.php';
user::post_handler();
vote::post_handler();
require_once base_path . 'template/' . get_config('template') . '/tpl/main.php';

View File

@@ -68,6 +68,59 @@ require_once 'rules.php';
Restore Password
</button>
</div>
<?php if (get_config('vote_system')) { ?>
<div class="text-center" data-aos="fade-up" data-aos-delay="100" style="margin-top: 5px;">
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#vote-modal">
Vote for us
</button>
</div>
<div class="modal" id="vote-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Vote</h4>
<button type="button" class="close" data-dismiss="modal">&times;
</button>
</div>
<div class="modal-body">
<form action="<?php echo $antiXss->xss_clean(get_config("baseurl")); ?>/index.php#register"
method="post">
<?php if (get_config('battlenet_support')) { ?>
<div class="input-group">
<span class="input-group">Email</span>
<input type="email" class="form-control" placeholder="Email"
name="account">
</div>
<?php } else { ?>
<div class="input-group">
<span class="input-group">Username</span>
<input type="text" class="form-control" placeholder="Username"
name="account">
</div>
<?php } ?>
<div class="text-center" style="margin-top: 10px;">
<?php
$vote_sites = get_config('vote_sites');
if (!empty($vote_sites)) {
foreach ($vote_sites as $siteID => $vote_site) {
$tmp_id = $siteID + 1;
echo '<button type="submit" name="siteid" value="' . $tmp_id . '" style="border:none; background-color: transparent;"><img src="' . $vote_site['image'] . '"></button>';
}
}
?>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="modal" id="restorepassword-modal">
<div class="modal-dialog">
<div class="modal-content">
@@ -328,7 +381,7 @@ require_once 'rules.php';
</div>
</section>
<?php
require_once 'faq.php';
require_once 'contact.php';
require_once 'footer.php';
require_once 'faq.php';
require_once 'contact.php';
require_once 'footer.php';
?>

View File

@@ -125,6 +125,62 @@ require_once 'header.php'; ?>
Restore Password
</button>
</div>
<?php if (get_config('vote_system')) { ?>
<div class="text-center" style="margin-top: 5px;">
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#vote-modal">
Vote for us
</button>
</div>
<div class="modal" id="vote-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Vote</h4>
<button type="button" class="close" data-dismiss="modal">&times;
</button>
</div>
<div class="modal-body">
<form action="<?php echo $antiXss->xss_clean(get_config("baseurl")); ?>/index.php#register"
method="post">
<?php if (get_config('battlenet_support')) { ?>
<div class="input-group">
<span class="input-group">Email</span>
<input type="email" class="form-control"
placeholder="Email"
name="account">
</div>
<?php } else { ?>
<div class="input-group">
<span class="input-group">Username</span>
<input type="text" class="form-control"
placeholder="Username"
name="account">
</div>
<?php } ?>
<div class="text-center" style="margin-top: 10px;">
<?php
$vote_sites = get_config('vote_sites');
if (!empty($vote_sites)) {
foreach ($vote_sites as $siteID => $vote_site) {
$tmp_id = $siteID + 1;
echo '<button type="submit" name="siteid" value="' . $tmp_id . '" style="border:none; background-color: transparent;"><img src="' . $vote_site['image'] . '"></button>';
}
}
?>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger"
data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="modal" id="restorepassword-modal">
<div class="modal-dialog">
<div class="modal-content">
@@ -138,13 +194,15 @@ require_once 'header.php'; ?>
<?php if (get_config('battlenet_support')) { ?>
<div class="input-group">
<span class="input-group">Email</span>
<input type="email" class="form-control" placeholder="Email"
<input type="email" class="form-control"
placeholder="Email"
name="email">
</div>
<?php } else { ?>
<div class="input-group">
<span class="input-group">Username</span>
<input type="text" class="form-control" placeholder="Username"
<input type="text" class="form-control"
placeholder="Username"
name="username">
</div>
<?php } ?>
@@ -187,13 +245,15 @@ require_once 'header.php'; ?>
<?php if (get_config('battlenet_support')) { ?>
<div class="input-group">
<span class="input-group">Email</span>
<input type="email" class="form-control" placeholder="Email"
<input type="email" class="form-control"
placeholder="Email"
name="email">
</div>
<?php } else { ?>
<div class="input-group">
<span class="input-group">Username</span>
<input type="text" class="form-control" placeholder="Username"
<input type="text" class="form-control"
placeholder="Username"
name="username">
</div>
<?php } ?>
@@ -341,26 +401,24 @@ require_once 'header.php'; ?>
echo "<span style='color: #0d99e5;'>Don't have anything for display.</span>";
} else {
echo '<table class="table table-dark"><thead><tr><th scope="col">Rank</th><th scope="col">Name</th><th scope="col">Race</th> <th scope="col">Class</th><th scope="col">Level</th>';
if(get_config('expansion') >= 6)
{
echo '<th scope="col">Honor Level</th>';
}
echo '<th scope="col">Honor Points</th></tr></thead><tbody>';
if (get_config('expansion') >= 6) {
echo '<th scope="col">Honor Level</th>';
}
echo '<th scope="col">Honor Points</th></tr></thead><tbody>';
$m = 1;
foreach ($data2show as $one_char) {
echo '<tr><td>' . $m++ . '<th scope="row">' . $antiXss->xss_clean($one_char['name']) . '</th><td><img src=\'' . get_config("baseurl") . '/template/' . $antiXss->xss_clean(get_config("template")) . '/images/race/' . $antiXss->xss_clean($one_char["race"]) . '-' . $antiXss->xss_clean($one_char["gender"]) . '.gif\'></td><td><img src=\'' . get_config("baseurl") . '/template/' . $antiXss->xss_clean(get_config("template")) . '/images/class/' . $antiXss->xss_clean($one_char["class"]) . '.gif\'></td><td>' . $antiXss->xss_clean($one_char['level']) . '</td>';
if(get_config('expansion') >= 6)
{
echo '<td>' . $antiXss->xss_clean($one_char['honorLevel']) . '</td>';
echo '<td>' . $antiXss->xss_clean($one_char['honor']) . '</td>';
} else {
echo '<td>' . $antiXss->xss_clean($one_char['totalHonorPoints']) . '</td>';
}
echo '</tr>';
if (get_config('expansion') >= 6) {
echo '<td>' . $antiXss->xss_clean($one_char['honorLevel']) . '</td>';
echo '<td>' . $antiXss->xss_clean($one_char['honor']) . '</td>';
} else {
echo '<td>' . $antiXss->xss_clean($one_char['totalHonorPoints']) . '</td>';
}
echo '</tr>';
}
echo '</table>';
}

View File

@@ -109,6 +109,62 @@ require_once 'header.php'; ?>
Restore Password
</button>
</div>
<?php if (get_config('vote_system')) { ?>
<div class="text-center" style="margin-top: 5px;">
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#vote-modal">
Vote for us
</button>
</div>
<div class="modal" id="vote-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Vote</h4>
<button type="button" class="close" data-dismiss="modal">&times;
</button>
</div>
<div class="modal-body">
<form action="<?php echo $antiXss->xss_clean(get_config("baseurl")); ?>/index.php#register"
method="post">
<?php if (get_config('battlenet_support')) { ?>
<div class="input-group">
<span class="input-group">Email</span>
<input type="email" class="form-control"
placeholder="Email"
name="account">
</div>
<?php } else { ?>
<div class="input-group">
<span class="input-group">Username</span>
<input type="text" class="form-control"
placeholder="Username"
name="account">
</div>
<?php } ?>
<div class="text-center" style="margin-top: 10px;">
<?php
$vote_sites = get_config('vote_sites');
if (!empty($vote_sites)) {
foreach ($vote_sites as $siteID => $vote_site) {
$tmp_id = $siteID + 1;
echo '<button type="submit" name="siteid" value="' . $tmp_id . '" style="border:none; background-color: transparent;"><img src="' . $vote_site['image'] . '"></button>';
}
}
?>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger"
data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="modal" id="restorepassword-modal">
<div class="modal-dialog">
<div class="modal-content">
@@ -122,13 +178,15 @@ require_once 'header.php'; ?>
<?php if (get_config('battlenet_support')) { ?>
<div class="input-group">
<span class="input-group">Email</span>
<input type="email" class="form-control" placeholder="Email"
<input type="email" class="form-control"
placeholder="Email"
name="email">
</div>
<?php } else { ?>
<div class="input-group">
<span class="input-group">Username</span>
<input type="text" class="form-control" placeholder="Username"
<input type="text" class="form-control"
placeholder="Username"
name="username">
</div>
<?php } ?>
@@ -171,13 +229,15 @@ require_once 'header.php'; ?>
<?php if (get_config('battlenet_support')) { ?>
<div class="input-group">
<span class="input-group">Email</span>
<input type="email" class="form-control" placeholder="Email"
<input type="email" class="form-control"
placeholder="Email"
name="email">
</div>
<?php } else { ?>
<div class="input-group">
<span class="input-group">Username</span>
<input type="text" class="form-control" placeholder="Username"
<input type="text" class="form-control"
placeholder="Username"
name="username">
</div>
<?php } ?>
@@ -328,26 +388,24 @@ require_once 'header.php'; ?>
echo "<span style='color: #0d99e5;'>Don't have anything for display.</span>";
} else {
echo '<table class="table table-dark"><thead><tr><th scope="col">Rank</th><th scope="col">Name</th><th scope="col">Race</th> <th scope="col">Class</th><th scope="col">Level</th>';
if(get_config('expansion') >= 6)
{
echo '<th scope="col">Honor Level</th>';
}
echo '<th scope="col">Honor Points</th></tr></thead><tbody>';
if (get_config('expansion') >= 6) {
echo '<th scope="col">Honor Level</th>';
}
echo '<th scope="col">Honor Points</th></tr></thead><tbody>';
$m = 1;
foreach ($data2show as $one_char) {
echo '<tr><td>' . $m++ . '<th scope="row">' . $antiXss->xss_clean($one_char['name']) . '</th><td><img src=\'' . get_config("baseurl") . '/template/' . $antiXss->xss_clean(get_config("template")) . '/images/race/' . $antiXss->xss_clean($one_char["race"]) . '-' . $antiXss->xss_clean($one_char["gender"]) . '.gif\'></td><td><img src=\'' . get_config("baseurl") . '/template/' . $antiXss->xss_clean(get_config("template")) . '/images/class/' . $antiXss->xss_clean($one_char["class"]) . '.gif\'></td><td>' . $antiXss->xss_clean($one_char['level']) . '</td>';
if(get_config('expansion') >= 6)
{
echo '<td>' . $antiXss->xss_clean($one_char['honorLevel']) . '</td>';
echo '<td>' . $antiXss->xss_clean($one_char['honor']) . '</td>';
} else {
echo '<td>' . $antiXss->xss_clean($one_char['totalHonorPoints']) . '</td>';
}
echo '</tr>';
if (get_config('expansion') >= 6) {
echo '<td>' . $antiXss->xss_clean($one_char['honorLevel']) . '</td>';
echo '<td>' . $antiXss->xss_clean($one_char['honor']) . '</td>';
} else {
echo '<td>' . $antiXss->xss_clean($one_char['totalHonorPoints']) . '</td>';
}
echo '</tr>';
}
echo '</table>';
}

View File

@@ -88,6 +88,61 @@ require_once 'header.php'; ?>
Restore Password
</button>
</div>
<?php if (get_config('vote_system')) { ?>
<div class="text-center" style="margin-top: 5px;">
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#vote-modal">
Vote for us
</button>
</div>
<div class="modal" id="vote-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Vote</h4>
<button type="button" class="close" data-dismiss="modal">&times;
</button>
</div>
<div class="modal-body">
<form action="<?php echo $antiXss->xss_clean(get_config("baseurl")); ?>/index.php#register"
method="post">
<?php if (get_config('battlenet_support')) { ?>
<div class="input-group">
<span class="input-group">Email</span>
<input type="email" class="form-control"
placeholder="Email"
name="account">
</div>
<?php } else { ?>
<div class="input-group">
<span class="input-group">Username</span>
<input type="text" class="form-control"
placeholder="Username"
name="account">
</div>
<?php } ?>
<div class="text-center" style="margin-top: 10px;">
<?php
$vote_sites = get_config('vote_sites');
if (!empty($vote_sites)) {
foreach ($vote_sites as $siteID => $vote_site) {
$tmp_id = $siteID + 1;
echo '<button type="submit" name="siteid" value="' . $tmp_id . '" style="border:none; background-color: transparent;"><img src="' . $vote_site['image'] . '"></button>';
}
}
?>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="modal" id="restorepassword-modal">
<div class="modal-dialog">
<div class="modal-content">