forked from LiveCarta/LiveCartaWP
Replaced plugin with local copy, removed unused plugins, updated dependencies
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Disable "BIG image" Threshold
|
||||
Description: Disable the big image threshold in WordPress.
|
||||
Author: LawCarta Team
|
||||
Text Domain: disable-image-threshold
|
||||
Version: 1.0
|
||||
*/
|
||||
add_filter('big_image_size_threshold', '__return_false');
|
||||
@@ -1,24 +0,0 @@
|
||||
$(document).ready(function () {
|
||||
$(".lc-subscrive-form").on("submit", function () {
|
||||
var form = $(this)
|
||||
var data = {email: form.find("#subscribe-email").val(), formId: form.find("#subscribe-from-id").val()}
|
||||
$.ajax({
|
||||
url: form.attr('action'),
|
||||
type: 'POST',
|
||||
data: JSON.stringify(data),
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
msg = "<b>Almost finished...</b><br/><br/>We need to confirm your email address.<br/><br/>To complete the subscription process, please click the link in the email we just sent you."
|
||||
customAlert(msg);
|
||||
}
|
||||
form[0].reset()
|
||||
},
|
||||
error: function (jqXHR) {
|
||||
console.log(jqXHR)
|
||||
}
|
||||
});
|
||||
return false;
|
||||
})
|
||||
});
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Plugin Name: SubscribeToLc_Widget
|
||||
Description: A plugin subscribe containing form thous sending email to livecarta API
|
||||
Version: 0.1
|
||||
Author: LiveCarta
|
||||
*/
|
||||
|
||||
class SubscribeToLc_Widget extends WP_Widget
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'subscribe_to_lc_widget',
|
||||
__('Subscribe to lc Widget', 'subscribetolc'),
|
||||
[
|
||||
'classname' => 'subscribetolc_widget',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function widget($args, $instance)
|
||||
{
|
||||
extract($args);
|
||||
if (empty($code)) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script('subscribe-to-lc-js', plugin_dir_url(__FILE__).'js/subscribe.js');
|
||||
|
||||
?>
|
||||
|
||||
<div id="mc_embed_signup">
|
||||
<form action="<?= LAWCARTA_WP_REST_API_URL.'/subscribe/add-member' ?>" method="post" name="mc-embedded-subscribe-form" class="lc-subscrive-form">
|
||||
<div id="mc_embed_signup_scroll">
|
||||
<input type="email" value="" id="subscribe-email" name="Subscribe[email]" class="email" placeholder="Enter your Email" required>
|
||||
|
||||
<input type="hidden" id="subscribe-from-id" name="Subscribe[formId]" tabindex="-1" value="<?= $code ?>">
|
||||
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button xxl mp-top-right">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
public function form($instance)
|
||||
{
|
||||
}
|
||||
|
||||
// Updating widget replacing old instances with new
|
||||
public function update($new_instance, $old_instance)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Register the widget */
|
||||
add_action('widgets_init', function () {
|
||||
register_widget('SubscribeToLc_Widget');
|
||||
});
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
namespace app\wpRestApiEvent;
|
||||
|
||||
/**
|
||||
* Class HttpClient
|
||||
* @package app\wpRestApiEvent
|
||||
*/
|
||||
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
|
||||
* @return null|string
|
||||
*/
|
||||
public function sendRequest($data)
|
||||
{
|
||||
return $this->doPostRequest(LAWCARTA_WP_REST_API_REQUEST_URL, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sysLogId
|
||||
* @param $data
|
||||
* @return string|\WP_Error
|
||||
*/
|
||||
public function sendResponse($sysLogId, $data)
|
||||
{
|
||||
$data['sysLogId'] = $sysLogId;
|
||||
return $this->doPostRequest(LAWCARTA_WP_REST_API_RESPONSE_URL, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $data
|
||||
* @return string|\WP_Error
|
||||
*/
|
||||
private function doPostRequest($url, $data)
|
||||
{
|
||||
$response = wp_remote_post($url, [
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'body' => json_encode($data),
|
||||
'sslverify' => false
|
||||
|
||||
]);
|
||||
$sysLogId = null;
|
||||
/** @var \WP_HTTP_Requests_Response $httpResponse */
|
||||
if(!empty($response['http_response'])){
|
||||
$httpResponse = $response['http_response'];
|
||||
if ($httpResponse->get_status() == 200) {
|
||||
$body = isset($response['body']) ? json_decode($response['body'], true) : null;
|
||||
$sysLogId = $body['sysLogId'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return $sysLogId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HttpClient
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
<?php
|
||||
namespace app\wpRestApiEvent\event;
|
||||
|
||||
|
||||
use app\wpRestApiEvent\HttpClient;
|
||||
/**
|
||||
* Class EventSubscriber
|
||||
* @package app\wpRestApiEvent\event
|
||||
*/
|
||||
class EventSubscriber
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $request;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $get;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $post;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $cookie;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $session;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $env;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $headers;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $server;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $userIp;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $sessionId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $parentSysLogId;
|
||||
|
||||
public static function onInit()
|
||||
{
|
||||
add_action('wpcf7_after_flamingo', [self::class, 'onDemoRequest']);
|
||||
apply_filters('parse_request', [self::class, 'onParseRequest']);
|
||||
// apply_filters('http_response', [self::class, 'onResponse'], 0);
|
||||
//apply_filters('shutdown', [self::class, 'onResponse'], 0);
|
||||
register_shutdown_function([self::class, 'onShutdown']);
|
||||
apply_filters('pre_http_request', [self::class, 'onRequest'], 0);
|
||||
self::onRequest();
|
||||
}
|
||||
|
||||
public static function onRequest()
|
||||
{
|
||||
$client = HttpClient::create();
|
||||
self::$parentSysLogId = $client->sendRequest(self::getSuperGlobals());
|
||||
}
|
||||
|
||||
public static function onResponse(array $response, array $r, $url)
|
||||
{
|
||||
// todo: add response handler
|
||||
}
|
||||
|
||||
public static function onParseRequest()
|
||||
{
|
||||
// todo: add request data from wp
|
||||
}
|
||||
|
||||
public static function onShutdown()
|
||||
{
|
||||
$client = HttpClient::create();
|
||||
$client->sendResponse(self::$parentSysLogId, array_merge(self::getSuperGlobals(), [
|
||||
'headers_list' => headers_list(),
|
||||
'response_code' => http_response_code()
|
||||
]));
|
||||
}
|
||||
|
||||
public static function onDemoRequest()
|
||||
{
|
||||
$client = HttpClient::create();
|
||||
$client->logEvent('demo-request', self::getSuperGlobals());
|
||||
}
|
||||
|
||||
public static function setGlobals()
|
||||
{
|
||||
self::$get = $_GET;
|
||||
self::$post = $_POST;
|
||||
self::$cookie = $_COOKIE;
|
||||
self::$session = $_SESSION;
|
||||
self::$env = $_ENV;
|
||||
self::$request = $_REQUEST;
|
||||
self::$server = $_SERVER;
|
||||
self::$userIp = self::getTheUserIp();
|
||||
self::$sessionId = $_COOKIE['PHPSESSID'] ?? null;
|
||||
|
||||
|
||||
if (function_exists('getallheaders')) {
|
||||
self::$headers = getallheaders();
|
||||
} elseif (function_exists('http_get_request_headers')) {
|
||||
self::$headers = http_get_request_headers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private static function getSuperGlobals()
|
||||
{
|
||||
return [
|
||||
'request' => self::$request,
|
||||
'server' => self::$server,
|
||||
'get' => self::$get,
|
||||
'post' => self::$post,
|
||||
'cookie' => self::$cookie,
|
||||
'env' => self::$env,
|
||||
'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;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: WP-REST-API Event
|
||||
Version: 0.0.1
|
||||
Description:
|
||||
Author:
|
||||
*/
|
||||
|
||||
function wp_rest_api_event_register() {
|
||||
spl_autoload_register(function($class) {
|
||||
$namespace = 'app\\wpRestApiEvent\\';
|
||||
if (false === strpos($class, $namespace)) {
|
||||
return false;
|
||||
}
|
||||
$filename = __DIR__ . '/' . str_replace('\\', '/', str_replace($namespace, '', $class)) . '.php';
|
||||
if (!file_exists($filename)) {
|
||||
return false;
|
||||
}
|
||||
include $filename;
|
||||
return true;
|
||||
});
|
||||
|
||||
\app\wpRestApiEvent\event\EventSubscriber::setGlobals();
|
||||
add_action('init', [\app\wpRestApiEvent\event\EventSubscriber::class, 'onInit']);
|
||||
}
|
||||
|
||||
|
||||
wp_rest_api_event_register();
|
||||
Reference in New Issue
Block a user