Second Pass

This commit is contained in:
2026-01-13 15:37:46 +01:00
parent 4f21d10383
commit 61606fd793
24 changed files with 1516 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?php
/**
* Fired during plugin activation
*
* @link https://github.com/Duskell
* @since 1.0.0
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
*/
/**
* Fired during plugin activation.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since 1.0.0
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
* @author Juhász Levente <juhasz.levente@rendszerepito.hu>
*/
class Partnerexpo_Core_Activator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function activate() {
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Fired during plugin deactivation
*
* @link https://github.com/Duskell
* @since 1.0.0
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
*/
/**
* Fired during plugin deactivation.
*
* This class defines all code necessary to run during the plugin's deactivation.
*
* @since 1.0.0
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
* @author Juhász Levente <juhasz.levente@rendszerepito.hu>
*/
class Partnerexpo_Core_Deactivator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function deactivate() {
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* Define the internationalization functionality
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @link https://github.com/Duskell
* @since 1.0.0
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
*/
/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @since 1.0.0
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
* @author Juhász Levente <juhasz.levente@rendszerepito.hu>
*/
class Partnerexpo_Core_i18n {
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
'partnerexpo-core',
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}
}

View File

@@ -0,0 +1,129 @@
<?php
/**
* Register all actions and filters for the plugin
*
* @link https://github.com/Duskell
* @since 1.0.0
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
*/
/**
* Register all actions and filters for the plugin.
*
* Maintain a list of all hooks that are registered throughout
* the plugin, and register them with the WordPress API. Call the
* run function to execute the list of actions and filters.
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
* @author Juhász Levente <juhasz.levente@rendszerepito.hu>
*/
class Partnerexpo_Core_Loader {
/**
* The array of actions registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
*/
protected $actions;
/**
* The array of filters registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
*/
protected $filters;
/**
* Initialize the collections used to maintain the actions and filters.
*
* @since 1.0.0
*/
public function __construct() {
$this->actions = array();
$this->filters = array();
}
/**
* Add a new action to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @since 1.0.0
* @access private
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args
);
return $hooks;
}
/**
* Register the filters and actions with WordPress.
*
* @since 1.0.0
*/
public function run() {
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}

View File

@@ -0,0 +1,218 @@
<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link https://github.com/Duskell
* @since 1.0.0
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
*/
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since 1.0.0
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/includes
* @author Juhász Levente <juhasz.levente@rendszerepito.hu>
*/
class Partnerexpo_Core {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var Partnerexpo_Core_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
if ( defined( 'PARTNEREXPO_CORE_VERSION' ) ) {
$this->version = PARTNEREXPO_CORE_VERSION;
} else {
$this->version = '1.0.0';
}
$this->plugin_name = 'partnerexpo-core';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Partnerexpo_Core_Loader. Orchestrates the hooks of the plugin.
* - Partnerexpo_Core_i18n. Defines internationalization functionality.
* - Partnerexpo_Core_Admin. Defines all hooks for the admin area.
* - Partnerexpo_Core_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-partnerexpo-core-loader.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-partnerexpo-core-i18n.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-partnerexpo-core-admin.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-partnerexpo-core-public.php';
$this->loader = new Partnerexpo_Core_Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Partnerexpo_Core_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new Partnerexpo_Core_i18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_admin_hooks() {
$plugin_admin = new Partnerexpo_Core_Admin( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_public_hooks() {
$plugin_public = new Partnerexpo_Core_Public( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 1.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 1.0.0
* @return Partnerexpo_Core_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}

View File

@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);
defined('ABSPATH') or die;
class Crypto {
private const VERSION = '1.1';
// --- Configuration ---
private const CIPHER = 'aes-256-gcm';
private const NONCE_LEN = 12;
private const TAG_LEN = 16;
private static function getKey(): string {
$material = (defined('CRYPTO_SALT_1') ? CRYPTO_SALT_1 : AUTH_SALT) .
(defined('CRYPTO_SALT_2') ? CRYPTO_SALT_2 : SECURE_AUTH_SALT) .
'crypto-v1';
return hash('sha256', $material, true); // 32 bytes for AES-256
}
public static function encryptSecret(?string $plaintext): ?string {
if (!is_string($plaintext) || $plaintext === '') {
return null;
}
$key = self::getKey();
$nonce = random_bytes(self::NONCE_LEN);
$ciphertext = openssl_encrypt(
$plaintext,
self::CIPHER,
$key,
OPENSSL_RAW_DATA,
$nonce,
$tag,
'',
self::TAG_LEN
);
if ($ciphertext === false) {
return null;
}
// Package as: [nonce | tag | ciphertext], then base64-encode for storage
return base64_encode($nonce . $tag . $ciphertext);
}
public static function decryptSecret(?string $encoded): ?string {
if (!is_string($encoded) || $encoded === '') {
return null;
}
$blob = base64_decode($encoded, true);
if ($blob === false) {
return null;
}
if (strlen($blob) < self::NONCE_LEN + self::TAG_LEN) {
return null;
}
$nonce = substr($blob, 0, self::NONCE_LEN);
$tag = substr($blob, self::NONCE_LEN, self::TAG_LEN);
$ciphertext = substr($blob, self::NONCE_LEN + self::TAG_LEN);
$key = self::getKey();
$plaintext = openssl_decrypt(
$ciphertext,
self::CIPHER,
$key,
OPENSSL_RAW_DATA,
$nonce,
$tag,
''
);
return ($plaintext === false) ? null : $plaintext;
}
public static function makeKey(bool $random = false, string $prefix = ''): string {
if ($random) {
return $prefix . bin2hex(random_bytes(16));
}
return $prefix . self::uuid7();
}
private static function uuid7(): string {
static $lastUnixMs = null;
static $sequence = 0;
$unixMs = (int) floor(microtime(true) * 1000);
if ($unixMs === $lastUnixMs) {
$sequence = ($sequence + 1) & 0x3FFF;
if ($sequence === 0) {
$unixMs++;
}
} else {
$sequence = random_int(0, 0x3FFF);
$lastUnixMs = $unixMs;
}
$time_high = ($unixMs >> 16) & 0xFFFFFFFF;
$time_low = $unixMs & 0xFFFF;
$time_hi_and_version = ($time_low & 0x0FFF) | (0x7 << 12);
$clock_seq_hi_and_reserved = ($sequence & 0x3FFF) | 0x8000;
$randHex = bin2hex(random_bytes(6));
return sprintf(
'%08x-%04x-%04x-%04x-%012s',
$time_high,
$time_low,
$time_hi_and_version,
$clock_seq_hi_and_reserved,
$randHex
);
}
}

View File

@@ -0,0 +1,97 @@
<?php
defined('ABSPATH') or die;
/**
* Centralized logging and admin notices for the MiniCRM integration.
*/
class Minicrm_Integration_Pb_Logger {
/**
* Log an error and optionally raise an admin notice.
*/
public static function log($message, array $context = [], $raise_notice = true) {
if ( $raise_notice ) {
update_option(
'minicrm_integration_last_error',
[
'message' => $message,
'context' => $context,
'time' => self::now_utc_plus_one()
],
false
);
}
if ( class_exists( '\WC_Logger' ) ) {
$logger = wc_get_logger();
$logger->error($message, array_merge(['source' => 'minicrm-integration'], $context));
return;
}
$context_str = '';
if ( ! empty($context) ) {
$context_str = ' | ' . wp_json_encode($context);
}
error_log('[minicrm-integration] ' . $message . $context_str);
}
/**
* Current time in UTC+1 (Y-m-d H:i:s) using wp_date().
*/
private static function now_utc_plus_one() {
return wp_date( 'Y-m-d H:i:s', time() + HOUR_IN_SECONDS, new DateTimeZone( 'UTC' ) );
}
/**
* Show latest MiniCRM sync error in the admin UI so someone can act on it.
*/
public static function render_admin_notice() {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
$error = get_option( 'minicrm_integration_last_error' );
if ( ! $error || empty( $error['message'] ) ) {
return;
}
$message = esc_html( $error['message'] );
$time = ! empty( $error['time'] ) ? esc_html( $error['time'] ) : '';
$context = '';
if ( ! empty( $error['context'] ) ) {
$context = '<pre style="white-space:pre-wrap;word-break:break-word;margin-top:4px;">' . esc_html( wp_json_encode( $error['context'], JSON_PARTIAL_OUTPUT_ON_ERROR ) ) . '</pre>';
}
$dismiss_url = wp_nonce_url(
add_query_arg( 'minicrm_clear_error', '1' ),
'minicrm_clear_error',
'minicrm_nonce'
);
printf(
'<div class="notice notice-error"><p><strong>MiniCRM integráció hiba:</strong> %s%s%s</p><p><a href="%s" class="button">Megjegyezve, elrejtés</a></p></div>',
$message,
$time ? ' <em>(' . $time . ')</em>' : '',
$context,
esc_url( $dismiss_url )
);
}
/**
* Clear error notice when user dismisses via link.
*/
public static function handle_admin_notice_dismiss() {
if ( ! isset( $_GET['minicrm_clear_error'], $_GET['minicrm_nonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_GET['minicrm_nonce'], 'minicrm_clear_error' ) ) {
return;
}
delete_option( 'minicrm_integration_last_error' );
wp_safe_redirect( remove_query_arg( [ 'minicrm_clear_error', 'minicrm_nonce' ] ) );
exit;
}
}

1
includes/index.php Normal file
View File

@@ -0,0 +1 @@
<?php // Silence is golden