Server : LiteSpeed System : Linux server 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : alsaif ( 1057) PHP Version : 7.4.33 Disable Function : show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/alsaif/domains/alsaif.group/public_html/plugins/system/tgeoip/field/ |
<?php
/**
* @package Convert Forms
* @version 4.3.3 Pro
*
* @author Tassos Marinos <info@tassos.gr>
* @link http://www.tassos.gr
* @copyright Copyright © 2024 Tassos Marinos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
// No direct access to this file
defined('_JEXEC') or die;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use NRFramework\User;
class JFormFieldTG_Lookup extends FormField
{
/**
* GeoIP Class
*
* @var object
*/
private $geoIP;
/**
* Method to render the input field
*
* @return string
*/
public function getInput()
{
// JavaScript
$ajaxURL = Uri::base() . 'index.php?option=com_ajax&format=raw&plugin=tgeoip&task=get&' . Session::getFormToken() . '=1';
Factory::getDocument()->addScriptDeclaration('
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("click", function(e) {
var btn = e.target.closest(".tGeoIPtest button");
if (!btn) {
return;
}
e.preventDefault();
ip = document.querySelector(".tGeoIPtest input").value;
if (!ip) {
alert("Please enter a valid IP address");
return false;
}
var data = new FormData();
data.append("ip", ip);
fetch("' . $ajaxURL . '",
{
method: "POST",
body: data
})
.then(function(res){ return res.json(); })
.then(function(response){
if (response) {
if (response.continent) {
document.querySelector(".tGeoIPtest .continent").innerHTML = response.continent.names.en;
}
if (response.city) {
document.querySelector(".tGeoIPtest .city").innerHTML = response.city.names.en;
}
if (response.country) {
document.querySelector(".tGeoIPtest .country").innerHTML = response.country.names.en;
document.querySelector(".tGeoIPtest .country_code").innerHTML = response.country.iso_code;
}
document.querySelector(".tGeoIPtest .results").style.display = "block";
} else {
alert("Invalid IP address");
document.querySelector(".tGeoIPtest .results").style.display = "none";
}
})
return false;
})
});
');
// HTML
$ip = User::getIP();
return '<div class="tGeoIPtest">
<input class="form-control input-medium" type="text" value="' . $ip . '"/>
<button class="btn btn-outline-secondary">Lookup</button>
<ul class="results" style="margin-top:20px; display:none;">
<li>Continent: <span class="continent"></span></li>
<li>Country: <span class="country"></span></li>
<li>Country Code: <span class="country_code"></span></li>
<li>City: <span class="city"></span></li>
<ul>
</div>';
}
}