forked from LiveCarta/LiveCartaWP
LAW-5279
This commit is contained in:
15
htdocs/wp-content/plugins/wp-rest-api-event/HttpClient.php
Normal file → Executable file
15
htdocs/wp-content/plugins/wp-rest-api-event/HttpClient.php
Normal file → Executable file
@@ -7,6 +7,21 @@ namespace app\wpRestApiEvent;
|
|||||||
*/
|
*/
|
||||||
class HttpClient
|
class HttpClient
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param string $eventType
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
public function logEvent(string $eventType, $data)
|
||||||
|
{
|
||||||
|
$data['event'] = [
|
||||||
|
'slug' => $eventType,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->doPostRequest(LAWCARTA_WP_REST_API_EVENT_LOG_URL, $data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return null|string
|
* @return null|string
|
||||||
|
|||||||
39
htdocs/wp-content/plugins/wp-rest-api-event/event/EventSubscriber.php
Normal file → Executable file
39
htdocs/wp-content/plugins/wp-rest-api-event/event/EventSubscriber.php
Normal file → Executable file
@@ -49,6 +49,16 @@ class EventSubscriber
|
|||||||
*/
|
*/
|
||||||
private static $server;
|
private static $server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $userIp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $sessionId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@@ -56,8 +66,9 @@ class EventSubscriber
|
|||||||
|
|
||||||
public static function onInit()
|
public static function onInit()
|
||||||
{
|
{
|
||||||
|
add_action('wpcf7_after_flamingo', [self::class, 'onDemoRequest']);
|
||||||
apply_filters('parse_request', [self::class, 'onParseRequest']);
|
apply_filters('parse_request', [self::class, 'onParseRequest']);
|
||||||
apply_filters('http_response', [self::class, 'onResponse'], 0);
|
// apply_filters('http_response', [self::class, 'onResponse'], 0);
|
||||||
//apply_filters('shutdown', [self::class, 'onResponse'], 0);
|
//apply_filters('shutdown', [self::class, 'onResponse'], 0);
|
||||||
register_shutdown_function([self::class, 'onShutdown']);
|
register_shutdown_function([self::class, 'onShutdown']);
|
||||||
apply_filters('pre_http_request', [self::class, 'onRequest'], 0);
|
apply_filters('pre_http_request', [self::class, 'onRequest'], 0);
|
||||||
@@ -89,6 +100,12 @@ class EventSubscriber
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function onDemoRequest()
|
||||||
|
{
|
||||||
|
$client = HttpClient::create();
|
||||||
|
$client->logEvent('demo-request', self::getSuperGlobals());
|
||||||
|
}
|
||||||
|
|
||||||
public static function setGlobals()
|
public static function setGlobals()
|
||||||
{
|
{
|
||||||
self::$get = $_GET;
|
self::$get = $_GET;
|
||||||
@@ -98,6 +115,9 @@ class EventSubscriber
|
|||||||
self::$env = $_ENV;
|
self::$env = $_ENV;
|
||||||
self::$request = $_REQUEST;
|
self::$request = $_REQUEST;
|
||||||
self::$server = $_SERVER;
|
self::$server = $_SERVER;
|
||||||
|
self::$userIp = self::getTheUserIp();
|
||||||
|
self::$sessionId = $_COOKIE['PHPSESSID'] ?? null;
|
||||||
|
|
||||||
|
|
||||||
if (function_exists('getallheaders')) {
|
if (function_exists('getallheaders')) {
|
||||||
self::$headers = getallheaders();
|
self::$headers = getallheaders();
|
||||||
@@ -118,7 +138,22 @@ class EventSubscriber
|
|||||||
'post' => self::$post,
|
'post' => self::$post,
|
||||||
'cookie' => self::$cookie,
|
'cookie' => self::$cookie,
|
||||||
'env' => self::$env,
|
'env' => self::$env,
|
||||||
'headers' => self::$headers
|
'headers' => self::$headers,
|
||||||
|
'user_ip' => self::$userIp,
|
||||||
|
'session_id' => self::$sessionId,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function getTheUserIp()
|
||||||
|
{
|
||||||
|
if ( ! empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||||
|
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||||
|
} elseif ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||||
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||||
|
} else {
|
||||||
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
93
htdocs/wp-content/themes/lawcarta/assets/js/customPopups.js
Normal file
93
htdocs/wp-content/themes/lawcarta/assets/js/customPopups.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
|
||||||
|
window.customConfirm = function(msg, okCallback, cancelCallback) {
|
||||||
|
|
||||||
|
var confirmHtml = '<div class="modal confirm fade" id="modal-confirm" tabindex="-1" role="dialog" aria-hidden="false">' +
|
||||||
|
'<div class="modal-dialog">' +
|
||||||
|
'<div class="modal-body">' +
|
||||||
|
'<div class="cont">' + msg +'</div>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="modal-footer">' +
|
||||||
|
'<div class="cont">' +
|
||||||
|
'<a href="#" class="cancel" id="modal-confirm-cancel">CANCEL</a>' +
|
||||||
|
'<input type="submit" value="Ok" class="button" id="modal-confirm-ok">' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
var okCallbackWrap = function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
if (okCallback) okCallback();
|
||||||
|
$('#modal-confirm').modal('hide');
|
||||||
|
};
|
||||||
|
|
||||||
|
var cancelCallbackWrap = function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
if (cancelCallback) cancelCallback();
|
||||||
|
$('#modal-confirm').modal('hide');
|
||||||
|
};
|
||||||
|
|
||||||
|
var removeCallback = function(){
|
||||||
|
document.getElementById('modal-confirm-ok').removeEventListener("click", okCallbackWrap , false);
|
||||||
|
document.getElementById('modal-confirm-cancel').removeEventListener("click", cancelCallbackWrap , false);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.body.insertAdjacentHTML('beforeEnd', confirmHtml);
|
||||||
|
removeCallback();
|
||||||
|
document.getElementById('modal-confirm-ok').addEventListener("click", okCallbackWrap , false);
|
||||||
|
document.getElementById('modal-confirm-cancel').addEventListener("click", cancelCallbackWrap , false);
|
||||||
|
|
||||||
|
$('#modal-confirm').on('hidden.bs.modal', function(){
|
||||||
|
removeCallback();
|
||||||
|
document.body.removeChild(document.getElementById('modal-confirm'));
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#modal-confirm').modal();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
window.customAlert = function(msg) {
|
||||||
|
|
||||||
|
var confirmHtml = '<div class="modal confirm fade" id="modal-alert" tabindex="-1" role="dialog" aria-hidden="false">' +
|
||||||
|
'<div class="modal-dialog">' +
|
||||||
|
'<div class="modal-body">' +
|
||||||
|
'<div class="cont">' + msg +'</div>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="modal-footer">' +
|
||||||
|
'<div class="cont">' +
|
||||||
|
'<input type="submit" value="Ok" class="button" data-dismiss="modal">' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
document.body.insertAdjacentHTML('beforeEnd', confirmHtml);
|
||||||
|
|
||||||
|
$('#modal-alert').on('hidden.bs.modal', function(){
|
||||||
|
document.body.removeChild(document.getElementById('modal-alert'));
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#modal-alert').modal();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
window.customCopyLink = function(copylink) {
|
||||||
|
|
||||||
|
|
||||||
|
var copyToClipboard = function(str) {
|
||||||
|
var el = document.createElement('textarea');
|
||||||
|
el.classList.add('can-copy');
|
||||||
|
el.value = str;
|
||||||
|
document.body.appendChild(el);
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
$('#modal-copylink').modal('hide');
|
||||||
|
window.customAlert('Link is copied to the clipboard');
|
||||||
|
};
|
||||||
|
|
||||||
|
copyToClipboard(copylink);
|
||||||
|
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user