1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
use Pagantis\ModuleUtils\Model\Log\LogEntry; |
5
|
|
|
|
6
|
|
|
require_once dirname(__FILE__) . '/class-wc-pagantis-config.php'; |
7
|
|
|
|
8
|
|
|
function pg_areKeysSet() |
9
|
|
|
{ |
10
|
|
|
$settings = pg_get_plugin_settings(); |
11
|
|
|
if ($settings['pagantis_public_key'] == '' || $settings['pagantis_private_key'] == '') { |
12
|
|
|
return false; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
return true; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
function pg_isSimulatorSettingEnabled() |
19
|
|
|
{ |
20
|
|
|
$settings = pg_get_plugin_settings(); |
21
|
|
|
|
22
|
|
|
if ($settings['simulator'] !== 'yes') { |
23
|
|
|
WC_Admin_Settings::add_error(__('Error: PG Simulator is not enabled', 'pagantis')); |
|
|
|
|
24
|
|
|
|
25
|
|
|
return false; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return true; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function pg_IsCountryAllowed() |
32
|
|
|
{ |
33
|
|
|
$locale = strtolower(strstr(get_locale(), '_', true)); |
|
|
|
|
34
|
|
|
$allowedCountries = WC_Pagantis_Config::getAllowedCountriesSerialized(); |
35
|
|
|
$allowedCountry = (in_array(strtolower($locale), $allowedCountries)); |
36
|
|
|
|
37
|
|
|
if (! $allowedCountry) { |
38
|
|
|
return false; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function pg_IsAmountValid() |
45
|
|
|
{ |
46
|
|
|
global $product; |
47
|
|
|
$locale = pg_GetLocaleString(); |
48
|
|
|
$allowedCountries = WC_Pagantis_Config::getAllowedCountriesSerialized(); |
49
|
|
|
$allowedCountry = (in_array(strtolower($locale), $allowedCountries)); |
|
|
|
|
50
|
|
|
$minAmount = WC_Pagantis_Config::getValueOfKey('PAGANTIS_DISPLAY_MIN_AMOUNT'); |
51
|
|
|
$maxAmount = WC_Pagantis_Config::getValueOfKey('PAGANTIS_DISPLAY_MAX_AMOUNT'); |
52
|
|
|
$totalPrice = $product->get_price(); |
53
|
|
|
$validAmount = ($totalPrice >= $minAmount && ($totalPrice <= $maxAmount || $maxAmount == '0')); |
54
|
|
|
if (! $validAmount) { |
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function pg_get_plugin_settings() |
62
|
|
|
{ |
63
|
|
|
$settings = get_option('woocommerce_pagantis_settings'); |
|
|
|
|
64
|
|
|
|
65
|
|
|
return $settings; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
function pg_GetLocaleString() |
69
|
|
|
{ |
70
|
|
|
$locale = strtolower(strstr(get_locale(), '_', true)); |
|
|
|
|
71
|
|
|
|
72
|
|
|
return $locale; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function pg_canProductSimulatorLoad() |
76
|
|
|
{ |
77
|
|
|
global $product; |
78
|
|
|
|
79
|
|
|
$settings = get_option('woocommerce_pagantis_settings'); |
|
|
|
|
80
|
|
|
$locale = strtolower(strstr(get_locale(), '_', true)); |
|
|
|
|
81
|
|
|
$allowedCountries = WC_Pagantis_Config::getAllowedCountriesSerialized(); |
82
|
|
|
$allowedCountry = (in_array(strtolower($locale), $allowedCountries)); |
|
|
|
|
83
|
|
|
$minAmount = WC_Pagantis_Config::getValueOfKey('PAGANTIS_DISPLAY_MIN_AMOUNT'); |
84
|
|
|
$maxAmount = WC_Pagantis_Config::getValueOfKey('PAGANTIS_DISPLAY_MAX_AMOUNT'); |
85
|
|
|
$totalPrice = $product->get_price(); |
86
|
|
|
$validAmount = ($totalPrice >= $minAmount && ($totalPrice <= $maxAmount || $maxAmount == '0')); |
|
|
|
|
87
|
|
|
if ($settings['enabled'] !== 'yes' || pg_areKeysSet() || pg_isSimulatorSettingEnabled() |
88
|
|
|
|| ! pg_IsCountryAllowed() |
89
|
|
|
|| ! pg_IsAmountValid() |
90
|
|
|
) { |
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param $product_id |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
function pg_isProductPromoted($product_id) |
101
|
|
|
{ |
102
|
|
|
$metaProduct = get_post_meta($product_id); |
|
|
|
|
103
|
|
|
|
104
|
|
|
return (array_key_exists('custom_product_pagantis_promoted', $metaProduct) |
105
|
|
|
&& $metaProduct['custom_product_pagantis_promoted']['0'] === 'yes') ? 'true' : 'false'; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Determines if the plugin is active.* |
110
|
|
|
* |
111
|
|
|
* @return bool True, if in the active plugins list. False, not in the list. |
112
|
|
|
* @since 8.3.7 |
113
|
|
|
*/ |
114
|
|
|
function pg_isPluginActive() |
115
|
|
|
{ |
116
|
|
|
return in_array('pagantis', (array) get_option('active_plugins', array()), true); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param $css_price_selector |
122
|
|
|
* |
123
|
|
|
* @return mixed|string |
124
|
|
|
*/ |
125
|
|
|
function preparePriceSelector($css_price_selector) |
126
|
|
|
{ |
127
|
|
|
if ($css_price_selector === 'default' || $css_price_selector === '') { |
128
|
|
|
$css_price_selector === $this->defaultConfigs['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']; |
|
|
|
|
129
|
|
|
} elseif (! unserialize($css_price_selector)) { //in the case of a custom string selector, we keep it |
130
|
|
|
$css_price_selector = serialize(array($css_price_selector)); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return $css_price_selector; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
function pg_wc_is_screen_correct() |
137
|
|
|
{ |
138
|
|
|
$current_screen = get_current_screen(); |
|
|
|
|
139
|
|
|
if ('shop_order' === $current_screen->id || 'plugins' === $current_screen->id |
140
|
|
|
|| 'woocommerce_page_wc-settings' === $current_screen->id |
141
|
|
|
) { |
142
|
|
|
return true; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return false; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
function pg_wc_get_pagantis_admin_url() |
150
|
|
|
{ |
151
|
|
|
return admin_url('admin.php?page=wc-settings&tab=checkout§ion=pagantis'); |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @global wpdb $wpdb WordPress database abstraction object. |
156
|
|
|
*/ |
157
|
|
|
function pg_wc_check_db_log_table() |
158
|
|
|
{ |
159
|
|
|
global $wpdb; |
160
|
|
|
$tableName = $wpdb->prefix . PAGANTIS_LOGS_TABLE; |
161
|
|
|
if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") !== $tableName) { |
162
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
163
|
|
|
$sql = "CREATE TABLE $tableName ( id int NOT NULL AUTO_INCREMENT, log text NOT NULL, |
164
|
|
|
createdAt timestamp DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY id (id)) $charset_collate"; |
165
|
|
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
|
|
|
166
|
|
|
dbDelta($sql); |
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Determine if the store is running SSL. |
175
|
|
|
* |
176
|
|
|
* @return bool Flag SSL enabled. |
177
|
|
|
* @since 8.3.7 |
178
|
|
|
*/ |
179
|
|
|
function pg_wc_is_ssl_active() |
180
|
|
|
{ |
181
|
|
|
$shop_page = wc_get_page_permalink('shop'); |
|
|
|
|
182
|
|
|
|
183
|
|
|
return (is_ssl() && 'https' === substr($shop_page, 0, 5)); |
|
|
|
|
184
|
|
|
} |
185
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths