diff --git a/README.md b/README.md index 2456eba..43fb286 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/application/config/config.php.sample b/application/config/config.php.sample index 530273f..f1282e4 100644 --- a/application/config/config.php.sample +++ b/application/config/config.php.sample @@ -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'; diff --git a/application/include/functions.php b/application/include/functions.php index 8e1307a..f26a025 100644 --- a/application/include/functions.php +++ b/application/include/functions.php @@ -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; diff --git a/application/include/vote.php b/application/include/vote.php new file mode 100644 index 0000000..210a7cf --- /dev/null +++ b/application/include/vote.php @@ -0,0 +1,119 @@ +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; + } +} diff --git a/application/loader.php b/application/loader.php index f6a3842..ee54313 100644 --- a/application/loader.php +++ b/application/loader.php @@ -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(); diff --git a/index.php b/index.php index 4c16177..4cd2611 100644 --- a/index.php +++ b/index.php @@ -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'; \ No newline at end of file diff --git a/template/advance/tpl/main.php b/template/advance/tpl/main.php index 664d229..3cdbafc 100644 --- a/template/advance/tpl/main.php +++ b/template/advance/tpl/main.php @@ -68,6 +68,59 @@ require_once 'rules.php'; Restore Password + +