first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
/**
* File that define P24_External_Multi_Currency class.
*
* @package Przelewy24
*/
defined( 'ABSPATH' ) || exit;
/**
* Class with support for external multi currency.
*/
class P24_MC_External_None implements P24_MC_Interface {
/**
* Check if external multi currency is activated.
*
* This one is always inactive.
*
* @return bool
*/
public function is_multi_currency_active() {
return false;
}
/**
* Check if multi currency is internal.
*
* @return bool
*/
public function is_internal() {
return false;
}
/**
* Get list of available currencies.
*
* @return array
*/
public function get_available_currencies() {
return array();
}
/**
* Get name.
*
* @return string
*/
public function get_name() {
return '';
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* File that define P24_External_Multi_Currency class.
*
* @package Przelewy24
*/
defined( 'ABSPATH' ) || exit;
/**
* Class with support for external multi currency.
*/
class P24_MC_External_WPML implements P24_MC_Interface {
/**
* Get wpml settings.
*
* @return array
*/
private static function get_wpml_settings() {
global $woocommerce_wpml;
if ( $woocommerce_wpml ) {
if ( isset( $woocommerce_wpml->settings['currencies_order'] ) ) {
return $woocommerce_wpml->settings['currencies_order'];
}
}
return array();
}
/**
* Try create instance.
*
* @return null|P24_MC_External_WPML
*/
public static function try_create() {
$settings = self::get_wpml_settings();
if ( $settings ) {
return new self();
} else {
return null;
}
}
/**
* Check if external multi currency is activated.
*
* @return bool
*/
public function is_multi_currency_active() {
$settings = self::get_wpml_settings();
return (bool) $settings;
}
/**
* Check if multi currency is internal.
*
* @return bool
*/
public function is_internal() {
return false;
}
/**
* Get list of available currencies.
*
* @return array
*/
public function get_available_currencies() {
$settings = self::get_wpml_settings();
return array_combine( $settings, $settings );
}
/**
* Get name.
*
* @return string
*/
public function get_name() {
return 'WPML';
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* File that define P24_External_Multi_Currency class.
*
* @package Przelewy24
*/
defined( 'ABSPATH' ) || exit;
/**
* Class with support for external multi currency.
*/
interface P24_MC_Interface {
/**
* Check if external multi currency is activated.
*
* @return bool
*/
public function is_multi_currency_active();
/**
* Check if multi currency is internal.
*
* @return bool
*/
public function is_internal();
/**
* Get list of available currencies.
*
* @return array
*/
public function get_available_currencies();
/**
* Get name of multi currency implementation.
*
* @return string
*/
public function get_name();
}

View File

@@ -0,0 +1,152 @@
<?php
/**
* File that define P24_MC_Pool class.
*
* @package Przelewy24
*/
defined( 'ABSPATH' ) || exit;
/**
* Class that pool all multi currency support.
*/
class P24_MC_Pool {
/**
* Instance of core of plugin.
*
* @var P24_Core
*/
private $plugin_core;
/**
* External multi currency proxy.
*
* @var P24_MC_Interface|null
*/
private $external = null;
/**
* Active currency.
*
* @var string|null
*/
private $active_currency = null;
/**
* P24_MC_Pool constructor.
*
* @param P24_Core $plugin_core Instance of main plugin.
*/
public function __construct( P24_Core $plugin_core ) {
$this->plugin_core = $plugin_core;
}
/**
* Set_active_currency.
*
* @param string $currency Currency.
*/
public function set_active_currency( $currency ) {
$this->active_currency = $currency;
}
/**
* Get external Multi Currency proxy.
*
* @return P24_MC_Interface
*/
public function get_external_mc() {
if ( ! $this->external ) {
$wpml = P24_MC_External_WPML::try_create();
if ( $wpml && $wpml->is_multi_currency_active() ) {
$this->external = $wpml;
} else {
$this->external = new P24_MC_External_None();
}
}
return $this->external;
}
/**
* Get preffered Multi Currency proxy.
*
* @return P24_MC_Interface|null
*/
public function get_preffered_mc() {
if ( $this->plugin_core->is_internal_multi_currency_active() ) {
$mc = $this->plugin_core->get_multi_currency_instance();
} else {
$mc = $this->get_external_mc();
}
return $mc;
}
/**
* Method for filter that change default currency.
*
* The default value is ignored.
* The wrapped function should always return something.
*
* @param string|null $default Default value provided by filter.
* @return string|null
*/
public function check_admin_currency( $default ) {
if ( ! $this->active_currency ) {
$mc = $this->get_preffered_mc();
$available = $mc->get_available_currencies();
wp_verify_nonce( null ); /* There is no noce. */
if ( $this->plugin_core->is_in_json_mode() ) {
if ( array_key_exists( P24_Request_Support::WP_JSON_GET_KEY_CURRENCY, $_GET ) ) {
$this->active_currency = sanitize_text_field( wp_unslash( $_GET[ P24_Request_Support::WP_JSON_GET_KEY_CURRENCY ] ) );
}
} else {
if ( isset( $_COOKIE['admin_p24_currency'] ) ) {
$this->active_currency = sanitize_text_field( wp_unslash( $_COOKIE['admin_p24_currency'] ) );
}
}
if ( ! $this->active_currency || ! array_key_exists( $this->active_currency, $available ) ) {
$this->active_currency = P24_Woo_Commerce_Low_Level_Getter::get_unhooked_currency_form_woocommerce();
}
}
return $this->active_currency ? $this->active_currency : $default;
}
/**
* Get list of available currencies.
*
* It is based on multipliers.
*
* @return array
*/
public function get_available_currencies() {
return $this->get_preffered_mc()->get_available_currencies();
}
/**
* An AJAX method to change currency for admin.
*/
public function admin_ajax_change_currency() {
$mc = $this->get_preffered_mc();
if ( $mc->is_multi_currency_active() ) {
header( 'Content-Type: text/plain; charset=utf-8' );
wc_setcookie( 'admin_p24_currency', $this->check_admin_currency( '' ) );
echo 'Ok';
wp_die();
}
}
/**
* Bind events to use multi currency.
*/
public function bind_events() {
add_action( 'wp_ajax_p24_change_currency', array( $this, 'admin_ajax_change_currency' ) );
add_filter( 'przelewy24_multi_currency_admin_currency', array( $this, 'check_admin_currency' ) );
add_filter( 'przelewy24_multi_currency_options', array( $this, 'get_available_currencies' ) );
}
}