| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.1.102 |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2024 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FPFramework\Base\Ajax; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class FPGeoIP |
| 20 |
{ |
| 21 |
/** |
| 22 |
* GeoIP Class |
| 23 |
* |
| 24 |
* @var object |
| 25 |
*/ |
| 26 |
private $geoIP; |
| 27 |
|
| 28 |
public function __construct() |
| 29 |
{ |
| 30 |
// Geo IP AJAX |
| 31 |
add_action('wp_ajax_fpf_on_geoip_ajax', [$this, 'fpf_on_geoip_ajax']); |
| 32 |
add_action('wp_ajax_nopriv_fpf_on_geoip_ajax', [$this, 'fpf_on_geoip_ajax']); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Geo IP Ajax |
| 37 |
* |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
public function fpf_on_geoip_ajax() |
| 41 |
{ |
| 42 |
if (!current_user_can('manage_options')) |
| 43 |
{ |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; |
| 48 |
|
| 49 |
// verify nonce |
| 50 |
if (!$verify = wp_verify_nonce($nonce, 'fpf-geo-lookup-nonce')) |
| 51 |
{ |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
$this->loadGeoIP(); |
| 56 |
|
| 57 |
$task = isset($_POST['task']) ? sanitize_text_field($_POST['task']) : ''; |
| 58 |
$license_key = isset($_POST['license_key']) ? sanitize_text_field($_POST['license_key']) : ''; |
| 59 |
|
| 60 |
$this->geoIP->setKey($license_key); |
| 61 |
|
| 62 |
switch ($task) |
| 63 |
{ |
| 64 |
// Update database and redirect |
| 65 |
case 'update-red': |
| 66 |
$result = $this->geoIP->updateDatabase(); |
| 67 |
|
| 68 |
if ($result === true) |
| 69 |
{ |
| 70 |
echo wp_json_encode('refresh'); |
| 71 |
} |
| 72 |
else |
| 73 |
{ |
| 74 |
echo wp_json_encode($result); |
| 75 |
} |
| 76 |
break; |
| 77 |
// Update database |
| 78 |
case 'update': |
| 79 |
echo wp_json_encode($this->geoIP->updateDatabase()); |
| 80 |
break; |
| 81 |
// IP Lookup |
| 82 |
case 'get': |
| 83 |
$ip = isset($_POST['ip']) ? sanitize_text_field($_POST['ip']) : ''; |
| 84 |
echo wp_json_encode($this->geoIP->setIP($ip)->getRecord()); |
| 85 |
break; |
| 86 |
} |
| 87 |
wp_die(); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Load GeoIP Classes |
| 92 |
* |
| 93 |
* @return void |
| 94 |
*/ |
| 95 |
private function loadGeoIP() |
| 96 |
{ |
| 97 |
$this->geoIP = new \FPFramework\Libs\Vendors\GeoIP\GeoIP(); |
| 98 |
} |
| 99 |
} |