@@ -16,24 +16,24 @@ discard block |
||
16 | 16 | * @return void |
17 | 17 | */ |
18 | 18 | function lsx_currencies_get_price_html( $value = '' ) { |
19 | - $prefix = '<span class="amount lsx-currencies" '; |
|
20 | - $value = preg_replace( '/[^0-9.]+/', '', $value ); |
|
21 | - $decimals = substr_count( $value, '.' ); |
|
19 | + $prefix = '<span class="amount lsx-currencies" '; |
|
20 | + $value = preg_replace( '/[^0-9.]+/', '', $value ); |
|
21 | + $decimals = substr_count( $value, '.' ); |
|
22 | 22 | |
23 | - if ( false !== $decimals && $decimals > 1 ) { |
|
24 | - $decimals--; |
|
25 | - $decimals = (int) $decimals; |
|
26 | - $value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals ); |
|
27 | - } |
|
28 | - $prefix .= '>'; |
|
29 | - $suffix = '</span>'; |
|
30 | - setlocale( LC_MONETARY, 'en_US' ); |
|
23 | + if ( false !== $decimals && $decimals > 1 ) { |
|
24 | + $decimals--; |
|
25 | + $decimals = (int) $decimals; |
|
26 | + $value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals ); |
|
27 | + } |
|
28 | + $prefix .= '>'; |
|
29 | + $suffix = '</span>'; |
|
30 | + setlocale( LC_MONETARY, 'en_US' ); |
|
31 | 31 | |
32 | - // Work out the other tags |
|
33 | - $currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>'; |
|
34 | - $amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( 'USD', '', money_format( '%i', ltrim( rtrim( $value ) ) ) ) ) . '">' . str_replace( 'USD', '', money_format( '%i', ltrim( rtrim( $value ) ) ) ) . '</span>'; |
|
35 | - $price_html = '<span class="amount lsx-currencies">' . $currency . $amount . '</span>'; |
|
36 | - return $price_html; |
|
32 | + // Work out the other tags |
|
33 | + $currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>'; |
|
34 | + $amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( 'USD', '', money_format( '%i', ltrim( rtrim( $value ) ) ) ) ) . '">' . str_replace( 'USD', '', money_format( '%i', ltrim( rtrim( $value ) ) ) ) . '</span>'; |
|
35 | + $price_html = '<span class="amount lsx-currencies">' . $currency . $amount . '</span>'; |
|
36 | + return $price_html; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | * @return void |
44 | 44 | */ |
45 | 45 | function lsx_currency_value( $atts ) { |
46 | - $a = shortcode_atts( |
|
47 | - array( |
|
48 | - 'value' => '0.00', |
|
49 | - ), |
|
50 | - $atts |
|
51 | - ); |
|
52 | - return lsx_currencies_get_price_html( $a['value'] ); |
|
46 | + $a = shortcode_atts( |
|
47 | + array( |
|
48 | + 'value' => '0.00', |
|
49 | + ), |
|
50 | + $atts |
|
51 | + ); |
|
52 | + return lsx_currencies_get_price_html( $a['value'] ); |
|
53 | 53 | } |
54 | 54 | add_shortcode( 'lsx_currency_value', 'lsx_currency_value' ); |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | // If this file is called directly, abort. |
16 | 16 | if ( ! defined( 'WPINC' ) ) { |
17 | - die; |
|
17 | + die; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | define( 'LSX_CURRENCIES_PATH', plugin_dir_path( __FILE__ ) ); |
@@ -31,6 +31,6 @@ discard block |
||
31 | 31 | * @return object \lsx\currencies\classes\Currencies() |
32 | 32 | */ |
33 | 33 | function lsx_currencies() { |
34 | - return \lsx\currencies\classes\Currencies::init(); |
|
34 | + return \lsx\currencies\classes\Currencies::init(); |
|
35 | 35 | } |
36 | 36 | lsx_currencies(); |
@@ -14,37 +14,37 @@ |
||
14 | 14 | */ |
15 | 15 | class LSX_Currencies { |
16 | 16 | |
17 | - /** |
|
18 | - * A wrapper for the deprecated class. |
|
19 | - * |
|
20 | - * @var object |
|
21 | - */ |
|
22 | - public $class = ''; |
|
17 | + /** |
|
18 | + * A wrapper for the deprecated class. |
|
19 | + * |
|
20 | + * @var object |
|
21 | + */ |
|
22 | + public $class = ''; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Holds instance of the class |
|
26 | - * |
|
27 | - * @var object \lsx\currencies\classes\Currencies() |
|
28 | - */ |
|
29 | - private static $instance; |
|
24 | + /** |
|
25 | + * Holds instance of the class |
|
26 | + * |
|
27 | + * @var object \lsx\currencies\classes\Currencies() |
|
28 | + */ |
|
29 | + private static $instance; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor |
|
33 | - */ |
|
34 | - public function __construct() { |
|
35 | - $this->class = lsx_currencies(); |
|
36 | - } |
|
31 | + /** |
|
32 | + * Constructor |
|
33 | + */ |
|
34 | + public function __construct() { |
|
35 | + $this->class = lsx_currencies(); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Return an instance of this class. |
|
40 | - * |
|
41 | - * @return object |
|
42 | - */ |
|
43 | - public static function init() { |
|
44 | - // If the single instance hasn't been set, set it now. |
|
45 | - if ( ! isset( self::$instance ) ) { |
|
46 | - self::$instance = new self(); |
|
47 | - } |
|
48 | - return self::$instance; |
|
49 | - } |
|
38 | + /** |
|
39 | + * Return an instance of this class. |
|
40 | + * |
|
41 | + * @return object |
|
42 | + */ |
|
43 | + public static function init() { |
|
44 | + // If the single instance hasn't been set, set it now. |
|
45 | + if ( ! isset( self::$instance ) ) { |
|
46 | + self::$instance = new self(); |
|
47 | + } |
|
48 | + return self::$instance; |
|
49 | + } |
|
50 | 50 | } |
@@ -16,560 +16,560 @@ |
||
16 | 16 | */ |
17 | 17 | class Currencies { |
18 | 18 | |
19 | - /** |
|
20 | - * Holds instance of the class |
|
21 | - * |
|
22 | - * @var object \lsx\currencies\classes\Currencies() |
|
23 | - */ |
|
24 | - private static $instance; |
|
25 | - |
|
26 | - /** |
|
27 | - * Holds the admin instance |
|
28 | - * |
|
29 | - * @var object \lsx\currencies\classes\Admin() |
|
30 | - */ |
|
31 | - public $admin; |
|
32 | - |
|
33 | - /** |
|
34 | - * Holds the frontend instance |
|
35 | - * |
|
36 | - * @var object \lsx\currencies\classes\Frontedn() |
|
37 | - */ |
|
38 | - public $frontend; |
|
39 | - |
|
40 | - /** |
|
41 | - * Holds the woocommerce instance |
|
42 | - * |
|
43 | - * @var object \lsx\currencies\classes\WooCommerce() |
|
44 | - */ |
|
45 | - public $woocommerce; |
|
46 | - |
|
47 | - /** |
|
48 | - * Holds the FacetWP instance |
|
49 | - * |
|
50 | - * @var object \lsx\currencies\classes\FacetWP() |
|
51 | - */ |
|
52 | - public $facetwp; |
|
53 | - |
|
54 | - /** |
|
55 | - * This hold the URL, it defaults to the free exchange rates. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $api_url = 'https://api.exchangeratesapi.io/latest?base=USD'; |
|
60 | - |
|
61 | - /** |
|
62 | - * General Parameters |
|
63 | - */ |
|
64 | - /** @var string */ |
|
65 | - public $plugin_slug = 'lsx-currencies'; |
|
66 | - |
|
67 | - /** @var array */ |
|
68 | - public $options = false; |
|
69 | - |
|
70 | - /** @var string */ |
|
71 | - public $base_currency = 'USD'; |
|
72 | - |
|
73 | - /** @var array */ |
|
74 | - public $additional_currencies = array(); |
|
75 | - |
|
76 | - /** @var array */ |
|
77 | - public $available_currencies = array(); |
|
78 | - |
|
79 | - /** @var array */ |
|
80 | - public $flag_relations = array(); |
|
81 | - |
|
82 | - /** @var array */ |
|
83 | - public $currency_symbols = array(); |
|
84 | - |
|
85 | - /** @var boolean */ |
|
86 | - public $multi_prices = false; |
|
87 | - |
|
88 | - /** @var boolean */ |
|
89 | - public $convert_to_single = false; |
|
90 | - |
|
91 | - /** @var boolean */ |
|
92 | - public $app_id = false; |
|
93 | - |
|
94 | - /* Currency Switcher Options */ |
|
95 | - /** @var array */ |
|
96 | - public $menus = false; |
|
97 | - |
|
98 | - /** @var boolean */ |
|
99 | - public $display_flags = false; |
|
100 | - |
|
101 | - /** @var string */ |
|
102 | - public $flag_position = 'left'; |
|
103 | - |
|
104 | - /** @var string */ |
|
105 | - public $switcher_symbol_position = 'right'; |
|
106 | - |
|
107 | - /** @var boolean */ |
|
108 | - public $remove_decimals = false; |
|
109 | - |
|
110 | - /** |
|
111 | - * Constructor |
|
112 | - */ |
|
113 | - public function __construct() { |
|
114 | - add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); |
|
115 | - add_action( 'plugins_loaded', array( $this, 'set_defaults' ) ); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Return an instance of this class. |
|
120 | - * |
|
121 | - * @return object |
|
122 | - */ |
|
123 | - public static function init() { |
|
124 | - // If the single instance hasn't been set, set it now. |
|
125 | - if ( ! isset( self::$instance ) ) { |
|
126 | - self::$instance = new self(); |
|
127 | - } |
|
128 | - return self::$instance; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * After active plugins and pluggable functions are loaded |
|
133 | - */ |
|
134 | - public function plugins_loaded() { |
|
135 | - require_once LSX_CURRENCIES_PATH . 'classes/class-admin.php'; |
|
136 | - $this->admin = \lsx\currencies\classes\Admin::init(); |
|
137 | - |
|
138 | - require_once LSX_CURRENCIES_PATH . 'classes/class-frontend.php'; |
|
139 | - $this->frontend = \lsx\currencies\classes\Frontend::init(); |
|
140 | - |
|
141 | - if ( class_exists( 'WooCommerce' ) ) { |
|
142 | - require_once LSX_CURRENCIES_PATH . 'classes/class-woocommerce.php'; |
|
143 | - $this->woocommerce = \lsx\currencies\classes\WooCommerce::init(); |
|
144 | - } |
|
145 | - |
|
146 | - if ( class_exists( 'FacetWP' ) ) { |
|
147 | - require_once LSX_CURRENCIES_PATH . 'classes/class-facetwp.php'; |
|
148 | - $this->facetwp = \lsx\currencies\classes\FacetWP::init(); |
|
149 | - } |
|
150 | - |
|
151 | - require_once LSX_CURRENCIES_PATH . '/includes/template-tags.php'; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Get the options |
|
156 | - */ |
|
157 | - public function set_defaults() { |
|
158 | - $settings_tab = 'display'; |
|
159 | - if ( function_exists( 'tour_operator' ) ) { |
|
160 | - $options = get_option( '_lsx-to_settings', false ); |
|
161 | - $settings_tab = 'general'; |
|
162 | - } else { |
|
163 | - $options = get_option( '_lsx_settings', false ); |
|
164 | - |
|
165 | - if ( false === $options ) { |
|
166 | - $options = get_option( '_lsx_lsx-settings', false ); |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - if ( false !== $options ) { |
|
171 | - $this->options = $options; |
|
172 | - $this->migration_uix_to_customize(); |
|
173 | - |
|
174 | - if ( isset( $this->options[ $settings_tab ] ) && isset( $this->options[ $settings_tab ]['currency'] ) ) { |
|
175 | - $this->base_currency = apply_filters( 'lsx_currencies_base_currency', $this->options[ $settings_tab ]['currency'], $this ); |
|
176 | - } |
|
177 | - |
|
178 | - if ( isset( $this->options[ $settings_tab ]['additional_currencies'] ) && is_array( $this->options[ $settings_tab ]['additional_currencies'] ) && ! empty( $this->options[ $settings_tab ]['additional_currencies'] ) ) { |
|
179 | - $this->additional_currencies = $this->options[ $settings_tab ]['additional_currencies']; |
|
180 | - } |
|
181 | - |
|
182 | - if ( isset( $this->options[ $settings_tab ]['multi_price'] ) && 'on' === $this->options[ $settings_tab ]['multi_price'] ) { |
|
183 | - $this->multi_prices = true; |
|
184 | - } |
|
185 | - |
|
186 | - if ( isset( $this->options[ $settings_tab ]['convert_to_single_currency'] ) && 'on' === $this->options[ $settings_tab ]['convert_to_single_currency'] ) { |
|
187 | - $this->convert_to_single = true; |
|
188 | - } |
|
189 | - |
|
190 | - if ( isset( $this->options[ $settings_tab ]['remove_decimals'] ) && 'on' === $this->options[ $settings_tab ]['remove_decimals'] ) { |
|
191 | - $this->remove_decimals = true; |
|
192 | - } |
|
193 | - |
|
194 | - if ( isset( $this->options['api']['openexchange_api'] ) && '' !== $this->options['api']['openexchange_api'] ) { |
|
195 | - $this->app_id = $this->options['api']['openexchange_api']; |
|
196 | - $this->api_url = 'http://openexchangerates.org/api/latest.json?app_id=' . $this->app_id; |
|
197 | - } |
|
198 | - |
|
199 | - // Currency Switcher Options. |
|
200 | - $this->menus = get_theme_mod( 'lsx_currencies_currency_menu_position', false ); |
|
201 | - |
|
202 | - if ( get_theme_mod( 'lsx_currencies_display_flags', false ) ) { |
|
203 | - $this->display_flags = true; |
|
204 | - } |
|
205 | - |
|
206 | - if ( get_theme_mod( 'lsx_currencies_flag_position', false ) ) { |
|
207 | - $this->flag_position = 'right'; |
|
208 | - } |
|
209 | - |
|
210 | - if ( get_theme_mod( 'lsx_currencies_currency_switcher_position', false ) ) { |
|
211 | - $this->switcher_symbol_position = 'left'; |
|
212 | - } |
|
213 | - } |
|
214 | - $this->available_currencies = $this->get_available_currencies(); |
|
215 | - $this->flag_relations = $this->get_flag_relations(); |
|
216 | - $this->currency_symbols = $this->get_currency_symbols(); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Returns Currency Flag for currency code provided |
|
221 | - * |
|
222 | - * @param $key string |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function get_currency_flag( $key = 'USD' ) { |
|
226 | - $key = strtoupper( $key ); |
|
227 | - return '<span class="flag-icon flag-icon-' . $this->flag_relations[ $key ] . '"></span> '; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Get Currency symbol. |
|
232 | - * |
|
233 | - * @param string $currency |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function get_currency_symbol( $currency = '' ) { |
|
237 | - if ( ! $currency ) { |
|
238 | - $currency = $this->base_currency; |
|
239 | - } |
|
240 | - $currency_symbol = isset( $this->currency_symbols[ $currency ] ) ? $this->currency_symbols[ $currency ] : ''; |
|
241 | - return $currency_symbol; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Returns an array of the available currencies |
|
246 | - * |
|
247 | - * @return array |
|
248 | - */ |
|
249 | - public function get_available_currencies() { |
|
250 | - |
|
251 | - $paid_currencies = array( |
|
252 | - 'BWP' => esc_html__( 'Botswana Pula', 'lsx-currencies' ), |
|
253 | - 'KES' => esc_html__( 'Kenyan Shilling', 'lsx-currencies' ), |
|
254 | - 'LAK' => esc_html__( 'Laos Kip', 'lsx-currencies' ), |
|
255 | - 'MWK' => esc_html__( 'Malawian Kwacha', 'lsx-currencies' ), |
|
256 | - 'MZN' => esc_html__( 'Mozambique Metical', 'lsx-currencies' ), |
|
257 | - 'NAD' => esc_html__( 'Namibian Dollar', 'lsx-currencies' ), |
|
258 | - 'TZS' => esc_html__( 'Tanzania Shilling', 'lsx-currencies' ), |
|
259 | - 'AED' => esc_html__( 'United Arab Emirates Dirham', 'lsx-currencies' ), |
|
260 | - 'ZMW' => esc_html__( 'Zambian Kwacha', 'lsx-currencies' ), |
|
261 | - 'ZWL' => esc_html__( 'Zimbabwean Dollar', 'lsx-currencies' ), |
|
262 | - ); |
|
263 | - $free_currencies = array( |
|
264 | - 'AUD' => esc_html__( 'Australian Dollar', 'lsx-currencies' ), |
|
265 | - 'BRL' => esc_html__( 'Brazilian Real', 'lsx-currencies' ), |
|
266 | - 'GBP' => esc_html__( 'British Pound Sterling', 'lsx-currencies' ), |
|
267 | - 'CAD' => esc_html__( 'Canadian Dollar', 'lsx-currencies' ), |
|
268 | - 'CNY' => esc_html__( 'Chinese Yuan', 'lsx-currencies' ), |
|
269 | - 'EUR' => esc_html__( 'Euro', 'lsx-currencies' ), |
|
270 | - 'HKD' => esc_html__( 'Hong Kong Dollar', 'lsx-currencies' ), |
|
271 | - 'INR' => esc_html__( 'Indian Rupee', 'lsx-currencies' ), |
|
272 | - 'IDR' => esc_html__( 'Indonesia Rupiah', 'lsx-currencies' ), |
|
273 | - 'ILS' => esc_html__( 'Israeli Shekel', 'lsx-currencies' ), |
|
274 | - 'JPY' => esc_html__( 'Japanese Yen', 'lsx-currencies' ), |
|
275 | - 'MYR' => esc_html__( 'Malaysia Ringgit', 'lsx-currencies' ), |
|
276 | - 'NOK' => esc_html__( 'Norwegian Krone', 'lsx-currencies' ), |
|
277 | - 'NZD' => esc_html__( 'New Zealand Dollar', 'lsx-currencies' ), |
|
278 | - 'RUB' => esc_html__( 'Russian Ruble', 'lsx-currencies' ), |
|
279 | - 'SGD' => esc_html__( 'Singapore Dollar', 'lsx-currencies' ), |
|
280 | - 'ZAR' => esc_html__( 'South African Rand', 'lsx-currencies' ), |
|
281 | - 'SEK' => esc_html__( 'Swedish Krona', 'lsx-currencies' ), |
|
282 | - 'CHF' => esc_html__( 'Swiss Franc', 'lsx-currencies' ), |
|
283 | - 'USD' => esc_html__( 'United States Dollar', 'lsx-currencies' ), |
|
284 | - ); |
|
285 | - |
|
286 | - if ( false !== $this->app_id ) { |
|
287 | - $free_currencies = array_merge( $free_currencies, $paid_currencies ); |
|
288 | - asort( $free_currencies ); |
|
289 | - } |
|
290 | - |
|
291 | - return $free_currencies; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Returns the ISO 3 code in relation to its 2 code values. |
|
296 | - * |
|
297 | - * @return array |
|
298 | - */ |
|
299 | - public function get_flag_relations() { |
|
300 | - return array( |
|
301 | - 'AUD' => 'au', |
|
302 | - 'BRL' => 'br', |
|
303 | - 'GBP' => 'gb', |
|
304 | - 'BWP' => 'bw', |
|
305 | - 'CAD' => 'ca', |
|
306 | - 'CNY' => 'cn', |
|
307 | - 'EUR' => 'eu', |
|
308 | - 'HKD' => 'hk', |
|
309 | - 'INR' => 'in', |
|
310 | - 'IDR' => 'id', |
|
311 | - 'ILS' => 'il', |
|
312 | - 'JPY' => 'jp', |
|
313 | - 'KES' => 'ke', |
|
314 | - 'LAK' => 'la', |
|
315 | - 'MWK' => 'mw', |
|
316 | - 'MYR' => 'my', |
|
317 | - 'MZN' => 'mz', |
|
318 | - 'NAD' => 'na', |
|
319 | - 'NZD' => 'nz', |
|
320 | - 'NOK' => 'no', |
|
321 | - 'RUB' => 'ru', |
|
322 | - 'SGD' => 'sg', |
|
323 | - 'ZAR' => 'za', |
|
324 | - 'SEK' => 'se', |
|
325 | - 'CHF' => 'ch', |
|
326 | - 'TZS' => 'tz', |
|
327 | - 'USD' => 'us', |
|
328 | - 'AED' => 'ae', |
|
329 | - 'ZMW' => 'zm', |
|
330 | - 'ZWL' => 'zw', |
|
331 | - ); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Returns all of the currency symbols. |
|
336 | - * |
|
337 | - * @return array |
|
338 | - */ |
|
339 | - public function get_currency_symbols() { |
|
340 | - return apply_filters( 'lsx_currencies_symbols', array( |
|
341 | - 'AED' => 'د.إ', |
|
342 | - 'AFN' => '؋', |
|
343 | - 'ALL' => 'L', |
|
344 | - 'AMD' => 'AMD', |
|
345 | - 'ANG' => 'ƒ', |
|
346 | - 'AOA' => 'Kz', |
|
347 | - 'ARS' => '$', |
|
348 | - 'AUD' => '$', |
|
349 | - 'AWG' => 'Afl.', |
|
350 | - 'AZN' => 'AZN', |
|
351 | - 'BAM' => 'KM', |
|
352 | - 'BBD' => '$', |
|
353 | - 'BDT' => '৳ ', |
|
354 | - 'BGN' => 'лв.', |
|
355 | - 'BHD' => '.د.ب', |
|
356 | - 'BIF' => 'Fr', |
|
357 | - 'BMD' => '$', |
|
358 | - 'BND' => '$', |
|
359 | - 'BOB' => 'Bs.', |
|
360 | - 'BRL' => 'R$', |
|
361 | - 'BSD' => '$', |
|
362 | - 'BTC' => '฿', |
|
363 | - 'BTN' => 'Nu.', |
|
364 | - 'BWP' => 'P', |
|
365 | - 'BYR' => 'Br', |
|
366 | - 'BZD' => '$', |
|
367 | - 'CAD' => '$', |
|
368 | - 'CDF' => 'Fr', |
|
369 | - 'CHF' => 'CHF', |
|
370 | - 'CLP' => '$', |
|
371 | - 'CNY' => '¥', |
|
372 | - 'COP' => '$', |
|
373 | - 'CRC' => '₡', |
|
374 | - 'CUC' => '$', |
|
375 | - 'CUP' => '$', |
|
376 | - 'CVE' => '$', |
|
377 | - 'CZK' => 'Kč', |
|
378 | - 'DJF' => 'Fr', |
|
379 | - 'DKK' => 'DKK', |
|
380 | - 'DOP' => 'RD$', |
|
381 | - 'DZD' => 'د.ج', |
|
382 | - 'EGP' => 'EGP', |
|
383 | - 'ERN' => 'Nfk', |
|
384 | - 'ETB' => 'Br', |
|
385 | - 'EUR' => '€', |
|
386 | - 'FJD' => '$', |
|
387 | - 'FKP' => '£', |
|
388 | - 'GBP' => '£', |
|
389 | - 'GEL' => 'ლ', |
|
390 | - 'GGP' => '£', |
|
391 | - 'GHS' => '₵', |
|
392 | - 'GIP' => '£', |
|
393 | - 'GMD' => 'D', |
|
394 | - 'GNF' => 'Fr', |
|
395 | - 'GTQ' => 'Q', |
|
396 | - 'GYD' => '$', |
|
397 | - 'HKD' => '$', |
|
398 | - 'HNL' => 'L', |
|
399 | - 'HRK' => 'Kn', |
|
400 | - 'HTG' => 'G', |
|
401 | - 'HUF' => 'Ft', |
|
402 | - 'IDR' => 'Rp', |
|
403 | - 'ILS' => '₪', |
|
404 | - 'IMP' => '£', |
|
405 | - 'INR' => '₹', |
|
406 | - 'IQD' => 'ع.د', |
|
407 | - 'IRR' => '﷼', |
|
408 | - 'IRT' => 'تومان', |
|
409 | - 'ISK' => 'kr.', |
|
410 | - 'JEP' => '£', |
|
411 | - 'JMD' => '$', |
|
412 | - 'JOD' => 'د.ا', |
|
413 | - 'JPY' => '¥', |
|
414 | - 'KES' => 'KSh', |
|
415 | - 'KGS' => 'сом', |
|
416 | - 'KHR' => '៛', |
|
417 | - 'KMF' => 'Fr', |
|
418 | - 'KPW' => '₩', |
|
419 | - 'KRW' => '₩', |
|
420 | - 'KWD' => 'د.ك', |
|
421 | - 'KYD' => '$', |
|
422 | - 'KZT' => 'KZT', |
|
423 | - 'LAK' => '₭', |
|
424 | - 'LBP' => 'ل.ل', |
|
425 | - 'LKR' => 'රු', |
|
426 | - 'LRD' => '$', |
|
427 | - 'LSL' => 'L', |
|
428 | - 'LYD' => 'ل.د', |
|
429 | - 'MAD' => 'د.م.', |
|
430 | - 'MDL' => 'MDL', |
|
431 | - 'MGA' => 'Ar', |
|
432 | - 'MKD' => 'ден', |
|
433 | - 'MMK' => 'Ks', |
|
434 | - 'MNT' => '₮', |
|
435 | - 'MOP' => 'P', |
|
436 | - 'MRO' => 'UM', |
|
437 | - 'MUR' => '₨', |
|
438 | - 'MVR' => '.ރ', |
|
439 | - 'MWK' => 'MK', |
|
440 | - 'MXN' => '$', |
|
441 | - 'MYR' => 'RM', |
|
442 | - 'MZN' => 'MT', |
|
443 | - 'NAD' => '$', |
|
444 | - 'NGN' => '₦', |
|
445 | - 'NIO' => 'C$', |
|
446 | - 'NOK' => 'kr', |
|
447 | - 'NPR' => '₨', |
|
448 | - 'NZD' => '$', |
|
449 | - 'OMR' => 'ر.ع.', |
|
450 | - 'PAB' => 'B/.', |
|
451 | - 'PEN' => 'S/.', |
|
452 | - 'PGK' => 'K', |
|
453 | - 'PHP' => '₱', |
|
454 | - 'PKR' => '₨', |
|
455 | - 'PLN' => 'zł', |
|
456 | - 'PRB' => 'р.', |
|
457 | - 'PYG' => '₲', |
|
458 | - 'QAR' => 'ر.ق', |
|
459 | - 'RMB' => '¥', |
|
460 | - 'RON' => 'lei', |
|
461 | - 'RSD' => 'дин.', |
|
462 | - 'RUB' => '₽', |
|
463 | - 'RWF' => 'Fr', |
|
464 | - 'SAR' => 'ر.س', |
|
465 | - 'SBD' => '$', |
|
466 | - 'SCR' => '₨', |
|
467 | - 'SDG' => 'ج.س.', |
|
468 | - 'SEK' => 'kr', |
|
469 | - 'SGD' => '$', |
|
470 | - 'SHP' => '£', |
|
471 | - 'SLL' => 'Le', |
|
472 | - 'SOS' => 'Sh', |
|
473 | - 'SRD' => '$', |
|
474 | - 'SSP' => '£', |
|
475 | - 'STD' => 'Db', |
|
476 | - 'SYP' => 'ل.س', |
|
477 | - 'SZL' => 'L', |
|
478 | - 'THB' => '฿', |
|
479 | - 'TJS' => 'ЅМ', |
|
480 | - 'TMT' => 'm', |
|
481 | - 'TND' => 'د.ت', |
|
482 | - 'TOP' => 'T$', |
|
483 | - 'TRY' => '₺', |
|
484 | - 'TTD' => '$', |
|
485 | - 'TWD' => 'NT$', |
|
486 | - 'TZS' => 'Sh', |
|
487 | - 'UAH' => '₴', |
|
488 | - 'UGX' => 'UGX', |
|
489 | - 'USD' => '$', |
|
490 | - 'UYU' => '$', |
|
491 | - 'UZS' => 'UZS', |
|
492 | - 'VEF' => 'Bs F', |
|
493 | - 'VND' => '₫', |
|
494 | - 'VUV' => 'Vt', |
|
495 | - 'WST' => 'T', |
|
496 | - 'XAF' => 'Fr', |
|
497 | - 'XCD' => '$', |
|
498 | - 'XOF' => 'Fr', |
|
499 | - 'XPF' => 'Fr', |
|
500 | - 'YER' => '﷼', |
|
501 | - 'ZAR' => 'R', |
|
502 | - 'ZMW' => 'ZK', |
|
503 | - ) ); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Sanitize checkbox. |
|
508 | - * |
|
509 | - * @param $input html |
|
510 | - * @return mixed |
|
511 | - */ |
|
512 | - public function sanitize_checkbox( $input ) { |
|
513 | - return ( 1 === absint( $input ) ) ? 1 : 0; |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Sanitize select. |
|
518 | - * |
|
519 | - * @param $input html |
|
520 | - * @return mixed |
|
521 | - */ |
|
522 | - public function sanitize_select( $input ) { |
|
523 | - if ( is_string( $input ) || is_integer( $input ) || is_bool( $input ) ) { |
|
524 | - return $input; |
|
525 | - } else { |
|
526 | - return ''; |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Sanitize textarea. |
|
532 | - * |
|
533 | - * @param $input html |
|
534 | - * @return mixed |
|
535 | - */ |
|
536 | - public function sanitize_textarea( $input ) { |
|
537 | - return wp_kses_post( $input ); |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * Migrate the old data (from UIX) to WP Customizer settings. |
|
542 | - * |
|
543 | - * @since 1.1.1 |
|
544 | - */ |
|
545 | - public function migration_uix_to_customize() { |
|
546 | - $visual_tab_migration = get_theme_mod( 'lsx_currencies_visual_tab_migration', false ); |
|
547 | - |
|
548 | - if ( empty( $visual_tab_migration ) ) { |
|
549 | - if ( isset( $this->options['display'] ) ) { |
|
550 | - if ( isset( $this->options['display']['currency_menu_switcher'] ) && is_array( $this->options['display']['currency_menu_switcher'] ) && ! empty( $this->options['display']['currency_menu_switcher'] ) ) { |
|
551 | - $currency_menu_position = $this->options['display']['currency_menu_switcher']; |
|
552 | - |
|
553 | - foreach ( $currency_menu_position as $key => $value ) { |
|
554 | - set_theme_mod( 'lsx_currencies_currency_menu_position', $key ); |
|
555 | - break; |
|
556 | - } |
|
557 | - } |
|
558 | - |
|
559 | - if ( isset( $this->options['display']['display_flags'] ) && 'on' === $this->options['display']['display_flags'] ) { |
|
560 | - set_theme_mod( 'lsx_currencies_display_flags', true ); |
|
561 | - } |
|
562 | - |
|
563 | - if ( isset( $this->options['display']['flag_position'] ) && 'on' === $this->options['display']['flag_position'] ) { |
|
564 | - set_theme_mod( 'lsx_currencies_flag_position', 'right' ); |
|
565 | - } |
|
566 | - |
|
567 | - if ( isset( $this->options['display']['currency_switcher_position'] ) && 'on' === $this->options['display']['currency_switcher_position'] ) { |
|
568 | - set_theme_mod( 'lsx_currencies_currency_switcher_position', 'left' ); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - set_theme_mod( 'lsx_currencies_visual_tab_migration', true ); |
|
573 | - } |
|
574 | - } |
|
19 | + /** |
|
20 | + * Holds instance of the class |
|
21 | + * |
|
22 | + * @var object \lsx\currencies\classes\Currencies() |
|
23 | + */ |
|
24 | + private static $instance; |
|
25 | + |
|
26 | + /** |
|
27 | + * Holds the admin instance |
|
28 | + * |
|
29 | + * @var object \lsx\currencies\classes\Admin() |
|
30 | + */ |
|
31 | + public $admin; |
|
32 | + |
|
33 | + /** |
|
34 | + * Holds the frontend instance |
|
35 | + * |
|
36 | + * @var object \lsx\currencies\classes\Frontedn() |
|
37 | + */ |
|
38 | + public $frontend; |
|
39 | + |
|
40 | + /** |
|
41 | + * Holds the woocommerce instance |
|
42 | + * |
|
43 | + * @var object \lsx\currencies\classes\WooCommerce() |
|
44 | + */ |
|
45 | + public $woocommerce; |
|
46 | + |
|
47 | + /** |
|
48 | + * Holds the FacetWP instance |
|
49 | + * |
|
50 | + * @var object \lsx\currencies\classes\FacetWP() |
|
51 | + */ |
|
52 | + public $facetwp; |
|
53 | + |
|
54 | + /** |
|
55 | + * This hold the URL, it defaults to the free exchange rates. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $api_url = 'https://api.exchangeratesapi.io/latest?base=USD'; |
|
60 | + |
|
61 | + /** |
|
62 | + * General Parameters |
|
63 | + */ |
|
64 | + /** @var string */ |
|
65 | + public $plugin_slug = 'lsx-currencies'; |
|
66 | + |
|
67 | + /** @var array */ |
|
68 | + public $options = false; |
|
69 | + |
|
70 | + /** @var string */ |
|
71 | + public $base_currency = 'USD'; |
|
72 | + |
|
73 | + /** @var array */ |
|
74 | + public $additional_currencies = array(); |
|
75 | + |
|
76 | + /** @var array */ |
|
77 | + public $available_currencies = array(); |
|
78 | + |
|
79 | + /** @var array */ |
|
80 | + public $flag_relations = array(); |
|
81 | + |
|
82 | + /** @var array */ |
|
83 | + public $currency_symbols = array(); |
|
84 | + |
|
85 | + /** @var boolean */ |
|
86 | + public $multi_prices = false; |
|
87 | + |
|
88 | + /** @var boolean */ |
|
89 | + public $convert_to_single = false; |
|
90 | + |
|
91 | + /** @var boolean */ |
|
92 | + public $app_id = false; |
|
93 | + |
|
94 | + /* Currency Switcher Options */ |
|
95 | + /** @var array */ |
|
96 | + public $menus = false; |
|
97 | + |
|
98 | + /** @var boolean */ |
|
99 | + public $display_flags = false; |
|
100 | + |
|
101 | + /** @var string */ |
|
102 | + public $flag_position = 'left'; |
|
103 | + |
|
104 | + /** @var string */ |
|
105 | + public $switcher_symbol_position = 'right'; |
|
106 | + |
|
107 | + /** @var boolean */ |
|
108 | + public $remove_decimals = false; |
|
109 | + |
|
110 | + /** |
|
111 | + * Constructor |
|
112 | + */ |
|
113 | + public function __construct() { |
|
114 | + add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); |
|
115 | + add_action( 'plugins_loaded', array( $this, 'set_defaults' ) ); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Return an instance of this class. |
|
120 | + * |
|
121 | + * @return object |
|
122 | + */ |
|
123 | + public static function init() { |
|
124 | + // If the single instance hasn't been set, set it now. |
|
125 | + if ( ! isset( self::$instance ) ) { |
|
126 | + self::$instance = new self(); |
|
127 | + } |
|
128 | + return self::$instance; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * After active plugins and pluggable functions are loaded |
|
133 | + */ |
|
134 | + public function plugins_loaded() { |
|
135 | + require_once LSX_CURRENCIES_PATH . 'classes/class-admin.php'; |
|
136 | + $this->admin = \lsx\currencies\classes\Admin::init(); |
|
137 | + |
|
138 | + require_once LSX_CURRENCIES_PATH . 'classes/class-frontend.php'; |
|
139 | + $this->frontend = \lsx\currencies\classes\Frontend::init(); |
|
140 | + |
|
141 | + if ( class_exists( 'WooCommerce' ) ) { |
|
142 | + require_once LSX_CURRENCIES_PATH . 'classes/class-woocommerce.php'; |
|
143 | + $this->woocommerce = \lsx\currencies\classes\WooCommerce::init(); |
|
144 | + } |
|
145 | + |
|
146 | + if ( class_exists( 'FacetWP' ) ) { |
|
147 | + require_once LSX_CURRENCIES_PATH . 'classes/class-facetwp.php'; |
|
148 | + $this->facetwp = \lsx\currencies\classes\FacetWP::init(); |
|
149 | + } |
|
150 | + |
|
151 | + require_once LSX_CURRENCIES_PATH . '/includes/template-tags.php'; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Get the options |
|
156 | + */ |
|
157 | + public function set_defaults() { |
|
158 | + $settings_tab = 'display'; |
|
159 | + if ( function_exists( 'tour_operator' ) ) { |
|
160 | + $options = get_option( '_lsx-to_settings', false ); |
|
161 | + $settings_tab = 'general'; |
|
162 | + } else { |
|
163 | + $options = get_option( '_lsx_settings', false ); |
|
164 | + |
|
165 | + if ( false === $options ) { |
|
166 | + $options = get_option( '_lsx_lsx-settings', false ); |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + if ( false !== $options ) { |
|
171 | + $this->options = $options; |
|
172 | + $this->migration_uix_to_customize(); |
|
173 | + |
|
174 | + if ( isset( $this->options[ $settings_tab ] ) && isset( $this->options[ $settings_tab ]['currency'] ) ) { |
|
175 | + $this->base_currency = apply_filters( 'lsx_currencies_base_currency', $this->options[ $settings_tab ]['currency'], $this ); |
|
176 | + } |
|
177 | + |
|
178 | + if ( isset( $this->options[ $settings_tab ]['additional_currencies'] ) && is_array( $this->options[ $settings_tab ]['additional_currencies'] ) && ! empty( $this->options[ $settings_tab ]['additional_currencies'] ) ) { |
|
179 | + $this->additional_currencies = $this->options[ $settings_tab ]['additional_currencies']; |
|
180 | + } |
|
181 | + |
|
182 | + if ( isset( $this->options[ $settings_tab ]['multi_price'] ) && 'on' === $this->options[ $settings_tab ]['multi_price'] ) { |
|
183 | + $this->multi_prices = true; |
|
184 | + } |
|
185 | + |
|
186 | + if ( isset( $this->options[ $settings_tab ]['convert_to_single_currency'] ) && 'on' === $this->options[ $settings_tab ]['convert_to_single_currency'] ) { |
|
187 | + $this->convert_to_single = true; |
|
188 | + } |
|
189 | + |
|
190 | + if ( isset( $this->options[ $settings_tab ]['remove_decimals'] ) && 'on' === $this->options[ $settings_tab ]['remove_decimals'] ) { |
|
191 | + $this->remove_decimals = true; |
|
192 | + } |
|
193 | + |
|
194 | + if ( isset( $this->options['api']['openexchange_api'] ) && '' !== $this->options['api']['openexchange_api'] ) { |
|
195 | + $this->app_id = $this->options['api']['openexchange_api']; |
|
196 | + $this->api_url = 'http://openexchangerates.org/api/latest.json?app_id=' . $this->app_id; |
|
197 | + } |
|
198 | + |
|
199 | + // Currency Switcher Options. |
|
200 | + $this->menus = get_theme_mod( 'lsx_currencies_currency_menu_position', false ); |
|
201 | + |
|
202 | + if ( get_theme_mod( 'lsx_currencies_display_flags', false ) ) { |
|
203 | + $this->display_flags = true; |
|
204 | + } |
|
205 | + |
|
206 | + if ( get_theme_mod( 'lsx_currencies_flag_position', false ) ) { |
|
207 | + $this->flag_position = 'right'; |
|
208 | + } |
|
209 | + |
|
210 | + if ( get_theme_mod( 'lsx_currencies_currency_switcher_position', false ) ) { |
|
211 | + $this->switcher_symbol_position = 'left'; |
|
212 | + } |
|
213 | + } |
|
214 | + $this->available_currencies = $this->get_available_currencies(); |
|
215 | + $this->flag_relations = $this->get_flag_relations(); |
|
216 | + $this->currency_symbols = $this->get_currency_symbols(); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Returns Currency Flag for currency code provided |
|
221 | + * |
|
222 | + * @param $key string |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function get_currency_flag( $key = 'USD' ) { |
|
226 | + $key = strtoupper( $key ); |
|
227 | + return '<span class="flag-icon flag-icon-' . $this->flag_relations[ $key ] . '"></span> '; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Get Currency symbol. |
|
232 | + * |
|
233 | + * @param string $currency |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function get_currency_symbol( $currency = '' ) { |
|
237 | + if ( ! $currency ) { |
|
238 | + $currency = $this->base_currency; |
|
239 | + } |
|
240 | + $currency_symbol = isset( $this->currency_symbols[ $currency ] ) ? $this->currency_symbols[ $currency ] : ''; |
|
241 | + return $currency_symbol; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Returns an array of the available currencies |
|
246 | + * |
|
247 | + * @return array |
|
248 | + */ |
|
249 | + public function get_available_currencies() { |
|
250 | + |
|
251 | + $paid_currencies = array( |
|
252 | + 'BWP' => esc_html__( 'Botswana Pula', 'lsx-currencies' ), |
|
253 | + 'KES' => esc_html__( 'Kenyan Shilling', 'lsx-currencies' ), |
|
254 | + 'LAK' => esc_html__( 'Laos Kip', 'lsx-currencies' ), |
|
255 | + 'MWK' => esc_html__( 'Malawian Kwacha', 'lsx-currencies' ), |
|
256 | + 'MZN' => esc_html__( 'Mozambique Metical', 'lsx-currencies' ), |
|
257 | + 'NAD' => esc_html__( 'Namibian Dollar', 'lsx-currencies' ), |
|
258 | + 'TZS' => esc_html__( 'Tanzania Shilling', 'lsx-currencies' ), |
|
259 | + 'AED' => esc_html__( 'United Arab Emirates Dirham', 'lsx-currencies' ), |
|
260 | + 'ZMW' => esc_html__( 'Zambian Kwacha', 'lsx-currencies' ), |
|
261 | + 'ZWL' => esc_html__( 'Zimbabwean Dollar', 'lsx-currencies' ), |
|
262 | + ); |
|
263 | + $free_currencies = array( |
|
264 | + 'AUD' => esc_html__( 'Australian Dollar', 'lsx-currencies' ), |
|
265 | + 'BRL' => esc_html__( 'Brazilian Real', 'lsx-currencies' ), |
|
266 | + 'GBP' => esc_html__( 'British Pound Sterling', 'lsx-currencies' ), |
|
267 | + 'CAD' => esc_html__( 'Canadian Dollar', 'lsx-currencies' ), |
|
268 | + 'CNY' => esc_html__( 'Chinese Yuan', 'lsx-currencies' ), |
|
269 | + 'EUR' => esc_html__( 'Euro', 'lsx-currencies' ), |
|
270 | + 'HKD' => esc_html__( 'Hong Kong Dollar', 'lsx-currencies' ), |
|
271 | + 'INR' => esc_html__( 'Indian Rupee', 'lsx-currencies' ), |
|
272 | + 'IDR' => esc_html__( 'Indonesia Rupiah', 'lsx-currencies' ), |
|
273 | + 'ILS' => esc_html__( 'Israeli Shekel', 'lsx-currencies' ), |
|
274 | + 'JPY' => esc_html__( 'Japanese Yen', 'lsx-currencies' ), |
|
275 | + 'MYR' => esc_html__( 'Malaysia Ringgit', 'lsx-currencies' ), |
|
276 | + 'NOK' => esc_html__( 'Norwegian Krone', 'lsx-currencies' ), |
|
277 | + 'NZD' => esc_html__( 'New Zealand Dollar', 'lsx-currencies' ), |
|
278 | + 'RUB' => esc_html__( 'Russian Ruble', 'lsx-currencies' ), |
|
279 | + 'SGD' => esc_html__( 'Singapore Dollar', 'lsx-currencies' ), |
|
280 | + 'ZAR' => esc_html__( 'South African Rand', 'lsx-currencies' ), |
|
281 | + 'SEK' => esc_html__( 'Swedish Krona', 'lsx-currencies' ), |
|
282 | + 'CHF' => esc_html__( 'Swiss Franc', 'lsx-currencies' ), |
|
283 | + 'USD' => esc_html__( 'United States Dollar', 'lsx-currencies' ), |
|
284 | + ); |
|
285 | + |
|
286 | + if ( false !== $this->app_id ) { |
|
287 | + $free_currencies = array_merge( $free_currencies, $paid_currencies ); |
|
288 | + asort( $free_currencies ); |
|
289 | + } |
|
290 | + |
|
291 | + return $free_currencies; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Returns the ISO 3 code in relation to its 2 code values. |
|
296 | + * |
|
297 | + * @return array |
|
298 | + */ |
|
299 | + public function get_flag_relations() { |
|
300 | + return array( |
|
301 | + 'AUD' => 'au', |
|
302 | + 'BRL' => 'br', |
|
303 | + 'GBP' => 'gb', |
|
304 | + 'BWP' => 'bw', |
|
305 | + 'CAD' => 'ca', |
|
306 | + 'CNY' => 'cn', |
|
307 | + 'EUR' => 'eu', |
|
308 | + 'HKD' => 'hk', |
|
309 | + 'INR' => 'in', |
|
310 | + 'IDR' => 'id', |
|
311 | + 'ILS' => 'il', |
|
312 | + 'JPY' => 'jp', |
|
313 | + 'KES' => 'ke', |
|
314 | + 'LAK' => 'la', |
|
315 | + 'MWK' => 'mw', |
|
316 | + 'MYR' => 'my', |
|
317 | + 'MZN' => 'mz', |
|
318 | + 'NAD' => 'na', |
|
319 | + 'NZD' => 'nz', |
|
320 | + 'NOK' => 'no', |
|
321 | + 'RUB' => 'ru', |
|
322 | + 'SGD' => 'sg', |
|
323 | + 'ZAR' => 'za', |
|
324 | + 'SEK' => 'se', |
|
325 | + 'CHF' => 'ch', |
|
326 | + 'TZS' => 'tz', |
|
327 | + 'USD' => 'us', |
|
328 | + 'AED' => 'ae', |
|
329 | + 'ZMW' => 'zm', |
|
330 | + 'ZWL' => 'zw', |
|
331 | + ); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Returns all of the currency symbols. |
|
336 | + * |
|
337 | + * @return array |
|
338 | + */ |
|
339 | + public function get_currency_symbols() { |
|
340 | + return apply_filters( 'lsx_currencies_symbols', array( |
|
341 | + 'AED' => 'د.إ', |
|
342 | + 'AFN' => '؋', |
|
343 | + 'ALL' => 'L', |
|
344 | + 'AMD' => 'AMD', |
|
345 | + 'ANG' => 'ƒ', |
|
346 | + 'AOA' => 'Kz', |
|
347 | + 'ARS' => '$', |
|
348 | + 'AUD' => '$', |
|
349 | + 'AWG' => 'Afl.', |
|
350 | + 'AZN' => 'AZN', |
|
351 | + 'BAM' => 'KM', |
|
352 | + 'BBD' => '$', |
|
353 | + 'BDT' => '৳ ', |
|
354 | + 'BGN' => 'лв.', |
|
355 | + 'BHD' => '.د.ب', |
|
356 | + 'BIF' => 'Fr', |
|
357 | + 'BMD' => '$', |
|
358 | + 'BND' => '$', |
|
359 | + 'BOB' => 'Bs.', |
|
360 | + 'BRL' => 'R$', |
|
361 | + 'BSD' => '$', |
|
362 | + 'BTC' => '฿', |
|
363 | + 'BTN' => 'Nu.', |
|
364 | + 'BWP' => 'P', |
|
365 | + 'BYR' => 'Br', |
|
366 | + 'BZD' => '$', |
|
367 | + 'CAD' => '$', |
|
368 | + 'CDF' => 'Fr', |
|
369 | + 'CHF' => 'CHF', |
|
370 | + 'CLP' => '$', |
|
371 | + 'CNY' => '¥', |
|
372 | + 'COP' => '$', |
|
373 | + 'CRC' => '₡', |
|
374 | + 'CUC' => '$', |
|
375 | + 'CUP' => '$', |
|
376 | + 'CVE' => '$', |
|
377 | + 'CZK' => 'Kč', |
|
378 | + 'DJF' => 'Fr', |
|
379 | + 'DKK' => 'DKK', |
|
380 | + 'DOP' => 'RD$', |
|
381 | + 'DZD' => 'د.ج', |
|
382 | + 'EGP' => 'EGP', |
|
383 | + 'ERN' => 'Nfk', |
|
384 | + 'ETB' => 'Br', |
|
385 | + 'EUR' => '€', |
|
386 | + 'FJD' => '$', |
|
387 | + 'FKP' => '£', |
|
388 | + 'GBP' => '£', |
|
389 | + 'GEL' => 'ლ', |
|
390 | + 'GGP' => '£', |
|
391 | + 'GHS' => '₵', |
|
392 | + 'GIP' => '£', |
|
393 | + 'GMD' => 'D', |
|
394 | + 'GNF' => 'Fr', |
|
395 | + 'GTQ' => 'Q', |
|
396 | + 'GYD' => '$', |
|
397 | + 'HKD' => '$', |
|
398 | + 'HNL' => 'L', |
|
399 | + 'HRK' => 'Kn', |
|
400 | + 'HTG' => 'G', |
|
401 | + 'HUF' => 'Ft', |
|
402 | + 'IDR' => 'Rp', |
|
403 | + 'ILS' => '₪', |
|
404 | + 'IMP' => '£', |
|
405 | + 'INR' => '₹', |
|
406 | + 'IQD' => 'ع.د', |
|
407 | + 'IRR' => '﷼', |
|
408 | + 'IRT' => 'تومان', |
|
409 | + 'ISK' => 'kr.', |
|
410 | + 'JEP' => '£', |
|
411 | + 'JMD' => '$', |
|
412 | + 'JOD' => 'د.ا', |
|
413 | + 'JPY' => '¥', |
|
414 | + 'KES' => 'KSh', |
|
415 | + 'KGS' => 'сом', |
|
416 | + 'KHR' => '៛', |
|
417 | + 'KMF' => 'Fr', |
|
418 | + 'KPW' => '₩', |
|
419 | + 'KRW' => '₩', |
|
420 | + 'KWD' => 'د.ك', |
|
421 | + 'KYD' => '$', |
|
422 | + 'KZT' => 'KZT', |
|
423 | + 'LAK' => '₭', |
|
424 | + 'LBP' => 'ل.ل', |
|
425 | + 'LKR' => 'රු', |
|
426 | + 'LRD' => '$', |
|
427 | + 'LSL' => 'L', |
|
428 | + 'LYD' => 'ل.د', |
|
429 | + 'MAD' => 'د.م.', |
|
430 | + 'MDL' => 'MDL', |
|
431 | + 'MGA' => 'Ar', |
|
432 | + 'MKD' => 'ден', |
|
433 | + 'MMK' => 'Ks', |
|
434 | + 'MNT' => '₮', |
|
435 | + 'MOP' => 'P', |
|
436 | + 'MRO' => 'UM', |
|
437 | + 'MUR' => '₨', |
|
438 | + 'MVR' => '.ރ', |
|
439 | + 'MWK' => 'MK', |
|
440 | + 'MXN' => '$', |
|
441 | + 'MYR' => 'RM', |
|
442 | + 'MZN' => 'MT', |
|
443 | + 'NAD' => '$', |
|
444 | + 'NGN' => '₦', |
|
445 | + 'NIO' => 'C$', |
|
446 | + 'NOK' => 'kr', |
|
447 | + 'NPR' => '₨', |
|
448 | + 'NZD' => '$', |
|
449 | + 'OMR' => 'ر.ع.', |
|
450 | + 'PAB' => 'B/.', |
|
451 | + 'PEN' => 'S/.', |
|
452 | + 'PGK' => 'K', |
|
453 | + 'PHP' => '₱', |
|
454 | + 'PKR' => '₨', |
|
455 | + 'PLN' => 'zł', |
|
456 | + 'PRB' => 'р.', |
|
457 | + 'PYG' => '₲', |
|
458 | + 'QAR' => 'ر.ق', |
|
459 | + 'RMB' => '¥', |
|
460 | + 'RON' => 'lei', |
|
461 | + 'RSD' => 'дин.', |
|
462 | + 'RUB' => '₽', |
|
463 | + 'RWF' => 'Fr', |
|
464 | + 'SAR' => 'ر.س', |
|
465 | + 'SBD' => '$', |
|
466 | + 'SCR' => '₨', |
|
467 | + 'SDG' => 'ج.س.', |
|
468 | + 'SEK' => 'kr', |
|
469 | + 'SGD' => '$', |
|
470 | + 'SHP' => '£', |
|
471 | + 'SLL' => 'Le', |
|
472 | + 'SOS' => 'Sh', |
|
473 | + 'SRD' => '$', |
|
474 | + 'SSP' => '£', |
|
475 | + 'STD' => 'Db', |
|
476 | + 'SYP' => 'ل.س', |
|
477 | + 'SZL' => 'L', |
|
478 | + 'THB' => '฿', |
|
479 | + 'TJS' => 'ЅМ', |
|
480 | + 'TMT' => 'm', |
|
481 | + 'TND' => 'د.ت', |
|
482 | + 'TOP' => 'T$', |
|
483 | + 'TRY' => '₺', |
|
484 | + 'TTD' => '$', |
|
485 | + 'TWD' => 'NT$', |
|
486 | + 'TZS' => 'Sh', |
|
487 | + 'UAH' => '₴', |
|
488 | + 'UGX' => 'UGX', |
|
489 | + 'USD' => '$', |
|
490 | + 'UYU' => '$', |
|
491 | + 'UZS' => 'UZS', |
|
492 | + 'VEF' => 'Bs F', |
|
493 | + 'VND' => '₫', |
|
494 | + 'VUV' => 'Vt', |
|
495 | + 'WST' => 'T', |
|
496 | + 'XAF' => 'Fr', |
|
497 | + 'XCD' => '$', |
|
498 | + 'XOF' => 'Fr', |
|
499 | + 'XPF' => 'Fr', |
|
500 | + 'YER' => '﷼', |
|
501 | + 'ZAR' => 'R', |
|
502 | + 'ZMW' => 'ZK', |
|
503 | + ) ); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Sanitize checkbox. |
|
508 | + * |
|
509 | + * @param $input html |
|
510 | + * @return mixed |
|
511 | + */ |
|
512 | + public function sanitize_checkbox( $input ) { |
|
513 | + return ( 1 === absint( $input ) ) ? 1 : 0; |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Sanitize select. |
|
518 | + * |
|
519 | + * @param $input html |
|
520 | + * @return mixed |
|
521 | + */ |
|
522 | + public function sanitize_select( $input ) { |
|
523 | + if ( is_string( $input ) || is_integer( $input ) || is_bool( $input ) ) { |
|
524 | + return $input; |
|
525 | + } else { |
|
526 | + return ''; |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Sanitize textarea. |
|
532 | + * |
|
533 | + * @param $input html |
|
534 | + * @return mixed |
|
535 | + */ |
|
536 | + public function sanitize_textarea( $input ) { |
|
537 | + return wp_kses_post( $input ); |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * Migrate the old data (from UIX) to WP Customizer settings. |
|
542 | + * |
|
543 | + * @since 1.1.1 |
|
544 | + */ |
|
545 | + public function migration_uix_to_customize() { |
|
546 | + $visual_tab_migration = get_theme_mod( 'lsx_currencies_visual_tab_migration', false ); |
|
547 | + |
|
548 | + if ( empty( $visual_tab_migration ) ) { |
|
549 | + if ( isset( $this->options['display'] ) ) { |
|
550 | + if ( isset( $this->options['display']['currency_menu_switcher'] ) && is_array( $this->options['display']['currency_menu_switcher'] ) && ! empty( $this->options['display']['currency_menu_switcher'] ) ) { |
|
551 | + $currency_menu_position = $this->options['display']['currency_menu_switcher']; |
|
552 | + |
|
553 | + foreach ( $currency_menu_position as $key => $value ) { |
|
554 | + set_theme_mod( 'lsx_currencies_currency_menu_position', $key ); |
|
555 | + break; |
|
556 | + } |
|
557 | + } |
|
558 | + |
|
559 | + if ( isset( $this->options['display']['display_flags'] ) && 'on' === $this->options['display']['display_flags'] ) { |
|
560 | + set_theme_mod( 'lsx_currencies_display_flags', true ); |
|
561 | + } |
|
562 | + |
|
563 | + if ( isset( $this->options['display']['flag_position'] ) && 'on' === $this->options['display']['flag_position'] ) { |
|
564 | + set_theme_mod( 'lsx_currencies_flag_position', 'right' ); |
|
565 | + } |
|
566 | + |
|
567 | + if ( isset( $this->options['display']['currency_switcher_position'] ) && 'on' === $this->options['display']['currency_switcher_position'] ) { |
|
568 | + set_theme_mod( 'lsx_currencies_currency_switcher_position', 'left' ); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + set_theme_mod( 'lsx_currencies_visual_tab_migration', true ); |
|
573 | + } |
|
574 | + } |
|
575 | 575 | } |
@@ -16,80 +16,80 @@ |
||
16 | 16 | */ |
17 | 17 | class WooCommerce { |
18 | 18 | |
19 | - /** |
|
20 | - * Holds instance of the class |
|
21 | - * |
|
22 | - * @var object \lsx\currencies\classes\WooCommerce() |
|
23 | - */ |
|
24 | - private static $instance; |
|
19 | + /** |
|
20 | + * Holds instance of the class |
|
21 | + * |
|
22 | + * @var object \lsx\currencies\classes\WooCommerce() |
|
23 | + */ |
|
24 | + private static $instance; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Holds the current currency. |
|
28 | - * |
|
29 | - * @var boolean |
|
30 | - */ |
|
31 | - public $currency = false; |
|
26 | + /** |
|
27 | + * Holds the current currency. |
|
28 | + * |
|
29 | + * @var boolean |
|
30 | + */ |
|
31 | + public $currency = false; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor |
|
35 | - */ |
|
36 | - public function __construct() { |
|
37 | - add_filter( 'wc_price', array( $this, 'price_filter' ), 300, 3 ); |
|
38 | - add_filter( 'lsx_currencies_base_currency', array( $this, 'set_base_currency' ), 10, 1 ); |
|
39 | - } |
|
33 | + /** |
|
34 | + * Constructor |
|
35 | + */ |
|
36 | + public function __construct() { |
|
37 | + add_filter( 'wc_price', array( $this, 'price_filter' ), 300, 3 ); |
|
38 | + add_filter( 'lsx_currencies_base_currency', array( $this, 'set_base_currency' ), 10, 1 ); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Return an instance of this class. |
|
43 | - * |
|
44 | - * @return object |
|
45 | - */ |
|
46 | - public static function init() { |
|
47 | - // If the single instance hasn't been set, set it now. |
|
48 | - if ( ! isset( self::$instance ) ) { |
|
49 | - self::$instance = new self(); |
|
50 | - } |
|
51 | - return self::$instance; |
|
52 | - } |
|
41 | + /** |
|
42 | + * Return an instance of this class. |
|
43 | + * |
|
44 | + * @return object |
|
45 | + */ |
|
46 | + public static function init() { |
|
47 | + // If the single instance hasn't been set, set it now. |
|
48 | + if ( ! isset( self::$instance ) ) { |
|
49 | + self::$instance = new self(); |
|
50 | + } |
|
51 | + return self::$instance; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Filter the WooCommerce Price. |
|
56 | - * |
|
57 | - * @param $return mixed |
|
58 | - * @param $price string |
|
59 | - * @param $args array |
|
60 | - * |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - public function price_filter( $return, $price, $args ) { |
|
64 | - if ( '' !== $price ) { |
|
65 | - $return = str_replace( 'class', 'data-price-' . lsx_currencies()->base_currency . '=' . $price . ' class', $return ); |
|
66 | - $return = str_replace( 'woocommerce-Price-amount', 'woocommerce-Price-amount lsx-currencies', $return ); |
|
67 | - } |
|
68 | - return $return; |
|
69 | - } |
|
54 | + /** |
|
55 | + * Filter the WooCommerce Price. |
|
56 | + * |
|
57 | + * @param $return mixed |
|
58 | + * @param $price string |
|
59 | + * @param $args array |
|
60 | + * |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + public function price_filter( $return, $price, $args ) { |
|
64 | + if ( '' !== $price ) { |
|
65 | + $return = str_replace( 'class', 'data-price-' . lsx_currencies()->base_currency . '=' . $price . ' class', $return ); |
|
66 | + $return = str_replace( 'woocommerce-Price-amount', 'woocommerce-Price-amount lsx-currencies', $return ); |
|
67 | + } |
|
68 | + return $return; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param $cart_subtotal |
|
73 | - * @param $compound |
|
74 | - * @param $obj |
|
75 | - * |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - public function cart_subtotal( $cart_subtotal, $compound, $obj ) { |
|
71 | + /** |
|
72 | + * @param $cart_subtotal |
|
73 | + * @param $compound |
|
74 | + * @param $obj |
|
75 | + * |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + public function cart_subtotal( $cart_subtotal, $compound, $obj ) { |
|
79 | 79 | |
80 | - $return = str_replace( 'class', 'data-price-' . $this->currency . '=' . $price . ' class', $return ); |
|
81 | - $return = str_replace( 'woocommerce-Price-amount', 'woocommerce-Price-amount lsx-currencies', $return ); |
|
80 | + $return = str_replace( 'class', 'data-price-' . $this->currency . '=' . $price . ' class', $return ); |
|
81 | + $return = str_replace( 'woocommerce-Price-amount', 'woocommerce-Price-amount lsx-currencies', $return ); |
|
82 | 82 | |
83 | - return $cart_subtotal; |
|
84 | - } |
|
83 | + return $cart_subtotal; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Make sure our base currency is set to the same as woocommerce. |
|
88 | - * |
|
89 | - * @param string $currency |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function set_base_currency( $currency ) { |
|
93 | - return get_woocommerce_currency(); |
|
94 | - } |
|
86 | + /** |
|
87 | + * Make sure our base currency is set to the same as woocommerce. |
|
88 | + * |
|
89 | + * @param string $currency |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function set_base_currency( $currency ) { |
|
93 | + return get_woocommerce_currency(); |
|
94 | + } |
|
95 | 95 | } |
@@ -1,20 +1,20 @@ discard block |
||
1 | 1 | <div class="uix-field-wrapper"> |
2 | 2 | <?php |
3 | - $display_settings_page = false; |
|
3 | + $display_settings_page = false; |
|
4 | 4 | |
5 | - if ( class_exists( 'LSX_Currencies' ) ) { |
|
6 | - $display_settings_page = true; |
|
7 | - } |
|
8 | - ?> |
|
5 | + if ( class_exists( 'LSX_Currencies' ) ) { |
|
6 | + $display_settings_page = true; |
|
7 | + } |
|
8 | + ?> |
|
9 | 9 | |
10 | 10 | <ul class="ui-tab-nav"> |
11 | 11 | <?php |
12 | - if ( false !== $display_settings_page ) { |
|
12 | + if ( false !== $display_settings_page ) { |
|
13 | 13 | ?> |
14 | 14 | <li><a href="#ui-settings" class="active"><?php esc_html_e( 'Settings', 'lsx-currencies' ); ?></a></li><?php } ?> |
15 | 15 | <li><a href="#ui-keys" |
16 | 16 | <?php |
17 | - if ( false === $display_settings_page ) { |
|
17 | + if ( false === $display_settings_page ) { |
|
18 | 18 | ?> |
19 | 19 | class="active"<?php } ?>><?php esc_html_e( 'License Keys', 'lsx-currencies' ); ?></a></li> |
20 | 20 | </ul> |
@@ -33,25 +33,25 @@ discard block |
||
33 | 33 | |
34 | 34 | <div id="ui-keys" class="ui-tab |
35 | 35 | <?php |
36 | - if ( false === $display_settings_page ) { |
|
36 | + if ( false === $display_settings_page ) { |
|
37 | 37 | ?> |
38 | 38 | active<?php } ?>"> |
39 | 39 | <table class="form-table" style="margin-top:-13px !important;"> |
40 | 40 | <tbody> |
41 | 41 | <?php |
42 | - $lsx = admin_url( 'themes.php?page=lsx-welcome' ); |
|
43 | - $message = sprintf( "Please enter the license and API key's for your add-ons below." ); |
|
44 | - $message .= sprintf( " Follow this <a href='%s' title='LSX add-ons'>link</a> to see what extensions are available for LSX.", $lsx ); |
|
45 | - ?> |
|
42 | + $lsx = admin_url( 'themes.php?page=lsx-welcome' ); |
|
43 | + $message = sprintf( "Please enter the license and API key's for your add-ons below." ); |
|
44 | + $message .= sprintf( " Follow this <a href='%s' title='LSX add-ons'>link</a> to see what extensions are available for LSX.", $lsx ); |
|
45 | + ?> |
|
46 | 46 | |
47 | 47 | <p class="info"><?php echo wp_kses_post( $message ); ?></p> |
48 | 48 | |
49 | 49 | <?php |
50 | - $api_keys_content = false; |
|
51 | - ob_start(); |
|
52 | - do_action( 'lsx_framework_api_tab_content', 'api' ); |
|
53 | - $api_keys_content = ob_end_clean(); |
|
54 | - ?> |
|
50 | + $api_keys_content = false; |
|
51 | + ob_start(); |
|
52 | + do_action( 'lsx_framework_api_tab_content', 'api' ); |
|
53 | + $api_keys_content = ob_end_clean(); |
|
54 | + ?> |
|
55 | 55 | </tbody> |
56 | 56 | </table> |
57 | 57 | </div> |
@@ -16,104 +16,104 @@ |
||
16 | 16 | */ |
17 | 17 | class FacetWP { |
18 | 18 | |
19 | - /** |
|
20 | - * Holds instance of the class |
|
21 | - * |
|
22 | - * @var object \lsx\currencies\classes\FacetWP() |
|
23 | - */ |
|
24 | - private static $instance; |
|
19 | + /** |
|
20 | + * Holds instance of the class |
|
21 | + * |
|
22 | + * @var object \lsx\currencies\classes\FacetWP() |
|
23 | + */ |
|
24 | + private static $instance; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Holds the current currency. |
|
28 | - * |
|
29 | - * @var boolean |
|
30 | - */ |
|
31 | - public $currency = false; |
|
26 | + /** |
|
27 | + * Holds the current currency. |
|
28 | + * |
|
29 | + * @var boolean |
|
30 | + */ |
|
31 | + public $currency = false; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor |
|
35 | - */ |
|
36 | - public function __construct() { |
|
37 | - add_filter( 'facetwp_indexer_row_data', array( $this, 'facetwp_index_row_data' ), 20, 2 ); |
|
38 | - add_action( 'lsx_currencies_rates_refreshed', array( $this, 'refresh_the_currencies' ), 20 ); |
|
39 | - } |
|
33 | + /** |
|
34 | + * Constructor |
|
35 | + */ |
|
36 | + public function __construct() { |
|
37 | + add_filter( 'facetwp_indexer_row_data', array( $this, 'facetwp_index_row_data' ), 20, 2 ); |
|
38 | + add_action( 'lsx_currencies_rates_refreshed', array( $this, 'refresh_the_currencies' ), 20 ); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Return an instance of this class. |
|
43 | - * |
|
44 | - * @return object |
|
45 | - */ |
|
46 | - public static function init() { |
|
47 | - // If the single instance hasn't been set, set it now. |
|
48 | - if ( ! isset( self::$instance ) ) { |
|
49 | - self::$instance = new self(); |
|
50 | - } |
|
51 | - return self::$instance; |
|
52 | - } |
|
41 | + /** |
|
42 | + * Return an instance of this class. |
|
43 | + * |
|
44 | + * @return object |
|
45 | + */ |
|
46 | + public static function init() { |
|
47 | + // If the single instance hasn't been set, set it now. |
|
48 | + if ( ! isset( self::$instance ) ) { |
|
49 | + self::$instance = new self(); |
|
50 | + } |
|
51 | + return self::$instance; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Alter the rows and include extra facets rows for the continents. |
|
56 | - */ |
|
57 | - public function facetwp_index_row_data( $rows, $params ) { |
|
58 | - switch ( $params['facet']['source'] ) { |
|
59 | - case 'cf/price': |
|
60 | - // only convert a price to the base currency if the setting is active. |
|
61 | - // If $rows is empty then there is no base currency set. |
|
62 | - if ( true === lsx_currencies()->convert_to_single && empty( $rows ) ) { |
|
63 | - lsx_currencies()->frontend->set_defaults(); |
|
64 | - $additional_prices = get_post_meta( $params['defaults']['post_id'], 'additional_prices', false ); |
|
54 | + /** |
|
55 | + * Alter the rows and include extra facets rows for the continents. |
|
56 | + */ |
|
57 | + public function facetwp_index_row_data( $rows, $params ) { |
|
58 | + switch ( $params['facet']['source'] ) { |
|
59 | + case 'cf/price': |
|
60 | + // only convert a price to the base currency if the setting is active. |
|
61 | + // If $rows is empty then there is no base currency set. |
|
62 | + if ( true === lsx_currencies()->convert_to_single && empty( $rows ) ) { |
|
63 | + lsx_currencies()->frontend->set_defaults(); |
|
64 | + $additional_prices = get_post_meta( $params['defaults']['post_id'], 'additional_prices', false ); |
|
65 | 65 | |
66 | - if ( ! empty( $additional_prices ) && isset( $additional_prices[0] ) && ! empty( lsx_currencies()->frontend->rates ) ) { |
|
67 | - $row_currency = $additional_prices[0]['currency']; |
|
68 | - $row_value = $additional_prices[0]['amount']; |
|
69 | - $current_currency = lsx_currencies()->frontend->current_currency; |
|
70 | - $usd_value = $row_value / lsx_currencies()->frontend->rates->$row_currency; |
|
71 | - if ( $row_currency !== $current_currency ) { |
|
72 | - $usd_value = $usd_value * lsx_currencies()->frontend->rates->$current_currency; |
|
73 | - } |
|
74 | - $new_row = $params['defaults']; |
|
75 | - $new_row['facet_value'] = round( $usd_value, 0 ); |
|
76 | - $new_row['facet_display_value'] = round( $usd_value, 0 ); |
|
77 | - $rows[] = $new_row; |
|
78 | - } |
|
79 | - } |
|
80 | - break; |
|
66 | + if ( ! empty( $additional_prices ) && isset( $additional_prices[0] ) && ! empty( lsx_currencies()->frontend->rates ) ) { |
|
67 | + $row_currency = $additional_prices[0]['currency']; |
|
68 | + $row_value = $additional_prices[0]['amount']; |
|
69 | + $current_currency = lsx_currencies()->frontend->current_currency; |
|
70 | + $usd_value = $row_value / lsx_currencies()->frontend->rates->$row_currency; |
|
71 | + if ( $row_currency !== $current_currency ) { |
|
72 | + $usd_value = $usd_value * lsx_currencies()->frontend->rates->$current_currency; |
|
73 | + } |
|
74 | + $new_row = $params['defaults']; |
|
75 | + $new_row['facet_value'] = round( $usd_value, 0 ); |
|
76 | + $new_row['facet_display_value'] = round( $usd_value, 0 ); |
|
77 | + $rows[] = $new_row; |
|
78 | + } |
|
79 | + } |
|
80 | + break; |
|
81 | 81 | |
82 | - default: |
|
83 | - break; |
|
84 | - } |
|
85 | - return $rows; |
|
86 | - } |
|
82 | + default: |
|
83 | + break; |
|
84 | + } |
|
85 | + return $rows; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * This will refresh the saved currencies that ar not the same as the base currency. |
|
90 | - * |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - public function refresh_the_currencies() { |
|
94 | - if ( true === lsx_currencies()->convert_to_single ) { |
|
95 | - add_action( 'wp_footer', array( $this, 'trigger_the_index' ) ); |
|
96 | - } |
|
97 | - } |
|
88 | + /** |
|
89 | + * This will refresh the saved currencies that ar not the same as the base currency. |
|
90 | + * |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + public function refresh_the_currencies() { |
|
94 | + if ( true === lsx_currencies()->convert_to_single ) { |
|
95 | + add_action( 'wp_footer', array( $this, 'trigger_the_index' ) ); |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Grabs the tour ids and runs them through the index. |
|
101 | - * |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - public function trigger_the_index() { |
|
105 | - $tours_args = array( |
|
106 | - 'post_type' => 'tour', |
|
107 | - 'post_status' => 'publish', |
|
108 | - 'posts_per_page' => '-1', |
|
109 | - 'nopagin' => true, |
|
110 | - 'fields' => 'ids', |
|
111 | - ); |
|
112 | - $tours_query = new \WP_Query( $tours_args ); |
|
113 | - if ( $tours_query->have_posts() ) { |
|
114 | - foreach ( $tours_query->posts as $tour_id ) { |
|
115 | - FWP()->indexer->index( $tour_id ); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
99 | + /** |
|
100 | + * Grabs the tour ids and runs them through the index. |
|
101 | + * |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + public function trigger_the_index() { |
|
105 | + $tours_args = array( |
|
106 | + 'post_type' => 'tour', |
|
107 | + 'post_status' => 'publish', |
|
108 | + 'posts_per_page' => '-1', |
|
109 | + 'nopagin' => true, |
|
110 | + 'fields' => 'ids', |
|
111 | + ); |
|
112 | + $tours_query = new \WP_Query( $tours_args ); |
|
113 | + if ( $tours_query->have_posts() ) { |
|
114 | + foreach ( $tours_query->posts as $tour_id ) { |
|
115 | + FWP()->indexer->index( $tour_id ); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | } |
@@ -16,95 +16,95 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class Admin { |
18 | 18 | |
19 | - /** |
|
20 | - * Holds instance of the class |
|
21 | - * |
|
22 | - * @var object \lsx\currencies\classes\Admin() |
|
23 | - */ |
|
24 | - private static $instance; |
|
25 | - |
|
26 | - /** |
|
27 | - * Constructor |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
31 | - add_action( 'init', array( $this, 'create_settings_page' ), 100 ); |
|
32 | - add_filter( 'lsx_framework_settings_tabs', array( $this, 'register_tabs' ), 100, 1 ); |
|
33 | - add_filter( 'lsx_to_tour_custom_fields', array( $this, 'fields' ), 80, 1 ); |
|
34 | - add_action( 'customize_register', array( $this, 'customize_register' ), 20 ); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Return an instance of this class. |
|
39 | - * |
|
40 | - * @return object |
|
41 | - */ |
|
42 | - public static function init() { |
|
43 | - // If the single instance hasn't been set, set it now. |
|
44 | - if ( ! isset( self::$instance ) ) { |
|
45 | - self::$instance = new self(); |
|
46 | - } |
|
47 | - return self::$instance; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Enques the assets |
|
52 | - */ |
|
53 | - public function assets() { |
|
54 | - //wp_enqueue_script( 'lsx-currencies-admin', LSX_CURRENCIES_URL . 'assets/js/lsx-currencies-admin.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true ); |
|
55 | - wp_enqueue_style( 'lsx-currencies-admin', LSX_CURRENCIES_URL . 'assets/css/lsx-currencies-admin.css', array(), LSX_CURRENCIES_VER ); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Returns the array of settings to the UIX Class |
|
60 | - */ |
|
61 | - public function create_settings_page() { |
|
62 | - if ( is_admin() ) { |
|
63 | - if ( ! class_exists( '\lsx\ui\uix' ) && ! function_exists( 'tour_operator' ) ) { |
|
64 | - include_once LSX_CURRENCIES_PATH . 'vendor/uix/uix.php'; |
|
65 | - $pages = $this->settings_page_array(); |
|
66 | - $uix = \lsx\ui\uix::get_instance( 'lsx' ); |
|
67 | - $uix->register_pages( $pages ); |
|
68 | - } |
|
69 | - add_action( 'lsx_to_framework_dashboard_tab_content', array( $this, 'general_settings' ), 11, 1 ); |
|
70 | - add_action( 'lsx_to_framework_api_tab_content', array( $this, 'api_settings' ), 11, 1 ); |
|
71 | - |
|
72 | - add_action( 'lsx_framework_display_tab_content', array( $this, 'general_settings' ), 11, 1 ); |
|
73 | - add_action( 'lsx_framework_api_tab_content', array( $this, 'api_settings' ), 11, 1 ); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Returns the array of settings to the UIX Class |
|
79 | - */ |
|
80 | - public function settings_page_array() { |
|
81 | - $tabs = apply_filters( 'lsx_framework_settings_tabs', array() ); |
|
82 | - |
|
83 | - return array( |
|
84 | - 'settings' => array( |
|
85 | - 'page_title' => esc_html__( 'Theme Options', 'lsx-currencies' ), |
|
86 | - 'menu_title' => esc_html__( 'Theme Options', 'lsx-currencies' ), |
|
87 | - 'capability' => 'manage_options', |
|
88 | - 'icon' => 'dashicons-book-alt', |
|
89 | - 'parent' => 'themes.php', |
|
90 | - 'save_button' => esc_html__( 'Save Changes', 'lsx-currencies' ), |
|
91 | - 'tabs' => $tabs, |
|
92 | - ), |
|
93 | - ); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Register tabs |
|
98 | - */ |
|
99 | - public function register_tabs( $tabs ) { |
|
100 | - $default = true; |
|
101 | - |
|
102 | - if ( false !== $tabs && is_array( $tabs ) && count( $tabs ) > 0 ) { |
|
103 | - $default = false; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! function_exists( 'tour_operator' ) ) { |
|
107 | - /*if ( ! array_key_exists( 'general', $tabs ) ) { |
|
19 | + /** |
|
20 | + * Holds instance of the class |
|
21 | + * |
|
22 | + * @var object \lsx\currencies\classes\Admin() |
|
23 | + */ |
|
24 | + private static $instance; |
|
25 | + |
|
26 | + /** |
|
27 | + * Constructor |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
31 | + add_action( 'init', array( $this, 'create_settings_page' ), 100 ); |
|
32 | + add_filter( 'lsx_framework_settings_tabs', array( $this, 'register_tabs' ), 100, 1 ); |
|
33 | + add_filter( 'lsx_to_tour_custom_fields', array( $this, 'fields' ), 80, 1 ); |
|
34 | + add_action( 'customize_register', array( $this, 'customize_register' ), 20 ); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Return an instance of this class. |
|
39 | + * |
|
40 | + * @return object |
|
41 | + */ |
|
42 | + public static function init() { |
|
43 | + // If the single instance hasn't been set, set it now. |
|
44 | + if ( ! isset( self::$instance ) ) { |
|
45 | + self::$instance = new self(); |
|
46 | + } |
|
47 | + return self::$instance; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Enques the assets |
|
52 | + */ |
|
53 | + public function assets() { |
|
54 | + //wp_enqueue_script( 'lsx-currencies-admin', LSX_CURRENCIES_URL . 'assets/js/lsx-currencies-admin.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true ); |
|
55 | + wp_enqueue_style( 'lsx-currencies-admin', LSX_CURRENCIES_URL . 'assets/css/lsx-currencies-admin.css', array(), LSX_CURRENCIES_VER ); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Returns the array of settings to the UIX Class |
|
60 | + */ |
|
61 | + public function create_settings_page() { |
|
62 | + if ( is_admin() ) { |
|
63 | + if ( ! class_exists( '\lsx\ui\uix' ) && ! function_exists( 'tour_operator' ) ) { |
|
64 | + include_once LSX_CURRENCIES_PATH . 'vendor/uix/uix.php'; |
|
65 | + $pages = $this->settings_page_array(); |
|
66 | + $uix = \lsx\ui\uix::get_instance( 'lsx' ); |
|
67 | + $uix->register_pages( $pages ); |
|
68 | + } |
|
69 | + add_action( 'lsx_to_framework_dashboard_tab_content', array( $this, 'general_settings' ), 11, 1 ); |
|
70 | + add_action( 'lsx_to_framework_api_tab_content', array( $this, 'api_settings' ), 11, 1 ); |
|
71 | + |
|
72 | + add_action( 'lsx_framework_display_tab_content', array( $this, 'general_settings' ), 11, 1 ); |
|
73 | + add_action( 'lsx_framework_api_tab_content', array( $this, 'api_settings' ), 11, 1 ); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Returns the array of settings to the UIX Class |
|
79 | + */ |
|
80 | + public function settings_page_array() { |
|
81 | + $tabs = apply_filters( 'lsx_framework_settings_tabs', array() ); |
|
82 | + |
|
83 | + return array( |
|
84 | + 'settings' => array( |
|
85 | + 'page_title' => esc_html__( 'Theme Options', 'lsx-currencies' ), |
|
86 | + 'menu_title' => esc_html__( 'Theme Options', 'lsx-currencies' ), |
|
87 | + 'capability' => 'manage_options', |
|
88 | + 'icon' => 'dashicons-book-alt', |
|
89 | + 'parent' => 'themes.php', |
|
90 | + 'save_button' => esc_html__( 'Save Changes', 'lsx-currencies' ), |
|
91 | + 'tabs' => $tabs, |
|
92 | + ), |
|
93 | + ); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Register tabs |
|
98 | + */ |
|
99 | + public function register_tabs( $tabs ) { |
|
100 | + $default = true; |
|
101 | + |
|
102 | + if ( false !== $tabs && is_array( $tabs ) && count( $tabs ) > 0 ) { |
|
103 | + $default = false; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! function_exists( 'tour_operator' ) ) { |
|
107 | + /*if ( ! array_key_exists( 'general', $tabs ) ) { |
|
108 | 108 | $tabs['general'] = array( |
109 | 109 | 'page_title' => '', |
110 | 110 | 'page_description' => '', |
@@ -116,161 +116,161 @@ discard block |
||
116 | 116 | $default = false; |
117 | 117 | }*/ |
118 | 118 | |
119 | - if ( ! array_key_exists( 'display', $tabs ) ) { |
|
120 | - $tabs['display'] = array( |
|
121 | - 'page_title' => '', |
|
122 | - 'page_description' => '', |
|
123 | - 'menu_title' => esc_html__( 'Display', 'lsx-currencies' ), |
|
124 | - 'template' => LSX_CURRENCIES_PATH . 'includes/settings/display.php', |
|
125 | - 'default' => $default, |
|
126 | - ); |
|
127 | - |
|
128 | - $default = false; |
|
129 | - } |
|
130 | - |
|
131 | - if ( ! array_key_exists( 'api', $tabs ) ) { |
|
132 | - $tabs['api'] = array( |
|
133 | - 'page_title' => '', |
|
134 | - 'page_description' => '', |
|
135 | - 'menu_title' => esc_html__( 'API', 'lsx-currencies' ), |
|
136 | - 'template' => LSX_CURRENCIES_PATH . 'includes/settings/api.php', |
|
137 | - 'default' => $default, |
|
138 | - ); |
|
139 | - |
|
140 | - $default = false; |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - return $tabs; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Outputs the dashboard tabs settings |
|
149 | - * |
|
150 | - * @param $tab string |
|
151 | - * @return null |
|
152 | - */ |
|
153 | - public function general_settings( $tab = 'general' ) { |
|
154 | - if ( 'currency_switcher' === $tab ) { |
|
155 | - $this->base_currency_field(); |
|
156 | - $this->additional_currencies_field(); |
|
157 | - $this->remove_decimals_field(); |
|
158 | - if ( function_exists( 'tour_operator' ) ) { |
|
159 | - $this->enable_multiple_prices_field(); |
|
160 | - $this->enable_convert_to_single_currency_field(); |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Outputs the dashboard tabs settings |
|
167 | - * |
|
168 | - * @param $tab string |
|
169 | - * @return null |
|
170 | - */ |
|
171 | - public function api_settings( $tab = 'general' ) { |
|
172 | - if ( 'settings' === $tab ) { |
|
173 | - $this->currency_api_heading(); |
|
174 | - $this->api_key_field(); |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Outputs the base currency drop down |
|
180 | - */ |
|
181 | - public function base_currency_field() { |
|
182 | - ?> |
|
119 | + if ( ! array_key_exists( 'display', $tabs ) ) { |
|
120 | + $tabs['display'] = array( |
|
121 | + 'page_title' => '', |
|
122 | + 'page_description' => '', |
|
123 | + 'menu_title' => esc_html__( 'Display', 'lsx-currencies' ), |
|
124 | + 'template' => LSX_CURRENCIES_PATH . 'includes/settings/display.php', |
|
125 | + 'default' => $default, |
|
126 | + ); |
|
127 | + |
|
128 | + $default = false; |
|
129 | + } |
|
130 | + |
|
131 | + if ( ! array_key_exists( 'api', $tabs ) ) { |
|
132 | + $tabs['api'] = array( |
|
133 | + 'page_title' => '', |
|
134 | + 'page_description' => '', |
|
135 | + 'menu_title' => esc_html__( 'API', 'lsx-currencies' ), |
|
136 | + 'template' => LSX_CURRENCIES_PATH . 'includes/settings/api.php', |
|
137 | + 'default' => $default, |
|
138 | + ); |
|
139 | + |
|
140 | + $default = false; |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + return $tabs; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Outputs the dashboard tabs settings |
|
149 | + * |
|
150 | + * @param $tab string |
|
151 | + * @return null |
|
152 | + */ |
|
153 | + public function general_settings( $tab = 'general' ) { |
|
154 | + if ( 'currency_switcher' === $tab ) { |
|
155 | + $this->base_currency_field(); |
|
156 | + $this->additional_currencies_field(); |
|
157 | + $this->remove_decimals_field(); |
|
158 | + if ( function_exists( 'tour_operator' ) ) { |
|
159 | + $this->enable_multiple_prices_field(); |
|
160 | + $this->enable_convert_to_single_currency_field(); |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Outputs the dashboard tabs settings |
|
167 | + * |
|
168 | + * @param $tab string |
|
169 | + * @return null |
|
170 | + */ |
|
171 | + public function api_settings( $tab = 'general' ) { |
|
172 | + if ( 'settings' === $tab ) { |
|
173 | + $this->currency_api_heading(); |
|
174 | + $this->api_key_field(); |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Outputs the base currency drop down |
|
180 | + */ |
|
181 | + public function base_currency_field() { |
|
182 | + ?> |
|
183 | 183 | <tr data-trigger="additional_currencies" class="lsx-select-trigger form-field-wrap"> |
184 | 184 | <th scope="row"> |
185 | 185 | <label for="currency"> |
186 | 186 | <?php |
187 | - esc_html_e( 'Base Currency', 'lsx-currencies' ); |
|
188 | - ?> |
|
187 | + esc_html_e( 'Base Currency', 'lsx-currencies' ); |
|
188 | + ?> |
|
189 | 189 | </label> |
190 | 190 | </th> |
191 | 191 | <td> |
192 | 192 | <?php |
193 | - if ( ! function_exists( 'WC' ) ) { |
|
194 | - ?> |
|
193 | + if ( ! function_exists( 'WC' ) ) { |
|
194 | + ?> |
|
195 | 195 | <select value="{{currency}}" name="currency"> |
196 | 196 | <?php |
197 | - foreach ( lsx_currencies()->available_currencies as $currency_id => $currency_label ) { |
|
198 | - $selected = ''; |
|
199 | - |
|
200 | - if ( lsx_currencies()->base_currency === $currency_id ) { |
|
201 | - $selected = 'selected="selected"'; |
|
202 | - } |
|
203 | - $allowed_html = array( |
|
204 | - 'option' => array( |
|
205 | - 'value' => array(), |
|
206 | - 'selected' => array(), |
|
207 | - ), |
|
208 | - ); |
|
209 | - echo wp_kses( '<option value="' . $currency_id . '" ' . $selected . '>' . $currency_label . '</option>', $allowed_html ); |
|
210 | - } |
|
211 | - ?> |
|
197 | + foreach ( lsx_currencies()->available_currencies as $currency_id => $currency_label ) { |
|
198 | + $selected = ''; |
|
199 | + |
|
200 | + if ( lsx_currencies()->base_currency === $currency_id ) { |
|
201 | + $selected = 'selected="selected"'; |
|
202 | + } |
|
203 | + $allowed_html = array( |
|
204 | + 'option' => array( |
|
205 | + 'value' => array(), |
|
206 | + 'selected' => array(), |
|
207 | + ), |
|
208 | + ); |
|
209 | + echo wp_kses( '<option value="' . $currency_id . '" ' . $selected . '>' . $currency_label . '</option>', $allowed_html ); |
|
210 | + } |
|
211 | + ?> |
|
212 | 212 | </select> |
213 | 213 | <?php |
214 | - } else { |
|
215 | - $currency_label = ''; |
|
216 | - if ( isset( lsx_currencies()->available_currencies[ lsx_currencies()->base_currency ] ) ) { |
|
217 | - $currency_label = lsx_currencies()->available_currencies[ lsx_currencies()->base_currency ]; |
|
218 | - } |
|
219 | - ?> |
|
214 | + } else { |
|
215 | + $currency_label = ''; |
|
216 | + if ( isset( lsx_currencies()->available_currencies[ lsx_currencies()->base_currency ] ) ) { |
|
217 | + $currency_label = lsx_currencies()->available_currencies[ lsx_currencies()->base_currency ]; |
|
218 | + } |
|
219 | + ?> |
|
220 | 220 | <p><?php echo wp_kses_post( lsx_currencies()->get_currency_flag( lsx_currencies()->base_currency ) ); ?> <?php echo esc_attr( $currency_label ); ?></p> |
221 | 221 | <p><small><?php esc_html_e( 'When WooCommerce is active, that currency is used as the base currency.', 'lsx-currencies' ); ?></small></p> |
222 | 222 | <?php |
223 | - } |
|
224 | - ?> |
|
223 | + } |
|
224 | + ?> |
|
225 | 225 | </td> |
226 | 226 | </tr> |
227 | 227 | <?php |
228 | - } |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * Outputs the additional currencies checkboxes |
|
232 | - */ |
|
233 | - public function additional_currencies_field() { |
|
234 | - ?> |
|
230 | + /** |
|
231 | + * Outputs the additional currencies checkboxes |
|
232 | + */ |
|
233 | + public function additional_currencies_field() { |
|
234 | + ?> |
|
235 | 235 | <tr data-trigger="currency" class="lsx-checkbox-action form-field-wrap"> |
236 | 236 | <th scope="row"> |
237 | 237 | <label for="modules"> |
238 | 238 | <?php |
239 | - esc_html_e( 'Additional Currencies', 'lsx-currencies' ); |
|
240 | - ?> |
|
239 | + esc_html_e( 'Additional Currencies', 'lsx-currencies' ); |
|
240 | + ?> |
|
241 | 241 | </label> |
242 | 242 | </th> |
243 | 243 | <td> |
244 | 244 | <ul> |
245 | 245 | <?php |
246 | - foreach ( lsx_currencies()->available_currencies as $slug => $label ) { |
|
247 | - $checked = ''; |
|
248 | - $hidden = $checked; |
|
249 | - if ( array_key_exists( $slug, lsx_currencies()->additional_currencies ) || lsx_currencies()->base_currency === $slug ) { |
|
250 | - $checked = 'checked="checked"'; |
|
251 | - } |
|
252 | - |
|
253 | - if ( lsx_currencies()->base_currency === $slug ) { |
|
254 | - $hidden = 'style="display:none;" class="hidden"'; |
|
255 | - } |
|
256 | - ?> |
|
246 | + foreach ( lsx_currencies()->available_currencies as $slug => $label ) { |
|
247 | + $checked = ''; |
|
248 | + $hidden = $checked; |
|
249 | + if ( array_key_exists( $slug, lsx_currencies()->additional_currencies ) || lsx_currencies()->base_currency === $slug ) { |
|
250 | + $checked = 'checked="checked"'; |
|
251 | + } |
|
252 | + |
|
253 | + if ( lsx_currencies()->base_currency === $slug ) { |
|
254 | + $hidden = 'style="display:none;" class="hidden"'; |
|
255 | + } |
|
256 | + ?> |
|
257 | 257 | <li <?php echo wp_kses_post( $hidden ); ?>> |
258 | 258 | <input type="checkbox" <?php echo esc_attr( $checked ); ?> data-name="additional_currencies" data-value="<?php echo esc_attr( $slug ); ?>" name="additional_currencies[<?php echo esc_attr( $slug ); ?>]" /> <label for="additional_currencies"><?php echo wp_kses_post( lsx_currencies()->get_currency_flag( $slug ) . $label ); ?></label> |
259 | 259 | </li> |
260 | 260 | <?php |
261 | - } |
|
262 | - ?> |
|
261 | + } |
|
262 | + ?> |
|
263 | 263 | </ul> |
264 | 264 | </td> |
265 | 265 | </tr> |
266 | 266 | <?php |
267 | - } |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
270 | - * Outputs the multiple prices checkbox |
|
271 | - */ |
|
272 | - public function remove_decimals_field() { |
|
273 | - ?> |
|
269 | + /** |
|
270 | + * Outputs the multiple prices checkbox |
|
271 | + */ |
|
272 | + public function remove_decimals_field() { |
|
273 | + ?> |
|
274 | 274 | <tr class="form-field"> |
275 | 275 | <th scope="row"> |
276 | 276 | <label for="remove_decimals"><?php esc_html_e( 'Remove Decimals', 'lsx-currencies' ); ?></label> |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | </td> |
282 | 282 | </tr> |
283 | 283 | <?php |
284 | - } |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * Outputs the multiple prices checkbox |
|
288 | - */ |
|
289 | - public function enable_multiple_prices_field() { |
|
290 | - ?> |
|
286 | + /** |
|
287 | + * Outputs the multiple prices checkbox |
|
288 | + */ |
|
289 | + public function enable_multiple_prices_field() { |
|
290 | + ?> |
|
291 | 291 | <tr class="form-field"> |
292 | 292 | <th scope="row"> |
293 | 293 | <label for="multi_price"><?php esc_html_e( 'Enable Multiple Prices', 'lsx-currencies' ); ?></label> |
@@ -298,13 +298,13 @@ discard block |
||
298 | 298 | </td> |
299 | 299 | </tr> |
300 | 300 | <?php |
301 | - } |
|
301 | + } |
|
302 | 302 | |
303 | - /** |
|
304 | - * Outputs the multiple prices checkbox |
|
305 | - */ |
|
306 | - public function enable_convert_to_single_currency_field() { |
|
307 | - ?> |
|
303 | + /** |
|
304 | + * Outputs the multiple prices checkbox |
|
305 | + */ |
|
306 | + public function enable_convert_to_single_currency_field() { |
|
307 | + ?> |
|
308 | 308 | <tr class="form-field"> |
309 | 309 | <th scope="row"> |
310 | 310 | <label for="convert_to_single_currency"><?php esc_html_e( 'Enable Convert to Single Currency', 'lsx-currencies' ); ?></label> |
@@ -315,26 +315,26 @@ discard block |
||
315 | 315 | </td> |
316 | 316 | </tr> |
317 | 317 | <?php |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * Outputs the currency heading |
|
322 | - */ |
|
323 | - public function currency_api_heading() { |
|
324 | - ?> |
|
320 | + /** |
|
321 | + * Outputs the currency heading |
|
322 | + */ |
|
323 | + public function currency_api_heading() { |
|
324 | + ?> |
|
325 | 325 | <tr class="form-field banner-wrap"> |
326 | 326 | <th class="table_heading" style="padding-bottom:0px;" scope="row" colspan="2"> |
327 | 327 | <h4 style="margin-bottom:0px;"><?php esc_html_e( 'Openexchange API', 'lsx-currencies' ); ?></h4> |
328 | 328 | </th> |
329 | 329 | </tr> |
330 | 330 | <?php |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - /** |
|
334 | - * Outputs the api key text field |
|
335 | - */ |
|
336 | - public function api_key_field() { |
|
337 | - ?> |
|
333 | + /** |
|
334 | + * Outputs the api key text field |
|
335 | + */ |
|
336 | + public function api_key_field() { |
|
337 | + ?> |
|
338 | 338 | <tr class="form-field"> |
339 | 339 | <th scope="row"> |
340 | 340 | <i class="dashicons-before dashicons-admin-network"></i><label for="openexchange_api"> <?php esc_html_e( 'Key', 'to-maps' ); ?></label> |
@@ -345,172 +345,172 @@ discard block |
||
345 | 345 | </td> |
346 | 346 | </tr> |
347 | 347 | <?php |
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * adds in our multiple prices field |
|
352 | - */ |
|
353 | - public function fields( $meta_boxes ) { |
|
354 | - if ( true === lsx_currencies()->multi_prices && ! empty( lsx_currencies()->additional_currencies ) ) { |
|
355 | - $currency_options = array(); |
|
356 | - |
|
357 | - foreach ( lsx_currencies()->additional_currencies as $key => $values ) { |
|
358 | - if ( lsx_currencies()->base_currency === $key ) { |
|
359 | - continue; |
|
360 | - } |
|
361 | - |
|
362 | - $currency_options[ $key ] = lsx_currencies()->available_currencies[ $key ]; |
|
363 | - } |
|
364 | - |
|
365 | - $new_boxes = array(); |
|
366 | - $injected = false; |
|
367 | - if ( ! empty( $meta_boxes ) ) { |
|
368 | - foreach ( $meta_boxes as $meta_box ) { |
|
369 | - if ( 'price' === $meta_box['id'] ) { |
|
370 | - $new_boxes[] = array( |
|
371 | - 'id' => 'price', |
|
372 | - 'name' => 'Base Price (' . lsx_currencies()->base_currency . ')', |
|
373 | - 'type' => 'text', |
|
374 | - ); |
|
375 | - $new_boxes[] = array( |
|
376 | - 'id' => 'additional_prices', |
|
377 | - 'name' => '', |
|
378 | - 'single_name' => 'Price', |
|
379 | - 'type' => 'group', |
|
380 | - 'repeatable' => true, |
|
381 | - 'sortable' => true, |
|
382 | - 'fields' => array( |
|
383 | - array( |
|
384 | - 'id' => 'amount', |
|
385 | - 'name' => 'Amount', |
|
386 | - 'type' => 'text', |
|
387 | - ), |
|
388 | - array( |
|
389 | - 'id' => 'currency', |
|
390 | - 'name' => 'Currency', |
|
391 | - 'type' => 'select', |
|
392 | - 'options' => $currency_options, |
|
393 | - ), |
|
394 | - ), |
|
395 | - ); |
|
396 | - $injected = true; |
|
397 | - continue; |
|
398 | - } |
|
399 | - $new_boxes[] = $meta_box; |
|
400 | - } |
|
401 | - } |
|
402 | - if ( true === $injected ) { |
|
403 | - $meta_boxes = $new_boxes; |
|
404 | - } |
|
405 | - } |
|
406 | - return $meta_boxes; |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Customizer Controls and Settings. |
|
411 | - * |
|
412 | - * @since 1.1.1 |
|
413 | - */ |
|
414 | - public function customize_register( $wp_customize ) { |
|
415 | - /** |
|
416 | - * Panel. |
|
417 | - */ |
|
418 | - $wp_customize->add_panel( 'lsx_currencies', array( |
|
419 | - 'priority' => 62, |
|
420 | - 'capability' => 'edit_theme_options', |
|
421 | - 'theme_supports' => '', |
|
422 | - 'title' => esc_html__( 'Currencies', 'lsx-currencies' ), |
|
423 | - 'description' => esc_html__( 'LSX Currencies extension settings.', 'lsx-currencies' ), |
|
424 | - ) ); |
|
425 | - |
|
426 | - /** |
|
427 | - * Section. |
|
428 | - */ |
|
429 | - |
|
430 | - $wp_customize->add_section( 'lsx_currencies_display', array( |
|
431 | - 'title' => esc_html__( 'Display', 'lsx-currencies' ), |
|
432 | - 'description' => esc_html__( 'LSX Currencies extension display settings.', 'lsx-currencies' ), |
|
433 | - 'panel' => 'lsx_currencies', |
|
434 | - 'priority' => 1, |
|
435 | - ) ); |
|
436 | - |
|
437 | - /** |
|
438 | - * Fields. |
|
439 | - */ |
|
440 | - |
|
441 | - $wp_customize->add_setting( 'lsx_currencies_currency_menu_position', array( |
|
442 | - 'default' => '', |
|
443 | - 'sanitize_callback' => array( '\lsx\currencies\classes\Currencies', 'sanitize_select' ), |
|
444 | - ) ); |
|
445 | - |
|
446 | - $choices = array( |
|
447 | - '' => esc_html__( 'None', 'lsx-currencies' ), |
|
448 | - ); |
|
449 | - |
|
450 | - $menus = get_registered_nav_menus(); |
|
451 | - |
|
452 | - if ( is_array( $menus ) && ! empty( $menus ) ) { |
|
453 | - $choices = array_merge( $choices, $menus ); |
|
454 | - } |
|
455 | - |
|
456 | - $wp_customize->add_control( new \WP_Customize_Control( $wp_customize, 'lsx_currencies_currency_menu_position', array( |
|
457 | - 'label' => esc_html__( 'Display in Menu', 'lsx-currencies' ), |
|
458 | - 'description' => esc_html__( 'Select the menu to display the currency menu switcher.', 'lsx-currencies' ), |
|
459 | - 'section' => 'lsx_currencies_display', |
|
460 | - 'settings' => 'lsx_currencies_currency_menu_position', |
|
461 | - 'type' => 'select', |
|
462 | - 'priority' => 1, |
|
463 | - 'choices' => $choices, |
|
464 | - ) ) ); |
|
465 | - |
|
466 | - $wp_customize->add_setting( 'lsx_currencies_display_flags', array( |
|
467 | - 'default' => false, |
|
468 | - 'sanitize_callback' => array( '\lsx\currencies\classes\Currencies', 'sanitize_checkbox' ), |
|
469 | - ) ); |
|
470 | - |
|
471 | - $wp_customize->add_control( new \WP_Customize_Control( $wp_customize, 'lsx_currencies_display_flags', array( |
|
472 | - 'label' => esc_html__( 'Display Flags', 'lsx-currencies' ), |
|
473 | - 'description' => esc_html__( 'Displays a small flag in front of the name.', 'lsx-currencies' ), |
|
474 | - 'section' => 'lsx_currencies_display', |
|
475 | - 'settings' => 'lsx_currencies_display_flags', |
|
476 | - 'type' => 'checkbox', |
|
477 | - 'priority' => 2, |
|
478 | - ) ) ); |
|
479 | - |
|
480 | - $wp_customize->add_setting( 'lsx_currencies_flag_position', array( |
|
481 | - 'default' => 'left', |
|
482 | - 'sanitize_callback' => array( '\lsx\currencies\classes\Currencies', 'sanitize_select' ), |
|
483 | - ) ); |
|
484 | - |
|
485 | - $wp_customize->add_control( new \WP_Customize_Control( $wp_customize, 'lsx_currencies_flag_position', array( |
|
486 | - 'label' => esc_html__( 'Flag Position', 'lsx-currencies' ), |
|
487 | - 'description' => esc_html__( 'This moves the flag to the right (after the symbol).', 'lsx-currencies' ), |
|
488 | - 'section' => 'lsx_currencies_display', |
|
489 | - 'settings' => 'lsx_currencies_flag_position', |
|
490 | - 'type' => 'select', |
|
491 | - 'priority' => 3, |
|
492 | - 'choices' => array( |
|
493 | - 'left' => esc_html__( 'Left', 'lsx-currencies' ), |
|
494 | - 'right' => esc_html__( 'Right', 'lsx-currencies' ), |
|
495 | - ), |
|
496 | - ) ) ); |
|
497 | - |
|
498 | - $wp_customize->add_setting( 'lsx_currencies_currency_switcher_position', array( |
|
499 | - 'default' => 'right', |
|
500 | - 'sanitize_callback' => array( '\lsx\currencies\classes\Currencies', 'sanitize_select' ), |
|
501 | - ) ); |
|
502 | - |
|
503 | - $wp_customize->add_control( new \WP_Customize_Control( $wp_customize, 'lsx_currencies_currency_switcher_position', array( |
|
504 | - 'label' => esc_html__( 'Symbol Position', 'lsx-currencies' ), |
|
505 | - 'description' => esc_html__( 'This moves the symbol for the switcher to the left (before the flag).', 'lsx-currencies' ), |
|
506 | - 'section' => 'lsx_currencies_display', |
|
507 | - 'settings' => 'lsx_currencies_currency_switcher_position', |
|
508 | - 'type' => 'select', |
|
509 | - 'priority' => 4, |
|
510 | - 'choices' => array( |
|
511 | - 'left' => esc_html__( 'Left', 'lsx-currencies' ), |
|
512 | - 'right' => esc_html__( 'Right', 'lsx-currencies' ), |
|
513 | - ), |
|
514 | - ) ) ); |
|
515 | - } |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * adds in our multiple prices field |
|
352 | + */ |
|
353 | + public function fields( $meta_boxes ) { |
|
354 | + if ( true === lsx_currencies()->multi_prices && ! empty( lsx_currencies()->additional_currencies ) ) { |
|
355 | + $currency_options = array(); |
|
356 | + |
|
357 | + foreach ( lsx_currencies()->additional_currencies as $key => $values ) { |
|
358 | + if ( lsx_currencies()->base_currency === $key ) { |
|
359 | + continue; |
|
360 | + } |
|
361 | + |
|
362 | + $currency_options[ $key ] = lsx_currencies()->available_currencies[ $key ]; |
|
363 | + } |
|
364 | + |
|
365 | + $new_boxes = array(); |
|
366 | + $injected = false; |
|
367 | + if ( ! empty( $meta_boxes ) ) { |
|
368 | + foreach ( $meta_boxes as $meta_box ) { |
|
369 | + if ( 'price' === $meta_box['id'] ) { |
|
370 | + $new_boxes[] = array( |
|
371 | + 'id' => 'price', |
|
372 | + 'name' => 'Base Price (' . lsx_currencies()->base_currency . ')', |
|
373 | + 'type' => 'text', |
|
374 | + ); |
|
375 | + $new_boxes[] = array( |
|
376 | + 'id' => 'additional_prices', |
|
377 | + 'name' => '', |
|
378 | + 'single_name' => 'Price', |
|
379 | + 'type' => 'group', |
|
380 | + 'repeatable' => true, |
|
381 | + 'sortable' => true, |
|
382 | + 'fields' => array( |
|
383 | + array( |
|
384 | + 'id' => 'amount', |
|
385 | + 'name' => 'Amount', |
|
386 | + 'type' => 'text', |
|
387 | + ), |
|
388 | + array( |
|
389 | + 'id' => 'currency', |
|
390 | + 'name' => 'Currency', |
|
391 | + 'type' => 'select', |
|
392 | + 'options' => $currency_options, |
|
393 | + ), |
|
394 | + ), |
|
395 | + ); |
|
396 | + $injected = true; |
|
397 | + continue; |
|
398 | + } |
|
399 | + $new_boxes[] = $meta_box; |
|
400 | + } |
|
401 | + } |
|
402 | + if ( true === $injected ) { |
|
403 | + $meta_boxes = $new_boxes; |
|
404 | + } |
|
405 | + } |
|
406 | + return $meta_boxes; |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Customizer Controls and Settings. |
|
411 | + * |
|
412 | + * @since 1.1.1 |
|
413 | + */ |
|
414 | + public function customize_register( $wp_customize ) { |
|
415 | + /** |
|
416 | + * Panel. |
|
417 | + */ |
|
418 | + $wp_customize->add_panel( 'lsx_currencies', array( |
|
419 | + 'priority' => 62, |
|
420 | + 'capability' => 'edit_theme_options', |
|
421 | + 'theme_supports' => '', |
|
422 | + 'title' => esc_html__( 'Currencies', 'lsx-currencies' ), |
|
423 | + 'description' => esc_html__( 'LSX Currencies extension settings.', 'lsx-currencies' ), |
|
424 | + ) ); |
|
425 | + |
|
426 | + /** |
|
427 | + * Section. |
|
428 | + */ |
|
429 | + |
|
430 | + $wp_customize->add_section( 'lsx_currencies_display', array( |
|
431 | + 'title' => esc_html__( 'Display', 'lsx-currencies' ), |
|
432 | + 'description' => esc_html__( 'LSX Currencies extension display settings.', 'lsx-currencies' ), |
|
433 | + 'panel' => 'lsx_currencies', |
|
434 | + 'priority' => 1, |
|
435 | + ) ); |
|
436 | + |
|
437 | + /** |
|
438 | + * Fields. |
|
439 | + */ |
|
440 | + |
|
441 | + $wp_customize->add_setting( 'lsx_currencies_currency_menu_position', array( |
|
442 | + 'default' => '', |
|
443 | + 'sanitize_callback' => array( '\lsx\currencies\classes\Currencies', 'sanitize_select' ), |
|
444 | + ) ); |
|
445 | + |
|
446 | + $choices = array( |
|
447 | + '' => esc_html__( 'None', 'lsx-currencies' ), |
|
448 | + ); |
|
449 | + |
|
450 | + $menus = get_registered_nav_menus(); |
|
451 | + |
|
452 | + if ( is_array( $menus ) && ! empty( $menus ) ) { |
|
453 | + $choices = array_merge( $choices, $menus ); |
|
454 | + } |
|
455 | + |
|
456 | + $wp_customize->add_control( new \WP_Customize_Control( $wp_customize, 'lsx_currencies_currency_menu_position', array( |
|
457 | + 'label' => esc_html__( 'Display in Menu', 'lsx-currencies' ), |
|
458 | + 'description' => esc_html__( 'Select the menu to display the currency menu switcher.', 'lsx-currencies' ), |
|
459 | + 'section' => 'lsx_currencies_display', |
|
460 | + 'settings' => 'lsx_currencies_currency_menu_position', |
|
461 | + 'type' => 'select', |
|
462 | + 'priority' => 1, |
|
463 | + 'choices' => $choices, |
|
464 | + ) ) ); |
|
465 | + |
|
466 | + $wp_customize->add_setting( 'lsx_currencies_display_flags', array( |
|
467 | + 'default' => false, |
|
468 | + 'sanitize_callback' => array( '\lsx\currencies\classes\Currencies', 'sanitize_checkbox' ), |
|
469 | + ) ); |
|
470 | + |
|
471 | + $wp_customize->add_control( new \WP_Customize_Control( $wp_customize, 'lsx_currencies_display_flags', array( |
|
472 | + 'label' => esc_html__( 'Display Flags', 'lsx-currencies' ), |
|
473 | + 'description' => esc_html__( 'Displays a small flag in front of the name.', 'lsx-currencies' ), |
|
474 | + 'section' => 'lsx_currencies_display', |
|
475 | + 'settings' => 'lsx_currencies_display_flags', |
|
476 | + 'type' => 'checkbox', |
|
477 | + 'priority' => 2, |
|
478 | + ) ) ); |
|
479 | + |
|
480 | + $wp_customize->add_setting( 'lsx_currencies_flag_position', array( |
|
481 | + 'default' => 'left', |
|
482 | + 'sanitize_callback' => array( '\lsx\currencies\classes\Currencies', 'sanitize_select' ), |
|
483 | + ) ); |
|
484 | + |
|
485 | + $wp_customize->add_control( new \WP_Customize_Control( $wp_customize, 'lsx_currencies_flag_position', array( |
|
486 | + 'label' => esc_html__( 'Flag Position', 'lsx-currencies' ), |
|
487 | + 'description' => esc_html__( 'This moves the flag to the right (after the symbol).', 'lsx-currencies' ), |
|
488 | + 'section' => 'lsx_currencies_display', |
|
489 | + 'settings' => 'lsx_currencies_flag_position', |
|
490 | + 'type' => 'select', |
|
491 | + 'priority' => 3, |
|
492 | + 'choices' => array( |
|
493 | + 'left' => esc_html__( 'Left', 'lsx-currencies' ), |
|
494 | + 'right' => esc_html__( 'Right', 'lsx-currencies' ), |
|
495 | + ), |
|
496 | + ) ) ); |
|
497 | + |
|
498 | + $wp_customize->add_setting( 'lsx_currencies_currency_switcher_position', array( |
|
499 | + 'default' => 'right', |
|
500 | + 'sanitize_callback' => array( '\lsx\currencies\classes\Currencies', 'sanitize_select' ), |
|
501 | + ) ); |
|
502 | + |
|
503 | + $wp_customize->add_control( new \WP_Customize_Control( $wp_customize, 'lsx_currencies_currency_switcher_position', array( |
|
504 | + 'label' => esc_html__( 'Symbol Position', 'lsx-currencies' ), |
|
505 | + 'description' => esc_html__( 'This moves the symbol for the switcher to the left (before the flag).', 'lsx-currencies' ), |
|
506 | + 'section' => 'lsx_currencies_display', |
|
507 | + 'settings' => 'lsx_currencies_currency_switcher_position', |
|
508 | + 'type' => 'select', |
|
509 | + 'priority' => 4, |
|
510 | + 'choices' => array( |
|
511 | + 'left' => esc_html__( 'Left', 'lsx-currencies' ), |
|
512 | + 'right' => esc_html__( 'Right', 'lsx-currencies' ), |
|
513 | + ), |
|
514 | + ) ) ); |
|
515 | + } |
|
516 | 516 | } |
@@ -16,379 +16,379 @@ |
||
16 | 16 | */ |
17 | 17 | class Frontend { |
18 | 18 | |
19 | - /** |
|
20 | - * Holds instance of the class |
|
21 | - * |
|
22 | - * @var object \lsx\currencies\classes\Admin() |
|
23 | - */ |
|
24 | - private static $instance; |
|
25 | - |
|
26 | - /** |
|
27 | - * This will hold the rates with a base currency of USD. |
|
28 | - * |
|
29 | - * @var boolean |
|
30 | - */ |
|
31 | - public $rates = false; |
|
32 | - |
|
33 | - /** |
|
34 | - * This will hold the rates error message. |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - public $rates_message = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * This is the current currency selected, default to the base currency. |
|
42 | - * |
|
43 | - * @var boolean |
|
44 | - */ |
|
45 | - public $current_currency = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Constructor |
|
49 | - */ |
|
50 | - public function __construct() { |
|
51 | - if ( ! is_admin() ) { |
|
52 | - add_action( 'plugins_loaded', array( $this, 'set_defaults' ), 11, 1 ); |
|
53 | - add_filter( 'lsx_to_custom_field_query', array( $this, 'price_filter' ), 20, 5 ); |
|
54 | - add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
|
55 | - add_filter( 'wp_nav_menu_items', array( $this, 'wp_nav_menu_items_filter' ), 10, 2 ); |
|
56 | - add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 ); |
|
57 | - add_filter( 'get_post_metadata', array( $this, 'filter_post_meta' ), 100, 4 ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Return an instance of this class. |
|
63 | - * |
|
64 | - * @return object |
|
65 | - */ |
|
66 | - public static function init() { |
|
67 | - // If the single instance hasn't been set, set it now. |
|
68 | - if ( ! isset( self::$instance ) ) { |
|
69 | - self::$instance = new self(); |
|
70 | - } |
|
71 | - return self::$instance; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Constructor |
|
76 | - */ |
|
77 | - public function set_defaults() { |
|
78 | - $this->rates_message = esc_html__( 'Error: API key isn\'t set.', 'lsx-currencies' ); |
|
79 | - $this->rates = get_transient( 'lsx_currencies_rates' ); |
|
80 | - if ( false === $this->rates ) { |
|
81 | - $rates = wp_remote_retrieve_body( wp_safe_remote_get( lsx_currencies()->api_url ) ); |
|
82 | - $decoded_rates = json_decode( $rates ); |
|
83 | - |
|
84 | - if ( is_wp_error( $rates ) ) { |
|
85 | - $this->rates_message = $rates->get_error_message(); |
|
86 | - } elseif ( ! empty( $decoded_rates->error ) ) { |
|
87 | - $this->rates_message = $decoded_rates->description; |
|
88 | - } elseif ( empty( $rates ) ) { |
|
89 | - $this->rates_message = esc_html__( 'Error: API response is empty.', 'lsx-currencies' ); |
|
90 | - } else { |
|
91 | - $this->rates_message = esc_html__( 'Success (new request).', 'lsx-currencies' ); |
|
92 | - set_transient( 'lsx_currencies_rates', $decoded_rates->rates, 60 * 60 * 12 ); |
|
93 | - do_action( 'lsx_currencies_rates_refreshed' ); |
|
94 | - $this->rates = $decoded_rates->rates; |
|
95 | - } |
|
96 | - } else { |
|
97 | - $this->rates_message = esc_html__( 'Success (from cache).', 'lsx-currencies' ); |
|
98 | - } |
|
99 | - $this->current_currency = isset( $_COOKIE['lsx_currencies_choice'] ) ? sanitize_key( $_COOKIE['lsx_currencies_choice'] ) : lsx_currencies()->base_currency; |
|
100 | - $this->current_currency = strtoupper( $this->current_currency ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Enques the assets |
|
105 | - */ |
|
106 | - public function assets() { |
|
107 | - wp_enqueue_script( 'lsx-moneyjs', LSX_CURRENCIES_URL . 'assets/js/vendor/money.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true ); |
|
108 | - wp_enqueue_script( 'lsx-accountingjs', LSX_CURRENCIES_URL . 'assets/js/vendor/accounting.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true ); |
|
109 | - wp_enqueue_script( 'lsx-jquery-cookie', LSX_CURRENCIES_URL . 'assets/js/vendor/cookie.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true ); |
|
110 | - |
|
111 | - $prefix = '.min'; |
|
112 | - $src = ''; |
|
113 | - $script_debug = false; |
|
114 | - if ( defined( 'SCRIPT_DEBUG' ) ) { |
|
115 | - $prefix = ''; |
|
116 | - $src = 'src/'; |
|
117 | - $script_debug = true; |
|
118 | - } |
|
119 | - wp_enqueue_script( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/js/' . $src . 'lsx-currencies' . $prefix . '.js', array( 'jquery', 'lsx-moneyjs', 'lsx-accountingjs', 'lsx-jquery-cookie' ), LSX_CURRENCIES_VER, true ); |
|
120 | - |
|
121 | - $base_currency = lsx_currencies()->base_currency; |
|
122 | - $current_currency = $this->current_currency; |
|
123 | - if ( true === lsx_currencies()->convert_to_single ) { |
|
124 | - $current_currency = $base_currency; |
|
125 | - } |
|
126 | - |
|
127 | - $params = apply_filters( 'lsx_currencies_js_params', array( |
|
128 | - 'current_currency' => $current_currency, |
|
129 | - 'currency_symbols' => $this->get_available_symbols(), |
|
130 | - 'rates' => $this->rates, |
|
131 | - 'rates_message' => $this->rates_message, |
|
132 | - 'base' => $base_currency, |
|
133 | - 'flags' => lsx_currencies()->display_flags, |
|
134 | - 'convert_to_single' => lsx_currencies()->convert_to_single, |
|
135 | - 'script_debug' => $script_debug, |
|
136 | - 'remove_decimals' => lsx_currencies()->remove_decimals, |
|
137 | - )); |
|
138 | - |
|
139 | - wp_localize_script( 'lsx-currencies', 'lsx_currencies_params', $params ); |
|
140 | - |
|
141 | - wp_enqueue_style( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/css/lsx-currencies.css', array(), LSX_CURRENCIES_VER ); |
|
142 | - wp_style_add_data( 'lsx-currencies', 'rtl', 'replace' ); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Returns all of the available symbols. |
|
147 | - * |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - public function get_available_symbols() { |
|
151 | - $symbols = array(); |
|
152 | - if ( false !== lsx_currencies()->additional_currencies && ! empty( lsx_currencies()->additional_currencies ) ) { |
|
153 | - foreach ( lsx_currencies()->additional_currencies as $key => $currency ) { |
|
154 | - $symbols[ $key ] = lsx_currencies()->currency_symbols[ $key ]; |
|
155 | - } |
|
156 | - } |
|
157 | - return $symbols; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Adds in the required currency conversion tags |
|
162 | - */ |
|
163 | - public function price_filter( $return_html, $meta_key, $value, $before, $after ) { |
|
164 | - if ( 'price' === $meta_key ) { |
|
165 | - $additional_html = ''; |
|
166 | - $additional_prices = get_post_meta( get_the_ID(), 'additional_prices', false ); |
|
167 | - $prefix = '<span class="amount lsx-currencies" '; |
|
168 | - |
|
169 | - if ( true === lsx_currencies()->multi_prices && ! empty( $additional_prices ) ) { |
|
170 | - foreach ( $additional_prices as $a_price ) { |
|
171 | - $additional_html .= ' data-price-' . $a_price['currency'] . '="' . $a_price['amount'] . '"'; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - $value = preg_replace( '/[^0-9.]+/', '', $value ); |
|
176 | - $decimals = substr_count( $value, '.' ); |
|
177 | - |
|
178 | - if ( false !== $decimals && $decimals > 1 ) { |
|
179 | - $decimals--; |
|
180 | - $decimals = (int) $decimals; |
|
181 | - $value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals ); |
|
182 | - } |
|
183 | - |
|
184 | - $money_format = '%i'; |
|
185 | - if ( false !== lsx_currencies()->remove_decimals ) { |
|
186 | - $money_format = '%.0n'; |
|
187 | - } |
|
188 | - |
|
189 | - $prefix .= '>'; |
|
190 | - $suffix = '</span>'; |
|
191 | - |
|
192 | - setlocale( LC_MONETARY, 'en_US' ); |
|
193 | - |
|
194 | - // Work out the other tags |
|
195 | - $currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>'; |
|
196 | - $amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( array( '$', 'USD' ), '', money_format( (float) $money_format, ltrim( rtrim( $value ) ) ) ) ) . '" ' . $additional_html . '>' . str_replace( array( '$', 'USD' ), '', money_format( $money_format, ltrim( rtrim( $value ) ) ) ) . '</span>'; |
|
197 | - |
|
198 | - // Check for a price type and add that in. |
|
199 | - $price_type = get_post_meta( get_the_ID(), 'price_type', true ); |
|
200 | - |
|
201 | - switch ( $price_type ) { |
|
202 | - case 'per_person_per_night': |
|
203 | - case 'per_person_sharing': |
|
204 | - case 'per_person_sharing_per_night': |
|
205 | - $amount = $currency . $amount . ' ' . ucwords( str_replace( '_', ' ', $price_type ) ); |
|
206 | - break; |
|
207 | - |
|
208 | - case 'total_percentage': |
|
209 | - $amount .= '% ' . esc_html__( 'Off', 'lsx-currencies' ); |
|
210 | - $before = str_replace( 'from', '', $before ); |
|
211 | - break; |
|
212 | - |
|
213 | - case 'none': |
|
214 | - default: |
|
215 | - $amount = $currency . $amount; |
|
216 | - break; |
|
217 | - } |
|
218 | - |
|
219 | - $return_html = $before . $prefix . $amount . $suffix . $after; |
|
220 | - } |
|
221 | - |
|
222 | - return $return_html; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Filter on the 'wp_nav_menu_items' hook, that potentially adds a currency switcher to the item of some menus. |
|
227 | - * |
|
228 | - * @param $items string |
|
229 | - * @param $args object |
|
230 | - * |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function wp_nav_menu_items_filter( $items, $args ) { |
|
234 | - if ( '' !== lsx_currencies()->menus && lsx_currencies()->menus === $args->theme_location ) { |
|
235 | - if ( 'top-menu' === $args->theme_location ) { |
|
236 | - $items = $this->get_menu_html( $args ) . $items; |
|
237 | - } else { |
|
238 | - $items = $items . $this->get_menu_html( $args ); |
|
239 | - } |
|
240 | - } |
|
241 | - return $items; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Returns the HTML string of the language switcher for a given menu. |
|
246 | - * |
|
247 | - * @param $args object |
|
248 | - * |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - private function get_menu_html( $args ) { |
|
252 | - if ( empty( lsx_currencies()->additional_currencies ) ) { |
|
253 | - return ''; |
|
254 | - } |
|
255 | - |
|
256 | - $items = ''; |
|
257 | - $items .= '<li class="menu-item menu-item-currency menu-item-currency-current menu-item-has-children dropdown">'; |
|
258 | - $items .= isset( $args->before ) ? $args->before : ''; |
|
259 | - $items .= '<a class="current symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $this->current_currency ) . '">'; |
|
260 | - $items .= isset( $args->link_before ) ? $args->link_before : ''; |
|
261 | - |
|
262 | - if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) { |
|
263 | - $items .= lsx_currencies()->get_currency_flag( $this->current_currency ); |
|
264 | - } |
|
265 | - |
|
266 | - if ( 'left' === lsx_currencies()->switcher_symbol_position ) { |
|
267 | - $items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>'; |
|
268 | - } |
|
269 | - |
|
270 | - $items .= $this->current_currency; |
|
271 | - |
|
272 | - if ( 'right' === lsx_currencies()->switcher_symbol_position ) { |
|
273 | - $items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>'; |
|
274 | - } |
|
275 | - |
|
276 | - if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) { |
|
277 | - $items .= lsx_currencies()->get_currency_flag( $this->current_currency ); |
|
278 | - } |
|
279 | - |
|
280 | - $items .= isset( $args->link_after ) ? $args->link_after : ''; |
|
281 | - $items .= '<span class="caret"></span></a>'; |
|
282 | - $items .= isset( $args->after ) ? $args->after : ''; |
|
283 | - $items .= $this->render_sub_items(); |
|
284 | - $items .= '</li>'; |
|
285 | - return $items; |
|
286 | - } |
|
287 | - /** |
|
288 | - * Returns the HTML string of the language switcher for a given menu. |
|
289 | - * |
|
290 | - * @param object $args |
|
291 | - * |
|
292 | - * @return string |
|
293 | - */ |
|
294 | - private function render_sub_items() { |
|
295 | - $sub_items = ''; |
|
296 | - foreach ( lsx_currencies()->additional_currencies as $key => $currency ) { |
|
297 | - $hidden = ''; |
|
298 | - $class = ''; |
|
299 | - |
|
300 | - if ( $this->current_currency === $key ) { |
|
301 | - $hidden = 'style="display:none";'; |
|
302 | - $class = 'hidden'; |
|
303 | - } |
|
304 | - |
|
305 | - $sub_items .= '<li ' . $hidden . ' class="' . $class . ' menu-item menu-item-currency ' . lsx_currencies()->switcher_symbol_position . '">'; |
|
306 | - $sub_items .= '<a class=" symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $key ) . '">'; |
|
307 | - |
|
308 | - if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) { |
|
309 | - $sub_items .= lsx_currencies()->get_currency_flag( $key ); |
|
310 | - } |
|
311 | - |
|
312 | - if ( 'left' === lsx_currencies()->switcher_symbol_position ) { |
|
313 | - $sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>'; |
|
314 | - } |
|
315 | - |
|
316 | - $sub_items .= ucwords( $key ); |
|
317 | - |
|
318 | - if ( 'right' === lsx_currencies()->switcher_symbol_position ) { |
|
319 | - $sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>'; |
|
320 | - } |
|
321 | - |
|
322 | - if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) { |
|
323 | - $sub_items .= lsx_currencies()->get_currency_flag( $key ); |
|
324 | - } |
|
325 | - |
|
326 | - $sub_items .= '</a></li>'; |
|
327 | - } |
|
328 | - |
|
329 | - $sub_items = '<ul class="sub-menu submenu-currency dropdown-menu">' . $sub_items . '</ul>'; |
|
330 | - return $sub_items; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Allow data params for Slick slider addon. |
|
335 | - */ |
|
336 | - public function wp_kses_allowed_html( $allowedtags, $context ) { |
|
337 | - if ( ! isset( $allowedtags['span'] ) ) { |
|
338 | - $allowedtags['span'] = array(); |
|
339 | - } |
|
340 | - |
|
341 | - $allowedtags['span']['data-price-AUD'] = true; |
|
342 | - $allowedtags['span']['data-price-BRL'] = true; |
|
343 | - $allowedtags['span']['data-price-GBP'] = true; |
|
344 | - $allowedtags['span']['data-price-BWP'] = true; |
|
345 | - $allowedtags['span']['data-price-CAD'] = true; |
|
346 | - $allowedtags['span']['data-price-CNY'] = true; |
|
347 | - $allowedtags['span']['data-price-EUR'] = true; |
|
348 | - $allowedtags['span']['data-price-HKD'] = true; |
|
349 | - $allowedtags['span']['data-price-INR'] = true; |
|
350 | - $allowedtags['span']['data-price-IDR'] = true; |
|
351 | - $allowedtags['span']['data-price-ILS'] = true; |
|
352 | - $allowedtags['span']['data-price-JPY'] = true; |
|
353 | - $allowedtags['span']['data-price-KES'] = true; |
|
354 | - $allowedtags['span']['data-price-LAK'] = true; |
|
355 | - $allowedtags['span']['data-price-MWK'] = true; |
|
356 | - $allowedtags['span']['data-price-MYR'] = true; |
|
357 | - $allowedtags['span']['data-price-MZN'] = true; |
|
358 | - $allowedtags['span']['data-price-NAD'] = true; |
|
359 | - $allowedtags['span']['data-price-NZD'] = true; |
|
360 | - $allowedtags['span']['data-price-NOK'] = true; |
|
361 | - $allowedtags['span']['data-price-RUB'] = true; |
|
362 | - $allowedtags['span']['data-price-SGD'] = true; |
|
363 | - $allowedtags['span']['data-price-ZAR'] = true; |
|
364 | - $allowedtags['span']['data-price-SEK'] = true; |
|
365 | - $allowedtags['span']['data-price-CHF'] = true; |
|
366 | - $allowedtags['span']['data-price-TZS'] = true; |
|
367 | - $allowedtags['span']['data-price-USD'] = true; |
|
368 | - $allowedtags['span']['data-price-AED'] = true; |
|
369 | - $allowedtags['span']['data-price-ZMW'] = true; |
|
370 | - $allowedtags['span']['data-price-ZWL'] = true; |
|
371 | - |
|
372 | - return $allowedtags; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Allow empty prices if the convert to single currency is active. |
|
377 | - * |
|
378 | - * @param null $metadata |
|
379 | - * @param string $object_id |
|
380 | - * @param string $meta_key |
|
381 | - * @param boolean $single |
|
382 | - * @return void |
|
383 | - */ |
|
384 | - public function filter_post_meta( $metadata = null, $object_id, $meta_key, $single ) { |
|
385 | - if ( true === lsx_currencies()->convert_to_single && 'price' === $meta_key ) { |
|
386 | - $meta_cache = wp_cache_get( $object_id, 'post_meta' ); |
|
387 | - |
|
388 | - if ( ! isset( $meta_cache[ $meta_key ] ) || '' === $meta_cache[ $meta_key ] ) { |
|
389 | - $metadata = '0'; |
|
390 | - } |
|
391 | - } |
|
392 | - return $metadata; |
|
393 | - } |
|
19 | + /** |
|
20 | + * Holds instance of the class |
|
21 | + * |
|
22 | + * @var object \lsx\currencies\classes\Admin() |
|
23 | + */ |
|
24 | + private static $instance; |
|
25 | + |
|
26 | + /** |
|
27 | + * This will hold the rates with a base currency of USD. |
|
28 | + * |
|
29 | + * @var boolean |
|
30 | + */ |
|
31 | + public $rates = false; |
|
32 | + |
|
33 | + /** |
|
34 | + * This will hold the rates error message. |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + public $rates_message = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * This is the current currency selected, default to the base currency. |
|
42 | + * |
|
43 | + * @var boolean |
|
44 | + */ |
|
45 | + public $current_currency = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Constructor |
|
49 | + */ |
|
50 | + public function __construct() { |
|
51 | + if ( ! is_admin() ) { |
|
52 | + add_action( 'plugins_loaded', array( $this, 'set_defaults' ), 11, 1 ); |
|
53 | + add_filter( 'lsx_to_custom_field_query', array( $this, 'price_filter' ), 20, 5 ); |
|
54 | + add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
|
55 | + add_filter( 'wp_nav_menu_items', array( $this, 'wp_nav_menu_items_filter' ), 10, 2 ); |
|
56 | + add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 ); |
|
57 | + add_filter( 'get_post_metadata', array( $this, 'filter_post_meta' ), 100, 4 ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Return an instance of this class. |
|
63 | + * |
|
64 | + * @return object |
|
65 | + */ |
|
66 | + public static function init() { |
|
67 | + // If the single instance hasn't been set, set it now. |
|
68 | + if ( ! isset( self::$instance ) ) { |
|
69 | + self::$instance = new self(); |
|
70 | + } |
|
71 | + return self::$instance; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Constructor |
|
76 | + */ |
|
77 | + public function set_defaults() { |
|
78 | + $this->rates_message = esc_html__( 'Error: API key isn\'t set.', 'lsx-currencies' ); |
|
79 | + $this->rates = get_transient( 'lsx_currencies_rates' ); |
|
80 | + if ( false === $this->rates ) { |
|
81 | + $rates = wp_remote_retrieve_body( wp_safe_remote_get( lsx_currencies()->api_url ) ); |
|
82 | + $decoded_rates = json_decode( $rates ); |
|
83 | + |
|
84 | + if ( is_wp_error( $rates ) ) { |
|
85 | + $this->rates_message = $rates->get_error_message(); |
|
86 | + } elseif ( ! empty( $decoded_rates->error ) ) { |
|
87 | + $this->rates_message = $decoded_rates->description; |
|
88 | + } elseif ( empty( $rates ) ) { |
|
89 | + $this->rates_message = esc_html__( 'Error: API response is empty.', 'lsx-currencies' ); |
|
90 | + } else { |
|
91 | + $this->rates_message = esc_html__( 'Success (new request).', 'lsx-currencies' ); |
|
92 | + set_transient( 'lsx_currencies_rates', $decoded_rates->rates, 60 * 60 * 12 ); |
|
93 | + do_action( 'lsx_currencies_rates_refreshed' ); |
|
94 | + $this->rates = $decoded_rates->rates; |
|
95 | + } |
|
96 | + } else { |
|
97 | + $this->rates_message = esc_html__( 'Success (from cache).', 'lsx-currencies' ); |
|
98 | + } |
|
99 | + $this->current_currency = isset( $_COOKIE['lsx_currencies_choice'] ) ? sanitize_key( $_COOKIE['lsx_currencies_choice'] ) : lsx_currencies()->base_currency; |
|
100 | + $this->current_currency = strtoupper( $this->current_currency ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Enques the assets |
|
105 | + */ |
|
106 | + public function assets() { |
|
107 | + wp_enqueue_script( 'lsx-moneyjs', LSX_CURRENCIES_URL . 'assets/js/vendor/money.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true ); |
|
108 | + wp_enqueue_script( 'lsx-accountingjs', LSX_CURRENCIES_URL . 'assets/js/vendor/accounting.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true ); |
|
109 | + wp_enqueue_script( 'lsx-jquery-cookie', LSX_CURRENCIES_URL . 'assets/js/vendor/cookie.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true ); |
|
110 | + |
|
111 | + $prefix = '.min'; |
|
112 | + $src = ''; |
|
113 | + $script_debug = false; |
|
114 | + if ( defined( 'SCRIPT_DEBUG' ) ) { |
|
115 | + $prefix = ''; |
|
116 | + $src = 'src/'; |
|
117 | + $script_debug = true; |
|
118 | + } |
|
119 | + wp_enqueue_script( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/js/' . $src . 'lsx-currencies' . $prefix . '.js', array( 'jquery', 'lsx-moneyjs', 'lsx-accountingjs', 'lsx-jquery-cookie' ), LSX_CURRENCIES_VER, true ); |
|
120 | + |
|
121 | + $base_currency = lsx_currencies()->base_currency; |
|
122 | + $current_currency = $this->current_currency; |
|
123 | + if ( true === lsx_currencies()->convert_to_single ) { |
|
124 | + $current_currency = $base_currency; |
|
125 | + } |
|
126 | + |
|
127 | + $params = apply_filters( 'lsx_currencies_js_params', array( |
|
128 | + 'current_currency' => $current_currency, |
|
129 | + 'currency_symbols' => $this->get_available_symbols(), |
|
130 | + 'rates' => $this->rates, |
|
131 | + 'rates_message' => $this->rates_message, |
|
132 | + 'base' => $base_currency, |
|
133 | + 'flags' => lsx_currencies()->display_flags, |
|
134 | + 'convert_to_single' => lsx_currencies()->convert_to_single, |
|
135 | + 'script_debug' => $script_debug, |
|
136 | + 'remove_decimals' => lsx_currencies()->remove_decimals, |
|
137 | + )); |
|
138 | + |
|
139 | + wp_localize_script( 'lsx-currencies', 'lsx_currencies_params', $params ); |
|
140 | + |
|
141 | + wp_enqueue_style( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/css/lsx-currencies.css', array(), LSX_CURRENCIES_VER ); |
|
142 | + wp_style_add_data( 'lsx-currencies', 'rtl', 'replace' ); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Returns all of the available symbols. |
|
147 | + * |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + public function get_available_symbols() { |
|
151 | + $symbols = array(); |
|
152 | + if ( false !== lsx_currencies()->additional_currencies && ! empty( lsx_currencies()->additional_currencies ) ) { |
|
153 | + foreach ( lsx_currencies()->additional_currencies as $key => $currency ) { |
|
154 | + $symbols[ $key ] = lsx_currencies()->currency_symbols[ $key ]; |
|
155 | + } |
|
156 | + } |
|
157 | + return $symbols; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Adds in the required currency conversion tags |
|
162 | + */ |
|
163 | + public function price_filter( $return_html, $meta_key, $value, $before, $after ) { |
|
164 | + if ( 'price' === $meta_key ) { |
|
165 | + $additional_html = ''; |
|
166 | + $additional_prices = get_post_meta( get_the_ID(), 'additional_prices', false ); |
|
167 | + $prefix = '<span class="amount lsx-currencies" '; |
|
168 | + |
|
169 | + if ( true === lsx_currencies()->multi_prices && ! empty( $additional_prices ) ) { |
|
170 | + foreach ( $additional_prices as $a_price ) { |
|
171 | + $additional_html .= ' data-price-' . $a_price['currency'] . '="' . $a_price['amount'] . '"'; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + $value = preg_replace( '/[^0-9.]+/', '', $value ); |
|
176 | + $decimals = substr_count( $value, '.' ); |
|
177 | + |
|
178 | + if ( false !== $decimals && $decimals > 1 ) { |
|
179 | + $decimals--; |
|
180 | + $decimals = (int) $decimals; |
|
181 | + $value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals ); |
|
182 | + } |
|
183 | + |
|
184 | + $money_format = '%i'; |
|
185 | + if ( false !== lsx_currencies()->remove_decimals ) { |
|
186 | + $money_format = '%.0n'; |
|
187 | + } |
|
188 | + |
|
189 | + $prefix .= '>'; |
|
190 | + $suffix = '</span>'; |
|
191 | + |
|
192 | + setlocale( LC_MONETARY, 'en_US' ); |
|
193 | + |
|
194 | + // Work out the other tags |
|
195 | + $currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>'; |
|
196 | + $amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( array( '$', 'USD' ), '', money_format( (float) $money_format, ltrim( rtrim( $value ) ) ) ) ) . '" ' . $additional_html . '>' . str_replace( array( '$', 'USD' ), '', money_format( $money_format, ltrim( rtrim( $value ) ) ) ) . '</span>'; |
|
197 | + |
|
198 | + // Check for a price type and add that in. |
|
199 | + $price_type = get_post_meta( get_the_ID(), 'price_type', true ); |
|
200 | + |
|
201 | + switch ( $price_type ) { |
|
202 | + case 'per_person_per_night': |
|
203 | + case 'per_person_sharing': |
|
204 | + case 'per_person_sharing_per_night': |
|
205 | + $amount = $currency . $amount . ' ' . ucwords( str_replace( '_', ' ', $price_type ) ); |
|
206 | + break; |
|
207 | + |
|
208 | + case 'total_percentage': |
|
209 | + $amount .= '% ' . esc_html__( 'Off', 'lsx-currencies' ); |
|
210 | + $before = str_replace( 'from', '', $before ); |
|
211 | + break; |
|
212 | + |
|
213 | + case 'none': |
|
214 | + default: |
|
215 | + $amount = $currency . $amount; |
|
216 | + break; |
|
217 | + } |
|
218 | + |
|
219 | + $return_html = $before . $prefix . $amount . $suffix . $after; |
|
220 | + } |
|
221 | + |
|
222 | + return $return_html; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Filter on the 'wp_nav_menu_items' hook, that potentially adds a currency switcher to the item of some menus. |
|
227 | + * |
|
228 | + * @param $items string |
|
229 | + * @param $args object |
|
230 | + * |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function wp_nav_menu_items_filter( $items, $args ) { |
|
234 | + if ( '' !== lsx_currencies()->menus && lsx_currencies()->menus === $args->theme_location ) { |
|
235 | + if ( 'top-menu' === $args->theme_location ) { |
|
236 | + $items = $this->get_menu_html( $args ) . $items; |
|
237 | + } else { |
|
238 | + $items = $items . $this->get_menu_html( $args ); |
|
239 | + } |
|
240 | + } |
|
241 | + return $items; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Returns the HTML string of the language switcher for a given menu. |
|
246 | + * |
|
247 | + * @param $args object |
|
248 | + * |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + private function get_menu_html( $args ) { |
|
252 | + if ( empty( lsx_currencies()->additional_currencies ) ) { |
|
253 | + return ''; |
|
254 | + } |
|
255 | + |
|
256 | + $items = ''; |
|
257 | + $items .= '<li class="menu-item menu-item-currency menu-item-currency-current menu-item-has-children dropdown">'; |
|
258 | + $items .= isset( $args->before ) ? $args->before : ''; |
|
259 | + $items .= '<a class="current symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $this->current_currency ) . '">'; |
|
260 | + $items .= isset( $args->link_before ) ? $args->link_before : ''; |
|
261 | + |
|
262 | + if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) { |
|
263 | + $items .= lsx_currencies()->get_currency_flag( $this->current_currency ); |
|
264 | + } |
|
265 | + |
|
266 | + if ( 'left' === lsx_currencies()->switcher_symbol_position ) { |
|
267 | + $items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>'; |
|
268 | + } |
|
269 | + |
|
270 | + $items .= $this->current_currency; |
|
271 | + |
|
272 | + if ( 'right' === lsx_currencies()->switcher_symbol_position ) { |
|
273 | + $items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>'; |
|
274 | + } |
|
275 | + |
|
276 | + if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) { |
|
277 | + $items .= lsx_currencies()->get_currency_flag( $this->current_currency ); |
|
278 | + } |
|
279 | + |
|
280 | + $items .= isset( $args->link_after ) ? $args->link_after : ''; |
|
281 | + $items .= '<span class="caret"></span></a>'; |
|
282 | + $items .= isset( $args->after ) ? $args->after : ''; |
|
283 | + $items .= $this->render_sub_items(); |
|
284 | + $items .= '</li>'; |
|
285 | + return $items; |
|
286 | + } |
|
287 | + /** |
|
288 | + * Returns the HTML string of the language switcher for a given menu. |
|
289 | + * |
|
290 | + * @param object $args |
|
291 | + * |
|
292 | + * @return string |
|
293 | + */ |
|
294 | + private function render_sub_items() { |
|
295 | + $sub_items = ''; |
|
296 | + foreach ( lsx_currencies()->additional_currencies as $key => $currency ) { |
|
297 | + $hidden = ''; |
|
298 | + $class = ''; |
|
299 | + |
|
300 | + if ( $this->current_currency === $key ) { |
|
301 | + $hidden = 'style="display:none";'; |
|
302 | + $class = 'hidden'; |
|
303 | + } |
|
304 | + |
|
305 | + $sub_items .= '<li ' . $hidden . ' class="' . $class . ' menu-item menu-item-currency ' . lsx_currencies()->switcher_symbol_position . '">'; |
|
306 | + $sub_items .= '<a class=" symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $key ) . '">'; |
|
307 | + |
|
308 | + if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) { |
|
309 | + $sub_items .= lsx_currencies()->get_currency_flag( $key ); |
|
310 | + } |
|
311 | + |
|
312 | + if ( 'left' === lsx_currencies()->switcher_symbol_position ) { |
|
313 | + $sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>'; |
|
314 | + } |
|
315 | + |
|
316 | + $sub_items .= ucwords( $key ); |
|
317 | + |
|
318 | + if ( 'right' === lsx_currencies()->switcher_symbol_position ) { |
|
319 | + $sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>'; |
|
320 | + } |
|
321 | + |
|
322 | + if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) { |
|
323 | + $sub_items .= lsx_currencies()->get_currency_flag( $key ); |
|
324 | + } |
|
325 | + |
|
326 | + $sub_items .= '</a></li>'; |
|
327 | + } |
|
328 | + |
|
329 | + $sub_items = '<ul class="sub-menu submenu-currency dropdown-menu">' . $sub_items . '</ul>'; |
|
330 | + return $sub_items; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Allow data params for Slick slider addon. |
|
335 | + */ |
|
336 | + public function wp_kses_allowed_html( $allowedtags, $context ) { |
|
337 | + if ( ! isset( $allowedtags['span'] ) ) { |
|
338 | + $allowedtags['span'] = array(); |
|
339 | + } |
|
340 | + |
|
341 | + $allowedtags['span']['data-price-AUD'] = true; |
|
342 | + $allowedtags['span']['data-price-BRL'] = true; |
|
343 | + $allowedtags['span']['data-price-GBP'] = true; |
|
344 | + $allowedtags['span']['data-price-BWP'] = true; |
|
345 | + $allowedtags['span']['data-price-CAD'] = true; |
|
346 | + $allowedtags['span']['data-price-CNY'] = true; |
|
347 | + $allowedtags['span']['data-price-EUR'] = true; |
|
348 | + $allowedtags['span']['data-price-HKD'] = true; |
|
349 | + $allowedtags['span']['data-price-INR'] = true; |
|
350 | + $allowedtags['span']['data-price-IDR'] = true; |
|
351 | + $allowedtags['span']['data-price-ILS'] = true; |
|
352 | + $allowedtags['span']['data-price-JPY'] = true; |
|
353 | + $allowedtags['span']['data-price-KES'] = true; |
|
354 | + $allowedtags['span']['data-price-LAK'] = true; |
|
355 | + $allowedtags['span']['data-price-MWK'] = true; |
|
356 | + $allowedtags['span']['data-price-MYR'] = true; |
|
357 | + $allowedtags['span']['data-price-MZN'] = true; |
|
358 | + $allowedtags['span']['data-price-NAD'] = true; |
|
359 | + $allowedtags['span']['data-price-NZD'] = true; |
|
360 | + $allowedtags['span']['data-price-NOK'] = true; |
|
361 | + $allowedtags['span']['data-price-RUB'] = true; |
|
362 | + $allowedtags['span']['data-price-SGD'] = true; |
|
363 | + $allowedtags['span']['data-price-ZAR'] = true; |
|
364 | + $allowedtags['span']['data-price-SEK'] = true; |
|
365 | + $allowedtags['span']['data-price-CHF'] = true; |
|
366 | + $allowedtags['span']['data-price-TZS'] = true; |
|
367 | + $allowedtags['span']['data-price-USD'] = true; |
|
368 | + $allowedtags['span']['data-price-AED'] = true; |
|
369 | + $allowedtags['span']['data-price-ZMW'] = true; |
|
370 | + $allowedtags['span']['data-price-ZWL'] = true; |
|
371 | + |
|
372 | + return $allowedtags; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Allow empty prices if the convert to single currency is active. |
|
377 | + * |
|
378 | + * @param null $metadata |
|
379 | + * @param string $object_id |
|
380 | + * @param string $meta_key |
|
381 | + * @param boolean $single |
|
382 | + * @return void |
|
383 | + */ |
|
384 | + public function filter_post_meta( $metadata = null, $object_id, $meta_key, $single ) { |
|
385 | + if ( true === lsx_currencies()->convert_to_single && 'price' === $meta_key ) { |
|
386 | + $meta_cache = wp_cache_get( $object_id, 'post_meta' ); |
|
387 | + |
|
388 | + if ( ! isset( $meta_cache[ $meta_key ] ) || '' === $meta_cache[ $meta_key ] ) { |
|
389 | + $metadata = '0'; |
|
390 | + } |
|
391 | + } |
|
392 | + return $metadata; |
|
393 | + } |
|
394 | 394 | } |