Completed
Push — master ( 37bd96...3d5289 )
by
unknown
15s queued 10s
created
WC_Pagantis.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 }
20 20
 
21 21
 
22
-require_once(__DIR__ . '/includes/pg-functions.php');
22
+require_once(__DIR__.'/includes/pg-functions.php');
23 23
 
24 24
 /**
25 25
  * Required minimums and constants
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     public function __construct()
82 82
     {
83 83
         require_once(plugin_dir_path(__FILE__).'/vendor/autoload.php');
84
-        require_once(PG_ABSPATH . '/includes/pg-functions.php');
84
+        require_once(PG_ABSPATH.'/includes/pg-functions.php');
85 85
 
86 86
         $this->template_path = plugin_dir_path(__FILE__).'/templates/';
87 87
 
@@ -98,15 +98,15 @@  discard block
 block discarded – undo
98 98
         add_action('init', array($this, 'checkWcPriceSettings'), 10);
99 99
         add_action('woocommerce_after_template_part', array($this, 'pagantisAddSimulatorHtmlDiv'), 10);
100 100
         add_action('woocommerce_single_product_summary', array($this, 'pagantisInitProductSimulator'), 20);
101
-        add_action('woocommerce_single_variation', array($this,'pagantisAddProductSnippetForVariations'), 30);
101
+        add_action('woocommerce_single_variation', array($this, 'pagantisAddProductSnippetForVariations'), 30);
102 102
         add_action('wp_enqueue_scripts', 'add_pagantis_widget_js');
103 103
         add_action('rest_api_init', array($this, 'pagantisRegisterEndpoint')); //Endpoint
104 104
         add_filter('load_textdomain_mofile', array($this, 'loadPagantisTranslation'), 10, 2);
105 105
         register_activation_hook(__FILE__, array($this, 'pagantisActivation'));
106 106
         add_action('woocommerce_product_options_general_product_data', array($this, 'pagantisPromotedProductTpl'));
107 107
         add_action('woocommerce_process_product_meta', array($this, 'pagantisPromotedVarSave'));
108
-        add_action('woocommerce_product_bulk_edit_start', array($this,'pagantisPromotedBulkTemplate'));
109
-        add_action('woocommerce_product_bulk_edit_save', array($this,'pagantisPromotedBulkTemplateSave'));
108
+        add_action('woocommerce_product_bulk_edit_start', array($this, 'pagantisPromotedBulkTemplate'));
109
+        add_action('woocommerce_product_bulk_edit_save', array($this, 'pagantisPromotedBulkTemplateSave'));
110 110
     }
111 111
 
112 112
     /**
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     {
133 133
         $post_id = $product->get_id();
134 134
         $pagantis_promoted_value = $_REQUEST['pagantis_promoted'];
135
-        if ($pagantis_promoted_value === 'on') {
135
+        if ($pagantis_promoted_value==='on') {
136 136
             $pagantis_promoted_value = 'yes';
137 137
         } else {
138 138
             $pagantis_promoted_value = 'no';
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     public function pagantisPromotedVarSave($post_id)
167 167
     {
168 168
         $pagantis_promoted_value = $_POST['pagantis_promoted'];
169
-        if ($pagantis_promoted_value !== 'yes') {
169
+        if ($pagantis_promoted_value!=='yes') {
170 170
             $pagantis_promoted_value = 'no';
171 171
         }
172 172
 
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function loadPagantisTranslation($mofile, $domain)
182 182
     {
183
-        if ('pagantis' === $domain) {
184
-            $mofile = WP_LANG_DIR . '/../plugins/pagantis/languages/pagantis-' . get_locale() . '.mo';
183
+        if ('pagantis'===$domain) {
184
+            $mofile = WP_LANG_DIR.'/../plugins/pagantis/languages/pagantis-'.get_locale().'.mo';
185 185
         }
186 186
         return $mofile;
187 187
     }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         global $wpdb;
195 195
 
196 196
         $tableName = $wpdb->prefix.PG_CONCURRENCY_TABLE_NAME;
197
-        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
197
+        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'")!=$tableName) {
198 198
             $charset_collate = $wpdb->get_charset_collate();
199 199
             $sql = "CREATE TABLE $tableName ( order_id int NOT NULL,  
200 200
                     createdAt timestamp DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY id (order_id)) $charset_collate";
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
206 206
 
207 207
         //Check if table exists
208
-        $tableExists = $wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName;
208
+        $tableExists = $wpdb->get_var("SHOW TABLES LIKE '$tableName'")!=$tableName;
209 209
         if ($tableExists) {
210 210
             $charset_collate = $wpdb->get_charset_collate();
211 211
             $sql = "CREATE TABLE IF NOT EXISTS $tableName (
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
             //Updated value field to adapt to new length < v8.0.1
221 221
             $query = "select COLUMN_TYPE FROM information_schema.COLUMNS where TABLE_NAME='$tableName' AND COLUMN_NAME='value'";
222 222
             $results = $wpdb->get_results($query, ARRAY_A);
223
-            if ($results['0']['COLUMN_TYPE'] == 'varchar(100)') {
223
+            if ($results['0']['COLUMN_TYPE']=='varchar(100)') {
224 224
                 $sql = "ALTER TABLE $tableName MODIFY value varchar(1000)";
225 225
                 $wpdb->query($sql);
226 226
             }
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
                                or config='PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'";
231 231
             $dbCurrentConfig = $wpdb->get_results($query, ARRAY_A);
232 232
             foreach ($dbCurrentConfig as $item) {
233
-                if ($item['config'] == 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR') {
233
+                if ($item['config']=='PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR') {
234 234
                     $css_price_selector = $this->preparePriceSelector($item['value']);
235
-                    if ($item['value'] != $css_price_selector) {
235
+                    if ($item['value']!=$css_price_selector) {
236 236
                         $wpdb->update(
237 237
                             $tableName,
238 238
                             array('value' => stripslashes($css_price_selector)),
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
                             array('%s')
242 242
                         );
243 243
                     }
244
-                } elseif ($item['config'] == 'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR') {
244
+                } elseif ($item['config']=='PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR') {
245 245
                     $css_quantity_selector = $this->prepareQuantitySelector($item['value']);
246
-                    if ($item['value'] != $css_quantity_selector) {
246
+                    if ($item['value']!=$css_quantity_selector) {
247 247
                         $wpdb->update(
248 248
                             $tableName,
249 249
                             array('value' => stripslashes($css_quantity_selector)),
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
         }
258 258
 
259 259
         // Making sure DB tables are created < v8.6.9
260
-        if (!isPgTableCreated(PG_LOGS_TABLE_NAME)){
260
+        if (!isPgTableCreated(PG_LOGS_TABLE_NAME)) {
261 261
             createLogsTable();
262 262
         }
263 263
         checkCartProcessTable();
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
267 267
         $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'";
268 268
         $results = $wpdb->get_results($query, ARRAY_A);
269
-        if (count($results) == 0) {
269
+        if (count($results)==0) {
270 270
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR', 'value'  => '.'), array('%s', '%s'));
271 271
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR', 'value'  => ','), array('%s', '%s'));
272 272
         }
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
276 276
         $query = "select * from $tableName where config='PAGANTIS_DISPLAY_MAX_AMOUNT'";
277 277
         $results = $wpdb->get_results($query, ARRAY_A);
278
-        if (count($results) == 0) {
278
+        if (count($results)==0) {
279 279
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_DISPLAY_MAX_AMOUNT', 'value'  => '0'), array('%s', '%s'));
280 280
         }
281 281
 
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
284 284
         $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_DISPLAY_SITUATION'";
285 285
         $results = $wpdb->get_results($query, ARRAY_A);
286
-        if (count($results) == 0) {
286
+        if (count($results)==0) {
287 287
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_DISPLAY_SITUATION', 'value'  => 'default'), array('%s', '%s'));
288 288
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_SELECTOR_VARIATION', 'value'  => 'default'), array('%s', '%s'));
289 289
         }
@@ -293,17 +293,17 @@  discard block
 block discarded – undo
293 293
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
294 294
         $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_DISPLAY_TYPE_CHECKOUT'";
295 295
         $results = $wpdb->get_results($query, ARRAY_A);
296
-        if (count($results) == 0) {
296
+        if (count($results)==0) {
297 297
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_DISPLAY_TYPE_CHECKOUT', 'value'  => 'sdk.simulator.types.CHECKOUT_PAGE'), array('%s', '%s'));
298 298
             $wpdb->update($tableName, array('value' => 'sdk.simulator.types.PRODUCT_PAGE'), array('config' => 'PAGANTIS_SIMULATOR_DISPLAY_TYPE'), array('%s'), array('%s'));
299 299
         }
300 300
 
301 301
         //Adapting to variable selector < v8.3.6
302
-        $variableSelector="div.summary div.woocommerce-variation.single_variation > div.woocommerce-variation-price span.price";
302
+        $variableSelector = "div.summary div.woocommerce-variation.single_variation > div.woocommerce-variation-price span.price";
303 303
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
304 304
         $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_SELECTOR_VARIATION' and value='default'";
305 305
         $results = $wpdb->get_results($query, ARRAY_A);
306
-        if (count($results) == 0) {
306
+        if (count($results)==0) {
307 307
             $wpdb->update($tableName, array('value' => $variableSelector), array('config' => 'PAGANTIS_SIMULATOR_SELECTOR_VARIATION'), array('%s'), array('%s'));
308 308
         }
309 309
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
312 312
         $query = "select * from $tableName where config='PAGANTIS_TITLE_4x'";
313 313
         $results = $wpdb->get_results($query, ARRAY_A);
314
-        if (count($results) == 0) {
314
+        if (count($results)==0) {
315 315
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_TITLE_4x', 'value'  => 'Until 4 installments, without fees'), array('%s', '%s'));
316 316
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_DISPLAY_MIN_AMOUNT_4x', 'value'  => 1), array('%s', '%s'));
317 317
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_DISPLAY_MAX_AMOUNT_4x', 'value'  => 800), array('%s', '%s'));
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
325 325
         $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR_4X'";
326 326
         $results = $wpdb->get_results($query, ARRAY_A);
327
-        if (count($results) == 0) {
327
+        if (count($results)==0) {
328 328
             $wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR_4X', 'value'  => 'default'), array('%s', '%s'));
329 329
         }
330 330
 
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
         $tableName = $wpdb->prefix.PG_CONFIG_TABLE_NAME;
341 341
         $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'";
342 342
         $results = $wpdb->get_results($query, ARRAY_A);
343
-        if (count($results) == 0) {
343
+        if (count($results)==0) {
344 344
             $wpdb->update($tableName, array('value' => 'a:4:{i:0;s:52:"div.summary *:not(del)>.woocommerce-Price-amount bdi";i:1;s:48:"div.summary *:not(del)>.woocommerce-Price-amount";i:2;s:54:"div.entry-summary *:not(del)>.woocommerce-Price-amount";i:3;s:36:"*:not(del)>.woocommerce-Price-amount";}'), array('config' => 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'), array('%s'), array('%s'));
345 345
         }
346 346
 
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         $isAtcTplPresent = isTemplatePresent(
434 434
             $template_name,
435 435
             array('single-product/add-to-cart/variation-add-to-cart-button.php',
436
-                'single-product/add-to-cart/variation.php','single-product/add-to-cart/simple.php')
436
+                'single-product/add-to-cart/variation.php', 'single-product/add-to-cart/simple.php')
437 437
         );
438 438
 
439 439
         $html = apply_filters('pagantis_simulator_selector_html', '<div class="mainPagantisSimulator"></div><div class="pagantisSimulator"></div>');
@@ -445,10 +445,10 @@  discard block
 block discarded – undo
445 445
         }
446 446
 
447 447
         $pagantisSimulator4x = 'enabled';
448
-        if (!isPluginEnabled4x() || !areMerchantKeysSet4x()  || !isCountryShopContextValid() || !isProductAmountValid4x()) {
448
+        if (!isPluginEnabled4x() || !areMerchantKeysSet4x() || !isCountryShopContextValid() || !isProductAmountValid4x()) {
449 449
             $pagantisSimulator4x = 'disabled';
450 450
         }
451
-        if ($pagantisSimulator === 'disabled' && $pagantisSimulator4x === 'disabled') {
451
+        if ($pagantisSimulator==='disabled' && $pagantisSimulator4x==='disabled') {
452 452
             return;
453 453
         }
454 454
 
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
             $pagantisSimulator4x = 'disabled';
505 505
         }
506 506
 
507
-        if ($pagantisSimulator === 'disabled' && $pagantisSimulator4x === 'disabled') {
507
+        if ($pagantisSimulator==='disabled' && $pagantisSimulator4x==='disabled') {
508 508
             return;
509 509
         }
510 510
 
511 511
         $totalPrice = $product->get_price();
512
-        $formattedInstallments = number_format($totalPrice/4, 2);
512
+        $formattedInstallments = number_format($totalPrice / 4, 2);
513 513
         $simulatorMessage = sprintf(__('or 4 installments of %s€, without fees, with ', 'pagantis'), $formattedInstallments);
514 514
         $post_id = $product->get_id();
515 515
         $simulatorData = array(
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
      */
552 552
     public function addPagantisGateway($methods)
553 553
     {
554
-        if (! class_exists('WC_Payment_Gateway')) {
554
+        if (!class_exists('WC_Payment_Gateway')) {
555 555
             return $methods;
556 556
         }
557 557
 
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
      */
617 617
     public function pagantisRowMeta($links, $file)
618 618
     {
619
-        if ($file == plugin_basename(__FILE__)) {
619
+        if ($file==plugin_basename(__FILE__)) {
620 620
             $links[] = '<a href="'.WcPagantis::GIT_HUB_URL.'" target="_blank">'.__('Documentation', 'pagantis').'</a>';
621 621
             $links[] = '<a href="'.WcPagantis::PAGANTIS_DOC_URL.'" target="_blank">'.
622 622
                        __('API documentation', 'pagantis').'</a>';
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
         $tableName = $wpdb->prefix.PG_LOGS_TABLE_NAME;
646 646
         $query = "select * from $tableName where createdAt>$from and createdAt<$to order by createdAt desc";
647 647
         $results = $wpdb->get_results($query);
648
-        if (isset($results) && ($privateKey == $secretKey || $privateKey4x == $secretKey)) {
648
+        if (isset($results) && ($privateKey==$secretKey || $privateKey4x==$secretKey)) {
649 649
             foreach ($results as $key => $result) {
650 650
                 $response[$key]['timestamp'] = $result->createdAt;
651 651
                 $response[$key]['log']       = json_decode($result->log);
@@ -672,13 +672,13 @@  discard block
 block discarded – undo
672 672
 
673 673
         $filters   = ($data->get_params());
674 674
         $secretKey = $filters['secret'];
675
-        $cfg  = get_option('woocommerce_pagantis_settings');
675
+        $cfg = get_option('woocommerce_pagantis_settings');
676 676
         $privateKey   = isset($cfg['pagantis_private_key']) ? $cfg['pagantis_private_key'] : null;
677 677
         $privateKey4x = isset($cfg['pagantis_private_key_4x']) ? $cfg['pagantis_private_key_4x'] : null;
678
-        if ($privateKey != $secretKey && $privateKey4x != $secretKey) {
678
+        if ($privateKey!=$secretKey && $privateKey4x!=$secretKey) {
679 679
             $response['status'] = 401;
680 680
             $response['result'] = 'Unauthorized';
681
-        } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
681
+        } elseif ($_SERVER['REQUEST_METHOD']=='POST') {
682 682
             if (count($_POST)) {
683 683
                 foreach ($_POST as $config => $value) {
684 684
                     if (isset($this->defaultConfigs[$config]) && $response['status']==null) {
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
                   and tn.post_date<'".$to->format("Y-m-d")."' order by tn.post_date desc";
740 740
         $results = $wpdb->get_results($query);
741 741
 
742
-        if (isset($results) && ($privateKey == $secretKey || $privateKey4x == $secretKey)) {
742
+        if (isset($results) && ($privateKey==$secretKey || $privateKey4x==$secretKey)) {
743 743
             foreach ($results as $result) {
744 744
                 $key = $result->ID;
745 745
                 $response['message'][$key]['timestamp'] = $result->post_date;
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
      */
813 813
     private function prepareQuantitySelector($css_quantity_selector)
814 814
     {
815
-        if ($css_quantity_selector == 'default' || $css_quantity_selector == '') {
815
+        if ($css_quantity_selector=='default' || $css_quantity_selector=='') {
816 816
             $css_quantity_selector = $this->defaultConfigs['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'];
817 817
         } elseif (!unserialize($css_quantity_selector)) { //in the case of a custom string selector, we keep it
818 818
             $css_quantity_selector = serialize(array($css_quantity_selector));
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
      */
829 829
     private function preparePriceSelector($css_price_selector)
830 830
     {
831
-        if ($css_price_selector == 'default' || $css_price_selector == '') {
831
+        if ($css_price_selector=='default' || $css_price_selector=='') {
832 832
             $css_price_selector = $this->defaultConfigs['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'];
833 833
         } elseif (!unserialize($css_price_selector)) { //in the case of a custom string selector, we keep it
834 834
             $css_price_selector = serialize(array($css_price_selector));
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
     {
847 847
         $metaProduct = get_post_meta($product_id);
848 848
         return (array_key_exists('custom_product_pagantis_promoted', $metaProduct) &&
849
-                $metaProduct['custom_product_pagantis_promoted']['0'] === 'yes') ? 'true' : 'false';
849
+                $metaProduct['custom_product_pagantis_promoted']['0']==='yes') ? 'true' : 'false';
850 850
     }
851 851
 
852 852
     /**
Please login to merge, or discard this patch.