finished comment integration, it should be working now
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
class Partnerexpo_Core_Integrations {
|
||||
public static function add_hooks($loader) {
|
||||
public static function add_hooks($loader, $crm_client) {
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/mc-integrations/com-form.php';
|
||||
|
||||
if ( ! $loader ) {
|
||||
@@ -9,7 +9,9 @@ class Partnerexpo_Core_Integrations {
|
||||
return;
|
||||
}
|
||||
|
||||
$loader->add_action( 'comment_post', Partnerexpo_Core_Integration_Comment_Form::class, 'queue_up', 10, 3 );
|
||||
$loader->add_action( 'process_comment_data', Partnerexpo_Core_Integration_Comment_Form::class, 'run_process', 10, 1 );
|
||||
$comment_form_integration = new Partnerexpo_Core_Integration_Comment_Form($crm_client);
|
||||
|
||||
$loader->add_action( 'comment_post', $comment_form_integration, 'queue_up', 10, 3 );
|
||||
$loader->add_action( 'process_comment_data', $comment_form_integration, 'run_process', 10, 1 );
|
||||
}
|
||||
}
|
||||
@@ -173,11 +173,62 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
wp_die( sprintf('<strong>%s</strong>: %s',__( 'Error', 'partnerexpo-core' ),__( 'Cég megadása kötelező!', 'partnerexpo-core' ) ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset($_POST['last_name']) ) {
|
||||
add_comment_meta(
|
||||
$id,
|
||||
'last_name',
|
||||
sanitize_text_field($_POST['last_name'])
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset($_POST['first_name']) ) {
|
||||
add_comment_meta(
|
||||
$id,
|
||||
'first_name',
|
||||
sanitize_text_field($_POST['first_name'])
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset($_POST['mail']) ) {
|
||||
add_comment_meta(
|
||||
$id,
|
||||
'mail',
|
||||
sanitize_text_field($_POST['mail'])
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset($_POST['phone']) ) {
|
||||
add_comment_meta(
|
||||
$id,
|
||||
'phone',
|
||||
sanitize_text_field($_POST['phone'])
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset($_POST['company']) ) {
|
||||
add_comment_meta(
|
||||
$id,
|
||||
'company',
|
||||
sanitize_text_field($_POST['company'])
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset($_POST['gdpr']) ) {
|
||||
add_comment_meta(
|
||||
$id,
|
||||
'gdpr',
|
||||
sanitize_text_field($_POST['gdpr'])
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset($_POST['newsletter']) ) {
|
||||
add_comment_meta(
|
||||
$id,
|
||||
'newsletter',
|
||||
sanitize_text_field($_POST['newsletter'])
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,10 +126,19 @@ class Partnerexpo_Core {
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/utils/class-query-w-relevance.php';
|
||||
|
||||
include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/utils/class-crypto.php';
|
||||
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/utils/class-logger.php';
|
||||
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/utils/class-crm-client.php';
|
||||
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-partnerexpo-core-integrations.php';
|
||||
|
||||
/**
|
||||
* Action scheduler, used for scheduling comment processing.
|
||||
*/
|
||||
require_once( plugin_dir_path( dirname( __FILE__ ) ) . '/libraries/action-scheduler/action-scheduler.php' );
|
||||
|
||||
/**
|
||||
* The class responsible for registering custom user fields.
|
||||
*/
|
||||
@@ -143,8 +152,9 @@ class Partnerexpo_Core {
|
||||
public function setup() {
|
||||
Logger::init("PartnerEXPO Core", __("Megjegyezve, elrejtés", 'partnerexpo-core'), 'partnerexpo-core');
|
||||
|
||||
$crm_client = new CRMClient(Crypto::encryptSecret(CRM_AUTH));
|
||||
|
||||
Partnerexpo_Core_Integrations::add_hooks( $this->loader );
|
||||
Partnerexpo_Core_Integrations::add_hooks( $this->loader, $crm_client );
|
||||
|
||||
$user_fields = new Partnerexpo_Core_User_Fields( $this->loader );
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @since 1.1.11
|
||||
*
|
||||
* @package Partnerexpo_Core
|
||||
* @subpackage Partnerexpo_Core/includes/mc-integrations
|
||||
* @compackage Partnerexpo_Core/includes/mc-integrations
|
||||
*/
|
||||
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
@@ -15,13 +15,191 @@ if ( ! defined( 'WPINC' ) ) {
|
||||
}
|
||||
|
||||
class Partnerexpo_Core_Integration_Comment_Form {
|
||||
public static function queue_up($comment_id, $comment_approved, $commentdata) {
|
||||
private $client;
|
||||
|
||||
public function __construct($crm_client) {
|
||||
$this->client = $crm_client;
|
||||
}
|
||||
|
||||
public function queue_up($comment_id, $comment_approved, $commentdata) {
|
||||
as_schedule_single_action( time() + 60, 'process_comment_data', [ $comment_id ] );
|
||||
}
|
||||
|
||||
public static function run_process($comment_id) {
|
||||
Logger::log('data', $comment_id);
|
||||
public function run_process($comment_id) {
|
||||
# DATA #
|
||||
$crm_user_id = "Kotlárik Diána, Ügyfélszolgálat";
|
||||
$category_id = 98;
|
||||
$deadline = date("Y-m-d");
|
||||
$com_id_text = __("Komment azonosító", "partnerexpo-core");
|
||||
$task_message = __("Új visszajelzés érkezett a(z) %s oldalra!\n\nVisszajelzés tartalma:\n%s\n\nEzen a linken tudod megtekinteni a visszajelzést a WordPress adminban: %s", "partnerexpo-core");
|
||||
$error_text = __("hiba", "partnerexpo-core");
|
||||
$gdpr_value = 1;
|
||||
$newsletter_value = 1;
|
||||
# # # # #
|
||||
try {
|
||||
|
||||
|
||||
if ( ! $this->client ) {
|
||||
Logger::log(__("MiniCRM Kliens nem található, Szinkronizálás megszakítása!", 'partnerexpo-core'), [$com_id_text => $comment_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
$com_data = get_comment($comment_id, ARRAY_A);
|
||||
|
||||
$data = [
|
||||
'firstName' => get_comment_meta($comment_id, 'first_name', true) ?? '',
|
||||
'lastName' => get_comment_meta($comment_id, 'last_name', true) ?? '',
|
||||
'company' => get_comment_meta($comment_id, 'company', true) ?? '',
|
||||
'email' => get_comment_meta($comment_id, 'mail', true) ?? '',
|
||||
'phone' => get_comment_meta($comment_id, 'phone', true) ?? '',
|
||||
'content' => get_comment_text($comment_id) ?? '',
|
||||
'postTitle' => get_the_title($com_data['comment_post_ID']) ?? '',
|
||||
'editLink' => get_edit_comment_link($comment_id) ?? '',
|
||||
'gdpr' => get_comment_meta($comment_id, 'gdpr', true) ?? '',
|
||||
'newsletter' => get_comment_meta($comment_id, 'newsletter', true) ?? '',
|
||||
];
|
||||
|
||||
# Task messages #
|
||||
|
||||
$message = sprintf($task_message, $data['postTitle'] ?? __("Nincs cím megadva!", "partnerexpo-core"), $data['content'] ?: __("Nincs leírás megadva!", "partnerexpo-core"), $data['editLink'] ?? __("Szerkesztési link nem elérhető!", "partnerexpo-core"));
|
||||
|
||||
# # # # # # # # #
|
||||
|
||||
if (empty($data['email'])) {
|
||||
Logger::log(__("Email nincs megadva, lekérdezés nem lehetséges!", "partnerexpo-core"), [$com_id_text => $comment_id, 'data' => $data]);
|
||||
return;
|
||||
}
|
||||
|
||||
$user_exists = $this->client->get('Contact', ['Email' => $data['email']]);
|
||||
if ( ! is_array($user_exists) ) {
|
||||
Logger::log(__("Kontakt létezésének lekérése sikertelen!", "partnerexpo-core"), [$com_id_text => $comment_id, 'email' => $data['email'], $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = 0;
|
||||
$has_company = true;
|
||||
|
||||
if ($user_exists['Count'] == 0) {
|
||||
$new_contact = $this->client->put('Contact', [
|
||||
'FirstName' => $data['firstName'],
|
||||
'LastName' => $data['lastName'],
|
||||
'Email' => $data['email'],
|
||||
'Phone' => $data['phone'],
|
||||
'Type' => "Person"
|
||||
]);
|
||||
if ( ! is_array($new_contact) || ! isset($new_contact['Id']) ) {
|
||||
Logger::log(__("Kontakt létrehozása sikertelen!", "partnerexpo-core"), [$com_id_text => $comment_id, 'email' => $data['email'], $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
$user_id = $new_contact['Id'];
|
||||
$has_company = false;
|
||||
} else {
|
||||
$user_id = array_key_first($user_exists['Results']);
|
||||
$existing_contact = $this->client->get('Contact/'.$user_id);
|
||||
if ( ! is_array($existing_contact) || ! isset($existing_contact['id']) ) {
|
||||
Logger::log(__("Kontakt adatok lekérése sikertelen!", "partnerexpo-core"), [$com_id_text => $comment_id, 'contact_id' => $user_id, $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
if (!isset($existing_contact['BusinessId']) || empty($existing_contact['BusinessId'])) {
|
||||
$has_company = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ! $user_id ) {
|
||||
Logger::log(__("Kontakt azonosító hiányzik lekérés/létrehozás után is!", "partnerexpo-core"), [$com_id_text => $comment_id, 'email' => $data['email']]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $has_company ) {
|
||||
$comp_exists = $this->client->get('Contact', ['Name' => $data['company'], 'Type' => 'Business']);
|
||||
if ( ! is_array($user_exists) ) {
|
||||
Logger::log(__("Kontakt létezésének lekérése sikertelen!", "partnerexpo-core"), [$com_id_text => $comment_id, 'email' => $data['email'], $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
|
||||
$comp_id = 0;
|
||||
|
||||
if ($comp_exists['Count'] == 0) {
|
||||
$new_comp = $this->client->put('Contact', [
|
||||
'Name' => $data['company'],
|
||||
'ContactId' => $user_id,
|
||||
'Type' => "Business"
|
||||
]);
|
||||
if ( ! is_array($new_comp) || ! isset($new_comp['Id']) ) {
|
||||
Logger::log(__("Cég létrehozása sikertelen!", "partnerexpo-core"), [$com_id_text => $comment_id, 'email' => $data['email'], $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
$comp_id = $new_comp['Id'];
|
||||
} else {
|
||||
$comp_id = array_key_first($comp_exists['Results']);
|
||||
}
|
||||
|
||||
$updated_contact = $this->client->put('Contact/'.$user_id, [
|
||||
'BusinessId' => $comp_id
|
||||
]);
|
||||
}
|
||||
|
||||
if ( ! $comp_id ) {
|
||||
Logger::log(__("Cég azonosító hiányzik lekérés/létrehozás után is!", "partnerexpo-core"), [$com_id_text => $comment_id, 'email' => $data['email']]);
|
||||
return;
|
||||
}
|
||||
|
||||
$card_exists = $this->client->get('Project', ['CategoryId' => $category_id, 'ContactId' => $user_id]);
|
||||
if ( ! is_array($card_exists) ) {
|
||||
Logger::log(__("Adatlap adatok lekérése sikertelen:", "partnerexpo-core"), [$com_id_text => $comment_id, 'contact_id' => $user_id, $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
|
||||
$card_id = 0;
|
||||
|
||||
|
||||
if ($card_exists['Count'] == 0) {
|
||||
$payload = [
|
||||
'CategoryId' => $category_id,
|
||||
'ContactId' => $user_id,
|
||||
'Name' => $data['lastName']. " " .$data['firstName'],
|
||||
'UserId' => $crm_user_id,
|
||||
'GdprNyilatkozat4' => ($data['gdpr'] === 'on') ? 1 : '',
|
||||
'ModeratorRendszerepitoHirlevel2' => ($data['newsletter'] === 'on') ? 1 : ''
|
||||
];
|
||||
|
||||
$new_card = $this->client->put('Project', $payload);
|
||||
if ( ! is_array($new_card) || ! array_key_exists('Id', $new_card) ) {
|
||||
Logger::log(__("Adatlap létrehozás sikertelen:", "partnerexpo-core"), [$com_id_text => $comment_id, 'contact_id' => $user_id, $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
$card_id = $new_card['Id'];
|
||||
|
||||
$result = $this->client->put('ToDo', [
|
||||
'UserId' => $crm_user_id,
|
||||
'ProjectId' => $card_id,
|
||||
'Comment' => $message,
|
||||
'Deadline' => $deadline,
|
||||
]);
|
||||
|
||||
if ( ! is_array($result) ) {
|
||||
Logger::log(__("Teendő létrehozása sikertelen létező adatlap esetén!", "partnerexpo-core"), [$com_id_text => $comment_id, 'project_id' => $card_id, $error_text => $this->client->getLastError()]);
|
||||
}
|
||||
} else {
|
||||
$card_id = array_key_first($card_exists['Results']);
|
||||
|
||||
$result = $this->client->put('ToDo', [
|
||||
'UserId' => $crm_user_id,
|
||||
'ProjectId' => $card_id,
|
||||
'Comment' => $message,
|
||||
'Deadline' => $deadline,
|
||||
]);
|
||||
|
||||
if ( ! is_array($result) ) {
|
||||
Logger::log(__("Teendő létrehozása sikertelen létező adatlap esetén!", "partnerexpo-core"), [$com_id_text => $comment_id, 'project_id' => $card_id, $error_text => $this->client->getLastError()]);
|
||||
}
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
Logger::log(__("Ismeretlen hiba történt a szinkronizálás során!", "partnerexpo-core"), [$com_id_text => $comment_id, 'exception' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
362
includes/utils/class-crm-client.php
Normal file
362
includes/utils/class-crm-client.php
Normal file
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
defined('ABSPATH') or die;
|
||||
|
||||
/**
|
||||
* Minimal abstraction layer for MiniCRM R3 API and Vera R3 API
|
||||
*
|
||||
* The client depends on the crypto class by the same author, make sure to have it loaded beforehand.
|
||||
*
|
||||
* @author Juhász Levente <juhasz.levente@rendszerepito.hu>
|
||||
*
|
||||
* Based on work by Drew McLellan <drew.mclellan@gmail.com>
|
||||
* Source: https://github.com/drewm/mailchimp-api
|
||||
*/
|
||||
class CRMClient {
|
||||
public const VERSION = '1.1';
|
||||
|
||||
private $auth;
|
||||
private $model = "MiniCRM";
|
||||
private $api_endpoint = 'https://r3.minicrm.hu/Api/R3';
|
||||
|
||||
/* SSL Verification
|
||||
Read before disabling:
|
||||
http://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
|
||||
*/
|
||||
public $verify_ssl = true;
|
||||
|
||||
private $request_successful = false;
|
||||
private $last_error = '';
|
||||
private $last_response = [];
|
||||
private $last_request = [];
|
||||
private $last_http_status = 418;
|
||||
|
||||
public function __construct($auth, $model = null, $endpoint = null ) {
|
||||
$this->auth = $auth;
|
||||
$this->last_response = ['headers' => null, 'body' => null];
|
||||
$this->model = $model ?? $this->model;
|
||||
|
||||
if ( $endpoint ) {
|
||||
$this->api_endpoint = $endpoint;
|
||||
} elseif ( $model === 'Vera' ) {
|
||||
$this->api_endpoint = 'https://api.rendszerepito.hu/R3';
|
||||
}
|
||||
}
|
||||
|
||||
public function getApiEndpoint() {
|
||||
return $this->api_endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Was the last message successfull
|
||||
*
|
||||
* @return bool True for success, false for failure
|
||||
*/
|
||||
public function success() {
|
||||
return $this->request_successful;
|
||||
}
|
||||
|
||||
public function getLastError() {
|
||||
return $this->last_error ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array containing the HTTP headers and body of the API request
|
||||
*
|
||||
* @return array assoc array with keys 'headers' and 'body'
|
||||
*/
|
||||
public function getLastResponse() {
|
||||
return $this->last_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP status of the last response
|
||||
*
|
||||
* @return array int
|
||||
*/
|
||||
public function getLastStatus() {
|
||||
return $this->last_http_status;
|
||||
}
|
||||
|
||||
public function get($method, $args = []) {
|
||||
return $this->makeRequest('get', $method, $args);
|
||||
}
|
||||
|
||||
public function put($method, $args = []) {
|
||||
return $this->makeRequest('put', $method, $args);
|
||||
}
|
||||
|
||||
public function post($method, $args = []) {
|
||||
return $this->makeRequest('post', $method, $args);
|
||||
}
|
||||
|
||||
|
||||
private function makeRequest($http_verb, $method, $args = []) {
|
||||
if (! function_exists('curl_init') || ! function_exists('curl_setopt')) {
|
||||
throw new \Exception("cURL support is required, but can't be found!");
|
||||
}
|
||||
|
||||
$url = $this->api_endpoint . '/' . $method;
|
||||
|
||||
$response = $this->prepareStateForRequest($http_verb, $method, $url);
|
||||
|
||||
$httpHeader = [
|
||||
'Accept: application/json',
|
||||
];
|
||||
|
||||
if (!empty($args)) {
|
||||
$httpHeader[] = 'Content-Type: application/json';
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
if ($this-> model == 'MiniCRM') {curl_setopt($ch, CURLOPT_USERPWD, Crypto::decryptSecret($this->auth));}
|
||||
elseif ($this-> model === 'Vera') {$httpHeader[] = 'Authorization: Bearer '.Crypto::decryptSecret($this->auth);}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Levente-CRMClient/'. self::VERSION);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
|
||||
|
||||
switch ($http_verb) {
|
||||
case 'get':
|
||||
if (!empty($args)) {
|
||||
$query = http_build_query($args, '', '&');
|
||||
curl_setopt($ch, CURLOPT_URL, $url . '?' . $query);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'put':
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
$this->attachRequestPayload($ch, $args);
|
||||
break;
|
||||
case 'post':
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
$this->attachRequestPayload($ch, $args);
|
||||
break;
|
||||
}
|
||||
|
||||
$responseContent = curl_exec($ch);
|
||||
$response['headers'] = curl_getinfo($ch);
|
||||
$response = $this->setResponseState($response, $responseContent, $ch);
|
||||
$formattedResponse = $this->formatResponse($response);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$this->determineSuccess($response, $formattedResponse);
|
||||
|
||||
return $formattedResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $http_verb
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
*/
|
||||
private function prepareStateForRequest($http_verb, $method, $url) {
|
||||
$this->last_error = '';
|
||||
|
||||
$this->request_successful = false;
|
||||
|
||||
$this->last_response = [
|
||||
'headers' => null,
|
||||
'httpHeaders' => null,
|
||||
'body' => null,
|
||||
];
|
||||
|
||||
$this->last_request = [
|
||||
'method' => $http_verb,
|
||||
'path' => $method,
|
||||
'url' => $url,
|
||||
'body' => '',
|
||||
];
|
||||
|
||||
return $this->last_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP headers as an array of header-name => header-value pairs.
|
||||
*
|
||||
* The "Link" header is parsed into an associative array based on the
|
||||
* rel names it contains. The original value is available under
|
||||
* the "_raw" key.
|
||||
*
|
||||
* @param string $headersAsString
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getHeadersAsArray($headersAsString)
|
||||
{
|
||||
$headers = [];
|
||||
|
||||
foreach (explode("\r\n", $headersAsString) as $i => $line) {
|
||||
if (0 === $i) { // HTTP code
|
||||
continue;
|
||||
}
|
||||
|
||||
$line = trim($line);
|
||||
if (empty($line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($line, ':') === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list($key, $value) = array_pad(explode(':', $line, 2), 2, '');
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
|
||||
if ('Link' == $key) {
|
||||
$value = array_merge(
|
||||
['_raw' => $value],
|
||||
$this->getLinkHeaderAsArray($value)
|
||||
);
|
||||
}
|
||||
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the data and attach it to the request
|
||||
*
|
||||
* @param resource $ch cURL session handle, used by reference
|
||||
* @param array $data Assoc array of data to attach
|
||||
*/
|
||||
private function attachRequestPayload($ch, $data)
|
||||
{
|
||||
$encoded = json_encode($data);
|
||||
$this->last_request['body'] = $encoded;
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the response and format any error messages for debugging
|
||||
*
|
||||
* @param array $response The response from the curl request
|
||||
*
|
||||
* @return array|false The JSON decoded into an array
|
||||
*/
|
||||
private function formatResponse($response)
|
||||
{
|
||||
$this->last_response = $response;
|
||||
|
||||
$message = null;
|
||||
if (!empty($response['body'])) {
|
||||
$decoded = json_decode($response['body'], true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$message = $decoded;
|
||||
} else {
|
||||
$message = $response['body'];
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract all rel => URL pairs from the provided Link header value
|
||||
*
|
||||
* @param string $linkHeaderAsString
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getLinkHeaderAsArray($linkHeaderAsString)
|
||||
{
|
||||
$urls = [];
|
||||
|
||||
if (preg_match_all('/<(.*?)>\s*;\s*rel="(.*?)"\s*/', $linkHeaderAsString, $matches)) {
|
||||
foreach ($matches[2] as $i => $relName) {
|
||||
$urls[$relName] = $matches[1][$i];
|
||||
}
|
||||
}
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Do post-request formatting and setting state from the response
|
||||
*
|
||||
* @param array $response The response from the curl request
|
||||
* @param string $responseContent The body of the response from the curl request
|
||||
*
|
||||
* * @return array The modified response
|
||||
*/
|
||||
private function setResponseState($response, $responseContent, $ch)
|
||||
{
|
||||
if (false === $responseContent) {
|
||||
$this->last_error = curl_error($ch);
|
||||
} else {
|
||||
$headerSize = $response['headers']['header_size'];
|
||||
$response['httpHeaders'] = $this->getHeadersAsArray(substr($responseContent, 0, $headerSize));
|
||||
$response['body'] = substr($responseContent, $headerSize);
|
||||
|
||||
if (isset($response['headers']['request_header'])) {
|
||||
$this->last_request['headers'] = $response['headers']['request_header'];
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the response was successful or a failure. If it failed, store the error.
|
||||
*
|
||||
* @param array $response The response from the curl request
|
||||
* @param array|false $formattedResponse The response body payload from the curl request
|
||||
*
|
||||
* @return bool If the request was successful
|
||||
*/
|
||||
private function determineSuccess($response, $formattedResponse)
|
||||
{
|
||||
$status = $this->findHTTPStatus($response, $formattedResponse);
|
||||
|
||||
$this->last_http_status = $status;
|
||||
|
||||
if ($status >= 200 && $status <= 299) {
|
||||
$this->request_successful = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($formattedResponse){
|
||||
$this->last_error = sprintf('%d: %s', $status, $formattedResponse);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->last_error = 'Unknown error, call getLastResponse() to find out what happened.';
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the HTTP status code from the headers or API response body
|
||||
*
|
||||
* @param array $response The response from the curl request
|
||||
* @param array|false $formattedResponse The response body payload from the curl request
|
||||
*
|
||||
* @return int HTTP status code
|
||||
*/
|
||||
private function findHTTPStatus($response, $formattedResponse)
|
||||
{
|
||||
if (! empty($response['headers']) && isset($response['headers']['http_code'])) {
|
||||
return (int) $response['headers']['http_code'];
|
||||
}
|
||||
|
||||
if (! empty($response['body']) && isset($formattedResponse['status'])) {
|
||||
return (int) $formattedResponse['status'];
|
||||
}
|
||||
|
||||
return 418;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
* Plugin Name: PartnerExpo Core
|
||||
* Plugin URI: https://partnerexpo.eu
|
||||
* Description: A PartnerEXPO oldal belső pluginja
|
||||
* Version: 1.1.11
|
||||
* Version: 1.1.12
|
||||
* Author: Juhász Levente
|
||||
* Author URI: https://github.com/Duskell/
|
||||
* License: GPL-2.0+
|
||||
@@ -23,7 +23,7 @@ if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
define( 'PARTNEREXPO_CORE_VERSION', '1.1.11' );
|
||||
define( 'PARTNEREXPO_CORE_VERSION', '1.1.12' );
|
||||
|
||||
function activate_partnerexpo_core() {
|
||||
require_once plugin_dir_path( __FILE__ ) . 'includes/class-partnerexpo-core-activator.php';
|
||||
|
||||
@@ -59,9 +59,8 @@ class Partnerexpo_Core_Public {
|
||||
|
||||
public function comments_shortcode($atts) {
|
||||
wp_enqueue_style( $this->plugin_name . '-comments-css' );
|
||||
wp_enqueue_script('jquery');
|
||||
wp_enqueue_script( $this->plugin_name . '-comments-js' );
|
||||
// wp_enqueue_style( $this->plugin_name . '-multiselect-css' );
|
||||
// wp_enqueue_script( $this->plugin_name . '-multiselect-js' );
|
||||
|
||||
$atts = shortcode_atts( array(
|
||||
'post_id' => get_the_ID(),
|
||||
@@ -264,6 +263,15 @@ class Partnerexpo_Core_Public {
|
||||
$this->version,
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
wp_register_script(
|
||||
$this->plugin_name . '-comments-js',
|
||||
plugin_dir_url( __FILE__ ) . 'js/comments.js',
|
||||
[ 'jquery' ],
|
||||
$this->version,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,13 +46,13 @@
|
||||
width: max-content;
|
||||
will-change: transform;
|
||||
animation: scrolling 20s linear infinite;
|
||||
gap: 100px;
|
||||
}
|
||||
|
||||
|
||||
.pexpo-core-comment-group {
|
||||
display: flex;
|
||||
gap: 100px;
|
||||
width: max-content;
|
||||
}
|
||||
|
||||
.pexpo-core-comment {
|
||||
@@ -149,6 +149,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
.pexpo-core-com-consent {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
justify-content: left;
|
||||
font-size: 1.3rem;
|
||||
|
||||
& div {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
|
||||
& input[type="checkbox"] {
|
||||
width: auto;
|
||||
transform: scale(1.2);
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pexpo-core-no-comments {
|
||||
text-align: center;
|
||||
font-size: 1.2rem;
|
||||
@@ -177,6 +199,6 @@
|
||||
|
||||
@keyframes scrolling {
|
||||
to {
|
||||
transform: translate3d(-50%,0,0);
|
||||
transform: translate3d(-50%, 0, 0);
|
||||
}
|
||||
}
|
||||
10
public/js/comments.js
Normal file
10
public/js/comments.js
Normal file
@@ -0,0 +1,10 @@
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
const wrapper = $('.pexpo-core-comment-groups-wrapper').first();
|
||||
const group = wrapper.find('.pexpo-core-comment-group').first();
|
||||
|
||||
let childrenCount = group.children().length;
|
||||
|
||||
if (childrenCount > 3) {
|
||||
wrapper.css('animation', 'scrolling ' + group.children().length * 5 + 's linear infinite');
|
||||
}
|
||||
});
|
||||
@@ -10,6 +10,8 @@
|
||||
* @subpackage Partnerexpo_Core/public/partials
|
||||
*/
|
||||
|
||||
$complience_url = "rendszerepito.hu/adatkezeles";
|
||||
|
||||
?>
|
||||
|
||||
<div class="pexpo-core-comments" id="pexpo-core-comments">
|
||||
@@ -40,14 +42,14 @@
|
||||
<?php echo get_comment_text( $comment ); ?>
|
||||
</div>
|
||||
<div class="pexpo-core-comment-said_by">
|
||||
<?php if ( get_comment_meta( $comment->comment_ID, 'author', true ) ): ?>
|
||||
<?php if ( get_comment_meta( $comment->comment_ID, 'first_name', true ) && get_comment_meta( $comment->comment_ID, 'last_name', true ) ): ?>
|
||||
<div class="pexpo-core-comment-author">
|
||||
<p><?php echo get_comment_meta( $comment->comment_ID, 'author', true ); ?></p>
|
||||
<p><?php echo esc_html( get_comment_meta( $comment->comment_ID, 'first_name', true ) ); ?> <?php echo esc_html( get_comment_meta( $comment->comment_ID, 'last_name', true ) ); ?></p>
|
||||
</div>
|
||||
<p>-</p>
|
||||
<?php endif; ?>
|
||||
<div class="pexpo-core-comment-business">
|
||||
<p><?php echo get_comment_meta( $comment->comment_ID, 'company', true ); ?></p>
|
||||
<p><?php echo esc_html( get_comment_meta( $comment->comment_ID, 'company', true ) ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -69,13 +71,23 @@
|
||||
<div class="pexpo-core-com-form-wrapper">
|
||||
<h2 class="pexpo-core-com-form-title"><?php echo esc_html_x( 'Visszajelzés küldése', 'partnerexpo_core' ); ?></h2>
|
||||
<p class="pexpo-core-com-field">
|
||||
<label for="author"><?php echo esc_html_x( 'Kitöltő neve', 'partnerexpo_core' ); ?></label><br />
|
||||
<input type="text" id="author" name="author" aria-required="true" required>
|
||||
<label for="last_name"><?php echo esc_html_x( 'Vezetéknév', 'partnerexpo_core' ); ?></label><br />
|
||||
<input type="text" id="last_name" name="last_name" aria-required="true" required>
|
||||
</p>
|
||||
|
||||
<p class="pexpo-core-com-field">
|
||||
<label for="email"><?php echo esc_html_x( 'Email cím', 'partnerexpo_core' ); ?></label><br />
|
||||
<input type="email" id="email" name="email" aria-required="true" required>
|
||||
<label for="first_name"><?php echo esc_html_x( 'Keresztnév', 'partnerexpo_core' ); ?></label><br />
|
||||
<input type="text" id="first_name" name="first_name" aria-required="true" required>
|
||||
</p>
|
||||
|
||||
<p class="pexpo-core-com-field">
|
||||
<label for="mail"><?php echo esc_html_x( 'Email cím', 'partnerexpo_core' ); ?></label><br />
|
||||
<input type="mail" id="mail" name="mail" aria-required="true" required>
|
||||
</p>
|
||||
|
||||
<p class="pexpo-core-com-field">
|
||||
<label for="phone"><?php echo esc_html_x( 'Telefonszám', 'partnerexpo_core' ); ?></label><br />
|
||||
<input type="tel" id="phone" name="phone" aria-required="true" required>
|
||||
</p>
|
||||
|
||||
<p class="pexpo-core-com-field">
|
||||
@@ -87,8 +99,13 @@
|
||||
<label for="comment"><?php echo esc_html_x( 'Hozzászólás / Visszajelzés', 'partnerexpo_core' ); ?></label><br />
|
||||
<textarea id="comment" name="comment" aria-required="true" maxlength="600" required></textarea>
|
||||
</p>
|
||||
<div><input type="hidden" name="comment_post_ID" value="<?php echo esc_attr( $post_id ); ?>" id="comment_post_ID"></div>
|
||||
<div><input type="hidden" name="comment_parent" id="comment_parent" value="0"></div></div>
|
||||
|
||||
<div class="pexpo-core-com-consent">
|
||||
<div><input type="checkbox" id="gdpr" name="gdpr" aria-required="true" maxlength="600" required>GDPR <a href="https://<?php echo esc_url( $complience_url ) ?>"><?php echo __( $complience_url ) ?></a> - <?php echo esc_html_x( 'Elfogadom', 'partnerexpo_core' ); ?></input></div>
|
||||
<div><input type="checkbox" id="newsletter" name="newsletter" aria-required="true" maxlength="600"> <?php echo esc_html_x( 'Feliratkozom a hírlevélre.', 'partnerexpo_core' ); ?></input></div></div>
|
||||
|
||||
<div><input type="hidden" name="comment_post_ID" value="<?php echo esc_attr( $post_id ); ?>" id="comment_post_ID" aria-hidden></div>
|
||||
<div><input type="hidden" name="comment_parent" id="comment_parent" value="0" aria-hidden></div></div>
|
||||
<div class="pexpo-core-submit-wrapper">
|
||||
<button type="submit" name="submit" id="submit" class="submit"><?php _e( 'Küldés', 'partnerexpo-core' ); ?></button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user