acf
This commit is contained in:
39
plugins/system/tgeoip/field/lastupdated.php
Normal file
39
plugins/system/tgeoip/field/lastupdated.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Advanced Custom Fields
|
||||
* @version 2.8.8 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\Factory;
|
||||
use Joomla\Filesystem\File;
|
||||
|
||||
class JFormFieldTG_LastUpdated extends FormField
|
||||
{
|
||||
/**
|
||||
* Method to render the input field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
$file = JPATH_PLUGINS . '/system/tgeoip/db/GeoLite2-City.mmdb';
|
||||
|
||||
if (!file_exists($file))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
return Factory::getDate(@filemtime($file))->format('d M Y H:m');
|
||||
}
|
||||
}
|
||||
108
plugins/system/tgeoip/field/lookup.php
Normal file
108
plugins/system/tgeoip/field/lookup.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Advanced Custom Fields
|
||||
* @version 2.8.8 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>';
|
||||
}
|
||||
}
|
||||
129
plugins/system/tgeoip/field/updatebutton.php
Normal file
129
plugins/system/tgeoip/field/updatebutton.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Advanced Custom Fields
|
||||
* @version 2.8.8 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\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
class JFormFieldTG_UpdateButton extends FormField
|
||||
{
|
||||
/**
|
||||
* Method to render the input field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
if (!NRFramework\Extension::pluginIsEnabled('tgeoip'))
|
||||
{
|
||||
return '<span class="label label-warning" style="margin-top:4px;">' . Text::_('PLG_SYSTEM_TGEOIP_ENABLE_PLUGIN') . '</span>';
|
||||
}
|
||||
|
||||
HTMLHelper::stylesheet('plg_system_nrframework/joomla4.css', ['relative' => true, 'version' => 'auto']);
|
||||
|
||||
$ajaxURL = Uri::base() . 'index.php?option=com_ajax&format=raw&plugin=tgeoip&task=update&license_key=USER_LICENSE_KEY&' . Session::getFormToken() . '=1';
|
||||
|
||||
Text::script('PLG_SYSTEM_TGEOIP_DATABASE_UPDATED');
|
||||
Text::script('PLG_SYSTEM_TGEOIP_PLEASE_WAIT');
|
||||
|
||||
Factory::getDocument()->addScriptDeclaration('
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
document.addEventListener("click", function(e) {
|
||||
var btn = e.target.closest(".geo button");
|
||||
if (!btn) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var license_key = e.target.closest("form").querySelector("#jform_params_license_key").value;
|
||||
if (!license_key) {
|
||||
return;
|
||||
}
|
||||
|
||||
var alert = document.querySelector(".geo .alert");
|
||||
|
||||
var url = "' . $ajaxURL . '";
|
||||
url = url.replace("USER_LICENSE_KEY", license_key);
|
||||
|
||||
// before request
|
||||
alert.style.display = "none";
|
||||
btn.querySelector("span").innerHTML = Joomla.Text._("PLG_SYSTEM_TGEOIP_PLEASE_WAIT");
|
||||
btn.classList.add("btn-working");
|
||||
|
||||
fetch(url,
|
||||
{
|
||||
method: "POST"
|
||||
})
|
||||
.then(function(res){ return res.text(); })
|
||||
.then(function(response){
|
||||
if (response == "1") {
|
||||
alert.innerHTML = Joomla.Text._("PLG_SYSTEM_TGEOIP_DATABASE_UPDATED");
|
||||
alert.style.display = "block";
|
||||
alert.classList.remove("alert-danger");
|
||||
alert.classList.add("alert-success");
|
||||
} else {
|
||||
alert.innerHTML = response;
|
||||
alert.style.display = "block";
|
||||
alert.classList.remove("alert-success");
|
||||
alert.classList.add("alert-danger");
|
||||
}
|
||||
|
||||
btn.classList.remove("btn-working");
|
||||
btn.querySelector("span").innerHTML = btn.dataset.label;
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
');
|
||||
|
||||
Factory::getDocument()->addStyleDeclaration('
|
||||
.geo .btn-working {
|
||||
pointer-events:none;
|
||||
}
|
||||
.geo .alert {
|
||||
display:none;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.geo button {
|
||||
outline:none !important;
|
||||
width: auto;
|
||||
height: auto;
|
||||
line-height: inherit;
|
||||
}
|
||||
.geo button:before {
|
||||
margin-right:5px;
|
||||
position:relative;
|
||||
top:1px;
|
||||
}
|
||||
#wrapper .geo .icon-refresh {
|
||||
margin-right: 5px;
|
||||
}
|
||||
');
|
||||
|
||||
return '
|
||||
<div class="geo">
|
||||
<div class="alert alert-danger"></div>
|
||||
<button class="btn btn-primary" data-label="' . Text::_('PLG_SYSTEM_TGEOIP_UPDATE_DATABASE') . '">
|
||||
<em class="icon-refresh"></em>
|
||||
<span>' . Text::_('PLG_SYSTEM_TGEOIP_UPDATE_DATABASE') . '</span>
|
||||
</button>
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user