Ecwid Ecommerce Shopping Cart - Version 6.10.26

Version Description

  • Aug 16, 2022 =
  • Compatibility improvements with the Elementor builder. If you are using the ecommerce widget in the Elementor builder, you may have encountered an issue where the storefront links in the menu or sitemap are not working properly. We've fixed it.
  • Plugin code improvements to comply with the WordPress plugin marketplace recommendations.
  • Minor fixes and improvements.
Download this release

Release Info

Developer Ecwid
Plugin Icon 128x128 Ecwid Ecommerce Shopping Cart
Version 6.10.26
Comparing to
See all releases

Code changes from version 6.10.25 to 6.10.26

Files changed (40) hide show
  1. ecwid-shopping-cart.php +40 -74
  2. includes/class-ecwid-admin-developers-page.php +1 -1
  3. includes/class-ecwid-admin-storefront-page.php +11 -6
  4. includes/class-ecwid-admin-ui-framework.php +59 -63
  5. includes/class-ecwid-ajax-defer-renderer.php +101 -103
  6. includes/class-ecwid-custom-admin-page.php +42 -51
  7. includes/class-ecwid-floating-minicart.php +94 -102
  8. includes/class-ecwid-message-manager.php +16 -32
  9. includes/class-ecwid-product-popup.php +7 -9
  10. includes/class-ecwid-seo-links.php +167 -151
  11. includes/class-ecwid-store-editor.php +35 -47
  12. includes/class-ecwid-store-page.php +186 -185
  13. includes/class-ecwid-wp-dashboard-feed.php +58 -55
  14. includes/gutenberg/class-ecwid-gutenberg-block-cart-page.php +14 -10
  15. includes/gutenberg/class-ecwid-gutenberg-block-filters-page.php +13 -9
  16. includes/importer/class-ecwid-import-page.php +4 -4
  17. includes/integrations/class-ecwid-integration-aiosp.php +13 -17
  18. includes/integrations/class-ecwid-integration-divibuilder.php +1 -0
  19. includes/integrations/class-ecwid-integration-elementor.php +51 -21
  20. includes/integrations/class-ecwid-integration-gutenberg.php +202 -180
  21. includes/integrations/class-ecwid-integration-rank-math.php +30 -41
  22. includes/integrations/class-ecwid-integration-wpseo.php +11 -26
  23. includes/shortcodes/class-ecwid-shortcode-base.php +44 -45
  24. includes/shortcodes/class-ecwid-shortcode-productbrowser.php +54 -44
  25. includes/shortcodes/class-ecwid-shortcode-stub.php +5 -7
  26. includes/themes.php +3 -3
  27. includes/themes/class-ecwid-theme-avada.php +21 -20
  28. includes/themes/class-ecwid-theme-mfupdate.php +17 -17
  29. includes/themes/class-ecwid-theme-trend.php +9 -90
  30. includes/widgets.php +41 -40
  31. includes/widgets/class-ecwid-widget-badge.php +67 -63
  32. includes/widgets/class-ecwid-widget-floating-shopping-cart.php +63 -59
  33. includes/widgets/class-ecwid-widget-products-base.php +32 -30
  34. includes/widgets/class-ecwid-widget-random-product.php +34 -33
  35. includes/widgets/class-ecwid-widget-recently-viewed.php +47 -50
  36. js/frontend.js +14 -14
  37. readme.txt +7 -2
  38. templates/admin-message.php +18 -16
  39. templates/debug.php +19 -19
  40. templates/product.php +2 -5
ecwid-shopping-cart.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.ecwid.com?partner=wporg
5
  Description: Ecwid is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
6
  Text Domain: ecwid-shopping-cart
7
  Author: Ecwid Ecommerce
8
- Version: 6.10.25
9
  Author URI: https://ecwid.to/ecwid-site
10
  License: GPLv2 or later
11
  */
@@ -337,20 +337,22 @@ function ecwid_ie8_fonts_inclusion() {
337
  }
338
 
339
  $url = ECWID_PLUGIN_URL . 'fonts/ecwid-logo.eot';
340
- echo '<style>
341
- @font-face {
342
- font-family: "ecwid-logo";
343
- src:url(' . esc_url( $url ) . ');
344
- }
345
- </style>';
 
 
346
  }
347
 
348
  add_action( 'wp_head', 'ecwid_maybe_remove_emoji', 0 );
349
  function ecwid_maybe_remove_emoji() {
350
 
351
  if ( Ecwid_Store_page::is_store_page() && get_option( 'ecwid_remove_emoji' ) == 'Y' ) {
352
- remove_action('wp_head', 'print_emoji_detection_script', 7);
353
- remove_action('wp_print_styles', 'print_emoji_styles');
354
 
355
  remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
356
  remove_action( 'admin_print_styles', 'print_emoji_styles' );
@@ -1068,8 +1070,7 @@ function add_ecwid_admin_bar_node() {
1068
  if (!is_admin()) {
1069
  $subject = sprintf( __('%s plugin doesn\'t work well with my "%s" theme', 'ecwid-shopping-cart'), Ecwid_Config::get_brand(), $theme );
1070
 
1071
- $body = <<<TEXT
1072
- Hey %s,
1073
 
1074
  My store looks bad with my theme on Wordpress.
1075
 
@@ -1078,12 +1079,10 @@ The store URL is %s
1078
 
1079
  Can you have a look?
1080
 
1081
- Thanks.
1082
- TEXT;
1083
  } else {
1084
  $subject = __('I have a problem with my %s store', 'ecwid-shopping-cart');
1085
- $body = <<<TEXT
1086
- Hey %s,
1087
 
1088
  I have a problem with my store.
1089
 
@@ -1094,8 +1093,7 @@ The store URL is %s
1094
 
1095
  Can you have a look?
1096
 
1097
- Thanks.
1098
- TEXT;
1099
  }
1100
 
1101
  $body = __($body, 'ecwid-shopping-cart');
@@ -1628,15 +1626,12 @@ function ecwid_store_activate() {
1628
 
1629
  $shortcode = Ecwid_Shortcode_Base::get_current_store_shortcode_name();
1630
 
1631
- $content = <<<EOT
1632
- [$shortcode widgets="productbrowser" default_category_id="0"]
1633
- EOT;
1634
 
1635
- $content = <<<EOT
1636
  <!-- wp:ecwid/store-block -->
1637
  $content
1638
- <!-- /wp:ecwid/store-block -->
1639
- EOT;
1640
 
1641
  add_option("ecwid_store_page_id", '', '', 'yes');
1642
 
@@ -2871,15 +2866,14 @@ function ecwid_get_product_browser_url_script()
2871
  if (ecwid_is_store_page_available() && !Ecwid_Store_Page::is_store_page()) {
2872
 
2873
  $url = esc_js( Ecwid_Store_Page::get_store_url() );
2874
-
2875
-
2876
- $str = <<<HTML
2877
- <script data-cfasync="false" type="text/javascript">
2878
- window.ec = window.ec || Object();
2879
- window.ec.config = window.ec.config || Object();
2880
- window.ec.config.store_main_page_url = '$url';
2881
- </script>
2882
- HTML;
2883
  }
2884
 
2885
  return $str;
@@ -2935,16 +2929,6 @@ function ecwid_sso() {
2935
 
2936
  $signin_url = wp_login_url(Ecwid_Store_Page::get_store_url());
2937
  $signout_url = wp_logout_url(Ecwid_Store_Page::get_store_url());
2938
- $sign_in_out_urls = <<<JS
2939
- window.EcwidSignInUrl = '$signin_url';
2940
- window.EcwidSignOutUrl = '$signout_url';
2941
- window.Ecwid.OnAPILoaded.add(function() {
2942
- window.Ecwid.setSignInUrls({
2943
- signInUrl: '$signin_url',
2944
- signOutUrl: '$signout_url'
2945
- });
2946
- });
2947
- JS;
2948
 
2949
  $ecwid_sso_profile = '';
2950
  if ($current_user->ID) {
@@ -2980,28 +2964,35 @@ JS;
2980
  $hmac = ecwid_hmacsha1("$user_data_encoded $time", $key);
2981
 
2982
  $ecwid_sso_profile = "$user_data_encoded $hmac $time";
2983
-
2984
  }
2985
 
2986
-
2987
- $ecwid_sso_script = <<<HTML
2988
  <script data-cfasync="false" type="text/javascript">
2989
 
2990
- var ecwid_sso_profile='$ecwid_sso_profile';
2991
- $sign_in_out_urls
 
 
 
 
 
 
 
2992
 
2993
  jQuery(document).ready(function() {
2994
  if (typeof Ecwid == 'undefined') return;
2995
 
2996
  Ecwid.OnPageLoad.add(function(page) {
2997
  if (page.type == 'SIGN_IN' && ecwid_sso_profile == '') {
2998
- location.href = '$signin_url';
2999
  }
3000
  })
3001
  }
3002
  );
3003
  </script>
3004
- HTML;
 
3005
 
3006
  return $ecwid_sso_script;
3007
  }
@@ -3087,31 +3078,6 @@ function ecwid_embed_svg($name) {
3087
  }
3088
  }
3089
 
3090
- function ecwid_kses_get_allowed_html() {
3091
- return array(
3092
- 'iframe' => array(
3093
- 'seamless' => array(),
3094
- 'id' => array(),
3095
- 'frameborder' => array(),
3096
- 'width' => array(),
3097
- 'height' => array(),
3098
- 'scrolling' => array(),
3099
- 'src' => array(),
3100
- ),
3101
- 'script' => array(
3102
- 'type' => array(),
3103
- ),
3104
- 'li' => array(),
3105
- 'a' => array(
3106
- 'href' => array(),
3107
- 'data-sort' => array()
3108
- ),
3109
- 'div' => array(
3110
- 'id' => array()
3111
- )
3112
- );
3113
- }
3114
-
3115
  /*
3116
  * Basically a copy of has_shortcode that returns the matched shortcode
3117
  */
5
  Description: Ecwid is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
6
  Text Domain: ecwid-shopping-cart
7
  Author: Ecwid Ecommerce
8
+ Version: 6.10.26
9
  Author URI: https://ecwid.to/ecwid-site
10
  License: GPLv2 or later
11
  */
337
  }
338
 
339
  $url = ECWID_PLUGIN_URL . 'fonts/ecwid-logo.eot';
340
+ ?>
341
+ <style>
342
+ @font-face {
343
+ font-family: "ecwid-logo";
344
+ src: url('<?php echo esc_url( $url ); ?>');
345
+ }
346
+ </style>
347
+ <?php
348
  }
349
 
350
  add_action( 'wp_head', 'ecwid_maybe_remove_emoji', 0 );
351
  function ecwid_maybe_remove_emoji() {
352
 
353
  if ( Ecwid_Store_page::is_store_page() && get_option( 'ecwid_remove_emoji' ) == 'Y' ) {
354
+ remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
355
+ remove_action( 'wp_print_styles', 'print_emoji_styles' );
356
 
357
  remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
358
  remove_action( 'admin_print_styles', 'print_emoji_styles' );
1070
  if (!is_admin()) {
1071
  $subject = sprintf( __('%s plugin doesn\'t work well with my "%s" theme', 'ecwid-shopping-cart'), Ecwid_Config::get_brand(), $theme );
1072
 
1073
+ $body = "Hey %s,
 
1074
 
1075
  My store looks bad with my theme on Wordpress.
1076
 
1079
 
1080
  Can you have a look?
1081
 
1082
+ Thanks.";
 
1083
  } else {
1084
  $subject = __('I have a problem with my %s store', 'ecwid-shopping-cart');
1085
+ $body = "Hey %s,
 
1086
 
1087
  I have a problem with my store.
1088
 
1093
 
1094
  Can you have a look?
1095
 
1096
+ Thanks.";
 
1097
  }
1098
 
1099
  $body = __($body, 'ecwid-shopping-cart');
1626
 
1627
  $shortcode = Ecwid_Shortcode_Base::get_current_store_shortcode_name();
1628
 
1629
+ $content = "[$shortcode widgets=\"productbrowser\" default_category_id=\"0\"]";
 
 
1630
 
1631
+ $content = "
1632
  <!-- wp:ecwid/store-block -->
1633
  $content
1634
+ <!-- /wp:ecwid/store-block -->";
 
1635
 
1636
  add_option("ecwid_store_page_id", '', '', 'yes');
1637
 
2866
  if (ecwid_is_store_page_available() && !Ecwid_Store_Page::is_store_page()) {
2867
 
2868
  $url = esc_js( Ecwid_Store_Page::get_store_url() );
2869
+ ?>
2870
+ <script data-cfasync="false" type="text/javascript">
2871
+ window.ec = window.ec || Object();
2872
+ window.ec.config = window.ec.config || Object();
2873
+ window.ec.config.store_main_page_url = '<?php echo esc_js( $url ); ?>';
2874
+ </script>
2875
+ <?php
2876
+ $str = ob_get_clean();
 
2877
  }
2878
 
2879
  return $str;
2929
 
2930
  $signin_url = wp_login_url(Ecwid_Store_Page::get_store_url());
2931
  $signout_url = wp_logout_url(Ecwid_Store_Page::get_store_url());
 
 
 
 
 
 
 
 
 
 
2932
 
2933
  $ecwid_sso_profile = '';
2934
  if ($current_user->ID) {
2964
  $hmac = ecwid_hmacsha1("$user_data_encoded $time", $key);
2965
 
2966
  $ecwid_sso_profile = "$user_data_encoded $hmac $time";
 
2967
  }
2968
 
2969
+ ob_start();
2970
+ ?>
2971
  <script data-cfasync="false" type="text/javascript">
2972
 
2973
+ var ecwid_sso_profile = '<?php echo esc_js( $ecwid_sso_profile ); ?>';
2974
+ window.EcwidSignInUrl = '<?php echo esc_js( $signin_url ); ?>';
2975
+ window.EcwidSignOutUrl = '<?php echo esc_js( $signout_url ); ?>';
2976
+ window.Ecwid.OnAPILoaded.add(function() {
2977
+ window.Ecwid.setSignInUrls({
2978
+ signInUrl: '<?php echo esc_js( $signin_url ); ?>',
2979
+ signOutUrl: '<?php echo esc_js( $signout_url ); ?>'
2980
+ });
2981
+ });
2982
 
2983
  jQuery(document).ready(function() {
2984
  if (typeof Ecwid == 'undefined') return;
2985
 
2986
  Ecwid.OnPageLoad.add(function(page) {
2987
  if (page.type == 'SIGN_IN' && ecwid_sso_profile == '') {
2988
+ location.href = '<?php echo esc_js( $signin_url ); ?>';
2989
  }
2990
  })
2991
  }
2992
  );
2993
  </script>
2994
+ <?php
2995
+ $ecwid_sso_script = ob_get_clean();
2996
 
2997
  return $ecwid_sso_script;
2998
  }
3078
  }
3079
  }
3080
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3081
  /*
3082
  * Basically a copy of has_shortcode that returns the matched shortcode
3083
  */
includes/class-ecwid-admin-developers-page.php CHANGED
@@ -21,7 +21,7 @@ class Ecwid_Admin_Developers_Page {
21
 
22
  self::$templates_dir = ECWID_PLUGIN_DIR . '/templates/admin/';
23
 
24
- echo Ecwid_Admin_UI_Framework::print_fix_js(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
25
  require_once self::$templates_dir . 'developers.php';
26
  }
27
  }
21
 
22
  self::$templates_dir = ECWID_PLUGIN_DIR . '/templates/admin/';
23
 
24
+ Ecwid_Admin_UI_Framework::print_fix_js();
25
  require_once self::$templates_dir . 'developers.php';
26
  }
27
  }
includes/class-ecwid-admin-storefront-page.php CHANGED
@@ -40,9 +40,11 @@ class Ecwid_Admin_Storefront_Page {
40
  $design_edit_link = get_edit_post_link( $page_id ) . '&ec-show-store-settings';
41
  } else {
42
  $page = Ecwid_Admin_Main_Page::PAGE_HASH_DASHBOARD;
43
- $time = time() - get_option( 'ecwid_time_correction', 0 );
44
  $iframe_src = false;
45
 
 
 
 
46
  if ( ! Ecwid_Admin::disable_dashboard() ) {
47
  $iframe_src = ecwid_get_iframe_src( $time, $page );
48
  }
@@ -72,7 +74,8 @@ class Ecwid_Admin_Storefront_Page {
72
  $products_total = $res->total;
73
  }
74
 
75
- $need_show_draft_warning = time() - get_option( 'ecwid_installation_date' ) > 3 * DAY_IN_SECONDS;
 
76
  } else {
77
  $store_on_front = false;
78
  $page_edit_link = false;
@@ -91,7 +94,7 @@ class Ecwid_Admin_Storefront_Page {
91
 
92
  wp_enqueue_script( 'ecwid-admin-storefront-js', ECWID_PLUGIN_URL . 'js/admin-storefront.js', array(), get_option( 'ecwid_plugin_version' ) );
93
 
94
- echo Ecwid_Admin_UI_Framework::print_fix_js();
95
  require_once self::$templates_dir . 'main.php';
96
  }
97
 
@@ -504,7 +507,7 @@ class Ecwid_Admin_Storefront_Page {
504
  });
505
  ";
506
 
507
- wp_register_script( 'ec-blockeditor-inline-js', '', array(), '', true );
508
  wp_enqueue_script( 'ec-blockeditor-inline-js' );
509
  wp_add_inline_script( 'ec-blockeditor-inline-js', $script );
510
  }
@@ -519,7 +522,9 @@ class Ecwid_Admin_Storefront_Page {
519
  $text = '';
520
 
521
  if ( isset( $item['is_separator'] ) && $item['is_separator'] ) {
522
- echo '<li class="list-dropdown__separator"></li>';
 
 
523
  continue;
524
  }
525
 
@@ -533,7 +538,7 @@ class Ecwid_Admin_Storefront_Page {
533
  $text = $item['text'];
534
  }
535
 
536
- echo sprintf( '<li><a%s>%s</a></li>', $attributes, $text );
537
  }//end foreach
538
  }
539
 
40
  $design_edit_link = get_edit_post_link( $page_id ) . '&ec-show-store-settings';
41
  } else {
42
  $page = Ecwid_Admin_Main_Page::PAGE_HASH_DASHBOARD;
 
43
  $iframe_src = false;
44
 
45
+ $time_correction = get_option( 'ecwid_time_correction', 0 );
46
+ $time = time() - $time_correction;
47
+
48
  if ( ! Ecwid_Admin::disable_dashboard() ) {
49
  $iframe_src = ecwid_get_iframe_src( $time, $page );
50
  }
74
  $products_total = $res->total;
75
  }
76
 
77
+ $plugin_installation_date = get_option( 'ecwid_installation_date' );
78
+ $need_show_draft_warning = time() - $plugin_installation_date > 3 * DAY_IN_SECONDS;
79
  } else {
80
  $store_on_front = false;
81
  $page_edit_link = false;
94
 
95
  wp_enqueue_script( 'ecwid-admin-storefront-js', ECWID_PLUGIN_URL . 'js/admin-storefront.js', array(), get_option( 'ecwid_plugin_version' ) );
96
 
97
+ Ecwid_Admin_UI_Framework::print_fix_js();
98
  require_once self::$templates_dir . 'main.php';
99
  }
100
 
507
  });
508
  ";
509
 
510
+ wp_register_script( 'ec-blockeditor-inline-js', '', array(), get_option( 'ecwid_plugin_version' ), true );
511
  wp_enqueue_script( 'ec-blockeditor-inline-js' );
512
  wp_add_inline_script( 'ec-blockeditor-inline-js', $script );
513
  }
522
  $text = '';
523
 
524
  if ( isset( $item['is_separator'] ) && $item['is_separator'] ) {
525
+ ?>
526
+ <li class="list-dropdown__separator"></li>
527
+ <?php
528
  continue;
529
  }
530
 
538
  $text = $item['text'];
539
  }
540
 
541
+ echo sprintf( '<li><a%s>%s</a></li>', esc_attr( $attributes ), esc_html( $text ) );
542
  }//end foreach
543
  }
544
 
includes/class-ecwid-admin-ui-framework.php CHANGED
@@ -1,78 +1,74 @@
1
  <?php
2
 
3
- class Ecwid_Admin_UI_Framework
4
- {
5
- public function __construct()
6
- {
7
- if( $this->is_need_include_assets() ) {
8
- add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ) );
9
- }
10
- }
11
 
12
- public function register_assets()
13
- {
14
- wp_enqueue_style(
15
- 'ecwid-app-ui',
16
- 'https://djqizrxa6f10j.cloudfront.net/ecwid-sdk/css/1.3.7/ecwid-app-ui.css',
17
- array(),
18
- get_option('ecwid_plugin_version')
19
- );
20
-
21
- wp_enqueue_script(
22
- 'ecwid-app-ui',
23
- 'https://djqizrxa6f10j.cloudfront.net/ecwid-sdk/css/1.3.7/ecwid-app-ui.min.js',
24
- array(),
25
- get_option('ecwid_plugin_version'),
26
- 'in_footer'
27
- );
28
- }
29
 
30
- static public function print_fix_js()
31
- {
32
- $js = '';
33
- $js .= "jQuery(document.body).addClass('ecwid-no-padding');" . PHP_EOL;
34
- $js .= "jQuery(document.body).css({ 'font-size': '13px' });" . PHP_EOL;
35
- $js .= "jQuery('#wpbody').css({ 'background-color': 'rgb(240, 242, 244)' });" . PHP_EOL;
36
-
37
- return sprintf( "<script type='text/javascript'>//<![CDATA[" . PHP_EOL . " %s //]]></script>", $js );
38
- }
39
 
40
- public function is_need_include_assets()
41
- {
42
- if( !isset($_GET['page']) ) {
43
- return false;
44
- }
 
 
 
45
 
46
- $ignore_pages = $this->get_pages_exclude_framework();
47
- $page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
 
 
 
 
 
 
 
48
 
49
- if( in_array($page, $ignore_pages) ) {
50
- return false;
51
- }
 
52
 
53
- if ( strpos($page, 'ec-developers') === 0 ) {
54
- return true;
55
- }
56
- if ( strpos($page, 'ec-store') === 0 ) {
57
- return true;
58
- }
59
 
60
- return false;
61
- }
 
62
 
63
- public function get_pages_exclude_framework() {
64
- $pages = array(
65
- 'ec-store-advanced',
66
- 'ec-store-help'
67
- );
 
68
 
69
- if( ecwid_is_demo_store() || isset($_GET['reconnect']) || Ecwid_Api_V3::get_token() == false ) {
70
- $pages[] = 'ec-store';
71
- }
72
 
73
- return $pages;
74
- }
 
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
  new Ecwid_Admin_UI_Framework();
78
- ?>
1
  <?php
2
 
3
+ class Ecwid_Admin_UI_Framework {
 
 
 
 
 
 
 
4
 
5
+ public function __construct() {
6
+ if ( $this->is_need_include_assets() ) {
7
+ add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ) );
8
+ }
9
+ }
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ public function register_assets() {
12
+ wp_enqueue_style(
13
+ 'ecwid-app-ui',
14
+ 'https://djqizrxa6f10j.cloudfront.net/ecwid-sdk/css/1.3.7/ecwid-app-ui.css',
15
+ array(),
16
+ get_option( 'ecwid_plugin_version' )
17
+ );
 
 
18
 
19
+ wp_enqueue_script(
20
+ 'ecwid-app-ui',
21
+ 'https://djqizrxa6f10j.cloudfront.net/ecwid-sdk/css/1.3.7/ecwid-app-ui.min.js',
22
+ array(),
23
+ get_option( 'ecwid_plugin_version' ),
24
+ 'in_footer'
25
+ );
26
+ }
27
 
28
+ public static function print_fix_js() {
29
+ ?>
30
+ <script type='text/javascript'>//<![CDATA[
31
+ jQuery(document.body).addClass('ecwid-no-padding');
32
+ jQuery(document.body).css({ 'font-size': '13px' });
33
+ jQuery('#wpbody').css({ 'background-color': 'rgb(240, 242, 244)' });
34
+ //]]></script>
35
+ <?php
36
+ }
37
 
38
+ public function is_need_include_assets() {
39
+ if ( ! isset( $_GET['page'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
40
+ return false;
41
+ }
42
 
43
+ $ignore_pages = $this->get_pages_exclude_framework();
44
+ $page = sanitize_text_field( wp_unslash( $_GET['page'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
 
 
 
 
45
 
46
+ if ( in_array( $page, $ignore_pages, true ) ) {
47
+ return false;
48
+ }
49
 
50
+ if ( strpos( $page, 'ec-developers' ) === 0 ) {
51
+ return true;
52
+ }
53
+ if ( strpos( $page, 'ec-store' ) === 0 ) {
54
+ return true;
55
+ }
56
 
57
+ return false;
58
+ }
 
59
 
60
+ public function get_pages_exclude_framework() {
61
+ $pages = array(
62
+ 'ec-store-advanced',
63
+ 'ec-store-help',
64
+ );
65
+
66
+ if ( ecwid_is_demo_store() || isset( $_GET['reconnect'] ) || Ecwid_Api_V3::get_token() === false ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
67
+ $pages[] = 'ec-store';
68
+ }
69
+
70
+ return $pages;
71
+ }
72
  }
73
 
74
  new Ecwid_Admin_UI_Framework();
 
includes/class-ecwid-ajax-defer-renderer.php CHANGED
@@ -1,38 +1,36 @@
1
- <?php
2
 
3
  class Ecwid_Ajax_Defer_Renderer {
4
-
5
- const ALWAYS_ON = 'on';
6
- const ALWAYS_OFF = 'off';
7
- const AUTO = 'auto';
8
  const OPTION_DEFER_RENDERING = 'ecwid_ajax_defer_rendering';
9
- const FILTER_ENABLED = 'ecwid_enable_defer_rendering';
10
-
11
  protected $_already_enabled = false;
12
-
13
  protected static $instance = null;
14
-
15
- public static function get_instance()
16
- {
17
- if (!self::$instance) {
18
  self::$instance = new Ecwid_Ajax_Defer_Renderer();
19
  }
20
 
21
  return self::$instance;
22
  }
23
-
24
- protected function __construct()
25
- {
26
  add_option( self::OPTION_DEFER_RENDERING, self::AUTO );
27
-
28
- add_action( 'template_redirect', array( $this, 'init' ) );// to make sure it is called after ecwid_apply_theme
 
29
  add_action( 'admin_init', array( $this, 'init' ) );
30
- add_action( 'ecwid_on_plugin_upgrade', array( $this, 'plugin_upgrade' ) );
31
  }
32
-
33
- public function init()
34
- {
35
- if ( self::is_enabled() && !$this->_already_enabled ) {
36
  add_filter( 'ecwid_disable_widgets', '__return_true' );
37
  add_filter( 'ecwid_shortcode_custom_renderer', array( $this, 'get_custom_renderer' ) );
38
  add_filter( 'the_content', array( $this, 'add_shortcodes' ) );
@@ -40,38 +38,36 @@ class Ecwid_Ajax_Defer_Renderer {
40
  }
41
  }
42
 
43
- public function plugin_upgrade()
44
- {
45
  $old_option = 'ecwid_defer_rendering';
46
-
47
- $value = get_option( $old_option , null );
48
-
49
- if ( !is_null( $value ) ) {
50
- if ( !$value ) {
51
  update_option( self::OPTION_DEFER_RENDERING, self::ALWAYS_OFF );
52
  }
53
-
54
  delete_option( $old_option );
55
  }
56
  }
57
-
58
-
59
- public static function is_enabled()
60
- {
61
  $option_value = get_option( self::OPTION_DEFER_RENDERING );
62
-
63
  if ( $option_value == self::AUTO ) {
64
 
65
  $filter_results = false;
66
-
67
- if( self::is_ajax_request() ) {
68
  $filter_results = true;
69
  }
70
 
71
  $filter_results = apply_filters( self::FILTER_ENABLED, $filter_results );
72
-
73
  return $filter_results;
74
- } else if ( $option_value == self::ALWAYS_ON ) {
75
  return true;
76
  } else {
77
  return false;
@@ -79,15 +75,15 @@ class Ecwid_Ajax_Defer_Renderer {
79
  }
80
 
81
  public static function is_ajax_request() {
82
- return !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower(sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REQUESTED_WITH']))) == 'xmlhttprequest';
83
  }
84
 
85
-
86
  public function get_custom_renderer() {
87
- return array($this, 'render_shortcode');
88
  }
89
 
90
- public function render_shortcode($shortcode) {
91
 
92
  if ( $shortcode instanceof Ecwid_Shortcode_Base ) {
93
  return $shortcode->render_placeholder() . $this->_render_shortcode_script( $shortcode );
@@ -96,80 +92,82 @@ class Ecwid_Ajax_Defer_Renderer {
96
  return '';
97
  }
98
 
99
- public function add_shortcodes($content) {
100
  $ecwid_store_id = get_ecwid_store_id();
101
- $before = <<<HTML
102
- <script>
103
- var ecwid_shortcodes = [];
104
- </script>
105
- HTML;
106
-
107
  $app_ecwid_com = Ecwid_Config::get_scriptjs_domain();
108
 
109
  $lang = ecwid_get_current_user_locale();
110
  $lang = apply_filters( 'ecwid_lang', $lang );
111
-
112
- $after = <<<HTML
113
- <script>
114
- window.ecwid_script_defer = true;
115
- window.ecwid_dynamic_widgets = true;
116
-
117
- if (typeof Ecwid != 'undefined' && Ecwid.destroy) Ecwid.destroy();
118
 
119
- if (typeof ecwid_shortcodes != 'undefined') {
120
- window._xnext_initialization_scripts = ecwid_shortcodes;
121
-
122
- if (!document.getElementById('ecwid-script')) {
123
- var script = document.createElement('script');
124
- script.charset = 'utf-8';
125
- script.type = 'text/javascript';
126
- script.src = 'https://$app_ecwid_com/script.js?$ecwid_store_id&lang=$lang';
127
- script.id = 'ecwid-script';
128
- script.setAttribute('data-cfasync', 'false');
129
-
130
- document.body.appendChild(script);
131
- var el = document.getElementById('ecwid-html-catalog-$ecwid_store_id');
132
- if (el) {
133
- el.style.display = 'none';
134
- }
135
- if ( typeof Ecwid != 'undefined' ) {
136
- Ecwid.OnPageLoad.add(function() {
137
- var catalog = document.getElementById('ecwid-html-catalog-$ecwid_store_id');
138
- catalog.parentElement.removeChild(catalog);
139
- });
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
141
- } else {
142
- ecwid_onBodyDone();
143
  }
144
- }
145
- </script>
146
- HTML;
 
147
  return $before . $content . $after;
148
  }
149
 
150
- protected function _render_shortcode_script($shortcode) {
151
 
152
- $args = $shortcode->build_params_string();
153
- $id = $shortcode->get_html_id();
154
- $widgetType = substr($shortcode->get_ecwid_widget_function_name(), 1);
155
- if ($widgetType == 'Search') {
156
- $widgetType = 'SearchWidget';
157
  }
158
- $store_id = get_ecwid_store_id();
159
-
160
- $code = <<<HTML
161
- <script type="text/javascript">
162
- if (typeof ecwid_shortcodes != 'undefined') {
163
- ecwid_shortcodes[ecwid_shortcodes.length] = {
164
- widgetType: '$widgetType',
165
- id: '$id',
166
- arg: [$args]
167
- };
168
- }
169
- </script>
170
- HTML;
 
 
171
  return $code;
172
  }
173
  }
174
 
175
- add_action('init', array('Ecwid_Ajax_Defer_Renderer', 'get_instance'), 0);
1
+ <?php
2
 
3
  class Ecwid_Ajax_Defer_Renderer {
4
+
5
+ const ALWAYS_ON = 'on';
6
+ const ALWAYS_OFF = 'off';
7
+ const AUTO = 'auto';
8
  const OPTION_DEFER_RENDERING = 'ecwid_ajax_defer_rendering';
9
+ const FILTER_ENABLED = 'ecwid_enable_defer_rendering';
10
+
11
  protected $_already_enabled = false;
12
+
13
  protected static $instance = null;
14
+
15
+ public static function get_instance() {
16
+ if ( ! self::$instance ) {
 
17
  self::$instance = new Ecwid_Ajax_Defer_Renderer();
18
  }
19
 
20
  return self::$instance;
21
  }
22
+
23
+ protected function __construct() {
 
24
  add_option( self::OPTION_DEFER_RENDERING, self::AUTO );
25
+
26
+ add_action( 'template_redirect', array( $this, 'init' ) );
27
+ // to make sure it is called after ecwid_apply_theme
28
  add_action( 'admin_init', array( $this, 'init' ) );
29
+ add_action( 'ecwid_on_plugin_upgrade', array( $this, 'plugin_upgrade' ) );
30
  }
31
+
32
+ public function init() {
33
+ if ( self::is_enabled() && ! $this->_already_enabled ) {
 
34
  add_filter( 'ecwid_disable_widgets', '__return_true' );
35
  add_filter( 'ecwid_shortcode_custom_renderer', array( $this, 'get_custom_renderer' ) );
36
  add_filter( 'the_content', array( $this, 'add_shortcodes' ) );
38
  }
39
  }
40
 
41
+ public function plugin_upgrade() {
 
42
  $old_option = 'ecwid_defer_rendering';
43
+
44
+ $value = get_option( $old_option, null );
45
+
46
+ if ( ! is_null( $value ) ) {
47
+ if ( ! $value ) {
48
  update_option( self::OPTION_DEFER_RENDERING, self::ALWAYS_OFF );
49
  }
50
+
51
  delete_option( $old_option );
52
  }
53
  }
54
+
55
+
56
+ public static function is_enabled() {
 
57
  $option_value = get_option( self::OPTION_DEFER_RENDERING );
58
+
59
  if ( $option_value == self::AUTO ) {
60
 
61
  $filter_results = false;
62
+
63
+ if ( self::is_ajax_request() ) {
64
  $filter_results = true;
65
  }
66
 
67
  $filter_results = apply_filters( self::FILTER_ENABLED, $filter_results );
68
+
69
  return $filter_results;
70
+ } elseif ( $option_value == self::ALWAYS_ON ) {
71
  return true;
72
  } else {
73
  return false;
75
  }
76
 
77
  public static function is_ajax_request() {
78
+ return ! empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ) ) == 'xmlhttprequest';
79
  }
80
 
81
+
82
  public function get_custom_renderer() {
83
+ return array( $this, 'render_shortcode' );
84
  }
85
 
86
+ public function render_shortcode( $shortcode ) {
87
 
88
  if ( $shortcode instanceof Ecwid_Shortcode_Base ) {
89
  return $shortcode->render_placeholder() . $this->_render_shortcode_script( $shortcode );
92
  return '';
93
  }
94
 
95
+ public function add_shortcodes( $content ) {
96
  $ecwid_store_id = get_ecwid_store_id();
97
+ $before = '<script>var ecwid_shortcodes = [];</script>';
98
+
 
 
 
 
99
  $app_ecwid_com = Ecwid_Config::get_scriptjs_domain();
100
 
101
  $lang = ecwid_get_current_user_locale();
102
  $lang = apply_filters( 'ecwid_lang', $lang );
 
 
 
 
 
 
 
103
 
104
+ $script_src = "https://$app_ecwid_com/script.js?$ecwid_store_id&lang=$lang";
105
+ ob_start();
106
+ ?>
107
+ <script>
108
+ window.ecwid_script_defer = true;
109
+ window.ecwid_dynamic_widgets = true;
110
+
111
+ if (typeof Ecwid != 'undefined' && Ecwid.destroy) Ecwid.destroy();
112
+
113
+ if (typeof ecwid_shortcodes != 'undefined') {
114
+ window._xnext_initialization_scripts = ecwid_shortcodes;
115
+
116
+ if (!document.getElementById('ecwid-script')) {
117
+ var script = document.createElement('script');
118
+ script.charset = 'utf-8';
119
+ script.type = 'text/javascript';
120
+ script.src = '<?php echo esc_attr( $script_src ); ?>';
121
+ script.id = 'ecwid-script';
122
+ script.setAttribute('data-cfasync', 'false');
123
+
124
+ document.body.appendChild(script);
125
+ var el = document.getElementById('ecwid-html-catalog-<?php echo esc_js( $ecwid_store_id ); ?>');
126
+ if (el) {
127
+ el.style.display = 'none';
128
+ }
129
+ if ( typeof Ecwid != 'undefined' ) {
130
+ Ecwid.OnPageLoad.add(function() {
131
+ var catalog = document.getElementById('ecwid-html-catalog-<?php echo esc_js( $ecwid_store_id ); ?>');
132
+ catalog.parentElement.removeChild(catalog);
133
+ });
134
+ }
135
+ } else {
136
+ ecwid_onBodyDone();
137
  }
 
 
138
  }
139
+ </script>
140
+ <?php
141
+ $after = ob_get_clean();
142
+
143
  return $before . $content . $after;
144
  }
145
 
146
+ protected function _render_shortcode_script( $shortcode ) {
147
 
148
+ $args = $shortcode->build_params_string();
149
+ $id = $shortcode->get_html_id();
150
+ $widget_type = substr( $shortcode->get_ecwid_widget_function_name(), 1 );
151
+ if ( $widget_type == 'Search' ) {
152
+ $widget_type = 'SearchWidget';
153
  }
154
+
155
+ ob_start();
156
+ ?>
157
+ <script type="text/javascript">
158
+ if (typeof ecwid_shortcodes != 'undefined') {
159
+ ecwid_shortcodes[ecwid_shortcodes.length] = {
160
+ widgetType: '<?php echo esc_js( $widget_type ); ?>',
161
+ id: '<?php echo esc_js( $id ); ?>',
162
+ arg: [<?php echo wp_kses_post( $args ); ?>]
163
+ };
164
+ }
165
+ </script>
166
+ <?php
167
+ $code = ob_get_clean();
168
+
169
  return $code;
170
  }
171
  }
172
 
173
+ add_action( 'init', array( 'Ecwid_Ajax_Defer_Renderer', 'get_instance' ), 0 );
includes/class-ecwid-custom-admin-page.php CHANGED
@@ -11,24 +11,18 @@ class Ecwid_Custom_Admin_Page {
11
 
12
  public function init( $current_screen ) {
13
 
14
- if ( $current_screen->id == 'plugin-install' ) {
15
  add_filter( 'install_plugins_tabs', array( $this, 'plugin_install_init_tab' ), 10, 1 );
16
  add_action( 'install_plugins_' . self::TAB_NAME, array( $this, 'plugin_install_render_tab' ), 10, 1 );
17
  }
18
 
19
- if ( $current_screen->id == 'theme-install' ) {
20
  add_action( 'install_themes_tabs', array( $this, 'themes_install_init_tab' ) );
21
  add_action( 'wp_ajax_query-themes', array( $this, 'themes_install_ajax' ), 1 );
22
  }
23
 
24
  }
25
 
26
- public function get_iframe_html( $iframe_src ) {
27
- $html = '<iframe seamless id="ecwid-frame" frameborder="0" width="100%" height="700" scrolling="no" src="' . $iframe_src . '"></iframe>';
28
-
29
- return $html;
30
- }
31
-
32
  public function plugin_install_init_tab( $tabs ) {
33
  $tabs[ self::TAB_NAME ] = __( 'Plugins for Ecwid', 'ecwid-shopping-cart' );
34
  return $tabs;
@@ -38,71 +32,68 @@ class Ecwid_Custom_Admin_Page {
38
  $iframe_src = ecwid_get_iframe_src( time(), 'appmarket' );
39
  $iframe_src .= '&hide_profile_header=true';
40
 
41
- echo "<script type='text/javascript'>
42
- jQuery(document).ready(function() {
43
- jQuery('.search-form.search-plugins').hide();
44
- });
45
- </script>
46
- <p></p>";
47
-
48
- $iframe_html = $this->get_iframe_html( $iframe_src );
49
- echo wp_kses( $iframe_html, ecwid_kses_get_allowed_html() );
50
  }
51
 
52
  public function themes_install_init_tab( $tabs ) {
53
 
54
- $tab_content = '<div id="ec-theme-tab">';
55
- $tab_content .= sprintf(
56
  __(
57
  'Ecwid is compatible with any WordPress theme. Be it a free theme from WordPress.org catalog, a premium theme by a third-party vendor or a custom-made theme, your Ecwid store will work good with it. If you want a premium theme, we recommend <a href="%s">TemplateMonster themes</a>',
58
  'ecwid-shopping-cart'
59
  ),
60
  'https://www.templatemonster.com/ecwid-ready-wordpress-themes/?aff=Ecwid'
61
  );
62
- $tab_content .= '</div>';
63
-
64
- $link_html = sprintf( '<li><a href="#" data-sort="%s">%s</a></li>', self::TAB_NAME, __( 'Themes for Ecwid', 'ecwid-shopping-cart' ) );
65
 
66
- $init_script = '';
67
- if ( isset( $_GET['browse'] ) && $_GET['browse'] === self::TAB_NAME ) {
68
- $init_script = sprintf( 'ecwid_switch_theme_tab("%s");', self::TAB_NAME );
69
- }
70
-
71
- $content = "<script type='text/javascript'>
72
- function ecwid_switch_theme_tab( sort ){
73
- if( sort == '%s' ) {
74
- if( jQuery('#ec-theme-tab').length == 0 ) {
75
- jQuery('.theme-browser').before('%s');
76
- }
77
-
78
- jQuery('#ec-theme-tab').show();
79
- jQuery('.filter-count, .button.drawer-toggle, .search-form, .theme-browser, .no-themes').hide();
80
- } else {
81
- jQuery('#ec-theme-tab').hide();
82
- jQuery('.theme-browser').removeAttr('style');
83
- jQuery('.filter-count, .button.drawer-toggle, .search-form').show();
84
  }
85
- }
86
 
87
- jQuery(document).ready(function(){
88
- jQuery('.filter-links').append('%s');
 
 
 
 
 
 
89
 
90
- jQuery(document).on('click', '.filter-links li a', function(){
91
- ecwid_switch_theme_tab( jQuery(this).data('sort') );
92
- });
93
 
94
- %s
 
95
  });
96
- </script>";
97
 
98
- $content = sprintf( $content, self::TAB_NAME, $tab_content, $link_html, $init_script );
99
- echo wp_kses( $content, ecwid_kses_get_allowed_html() );
 
 
 
 
 
 
 
 
100
 
101
  return $tabs;
102
  }
103
 
104
  public function themes_install_ajax() {
105
- if ( isset( $_REQUEST['request']['browse'] ) && $_REQUEST['request']['browse'] == self::TAB_NAME ) {
106
  $themes_data = array(
107
  'data' => array(
108
  'info' => array(
11
 
12
  public function init( $current_screen ) {
13
 
14
+ if ( $current_screen->id === 'plugin-install' ) {
15
  add_filter( 'install_plugins_tabs', array( $this, 'plugin_install_init_tab' ), 10, 1 );
16
  add_action( 'install_plugins_' . self::TAB_NAME, array( $this, 'plugin_install_render_tab' ), 10, 1 );
17
  }
18
 
19
+ if ( $current_screen->id === 'theme-install' ) {
20
  add_action( 'install_themes_tabs', array( $this, 'themes_install_init_tab' ) );
21
  add_action( 'wp_ajax_query-themes', array( $this, 'themes_install_ajax' ), 1 );
22
  }
23
 
24
  }
25
 
 
 
 
 
 
 
26
  public function plugin_install_init_tab( $tabs ) {
27
  $tabs[ self::TAB_NAME ] = __( 'Plugins for Ecwid', 'ecwid-shopping-cart' );
28
  return $tabs;
32
  $iframe_src = ecwid_get_iframe_src( time(), 'appmarket' );
33
  $iframe_src .= '&hide_profile_header=true';
34
 
35
+ ?>
36
+ <script type='text/javascript'>
37
+ jQuery(document).ready(function() {
38
+ jQuery('.search-form.search-plugins').hide();
39
+ });
40
+ </script>
41
+ <p></p>
42
+ <iframe seamless id="ecwid-frame" frameborder="0" width="100%" height="700" scrolling="no" src="<?php echo esc_url( $iframe_src ); ?>"></iframe>
43
+ <?php
44
  }
45
 
46
  public function themes_install_init_tab( $tabs ) {
47
 
48
+ $tab_content = sprintf(
49
+ /* translators: %s: affiliate link */
50
  __(
51
  'Ecwid is compatible with any WordPress theme. Be it a free theme from WordPress.org catalog, a premium theme by a third-party vendor or a custom-made theme, your Ecwid store will work good with it. If you want a premium theme, we recommend <a href="%s">TemplateMonster themes</a>',
52
  'ecwid-shopping-cart'
53
  ),
54
  'https://www.templatemonster.com/ecwid-ready-wordpress-themes/?aff=Ecwid'
55
  );
56
+ ?>
 
 
57
 
58
+ <script type='text/javascript'>
59
+ function ecwid_switch_theme_tab( sort ){
60
+ if( sort == '<?php echo esc_js( self::TAB_NAME ); ?>' ) {
61
+ if( jQuery('#ec-theme-tab').length == 0 ) {
62
+ jQuery('.theme-browser').before('<div id="ec-theme-tab"><?php echo wp_kses_post( $tab_content ); ?></div>');
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
 
64
 
65
+ jQuery('#ec-theme-tab').show();
66
+ jQuery('.filter-count, .button.drawer-toggle, .search-form, .theme-browser, .no-themes').hide();
67
+ } else {
68
+ jQuery('#ec-theme-tab').hide();
69
+ jQuery('.theme-browser').removeAttr('style');
70
+ jQuery('.filter-count, .button.drawer-toggle, .search-form').show();
71
+ }
72
+ }
73
 
74
+ jQuery(document).ready(function(){
75
+ jQuery('.filter-links').append('<li><a href="#" data-sort="<?php echo esc_js( self::TAB_NAME ); ?>"><?php echo esc_html__( 'Themes for Ecwid', 'ecwid-shopping-cart' ); ?></a></li>');
 
76
 
77
+ jQuery(document).on('click', '.filter-links li a', function(){
78
+ ecwid_switch_theme_tab( jQuery(this).data('sort') );
79
  });
 
80
 
81
+ <?php
82
+ if ( isset( $_GET['browse'] ) && $_GET['browse'] === self::TAB_NAME ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
83
+ ?>
84
+ ecwid_switch_theme_tab('<?php echo esc_js( self::TAB_NAME ); ?>');
85
+ <?php
86
+ }
87
+ ?>
88
+ });
89
+ </script>
90
+ <?php
91
 
92
  return $tabs;
93
  }
94
 
95
  public function themes_install_ajax() {
96
+ if ( isset( $_REQUEST['request']['browse'] ) && $_REQUEST['request']['browse'] === self::TAB_NAME ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
97
  $themes_data = array(
98
  'data' => array(
99
  'info' => array(
includes/class-ecwid-floating-minicart.php CHANGED
@@ -1,166 +1,158 @@
1
  <?php
2
 
3
 
4
- if ( version_compare( get_bloginfo('version'), '4.0' ) >= 0 ) {
5
-
6
- class Ecwid_Floating_Minicart
7
- {
8
- const OPTION_WIDGET_DISPLAY = 'ec_show_floating_cart_widget';
9
- const OPTION_FIXED_POSITION = 'ec_store_cart_widget_fixed_position';
10
- const OPTION_ICON = 'ec_store_cart_widget_icon';
11
- const OPTION_FIXED_SHAPE = 'ec_store_cart_widget_fixed_shape';
12
- const OPTION_LAYOUT = 'ec_store_cart_widget_layout';
13
- const OPTION_SHOW_EMPTY_CART = 'ec_store_cart_widget_show_empty_cart';
14
  const OPTION_HORIZONTAL_INDENT = 'ec_store_cart_widget_horizontal_indent';
15
- const OPTION_VERTICAL_INDENT = 'ec_store_cart_widget_vertical_indent';
16
 
17
- const DISPLAY_NONE = 'do_not_show';
18
  const DISPLAY_STORE = 'show_on_store_pages';
19
- const DISPLAY_ALL = 'show_on_all_pages';
20
 
21
  const CUSTOMIZE_ID = 'ec-customize-cart';
22
 
23
- public function __construct()
24
- {
25
- add_action('wp_footer', array($this, 'display'));
26
  }
27
 
28
- public function display()
29
- {
30
- if ( post_password_required() ) return;
31
-
32
- $display = get_option(self::OPTION_WIDGET_DISPLAY, self::DISPLAY_STORE);
 
33
 
34
- if (!array_key_exists($display, self::get_display_options())) {
35
  $display = self::DISPLAY_NONE;
36
  }
37
 
38
- if ($display == self::DISPLAY_NONE && !is_customize_preview()) {
39
  return;
40
  }
41
 
42
- if ($display == self::DISPLAY_STORE && !Ecwid_Store_Page::is_store_page() && !is_customize_preview()) {
43
  return;
44
  }
45
 
46
- if( isset($_REQUEST['legacy-widget-preview']) ) {
47
  return;
48
  }
49
 
50
  echo ecwid_get_scriptjs_code();
51
 
52
- $position = esc_attr(get_option(self::OPTION_FIXED_POSITION));
53
- $shape = esc_attr(get_option(self::OPTION_FIXED_SHAPE));
54
- $layout = esc_attr(get_option(self::OPTION_LAYOUT));
55
- $show_empty = esc_attr(get_option(self::OPTION_SHOW_EMPTY_CART) ? 'TRUE' : 'FALSE');
56
- $icon = esc_attr(get_option(self::OPTION_ICON));
57
 
58
- $hindent = esc_attr(get_option(self::OPTION_HORIZONTAL_INDENT));
59
- $vindent = esc_attr(get_option(self::OPTION_VERTICAL_INDENT));
60
 
61
- $customize_id = is_customize_preview() ? 'id="' . self::CUSTOMIZE_ID . '"' : '';
62
  $customize_hide = is_customize_preview() && $display == self::DISPLAY_NONE ? 'style="display:none"' : '';
63
 
64
- echo <<<HTML
65
- <div $customize_id $customize_hide class='ec-cart-widget'
66
- data-fixed='true'
67
- data-fixed-position='$position'
68
- data-fixed-shape='$shape'
69
- data-horizontal-indent="$hindent"
70
- data-vertical-indent="$vindent"
71
- data-layout='$layout'
72
- data-show-empty-cart='$show_empty'
73
- data-show-buy-animation='true'
74
- data-icon='$icon'
75
- ></div>
76
-
77
- <script>
78
- if (typeof Ecwid != 'undefined'){
79
- Ecwid.init();
80
- }
81
- </script>
82
- HTML;
83
  }
84
 
85
- public static function create_default_options()
86
- {
87
-
88
  $options = self::_get_default_options();
89
- if (!ecwid_is_recent_installation()) {
90
- $options[self::OPTION_WIDGET_DISPLAY] = self::DISPLAY_NONE;
91
  }
92
 
93
- foreach ($options as $name => $value) {
94
- add_option($name, $value);
95
  }
96
  }
97
 
98
- protected static function _get_default_options()
99
- {
100
  return array(
101
- self::OPTION_WIDGET_DISPLAY => self::DISPLAY_STORE,
102
- self::OPTION_SHOW_EMPTY_CART => true,
103
- self::OPTION_LAYOUT => 'MEDIUM_ICON_COUNTER',
104
- self::OPTION_FIXED_SHAPE => 'PILL',
105
- self::OPTION_FIXED_POSITION => 'BOTTOM_RIGHT',
106
- self::OPTION_ICON => 'BAG',
107
  self::OPTION_HORIZONTAL_INDENT => '30',
108
- self::OPTION_VERTICAL_INDENT => '30',
109
  );
110
  }
111
 
112
- public static function get_display_options()
113
- {
114
  return array(
115
- self::DISPLAY_NONE => __('Do not show', 'ecwid-shopping-cart'),
116
- self::DISPLAY_STORE => __('Show on store pages', 'ecwid-shopping-cart'),
117
- self::DISPLAY_ALL => __('Show on all pages', 'ecwid-shopping-cart')
118
  );
119
  }
120
 
121
- public static function get_layouts()
122
- {
123
  return array(
124
- 'SMALL_ICON' => __('Small icon', 'ecwid-shopping-cart'),
125
- 'SMALL_ICON_COUNTER' => __('Small icon and item count', 'ecwid-shopping-cart'),
126
- 'COUNTER_ONLY' => __('Item count only', 'ecwid-shopping-cart'),
127
- 'TITLE_COUNTER' => __('Label and item count', 'ecwid-shopping-cart'),
128
- 'MEDIUM_ICON_COUNTER' => __('Icon and item count', 'ecwid-shopping-cart'),
129
- 'MEDIUM_ICON_TITLE_COUNTER' => __('Icon, label and item count', 'ecwid-shopping-cart'),
130
- 'BIG_ICON_TITLE_SUBTOTAL' => __('Icon, label, item count and subtotal', 'ecwid-shopping-cart'),
131
- 'BIG_ICON_DETAILS_SUBTOTAL' => __('Icon, label, item count, subtotal and link', 'ecwid-shopping-cart')
132
  );
133
  }
134
 
135
- public static function get_icons()
136
- {
137
  return array(
138
- 'BAG' => __('Bag', 'ecwid-shopping-cart'),
139
- 'CART' => __('Cart', 'ecwid-shopping-cart'),
140
- 'BASKET' => __('Basket', 'ecwid-shopping-cart')
141
  );
142
  }
143
 
144
- public static function get_fixed_shapes()
145
- {
146
- return array(
147
- 'RECT' => __('Rectangle', 'ecwid-shopping-cart'),
148
- 'PILL' => __('Pill', 'ecwid-shopping-cart'),
149
- '' => __('No border', 'ecwid-shopping-cart')
150
- );
151
  }
152
 
153
- public static function get_fixed_positions()
154
- {
155
  return array(
156
- 'BOTTOM_RIGHT' => __('Bottom right', 'ecwid-shopping-cart'),
157
- 'TOP_RIGHT' => __('Top right', 'ecwid-shopping-cart'),
158
- 'TOP_LEFT' => __('Top left', 'ecwid-shopping-cart'),
159
- 'BOTTOM_LEFT' => __('Bottom left', 'ecwid-shopping-cart')
160
  );
161
  }
162
  }
163
 
164
  $minicart = new Ecwid_Floating_Minicart();
165
 
166
- }
1
  <?php
2
 
3
 
4
+ if ( version_compare( get_bloginfo( 'version' ), '4.0' ) >= 0 ) {
5
+
6
+ class Ecwid_Floating_Minicart {
7
+
8
+ const OPTION_WIDGET_DISPLAY = 'ec_show_floating_cart_widget';
9
+ const OPTION_FIXED_POSITION = 'ec_store_cart_widget_fixed_position';
10
+ const OPTION_ICON = 'ec_store_cart_widget_icon';
11
+ const OPTION_FIXED_SHAPE = 'ec_store_cart_widget_fixed_shape';
12
+ const OPTION_LAYOUT = 'ec_store_cart_widget_layout';
13
+ const OPTION_SHOW_EMPTY_CART = 'ec_store_cart_widget_show_empty_cart';
14
  const OPTION_HORIZONTAL_INDENT = 'ec_store_cart_widget_horizontal_indent';
15
+ const OPTION_VERTICAL_INDENT = 'ec_store_cart_widget_vertical_indent';
16
 
17
+ const DISPLAY_NONE = 'do_not_show';
18
  const DISPLAY_STORE = 'show_on_store_pages';
19
+ const DISPLAY_ALL = 'show_on_all_pages';
20
 
21
  const CUSTOMIZE_ID = 'ec-customize-cart';
22
 
23
+ public function __construct() {
24
+ add_action( 'wp_footer', array( $this, 'display' ) );
 
25
  }
26
 
27
+ public function display() {
28
+ if ( post_password_required() ) {
29
+ return;
30
+ }
31
+
32
+ $display = get_option( self::OPTION_WIDGET_DISPLAY, self::DISPLAY_STORE );
33
 
34
+ if ( ! array_key_exists( $display, self::get_display_options() ) ) {
35
  $display = self::DISPLAY_NONE;
36
  }
37
 
38
+ if ( $display == self::DISPLAY_NONE && ! is_customize_preview() ) {
39
  return;
40
  }
41
 
42
+ if ( $display == self::DISPLAY_STORE && ! Ecwid_Store_Page::is_store_page() && ! is_customize_preview() ) {
43
  return;
44
  }
45
 
46
+ if ( isset( $_REQUEST['legacy-widget-preview'] ) ) {
47
  return;
48
  }
49
 
50
  echo ecwid_get_scriptjs_code();
51
 
52
+ $position = esc_attr( get_option( self::OPTION_FIXED_POSITION ) );
53
+ $shape = esc_attr( get_option( self::OPTION_FIXED_SHAPE ) );
54
+ $layout = esc_attr( get_option( self::OPTION_LAYOUT ) );
55
+ $show_empty = esc_attr( get_option( self::OPTION_SHOW_EMPTY_CART ) ? 'TRUE' : 'FALSE' );
56
+ $icon = esc_attr( get_option( self::OPTION_ICON ) );
57
 
58
+ $hindent = esc_attr( get_option( self::OPTION_HORIZONTAL_INDENT ) );
59
+ $vindent = esc_attr( get_option( self::OPTION_VERTICAL_INDENT ) );
60
 
61
+ $customize_id = is_customize_preview() ? 'id="' . self::CUSTOMIZE_ID . '"' : '';
62
  $customize_hide = is_customize_preview() && $display == self::DISPLAY_NONE ? 'style="display:none"' : '';
63
 
64
+ ?>
65
+ <div <?php echo esc_attr( $customize_id ); ?> <?php echo esc_attr( $customize_hide ); ?> class='ec-cart-widget'
66
+ data-fixed='true'
67
+ data-fixed-position='<?php echo esc_attr( $position ); ?>'
68
+ data-fixed-shape='<?php echo esc_attr( $shape ); ?>'
69
+ data-horizontal-indent="<?php echo esc_attr( $hindent ); ?>"
70
+ data-vertical-indent="<?php echo esc_attr( $vindent ); ?>"
71
+ data-layout='<?php echo esc_attr( $layout ); ?>'
72
+ data-show-empty-cart='<?php echo esc_attr( $show_empty ); ?>'
73
+ data-show-buy-animation='true'
74
+ data-icon='<?php echo esc_attr( $icon ); ?>'
75
+ ></div>
76
+
77
+ <script>
78
+ if (typeof Ecwid != 'undefined'){
79
+ Ecwid.init();
80
+ }
81
+ </script>
82
+ <?php
83
  }
84
 
85
+ public static function create_default_options() {
 
 
86
  $options = self::_get_default_options();
87
+ if ( ! ecwid_is_recent_installation() ) {
88
+ $options[ self::OPTION_WIDGET_DISPLAY ] = self::DISPLAY_NONE;
89
  }
90
 
91
+ foreach ( $options as $name => $value ) {
92
+ add_option( $name, $value );
93
  }
94
  }
95
 
96
+ protected static function _get_default_options() {
 
97
  return array(
98
+ self::OPTION_WIDGET_DISPLAY => self::DISPLAY_STORE,
99
+ self::OPTION_SHOW_EMPTY_CART => true,
100
+ self::OPTION_LAYOUT => 'MEDIUM_ICON_COUNTER',
101
+ self::OPTION_FIXED_SHAPE => 'PILL',
102
+ self::OPTION_FIXED_POSITION => 'BOTTOM_RIGHT',
103
+ self::OPTION_ICON => 'BAG',
104
  self::OPTION_HORIZONTAL_INDENT => '30',
105
+ self::OPTION_VERTICAL_INDENT => '30',
106
  );
107
  }
108
 
109
+ public static function get_display_options() {
 
110
  return array(
111
+ self::DISPLAY_NONE => __( 'Do not show', 'ecwid-shopping-cart' ),
112
+ self::DISPLAY_STORE => __( 'Show on store pages', 'ecwid-shopping-cart' ),
113
+ self::DISPLAY_ALL => __( 'Show on all pages', 'ecwid-shopping-cart' ),
114
  );
115
  }
116
 
117
+ public static function get_layouts() {
 
118
  return array(
119
+ 'SMALL_ICON' => __( 'Small icon', 'ecwid-shopping-cart' ),
120
+ 'SMALL_ICON_COUNTER' => __( 'Small icon and item count', 'ecwid-shopping-cart' ),
121
+ 'COUNTER_ONLY' => __( 'Item count only', 'ecwid-shopping-cart' ),
122
+ 'TITLE_COUNTER' => __( 'Label and item count', 'ecwid-shopping-cart' ),
123
+ 'MEDIUM_ICON_COUNTER' => __( 'Icon and item count', 'ecwid-shopping-cart' ),
124
+ 'MEDIUM_ICON_TITLE_COUNTER' => __( 'Icon, label and item count', 'ecwid-shopping-cart' ),
125
+ 'BIG_ICON_TITLE_SUBTOTAL' => __( 'Icon, label, item count and subtotal', 'ecwid-shopping-cart' ),
126
+ 'BIG_ICON_DETAILS_SUBTOTAL' => __( 'Icon, label, item count, subtotal and link', 'ecwid-shopping-cart' ),
127
  );
128
  }
129
 
130
+ public static function get_icons() {
 
131
  return array(
132
+ 'BAG' => __( 'Bag', 'ecwid-shopping-cart' ),
133
+ 'CART' => __( 'Cart', 'ecwid-shopping-cart' ),
134
+ 'BASKET' => __( 'Basket', 'ecwid-shopping-cart' ),
135
  );
136
  }
137
 
138
+ public static function get_fixed_shapes() {
139
+ return array(
140
+ 'RECT' => __( 'Rectangle', 'ecwid-shopping-cart' ),
141
+ 'PILL' => __( 'Pill', 'ecwid-shopping-cart' ),
142
+ '' => __( 'No border', 'ecwid-shopping-cart' ),
143
+ );
 
144
  }
145
 
146
+ public static function get_fixed_positions() {
 
147
  return array(
148
+ 'BOTTOM_RIGHT' => __( 'Bottom right', 'ecwid-shopping-cart' ),
149
+ 'TOP_RIGHT' => __( 'Top right', 'ecwid-shopping-cart' ),
150
+ 'TOP_LEFT' => __( 'Top left', 'ecwid-shopping-cart' ),
151
+ 'BOTTOM_LEFT' => __( 'Bottom left', 'ecwid-shopping-cart' ),
152
  );
153
  }
154
  }
155
 
156
  $minicart = new Ecwid_Floating_Minicart();
157
 
158
+ }//end if
includes/class-ecwid-message-manager.php CHANGED
@@ -29,21 +29,11 @@ class Ecwid_Message_Manager
29
  {
30
  if (!$wp_remote_post_error) {
31
  $message = sprintf(
32
- __( <<<TXT
33
- Sorry, there is a problem. This page is supposed to display your store control panel. But this WordPress site doesn't seem to be able to connect to the %s server, that's why there is no dashboard. This is caused by your server misconfiguration and can be fixed by your hosting provider.
34
- <br /><br />
35
- Here is a more techy description of the problem, please send it to your hosting provider: "The WordPress function wp_remote_post() failed to connect a remote server because of some error. Seems like HTTP requests to remote servers are disabled on this server. Specifically, the requests to %s and %s are blocked.".
36
- <br /><br />
37
- Please also feel free to contact us at <a %s">%s</a> and we will help you handle it with your hosting.
38
- <br /><br />
39
- Meanwhile, to manage your store, you can use the %s Control Panel at <a %s>%s</a>. Your store front is working fine as well and you can check it here: <a %s>%s</a>.
40
- TXT
41
-
42
- ),
43
  Ecwid_Config::get_brand(),
44
  Ecwid_Config::get_api_domain(),
45
  Ecwid_Config::get_cpanel_domain(),
46
- 'href="https://'. Ecwid_Config::get_contact_us_url() .'" target="_blank"',
47
  Ecwid_Config::get_contact_us_url(),
48
  Ecwid_Config::get_brand(),
49
  'href="https://'. Ecwid_Config::get_cpanel_domain() .'" target="_blank"',
@@ -253,7 +243,6 @@ TXT
253
  ),
254
 
255
  'on_no_storeid_on_setup_pages' => array(
256
- 'type' => 'warning',
257
  'title' => __('Your store is almost ready!', 'ecwid-shopping-cart' ),
258
  'message' => __('Complete setup and start selling', 'ecwid-shopping-cart' ),
259
  'primary_title' => __('Complete Setup', 'ecwid-shopping-cart' ),
@@ -304,18 +293,14 @@ TXT
304
  'ecwid-shopping-cart'
305
  ),
306
  'message' => sprintf(
307
- __(
308
- <<<HTML
309
- <b>What happened:</b> This WordPress site doesn't seem to be able to connect to the %1\$s servers. Your store is working and your products can be purchased from your site, but some features are disabled, including SEO, product sidebar widgets, advanced site menu and store navigation. The %1\$s plugin tries to reach the %1\$s APIs at our servers and cannot do that because of your server misconfiguration.
310
- <br /><br />
311
- <b>How to fix:</b> Your server seems to be using outdated software (TLS v1.0) to communicate with the %1\$s APIs. The reason can also be a deprecated version of the CURL module. This can be fixed by your hosting provider by updating your server software to the latest version. Please send this message to your hosting provider and ask them to check it for you. If this doesn't help, please contact us at <a target="_blank" href="%2\$s">%2\$s</a>.
312
- HTML
313
- , 'ecwid-shopping-cart'
314
- ),
315
  Ecwid_Config::get_brand(),
316
  Ecwid_Config::get_contact_us_url()
317
  ),
318
- 'type' => 'warning',
319
  'hideable' => false
320
  ),
321
 
@@ -325,17 +310,14 @@ HTML
325
  'ecwid-shopping-cart'
326
  ),
327
  'message' => sprintf(
328
- __(
329
- <<<HTML
330
- <b>What happened:</b> This WordPress site doesn't seem to be able to connect to the %1\$s servers. Your store is working and your products can be purchased from your site, but some features are disabled, including SEO, product sidebar widgets, advanced site menu and store navigation. The %1\$s plugin tries to reach the %1\$s APIs at our servers and cannot do that as your server blocks those requests for some reason.
331
- <br /><br />
332
- <b>How to fix:</b> Refresh this page after a few minutes. If this message does not disappear, then the problem is likely caused by your server misconfiguration and can be fixed by your hosting provider. In particular, the CURL module can be disabled in your PHP config or a firewall might block requests to our servers. Please send this message to your hosting provider and ask them to check it for you. If this doesn't help, please contact us at <a target="_blank" href="%2\$s">%2\$s</a>.
333
- HTML
334
- , 'ecwid-shopping-cart' ),
335
  Ecwid_Config::get_brand(),
336
  Ecwid_Config::get_contact_us_url()
337
  ),
338
- 'type' => 'warning',
339
  'hideable' => false
340
  )
341
  );
@@ -446,18 +428,20 @@ HTML
446
  return $result;
447
 
448
  case 'api_failed_tls':
 
449
  return
450
  !ecwid_is_demo_store()
451
  && get_current_screen()->parent_base == Ecwid_Admin::ADMIN_SLUG
452
  && Ecwid_Api_V3::get_api_status() == Ecwid_Api_V3::API_STATUS_ERROR_TLS
453
- && time() - get_option( 'ecwid_connected_via_legacy_page_time' ) > 15 * MINUTE_IN_SECONDS;
454
 
455
  case 'api_failed_other':
 
456
  return
457
  !ecwid_is_demo_store()
458
  && get_current_screen()->parent_base == Ecwid_Admin::ADMIN_SLUG
459
  && Ecwid_Api_V3::get_api_status() == Ecwid_Api_V3::API_STATUS_ERROR_OTHER
460
- && time() - get_option( 'ecwid_connected_via_legacy_page_time' ) > 15 * MINUTE_IN_SECONDS;
461
 
462
  case 'no_oauth':
463
  global $ecwid_oauth;
29
  {
30
  if (!$wp_remote_post_error) {
31
  $message = sprintf(
32
+ __('Sorry, there is a problem. This page is supposed to display your store control panel. But this WordPress site doesn\'t seem to be able to connect to the %s server, that\'s why there is no dashboard. This is caused by your server misconfiguration and can be fixed by your hosting provider. <br /><br />Here is a more techy description of the problem, please send it to your hosting provider: "The WordPress function wp_remote_post() failed to connect a remote server because of some error. Seems like HTTP requests to remote servers are disabled on this server. Specifically, the requests to %s and %s are blocked.". <br /><br />Please also feel free to contact us at <a %s">%s</a> and we will help you handle it with your hosting. <br /><br />Meanwhile, to manage your store, you can use the %s Control Panel at <a %s>%s</a>. Your store front is working fine as well and you can check it here: <a %s>%s</a>.'),
 
 
 
 
 
 
 
 
 
 
33
  Ecwid_Config::get_brand(),
34
  Ecwid_Config::get_api_domain(),
35
  Ecwid_Config::get_cpanel_domain(),
36
+ 'href="'. Ecwid_Config::get_contact_us_url() .'" target="_blank"',
37
  Ecwid_Config::get_contact_us_url(),
38
  Ecwid_Config::get_brand(),
39
  'href="https://'. Ecwid_Config::get_cpanel_domain() .'" target="_blank"',
243
  ),
244
 
245
  'on_no_storeid_on_setup_pages' => array(
 
246
  'title' => __('Your store is almost ready!', 'ecwid-shopping-cart' ),
247
  'message' => __('Complete setup and start selling', 'ecwid-shopping-cart' ),
248
  'primary_title' => __('Complete Setup', 'ecwid-shopping-cart' ),
293
  'ecwid-shopping-cart'
294
  ),
295
  'message' => sprintf(
296
+ __(
297
+ "<b>What happened:</b> This WordPress site doesn't seem to be able to connect to the %1\$s servers. Your store is working and your products can be purchased from your site, but some features are disabled, including SEO, product sidebar widgets, advanced site menu and store navigation. The %1\$s plugin tries to reach the %1\$s APIs at our servers and cannot do that because of your server misconfiguration. <br /><br /><b>How to fix:</b> Your server seems to be using outdated software (TLS v1.0) to communicate with the %1\$s APIs. The reason can also be a deprecated version of the CURL module. This can be fixed by your hosting provider by updating your server software to the latest version. Please send this message to your hosting provider and ask them to check it for you. If this doesn't help, please contact us at <a target=\"_blank\" href=\"%2\$s\">%2\$s</a>.",
298
+ 'ecwid-shopping-cart'
299
+ ),
 
 
 
 
300
  Ecwid_Config::get_brand(),
301
  Ecwid_Config::get_contact_us_url()
302
  ),
303
+ 'type' => 'error',
304
  'hideable' => false
305
  ),
306
 
310
  'ecwid-shopping-cart'
311
  ),
312
  'message' => sprintf(
313
+ __(
314
+ "<b>What happened:</b> This WordPress site doesn't seem to be able to connect to the %1\$s servers. Your store is working and your products can be purchased from your site, but some features are disabled, including SEO, product sidebar widgets, advanced site menu and store navigation. The %1\$s plugin tries to reach the %1\$s APIs at our servers and cannot do that as your server blocks those requests for some reason. <br /><br /><b>How to fix:</b> Refresh this page after a few minutes. If this message does not disappear, then the problem is likely caused by your server misconfiguration and can be fixed by your hosting provider. In particular, the CURL module can be disabled in your PHP config or a firewall might block requests to our servers. Please send this message to your hosting provider and ask them to check it for you. If this doesn't help, please contact us at <a target=\"_blank\" href=\"%2\$s\">%2\$s</a>.",
315
+ 'ecwid-shopping-cart'
316
+ ),
 
 
 
317
  Ecwid_Config::get_brand(),
318
  Ecwid_Config::get_contact_us_url()
319
  ),
320
+ 'type' => 'error',
321
  'hideable' => false
322
  )
323
  );
428
  return $result;
429
 
430
  case 'api_failed_tls':
431
+ $legacy_page_time = get_option( 'ecwid_connected_via_legacy_page_time', 0 );
432
  return
433
  !ecwid_is_demo_store()
434
  && get_current_screen()->parent_base == Ecwid_Admin::ADMIN_SLUG
435
  && Ecwid_Api_V3::get_api_status() == Ecwid_Api_V3::API_STATUS_ERROR_TLS
436
+ && time() - $legacy_page_time > 15 * MINUTE_IN_SECONDS;
437
 
438
  case 'api_failed_other':
439
+ $legacy_page_time = get_option( 'ecwid_connected_via_legacy_page_time', 0 );
440
  return
441
  !ecwid_is_demo_store()
442
  && get_current_screen()->parent_base == Ecwid_Admin::ADMIN_SLUG
443
  && Ecwid_Api_V3::get_api_status() == Ecwid_Api_V3::API_STATUS_ERROR_OTHER
444
+ && time() - $legacy_page_time > 15 * MINUTE_IN_SECONDS;
445
 
446
  case 'no_oauth':
447
  global $ecwid_oauth;
includes/class-ecwid-product-popup.php CHANGED
@@ -97,7 +97,7 @@ class Ecwid_Product_Popup {
97
  $output['items'][] = array(
98
  'id' => $product->id,
99
  'name' => $product->name,
100
- 'thumb' => @$product->thumbnailUrl,
101
  'sku' => $product->sku,
102
  );
103
  }
@@ -110,14 +110,12 @@ class Ecwid_Product_Popup {
110
 
111
  public function add_editor_button( $editor_id ) {
112
 
113
- $title = __( 'Add Product', 'ecwid-shopping-cart' );
114
- $button = <<<HTML
115
- <button id="insert-ecwid-product-button" class="button add-ecwid-product ecwid_button" title="$title">
116
- $title
117
- </button>
118
- HTML;
119
-
120
- echo $button;
121
  }
122
 
123
  public function add_scripts() {
97
  $output['items'][] = array(
98
  'id' => $product->id,
99
  'name' => $product->name,
100
+ 'thumb' => @$product->thumbnailUrl, //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
101
  'sku' => $product->sku,
102
  );
103
  }
110
 
111
  public function add_editor_button( $editor_id ) {
112
 
113
+ $title = __( 'Add Product', 'ecwid-shopping-cart' );
114
+ ?>
115
+ <button id="insert-ecwid-product-button" class="button add-ecwid-product ecwid_button" title="<?php echo esc_attr( $title ); ?>">
116
+ <?php echo esc_html( $title ); ?>
117
+ </button>
118
+ <?php
 
 
119
  }
120
 
121
  public function add_scripts() {
includes/class-ecwid-seo-links.php CHANGED
@@ -3,11 +3,11 @@
3
 
4
  class Ecwid_Seo_Links {
5
 
6
- const OPTION_ENABLED = 'ecwid_seo_links_enabled';
7
  const OPTION_ALL_BASE_URLS = 'ecwid_all_base_urls';
8
 
9
- public function __construct()
10
- {
11
  // therefore the action must me registered
12
  add_action( 'init', array( $this, 'build_rewrite_rules' ) );
13
 
@@ -23,61 +23,62 @@ class Ecwid_Seo_Links {
23
  add_filter( 'redirect_canonical', array( $this, 'redirect_canonical' ), 10, 2 );
24
  add_action( 'template_redirect', array( $this, 'redirect_escaped_fragment' ) );
25
  add_filter( 'get_shortlink', array( $this, 'get_shortlink' ) );
26
-
27
- add_action( 'ecwid_inline_js_config', array( $this, 'add_js_config') );
28
 
29
- add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', array( $this, 'is_post_slug_bad'), 10, 4 );
30
- add_filter( 'wp_unique_post_slug_is_bad_flat_slug', array( $this, 'is_post_slug_bad' ), 10, 2 );
31
- add_filter( 'wp_unique_post_slug_is_bad_attachment_slug', array( $this, 'is_post_slug_bad' ), 10, 2 );
32
-
 
 
33
  if ( is_admin() ) {
34
- add_action( 'current_screen', array( $this, 'check_base_urls_on_edit_store_page' ) );
35
  }
36
  }
37
  }
38
 
39
  public function on_save_post( $post_id ) {
40
- if ( wp_is_post_revision( $post_id ) )
41
  return;
42
-
 
43
  if ( Ecwid_Store_Page::is_store_page( $post_id ) ) {
44
- if ( !$this->are_base_urls_ok() ) {
45
  flush_rewrite_rules();
46
  }
47
- }
48
  }
49
-
50
  public function check_base_urls_on_edit_store_page() {
51
 
52
  $current_screen = get_current_screen();
53
-
54
- if ( $current_screen->base != 'post' || !in_array( $current_screen->post_type, array( 'post', 'page' ) ) ) {
55
  return;
56
  }
57
-
58
- $id = (isset( $_GET['post'] )) ? intval($_GET['post']) : false;
59
-
60
- if ( !$id ) {
61
  return;
62
  }
63
-
64
  if ( Ecwid_Store_Page::is_store_page( $id ) ) {
65
- if ( !$this->are_base_urls_ok() ) {
66
  flush_rewrite_rules();
67
- }
68
  }
69
  }
70
-
71
  public function check_base_urls_on_view_store_page_as_admin() {
72
  $id = get_the_ID();
73
-
74
  if ( Ecwid_Store_Page::is_store_page( $id ) ) {
75
- if ( !$this->are_base_urls_ok() ) {
76
  flush_rewrite_rules();
77
  }
78
  }
79
  }
80
-
81
  public function on_fresh_install() {
82
  add_option( self::OPTION_ENABLED, 'Y' );
83
  }
@@ -88,7 +89,7 @@ class Ecwid_Seo_Links {
88
 
89
  public function redirect_canonical( $redir, $req ) {
90
 
91
- if (self::is_store_on_home_page() && get_queried_object_id() == get_option('page_on_front')) {
92
  return false;
93
  }
94
 
@@ -99,17 +100,17 @@ class Ecwid_Seo_Links {
99
  if ( ecwid_should_display_escaped_fragment_catalog() ) {
100
  $params = ecwid_parse_escaped_fragment();
101
 
102
- if ( !isset( $params[ 'mode' ] ) ) {
103
  return;
104
  }
105
 
106
  if ( $params['mode'] == 'product' ) {
107
  $redirect = Ecwid_Store_Page::get_product_url( $params['id'] );
108
- } else if ($params['mode'] == 'category') {
109
  $redirect = Ecwid_Store_Page::get_category_url( $params['id'] );
110
  }
111
 
112
- if( isset($redirect) ) {
113
  wp_safe_redirect( $redirect, 301 );
114
  exit;
115
  }
@@ -122,11 +123,11 @@ class Ecwid_Seo_Links {
122
  }
123
 
124
  return $shortlink;
125
- }
126
 
127
  public function is_post_slug_bad( $value, $slug, $type = '', $parent = '' ) {
128
 
129
- if ( !self::is_store_on_home_page() ) {
130
  return $value;
131
  }
132
 
@@ -136,19 +137,19 @@ class Ecwid_Seo_Links {
136
 
137
  return $value;
138
  }
139
- public function slug_matches_seo_pattern($slug) {
140
  static $pattern = '';
141
 
142
- if ( !$pattern ) {
143
  $patterns = self::get_seo_links_patterns();
144
 
145
- $pattern = '!(^' . implode('$|^', $patterns) . '$)!';
146
  }
147
 
148
- return preg_match($pattern, $slug);
149
- }
150
 
151
- public static function get_seo_links_patterns() {
152
  return array(
153
  '.*-p([0-9]+)(\/.*|\?.*)?',
154
  '.*-c([0-9]+)(\/.*|\?.*)?',
@@ -175,17 +176,17 @@ class Ecwid_Seo_Links {
175
  'checkoutCC.*',
176
  'checkoutEC.*',
177
  'checkoutAC.*',
178
- 'FBAutofillCheckout.*'
179
  );
180
  }
181
 
182
  public static function is_store_on_home_page() {
183
  $front_page = get_option( 'page_on_front' );
184
-
185
- if ( !$front_page ) {
186
  return false;
187
  }
188
-
189
  if ( Ecwid_Store_Page::is_store_page( $front_page ) ) {
190
  return true;
191
  }
@@ -194,13 +195,13 @@ class Ecwid_Seo_Links {
194
  }
195
 
196
  public function add_js_config( $config ) {
197
-
198
  $page_id = get_queried_object_id();
199
 
200
  $has_store = Ecwid_Store_Page::is_store_page( $page_id );
201
-
202
- if ( !$has_store ) {
203
- if ( !Ecwid_Ajax_Defer_Renderer::is_enabled() ) {
204
  return $config;
205
  }
206
  }
@@ -215,145 +216,155 @@ class Ecwid_Seo_Links {
215
  $url = esc_js( get_permalink( $page_id ) );
216
  }
217
 
218
-
219
- if( parse_url($url, PHP_URL_SCHEME) == 'https' && parse_url($url, PHP_URL_PORT) == '443' ) {
220
  $url = str_replace( ':443', '', $url );
221
  }
222
 
223
  $result = self::get_js_config_storefront_urls();
224
 
225
- $result .= <<<JS
226
- window.ec.config.baseUrl = '$url';
227
- window.ec.storefront = window.ec.storefront || {};
228
- window.ec.storefront.sharing_button_link = "DIRECT_PAGE_URL";
229
 
230
- JS;
231
  $config .= $result;
232
-
233
  return $config;
234
  }
235
 
236
  public static function get_js_config_storefront_urls() {
237
- return <<<JS
238
- window.ec.config.storefrontUrls = window.ec.config.storefrontUrls || {};
239
- window.ec.config.storefrontUrls.cleanUrls = true;
240
- JS;
241
  }
242
 
243
  public static function is_404_seo_link() {
244
-
245
  if ( ! self::is_product_browser_url() ) {
246
  return false;
247
  }
248
-
249
  $params = self::maybe_extract_html_catalog_params();
250
- if ( !$params ) return false;
251
-
 
 
252
  // Root is always ok
253
  $is_root_cat = $params['mode'] == 'category' && $params['id'] == 0;
254
  if ( $is_root_cat ) {
255
  return false;
256
  }
257
-
258
  $result = false;
259
-
260
- if ($params['mode'] == 'product') {
261
  $result = Ecwid_Product::get_by_id( $params['id'] );
262
- } elseif (!$is_root_cat && $params['mode'] == 'category') {
263
  $result = Ecwid_Category::get_by_id( $params['id'] );
264
  }
265
-
266
  // Can't parse params, assume its ok
267
- if ( !$result ) {
268
  return false;
269
  }
270
-
271
  // product/category not found, 404
272
- if ( is_object ( $result ) && ( !isset( $result->id ) || !$result->enabled ) ) {
273
  return true;
274
  }
275
-
276
  return false;
277
  }
278
-
279
  public static function maybe_extract_html_catalog_params() {
280
 
281
  $current_url = add_query_arg( null, null );
282
- $matches = array();
283
- if ( !preg_match( self::_get_pb_preg_pattern(), $current_url, $matches ) ) {
284
  return array();
285
  }
286
 
287
  $modes = array(
288
  'p' => 'product',
289
- 'c' => 'category'
290
  );
291
 
292
- return array( 'mode' => $modes[$matches[1]], 'id' => $matches[2] );
 
 
 
293
  }
294
 
295
  public static function is_product_browser_url( $url = '' ) {
296
- if (!$url) {
297
  $url = add_query_arg( null, null );
298
  }
299
 
300
  return preg_match( self::_get_pb_preg_pattern(), $url );
301
  }
302
-
303
  public static function is_seo_link() {
304
- if ( !Ecwid_Store_Page::is_store_page() ) return false;
305
-
 
 
306
  $url = add_query_arg( null, null );
307
-
308
- $link = urldecode( self::_get_relative_permalink( get_the_ID() ) );
309
- $site_url = parse_url( get_bloginfo('url') );
310
- $site_path = (isset($site_url['path'])) ? $site_url['path'] : '';
311
-
312
  foreach ( self::get_seo_links_patterns() as $pattern ) {
313
  $pattern = '#' . $site_path . preg_quote( $link ) . $pattern . '#';
314
-
315
  if ( preg_match( $pattern, $url ) ) {
316
  return true;
317
  }
318
  }
319
-
320
  return false;
321
  }
322
 
323
  protected static function _get_pb_preg_pattern() {
324
- return $pattern = '!.*-(p|c)([0-9]+)(\/.*|\?.*)?$!';
325
  }
326
 
327
- public function build_rewrite_rules( ) {
 
 
 
 
328
 
329
- if ( !self::is_enabled() ) return;
330
-
331
  $all_base_urls = $this->_build_all_base_urls();
332
-
333
  foreach ( $all_base_urls as $page_id => $links ) {
334
  $patterns = self::get_seo_links_patterns();
335
-
336
  $post = get_post( $page_id );
337
- if ( ! $post ) continue;
338
- if ( !in_array( $post->post_type, array( 'page', 'post' ) ) ) continue;
339
-
 
 
 
 
340
  $param_name = $post->post_type == 'page' ? 'page_id' : 'p';
341
-
342
  foreach ( $links as $link ) {
343
  $link = trim( $link, '/' );
344
 
345
- $link = apply_filters( 'ecwid_rewrite_rules_relative_link', $link, $page_id );
346
  $link_page_id = apply_filters( 'ecwid_rewrite_rules_page_id', $page_id, $link );
347
 
348
- if (strpos($link, 'index.php') !== 0) {
349
  $link = '^' . preg_quote( $link );
350
  }
351
-
352
  foreach ( $patterns as $pattern ) {
353
  add_rewrite_rule( $link . '/' . $pattern . '.*', 'index.php?' . $param_name . '=' . $link_page_id, 'top' );
354
  }
355
  }
356
- }
357
 
358
  if ( self::is_store_on_home_page() ) {
359
  $patterns = self::get_seo_links_patterns();
@@ -364,98 +375,103 @@ JS;
364
 
365
  update_option( self::OPTION_ALL_BASE_URLS, array_merge( $all_base_urls, array( 'home' => self::is_store_on_home_page() ) ) );
366
  }
367
-
368
  public function are_base_urls_ok() {
369
- if (! self::is_feature_available() ) {
370
  return true;
371
  }
372
-
373
  $all_base_urls = $this->_build_all_base_urls();
374
-
375
  $flattened = array();
376
  foreach ( $all_base_urls as $page_id => $links ) {
377
  foreach ( $links as $link ) {
378
- $flattened[$link] = $link;
379
  }
380
  }
381
-
382
  $saved = get_option( self::OPTION_ALL_BASE_URLS );
383
 
384
- if ( empty( $saved ) || !is_array( $saved ) ) {
385
  return false;
386
  }
387
-
388
  $saved_home = false;
389
  if ( isset( $saved['home'] ) ) {
390
  $saved_home = $saved['home'];
391
  unset( $saved['home'] );
392
  }
393
-
394
  $flattened_saved = array();
395
  foreach ( $saved as $page_id => $links ) {
396
  foreach ( $links as $link ) {
397
- $flattened_saved[$link] = $link;
398
  }
399
  }
400
-
401
  $rules = get_option( 'rewrite_rules' );
402
-
403
- if ( empty( $rules ) ) return false;
404
-
 
 
405
  foreach ( $flattened as $link ) {
406
  $link = trim( $link, '/' );
407
-
408
  $patterns = self::get_seo_links_patterns();
409
- $pattern = $patterns[0];
410
-
411
  $rules_pattern = '^' . $link . '/' . $pattern . '.*';
412
-
413
- if ( !array_key_exists( $rules_pattern, $rules ) ) {
414
  return false;
415
  }
416
  }
417
-
418
  $are_the_same = array_diff( $flattened, $flattened_saved );
419
-
420
  return empty( $are_the_same ) && $saved_home == self::is_store_on_home_page();
421
  }
422
-
423
- protected function _build_all_base_urls()
424
- {
425
- $base_urls = array();
426
 
427
  $pages = Ecwid_Store_Page::get_store_pages_array();
428
 
429
  if ( is_array( $pages ) ) {
430
  foreach ( $pages as $page_id ) {
431
-
432
- if ( !isset( $base_urls[$page_id] ) ) {
433
- $base_urls[$page_id] = array();
434
  }
435
-
436
  $link = urldecode( self::_get_relative_permalink( $page_id, true ) );
437
 
438
- $base_urls[$page_id][] = $link;
439
  }
440
  }
441
-
442
  return $base_urls;
443
  }
444
-
445
  protected static function _get_relative_permalink( $item_id, $not_filter_return_value = false ) {
446
  $permalink = parse_url( get_permalink( $item_id ) );
447
- $home_url = parse_url( home_url() );
448
 
449
- if( !isset($permalink['path']) ) $permalink['path'] = '/';
450
- if( !isset($home_url['path']) ) $home_url['path'] = '';
 
 
 
 
451
 
452
- if( isset($home_url['query']) ) {
453
  $home_url['path'] = substr( $home_url['path'], 0, -1 );
454
  }
455
 
456
  $default_link = substr( $permalink['path'], strlen( $home_url['path'] ) );
457
 
458
- if( $not_filter_return_value ) {
459
  return $default_link;
460
  }
461
 
@@ -463,8 +479,8 @@ JS;
463
  }
464
 
465
  public static function is_noindex_page() {
466
-
467
- if ( !Ecwid_Store_Page::is_store_page() ) {
468
  return false;
469
  }
470
 
@@ -475,24 +491,24 @@ JS;
475
  'account',
476
  'checkout',
477
  'signin',
478
- 'search'
479
  );
480
-
481
  $home_url = home_url();
482
- $path = parse_url( $home_url, PHP_URL_PATH );
 
 
 
483
 
484
- $request_uri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : '';
485
- $seo_part = str_replace( $path . $relative_permalink, '', $request_uri );
486
-
487
  foreach ( $noindex_pages as $page ) {
488
  if ( preg_match( '!' . $page . '([\?\/]+.*|)$' . '!', $seo_part ) ) {
489
  return true;
490
  }
491
  }
492
-
493
  return false;
494
  }
495
-
496
  public static function is_enabled() {
497
 
498
  return self::is_feature_available() && get_option( self::OPTION_ENABLED );
@@ -518,4 +534,4 @@ JS;
518
 
519
  }
520
 
521
- $ecwid_seo_links = new Ecwid_Seo_Links();
3
 
4
  class Ecwid_Seo_Links {
5
 
6
+ const OPTION_ENABLED = 'ecwid_seo_links_enabled';
7
  const OPTION_ALL_BASE_URLS = 'ecwid_all_base_urls';
8
 
9
+ public function __construct() {
10
+
11
  // therefore the action must me registered
12
  add_action( 'init', array( $this, 'build_rewrite_rules' ) );
13
 
23
  add_filter( 'redirect_canonical', array( $this, 'redirect_canonical' ), 10, 2 );
24
  add_action( 'template_redirect', array( $this, 'redirect_escaped_fragment' ) );
25
  add_filter( 'get_shortlink', array( $this, 'get_shortlink' ) );
 
 
26
 
27
+ add_action( 'ecwid_inline_js_config', array( $this, 'add_js_config' ) );
28
+
29
+ add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', array( $this, 'is_post_slug_bad' ), 10, 4 );
30
+ add_filter( 'wp_unique_post_slug_is_bad_flat_slug', array( $this, 'is_post_slug_bad' ), 10, 2 );
31
+ add_filter( 'wp_unique_post_slug_is_bad_attachment_slug', array( $this, 'is_post_slug_bad' ), 10, 2 );
32
+
33
  if ( is_admin() ) {
34
+ add_action( 'current_screen', array( $this, 'check_base_urls_on_edit_store_page' ) );
35
  }
36
  }
37
  }
38
 
39
  public function on_save_post( $post_id ) {
40
+ if ( wp_is_post_revision( $post_id ) ) {
41
  return;
42
+ }
43
+
44
  if ( Ecwid_Store_Page::is_store_page( $post_id ) ) {
45
+ if ( ! $this->are_base_urls_ok() ) {
46
  flush_rewrite_rules();
47
  }
48
+ }
49
  }
50
+
51
  public function check_base_urls_on_edit_store_page() {
52
 
53
  $current_screen = get_current_screen();
54
+
55
+ if ( $current_screen->base != 'post' || ! in_array( $current_screen->post_type, array( 'post', 'page' ) ) ) {
56
  return;
57
  }
58
+
59
+ $id = ( isset( $_GET['post'] ) ) ? intval( $_GET['post'] ) : false;
60
+
61
+ if ( ! $id ) {
62
  return;
63
  }
64
+
65
  if ( Ecwid_Store_Page::is_store_page( $id ) ) {
66
+ if ( ! $this->are_base_urls_ok() ) {
67
  flush_rewrite_rules();
68
+ }
69
  }
70
  }
71
+
72
  public function check_base_urls_on_view_store_page_as_admin() {
73
  $id = get_the_ID();
74
+
75
  if ( Ecwid_Store_Page::is_store_page( $id ) ) {
76
+ if ( ! $this->are_base_urls_ok() ) {
77
  flush_rewrite_rules();
78
  }
79
  }
80
  }
81
+
82
  public function on_fresh_install() {
83
  add_option( self::OPTION_ENABLED, 'Y' );
84
  }
89
 
90
  public function redirect_canonical( $redir, $req ) {
91
 
92
+ if ( self::is_store_on_home_page() && get_queried_object_id() == get_option( 'page_on_front' ) ) {
93
  return false;
94
  }
95
 
100
  if ( ecwid_should_display_escaped_fragment_catalog() ) {
101
  $params = ecwid_parse_escaped_fragment();
102
 
103
+ if ( ! isset( $params['mode'] ) ) {
104
  return;
105
  }
106
 
107
  if ( $params['mode'] == 'product' ) {
108
  $redirect = Ecwid_Store_Page::get_product_url( $params['id'] );
109
+ } elseif ( $params['mode'] == 'category' ) {
110
  $redirect = Ecwid_Store_Page::get_category_url( $params['id'] );
111
  }
112
 
113
+ if ( isset( $redirect ) ) {
114
  wp_safe_redirect( $redirect, 301 );
115
  exit;
116
  }
123
  }
124
 
125
  return $shortlink;
126
+ }
127
 
128
  public function is_post_slug_bad( $value, $slug, $type = '', $parent = '' ) {
129
 
130
+ if ( ! self::is_store_on_home_page() ) {
131
  return $value;
132
  }
133
 
137
 
138
  return $value;
139
  }
140
+ public function slug_matches_seo_pattern( $slug ) {
141
  static $pattern = '';
142
 
143
+ if ( ! $pattern ) {
144
  $patterns = self::get_seo_links_patterns();
145
 
146
+ $pattern = '!(^' . implode( '$|^', $patterns ) . '$)!';
147
  }
148
 
149
+ return preg_match( $pattern, $slug );
150
+ }
151
 
152
+ public static function get_seo_links_patterns() {
153
  return array(
154
  '.*-p([0-9]+)(\/.*|\?.*)?',
155
  '.*-c([0-9]+)(\/.*|\?.*)?',
176
  'checkoutCC.*',
177
  'checkoutEC.*',
178
  'checkoutAC.*',
179
+ 'FBAutofillCheckout.*',
180
  );
181
  }
182
 
183
  public static function is_store_on_home_page() {
184
  $front_page = get_option( 'page_on_front' );
185
+
186
+ if ( ! $front_page ) {
187
  return false;
188
  }
189
+
190
  if ( Ecwid_Store_Page::is_store_page( $front_page ) ) {
191
  return true;
192
  }
195
  }
196
 
197
  public function add_js_config( $config ) {
198
+
199
  $page_id = get_queried_object_id();
200
 
201
  $has_store = Ecwid_Store_Page::is_store_page( $page_id );
202
+
203
+ if ( ! $has_store ) {
204
+ if ( ! Ecwid_Ajax_Defer_Renderer::is_enabled() ) {
205
  return $config;
206
  }
207
  }
216
  $url = esc_js( get_permalink( $page_id ) );
217
  }
218
 
219
+ if ( parse_url( $url, PHP_URL_SCHEME ) == 'https' && parse_url( $url, PHP_URL_PORT ) == '443' ) {
 
220
  $url = str_replace( ':443', '', $url );
221
  }
222
 
223
  $result = self::get_js_config_storefront_urls();
224
 
225
+ $result .= "
226
+ window.ec.config.baseUrl = '$url';
227
+ window.ec.storefront = window.ec.storefront || {};
228
+ window.ec.storefront.sharing_button_link = 'DIRECT_PAGE_URL';";
229
 
 
230
  $config .= $result;
231
+
232
  return $config;
233
  }
234
 
235
  public static function get_js_config_storefront_urls() {
236
+ return '
237
+ window.ec.config.storefrontUrls = window.ec.config.storefrontUrls || {};
238
+ window.ec.config.storefrontUrls.cleanUrls = true;';
 
239
  }
240
 
241
  public static function is_404_seo_link() {
242
+
243
  if ( ! self::is_product_browser_url() ) {
244
  return false;
245
  }
246
+
247
  $params = self::maybe_extract_html_catalog_params();
248
+ if ( ! $params ) {
249
+ return false;
250
+ }
251
+
252
  // Root is always ok
253
  $is_root_cat = $params['mode'] == 'category' && $params['id'] == 0;
254
  if ( $is_root_cat ) {
255
  return false;
256
  }
257
+
258
  $result = false;
259
+
260
+ if ( $params['mode'] == 'product' ) {
261
  $result = Ecwid_Product::get_by_id( $params['id'] );
262
+ } elseif ( ! $is_root_cat && $params['mode'] == 'category' ) {
263
  $result = Ecwid_Category::get_by_id( $params['id'] );
264
  }
265
+
266
  // Can't parse params, assume its ok
267
+ if ( ! $result ) {
268
  return false;
269
  }
270
+
271
  // product/category not found, 404
272
+ if ( is_object( $result ) && ( ! isset( $result->id ) || ! $result->enabled ) ) {
273
  return true;
274
  }
275
+
276
  return false;
277
  }
278
+
279
  public static function maybe_extract_html_catalog_params() {
280
 
281
  $current_url = add_query_arg( null, null );
282
+ $matches = array();
283
+ if ( ! preg_match( self::_get_pb_preg_pattern(), $current_url, $matches ) ) {
284
  return array();
285
  }
286
 
287
  $modes = array(
288
  'p' => 'product',
289
+ 'c' => 'category',
290
  );
291
 
292
+ return array(
293
+ 'mode' => $modes[ $matches[1] ],
294
+ 'id' => $matches[2],
295
+ );
296
  }
297
 
298
  public static function is_product_browser_url( $url = '' ) {
299
+ if ( ! $url ) {
300
  $url = add_query_arg( null, null );
301
  }
302
 
303
  return preg_match( self::_get_pb_preg_pattern(), $url );
304
  }
305
+
306
  public static function is_seo_link() {
307
+ if ( ! Ecwid_Store_Page::is_store_page() ) {
308
+ return false;
309
+ }
310
+
311
  $url = add_query_arg( null, null );
312
+
313
+ $link = urldecode( self::_get_relative_permalink( get_the_ID() ) );
314
+ $site_url = parse_url( get_bloginfo( 'url' ) );
315
+ $site_path = ( isset( $site_url['path'] ) ) ? $site_url['path'] : '';
316
+
317
  foreach ( self::get_seo_links_patterns() as $pattern ) {
318
  $pattern = '#' . $site_path . preg_quote( $link ) . $pattern . '#';
319
+
320
  if ( preg_match( $pattern, $url ) ) {
321
  return true;
322
  }
323
  }
324
+
325
  return false;
326
  }
327
 
328
  protected static function _get_pb_preg_pattern() {
329
+ return '!.*-(p|c)([0-9]+)(\/.*|\?.*)?$!';
330
  }
331
 
332
+ public function build_rewrite_rules() {
333
+
334
+ if ( ! self::is_enabled() ) {
335
+ return;
336
+ }
337
 
 
 
338
  $all_base_urls = $this->_build_all_base_urls();
339
+
340
  foreach ( $all_base_urls as $page_id => $links ) {
341
  $patterns = self::get_seo_links_patterns();
342
+
343
  $post = get_post( $page_id );
344
+ if ( ! $post ) {
345
+ continue;
346
+ }
347
+ if ( ! in_array( $post->post_type, array( 'page', 'post' ) ) ) {
348
+ continue;
349
+ }
350
+
351
  $param_name = $post->post_type == 'page' ? 'page_id' : 'p';
352
+
353
  foreach ( $links as $link ) {
354
  $link = trim( $link, '/' );
355
 
356
+ $link = apply_filters( 'ecwid_rewrite_rules_relative_link', $link, $page_id );
357
  $link_page_id = apply_filters( 'ecwid_rewrite_rules_page_id', $page_id, $link );
358
 
359
+ if ( strpos( $link, 'index.php' ) !== 0 ) {
360
  $link = '^' . preg_quote( $link );
361
  }
362
+
363
  foreach ( $patterns as $pattern ) {
364
  add_rewrite_rule( $link . '/' . $pattern . '.*', 'index.php?' . $param_name . '=' . $link_page_id, 'top' );
365
  }
366
  }
367
+ }//end foreach
368
 
369
  if ( self::is_store_on_home_page() ) {
370
  $patterns = self::get_seo_links_patterns();
375
 
376
  update_option( self::OPTION_ALL_BASE_URLS, array_merge( $all_base_urls, array( 'home' => self::is_store_on_home_page() ) ) );
377
  }
378
+
379
  public function are_base_urls_ok() {
380
+ if ( ! self::is_feature_available() ) {
381
  return true;
382
  }
383
+
384
  $all_base_urls = $this->_build_all_base_urls();
385
+
386
  $flattened = array();
387
  foreach ( $all_base_urls as $page_id => $links ) {
388
  foreach ( $links as $link ) {
389
+ $flattened[ $link ] = $link;
390
  }
391
  }
392
+
393
  $saved = get_option( self::OPTION_ALL_BASE_URLS );
394
 
395
+ if ( empty( $saved ) || ! is_array( $saved ) ) {
396
  return false;
397
  }
398
+
399
  $saved_home = false;
400
  if ( isset( $saved['home'] ) ) {
401
  $saved_home = $saved['home'];
402
  unset( $saved['home'] );
403
  }
404
+
405
  $flattened_saved = array();
406
  foreach ( $saved as $page_id => $links ) {
407
  foreach ( $links as $link ) {
408
+ $flattened_saved[ $link ] = $link;
409
  }
410
  }
411
+
412
  $rules = get_option( 'rewrite_rules' );
413
+
414
+ if ( empty( $rules ) ) {
415
+ return false;
416
+ }
417
+
418
  foreach ( $flattened as $link ) {
419
  $link = trim( $link, '/' );
420
+
421
  $patterns = self::get_seo_links_patterns();
422
+ $pattern = $patterns[0];
423
+
424
  $rules_pattern = '^' . $link . '/' . $pattern . '.*';
425
+
426
+ if ( ! array_key_exists( $rules_pattern, $rules ) ) {
427
  return false;
428
  }
429
  }
430
+
431
  $are_the_same = array_diff( $flattened, $flattened_saved );
432
+
433
  return empty( $are_the_same ) && $saved_home == self::is_store_on_home_page();
434
  }
435
+
436
+ protected function _build_all_base_urls() {
437
+ $base_urls = array();
 
438
 
439
  $pages = Ecwid_Store_Page::get_store_pages_array();
440
 
441
  if ( is_array( $pages ) ) {
442
  foreach ( $pages as $page_id ) {
443
+
444
+ if ( ! isset( $base_urls[ $page_id ] ) ) {
445
+ $base_urls[ $page_id ] = array();
446
  }
447
+
448
  $link = urldecode( self::_get_relative_permalink( $page_id, true ) );
449
 
450
+ $base_urls[ $page_id ][] = $link;
451
  }
452
  }
453
+
454
  return $base_urls;
455
  }
456
+
457
  protected static function _get_relative_permalink( $item_id, $not_filter_return_value = false ) {
458
  $permalink = parse_url( get_permalink( $item_id ) );
459
+ $home_url = parse_url( home_url() );
460
 
461
+ if ( ! isset( $permalink['path'] ) ) {
462
+ $permalink['path'] = '/';
463
+ }
464
+ if ( ! isset( $home_url['path'] ) ) {
465
+ $home_url['path'] = '';
466
+ }
467
 
468
+ if ( isset( $home_url['query'] ) ) {
469
  $home_url['path'] = substr( $home_url['path'], 0, -1 );
470
  }
471
 
472
  $default_link = substr( $permalink['path'], strlen( $home_url['path'] ) );
473
 
474
+ if ( $not_filter_return_value ) {
475
  return $default_link;
476
  }
477
 
479
  }
480
 
481
  public static function is_noindex_page() {
482
+
483
+ if ( ! Ecwid_Store_Page::is_store_page() ) {
484
  return false;
485
  }
486
 
491
  'account',
492
  'checkout',
493
  'signin',
494
+ 'search',
495
  );
496
+
497
  $home_url = home_url();
498
+ $path = parse_url( $home_url, PHP_URL_PATH );
499
+
500
+ $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
501
+ $seo_part = str_replace( $path . $relative_permalink, '', $request_uri );
502
 
 
 
 
503
  foreach ( $noindex_pages as $page ) {
504
  if ( preg_match( '!' . $page . '([\?\/]+.*|)$' . '!', $seo_part ) ) {
505
  return true;
506
  }
507
  }
508
+
509
  return false;
510
  }
511
+
512
  public static function is_enabled() {
513
 
514
  return self::is_feature_available() && get_option( self::OPTION_ENABLED );
534
 
535
  }
536
 
537
+ $ecwid_seo_links = new Ecwid_Seo_Links();
includes/class-ecwid-store-editor.php CHANGED
@@ -1,77 +1,65 @@
1
  <?php
2
 
3
  class Ecwid_Store_Editor {
4
- public function __construct()
5
- {
6
  $version = get_bloginfo( 'version' );
7
  if ( version_compare( $version, '3.5' ) < 0 ) {
8
  return;
9
  }
10
 
11
- add_action( 'template_redirect', array( $this, 'get_store_svg' ) );
12
 
13
- add_action( 'current_screen', array($this, 'init') );
14
  }
15
-
16
- public function init()
17
- {
18
  $current_screen = get_current_screen();
19
 
20
- if ( $current_screen->base != 'post' || !in_array( $current_screen->post_type, array( 'post', 'page' ) ) ) {
21
  return;
22
  }
23
-
24
- if ( is_plugin_active( 'elementor/elementor.php' ) && isset($_GET['action']) && $_GET['action'] == 'elementor' ) {
25
- return;
26
  }
27
 
28
- if ( is_plugin_active( 'gutenberg/gutenberg.php' ) && !isset( $_GET['classic-editor'] ) ) {
29
  return;
30
- }
31
-
32
- add_filter( 'mce_external_plugins', array( $this, 'add_mce_plugin' ) );
33
  add_action( 'media_buttons', array( $this, 'add_editor_button' ) );
34
  add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
35
- add_action( 'in_admin_header', array( $this, 'add_popup' ) );
36
  }
37
 
38
- public function add_mce_plugin($plugins) {
39
 
40
  $plugins_array = array(
41
- 'ecwid' => ECWID_PLUGIN_URL . 'js/store-editor-mce.js',
42
  'ecwid_common' => ECWID_PLUGIN_URL . 'js/store-editor-common.js',
43
  );
44
 
45
- return array_merge($plugins, $plugins_array);
46
  }
47
 
48
- public function add_editor_button($editor_id) {
49
-
50
- $image_code = file_get_contents( ECWID_PLUGIN_DIR . 'images/store.svg' );
51
-
52
- $title = __( 'Add Store', 'ecwid-shopping-cart' );
53
- $button = <<<HTML
54
- <button id="insert-ecwid-button" class="button add-ecwid ecwid_button" title="$title">
55
- <span class="ecwid-store-icon">$image_code</span>
56
- $title
57
- </button>
58
- HTML;
59
-
60
- $title = __( 'Edit Store', 'ecwid-shopping-cart' );
61
- $button .= <<<HTML
62
- <button id="update-ecwid-button" class="button update-ecwid ecwid_button" title="$title">
63
- <span class="ecwid-store-icon">$image_code</span>
64
- $title
65
- </button>
66
- HTML;
67
-
68
- echo $button;
69
  }
70
 
71
  public function add_scripts() {
72
- wp_enqueue_style( 'ecwid-store-editor-css', ECWID_PLUGIN_URL . 'css/store-popup.css', array(), get_option('ecwid_plugin_version') );
73
- wp_enqueue_script( 'ecwid-store-editor-common-js', ECWID_PLUGIN_URL . 'js/store-editor-common.js', array(), get_option('ecwid_plugin_version') );
74
- wp_enqueue_script( 'ecwid-store-editor-page-js', ECWID_PLUGIN_URL . 'js/store-editor-page.js', array(), get_option('ecwid_plugin_version') );
75
  wp_localize_script( 'ecwid-store-editor-page-js', 'ecwid_i18n', array( 'edit_store_appearance' => __( 'Edit Appearance', 'ecwid-shopping-cart' ) ) );
76
  wp_localize_script( 'ecwid-store-editor-page-js', 'ecwid_pb_defaults', ecwid_get_default_pb_size() );
77
  add_editor_style( ECWID_PLUGIN_URL . 'css/page-editor.css' );
@@ -79,18 +67,18 @@ HTML;
79
 
80
  public function get_store_svg() {
81
  // TODO: Move this to admin-post
82
- if (isset($_GET['file']) && $_GET['file'] == 'ecwid_store_svg.svg' && current_user_can('administrator')) {
83
  ecwid_load_textdomain();
84
  header( 'Content-type: image/svg+xml' );
85
- require_once( ECWID_PLUGIN_DIR . 'templates/store-svg.php' );
86
  die();
87
  }
88
  }
89
 
90
  public function add_popup() {
91
  $categories = ecwid_get_categories_for_selector();
92
-
93
- require_once( ECWID_PLUGIN_DIR . 'templates/store-popup.php' );
94
  }
95
  }
96
 
1
  <?php
2
 
3
  class Ecwid_Store_Editor {
4
+ public function __construct() {
 
5
  $version = get_bloginfo( 'version' );
6
  if ( version_compare( $version, '3.5' ) < 0 ) {
7
  return;
8
  }
9
 
10
+ add_action( 'template_redirect', array( $this, 'get_store_svg' ) );
11
 
12
+ add_action( 'current_screen', array( $this, 'init' ) );
13
  }
14
+
15
+ public function init() {
 
16
  $current_screen = get_current_screen();
17
 
18
+ if ( $current_screen->base != 'post' || ! in_array( $current_screen->post_type, array( 'post', 'page' ) ) ) {
19
  return;
20
  }
21
+
22
+ if ( is_plugin_active( 'elementor/elementor.php' ) && isset( $_GET['action'] ) && $_GET['action'] == 'elementor' ) {
23
+ return;
24
  }
25
 
26
+ if ( is_plugin_active( 'gutenberg/gutenberg.php' ) && ! isset( $_GET['classic-editor'] ) ) {
27
  return;
28
+ }
29
+
30
+ add_filter( 'mce_external_plugins', array( $this, 'add_mce_plugin' ) );
31
  add_action( 'media_buttons', array( $this, 'add_editor_button' ) );
32
  add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
33
+ add_action( 'in_admin_header', array( $this, 'add_popup' ) );
34
  }
35
 
36
+ public function add_mce_plugin( $plugins ) {
37
 
38
  $plugins_array = array(
39
+ 'ecwid' => ECWID_PLUGIN_URL . 'js/store-editor-mce.js',
40
  'ecwid_common' => ECWID_PLUGIN_URL . 'js/store-editor-common.js',
41
  );
42
 
43
+ return array_merge( $plugins, $plugins_array );
44
  }
45
 
46
+ public function add_editor_button( $editor_id ) {
47
+ ?>
48
+ <button id="insert-ecwid-button" class="button add-ecwid ecwid_button" title="$title">
49
+ <span class="ecwid-store-icon"><?php ecwid_embed_svg( 'store' ); ?></span>
50
+ <?php echo esc_html__( 'Add Store', 'ecwid-shopping-cart' ); ?>
51
+ </button>
52
+ <button id="update-ecwid-button" class="button update-ecwid ecwid_button" title="$title">
53
+ <span class="ecwid-store-icon"><?php ecwid_embed_svg( 'store' ); ?></span>
54
+ <?php echo esc_html__( 'Edit Store', 'ecwid-shopping-cart' ); ?>
55
+ </button>
56
+ <?php
 
 
 
 
 
 
 
 
 
 
57
  }
58
 
59
  public function add_scripts() {
60
+ wp_enqueue_style( 'ecwid-store-editor-css', ECWID_PLUGIN_URL . 'css/store-popup.css', array(), get_option( 'ecwid_plugin_version' ) );
61
+ wp_enqueue_script( 'ecwid-store-editor-common-js', ECWID_PLUGIN_URL . 'js/store-editor-common.js', array(), get_option( 'ecwid_plugin_version' ) );
62
+ wp_enqueue_script( 'ecwid-store-editor-page-js', ECWID_PLUGIN_URL . 'js/store-editor-page.js', array(), get_option( 'ecwid_plugin_version' ) );
63
  wp_localize_script( 'ecwid-store-editor-page-js', 'ecwid_i18n', array( 'edit_store_appearance' => __( 'Edit Appearance', 'ecwid-shopping-cart' ) ) );
64
  wp_localize_script( 'ecwid-store-editor-page-js', 'ecwid_pb_defaults', ecwid_get_default_pb_size() );
65
  add_editor_style( ECWID_PLUGIN_URL . 'css/page-editor.css' );
67
 
68
  public function get_store_svg() {
69
  // TODO: Move this to admin-post
70
+ if ( isset( $_GET['file'] ) && $_GET['file'] == 'ecwid_store_svg.svg' && current_user_can( 'administrator' ) ) {
71
  ecwid_load_textdomain();
72
  header( 'Content-type: image/svg+xml' );
73
+ require_once ECWID_PLUGIN_DIR . 'templates/store-svg.php';
74
  die();
75
  }
76
  }
77
 
78
  public function add_popup() {
79
  $categories = ecwid_get_categories_for_selector();
80
+
81
+ require_once ECWID_PLUGIN_DIR . 'templates/store-popup.php';
82
  }
83
  }
84
 
includes/class-ecwid-store-page.php CHANGED
@@ -2,23 +2,22 @@
2
 
3
  class Ecwid_Store_Page {
4
 
5
- const OPTION_STORE_PAGES = 'ecwid_store_pages';
6
  const OPTION_MAIN_STORE_PAGE_ID = 'ecwid_store_page_id';
7
  const OPTION_LAST_STORE_PAGE_ID = 'ecwid_last_store_page_id';
8
- const OPTION_FLUSH_REWRITES = 'ecwid_flush_rewrites';
9
- const OPTION_REPLACE_TITLE = 'ecwid_replace_title';
10
- const WARMUP_ACTION = 'ecwid_warmup_store';
11
-
12
  const META_STORE_DATA = 'ecwid_store';
13
 
14
  protected static $_store_pages = false;
15
 
16
- public static function get_product_url( $id )
17
- {
18
  $product = Ecwid_Product::get_by_id( $id );
19
-
20
  $url = $product->link;
21
-
22
  if ( $url ) {
23
  return $url;
24
  }
@@ -27,7 +26,7 @@ class Ecwid_Store_Page {
27
  }
28
 
29
  public static function get_product_url_from_api( $id ) {
30
-
31
  if ( Ecwid_Api_V3::is_available() ) {
32
 
33
  $api = new Ecwid_Api_V3();
@@ -47,17 +46,15 @@ class Ecwid_Store_Page {
47
  return self::get_store_url() . '#!/p/' . $id;
48
  }
49
 
50
- public static function get_category_url( $id )
51
- {
52
  $category = Ecwid_Category::get_by_id( $id );
53
 
54
  $url = $category->link;
55
-
56
  if ( $url ) {
57
  return $url;
58
  }
59
-
60
-
61
  if ( $id == 0 ) {
62
  return self::get_store_url();
63
  }
@@ -77,8 +74,7 @@ class Ecwid_Store_Page {
77
  return self::get_store_url() . '#!/c/' . $id;
78
  }
79
 
80
- public static function get_menu_item_url( $menu_item )
81
- {
82
  $suffix = '';
83
  if ( Ecwid_Seo_Links::is_enabled() ) {
84
  $suffix = $menu_item['ecwid-page'];
@@ -91,8 +87,7 @@ class Ecwid_Store_Page {
91
  return self::get_store_url() . $suffix;
92
  }
93
 
94
- public static function get_cart_url()
95
- {
96
  if ( Ecwid_Seo_Links::is_enabled() ) {
97
  return untrailingslashit( self::get_store_url() ) . '/cart';
98
  } else {
@@ -100,20 +95,19 @@ class Ecwid_Store_Page {
100
  }
101
  }
102
 
103
- public static function get_store_url()
104
- {
105
  static $link = null;
106
 
107
  if ( is_null( $link ) ) {
108
  $id = self::get_current_store_page_id();
109
-
110
- if ( !$id ) {
111
  return get_bloginfo( 'url' );
112
  }
113
-
114
  $link = get_permalink( $id );
115
  }
116
-
117
  return $link;
118
  }
119
 
@@ -121,34 +115,36 @@ class Ecwid_Store_Page {
121
  $existing = self::get_store_page_params();
122
 
123
  $data = array_merge( $existing, $data );
124
-
125
  EcwidPlatform::cache_set( self::_get_store_page_data_key(), $data );
126
  }
127
 
128
  public static function get_store_page_params( $page_id = 0 ) {
129
  $params = EcwidPlatform::cache_get( self::_get_store_page_data_key( $page_id ), array() );
130
-
131
- if ( !empty( $params) ) return $params;
 
 
132
 
133
  return array();
134
  }
135
 
136
- protected static function _get_store_page_data_key( $page_id = 0 )
137
- {
138
  $post = get_post( $page_id );
139
-
140
- if ( !$post ) return;
141
-
 
 
142
  return get_ecwid_store_id() . '_' . $post->ID . '_' . $post->post_modified_gmt;
143
 
144
  }
145
-
146
  public static function get_page_base_url( $page = 0 ) {
147
  return urldecode( get_page_uri( $page ) );
148
- }
149
-
150
- public static function get_current_store_page_id()
151
- {
152
  static $page_id = null;
153
 
154
  if ( is_null( $page_id ) ) {
@@ -157,45 +153,45 @@ class Ecwid_Store_Page {
157
  $id = get_option( self::OPTION_MAIN_STORE_PAGE_ID );
158
  if ( $id ) {
159
 
160
- $post = get_post( $id );
161
  $changed = false;
162
-
163
  while ( is_null( $post ) ) {
164
 
165
  $changed = true;
166
 
167
  $pages = self::get_store_pages_array();
168
- $ind = array_search( $id, $pages );
169
 
170
  if ( $ind !== false ) {
171
- unset($pages[$ind]);
172
- $pages = self::_set_store_pages($pages);
173
  }
174
 
175
  if ( count( $pages ) == 0 ) {
176
  return false;
177
  }
178
 
179
- $id = $pages[0];
180
- $post = get_post($id);
181
  }
182
  $status = get_post_status( $id );
183
 
184
- if (in_array($status, self::_get_allowed_post_statuses())) {
185
  $page_id = $id;
186
  if ( $changed ) {
187
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, $id );
188
  }
189
  }
190
- }
191
- }
192
 
193
  return $page_id;
194
  }
195
-
196
  public static function is_store_page( $page_id = 0 ) {
197
 
198
- if (!$page_id) {
199
  $page_id = get_the_ID();
200
  }
201
 
@@ -206,7 +202,7 @@ class Ecwid_Store_Page {
206
 
207
  public static function is_store_page_with_default_category() {
208
 
209
- if( !self::is_store_page() ) {
210
  return false;
211
  }
212
 
@@ -220,12 +216,12 @@ class Ecwid_Store_Page {
220
  }
221
 
222
  public static function is_store_home_page() {
223
- if( !self::is_store_page() ) {
224
  return false;
225
  }
226
-
227
  $html_catalog_params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
228
- $is_home_page = empty( $html_catalog_params );
229
 
230
  return $is_home_page;
231
  }
@@ -237,20 +233,20 @@ class Ecwid_Store_Page {
237
  return;
238
  }
239
 
240
- if( wp_is_post_revision( $page_id ) ) {
241
  return;
242
  }
243
 
244
  $pages[] = $page_id;
245
 
246
- if ( count( $pages ) == 1 || !get_option( self::OPTION_MAIN_STORE_PAGE_ID ) ) {
247
  self::update_main_store_page_id( $page_id );
248
  }
249
 
250
  self::_set_store_pages( $pages );
251
  self::schedule_flush_rewrites();
252
  }
253
-
254
  public static function reset_store_page( $page_id ) {
255
 
256
  $pages = self::get_store_pages_array();
@@ -260,23 +256,23 @@ class Ecwid_Store_Page {
260
  return;
261
  }
262
 
263
- unset( $pages[$index] );
264
  ecwid_reset_categories_cache();
265
-
266
  $pages = self::_set_store_pages( $pages );
267
 
268
  if ( $page_id == get_option( self::OPTION_MAIN_STORE_PAGE_ID ) ) {
269
-
270
  if ( isset( $pages[0] ) ) {
271
-
272
  $new_page = $pages[0];
273
  // we prefer pages, not posts
274
- foreach( $pages as $page ) {
275
- if ( get_post($page) && get_post($page)->post_type == 'page' ) {
276
  $new_page = $page;
277
  }
278
  }
279
-
280
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, $new_page );
281
  } else {
282
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, '' );
@@ -291,45 +287,43 @@ class Ecwid_Store_Page {
291
  }
292
 
293
  $pages = get_option( self::OPTION_STORE_PAGES );
294
- if ( !$pages || !is_string( $pages ) ) {
295
  $pages = '';
296
  }
297
 
298
- self::$_store_pages = explode( ',', $pages );
299
  self::$_store_pages[] = get_option( self::OPTION_MAIN_STORE_PAGE_ID );
300
- self::$_store_pages = array_values(
301
  array_filter(
302
  array_unique(
303
- self::$_store_pages
304
  )
305
  )
306
  );
307
 
308
-
309
  return self::$_store_pages;
310
  }
311
 
312
- public static function get_store_pages_array_for_selector()
313
- {
314
  $pages = self::get_store_pages_array();
315
  foreach ( $pages as $ind => $page ) {
316
-
317
- $post = get_post($page);
318
 
319
  if ( $page != self::get_current_store_page_id() && isset( $post ) && $post->post_type != 'page' ) {
320
- unset( $pages[$ind] );
321
  }
322
  }
323
-
324
  return $pages;
325
  }
326
-
327
  public static function schedule_flush_rewrites() {
328
  update_option( self::OPTION_FLUSH_REWRITES, 1 );
329
  }
330
 
331
  public static function flush_rewrites() {
332
- if ( get_option( self::OPTION_FLUSH_REWRITES ) == 1) {
333
  flush_rewrite_rules();
334
  }
335
 
@@ -354,13 +348,15 @@ class Ecwid_Store_Page {
354
  public static function post_content_has_productbrowser( $post_id = null ) {
355
 
356
  if ( is_null( $post_id ) ) {
357
- if ( is_admin() ) return false;
 
 
358
  $post_id = get_the_ID();
359
  }
360
 
361
  $result = false;
362
-
363
- $post = get_post($post_id);
364
  if ( $post ) {
365
  $post_content = get_post( $post_id )->post_content;
366
 
@@ -372,171 +368,173 @@ class Ecwid_Store_Page {
372
  }
373
 
374
  public static function update_main_store_page_id( $new_id ) {
375
-
376
  if ( self::post_content_has_productbrowser( $new_id ) ) {
377
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, $new_id );
378
  }
379
- }
380
-
381
  public static function on_save_post( $post_id ) {
382
 
383
- if ( wp_is_post_revision( $post_id ) )
384
  return;
 
385
 
386
- $has_pb = self::post_content_has_productbrowser( $post_id );
387
  $is_allowable_post_type = in_array( get_post_type( $post_id ), array( 'page', 'post' ) );
388
 
389
  if ( self::is_store_page( $post_id ) ) {
390
- $is_disabled = !in_array( get_post_status( $post_id ), self::_get_allowed_post_statuses() );
391
 
392
- if ( $is_disabled || !$has_pb ) {
393
  self::reset_store_page( $post_id );
394
  }
395
  }
396
-
397
  if ( $is_allowable_post_type && $has_pb ) {
398
  ecwid_reset_categories_cache();
399
  }
400
 
401
  if ( $is_allowable_post_type && $has_pb && in_array( get_post_status( $post_id ), self::_get_allowed_post_statuses() ) ) {
402
  self::add_store_page( $post_id );
403
- } else if ( get_option( self::OPTION_MAIN_STORE_PAGE_ID ) == $post_id ) {
404
  update_option( self::OPTION_LAST_STORE_PAGE_ID, $post_id );
405
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, '' );
406
  }
407
  }
408
 
409
- protected static function _get_allowed_post_statuses()
410
- {
411
- return array('publish', 'private', 'draft');
412
  }
413
 
414
- public static function warmup_store()
415
- {
416
  $store_page = get_post( self::get_current_store_page_id() );
417
-
418
- if ( !$store_page ) {
419
  return;
420
  }
421
-
422
  $shortcodes = array();
423
  foreach ( Ecwid_Shortcode_Base::get_store_shortcode_names() as $shortcode_name ) {
424
  $shortcodes[] = ecwid_find_shortcodes( $store_page->post_content, $shortcode_name );
425
  }
426
-
427
- if ( sizeof( $shortcodes ) == 0 ) {
428
  return;
429
  }
430
-
431
  $shortcode_data = $shortcodes[0];
432
-
433
  $category = 0;
434
-
435
  if ( isset( $shortcode_data[3] ) ) {
436
- $attributes = shortcode_parse_atts($shortcode_data[3]);
437
 
438
- if ( !$attributes ) {
439
  return;
440
  }
441
-
442
  $category = $attributes['default_category_id'];
443
  }
444
-
445
  $page_url = get_permalink( $store_page );
446
 
447
  include_once ECWID_PLUGIN_DIR . 'lib/ecwid_catalog.php';
448
 
449
- $catalog = new EcwidCatalog(get_ecwid_store_id(), $page_url);
450
-
451
- $catalog->warmup_store_page(intval($category));
452
- }
453
-
454
- /* If you figure out a better place to put this the_title functionality, go ahead, move it =) */
455
-
456
- static $main_page_title = '';
457
- static public function enqueue_original_page_title( )
458
- {
459
- if ( !get_option( self::OPTION_REPLACE_TITLE, false ) || !Ecwid_Store_Page::is_store_page() ) {
460
  return;
461
  }
462
-
463
  $script = 'dynamic-title';
464
  EcwidPlatform::enqueue_script( $script, array( 'jquery' ), true );
465
- wp_localize_script( EcwidPlatform::make_handle( $script ), 'ecwidOriginalTitle', array(
466
- 'initialTitle' => get_the_title(),
467
- 'mainPageTitle' => self::$main_page_title
468
- ) );
469
- }
470
-
471
- static public function the_title( $title, $post_id = 0 )
472
- {
473
- if ( ! self::is_store_page( $post_id ) || !get_option( self::OPTION_REPLACE_TITLE, false ) ) return $title;
474
-
475
- if( ecwid_is_demo_store() ) {
 
 
 
 
 
476
  $title .= ' &mdash; Demo';
477
  }
478
 
479
  self::$main_page_title = $title;
480
-
481
  return $title;
482
  }
483
-
484
- static public function display_post_states( $states, $post )
485
- {
486
  if ( in_array( $post->ID, self::get_store_pages_array() ) ) {
487
- $states[] = sprintf( __( '%s Store Page', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() );
 
488
  }
489
-
490
  return $states;
491
  }
492
 
493
 
494
- static public function set_store_url()
495
- {
496
  $store_page_id = self::get_current_store_page_id();
497
- if ( !$store_page_id ) {
498
  return;
499
  }
500
 
501
  $store_url = self::get_store_url();
502
 
503
- // EcwidPlatform::cache_reset( Ecwid_Api_V3::PROFILE_CACHE_NAME );
504
-
505
- $api = new Ecwid_Api_V3();
506
  $profile = $api->get_store_profile();
507
 
508
- if ( empty($profile) ) {
509
  return;
510
  }
511
 
512
  if ( ecwid_is_demo_store() ) {
513
- return;
514
  }
515
 
516
- if ( $profile->generalInfo->storeUrl == $store_url ) {
 
517
  return;
518
  }
519
 
520
- $is_empty = in_array( $profile->generalInfo->storeUrl, array('http://', 'https://') );
521
- $is_same_domain = wp_parse_url( $profile->generalInfo->storeUrl, PHP_URL_HOST ) == wp_parse_url( $store_url, PHP_URL_HOST );
522
-
523
  $is_custom_domain = isset( $profile->generalInfo->starterSite->customDomain );
524
- $is_generated_url = ($profile->generalInfo->storeUrl == $profile->generalInfo->starterSite->generatedUrl) && !$is_custom_domain;
525
 
526
- $is_dev_to_prod = self::is_localhost( $profile->generalInfo->storeUrl ) && !self::is_localhost( $store_url );
527
- if( $is_dev_to_prod ) {
528
  $is_same_domain = true;
529
  }
 
530
 
531
- if ( !$is_empty && !$is_generated_url && !$is_same_domain ) {
532
- return;
533
  }
534
 
535
  $params = array(
536
  'generalInfo' => array(
537
- 'storeUrl' => $store_url,
538
- 'websitePlatform' => 'wordpress'
539
- )
540
  );
541
 
542
  $result = $api->update_store_profile( $params );
@@ -546,63 +544,66 @@ class Ecwid_Store_Page {
546
  }
547
  }
548
 
549
- static public function is_localhost( $url ) {
550
 
551
- $hostname = wp_parse_url($url, PHP_URL_HOST);
552
- $ip = gethostbyname( $hostname );
553
 
554
- if( $ip ) {
555
- return in_array( $ip, array('127.0.0.1', '::1') );
556
  }
557
 
558
  return false;
559
  }
560
 
561
- static public function show_notice_for_demo( $content ) {
562
 
563
- if( ecwid_is_demo_store() && current_user_can('manage_options') && self::is_store_page() ) {
 
 
 
 
 
 
 
564
 
565
- $demo_notice = <<<HTML
566
- <script data-cfasync="false" type="text/javascript">
567
- jQuery(document).ready(function(){
568
- if( typeof Ecwid == 'object' && typeof Ecwid.OnPageLoaded == 'object' ) {
569
- Ecwid.OnPageLoaded.add(function(page){
570
- if( jQuery('.ec-notice.ec-demo-notice').length > 0 ) return;
571
 
572
- jQuery('.ec-store__content-wrapper').eq(0).append( '<div class="ec-notice ec-demo-notice"><div class="ec-notice__wrap"><div class="ec-notice__message"><div class="ec-notice__text"><div class="ec-notice__text-inner"><div>%s <a href="%s" class="ec-link">%s</a></div> </div></div></div></div></div>' );
573
- });
574
- }
575
- });
576
- </script>
577
- HTML;
578
- $demo_notice = sprintf(
579
  $demo_notice,
580
  __( 'This is a demo store. Create your store to see your store products here.', 'ecwid-shopping-cart' ),
581
  admin_url( 'admin.php?page=ec-store' ),
582
  __( 'Set up your store', 'ecwid-shopping-cart' )
583
  );
584
-
585
  $content .= $demo_notice;
586
- }
587
 
588
  return $content;
589
  }
590
 
591
- static public function delete_page_from_nav_menus() {
592
  $page_id = get_option( self::OPTION_LAST_STORE_PAGE_ID );
593
 
594
- if( empty( $page_id ) || intval($page_id) <= 0 ) {
595
  return false;
596
  }
597
 
598
- $args = array(
599
- 'post_type' => 'nav_menu_item'
600
  );
601
  $menu_items = get_posts( $args );
602
 
603
- if( count($menu_items) ) {
604
- foreach ($menu_items as $item) {
605
- if( $page_id == get_post_meta( $item->ID, '_menu_item_object_id', true ) ) {
606
  wp_delete_post( $item->ID, true );
607
  }
608
  }
@@ -614,7 +615,7 @@ add_action( 'init', array( 'Ecwid_Store_Page', 'flush_rewrites' ) );
614
  add_action( 'save_post', array( 'Ecwid_Store_Page', 'on_save_post' ) );
615
  add_action( 'wp_ajax_' . Ecwid_Store_Page::WARMUP_ACTION, array( 'Ecwid_Store_Page', 'warmup_store' ) );
616
  add_action( 'update_option_page_on_front', array( 'Ecwid_Store_Page', 'schedule_flush_rewrites' ) );
617
- add_action( 'display_post_states', array( 'Ecwid_Store_Page', 'display_post_states'), 10, 2 );
618
 
619
  add_action( 'wp_enqueue_scripts', array( 'Ecwid_Store_Page', 'enqueue_original_page_title' ) );
620
  add_filter( 'the_title', array( 'Ecwid_Store_Page', 'the_title' ), 10, 2 );
2
 
3
  class Ecwid_Store_Page {
4
 
5
+ const OPTION_STORE_PAGES = 'ecwid_store_pages';
6
  const OPTION_MAIN_STORE_PAGE_ID = 'ecwid_store_page_id';
7
  const OPTION_LAST_STORE_PAGE_ID = 'ecwid_last_store_page_id';
8
+ const OPTION_FLUSH_REWRITES = 'ecwid_flush_rewrites';
9
+ const OPTION_REPLACE_TITLE = 'ecwid_replace_title';
10
+ const WARMUP_ACTION = 'ecwid_warmup_store';
11
+
12
  const META_STORE_DATA = 'ecwid_store';
13
 
14
  protected static $_store_pages = false;
15
 
16
+ public static function get_product_url( $id ) {
 
17
  $product = Ecwid_Product::get_by_id( $id );
18
+
19
  $url = $product->link;
20
+
21
  if ( $url ) {
22
  return $url;
23
  }
26
  }
27
 
28
  public static function get_product_url_from_api( $id ) {
29
+
30
  if ( Ecwid_Api_V3::is_available() ) {
31
 
32
  $api = new Ecwid_Api_V3();
46
  return self::get_store_url() . '#!/p/' . $id;
47
  }
48
 
49
+ public static function get_category_url( $id ) {
 
50
  $category = Ecwid_Category::get_by_id( $id );
51
 
52
  $url = $category->link;
53
+
54
  if ( $url ) {
55
  return $url;
56
  }
57
+
 
58
  if ( $id == 0 ) {
59
  return self::get_store_url();
60
  }
74
  return self::get_store_url() . '#!/c/' . $id;
75
  }
76
 
77
+ public static function get_menu_item_url( $menu_item ) {
 
78
  $suffix = '';
79
  if ( Ecwid_Seo_Links::is_enabled() ) {
80
  $suffix = $menu_item['ecwid-page'];
87
  return self::get_store_url() . $suffix;
88
  }
89
 
90
+ public static function get_cart_url() {
 
91
  if ( Ecwid_Seo_Links::is_enabled() ) {
92
  return untrailingslashit( self::get_store_url() ) . '/cart';
93
  } else {
95
  }
96
  }
97
 
98
+ public static function get_store_url() {
 
99
  static $link = null;
100
 
101
  if ( is_null( $link ) ) {
102
  $id = self::get_current_store_page_id();
103
+
104
+ if ( ! $id ) {
105
  return get_bloginfo( 'url' );
106
  }
107
+
108
  $link = get_permalink( $id );
109
  }
110
+
111
  return $link;
112
  }
113
 
115
  $existing = self::get_store_page_params();
116
 
117
  $data = array_merge( $existing, $data );
118
+
119
  EcwidPlatform::cache_set( self::_get_store_page_data_key(), $data );
120
  }
121
 
122
  public static function get_store_page_params( $page_id = 0 ) {
123
  $params = EcwidPlatform::cache_get( self::_get_store_page_data_key( $page_id ), array() );
124
+
125
+ if ( ! empty( $params ) ) {
126
+ return $params;
127
+ }
128
 
129
  return array();
130
  }
131
 
132
+ protected static function _get_store_page_data_key( $page_id = 0 ) {
 
133
  $post = get_post( $page_id );
134
+
135
+ if ( ! $post ) {
136
+ return;
137
+ }
138
+
139
  return get_ecwid_store_id() . '_' . $post->ID . '_' . $post->post_modified_gmt;
140
 
141
  }
142
+
143
  public static function get_page_base_url( $page = 0 ) {
144
  return urldecode( get_page_uri( $page ) );
145
+ }
146
+
147
+ public static function get_current_store_page_id() {
 
148
  static $page_id = null;
149
 
150
  if ( is_null( $page_id ) ) {
153
  $id = get_option( self::OPTION_MAIN_STORE_PAGE_ID );
154
  if ( $id ) {
155
 
156
+ $post = get_post( $id );
157
  $changed = false;
158
+
159
  while ( is_null( $post ) ) {
160
 
161
  $changed = true;
162
 
163
  $pages = self::get_store_pages_array();
164
+ $ind = array_search( $id, $pages );
165
 
166
  if ( $ind !== false ) {
167
+ unset( $pages[ $ind ] );
168
+ $pages = self::_set_store_pages( $pages );
169
  }
170
 
171
  if ( count( $pages ) == 0 ) {
172
  return false;
173
  }
174
 
175
+ $id = $pages[0];
176
+ $post = get_post( $id );
177
  }
178
  $status = get_post_status( $id );
179
 
180
+ if ( in_array( $status, self::_get_allowed_post_statuses() ) ) {
181
  $page_id = $id;
182
  if ( $changed ) {
183
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, $id );
184
  }
185
  }
186
+ }//end if
187
+ }//end if
188
 
189
  return $page_id;
190
  }
191
+
192
  public static function is_store_page( $page_id = 0 ) {
193
 
194
+ if ( ! $page_id ) {
195
  $page_id = get_the_ID();
196
  }
197
 
202
 
203
  public static function is_store_page_with_default_category() {
204
 
205
+ if ( ! self::is_store_page() ) {
206
  return false;
207
  }
208
 
216
  }
217
 
218
  public static function is_store_home_page() {
219
+ if ( ! self::is_store_page() ) {
220
  return false;
221
  }
222
+
223
  $html_catalog_params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
224
+ $is_home_page = empty( $html_catalog_params );
225
 
226
  return $is_home_page;
227
  }
233
  return;
234
  }
235
 
236
+ if ( wp_is_post_revision( $page_id ) ) {
237
  return;
238
  }
239
 
240
  $pages[] = $page_id;
241
 
242
+ if ( count( $pages ) == 1 || ! get_option( self::OPTION_MAIN_STORE_PAGE_ID ) ) {
243
  self::update_main_store_page_id( $page_id );
244
  }
245
 
246
  self::_set_store_pages( $pages );
247
  self::schedule_flush_rewrites();
248
  }
249
+
250
  public static function reset_store_page( $page_id ) {
251
 
252
  $pages = self::get_store_pages_array();
256
  return;
257
  }
258
 
259
+ unset( $pages[ $index ] );
260
  ecwid_reset_categories_cache();
261
+
262
  $pages = self::_set_store_pages( $pages );
263
 
264
  if ( $page_id == get_option( self::OPTION_MAIN_STORE_PAGE_ID ) ) {
265
+
266
  if ( isset( $pages[0] ) ) {
267
+
268
  $new_page = $pages[0];
269
  // we prefer pages, not posts
270
+ foreach ( $pages as $page ) {
271
+ if ( get_post( $page ) && get_post( $page )->post_type == 'page' ) {
272
  $new_page = $page;
273
  }
274
  }
275
+
276
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, $new_page );
277
  } else {
278
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, '' );
287
  }
288
 
289
  $pages = get_option( self::OPTION_STORE_PAGES );
290
+ if ( ! $pages || ! is_string( $pages ) ) {
291
  $pages = '';
292
  }
293
 
294
+ self::$_store_pages = explode( ',', $pages );
295
  self::$_store_pages[] = get_option( self::OPTION_MAIN_STORE_PAGE_ID );
296
+ self::$_store_pages = array_values(
297
  array_filter(
298
  array_unique(
299
+ self::$_store_pages
300
  )
301
  )
302
  );
303
 
 
304
  return self::$_store_pages;
305
  }
306
 
307
+ public static function get_store_pages_array_for_selector() {
 
308
  $pages = self::get_store_pages_array();
309
  foreach ( $pages as $ind => $page ) {
310
+
311
+ $post = get_post( $page );
312
 
313
  if ( $page != self::get_current_store_page_id() && isset( $post ) && $post->post_type != 'page' ) {
314
+ unset( $pages[ $ind ] );
315
  }
316
  }
317
+
318
  return $pages;
319
  }
320
+
321
  public static function schedule_flush_rewrites() {
322
  update_option( self::OPTION_FLUSH_REWRITES, 1 );
323
  }
324
 
325
  public static function flush_rewrites() {
326
+ if ( get_option( self::OPTION_FLUSH_REWRITES ) == 1 ) {
327
  flush_rewrite_rules();
328
  }
329
 
348
  public static function post_content_has_productbrowser( $post_id = null ) {
349
 
350
  if ( is_null( $post_id ) ) {
351
+ if ( is_admin() ) {
352
+ return false;
353
+ }
354
  $post_id = get_the_ID();
355
  }
356
 
357
  $result = false;
358
+
359
+ $post = get_post( $post_id );
360
  if ( $post ) {
361
  $post_content = get_post( $post_id )->post_content;
362
 
368
  }
369
 
370
  public static function update_main_store_page_id( $new_id ) {
371
+
372
  if ( self::post_content_has_productbrowser( $new_id ) ) {
373
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, $new_id );
374
  }
375
+ }
376
+
377
  public static function on_save_post( $post_id ) {
378
 
379
+ if ( wp_is_post_revision( $post_id ) ) {
380
  return;
381
+ }
382
 
383
+ $has_pb = self::post_content_has_productbrowser( $post_id );
384
  $is_allowable_post_type = in_array( get_post_type( $post_id ), array( 'page', 'post' ) );
385
 
386
  if ( self::is_store_page( $post_id ) ) {
387
+ $is_disabled = ! in_array( get_post_status( $post_id ), self::_get_allowed_post_statuses() );
388
 
389
+ if ( $is_disabled || ! $has_pb ) {
390
  self::reset_store_page( $post_id );
391
  }
392
  }
393
+
394
  if ( $is_allowable_post_type && $has_pb ) {
395
  ecwid_reset_categories_cache();
396
  }
397
 
398
  if ( $is_allowable_post_type && $has_pb && in_array( get_post_status( $post_id ), self::_get_allowed_post_statuses() ) ) {
399
  self::add_store_page( $post_id );
400
+ } elseif ( get_option( self::OPTION_MAIN_STORE_PAGE_ID ) == $post_id ) {
401
  update_option( self::OPTION_LAST_STORE_PAGE_ID, $post_id );
402
  update_option( self::OPTION_MAIN_STORE_PAGE_ID, '' );
403
  }
404
  }
405
 
406
+ protected static function _get_allowed_post_statuses() {
407
+ return array( 'publish', 'private', 'draft' );
 
408
  }
409
 
410
+ public static function warmup_store() {
 
411
  $store_page = get_post( self::get_current_store_page_id() );
412
+
413
+ if ( ! $store_page ) {
414
  return;
415
  }
416
+
417
  $shortcodes = array();
418
  foreach ( Ecwid_Shortcode_Base::get_store_shortcode_names() as $shortcode_name ) {
419
  $shortcodes[] = ecwid_find_shortcodes( $store_page->post_content, $shortcode_name );
420
  }
421
+
422
+ if ( count( $shortcodes ) === 0 ) {
423
  return;
424
  }
425
+
426
  $shortcode_data = $shortcodes[0];
427
+
428
  $category = 0;
429
+
430
  if ( isset( $shortcode_data[3] ) ) {
431
+ $attributes = shortcode_parse_atts( $shortcode_data[3] );
432
 
433
+ if ( ! $attributes ) {
434
  return;
435
  }
436
+
437
  $category = $attributes['default_category_id'];
438
  }
439
+
440
  $page_url = get_permalink( $store_page );
441
 
442
  include_once ECWID_PLUGIN_DIR . 'lib/ecwid_catalog.php';
443
 
444
+ $catalog = new EcwidCatalog( get_ecwid_store_id(), $page_url );
445
+
446
+ $catalog->warmup_store_page( intval( $category ) );
447
+ }
448
+
449
+ public static $main_page_title = '';
450
+ // If you figure out a better place to put this the_title functionality, go ahead, move it =)
451
+
452
+ public static function enqueue_original_page_title() {
453
+ if ( ! get_option( self::OPTION_REPLACE_TITLE, false ) || ! self::is_store_page() ) {
 
454
  return;
455
  }
456
+
457
  $script = 'dynamic-title';
458
  EcwidPlatform::enqueue_script( $script, array( 'jquery' ), true );
459
+ wp_localize_script(
460
+ EcwidPlatform::make_handle( $script ),
461
+ 'ecwidOriginalTitle',
462
+ array(
463
+ 'initialTitle' => get_the_title(),
464
+ 'mainPageTitle' => self::$main_page_title,
465
+ )
466
+ );
467
+ }
468
+
469
+ public static function the_title( $title, $post_id = 0 ) {
470
+ if ( ! self::is_store_page( $post_id ) || ! get_option( self::OPTION_REPLACE_TITLE, false ) ) {
471
+ return $title;
472
+ }
473
+
474
+ if ( ecwid_is_demo_store() ) {
475
  $title .= ' &mdash; Demo';
476
  }
477
 
478
  self::$main_page_title = $title;
479
+
480
  return $title;
481
  }
482
+
483
+ public static function display_post_states( $states, $post ) {
 
484
  if ( in_array( $post->ID, self::get_store_pages_array() ) ) {
485
+ /* translators: %s: brand */
486
+ $states[] = sprintf( __( '%s Store Page', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() );
487
  }
488
+
489
  return $states;
490
  }
491
 
492
 
493
+ public static function set_store_url() {
 
494
  $store_page_id = self::get_current_store_page_id();
495
+ if ( ! $store_page_id ) {
496
  return;
497
  }
498
 
499
  $store_url = self::get_store_url();
500
 
501
+ $api = new Ecwid_Api_V3();
 
 
502
  $profile = $api->get_store_profile();
503
 
504
+ if ( empty( $profile ) ) {
505
  return;
506
  }
507
 
508
  if ( ecwid_is_demo_store() ) {
509
+ return;
510
  }
511
 
512
+ //phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
513
+ if ( $profile->generalInfo->storeUrl === $store_url ) {
514
  return;
515
  }
516
 
517
+ $is_empty = in_array( $profile->generalInfo->storeUrl, array( 'http://', 'https://' ), true );
518
+ $is_same_domain = wp_parse_url( $profile->generalInfo->storeUrl, PHP_URL_HOST ) === wp_parse_url( $store_url, PHP_URL_HOST );
519
+
520
  $is_custom_domain = isset( $profile->generalInfo->starterSite->customDomain );
521
+ $is_generated_url = ( $profile->generalInfo->storeUrl === $profile->generalInfo->starterSite->generatedUrl ) && ! $is_custom_domain;
522
 
523
+ $is_dev_to_prod = self::is_localhost( $profile->generalInfo->storeUrl ) && ! self::is_localhost( $store_url );
524
+ if ( $is_dev_to_prod ) {
525
  $is_same_domain = true;
526
  }
527
+ //phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
528
 
529
+ if ( ! $is_empty && ! $is_generated_url && ! $is_same_domain ) {
530
+ return;
531
  }
532
 
533
  $params = array(
534
  'generalInfo' => array(
535
+ 'storeUrl' => $store_url,
536
+ 'websitePlatform' => 'wordpress',
537
+ ),
538
  );
539
 
540
  $result = $api->update_store_profile( $params );
544
  }
545
  }
546
 
547
+ public static function is_localhost( $url ) {
548
 
549
+ $hostname = wp_parse_url( $url, PHP_URL_HOST );
550
+ $ip = gethostbyname( $hostname );
551
 
552
+ if ( $ip ) {
553
+ return in_array( $ip, array( '127.0.0.1', '::1' ), true );
554
  }
555
 
556
  return false;
557
  }
558
 
559
+ public static function show_notice_for_demo( $content ) {
560
 
561
+ if ( ecwid_is_demo_store() && current_user_can( 'manage_options' ) && self::is_store_page() ) {
562
+ ob_start();
563
+ ?>
564
+ <script data-cfasync="false" type="text/javascript">
565
+ jQuery(document).ready(function(){
566
+ if( typeof Ecwid == 'object' && typeof Ecwid.OnPageLoaded == 'object' ) {
567
+ Ecwid.OnPageLoaded.add(function(page){
568
+ if( jQuery('.ec-notice.ec-demo-notice').length > 0 ) return;
569
 
570
+ jQuery('.ec-store__content-wrapper').eq(0).append( '<div class="ec-notice ec-demo-notice"><div class="ec-notice__wrap"><div class="ec-notice__message"><div class="ec-notice__text"><div class="ec-notice__text-inner"><div>%s <a href="%s" class="ec-link">%s</a></div> </div></div></div></div></div>' );
571
+ });
572
+ }
573
+ });
574
+ </script>
575
+ <?php
576
 
577
+ $demo_notice = ob_get_clean();
578
+
579
+ $demo_notice = sprintf(
 
 
 
 
580
  $demo_notice,
581
  __( 'This is a demo store. Create your store to see your store products here.', 'ecwid-shopping-cart' ),
582
  admin_url( 'admin.php?page=ec-store' ),
583
  __( 'Set up your store', 'ecwid-shopping-cart' )
584
  );
585
+
586
  $content .= $demo_notice;
587
+ }//end if
588
 
589
  return $content;
590
  }
591
 
592
+ public static function delete_page_from_nav_menus() {
593
  $page_id = get_option( self::OPTION_LAST_STORE_PAGE_ID );
594
 
595
+ if ( empty( $page_id ) || intval( $page_id ) <= 0 ) {
596
  return false;
597
  }
598
 
599
+ $args = array(
600
+ 'post_type' => 'nav_menu_item',
601
  );
602
  $menu_items = get_posts( $args );
603
 
604
+ if ( count( $menu_items ) ) {
605
+ foreach ( $menu_items as $item ) {
606
+ if ( $page_id == get_post_meta( $item->ID, '_menu_item_object_id', true ) ) {
607
  wp_delete_post( $item->ID, true );
608
  }
609
  }
615
  add_action( 'save_post', array( 'Ecwid_Store_Page', 'on_save_post' ) );
616
  add_action( 'wp_ajax_' . Ecwid_Store_Page::WARMUP_ACTION, array( 'Ecwid_Store_Page', 'warmup_store' ) );
617
  add_action( 'update_option_page_on_front', array( 'Ecwid_Store_Page', 'schedule_flush_rewrites' ) );
618
+ add_action( 'display_post_states', array( 'Ecwid_Store_Page', 'display_post_states' ), 10, 2 );
619
 
620
  add_action( 'wp_enqueue_scripts', array( 'Ecwid_Store_Page', 'enqueue_original_page_title' ) );
621
  add_filter( 'the_title', array( 'Ecwid_Store_Page', 'the_title' ), 10, 2 );
includes/class-ecwid-wp-dashboard-feed.php CHANGED
@@ -1,102 +1,105 @@
1
  <?php
2
 
3
  class Ecwid_WP_Dashboard_Feed {
4
- const CACHE_POSTS = 'wp-dashboard-blog-posts';
5
- const ACTION_AJAX_SAVE = 'ecwid-save-posts';
6
  const PARAM_LAST_ECWID_ADMIN_PREFETCH_TIME = 'last-admin-prefetch-time';
7
-
8
  public function __construct() {
9
  if ( Ecwid_Config::is_wl() ) {
10
  return;
11
  }
12
-
13
  add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) );
14
-
15
  add_action( 'wp_ajax_' . self::ACTION_AJAX_SAVE, array( $this, 'ajax_save_posts' ) );
16
  }
17
-
18
  public function dashboard_setup() {
19
 
20
- if( !current_user_can( 'administrator' ) && !current_user_can( 'editor' )) {
21
  return;
22
  }
23
 
24
- $url = 'https://www.ecwid.com/wp-json/wp/v2/posts?per_page=3&categories=1';
25
- $media_url = 'https://www.ecwid.com/wp-json/wp/v2/media/';
26
  $images_cdn = 'https://web-cdn.ecwid.com/wp-content/uploads/';
27
-
28
  $lang = ecwid_get_current_user_locale();
29
- if ( $lang == 'ru_RU' ) {
30
- $url = 'https://www.ecwid.ru/wp-json/wp/v2/posts?per_page=3&categories=1';
31
- $media_url = 'https://www.ecwid.ru/wp-json/wp/v2/media/';
32
  $images_cdn = 'https://web-cdn.ecwid.com/wp-content/uploads/ru/';
33
  }
34
-
35
- wp_enqueue_style( 'ecwid-dashboard-blog', ECWID_PLUGIN_URL . '/css/dashboard-blog.css', array( ), get_option('ecwid_plugin_version') );
36
-
37
- wp_enqueue_script( 'ecwid-dashboard-blog', ECWID_PLUGIN_URL . '/js/dashboard-blog.js', array( 'jquery' ), get_option('ecwid_plugin_version') );
38
- wp_localize_script( 'ecwid-dashboard-blog', 'ecwidDashboardBlog', array(
39
- 'posts' => EcwidPlatform::cache_get( $this->_get_cache_name() ),
40
- 'url' => $url,
41
- 'mediaUrl' => $media_url,
42
- 'imagesCDN' => $images_cdn,
43
- 'saveAction' => self::ACTION_AJAX_SAVE
44
- ) );
45
-
46
- wp_add_dashboard_widget(
47
- 'ecwid_blog_feed',
48
- sprintf( __( '%s Blog', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
49
- array( $this, 'display' )
 
 
 
 
 
50
  );
51
  }
52
-
53
- public function ajax_save_posts()
54
- {
55
- if ( !current_user_can( Ecwid_Admin::get_capability() ) ) {
56
  die();
57
  }
58
 
59
  check_ajax_referer( 'ec_admin', '_ajax_nonce' );
60
 
61
- if( !isset($_POST['posts']) ) {
62
  die();
63
  }
64
-
65
  $posts = map_deep( wp_unslash( $_POST['posts'] ), 'sanitize_text_field' );
66
 
67
- EcwidPlatform::cache_set( $this->_get_cache_name(), $posts, 12 * HOUR_IN_SECONDS );
68
 
69
  header( 'HTTP/1.0 200 OK' );
70
  die();
71
  }
72
-
73
- protected function _get_cache_name()
74
- {
75
- $name = self::CACHE_POSTS;
76
  $name .= '-' . ecwid_get_current_user_locale();
77
-
78
  return $name;
79
  }
80
-
81
-
82
  public function display() {
83
  require_once ECWID_PLUGIN_DIR . '/templates/dashboard-blog-posts.tpl.php';
84
-
85
  if ( EcwidPlatform::get( self::PARAM_LAST_ECWID_ADMIN_PREFETCH_TIME ) > time() + HOUR_IN_SECONDS * 12 ) {
86
  $dashboard_url = ecwid_get_iframe_src( time(), 'dashboard' );
87
- echo <<<HTML
88
- <div style="display:none">
89
- <iframe id="ecwid-prefetch" src=""></iframe>
90
- <script type="text/javascript">
91
- jQuery(document).ready(function() {
92
- jQuery('#ecwid-prefetch').attr('src', '$dashboard_url');
93
- });
94
- </script>
95
- </div>
96
- HTML;
97
  EcwidPlatform::set( self::PARAM_LAST_ECWID_ADMIN_PREFETCH_TIME, time() );
98
  }
99
  }
100
  }
101
 
102
- $ecwid_wp_dashboard_feed = new Ecwid_WP_Dashboard_Feed();
1
  <?php
2
 
3
  class Ecwid_WP_Dashboard_Feed {
4
+ const CACHE_POSTS = 'wp-dashboard-blog-posts';
5
+ const ACTION_AJAX_SAVE = 'ecwid-save-posts';
6
  const PARAM_LAST_ECWID_ADMIN_PREFETCH_TIME = 'last-admin-prefetch-time';
7
+
8
  public function __construct() {
9
  if ( Ecwid_Config::is_wl() ) {
10
  return;
11
  }
12
+
13
  add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) );
14
+
15
  add_action( 'wp_ajax_' . self::ACTION_AJAX_SAVE, array( $this, 'ajax_save_posts' ) );
16
  }
17
+
18
  public function dashboard_setup() {
19
 
20
+ if ( ! current_user_can( 'administrator' ) && ! current_user_can( 'editor' ) ) {
21
  return;
22
  }
23
 
24
+ $url = 'https://www.ecwid.com/wp-json/wp/v2/posts?per_page=3&categories=1';
25
+ $media_url = 'https://www.ecwid.com/wp-json/wp/v2/media/';
26
  $images_cdn = 'https://web-cdn.ecwid.com/wp-content/uploads/';
27
+
28
  $lang = ecwid_get_current_user_locale();
29
+ if ( $lang === 'ru_RU' ) {
30
+ $url = 'https://www.ecwid.ru/wp-json/wp/v2/posts?per_page=3&categories=1';
31
+ $media_url = 'https://www.ecwid.ru/wp-json/wp/v2/media/';
32
  $images_cdn = 'https://web-cdn.ecwid.com/wp-content/uploads/ru/';
33
  }
34
+
35
+ wp_enqueue_style( 'ecwid-dashboard-blog', ECWID_PLUGIN_URL . '/css/dashboard-blog.css', array(), get_option( 'ecwid_plugin_version' ) );
36
+
37
+ wp_enqueue_script( 'ecwid-dashboard-blog', ECWID_PLUGIN_URL . '/js/dashboard-blog.js', array( 'jquery' ), get_option( 'ecwid_plugin_version' ) );
38
+ wp_localize_script(
39
+ 'ecwid-dashboard-blog',
40
+ 'ecwidDashboardBlog',
41
+ array(
42
+ 'posts' => EcwidPlatform::cache_get( $this->get_cache_name() ),
43
+ 'url' => $url,
44
+ 'mediaUrl' => $media_url,
45
+ 'imagesCDN' => $images_cdn,
46
+ 'saveAction' => self::ACTION_AJAX_SAVE,
47
+ )
48
+ );
49
+
50
+ wp_add_dashboard_widget(
51
+ 'ecwid_blog_feed',
52
+ /* translators: %s: brand */
53
+ sprintf( __( '%s Blog', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
54
+ array( $this, 'display' )
55
  );
56
  }
57
+
58
+ public function ajax_save_posts() {
59
+ if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
 
60
  die();
61
  }
62
 
63
  check_ajax_referer( 'ec_admin', '_ajax_nonce' );
64
 
65
+ if ( ! isset( $_POST['posts'] ) ) {
66
  die();
67
  }
68
+
69
  $posts = map_deep( wp_unslash( $_POST['posts'] ), 'sanitize_text_field' );
70
 
71
+ EcwidPlatform::cache_set( $this->get_cache_name(), $posts, 12 * HOUR_IN_SECONDS );
72
 
73
  header( 'HTTP/1.0 200 OK' );
74
  die();
75
  }
76
+
77
+ protected function get_cache_name() {
78
+ $name = self::CACHE_POSTS;
 
79
  $name .= '-' . ecwid_get_current_user_locale();
80
+
81
  return $name;
82
  }
83
+
84
+
85
  public function display() {
86
  require_once ECWID_PLUGIN_DIR . '/templates/dashboard-blog-posts.tpl.php';
87
+
88
  if ( EcwidPlatform::get( self::PARAM_LAST_ECWID_ADMIN_PREFETCH_TIME ) > time() + HOUR_IN_SECONDS * 12 ) {
89
  $dashboard_url = ecwid_get_iframe_src( time(), 'dashboard' );
90
+ ?>
91
+ <div style="display:none">
92
+ <iframe id="ecwid-prefetch" src=""></iframe>
93
+ <script type="text/javascript">
94
+ jQuery(document).ready(function() {
95
+ jQuery('#ecwid-prefetch').attr('src', '<?php esc_url( $dashboard_url ); ?>');
96
+ });
97
+ </script>
98
+ </div>
99
+ <?php
100
  EcwidPlatform::set( self::PARAM_LAST_ECWID_ADMIN_PREFETCH_TIME, time() );
101
  }
102
  }
103
  }
104
 
105
+ $ecwid_wp_dashboard_feed = new Ecwid_WP_Dashboard_Feed();
includes/gutenberg/class-ecwid-gutenberg-block-cart-page.php CHANGED
@@ -29,16 +29,20 @@ class Ecwid_Gutenberg_Block_Cart_Page extends Ecwid_Gutenberg_Block_Store {
29
 
30
  $result = parent::render_callback( $params );
31
 
32
- $result .= '
33
- <script>
34
- Ecwid.OnAPILoaded.add(function() {
35
- Ecwid.OnPageLoad.add(function(page) {
36
- if ("CATEGORY" == page.type && 0 == page.categoryId && !page.hasPrevious) {
37
- Ecwid.openPage("cart");
38
- }
39
- })
40
- });
41
- </script>';
 
 
 
 
42
 
43
  return $result;
44
  }
29
 
30
  $result = parent::render_callback( $params );
31
 
32
+ ob_start();
33
+ ?>
34
+ <script>
35
+ Ecwid.OnAPILoaded.add(function() {
36
+ Ecwid.OnPageLoad.add(function(page) {
37
+ if ("CATEGORY" == page.type && 0 == page.categoryId && !page.hasPrevious) {
38
+ Ecwid.openPage("cart");
39
+ }
40
+ })
41
+ });
42
+ </script>
43
+ <?php
44
+
45
+ $result .= ob_get_clean();
46
 
47
  return $result;
48
  }
includes/gutenberg/class-ecwid-gutenberg-block-filters-page.php CHANGED
@@ -48,15 +48,19 @@ class Ecwid_Gutenberg_Block_Filters_Page extends Ecwid_Gutenberg_Block_Store {
48
  }
49
 
50
  public static function get_script_for_open_filters_page() {
51
- return '<script>
52
- Ecwid.OnAPILoaded.add(function() {
53
- Ecwid.OnPageLoad.add(function(page) {
54
- if ("CATEGORY" == page.type && 0 == page.categoryId && !page.hasPrevious) {
55
- Ecwid.openPage("search");
56
- }
57
- })
58
- });
59
- </script>';
 
 
 
 
60
  }
61
 
62
  }
48
  }
49
 
50
  public static function get_script_for_open_filters_page() {
51
+ ob_start();
52
+ ?>
53
+ <script>
54
+ Ecwid.OnAPILoaded.add(function() {
55
+ Ecwid.OnPageLoad.add(function(page) {
56
+ if ("CATEGORY" == page.type && 0 == page.categoryId && !page.hasPrevious) {
57
+ Ecwid.openPage("search");
58
+ }
59
+ })
60
+ });
61
+ </script>
62
+ <?php
63
+ return ob_get_clean();
64
  }
65
 
66
  }
includes/importer/class-ecwid-import-page.php CHANGED
@@ -151,7 +151,7 @@ class Ecwid_Import_Page {
151
  }
152
 
153
  protected function _get_woo_url() {
154
- return 'admin.php?page=' . self::PAGE_SLUG_WOO;
155
  }
156
 
157
  protected function _need_to_show_woo() {
@@ -159,12 +159,12 @@ class Ecwid_Import_Page {
159
  }
160
 
161
  public function do_page() {
162
- require_once ECWID_IMPORTER_TEMPLATES_DIR . '/landing.tpl.php';
163
  }
164
 
165
  public function do_woo_page() {
166
- $import_data = Ecwid_Import::gather_import_data();
167
- echo Ecwid_Admin_UI_Framework::print_fix_js();
168
 
169
  require_once ECWID_IMPORTER_TEMPLATES_DIR . '/woo-main.tpl.php';
170
  }
151
  }
152
 
153
  protected function _get_woo_url() {
154
+ return 'admin.php?page=' . self::PAGE_SLUG_WOO;
155
  }
156
 
157
  protected function _need_to_show_woo() {
159
  }
160
 
161
  public function do_page() {
162
+ require_once ECWID_IMPORTER_TEMPLATES_DIR . '/landing.tpl.php';
163
  }
164
 
165
  public function do_woo_page() {
166
+ $import_data = Ecwid_Import::gather_import_data();
167
+ Ecwid_Admin_UI_Framework::print_fix_js();
168
 
169
  require_once ECWID_IMPORTER_TEMPLATES_DIR . '/woo-main.tpl.php';
170
  }
includes/integrations/class-ecwid-integration-aiosp.php CHANGED
@@ -100,31 +100,27 @@ class Ecwid_Integration_All_In_One_SEO_Pack {
100
  }
101
 
102
  // A callback for the streaming sitemap builder
103
- // phpcs:disable
104
  public function get_sitemap_items_callback( $url, $priority, $frequency, $obj ) {
105
- $url = htmlspecialchars( $url );
106
- $imageCode = '';
107
- $image = @$obj->originalImageUrl;
108
  if ( $image ) {
109
- $image = htmlspecialchars( $image );
110
- $title = htmlspecialchars( $obj->name );
111
- $imageCode = <<<XML
112
  <image:image>
113
  <image:title>$title</image:title>
114
  <image:loc>$image</image:loc>
115
- </image:image>
116
- XML;
117
  }
118
 
119
- $this->sitemap .= <<<XML
120
- <url>
121
- <loc>$url</loc>
122
- <changefreq>$frequency</changefreq>
123
- <priority>$priority</priority> $imageCode
124
- </url>
125
- XML;
126
  }
127
- // phpcs:enable
128
 
129
  public function aiosp_hook_sitemap_prio_item_filter( $pr_info, $post, $args ) {
130
  $post_type = (string) $post->post_type;
100
  }
101
 
102
  // A callback for the streaming sitemap builder
 
103
  public function get_sitemap_items_callback( $url, $priority, $frequency, $obj ) {
104
+ $url = htmlspecialchars( $url );
105
+ $image_code = '';
106
+ $image = @$obj->originalImageUrl; //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
107
  if ( $image ) {
108
+ $image = htmlspecialchars( $image );
109
+ $title = htmlspecialchars( $obj->name );
110
+ $image_code = "
111
  <image:image>
112
  <image:title>$title</image:title>
113
  <image:loc>$image</image:loc>
114
+ </image:image>";
 
115
  }
116
 
117
+ $this->sitemap .= "
118
+ <url>
119
+ <loc>$url</loc>
120
+ <changefreq>$frequency</changefreq>
121
+ <priority>$priority</priority> $image_code
122
+ </url>";
 
123
  }
 
124
 
125
  public function aiosp_hook_sitemap_prio_item_filter( $pr_info, $post, $args ) {
126
  $post_type = (string) $post->post_type;
includes/integrations/class-ecwid-integration-divibuilder.php CHANGED
@@ -22,6 +22,7 @@ function ecwid_create_divi_module() {
22
  if ( class_exists( 'ET_Builder_Module' ) && ! class_exists( 'ET_Builder_Module_Ecwid' ) ) {
23
  class ET_Builder_Module_Ecwid extends ET_Builder_Module {
24
  public function init() {
 
25
  $this->name = sprintf( __( '%s Store', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() );
26
  $this->slug = 'et_pb_ecwid';
27
  $this->use_raw_content = true;
22
  if ( class_exists( 'ET_Builder_Module' ) && ! class_exists( 'ET_Builder_Module_Ecwid' ) ) {
23
  class ET_Builder_Module_Ecwid extends ET_Builder_Module {
24
  public function init() {
25
+ // translators: %s: brand
26
  $this->name = sprintf( __( '%s Store', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() );
27
  $this->slug = 'et_pb_ecwid';
28
  $this->use_raw_content = true;
includes/integrations/class-ecwid-integration-elementor.php CHANGED
@@ -3,36 +3,37 @@
3
  require_once ECWID_PLUGIN_DIR . '/includes/class-ecwid-stub-renderer.php';
4
 
5
  class Ecwid_Integration_Elementor {
6
-
7
  const EC_WIDGETS_PATH = '/includes/integrations/elementor';
8
 
 
 
9
  public function __construct() {
10
 
11
  $is_needed_php_version = version_compare( phpversion(), '5.6', '>=' );
12
- $is_needed_wp_version = version_compare( get_bloginfo('version'), '5.4.1', '>=' );
13
 
14
  if ( $is_needed_php_version && $is_needed_wp_version ) {
15
-
16
  add_action( 'elementor/elements/categories_registered', array( $this, 'add_custom_widget_categories' ) );
17
-
18
- add_action( 'elementor/widgets/widgets_registered', array( $this, 'init_custom_widgets'), 10, 1 );
19
  }
20
 
21
- if( $this->_should_apply() ) {
22
- add_action( 'widgets_init', array( $this, 'init_sidebar_widgets') );
23
  }
24
 
25
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
 
26
  }
27
 
28
  protected function _should_apply() {
29
  global $pagenow;
30
- return !(is_admin() && $pagenow == 'widgets.php');
31
  }
32
 
33
  public function init_sidebar_widgets() {
34
- if( class_exists( 'Ecwid_Widget_Product_Browser' ) ) {
35
- register_widget('Ecwid_Widget_Product_Browser');
36
  }
37
  }
38
 
@@ -41,9 +42,9 @@ class Ecwid_Integration_Elementor {
41
  require_once ECWID_PLUGIN_DIR . self::EC_WIDGETS_PATH . '/class-ec-elementor-widget-buynow.php';
42
  }
43
 
44
- public function init_custom_widgets($widgets_manager) {
45
 
46
- if( !class_exists('\Elementor\Plugin') || !class_exists('\Elementor\Widget_Base') ) {
47
  return;
48
  }
49
 
@@ -59,16 +60,46 @@ class Ecwid_Integration_Elementor {
59
  'ec-store',
60
  array(
61
  'title' => sprintf(
62
- __( '%s Store', 'ecwid-shopping-cart'),
 
63
  Ecwid_Config::get_brand()
64
  ),
65
- 'icon' => 'fa fa-plug',
66
  )
67
  );
68
  }
69
 
70
  public function enqueue_scripts() {
71
- wp_enqueue_style('ec-elementor', ECWID_PLUGIN_URL . 'css/integrations/elementor.css', array(), get_option('ecwid_plugin_version'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
  }
74
 
@@ -81,22 +112,21 @@ class Ec_Integration_Elementor_Stub_Renderer extends Ecwid_Stub_Renderer {
81
 
82
  protected function _should_apply() {
83
 
84
- if( isset($_REQUEST['action']) && in_array( $_REQUEST['action'], array('elementor_ajax', 'elementor') ) ) {
85
  return true;
86
  }
87
 
88
- if( isset( $_GET['elementor-preview'] ) ) {
89
- return true;
90
  }
91
 
92
  return false;
93
  }
94
-
95
  public function enqueue_scripts() {
96
  parent::enqueue_scripts();
97
  }
98
  }
99
 
100
-
101
- $__ecwid_integration_elementor = new Ecwid_Integration_Elementor();
102
  $__ecwid_integration_elementor_stub_render = new Ec_Integration_Elementor_Stub_Renderer();
3
  require_once ECWID_PLUGIN_DIR . '/includes/class-ecwid-stub-renderer.php';
4
 
5
  class Ecwid_Integration_Elementor {
6
+
7
  const EC_WIDGETS_PATH = '/includes/integrations/elementor';
8
 
9
+ public $has_widget = false;
10
+
11
  public function __construct() {
12
 
13
  $is_needed_php_version = version_compare( phpversion(), '5.6', '>=' );
14
+ $is_needed_wp_version = version_compare( get_bloginfo( 'version' ), '5.4.1', '>=' );
15
 
16
  if ( $is_needed_php_version && $is_needed_wp_version ) {
 
17
  add_action( 'elementor/elements/categories_registered', array( $this, 'add_custom_widget_categories' ) );
18
+ add_action( 'elementor/widgets/widgets_registered', array( $this, 'init_custom_widgets' ), 10, 1 );
 
19
  }
20
 
21
+ if ( $this->_should_apply() ) {
22
+ add_action( 'widgets_init', array( $this, 'init_sidebar_widgets' ) );
23
  }
24
 
25
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
26
+ add_filter( 'ecwid_page_has_product_browser', array( $this, 'page_has_product_browser' ), 10, 2 );
27
  }
28
 
29
  protected function _should_apply() {
30
  global $pagenow;
31
+ return ! ( is_admin() && $pagenow == 'widgets.php' );
32
  }
33
 
34
  public function init_sidebar_widgets() {
35
+ if ( class_exists( 'Ecwid_Widget_Product_Browser' ) ) {
36
+ register_widget( 'Ecwid_Widget_Product_Browser' );
37
  }
38
  }
39
 
42
  require_once ECWID_PLUGIN_DIR . self::EC_WIDGETS_PATH . '/class-ec-elementor-widget-buynow.php';
43
  }
44
 
45
+ public function init_custom_widgets( $widgets_manager ) {
46
 
47
+ if ( ! class_exists( '\Elementor\Plugin' ) || ! class_exists( '\Elementor\Widget_Base' ) ) {
48
  return;
49
  }
50
 
60
  'ec-store',
61
  array(
62
  'title' => sprintf(
63
+ // translators: %s: brand
64
+ __( '%s Store', 'ecwid-shopping-cart' ),
65
  Ecwid_Config::get_brand()
66
  ),
67
+ 'icon' => 'fa fa-plug',
68
  )
69
  );
70
  }
71
 
72
  public function enqueue_scripts() {
73
+ wp_enqueue_style( 'ec-elementor', ECWID_PLUGIN_URL . 'css/integrations/elementor.css', array(), get_option( 'ecwid_plugin_version' ) );
74
+ }
75
+
76
+ public function page_has_product_browser( $result, $content ) {
77
+ if ( $result ) {
78
+ return true;
79
+ }
80
+
81
+ $meta = get_post_meta( get_the_ID(), '_elementor_data', true );
82
+
83
+ if ( ! empty( $meta ) ) {
84
+ $data = json_decode( $meta, true );
85
+
86
+ if ( is_array( $data ) ) {
87
+ $this->has_widget = false;
88
+ array_walk_recursive( $data, array( $this, 'filter_page_data' ) );
89
+ }
90
+
91
+ if ( $this->has_widget ) {
92
+ return true;
93
+ }
94
+ }
95
+
96
+ return $result;
97
+ }
98
+
99
+ public function filter_page_data( $item, $key ) {
100
+ if ( $key === 'widgetType' && $item === 'ec_store' ) {
101
+ $this->has_widget = true;
102
+ }
103
  }
104
  }
105
 
112
 
113
  protected function _should_apply() {
114
 
115
+ if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], array( 'elementor_ajax', 'elementor' ) ) ) {
116
  return true;
117
  }
118
 
119
+ if ( isset( $_GET['elementor-preview'] ) ) {
120
+ return true;
121
  }
122
 
123
  return false;
124
  }
125
+
126
  public function enqueue_scripts() {
127
  parent::enqueue_scripts();
128
  }
129
  }
130
 
131
+ $__ecwid_integration_elementor = new Ecwid_Integration_Elementor();
 
132
  $__ecwid_integration_elementor_stub_render = new Ec_Integration_Elementor_Stub_Renderer();
includes/integrations/class-ecwid-integration-gutenberg.php CHANGED
@@ -1,46 +1,53 @@
1
- <?php
2
 
3
  require_once ECWID_PLUGIN_DIR . '/includes/class-ecwid-product-browser.php';
4
 
5
  class Ecwid_Integration_Gutenberg {
6
-
7
- const STORE_BLOCK = 'ecwid/store-block';
8
  const PRODUCT_BLOCK = 'ecwid/product-block';
9
-
10
  public function __construct() {
11
 
12
- $version = get_bloginfo('version');
13
  if ( version_compare( $version, '5.0' ) < 0 ) {
14
  return;
15
  }
16
 
17
- if ( isset( $_GET['classic-editor'] ) ) return;
18
-
 
 
19
  add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
20
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
21
 
22
- add_action( "rest_insert_post", array( $this, 'on_save_post' ), 10, 3 );
23
- add_action( "rest_insert_page", array( $this, 'on_save_post' ), 10, 3 );
24
-
25
- register_block_type(self::STORE_BLOCK, array(
26
- 'editor_script' => 'ecwid-gutenberg-store',
27
- 'render_callback' => array( $this, 'render_callback' ),
28
- ));
29
-
30
- register_block_type(self::PRODUCT_BLOCK, array(
31
- 'editor_script' => 'ecwid-gutenberg-store',
32
- 'render_callback' => array( $this, 'product_render_callback' ),
33
- ));
34
-
 
 
 
 
 
 
35
  add_filter( 'block_categories', array( $this, 'block_categories' ) );
36
  }
37
 
38
- public function admin_enqueue_scripts()
39
- {
40
  wp_enqueue_script( 'gutenberg-store' );
41
  EcwidPlatform::enqueue_style( 'store-popup' );
42
  }
43
-
44
  public function block_categories( $categories ) {
45
  return array_merge(
46
  $categories,
@@ -48,31 +55,30 @@ class Ecwid_Integration_Gutenberg {
48
  array(
49
  'slug' => 'ec-store',
50
  'title' => sprintf( __( '%s', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
51
- 'icon' => '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="#555d66" d="' . $this->_get_store_icon_path() . '"/><path d="M19 13H5v-2h14v2z" /></svg>'
52
  ),
53
  )
54
  );
55
  }
56
-
57
  public function on_save_post( $post, $request, $creating ) {
58
- if (strpos( $post->post_content, '<!-- wp:' . self::STORE_BLOCK ) !== false ) {
59
  Ecwid_Store_Page::add_store_page( $post->ID );
60
  }
61
  }
62
-
63
  public function enqueue_block_editor_assets() {
64
 
65
  wp_enqueue_script( 'ecwid-gutenberg-store', ECWID_PLUGIN_URL . 'js/gutenberg/blocks.build.js', array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ) );
66
  wp_enqueue_style( 'ecwid-gutenberg-block', ECWID_PLUGIN_URL . 'css/gutenberg/blocks.editor.build.css' );
67
-
68
  $locale_data = '';
69
  if ( function_exists( 'gutenberg_get_jed_locale_data' ) ) {
70
  $locale_data = gutenberg_get_jed_locale_data( 'ecwid-shopping-cart' );
71
- } else if ( function_exists( 'wp_get_jed_locale_data' ) ) {
72
  $locale_data = wp_get_jed_locale_data( 'ecwid-shopping-cart' );
73
  }
74
-
75
-
76
  if ( $locale_data ) {
77
  wp_add_inline_script(
78
  'ecwid-gutenberg-store',
@@ -80,143 +86,155 @@ class Ecwid_Integration_Gutenberg {
80
  'before'
81
  );
82
  }
83
-
84
  $api = new Ecwid_Api_V3();
85
- wp_localize_script( 'ecwid-gutenberg-store', 'EcwidGutenbergStoreBlockParams',
 
 
86
  array(
87
- 'attributes' => $this->_get_attributes_for_editor(),
88
  'is_new_product_list' => $this->_is_new_product_list(),
89
  'is_new_details_page' => $this->_is_new_details_page(),
90
- 'storeBlockTitle' => _x( 'Store', 'gutenberg-store-block-stub', 'ecwid-shopping-cart' )
91
  )
92
  );
93
-
94
  $is_demo_store = ecwid_is_demo_store();
95
 
96
- $request_uri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : '';
97
 
98
- wp_localize_script( 'ecwid-gutenberg-store', 'EcwidGutenbergParams',
 
 
99
  array(
100
- 'ecwid_pb_defaults' => ecwid_get_default_pb_size(),
101
- 'storeImageUrl' => site_url('?file=ecwid_store_svg.svg'),
102
- 'storeBlockTitle' => sprintf( __( '%s Store', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
103
- 'storeShortcodeName' => Ecwid_Shortcode_Base::get_current_store_shortcode_name(),
104
- 'storeBlock' => self::STORE_BLOCK,
105
- 'productBlockTitle' => sprintf( __( '%s product', 'ecwid-shopping-cart'), Ecwid_Config::get_brand() ),
106
- 'productShortcodeName' => Ecwid_Shortcode_Product::get_shortcode_name(),
107
- 'productBlock' => self::PRODUCT_BLOCK,
108
- 'storeId' => get_ecwid_store_id(),
109
- 'chooseProduct' => __( 'Choose product', 'ecwid-shopping-cart' ),
110
- 'editAppearance' => __( 'Edit Appearance', 'ecwid-shopping-cart' ),
111
- 'yourStoreWill' => __( 'Your store will be shown here', 'ecwid-shopping-cart' ),
112
- 'storeIdLabel' => __( 'Store ID', 'ecwid-shopping-cart' ),
113
- 'yourProductLabel' => __( 'Your product', 'ecwid-shopping-cart' ),
114
- 'storeIcon' => $this->_get_store_icon_path(),
115
- 'productIcon' => $this->_get_product_icon_path(),
116
- 'isDemoStore' => $is_demo_store,
117
- 'isApiAvailable' => Ecwid_Api_V3::is_available(),
118
- 'products' => $this->_get_products_data(),
119
  'customizeMinicartText' =>
120
  sprintf(
121
  __(
122
  'You can enable an extra shopping bag icon widget that will appear on your site pages. Open “<a href="%1$s">Appearance → Customize → %2$s</a>” menu to enable it.',
123
  'ecwid-shopping-cart'
124
  ),
125
- 'customize.php?autofocus[section]=' . Ecwid_Customizer::SECTION_MINICART . '&return=' . rawurlencode( remove_query_arg( wp_removable_query_args(), $request_uri )
 
126
  ),
127
  Ecwid_Config::get_brand()
128
- )
129
  )
130
  );
131
 
132
  }
133
-
134
  protected function _get_products_data() {
135
 
136
  $blocks = self::get_blocks_on_page();
137
 
138
- $productIds = array();
139
  foreach ( $blocks as $block ) {
140
  if ( $block['blockName'] == self::PRODUCT_BLOCK ) {
141
- $productIds[] = $block['attrs']['id'];
142
  }
143
  }
144
-
145
- if ( empty( $productIds ) ) {
146
  return array();
147
  }
148
-
149
  $result = array();
150
- foreach ( $productIds as $id ) {
151
  $product = Ecwid_Product::get_by_id( $id );
152
-
153
- $result[$id] = array(
154
- 'name' => $product->name,
155
- 'imageUrl' => $product->thumbnailUrl
156
  );
157
  }
158
-
159
  return $result;
160
  }
161
-
162
  protected function _is_new_product_list() {
163
  $api = new Ecwid_Api_V3();
164
-
165
- return ecwid_is_demo_store() || !Ecwid_Api_V3::is_available() || $api->is_store_feature_enabled( Ecwid_Api_V3::FEATURE_NEW_PRODUCT_LIST );
166
  }
167
 
168
  protected function _is_new_details_page() {
169
  $api = new Ecwid_Api_V3();
170
 
171
- return ecwid_is_demo_store() || !Ecwid_Api_V3::is_available() || $api->is_store_feature_enabled( Ecwid_Api_V3::FEATURE_NEW_DETAILS_PAGE );
172
  }
173
-
174
  public function product_render_callback( $params ) {
175
-
176
- if ( !@$params['id'] ) return '';
177
-
 
 
178
  $params = wp_parse_args(
179
  $params,
180
  array(
181
- 'id' => 0,
182
- 'show_picture' => true,
183
- 'show_title' => true,
184
- 'show_price' => true,
185
- 'show_options' => true,
186
- 'show_addtobag' => true,
187
- 'show_border' => true,
188
- 'center_align' => true,
189
- 'show_price_on_button' => true
190
  )
191
  );
192
-
193
  $display = array(
194
- 'picture', 'title', 'price', 'options', 'qty', 'addtobag'
 
 
 
 
 
195
  );
196
-
197
  $params['display'] = '';
198
- $display_string = '';
199
  foreach ( $display as $name ) {
200
- if ( @$params['show_' . $name] ) {
201
  $params['display'] .= ' ' . $name;
202
  }
203
  }
204
-
205
  $params['version'] = 2;
206
 
207
  $shortcode = new Ecwid_Shortcode_Product( $params );
208
 
209
  return $shortcode->render();
210
  }
211
-
212
  public function render_callback( $params ) {
213
-
214
- if ( isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
215
  return '';
216
  }
217
 
218
- $result = "[ecwid";
219
-
220
  $params['widgets'] = 'productbrowser';
221
  if ( @$params['show_categories'] ) {
222
  $params['widgets'] .= ' categories';
@@ -224,98 +242,97 @@ class Ecwid_Integration_Gutenberg {
224
  if ( @$params['show_search'] ) {
225
  $params['widgets'] .= ' search';
226
  }
227
-
228
- foreach ($params as $key => $value) {
229
  $result .= " $key='$value'";
230
- }
231
-
232
  $result .= ']';
233
-
234
- $result .= <<<HTML
235
- <script type="text/javascript">
236
- window.ec = window.ec || Object();
237
- window.ec.storefront = window.ec.storefront || Object();
238
- HTML;
239
-
240
  $attributes = $this->_get_attributes_for_editor();
241
-
242
  $store_page_data = array();
243
-
244
  foreach ( $attributes as $key => $attribute ) {
245
-
246
  $name = $attribute['name'];
247
  // we do not print defaults
248
- if ( !isset( $params[$name] ) ) {
249
- $store_page_data[$name] = $attribute['default'];
250
  continue;
251
  }
252
-
253
- $value = $params[$name];
254
-
255
  if ( $name == 'show_description_under_image' ) {
256
  $attribute['is_storefront_api'] = true;
257
- $value = !@$params[$name];
258
-
259
  $layout = @$params['product_details_layout'];
260
  if ( is_null( $layout ) ) {
261
  $layout = $attributes['product_details_layout']['default'];
262
  }
263
-
264
  if ( $layout == 'TWO_COLUMNS_SIDEBAR_ON_THE_LEFT' ) {
265
  $name = 'product_details_two_columns_with_left_sidebar_show_product_description_on_sidebar';
266
- } else if ( $layout == 'TWO_COLUMNS_SIDEBAR_ON_THE_RIGHT' ) {
267
  $name = 'product_details_two_columns_with_right_sidebar_show_product_description_on_sidebar';
268
  } else {
269
  unset( $attribute['is_storefront_api'] );
270
  }
271
  }
272
-
273
  if ( @$attribute['is_storefront_api'] ) {
274
-
275
- if ( @$attribute['type'] == 'boolean') {
276
- $result .= 'window.ec.storefront.' . $name . "=" . ( $value ? 'true' : 'false' ) . ";" . PHP_EOL;
277
  } else {
278
  $result .= 'window.ec.storefront.' . $name . "='" . $value . "';" . PHP_EOL;
279
  }
280
- $store_page_data[$name] = $value;
281
  }
282
- }
283
-
284
  $colors = array();
285
  foreach ( array( 'foreground', 'background', 'link', 'price', 'button' ) as $kind ) {
286
- $color = @$params['chameleon_color_' . $kind];
287
  if ( $color ) {
288
- $colors['color-' . $kind] = $color;
289
  }
290
  }
291
-
292
  if ( empty( $colors ) ) {
293
  $colors = 'auto';
294
  }
295
 
296
- $colors = json_encode($colors);
297
-
298
  $chameleon = apply_filters( 'ecwid_chameleon_settings', array( 'colors' => $colors ) );
299
 
300
- if ( !is_array($chameleon ) ) {
301
  $chameleon = array(
302
  'colors' => $colors,
303
  );
304
  }
305
 
306
- if ( !isset( $chameleon['colors'] ) ) {
307
- $chameleon['colors'] = json_encode($colors);
308
  }
309
 
310
  $store_page_data['chameleon-colors'] = $chameleon['colors'];
311
-
312
  Ecwid_Store_Page::save_store_page_params( $store_page_data );
313
-
314
  if ( $chameleon['colors'] != 'auto' ) {
315
- $result .= <<<JS
316
- window.ec.config.chameleon = window.ec.config.chameleon || Object();
317
- window.ec.config.chameleon.colors = $chameleon[colors];
318
- JS;
319
  }
320
  $result .= "
321
  if ( typeof Ecwid != 'undefined' ) {
@@ -324,17 +341,17 @@ JS;
324
  });
325
  }
326
  </script>";
327
-
328
  return $result;
329
  }
330
 
331
  public static function get_block_names() {
332
  return array(
333
  self::STORE_BLOCK,
334
- self::PRODUCT_BLOCK
335
  );
336
  }
337
-
338
  /**
339
  * @param $post
340
  *
@@ -342,40 +359,41 @@ JS;
342
  */
343
  public static function get_blocks_on_page() {
344
  $post = get_post();
345
-
346
- if ( !$post ) return array();
347
-
 
 
348
  if ( function_exists( 'gutenberg_parse_blocks' ) ) {
349
  $blocks = gutenberg_parse_blocks( $post->post_content );
350
  } else {
351
  $blocks = parse_blocks( $post->post_content );
352
  }
353
-
354
  if ( empty( $blocks ) ) {
355
  return array();
356
  }
357
 
358
  $result = array();
359
-
360
  $ecwid_blocks = self::get_block_names();
361
  foreach ( $blocks as $block ) {
362
  if ( in_array( $block['blockName'], $ecwid_blocks ) ) {
363
- $result[$block['blockName']] = $block;
364
  }
365
  }
366
 
367
  return $result;
368
  }
369
 
370
- protected function _get_version_for_assets( $asset_file_path )
371
- {
372
- if ( isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'localhost' ) {
373
  return filemtime( ECWID_PLUGIN_DIR . '/' . $asset_file_path );
374
  }
375
-
376
  return get_option( 'ecwid_plugin_version' );
377
  }
378
-
379
  protected function _get_attributes_for_editor() {
380
  $api = new Ecwid_Api_V3();
381
 
@@ -388,7 +406,7 @@ JS;
388
  $attributes = Ecwid_Product_Browser::get_attributes();
389
  $to_remove = array(
390
  'product_details_two_columns_with_left_sidebar_show_product_description_on_sidebar',
391
- 'product_details_two_columns_with_right_sidebar_show_product_description_on_sidebar'
392
  );
393
  foreach ( $to_remove as $name ) {
394
  unset( $attributes[ $name ] );
@@ -398,7 +416,7 @@ JS;
398
  'name' => 'show_description_under_image',
399
  'title' => __( 'Show description under the image', 'ecwid-shopping-cart' ),
400
  'default' => false,
401
- 'type' => 'boolean'
402
  );
403
 
404
  foreach ( $attributes as $key => $attribute ) {
@@ -411,7 +429,7 @@ JS;
411
 
412
  $prop_to_default_exceptions = array(
413
  'product_list_category_image_aspect_ratio' => 'product_list_image_aspect_ratio',
414
- 'product_list_category_image_size' => 'product_list_image_size'
415
  );
416
 
417
  if ( array_key_exists( $name, $prop_to_default_exceptions ) ) {
@@ -424,7 +442,7 @@ JS;
424
  if ( $default !== null ) {
425
  $attributes[ $key ]['default'] = $default;
426
  }
427
- }
428
 
429
  $categories = ecwid_get_categories_for_selector();
430
 
@@ -432,13 +450,13 @@ JS;
432
  $attributes['default_category_id']['values'] = array(
433
  array(
434
  'value' => '',
435
- 'title' => __( 'Store root category', 'ecwid-shopping-cart' )
436
- )
437
  );
438
  foreach ( $categories as $category ) {
439
  $attributes['default_category_id']['values'][] = array(
440
  'value' => $category->id,
441
- 'title' => $category->name
442
  );
443
  }
444
  } else {
@@ -448,17 +466,21 @@ JS;
448
  if ( $cats && $cats->total == 0 ) {
449
  unset( $attributes['default_category_id'] );
450
  }
451
- }
452
 
453
- $attributes['widgets'] = array( 'type' => 'string', 'default' => '', 'name' => 'widgets' );
 
 
 
 
454
 
455
  return $attributes;
456
  }
457
-
458
  public static function get_store_block_data_from_current_page() {
459
-
460
  $blocks = self::get_blocks_on_page();
461
-
462
  $store_block = null;
463
  foreach ( $blocks as $block ) {
464
  if ( $block['blockName'] == self::STORE_BLOCK ) {
@@ -466,15 +488,16 @@ JS;
466
  break;
467
  }
468
  }
469
-
470
- if ( !$store_block ) return array();
471
-
 
 
472
  return $store_block['atts'];
473
  }
474
-
475
- protected function _get_store_icon_path()
476
- {
477
- return 'M15.32,15.58c-0.37,0-0.66,0.3-0.66,0.67c0,0.37,0.3,0.67,0.66,0.67c0.37,0,0.67-0.3,0.67-0.67
478
  C15.98,15.88,15.69,15.58,15.32,15.58z M15.45,0H4.55C2.04,0,0,2.04,0,4.55v10.91C0,17.97,2.04,20,4.55,20h10.91c2.51,0,4.55-2.04,4.55-4.55V4.55
479
  C20,2.04,17.96,0,15.45,0z M12.97,4.94C13.54,4.94,14,5.4,14,5.96s-0.46,1.03-1.03,1.03c-0.57,0-1.03-0.46-1.03-1.03
480
  C11.95,5.4,12.41,4.94,12.97,4.94z M12.97,8.02c0.57,0,1.03,0.46,1.03,1.03c0,0.57-0.46,1.03-1.03,1.03c-0.57,0-1.03-0.46-1.03-1.03
@@ -490,9 +513,8 @@ JS;
490
  c0.1,0,0.2,0.05,0.26,0.13C18.48,2.58,18.5,2.68,18.48,2.79z M4.6,15.5c-0.37,0-0.66,0.3-0.66,0.67c0,0.37,0.3,0.67,0.66,0.67c0.37,0,0.67-0.3,0.67-0.67
491
  S4.96,15.5,4.6,15.5z';
492
  }
493
-
494
- protected function _get_product_icon_path()
495
- {
496
  return 'M16.43,5.12c-0.13-1.19-0.15-1.19-1.35-1.33c-0.21-0.02-0.21-0.02-0.43-0.05c-0.01,0.06,0.06,0.78,0.14,1.13
497
  c0.57,0.37,0.87,0.98,0.87,1.71c0,1.14-0.93,2.07-2.07,2.07s-2.07-0.93-2.07-2.07c0-0.54,0.09-0.97,0.55-1.4
498
  c-0.06-0.61-0.19-1.54-0.18-1.64C10.14,3.46,8.72,3.46,8.58,3.6l-8.17,8.13c-0.56,0.55-0.56,1.43,0,1.97l5.54,5.93
@@ -503,4 +525,4 @@ JS;
503
  }
504
  }
505
 
506
- $ecwid_gutenberg = new Ecwid_Integration_Gutenberg();
1
+ <?php
2
 
3
  require_once ECWID_PLUGIN_DIR . '/includes/class-ecwid-product-browser.php';
4
 
5
  class Ecwid_Integration_Gutenberg {
6
+
7
+ const STORE_BLOCK = 'ecwid/store-block';
8
  const PRODUCT_BLOCK = 'ecwid/product-block';
9
+
10
  public function __construct() {
11
 
12
+ $version = get_bloginfo( 'version' );
13
  if ( version_compare( $version, '5.0' ) < 0 ) {
14
  return;
15
  }
16
 
17
+ if ( isset( $_GET['classic-editor'] ) ) {
18
+ return;
19
+ }
20
+
21
  add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
22
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
23
 
24
+ add_action( 'rest_insert_post', array( $this, 'on_save_post' ), 10, 3 );
25
+ add_action( 'rest_insert_page', array( $this, 'on_save_post' ), 10, 3 );
26
+
27
+ register_block_type(
28
+ self::STORE_BLOCK,
29
+ array(
30
+ 'editor_script' => 'ecwid-gutenberg-store',
31
+ 'render_callback' => array( $this, 'render_callback' ),
32
+ )
33
+ );
34
+
35
+ register_block_type(
36
+ self::PRODUCT_BLOCK,
37
+ array(
38
+ 'editor_script' => 'ecwid-gutenberg-store',
39
+ 'render_callback' => array( $this, 'product_render_callback' ),
40
+ )
41
+ );
42
+
43
  add_filter( 'block_categories', array( $this, 'block_categories' ) );
44
  }
45
 
46
+ public function admin_enqueue_scripts() {
 
47
  wp_enqueue_script( 'gutenberg-store' );
48
  EcwidPlatform::enqueue_style( 'store-popup' );
49
  }
50
+
51
  public function block_categories( $categories ) {
52
  return array_merge(
53
  $categories,
55
  array(
56
  'slug' => 'ec-store',
57
  'title' => sprintf( __( '%s', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
58
+ 'icon' => '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="#555d66" d="' . $this->_get_store_icon_path() . '"/><path d="M19 13H5v-2h14v2z" /></svg>',
59
  ),
60
  )
61
  );
62
  }
63
+
64
  public function on_save_post( $post, $request, $creating ) {
65
+ if ( strpos( $post->post_content, '<!-- wp:' . self::STORE_BLOCK ) !== false ) {
66
  Ecwid_Store_Page::add_store_page( $post->ID );
67
  }
68
  }
69
+
70
  public function enqueue_block_editor_assets() {
71
 
72
  wp_enqueue_script( 'ecwid-gutenberg-store', ECWID_PLUGIN_URL . 'js/gutenberg/blocks.build.js', array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ) );
73
  wp_enqueue_style( 'ecwid-gutenberg-block', ECWID_PLUGIN_URL . 'css/gutenberg/blocks.editor.build.css' );
74
+
75
  $locale_data = '';
76
  if ( function_exists( 'gutenberg_get_jed_locale_data' ) ) {
77
  $locale_data = gutenberg_get_jed_locale_data( 'ecwid-shopping-cart' );
78
+ } elseif ( function_exists( 'wp_get_jed_locale_data' ) ) {
79
  $locale_data = wp_get_jed_locale_data( 'ecwid-shopping-cart' );
80
  }
81
+
 
82
  if ( $locale_data ) {
83
  wp_add_inline_script(
84
  'ecwid-gutenberg-store',
86
  'before'
87
  );
88
  }
89
+
90
  $api = new Ecwid_Api_V3();
91
+ wp_localize_script(
92
+ 'ecwid-gutenberg-store',
93
+ 'EcwidGutenbergStoreBlockParams',
94
  array(
95
+ 'attributes' => $this->_get_attributes_for_editor(),
96
  'is_new_product_list' => $this->_is_new_product_list(),
97
  'is_new_details_page' => $this->_is_new_details_page(),
98
+ 'storeBlockTitle' => _x( 'Store', 'gutenberg-store-block-stub', 'ecwid-shopping-cart' ),
99
  )
100
  );
101
+
102
  $is_demo_store = ecwid_is_demo_store();
103
 
104
+ $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
105
 
106
+ wp_localize_script(
107
+ 'ecwid-gutenberg-store',
108
+ 'EcwidGutenbergParams',
109
  array(
110
+ 'ecwid_pb_defaults' => ecwid_get_default_pb_size(),
111
+ 'storeImageUrl' => site_url( '?file=ecwid_store_svg.svg' ),
112
+ 'storeBlockTitle' => sprintf( __( '%s Store', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
113
+ 'storeShortcodeName' => Ecwid_Shortcode_Base::get_current_store_shortcode_name(),
114
+ 'storeBlock' => self::STORE_BLOCK,
115
+ 'productBlockTitle' => sprintf( __( '%s product', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
116
+ 'productShortcodeName' => Ecwid_Shortcode_Product::get_shortcode_name(),
117
+ 'productBlock' => self::PRODUCT_BLOCK,
118
+ 'storeId' => get_ecwid_store_id(),
119
+ 'chooseProduct' => __( 'Choose product', 'ecwid-shopping-cart' ),
120
+ 'editAppearance' => __( 'Edit Appearance', 'ecwid-shopping-cart' ),
121
+ 'yourStoreWill' => __( 'Your store will be shown here', 'ecwid-shopping-cart' ),
122
+ 'storeIdLabel' => __( 'Store ID', 'ecwid-shopping-cart' ),
123
+ 'yourProductLabel' => __( 'Your product', 'ecwid-shopping-cart' ),
124
+ 'storeIcon' => $this->_get_store_icon_path(),
125
+ 'productIcon' => $this->_get_product_icon_path(),
126
+ 'isDemoStore' => $is_demo_store,
127
+ 'isApiAvailable' => Ecwid_Api_V3::is_available(),
128
+ 'products' => $this->_get_products_data(),
129
  'customizeMinicartText' =>
130
  sprintf(
131
  __(
132
  'You can enable an extra shopping bag icon widget that will appear on your site pages. Open “<a href="%1$s">Appearance → Customize → %2$s</a>” menu to enable it.',
133
  'ecwid-shopping-cart'
134
  ),
135
+ 'customize.php?autofocus[section]=' . Ecwid_Customizer::SECTION_MINICART . '&return=' . rawurlencode(
136
+ remove_query_arg( wp_removable_query_args(), $request_uri )
137
  ),
138
  Ecwid_Config::get_brand()
139
+ ),
140
  )
141
  );
142
 
143
  }
144
+
145
  protected function _get_products_data() {
146
 
147
  $blocks = self::get_blocks_on_page();
148
 
149
+ $product_ids = array();
150
  foreach ( $blocks as $block ) {
151
  if ( $block['blockName'] == self::PRODUCT_BLOCK ) {
152
+ $product_ids[] = $block['attrs']['id'];
153
  }
154
  }
155
+
156
+ if ( empty( $product_ids ) ) {
157
  return array();
158
  }
159
+
160
  $result = array();
161
+ foreach ( $product_ids as $id ) {
162
  $product = Ecwid_Product::get_by_id( $id );
163
+
164
+ $result[ $id ] = array(
165
+ 'name' => $product->name,
166
+ 'imageUrl' => $product->thumbnailUrl, //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
167
  );
168
  }
169
+
170
  return $result;
171
  }
172
+
173
  protected function _is_new_product_list() {
174
  $api = new Ecwid_Api_V3();
175
+
176
+ return ecwid_is_demo_store() || ! Ecwid_Api_V3::is_available() || $api->is_store_feature_enabled( Ecwid_Api_V3::FEATURE_NEW_PRODUCT_LIST );
177
  }
178
 
179
  protected function _is_new_details_page() {
180
  $api = new Ecwid_Api_V3();
181
 
182
+ return ecwid_is_demo_store() || ! Ecwid_Api_V3::is_available() || $api->is_store_feature_enabled( Ecwid_Api_V3::FEATURE_NEW_DETAILS_PAGE );
183
  }
184
+
185
  public function product_render_callback( $params ) {
186
+
187
+ if ( ! @$params['id'] ) {
188
+ return '';
189
+ }
190
+
191
  $params = wp_parse_args(
192
  $params,
193
  array(
194
+ 'id' => 0,
195
+ 'show_picture' => true,
196
+ 'show_title' => true,
197
+ 'show_price' => true,
198
+ 'show_options' => true,
199
+ 'show_addtobag' => true,
200
+ 'show_border' => true,
201
+ 'center_align' => true,
202
+ 'show_price_on_button' => true,
203
  )
204
  );
205
+
206
  $display = array(
207
+ 'picture',
208
+ 'title',
209
+ 'price',
210
+ 'options',
211
+ 'qty',
212
+ 'addtobag',
213
  );
214
+
215
  $params['display'] = '';
216
+ $display_string = '';
217
  foreach ( $display as $name ) {
218
+ if ( @$params[ 'show_' . $name ] ) {
219
  $params['display'] .= ' ' . $name;
220
  }
221
  }
222
+
223
  $params['version'] = 2;
224
 
225
  $shortcode = new Ecwid_Shortcode_Product( $params );
226
 
227
  return $shortcode->render();
228
  }
229
+
230
  public function render_callback( $params ) {
231
+
232
+ if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
233
  return '';
234
  }
235
 
236
+ $result = '[ecwid';
237
+
238
  $params['widgets'] = 'productbrowser';
239
  if ( @$params['show_categories'] ) {
240
  $params['widgets'] .= ' categories';
242
  if ( @$params['show_search'] ) {
243
  $params['widgets'] .= ' search';
244
  }
245
+
246
+ foreach ( $params as $key => $value ) {
247
  $result .= " $key='$value'";
248
+ }
249
+
250
  $result .= ']';
251
+
252
+ $result .= '<script type="text/javascript">';
253
+
254
+ $result .= '
255
+ window.ec = window.ec || Object();
256
+ window.ec.storefront = window.ec.storefront || Object();';
257
+
258
  $attributes = $this->_get_attributes_for_editor();
259
+
260
  $store_page_data = array();
261
+
262
  foreach ( $attributes as $key => $attribute ) {
263
+
264
  $name = $attribute['name'];
265
  // we do not print defaults
266
+ if ( ! isset( $params[ $name ] ) ) {
267
+ $store_page_data[ $name ] = $attribute['default'];
268
  continue;
269
  }
270
+
271
+ $value = $params[ $name ];
272
+
273
  if ( $name == 'show_description_under_image' ) {
274
  $attribute['is_storefront_api'] = true;
275
+ $value = ! @$params[ $name ];
276
+
277
  $layout = @$params['product_details_layout'];
278
  if ( is_null( $layout ) ) {
279
  $layout = $attributes['product_details_layout']['default'];
280
  }
281
+
282
  if ( $layout == 'TWO_COLUMNS_SIDEBAR_ON_THE_LEFT' ) {
283
  $name = 'product_details_two_columns_with_left_sidebar_show_product_description_on_sidebar';
284
+ } elseif ( $layout == 'TWO_COLUMNS_SIDEBAR_ON_THE_RIGHT' ) {
285
  $name = 'product_details_two_columns_with_right_sidebar_show_product_description_on_sidebar';
286
  } else {
287
  unset( $attribute['is_storefront_api'] );
288
  }
289
  }
290
+
291
  if ( @$attribute['is_storefront_api'] ) {
292
+
293
+ if ( @$attribute['type'] == 'boolean' ) {
294
+ $result .= 'window.ec.storefront.' . $name . '=' . ( $value ? 'true' : 'false' ) . ';' . PHP_EOL;
295
  } else {
296
  $result .= 'window.ec.storefront.' . $name . "='" . $value . "';" . PHP_EOL;
297
  }
298
+ $store_page_data[ $name ] = $value;
299
  }
300
+ }//end foreach
301
+
302
  $colors = array();
303
  foreach ( array( 'foreground', 'background', 'link', 'price', 'button' ) as $kind ) {
304
+ $color = @$params[ 'chameleon_color_' . $kind ];
305
  if ( $color ) {
306
+ $colors[ 'color-' . $kind ] = $color;
307
  }
308
  }
309
+
310
  if ( empty( $colors ) ) {
311
  $colors = 'auto';
312
  }
313
 
314
+ $colors = json_encode( $colors );
315
+
316
  $chameleon = apply_filters( 'ecwid_chameleon_settings', array( 'colors' => $colors ) );
317
 
318
+ if ( ! is_array( $chameleon ) ) {
319
  $chameleon = array(
320
  'colors' => $colors,
321
  );
322
  }
323
 
324
+ if ( ! isset( $chameleon['colors'] ) ) {
325
+ $chameleon['colors'] = json_encode( $colors );
326
  }
327
 
328
  $store_page_data['chameleon-colors'] = $chameleon['colors'];
329
+
330
  Ecwid_Store_Page::save_store_page_params( $store_page_data );
331
+
332
  if ( $chameleon['colors'] != 'auto' ) {
333
+ $result .= '
334
+ window.ec.config.chameleon = window.ec.config.chameleon || Object();
335
+ window.ec.config.chameleon.colors = ' . $chameleon['colors'] . ';';
 
336
  }
337
  $result .= "
338
  if ( typeof Ecwid != 'undefined' ) {
341
  });
342
  }
343
  </script>";
344
+
345
  return $result;
346
  }
347
 
348
  public static function get_block_names() {
349
  return array(
350
  self::STORE_BLOCK,
351
+ self::PRODUCT_BLOCK,
352
  );
353
  }
354
+
355
  /**
356
  * @param $post
357
  *
359
  */
360
  public static function get_blocks_on_page() {
361
  $post = get_post();
362
+
363
+ if ( ! $post ) {
364
+ return array();
365
+ }
366
+
367
  if ( function_exists( 'gutenberg_parse_blocks' ) ) {
368
  $blocks = gutenberg_parse_blocks( $post->post_content );
369
  } else {
370
  $blocks = parse_blocks( $post->post_content );
371
  }
372
+
373
  if ( empty( $blocks ) ) {
374
  return array();
375
  }
376
 
377
  $result = array();
378
+
379
  $ecwid_blocks = self::get_block_names();
380
  foreach ( $blocks as $block ) {
381
  if ( in_array( $block['blockName'], $ecwid_blocks ) ) {
382
+ $result[ $block['blockName'] ] = $block;
383
  }
384
  }
385
 
386
  return $result;
387
  }
388
 
389
+ protected function _get_version_for_assets( $asset_file_path ) {
390
+ if ( isset( $_SERVER['HTTP_HOST'] ) && $_SERVER['HTTP_HOST'] == 'localhost' ) {
 
391
  return filemtime( ECWID_PLUGIN_DIR . '/' . $asset_file_path );
392
  }
393
+
394
  return get_option( 'ecwid_plugin_version' );
395
  }
396
+
397
  protected function _get_attributes_for_editor() {
398
  $api = new Ecwid_Api_V3();
399
 
406
  $attributes = Ecwid_Product_Browser::get_attributes();
407
  $to_remove = array(
408
  'product_details_two_columns_with_left_sidebar_show_product_description_on_sidebar',
409
+ 'product_details_two_columns_with_right_sidebar_show_product_description_on_sidebar',
410
  );
411
  foreach ( $to_remove as $name ) {
412
  unset( $attributes[ $name ] );
416
  'name' => 'show_description_under_image',
417
  'title' => __( 'Show description under the image', 'ecwid-shopping-cart' ),
418
  'default' => false,
419
+ 'type' => 'boolean',
420
  );
421
 
422
  foreach ( $attributes as $key => $attribute ) {
429
 
430
  $prop_to_default_exceptions = array(
431
  'product_list_category_image_aspect_ratio' => 'product_list_image_aspect_ratio',
432
+ 'product_list_category_image_size' => 'product_list_image_size',
433
  );
434
 
435
  if ( array_key_exists( $name, $prop_to_default_exceptions ) ) {
442
  if ( $default !== null ) {
443
  $attributes[ $key ]['default'] = $default;
444
  }
445
+ }//end foreach
446
 
447
  $categories = ecwid_get_categories_for_selector();
448
 
450
  $attributes['default_category_id']['values'] = array(
451
  array(
452
  'value' => '',
453
+ 'title' => __( 'Store root category', 'ecwid-shopping-cart' ),
454
+ ),
455
  );
456
  foreach ( $categories as $category ) {
457
  $attributes['default_category_id']['values'][] = array(
458
  'value' => $category->id,
459
+ 'title' => $category->name,
460
  );
461
  }
462
  } else {
466
  if ( $cats && $cats->total == 0 ) {
467
  unset( $attributes['default_category_id'] );
468
  }
469
+ }//end if
470
 
471
+ $attributes['widgets'] = array(
472
+ 'type' => 'string',
473
+ 'default' => '',
474
+ 'name' => 'widgets',
475
+ );
476
 
477
  return $attributes;
478
  }
479
+
480
  public static function get_store_block_data_from_current_page() {
481
+
482
  $blocks = self::get_blocks_on_page();
483
+
484
  $store_block = null;
485
  foreach ( $blocks as $block ) {
486
  if ( $block['blockName'] == self::STORE_BLOCK ) {
488
  break;
489
  }
490
  }
491
+
492
+ if ( ! $store_block ) {
493
+ return array();
494
+ }
495
+
496
  return $store_block['atts'];
497
  }
498
+
499
+ protected function _get_store_icon_path() {
500
+ return 'M15.32,15.58c-0.37,0-0.66,0.3-0.66,0.67c0,0.37,0.3,0.67,0.66,0.67c0.37,0,0.67-0.3,0.67-0.67
 
501
  C15.98,15.88,15.69,15.58,15.32,15.58z M15.45,0H4.55C2.04,0,0,2.04,0,4.55v10.91C0,17.97,2.04,20,4.55,20h10.91c2.51,0,4.55-2.04,4.55-4.55V4.55
502
  C20,2.04,17.96,0,15.45,0z M12.97,4.94C13.54,4.94,14,5.4,14,5.96s-0.46,1.03-1.03,1.03c-0.57,0-1.03-0.46-1.03-1.03
503
  C11.95,5.4,12.41,4.94,12.97,4.94z M12.97,8.02c0.57,0,1.03,0.46,1.03,1.03c0,0.57-0.46,1.03-1.03,1.03c-0.57,0-1.03-0.46-1.03-1.03
513
  c0.1,0,0.2,0.05,0.26,0.13C18.48,2.58,18.5,2.68,18.48,2.79z M4.6,15.5c-0.37,0-0.66,0.3-0.66,0.67c0,0.37,0.3,0.67,0.66,0.67c0.37,0,0.67-0.3,0.67-0.67
514
  S4.96,15.5,4.6,15.5z';
515
  }
516
+
517
+ protected function _get_product_icon_path() {
 
518
  return 'M16.43,5.12c-0.13-1.19-0.15-1.19-1.35-1.33c-0.21-0.02-0.21-0.02-0.43-0.05c-0.01,0.06,0.06,0.78,0.14,1.13
519
  c0.57,0.37,0.87,0.98,0.87,1.71c0,1.14-0.93,2.07-2.07,2.07s-2.07-0.93-2.07-2.07c0-0.54,0.09-0.97,0.55-1.4
520
  c-0.06-0.61-0.19-1.54-0.18-1.64C10.14,3.46,8.72,3.46,8.58,3.6l-8.17,8.13c-0.56,0.55-0.56,1.43,0,1.97l5.54,5.93
525
  }
526
  }
527
 
528
+ $ecwid_gutenberg = new Ecwid_Integration_Gutenberg();
includes/integrations/class-ecwid-integration-rank-math.php CHANGED
@@ -1,24 +1,24 @@
1
  <?php
2
 
3
- class Ecwid_Integration_Rank_Math
4
- {
5
  protected $sitemap = array();
6
 
7
  public function __construct() {
8
- add_action( 'wp', array( $this, 'filter_meta_tags' ), 1000 );
9
 
10
- if ( ecwid_is_store_page_available()) {
11
  add_action( 'rank_math/sitemap/index', array( $this, 'sitemap_index' ) );
12
  add_filter( 'rank_math/sitemap/ecwid/content', array( $this, 'sitemap_content' ) );
13
  add_filter( 'rank_math/sitemap/exclude_post_type', array( $this, 'exclude_post_type' ), 10, 2 );
14
  add_filter( 'rank_math/excluded_post_types', array( $this, 'excluded_post_types' ), 10, 1 );
15
  }
16
 
 
17
  }
18
 
19
  public function exclude_post_type( $bool, $post_type ) {
20
 
21
- if ( $post_type == 'ec-product') {
22
  return true;
23
  }
24
 
@@ -27,7 +27,7 @@ class Ecwid_Integration_Rank_Math
27
 
28
  public function excluded_post_types( $accessible_post_types ) {
29
 
30
- if ( isset($accessible_post_types['ec-product']) ) {
31
  unset( $accessible_post_types['ec-product'] );
32
  }
33
 
@@ -37,73 +37,62 @@ class Ecwid_Integration_Rank_Math
37
  public function filter_meta_tags() {
38
  if ( Ecwid_Store_Page::is_store_page() ) {
39
  $is_home_page = Ecwid_Store_Page::is_store_home_page();
40
-
41
- if( !$is_home_page ) {
42
  remove_all_actions( 'rank_math/head' );
43
- add_action( 'wp_head', array( $this, 'render_title_tag'), 1 );
44
  }
45
  }
46
  }
47
 
48
  public function render_title_tag() {
49
  $title = _ecwid_get_seo_title();
50
- echo '<title>' . $title . '</title>' . "\n";
51
  }
52
 
53
  public function sitemap_index() {
54
- $now = date('c', time());
55
  $sitemap_url = RankMath\Sitemap\Router::get_base_url( 'ecwid-sitemap.xml' );
56
 
57
- return <<<XML
58
  <sitemap>
59
  <loc>$sitemap_url</loc>
60
  <lastmod>$now</lastmod>
61
- </sitemap>
62
- XML;
63
  }
64
 
65
  public function sitemap_content( $content ) {
66
 
67
- $this->sitemap = <<<XML
68
- <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
69
- XML;
70
 
71
- ecwid_build_sitemap( array($this, 'sitemap_callback') );
72
 
73
  $this->sitemap .= '</urlset>';
74
 
75
- $sitemap = $this->sitemap;
76
  $this->sitemap = null;
77
 
78
  return $sitemap;
79
  }
80
 
81
- public function sitemap_callback($url, $priority, $frequency, $obj) {
82
- $url = htmlspecialchars($url);
83
- $imageCode = '';
84
- $image = @$obj->originalImageUrl;
85
- if ($image) {
86
- $image = htmlspecialchars($image);
87
- $title = htmlspecialchars($obj->name);
88
- $imageCode = <<<XML
89
- <image:image>
90
- <image:title>$title</image:title>
91
- <image:loc>$image</image:loc>
92
-
93
- </image:image>
94
- XML;
95
- }
96
-
97
- $this->sitemap .= <<<XML
98
  <url>
99
  <loc>$url</loc>
100
  <changefreq>$frequency</changefreq>
101
  <priority>$priority</priority>
102
- $imageCode
103
- </url>
104
-
105
- XML;
106
  }
107
  }
108
 
109
- $ecwid_integration_rank_math = new Ecwid_Integration_Rank_Math();
1
  <?php
2
 
3
+ class Ecwid_Integration_Rank_Math {
4
+
5
  protected $sitemap = array();
6
 
7
  public function __construct() {
 
8
 
9
+ if ( ecwid_is_store_page_available() ) {
10
  add_action( 'rank_math/sitemap/index', array( $this, 'sitemap_index' ) );
11
  add_filter( 'rank_math/sitemap/ecwid/content', array( $this, 'sitemap_content' ) );
12
  add_filter( 'rank_math/sitemap/exclude_post_type', array( $this, 'exclude_post_type' ), 10, 2 );
13
  add_filter( 'rank_math/excluded_post_types', array( $this, 'excluded_post_types' ), 10, 1 );
14
  }
15
 
16
+ add_action( 'wp', array( $this, 'filter_meta_tags' ), 1000 );
17
  }
18
 
19
  public function exclude_post_type( $bool, $post_type ) {
20
 
21
+ if ( $post_type == 'ec-product' ) {
22
  return true;
23
  }
24
 
27
 
28
  public function excluded_post_types( $accessible_post_types ) {
29
 
30
+ if ( isset( $accessible_post_types['ec-product'] ) ) {
31
  unset( $accessible_post_types['ec-product'] );
32
  }
33
 
37
  public function filter_meta_tags() {
38
  if ( Ecwid_Store_Page::is_store_page() ) {
39
  $is_home_page = Ecwid_Store_Page::is_store_home_page();
40
+
41
+ if ( ! $is_home_page ) {
42
  remove_all_actions( 'rank_math/head' );
43
+ add_action( 'wp_head', array( $this, 'render_title_tag' ), 1 );
44
  }
45
  }
46
  }
47
 
48
  public function render_title_tag() {
49
  $title = _ecwid_get_seo_title();
50
+ echo '<title>' . esc_html( $title ) . '</title>' . "\n";
51
  }
52
 
53
  public function sitemap_index() {
54
+ $now = date( 'c', time() );
55
  $sitemap_url = RankMath\Sitemap\Router::get_base_url( 'ecwid-sitemap.xml' );
56
 
57
+ return "
58
  <sitemap>
59
  <loc>$sitemap_url</loc>
60
  <lastmod>$now</lastmod>
61
+ </sitemap>";
 
62
  }
63
 
64
  public function sitemap_content( $content ) {
65
 
66
+ $this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
 
 
67
 
68
+ ecwid_build_sitemap( array( $this, 'sitemap_callback' ) );
69
 
70
  $this->sitemap .= '</urlset>';
71
 
72
+ $sitemap = $this->sitemap;
73
  $this->sitemap = null;
74
 
75
  return $sitemap;
76
  }
77
 
78
+ public function sitemap_callback( $url, $priority, $frequency, $obj ) {
79
+ $url = htmlspecialchars( $url );
80
+ $image_code = '';
81
+ $image = @$obj->originalImageUrl; //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
82
+ if ( $image ) {
83
+ $image = htmlspecialchars( $image );
84
+ $title = htmlspecialchars( $obj->name );
85
+ $image_code = '<image:image><image:title>' . $title . '</image:title><image:loc>' . $image . '</image:loc></image:image>';
86
+ }
87
+
88
+ $this->sitemap .= "
 
 
 
 
 
 
89
  <url>
90
  <loc>$url</loc>
91
  <changefreq>$frequency</changefreq>
92
  <priority>$priority</priority>
93
+ $image_code
94
+ </url>";
 
 
95
  }
96
  }
97
 
98
+ $ecwid_integration_rank_math = new Ecwid_Integration_Rank_Math();
includes/integrations/class-ecwid-integration-wpseo.php CHANGED
@@ -171,19 +171,12 @@ class Ecwid_Integration_WordPress_SEO_By_Yoast {
171
  $now = date( 'c', time() );
172
 
173
  $sitemap_url = $this->_get_base_url( 'ecstore-sitemap.xml' );
174
- return <<<XML
175
- <sitemap>
176
- <loc>$sitemap_url</loc>
177
- <lastmod>$now</lastmod>
178
- </sitemap>
179
- XML;
180
  }
181
 
182
  // Hook that adds content to sitemap
183
  public function wpseo_hook_do_sitemap() {
184
- $this->sitemap = <<<XML
185
- <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
186
- XML;
187
 
188
  ecwid_build_sitemap( array( $this, 'sitemap_callback' ) );
189
 
@@ -197,30 +190,22 @@ XML;
197
 
198
  // A callback for the streaming sitemap builder
199
  public function sitemap_callback( $url, $priority, $frequency, $obj ) {
200
- $url = htmlspecialchars( $url );
201
- $imageCode = '';
202
- $image = @$obj->originalImageUrl;
203
  if ( $image ) {
204
- $image = htmlspecialchars( $image );
205
- $title = htmlspecialchars( $obj->name );
206
- $imageCode = <<<XML
207
- <image:image>
208
- <image:title>$title</image:title>
209
- <image:loc>$image</image:loc>
210
-
211
- </image:image>
212
- XML;
213
  }
214
 
215
- $this->sitemap .= <<<XML
216
  <url>
217
  <loc>$url</loc>
218
  <changefreq>$frequency</changefreq>
219
  <priority>$priority</priority>
220
- $imageCode
221
- </url>
222
-
223
- XML;
224
  }
225
 
226
  public function get_title_separator( $separator ) {
171
  $now = date( 'c', time() );
172
 
173
  $sitemap_url = $this->_get_base_url( 'ecstore-sitemap.xml' );
174
+ return '<sitemap><loc>' . $sitemap_url . '</loc><lastmod>' . $now . '</lastmod></sitemap>';
 
 
 
 
 
175
  }
176
 
177
  // Hook that adds content to sitemap
178
  public function wpseo_hook_do_sitemap() {
179
+ $this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
 
 
180
 
181
  ecwid_build_sitemap( array( $this, 'sitemap_callback' ) );
182
 
190
 
191
  // A callback for the streaming sitemap builder
192
  public function sitemap_callback( $url, $priority, $frequency, $obj ) {
193
+ $url = htmlspecialchars( $url );
194
+ $image_code = '';
195
+ $image = @$obj->originalImageUrl; //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
196
  if ( $image ) {
197
+ $image = htmlspecialchars( $image );
198
+ $title = htmlspecialchars( $obj->name );
199
+ $image_code = '<image:image><image:title>' . $title . '</image:title><image:loc>' . $image . '</image:loc></image:image>';
 
 
 
 
 
 
200
  }
201
 
202
+ $this->sitemap .= "
203
  <url>
204
  <loc>$url</loc>
205
  <changefreq>$frequency</changefreq>
206
  <priority>$priority</priority>
207
+ $image_code
208
+ </url>";
 
 
209
  }
210
 
211
  public function get_title_separator( $separator ) {
includes/shortcodes/class-ecwid-shortcode-base.php CHANGED
@@ -6,9 +6,9 @@ abstract class Ecwid_Shortcode_Base {
6
  protected $_should_render = true;
7
  protected $_index;
8
 
9
- static protected $shortcodes = array();
10
 
11
- static public function get_shortcode_name() {
12
  return 'ec_store';
13
  }
14
 
@@ -17,17 +17,17 @@ abstract class Ecwid_Shortcode_Base {
17
 
18
  public function __construct( $params ) {
19
 
20
- if (isset($params['lang']) && $params['lang']) {
21
  $this->_lang = $params['lang'];
22
  }
23
-
24
  $this->_process_params( $params );
25
-
26
- if (!isset(self::$shortcodes[$this->get_shortcode_name()])) {
27
- self::$shortcodes[$this->get_shortcode_name()] = array();
28
  }
29
- $this->_index = count(self::$shortcodes[$this->get_shortcode_name()]);
30
- self::$shortcodes[$this->get_shortcode_name()][] = $this;
31
  }
32
 
33
  public static function get_store_shortcode_names() {
@@ -43,10 +43,9 @@ abstract class Ecwid_Shortcode_Base {
43
  return 'ecwid';
44
  }
45
 
46
- public static function get_shortcode_object( $name, $params )
47
- {
48
- $names = array( 'productbrowser', 'minicart', 'search', 'categories', 'product' );
49
-
50
  $expected_prefix = 'ecwid_';
51
  if ( Ecwid_Config::is_wl() ) {
52
  $expected_prefix = 'ec_';
@@ -54,44 +53,48 @@ abstract class Ecwid_Shortcode_Base {
54
 
55
  $prefix = substr( $name, 0, strlen( $expected_prefix ) );
56
 
57
- if ( $prefix != $expected_prefix ) return '';
 
 
58
 
59
  $base = substr( $name, strlen( $expected_prefix ) );
60
 
61
  if ( in_array( $base, $names ) ) {
62
  $class = 'Ecwid_Shortcode_' . $base;
63
 
64
- $class = apply_filters( 'ecwid_get_shortcode_class', $class, $name );
65
  $shortcode = new $class( $params );
66
 
67
  return $shortcode;
68
- }
69
-
70
  return null;
71
  }
72
-
73
- public function wrap_code($code) {
74
 
75
- $version = get_option('ecwid_plugin_version');
76
 
77
- $shortcode_content = ecwid_get_scriptjs_code($this->_lang) . $code;
 
 
 
 
78
 
79
- $shortcode_content = apply_filters('ecwid_shortcode_content', $shortcode_content);
80
-
81
  $brand = Ecwid_Config::get_brand();
82
 
83
  $shortcode_content = "<!-- $brand shopping cart plugin v $version -->"
84
- . $shortcode_content
85
- . "<!-- END $brand Shopping Cart v $version -->";
86
 
87
  return $shortcode_content;
88
  }
89
 
90
  public function render() {
91
- if (!$this->_should_render) return '';
 
 
92
 
93
- $custom_renderer = apply_filters('ecwid_shortcode_custom_renderer', null, $this);
94
- if (is_callable($custom_renderer)) {
95
  return call_user_func( $custom_renderer, $this );
96
  }
97
 
@@ -102,24 +105,20 @@ abstract class Ecwid_Shortcode_Base {
102
  $params_string = $this->build_params_string(
103
  array_merge(
104
  $this->_params,
105
- array('id' => $this->get_html_id())
106
  )
107
  );
108
 
109
  $function = $this->get_ecwid_widget_function_name();
110
 
111
- return <<<HTML
112
- <script data-cfasync="false" data-no-optimize="1" type="text/javascript"> $function($params_string);</script>
113
- HTML;
114
  }
115
 
116
  public function render_placeholder() {
117
-
118
  $classname = $this->_get_html_class_name();
119
- $id = $this->get_html_id();
120
- return <<<HTML
121
- <div class="ecwid-shopping-cart-$classname" id="$id"></div>
122
- HTML;
123
  }
124
 
125
  protected function _get_html_class_name() {
@@ -127,7 +126,7 @@ HTML;
127
  }
128
 
129
  public function get_html_id() {
130
- return 'ecwid-shopping-cart-' . $this->get_shortcode_name() . '-' . ( $this->_index + 1);
131
  }
132
 
133
  protected function _default_render() {
@@ -136,34 +135,34 @@ HTML;
136
  $result .= $this->render_placeholder();
137
  $result .= $this->render_script();
138
 
139
- $result = apply_filters('ecwid_' . $this->get_shortcode_name() . '_shortcode_content', $result);
140
 
141
- if ($result) {
142
  return $this->wrap_code( $result );
143
  }
144
 
145
  return '';
146
  }
147
 
148
- public function build_params_string($params = null) {
149
 
150
- if (is_null($params)) {
151
  $params = $this->_params;
152
  }
153
 
154
  unset( $params['noHTMLCatalog'] );
155
 
156
  $pieces = array();
157
- if ( !empty ( $params ) ) {
158
  foreach ( $params as $key => $value ) {
159
  $pieces[] = "$key=$value";
160
  }
161
  }
162
 
163
- return '"' . implode('","', $pieces) . '"';
164
  }
165
 
166
  public function get_params() {
167
  return $this->_params;
168
  }
169
- }
6
  protected $_should_render = true;
7
  protected $_index;
8
 
9
+ protected static $shortcodes = array();
10
 
11
+ public static function get_shortcode_name() {
12
  return 'ec_store';
13
  }
14
 
17
 
18
  public function __construct( $params ) {
19
 
20
+ if ( isset( $params['lang'] ) && $params['lang'] ) {
21
  $this->_lang = $params['lang'];
22
  }
23
+
24
  $this->_process_params( $params );
25
+
26
+ if ( ! isset( self::$shortcodes[ $this->get_shortcode_name() ] ) ) {
27
+ self::$shortcodes[ $this->get_shortcode_name() ] = array();
28
  }
29
+ $this->_index = count( self::$shortcodes[ $this->get_shortcode_name() ] );
30
+ self::$shortcodes[ $this->get_shortcode_name() ][] = $this;
31
  }
32
 
33
  public static function get_store_shortcode_names() {
43
  return 'ecwid';
44
  }
45
 
46
+ public static function get_shortcode_object( $name, $params ) {
47
+ $names = array( 'productbrowser', 'minicart', 'search', 'categories', 'product' );
48
+
 
49
  $expected_prefix = 'ecwid_';
50
  if ( Ecwid_Config::is_wl() ) {
51
  $expected_prefix = 'ec_';
53
 
54
  $prefix = substr( $name, 0, strlen( $expected_prefix ) );
55
 
56
+ if ( $prefix != $expected_prefix ) {
57
+ return '';
58
+ }
59
 
60
  $base = substr( $name, strlen( $expected_prefix ) );
61
 
62
  if ( in_array( $base, $names ) ) {
63
  $class = 'Ecwid_Shortcode_' . $base;
64
 
65
+ $class = apply_filters( 'ecwid_get_shortcode_class', $class, $name );
66
  $shortcode = new $class( $params );
67
 
68
  return $shortcode;
69
+ }
70
+
71
  return null;
72
  }
 
 
73
 
74
+ public function wrap_code( $code ) {
75
 
76
+ $version = get_option( 'ecwid_plugin_version' );
77
+
78
+ $shortcode_content = ecwid_get_scriptjs_code( $this->_lang ) . $code;
79
+
80
+ $shortcode_content = apply_filters( 'ecwid_shortcode_content', $shortcode_content );
81
 
 
 
82
  $brand = Ecwid_Config::get_brand();
83
 
84
  $shortcode_content = "<!-- $brand shopping cart plugin v $version -->"
85
+ . $shortcode_content
86
+ . "<!-- END $brand Shopping Cart v $version -->";
87
 
88
  return $shortcode_content;
89
  }
90
 
91
  public function render() {
92
+ if ( ! $this->_should_render ) {
93
+ return '';
94
+ }
95
 
96
+ $custom_renderer = apply_filters( 'ecwid_shortcode_custom_renderer', null, $this );
97
+ if ( is_callable( $custom_renderer ) ) {
98
  return call_user_func( $custom_renderer, $this );
99
  }
100
 
105
  $params_string = $this->build_params_string(
106
  array_merge(
107
  $this->_params,
108
+ array( 'id' => $this->get_html_id() )
109
  )
110
  );
111
 
112
  $function = $this->get_ecwid_widget_function_name();
113
 
114
+ return sprintf( '<script data-cfasync="false" data-no-optimize="1" type="text/javascript">%s(%s);</script>', $function, $params_string );
 
 
115
  }
116
 
117
  public function render_placeholder() {
 
118
  $classname = $this->_get_html_class_name();
119
+ $id = $this->get_html_id();
120
+
121
+ return '<div class="ecwid-shopping-cart-' . esc_attr( $classname ) . ' id="' . esc_attr( $id ) . '"></div>';
 
122
  }
123
 
124
  protected function _get_html_class_name() {
126
  }
127
 
128
  public function get_html_id() {
129
+ return 'ecwid-shopping-cart-' . $this->get_shortcode_name() . '-' . ( $this->_index + 1 );
130
  }
131
 
132
  protected function _default_render() {
135
  $result .= $this->render_placeholder();
136
  $result .= $this->render_script();
137
 
138
+ $result = apply_filters( 'ecwid_' . $this->get_shortcode_name() . '_shortcode_content', $result );
139
 
140
+ if ( $result ) {
141
  return $this->wrap_code( $result );
142
  }
143
 
144
  return '';
145
  }
146
 
147
+ public function build_params_string( $params = null ) {
148
 
149
+ if ( is_null( $params ) ) {
150
  $params = $this->_params;
151
  }
152
 
153
  unset( $params['noHTMLCatalog'] );
154
 
155
  $pieces = array();
156
+ if ( ! empty( $params ) ) {
157
  foreach ( $params as $key => $value ) {
158
  $pieces[] = "$key=$value";
159
  }
160
  }
161
 
162
+ return '"' . implode( '","', $pieces ) . '"';
163
  }
164
 
165
  public function get_params() {
166
  return $this->_params;
167
  }
168
+ }
includes/shortcodes/class-ecwid-shortcode-productbrowser.php CHANGED
@@ -46,17 +46,19 @@ class Ecwid_Shortcode_ProductBrowser extends Ecwid_Shortcode_Base {
46
  $code = '';
47
  global $ecwid_current_theme;
48
  if ( $ecwid_current_theme ) {
 
 
 
 
 
 
49
 
50
- $code = "
51
- <script data-cfasync=\"false\" data-no-optimize=\"1\">
52
- if( typeof document.documentElement.id == 'undefined' || document.documentElement.id === '' ) {
53
- document.documentElement.id = 'ecwid_html';
54
- }
55
-
56
- if( typeof document.body.id == 'undefined' || document.body.id === '' ) {
57
- document.body.id = 'ecwid_body';
58
- }
59
- </script>";
60
  }
61
 
62
  $classname = '';
@@ -81,32 +83,38 @@ if( typeof document.body.id == 'undefined' || document.body.id === '' ) {
81
  }
82
 
83
  protected function _get_js_switch_dynamic( $static_container_id, $dynamic_container_id ) {
84
- return "
85
- <script data-cfasync=\"false\" data-no-optimize=\"1\" type=\"text/javascript\">
86
- window.ec.storefront = window.ec.storefront || {};
87
- window.ec.storefront.staticPages = window.ec.storefront.staticPages || Object();
88
-
89
- ec.storefront.staticPages.staticStorefrontEnabled = true;
90
- ec.storefront.staticPages.staticContainerID = '$static_container_id';
91
- ec.storefront.staticPages.dynamicContainerID = '$dynamic_container_id';
92
- ec.storefront.staticPages.autoSwitchStaticToDynamicWhenReady = true;
93
- </script>";
 
 
 
94
  }
95
 
96
  protected function _get_js_hide_static( $html_selector ) {
97
- return "
98
- <script data-cfasync=\"false\" data-no-optimize=\"1\" type=\"text/javascript\">
99
- function createClass(name,rules){
100
- var style = document.createElement('style');
101
- style.type = 'text/css';
102
- document.getElementsByTagName('head')[0].appendChild(style);
103
- if(!(style.sheet||{}).insertRule)
104
- (style.styleSheet || style.sheet).addRule(name, rules);
105
- else
106
- style.sheet.insertRule(name+'{'+rules+'}',0);
107
- }
108
- createClass('$html_selector','display:none;');
109
- </script>";
 
 
 
110
  }
111
 
112
 
@@ -258,17 +266,19 @@ if( typeof document.body.id == 'undefined' || document.body.id === '' ) {
258
  return false;
259
  }
260
 
261
- $result = '
262
- <script>
263
- Ecwid.OnAPILoaded.add(function() {
264
- Ecwid.OnPageLoad.add(function(page) {
265
- if ("CATEGORY" == page.type && 0 == page.categoryId && !page.hasPrevious) {
266
- Ecwid.openPage("' . $page . '");
267
- }
268
- })
269
- });
270
- </script>';
 
 
271
 
272
- return $result;
273
  }
274
  }
46
  $code = '';
47
  global $ecwid_current_theme;
48
  if ( $ecwid_current_theme ) {
49
+ ob_start();
50
+ ?>
51
+ <script data-cfasync="false" data-no-optimize="1">
52
+ if( typeof document.documentElement.id == 'undefined' || document.documentElement.id === '' ) {
53
+ document.documentElement.id = 'ecwid_html';
54
+ }
55
 
56
+ if( typeof document.body.id == 'undefined' || document.body.id === '' ) {
57
+ document.body.id = 'ecwid_body';
58
+ }
59
+ </script>
60
+ <?php
61
+ $code = ob_get_clean();
 
 
 
 
62
  }
63
 
64
  $classname = '';
83
  }
84
 
85
  protected function _get_js_switch_dynamic( $static_container_id, $dynamic_container_id ) {
86
+ ob_start();
87
+ ?>
88
+ <script data-cfasync="false" data-no-optimize="1" type="text/javascript">
89
+ window.ec.storefront = window.ec.storefront || {};
90
+ window.ec.storefront.staticPages = window.ec.storefront.staticPages || Object();
91
+
92
+ ec.storefront.staticPages.staticStorefrontEnabled = true;
93
+ ec.storefront.staticPages.staticContainerID = '<?php echo esc_js( $static_container_id ); ?>';
94
+ ec.storefront.staticPages.dynamicContainerID = '<?php echo esc_js( $dynamic_container_id ); ?>';
95
+ ec.storefront.staticPages.autoSwitchStaticToDynamicWhenReady = true;
96
+ </script>
97
+ <?php
98
+ return ob_get_clean();
99
  }
100
 
101
  protected function _get_js_hide_static( $html_selector ) {
102
+ ob_start();
103
+ ?>
104
+ <script data-cfasync="false" data-no-optimize="1" type="text/javascript">
105
+ function createClass(name,rules){
106
+ var style = document.createElement('style');
107
+ style.type = 'text/css';
108
+ document.getElementsByTagName('head')[0].appendChild(style);
109
+ if(!(style.sheet||{}).insertRule)
110
+ (style.styleSheet || style.sheet).addRule(name, rules);
111
+ else
112
+ style.sheet.insertRule(name+'{'+rules+'}',0);
113
+ }
114
+ createClass('<?php echo esc_js( $html_selector ); ?>','display:none;');
115
+ </script>
116
+ <?php
117
+ return ob_get_clean();
118
  }
119
 
120
 
266
  return false;
267
  }
268
 
269
+ ob_start();
270
+ ?>
271
+ <script>
272
+ Ecwid.OnAPILoaded.add(function() {
273
+ Ecwid.OnPageLoad.add(function(page) {
274
+ if ("CATEGORY" == page.type && 0 == page.categoryId && !page.hasPrevious) {
275
+ Ecwid.openPage("<?php echo esc_js( $page ); ?>");
276
+ }
277
+ })
278
+ });
279
+ </script>
280
+ <?php
281
 
282
+ return ob_get_clean();
283
  }
284
  }
includes/shortcodes/class-ecwid-shortcode-stub.php CHANGED
@@ -14,16 +14,14 @@ class Ecwid_Shortcode_Stub extends Ecwid_Shortcode_Base {
14
  public function get_ecwid_widget_function_name() {
15
  return '';
16
  }
17
-
18
  public function render_widget() {
19
-
20
  }
21
 
22
  public function render_placeholder() {
23
  $classname = $this->_get_html_class_name();
24
- $id = $this->get_html_id();
25
- return <<<HTML
26
- <div class="ecwid-shopping-cart-$classname"><div id="$id"></div></div>
27
- HTML;
28
  }
29
- }
14
  public function get_ecwid_widget_function_name() {
15
  return '';
16
  }
17
+
18
  public function render_widget() {
19
+
20
  }
21
 
22
  public function render_placeholder() {
23
  $classname = $this->_get_html_class_name();
24
+ $id = $this->get_html_id();
25
+ return '<div class="ecwid-shopping-cart-' . esc_attr( $classname ) . '"><div id="' . esc_attr( $id ) . '"></div></div>';
 
 
26
  }
27
+ }
includes/themes.php CHANGED
@@ -11,17 +11,17 @@ function ecwid_get_theme_name() {
11
  $version = get_bloginfo( 'version' );
12
 
13
  if ( version_compare( $version, '3.4' ) < 0 ) {
14
- $theme_name = get_current_theme();
15
  } else {
16
  $theme = wp_get_theme();
17
- $theme_name = $theme->Name;
18
  }
19
 
20
  return $theme_name;
21
  }
22
 
23
  function ecwid_get_theme_identification() {
24
- $version = get_bloginfo( 'version' );
25
 
26
  if ( version_compare( $version, '3.4' ) < 0 ) {
27
  $theme_name = get_template();
11
  $version = get_bloginfo( 'version' );
12
 
13
  if ( version_compare( $version, '3.4' ) < 0 ) {
14
+ $theme_name = get_current_theme(); //phpcs:ignore WordPress.WP.DeprecatedFunctions.get_current_themeFound
15
  } else {
16
  $theme = wp_get_theme();
17
+ $theme_name = $theme->Name; //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
18
  }
19
 
20
  return $theme_name;
21
  }
22
 
23
  function ecwid_get_theme_identification() {
24
+ $version = get_bloginfo( 'version' );
25
 
26
  if ( version_compare( $version, '3.4' ) < 0 ) {
27
  $theme_name = get_template();
includes/themes/class-ecwid-theme-avada.php CHANGED
@@ -2,12 +2,11 @@
2
 
3
  require_once ECWID_THEMES_DIR . '/class-ecwid-theme-base.php';
4
 
5
- class Ecwid_Theme_Avada extends Ecwid_Theme_Base
6
- {
7
  protected $name = 'Avada';
8
 
9
- public function __construct()
10
- {
11
  parent::__construct();
12
 
13
  add_filter( Ecwid_Nav_Menus::FILTER_USE_JS_API_FOR_CATS_MENU, array( $this, 'filter_use_js_api_for_cats_menu' ) );
@@ -15,24 +14,26 @@ class Ecwid_Theme_Avada extends Ecwid_Theme_Base
15
 
16
  $this->create_scroller( array( 'scroll' => 95 ) );
17
  }
18
-
19
- public function shortcode_content( $content )
20
- {
21
- $content .= <<<HTML
22
- <script type="text/javascript">
23
- Ecwid.OnPageLoaded.add( function() {
24
- if (typeof niceScrollReInit == 'function') {
25
- niceScrollReInit();
26
- }
27
 
28
- if (typeof jQuery("html").getNiceScroll == 'object') {
29
- jQuery("html").getNiceScroll().resize();
30
- }
31
- }
32
- );</script>
33
- HTML;
 
 
 
 
 
 
 
 
 
 
 
34
  return $content;
35
  }
36
  }
37
 
38
- return new Ecwid_Theme_Avada();
2
 
3
  require_once ECWID_THEMES_DIR . '/class-ecwid-theme-base.php';
4
 
5
+ class Ecwid_Theme_Avada extends Ecwid_Theme_Base {
6
+
7
  protected $name = 'Avada';
8
 
9
+ public function __construct() {
 
10
  parent::__construct();
11
 
12
  add_filter( Ecwid_Nav_Menus::FILTER_USE_JS_API_FOR_CATS_MENU, array( $this, 'filter_use_js_api_for_cats_menu' ) );
14
 
15
  $this->create_scroller( array( 'scroll' => 95 ) );
16
  }
 
 
 
 
 
 
 
 
 
17
 
18
+ public function shortcode_content( $content ) {
19
+ ob_start();
20
+ ?>
21
+ <script type="text/javascript">
22
+ Ecwid.OnPageLoaded.add( function() {
23
+ if (typeof niceScrollReInit == 'function') {
24
+ niceScrollReInit();
25
+ }
26
+
27
+ if (typeof jQuery("html").getNiceScroll == 'object') {
28
+ jQuery("html").getNiceScroll().resize();
29
+ }
30
+ });
31
+ </script>
32
+ <?php
33
+ $content .= ob_get_clean();
34
+
35
  return $content;
36
  }
37
  }
38
 
39
+ return new Ecwid_Theme_Avada();
includes/themes/class-ecwid-theme-mfupdate.php CHANGED
@@ -2,31 +2,31 @@
2
 
3
  require_once ECWID_THEMES_DIR . '/class-ecwid-theme-base.php';
4
 
5
- class Ecwid_Theme_MFUpdate extends Ecwid_Theme_Base
6
- {
7
  protected $name = 'MFUpdate';
8
 
9
- public function __construct()
10
- {
11
- parent::__construct();
12
 
13
  add_filter( 'ecwid_shortcode_content', array( $this, 'ecwid_shortcode_content' ) );
14
  }
15
 
16
- public function ecwid_shortcode_content($content) {
17
-
18
- $content .= <<<HTML
19
- <script type="text/javascript">
20
- Ecwid.OnPageLoaded.add( function() {
21
- if (jQuery('#container').data() && jQuery('#container').data().isotope) {
22
- jQuery('#container').data().isotope.reLayout();
23
- }
24
- }
25
- );</script>
26
- HTML;
 
27
 
28
  return $content;
29
  }
30
  }
31
 
32
- return new Ecwid_Theme_MFUpdate();
2
 
3
  require_once ECWID_THEMES_DIR . '/class-ecwid-theme-base.php';
4
 
5
+ class Ecwid_Theme_MFUpdate extends Ecwid_Theme_Base {
6
+
7
  protected $name = 'MFUpdate';
8
 
9
+ public function __construct() {
10
+ parent::__construct();
 
11
 
12
  add_filter( 'ecwid_shortcode_content', array( $this, 'ecwid_shortcode_content' ) );
13
  }
14
 
15
+ public function ecwid_shortcode_content( $content ) {
16
+ ob_start();
17
+ ?>
18
+ <script type="text/javascript">
19
+ Ecwid.OnPageLoaded.add( function() {
20
+ if (jQuery('#container').data() && jQuery('#container').data().isotope) {
21
+ jQuery('#container').data().isotope.reLayout();
22
+ }
23
+ });
24
+ </script>
25
+ <?php
26
+ $content .= ob_get_clean();
27
 
28
  return $content;
29
  }
30
  }
31
 
32
+ return new Ecwid_Theme_MFUpdate();
includes/themes/class-ecwid-theme-trend.php CHANGED
@@ -3,112 +3,31 @@
3
  require_once ECWID_THEMES_DIR . '/class-ecwid-theme-base.php';
4
  require_once ECWID_PLUGIN_DIR . '/includes/class-ecwid-ajax-defer-renderer.php';
5
 
6
- class Ecwid_Theme_Trend extends Ecwid_Theme_Base
7
- {
8
  protected $name = 'Trend';
9
 
10
  protected $shortcodes = array();
11
 
12
- public function __construct()
13
- {
14
  parent::__construct();
15
 
16
- if ( get_option('ecwid_defer_rendering') ) {
17
  update_option( Ecwid_Ajax_Defer_Renderer::OPTION_DEFER_RENDERING, true );
18
  delete_option( 'ecwid_defer_rendering' );
19
  }
20
-
21
- if ( !get_option( Ecwid_Ajax_Defer_Renderer::is_enabled() ) ) {
22
  return;
23
  }
24
 
25
  // That actually means that ajax loading is disabled. Really ambigious naming
26
- if (class_exists('BW') && method_exists('BW', 'get_option') && !@BW::get_option('disable_ajax_loading')) {
27
  return;
28
  }
29
 
30
- add_filter('ecwid_disable_widgets', '__return_true');
31
- add_filter('ecwid_shortcode_custom_renderer', array($this, 'get_custom_renderer'));
32
- add_filter('the_content', array($this, 'add_shortcodes'));
33
- }
34
-
35
- public function get_custom_renderer() {
36
- return array($this, 'render_shortcode');
37
- }
38
-
39
- public function render_shortcode($shortcode) {
40
-
41
- if ($shortcode instanceof Ecwid_Shortcode_Base) {
42
- return $shortcode->render_placeholder() . $this->_render_shortcode_script($shortcode);
43
- }
44
-
45
- return '';
46
- }
47
-
48
- public function add_shortcodes($content) {
49
- $ecwid_store_id = get_ecwid_store_id();
50
- $before = <<<HTML
51
- <script>
52
- var ecwid_shortcodes = [];
53
- </script>
54
- HTML;
55
-
56
- $app_ecwid_com = Ecwid_Config::get_scriptjs_domain();
57
-
58
- $after = <<<HTML
59
- <script>
60
- window.ecwid_script_defer = true;
61
- window.ecwid_dynamic_widgets = true;
62
-
63
- if (typeof Ecwid != 'undefined' && Ecwid.destroy) Ecwid.destroy();
64
-
65
- if (typeof ecwid_shortcodes != 'undefined') {
66
- window._xnext_initialization_scripts = ecwid_shortcodes;
67
-
68
- if (!document.getElementById('ecwid-script')) {
69
- var script = document.createElement('script');
70
- script.charset = 'utf-8';
71
- script.type = 'text/javascript';
72
- script.src = 'https://$app_ecwid_com/script.js?$ecwid_store_id';
73
- script.id = 'ecwid-script'
74
-
75
- document.body.appendChild(script);
76
-
77
- var catalog = document.getElementById('ecwid-html-catalog-$ecwid_store_id');
78
- catalog.parentElement.removeChild(catalog);
79
- } else {
80
- ecwid_onBodyDone();
81
- }
82
- }
83
- </script>
84
- HTML;
85
- return $before . $content . $after;
86
- }
87
-
88
- protected function _render_shortcode_script(Ecwid_Shortcode_Base $shortcode) {
89
-
90
- $args = $shortcode->build_params_string();
91
- $id = $shortcode->get_html_id();
92
- $widgetType = substr($shortcode->get_ecwid_widget_function_name(), 1);
93
- if ($widgetType == 'Search') {
94
- $widgetType = 'SearchWidget';
95
- }
96
- $store_id = get_ecwid_store_id();
97
-
98
- $code = <<<HTML
99
- <script type="text/javascript">
100
- if (typeof ecwid_shortcodes != 'undefined') {
101
- ecwid_shortcodes[ecwid_shortcodes.length] = {
102
- widgetType: '$widgetType',
103
- id: '$id',
104
- arg: [$args]
105
- };
106
- }
107
- </script>
108
- HTML;
109
- return $code;
110
-
111
  }
112
  }
113
 
114
- return new Ecwid_Theme_Trend();
3
  require_once ECWID_THEMES_DIR . '/class-ecwid-theme-base.php';
4
  require_once ECWID_PLUGIN_DIR . '/includes/class-ecwid-ajax-defer-renderer.php';
5
 
6
+ class Ecwid_Theme_Trend extends Ecwid_Theme_Base {
7
+
8
  protected $name = 'Trend';
9
 
10
  protected $shortcodes = array();
11
 
12
+ public function __construct() {
 
13
  parent::__construct();
14
 
15
+ if ( get_option( 'ecwid_defer_rendering' ) ) {
16
  update_option( Ecwid_Ajax_Defer_Renderer::OPTION_DEFER_RENDERING, true );
17
  delete_option( 'ecwid_defer_rendering' );
18
  }
19
+
20
+ if ( ! get_option( Ecwid_Ajax_Defer_Renderer::is_enabled() ) ) {
21
  return;
22
  }
23
 
24
  // That actually means that ajax loading is disabled. Really ambigious naming
25
+ if ( class_exists( 'BW' ) && method_exists( 'BW', 'get_option' ) && ! @BW::get_option( 'disable_ajax_loading' ) ) {
26
  return;
27
  }
28
 
29
+ add_filter( Ecwid_Ajax_Defer_Renderer::FILTER_ENABLED, '__return_true' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
  }
32
 
33
+ return new Ecwid_Theme_Trend();
includes/widgets.php CHANGED
@@ -1,67 +1,68 @@
1
  <?php
2
 
3
- include_once "widgets/class-ecwid-widget-badge.php";
4
- include_once "widgets/class-ecwid-widget-minicart.php";
5
- include_once "widgets/class-ecwid-widget-minicart-miniview.php";
6
- include_once "widgets/class-ecwid-widget-floating-shopping-cart.php";
7
- include_once "widgets/class-ecwid-widget-recently-viewed.php";
8
- include_once "widgets/class-ecwid-widget-latest-products.php";
9
- include_once "widgets/class-ecwid-widget-search.php";
10
- include_once "widgets/class-ecwid-widget-store-link.php";
11
- include_once "widgets/class-ecwid-widget-vertical-categories-list.php";
12
- include_once "widgets/class-ecwid-widget-random-product.php";
13
-
14
- include_once "widgets/class-ecwid-widget-nsf-minicart.php";
15
- include_once "widgets/class-ecwid-widget-product-browser.php";
16
-
17
-
18
- if (ecwid_migrations_is_original_plugin_version_older_than('4.3')) {
19
- include_once "widgets/class-ecwid-widget-vcategories.php";
20
  }
21
 
22
  function ecwid_sidebar_widgets_init() {
23
 
24
- $disable_widgets = apply_filters('ecwid_disable_widgets', false);
25
 
26
- if ($disable_widgets) {
27
  return;
28
  }
29
 
30
- if ( !Ecwid_Config::is_wl() ) {
31
- register_widget('Ecwid_Widget_Badge');
32
  }
33
 
34
- register_widget('Ecwid_Widget_Search');
35
 
36
- if ( version_compare( get_bloginfo('version'), '4.0' ) >= 0 ) {
37
- register_widget('Ecwid_Widget_NSF_Minicart');
38
  }
39
 
40
  $old_minicarts = array(
41
- 'ecwidminicart_miniview' => 'Ecwid_Widget_Minicart_Miniview',
42
- 'ecwidminicart' => 'Ecwid_Widget_Minicart',
43
- 'ecwidfloatingshoppingcart' => 'Ecwid_Widget_Floating_Shopping_Cart' );
44
-
 
45
  foreach ( $old_minicarts as $idbase => $widget_class ) {
46
- if ( is_active_widget( false, false, $idbase ) || version_compare( get_bloginfo('version'), '4.0' ) < 0 ) {
47
  register_widget( $widget_class );
48
  }
49
  }
50
 
51
- register_widget('Ecwid_Widget_Store_Link');
52
-
53
  if ( Ecwid_Api_V3::is_available() ) {
54
- register_widget('Ecwid_Widget_Recently_Viewed');
55
- register_widget('Ecwid_Widget_Latest_Products');
56
-
57
- register_widget('Ecwid_Widget_Vertical_Categories_List');
58
- register_widget('Ecwid_Widget_Random_Product');
59
  }
60
-
61
- if (ecwid_migrations_is_original_plugin_version_older_than('4.3')) {
62
- register_widget('Ecwid_Widget_VCategories');
63
  }
64
 
65
  }
66
 
67
- add_action('widgets_init', 'ecwid_sidebar_widgets_init');
1
  <?php
2
 
3
+ require_once 'widgets/class-ecwid-widget-badge.php';
4
+ require_once 'widgets/class-ecwid-widget-minicart.php';
5
+ require_once 'widgets/class-ecwid-widget-minicart-miniview.php';
6
+ require_once 'widgets/class-ecwid-widget-floating-shopping-cart.php';
7
+ require_once 'widgets/class-ecwid-widget-recently-viewed.php';
8
+ require_once 'widgets/class-ecwid-widget-latest-products.php';
9
+ require_once 'widgets/class-ecwid-widget-search.php';
10
+ require_once 'widgets/class-ecwid-widget-store-link.php';
11
+ require_once 'widgets/class-ecwid-widget-vertical-categories-list.php';
12
+ require_once 'widgets/class-ecwid-widget-random-product.php';
13
+
14
+ require_once 'widgets/class-ecwid-widget-nsf-minicart.php';
15
+ require_once 'widgets/class-ecwid-widget-product-browser.php';
16
+
17
+
18
+ if ( ecwid_migrations_is_original_plugin_version_older_than( '4.3' ) ) {
19
+ include_once 'widgets/class-ecwid-widget-vcategories.php';
20
  }
21
 
22
  function ecwid_sidebar_widgets_init() {
23
 
24
+ $disable_widgets = apply_filters( 'ecwid_disable_widgets', false );
25
 
26
+ if ( $disable_widgets ) {
27
  return;
28
  }
29
 
30
+ if ( ! Ecwid_Config::is_wl() ) {
31
+ register_widget( 'Ecwid_Widget_Badge' );
32
  }
33
 
34
+ register_widget( 'Ecwid_Widget_Search' );
35
 
36
+ if ( version_compare( get_bloginfo( 'version' ), '4.0' ) >= 0 ) {
37
+ register_widget( 'Ecwid_Widget_NSF_Minicart' );
38
  }
39
 
40
  $old_minicarts = array(
41
+ 'ecwidminicart_miniview' => 'Ecwid_Widget_Minicart_Miniview',
42
+ 'ecwidminicart' => 'Ecwid_Widget_Minicart',
43
+ 'ecwidfloatingshoppingcart' => 'Ecwid_Widget_Floating_Shopping_Cart',
44
+ );
45
+
46
  foreach ( $old_minicarts as $idbase => $widget_class ) {
47
+ if ( is_active_widget( false, false, $idbase ) || version_compare( get_bloginfo( 'version' ), '4.0' ) < 0 ) {
48
  register_widget( $widget_class );
49
  }
50
  }
51
 
52
+ register_widget( 'Ecwid_Widget_Store_Link' );
53
+
54
  if ( Ecwid_Api_V3::is_available() ) {
55
+ register_widget( 'Ecwid_Widget_Recently_Viewed' );
56
+ register_widget( 'Ecwid_Widget_Latest_Products' );
57
+
58
+ register_widget( 'Ecwid_Widget_Vertical_Categories_List' );
59
+ register_widget( 'Ecwid_Widget_Random_Product' );
60
  }
61
+
62
+ if ( ecwid_migrations_is_original_plugin_version_older_than( '4.3' ) ) {
63
+ register_widget( 'Ecwid_Widget_VCategories' );
64
  }
65
 
66
  }
67
 
68
+ add_action( 'widgets_init', 'ecwid_sidebar_widgets_init' );
includes/widgets/class-ecwid-widget-badge.php CHANGED
@@ -4,134 +4,138 @@ require_once ECWID_PLUGIN_DIR . '/includes/widgets/class-ecwid-widget-base.php';
4
 
5
  class Ecwid_Widget_Badge extends Ecwid_Widget_Base {
6
 
7
- var $url_template = "https://dj925myfyz5v.cloudfront.net/badges/%s.png";
8
- var $available_badges;
9
 
10
- function __construct() {
11
  $this->_hide_title = true;
12
-
13
- $widget_ops = array('classname' => 'widget_ecwid_badge', 'description' => __("Do you like Ecwid and want to help it grow? You can add this fancy 'Powered by Ecwid' badge on your site to show your visitors that you're a proud user of Ecwid.", 'ecwid-shopping-cart') );
14
- parent::__construct('ecwidbadge', __('Ecwid Badge', 'ecwid-shopping-cart'), $widget_ops);
 
 
 
15
 
16
  $this->available_badges = array(
17
- 'ecwid-shopping-cart-widget-5' => array (
18
  'name' => 'ecwid-shopping-cart-widget-5',
19
  'width' => '73',
20
  'height' => '20',
21
- 'alt' => __('Ecwid shopping cart widget', 'ecwid-shopping-cart')
22
  ),
23
- 'ecwid-shopping-cart-widget-6' => array (
24
  'name' => 'ecwid-shopping-cart-widget-6',
25
  'width' => '73',
26
  'height' => '20',
27
- 'alt' => __('Ecwid shopping cart widget', 'ecwid-shopping-cart')
28
  ),
29
- 'ecwid-ecommerce-solution-2' => array (
30
  'name' => 'ecwid-ecommerce-solution-2',
31
  'width' => '165',
32
  'height' => '58',
33
- 'alt' => __('Ecwid ecommerce solution', 'ecwid-shopping-cart')
34
  ),
35
- 'ecwid-free-shopping-cart-2' => array (
36
  'name' => 'ecwid-free-shopping-cart-2',
37
  'width' => '175',
38
  'height' => '58',
39
- 'alt' => __('Ecwid free shopping cart', 'ecwid-shopping-cart')
40
  ),
41
- 'ecwid-shopping-cart-3' => array (
42
  'name' => 'ecwid-shopping-cart-3',
43
  'width' => '165',
44
  'height' => '56',
45
- 'alt' => __('Ecwid shopping cart', 'ecwid-shopping-cart')
46
  ),
47
- 'ecwid-ecommerce-widgets-3' => array (
48
  'name' => 'ecwid-ecommerce-widgets-3',
49
  'width' => '165',
50
  'height' => '58',
51
- 'alt' => __('Ecwid e-commerce widgets', 'ecwid-shopping-cart')
52
  ),
53
- 'ecwid-shopping-cart-3' => array (
54
  'name' => 'ecwid-shopping-cart-3',
55
  'width' => '165',
56
  'height' => '56',
57
- 'alt' => __('Ecwid shopping cart', 'ecwid-shopping-cart')
58
  ),
59
- 'ecwid-ecommerce-widgets-3' => array (
60
  'name' => 'ecwid-ecommerce-widgets-3',
61
  'width' => '165',
62
  'height' => '58',
63
- 'alt' => __('Ecwid e-commerce widgets', 'ecwid-shopping-cart')
64
  ),
65
- 'ecwid-ecommerce-solution-3' => array (
66
  'name' => 'ecwid-ecommerce-solution-3',
67
  'width' => '165',
68
  'height' => '58',
69
- 'alt' => __('Ecwid ecommerce solution', 'ecwid-shopping-cart')
70
  ),
71
- 'ecwid-free-shopping-cart-3' => array (
72
  'name' => 'ecwid-free-shopping-cart-3',
73
  'width' => '175',
74
  'height' => '58',
75
- 'alt' => __('Ecwid free shopping cart', 'ecwid-shopping-cart')
76
- )
77
  );
78
  }
79
-
80
- protected function _render_widget_content( $args, $instance ) {
81
 
82
- if (!isset($instance['badge_id']) || !array_key_exists($instance['badge_id'], $this->available_badges)) {
 
 
83
  return;
84
  }
85
 
86
- $badge = $this->available_badges[$instance['badge_id']];
87
- $url = sprintf($this->url_template, $badge['name']);
88
 
89
- if (!isset($instance['badge_id']) || !array_key_exists($instance['badge_id'], $this->available_badges)) {
90
  return;
91
  }
92
 
93
- return <<<HTML
94
- <div>
95
- <a target="_blank" rel="nofollow" href="http://www.ecwid.com">
96
- <img src="$url" width="$badge[width]" height="$badge[height]" alt="$badge[alt]" />
97
- </a>
98
- </div>
99
- HTML;
 
100
 
 
101
  }
102
-
103
- function update($new_instance, $old_instance){
104
- $instance = $old_instance;
105
  $instance['badge_id'] =
106
- array_key_exists($new_instance['badge_id'], $this->available_badges)
107
  ? $new_instance['badge_id']
108
  : '';
109
 
110
  return $instance;
111
  }
112
 
113
- function form($instance) {
114
- $instance = wp_parse_args( (array) $instance, array('badge_id' => 'ecwid-shopping-cart-widget-5') );
115
 
116
- foreach ($this->available_badges as $id => $widget) {
117
  $element_id = "badge-$id";
118
- $name = $this->get_field_name('badge_id');
119
- $checked = '';
120
- if (isset($instance['badge_id']) && $instance['badge_id'] == $id) {
121
  $checked = 'checked="checked"';
122
  }
123
- $url = sprintf($this->url_template, $id);
124
- $content = <<<HTML
125
- <label class="ecwid-badge">
126
- <div class="checkbox">
127
- <input name="$name" type="radio" value="$widget[name]"$checked/>
128
- </div>
129
- <div class="image">
130
- <img src="$url" width="$widget[width]" height="$widget[height]" alt="$widget[alt]" />
131
- </div>
132
- </label>
133
- HTML;
134
- echo $content;
135
  }
136
  }
137
- }
4
 
5
  class Ecwid_Widget_Badge extends Ecwid_Widget_Base {
6
 
7
+ public $url_template = 'https://dj925myfyz5v.cloudfront.net/badges/%s.png';
8
+ public $available_badges;
9
 
10
+ public function __construct() {
11
  $this->_hide_title = true;
12
+
13
+ $widget_ops = array(
14
+ 'classname' => 'widget_ecwid_badge',
15
+ 'description' => __( "Do you like Ecwid and want to help it grow? You can add this fancy 'Powered by Ecwid' badge on your site to show your visitors that you're a proud user of Ecwid.", 'ecwid-shopping-cart' ),
16
+ );
17
+ parent::__construct( 'ecwidbadge', __( 'Ecwid Badge', 'ecwid-shopping-cart' ), $widget_ops );
18
 
19
  $this->available_badges = array(
20
+ 'ecwid-shopping-cart-widget-5' => array(
21
  'name' => 'ecwid-shopping-cart-widget-5',
22
  'width' => '73',
23
  'height' => '20',
24
+ 'alt' => __( 'Ecwid shopping cart widget', 'ecwid-shopping-cart' ),
25
  ),
26
+ 'ecwid-shopping-cart-widget-6' => array(
27
  'name' => 'ecwid-shopping-cart-widget-6',
28
  'width' => '73',
29
  'height' => '20',
30
+ 'alt' => __( 'Ecwid shopping cart widget', 'ecwid-shopping-cart' ),
31
  ),
32
+ 'ecwid-ecommerce-solution-2' => array(
33
  'name' => 'ecwid-ecommerce-solution-2',
34
  'width' => '165',
35
  'height' => '58',
36
+ 'alt' => __( 'Ecwid ecommerce solution', 'ecwid-shopping-cart' ),
37
  ),
38
+ 'ecwid-free-shopping-cart-2' => array(
39
  'name' => 'ecwid-free-shopping-cart-2',
40
  'width' => '175',
41
  'height' => '58',
42
+ 'alt' => __( 'Ecwid free shopping cart', 'ecwid-shopping-cart' ),
43
  ),
44
+ 'ecwid-shopping-cart-3' => array(
45
  'name' => 'ecwid-shopping-cart-3',
46
  'width' => '165',
47
  'height' => '56',
48
+ 'alt' => __( 'Ecwid shopping cart', 'ecwid-shopping-cart' ),
49
  ),
50
+ 'ecwid-ecommerce-widgets-3' => array(
51
  'name' => 'ecwid-ecommerce-widgets-3',
52
  'width' => '165',
53
  'height' => '58',
54
+ 'alt' => __( 'Ecwid e-commerce widgets', 'ecwid-shopping-cart' ),
55
  ),
56
+ 'ecwid-shopping-cart-3' => array(
57
  'name' => 'ecwid-shopping-cart-3',
58
  'width' => '165',
59
  'height' => '56',
60
+ 'alt' => __( 'Ecwid shopping cart', 'ecwid-shopping-cart' ),
61
  ),
62
+ 'ecwid-ecommerce-widgets-3' => array(
63
  'name' => 'ecwid-ecommerce-widgets-3',
64
  'width' => '165',
65
  'height' => '58',
66
+ 'alt' => __( 'Ecwid e-commerce widgets', 'ecwid-shopping-cart' ),
67
  ),
68
+ 'ecwid-ecommerce-solution-3' => array(
69
  'name' => 'ecwid-ecommerce-solution-3',
70
  'width' => '165',
71
  'height' => '58',
72
+ 'alt' => __( 'Ecwid ecommerce solution', 'ecwid-shopping-cart' ),
73
  ),
74
+ 'ecwid-free-shopping-cart-3' => array(
75
  'name' => 'ecwid-free-shopping-cart-3',
76
  'width' => '175',
77
  'height' => '58',
78
+ 'alt' => __( 'Ecwid free shopping cart', 'ecwid-shopping-cart' ),
79
+ ),
80
  );
81
  }
 
 
82
 
83
+ protected function _render_widget_content( $args, $instance ) { //phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
84
+
85
+ if ( ! isset( $instance['badge_id'] ) || ! array_key_exists( $instance['badge_id'], $this->available_badges ) ) {
86
  return;
87
  }
88
 
89
+ $badge = $this->available_badges[ $instance['badge_id'] ];
90
+ $url = sprintf( $this->url_template, $badge['name'] );
91
 
92
+ if ( ! isset( $instance['badge_id'] ) || ! array_key_exists( $instance['badge_id'], $this->available_badges ) ) {
93
  return;
94
  }
95
 
96
+ ob_start();
97
+ ?>
98
+ <div>
99
+ <a target="_blank" rel="nofollow" href="http://www.ecwid.com">
100
+ <img src="<?php echo esc_url( $url ); ?>" width="<?php echo esc_attr( $badge['width'] ); ?>" height="<?php echo esc_attr( $badge['height'] ); ?>" alt="<?php echo esc_attr( $badge['alt'] ); ?>" />
101
+ </a>
102
+ </div>
103
+ <?php
104
 
105
+ return ob_get_clean();
106
  }
107
+
108
+ public function update( $new_instance, $old_instance ) {
109
+ $instance = $old_instance;
110
  $instance['badge_id'] =
111
+ array_key_exists( $new_instance['badge_id'], $this->available_badges )
112
  ? $new_instance['badge_id']
113
  : '';
114
 
115
  return $instance;
116
  }
117
 
118
+ public function form( $instance ) {
119
+ $instance = wp_parse_args( (array) $instance, array( 'badge_id' => 'ecwid-shopping-cart-widget-5' ) );
120
 
121
+ foreach ( $this->available_badges as $id => $widget ) {
122
  $element_id = "badge-$id";
123
+ $name = $this->get_field_name( 'badge_id' );
124
+ $checked = '';
125
+ if ( isset( $instance['badge_id'] ) && $instance['badge_id'] == $id ) { //phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
126
  $checked = 'checked="checked"';
127
  }
128
+ $url = sprintf( $this->url_template, $id );
129
+ ?>
130
+ <label class="ecwid-badge">
131
+ <div class="checkbox">
132
+ <input name="<?php echo esc_attr( $name ); ?>" type="radio" value="<?php echo esc_attr( $widget['name'] ); ?>" <?php echo esc_attr( $checked ); ?> />
133
+ </div>
134
+ <div class="image">
135
+ <img src="<?php echo esc_url( $url ); ?>" width="<?php echo esc_attr( $widget['width'] ); ?>" height="<?php echo esc_attr( $widget['height'] ); ?>" alt="<?php echo esc_attr( $widget['alt'] ); ?>" />
136
+ </div>
137
+ </label>
138
+ <?php
 
139
  }
140
  }
141
+ }
includes/widgets/class-ecwid-widget-floating-shopping-cart.php CHANGED
@@ -4,79 +4,84 @@
4
  require_once ECWID_PLUGIN_DIR . '/includes/widgets/class-ecwid-widget-base.php';
5
 
6
  class Ecwid_Widget_Floating_Shopping_Cart extends Ecwid_Widget_Base {
7
- static $was_enqueued = false;
8
-
9
- static protected $positions = array(
10
  'topright',
11
- 'bottomright'
12
  );
13
 
14
  const OPTION_DISPLAY_POSITION = 'ecwid_floating_shopping_cart_mode';
15
- const OPTION_MOVE_INTO_BODY = 'ecwid_move_floating_shopping_cart_into_body';
16
-
17
- static protected $default_position = 'bottomright';
18
 
19
  public function __construct() {
20
- $widget_ops = array('classname' => 'widget_ecwid_floating_shopping_cart', 'description' => __("Adds a shopping cart widget to the top right corner of your site.", 'ecwid-shopping-cart') );
21
- parent::__construct('ecwidfloatingshoppingcart', __('Shopping Cart Floating (deprecated)', 'ecwid-shopping-cart'), $widget_ops);
 
 
 
22
 
23
- add_action('init', array($this, 'init'));
24
  }
25
 
26
  public function init() {
27
- if ( is_active_widget(false, false, $this->id_base, true ) || get_option(self::OPTION_DISPLAY_POSITION) ) {
28
- add_filter( 'body_class', array($this, 'body_class' ) );
29
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
30
  add_action( 'wp_footer', array( $this, 'render' ) );
31
  }
32
  }
33
 
34
  public function enqueue_scripts() {
35
- if (self::$was_enqueued) return;
 
 
36
 
37
- wp_enqueue_script('ecwid-floating-shopping-cart', ECWID_PLUGIN_URL . '/js/floating-shopping-cart.js', array('jquery'), get_option('ecwid_plugin_version'), true);
38
 
39
  $move_to_body = get_option( self::OPTION_MOVE_INTO_BODY );
40
-
41
- if ( $move_to_body == '' ) {
42
  $move_to_body = is_plugin_active( 'wptouch/wptouch.php' );
43
  }
44
-
45
  wp_localize_script(
46
- 'ecwid-floating-shopping-cart',
47
- 'ecwid_floating_shopping_cart_options',
48
  array(
49
- 'move_to_body' => intval($move_to_body)
50
  )
51
  );
52
 
53
- wp_enqueue_style('ecwid-floating-shopping-cart', ECWID_PLUGIN_URL . 'css/floating-shopping-cart.css', array(), get_option('ecwid_plugin_version'));
54
  }
55
 
56
- public function body_class($classes) {
57
  $classes[] = 'ecwid-floating-shopping-cart';
58
 
59
  return $classes;
60
  }
61
 
62
- protected function _render_widget_content( $args, $instance ) {
63
  return '';
64
  }
65
 
66
  public function render() {
67
 
68
- if (Ecwid_Ajax_Defer_Renderer::get_instance()->is_enabled()) {
69
  return;
70
  }
71
 
72
- $position = get_option(self::OPTION_DISPLAY_POSITION);
73
 
74
- if (!$position) {
75
- $options = get_option('widget_ecwidfloatingshoppingcart');
76
 
77
  if ( is_array( $options ) ) {
78
  foreach ( $options as $key => $option ) {
79
- if (is_array($option) && isset($option['position'])) {
80
  $position = $option['position'];
81
  break;
82
  }
@@ -84,10 +89,10 @@ class Ecwid_Widget_Floating_Shopping_Cart extends Ecwid_Widget_Base {
84
  }
85
  }
86
 
87
- if (!$position) {
88
  return;
89
  }
90
- $position = in_array($position, self::$positions) ? $position : self::$default_position;
91
 
92
  if ( Ecwid_Store_Page::is_store_page() ) {
93
  $cart_url = '#!/~/cart';
@@ -95,32 +100,31 @@ class Ecwid_Widget_Floating_Shopping_Cart extends Ecwid_Widget_Base {
95
  $cart_url = Ecwid_Store_Page::get_cart_url();
96
  }
97
 
98
- echo '<!-- noptimize -->';
99
- echo ecwid_get_scriptjs_code();
100
- echo
101
- <<<HTML
102
- <div class="ecwid-float-icons position-$position" ondragstart="return false">
103
- <div class="ecwid-cart-icon off">
104
- <a href="$cart_url" rel="nofollow" data-ecwid-page="cart" data-count="0">
105
- <svg width="20" height="26" viewBox="0 0 20 26" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><path d="M.5 6.5v14.81c0 2.255 1.79 4.084 4 4.084h11c2.21 0 4-1.83 4-4.085V6.5H.5zM6 10.585c.552 0 1-.457 1-1.02C7 9 6.552 8.542 6 8.542S5 9 5 9.563c0 .565.448 1.022 1 1.022zm8 0c.552 0 1-.457 1-1.02 0-.565-.448-1.022-1-1.022S13 9 13 9.563c0 .565.448 1.022 1 1.022z" stroke="#439CA0"/><path d="M14.5 6h-1V4.582c0-1.97-1.57-3.575-3.5-3.575S6.5 2.61 6.5 4.582V6h-1V4.582C5.5 2.048 7.52-.014 10-.014c2.482 0 4.5 2.062 4.5 4.596V6z" fill="#439CA0"/></g></svg>
106
- <div id="ecwid-cart"><script type="text/javascript"> xMinicart("style=","id=ecwid-cart"); </script></div>
107
- </a>
108
- </div>
109
- </div>
110
- <script type="text/javascript">
111
- if (window.EcwidFloatingShoppingCart) {
112
- var ecwid_floating_shopping_cart = new EcwidFloatingShoppingCart();
113
- ecwid_floating_shopping_cart.init();
114
- }
115
- </script>
116
- HTML;
117
- echo '<!-- /noptimize -->';
118
  }
119
 
120
  public function update( $new_instance, $old_instance ) {
121
  $instance = $old_instance;
122
 
123
- $instance['position'] = in_array( $new_instance['position'], self::$positions )
124
  ? $new_instance['position']
125
  : self::$default_position;
126
 
@@ -128,19 +132,19 @@ HTML;
128
  }
129
 
130
  public function form( $instance ) {
131
- $instance = wp_parse_args( (array) $instance, array('position' => self::$default_position ) );
132
 
133
  $position = $instance['position'];
134
 
135
- echo '<p>' . __('Position', 'ecwid-shopping-cart') . ':</p>';
136
- echo '<p><label><input type="radio" name="' . $this->get_field_name('position') . '" value="bottomright"'
137
- . ($position == 'bottomright' ? ' checked="checked"' : '') . '/>'
138
- . __('Bottom right', 'ecwid-shopping-cart')
139
  . '</label></p>';
140
 
141
- echo '<p><label><input type="radio" name="' . $this->get_field_name('position') . '" value="topright"'
142
- . ($position == 'topright' ? ' checked="checked"' : '') . '/>'
143
- . __('Top right', 'ecwid-shopping-cart')
144
  . '</label></p>';
145
 
146
  }
4
  require_once ECWID_PLUGIN_DIR . '/includes/widgets/class-ecwid-widget-base.php';
5
 
6
  class Ecwid_Widget_Floating_Shopping_Cart extends Ecwid_Widget_Base {
7
+ protected static $was_enqueued = false;
8
+
9
+ protected static $positions = array(
10
  'topright',
11
+ 'bottomright',
12
  );
13
 
14
  const OPTION_DISPLAY_POSITION = 'ecwid_floating_shopping_cart_mode';
15
+ const OPTION_MOVE_INTO_BODY = 'ecwid_move_floating_shopping_cart_into_body';
16
+
17
+ protected static $default_position = 'bottomright';
18
 
19
  public function __construct() {
20
+ $widget_ops = array(
21
+ 'classname' => 'widget_ecwid_floating_shopping_cart',
22
+ 'description' => __( 'Adds a shopping cart widget to the top right corner of your site.', 'ecwid-shopping-cart' ),
23
+ );
24
+ parent::__construct( 'ecwidfloatingshoppingcart', __( 'Shopping Cart Floating (deprecated)', 'ecwid-shopping-cart' ), $widget_ops );
25
 
26
+ add_action( 'init', array( $this, 'init' ) );
27
  }
28
 
29
  public function init() {
30
+ if ( is_active_widget( false, false, $this->id_base, true ) || get_option( self::OPTION_DISPLAY_POSITION ) ) {
31
+ add_filter( 'body_class', array( $this, 'body_class' ) );
32
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
33
  add_action( 'wp_footer', array( $this, 'render' ) );
34
  }
35
  }
36
 
37
  public function enqueue_scripts() {
38
+ if ( self::$was_enqueued ) {
39
+ return;
40
+ }
41
 
42
+ wp_enqueue_script( 'ecwid-floating-shopping-cart', ECWID_PLUGIN_URL . '/js/floating-shopping-cart.js', array( 'jquery' ), get_option( 'ecwid_plugin_version' ), true );
43
 
44
  $move_to_body = get_option( self::OPTION_MOVE_INTO_BODY );
45
+
46
+ if ( $move_to_body === '' ) {
47
  $move_to_body = is_plugin_active( 'wptouch/wptouch.php' );
48
  }
49
+
50
  wp_localize_script(
51
+ 'ecwid-floating-shopping-cart',
52
+ 'ecwid_floating_shopping_cart_options',
53
  array(
54
+ 'move_to_body' => intval( $move_to_body ),
55
  )
56
  );
57
 
58
+ wp_enqueue_style( 'ecwid-floating-shopping-cart', ECWID_PLUGIN_URL . 'css/floating-shopping-cart.css', array(), get_option( 'ecwid_plugin_version' ) );
59
  }
60
 
61
+ public function body_class( $classes ) {
62
  $classes[] = 'ecwid-floating-shopping-cart';
63
 
64
  return $classes;
65
  }
66
 
67
+ protected function _render_widget_content( $args, $instance ) { //phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
68
  return '';
69
  }
70
 
71
  public function render() {
72
 
73
+ if ( Ecwid_Ajax_Defer_Renderer::get_instance()->is_enabled() ) {
74
  return;
75
  }
76
 
77
+ $position = get_option( self::OPTION_DISPLAY_POSITION );
78
 
79
+ if ( ! $position ) {
80
+ $options = get_option( 'widget_ecwidfloatingshoppingcart' );
81
 
82
  if ( is_array( $options ) ) {
83
  foreach ( $options as $key => $option ) {
84
+ if ( is_array( $option ) && isset( $option['position'] ) ) {
85
  $position = $option['position'];
86
  break;
87
  }
89
  }
90
  }
91
 
92
+ if ( ! $position ) {
93
  return;
94
  }
95
+ $position = in_array( $position, self::$positions, true ) ? $position : self::$default_position;
96
 
97
  if ( Ecwid_Store_Page::is_store_page() ) {
98
  $cart_url = '#!/~/cart';
100
  $cart_url = Ecwid_Store_Page::get_cart_url();
101
  }
102
 
103
+ ?>
104
+ <!-- noptimize -->
105
+ <?php echo ecwid_get_scriptjs_code(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
106
+ <div class="ecwid-float-icons position-<?php echo esc_attr( $position ); ?>" ondragstart="return false">
107
+ <div class="ecwid-cart-icon off">
108
+ <a href="<?php echo esc_url( $cart_url ); ?>" rel="nofollow" data-ecwid-page="cart" data-count="0">
109
+ <svg width="20" height="26" viewBox="0 0 20 26" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><path d="M.5 6.5v14.81c0 2.255 1.79 4.084 4 4.084h11c2.21 0 4-1.83 4-4.085V6.5H.5zM6 10.585c.552 0 1-.457 1-1.02C7 9 6.552 8.542 6 8.542S5 9 5 9.563c0 .565.448 1.022 1 1.022zm8 0c.552 0 1-.457 1-1.02 0-.565-.448-1.022-1-1.022S13 9 13 9.563c0 .565.448 1.022 1 1.022z" stroke="#439CA0"/><path d="M14.5 6h-1V4.582c0-1.97-1.57-3.575-3.5-3.575S6.5 2.61 6.5 4.582V6h-1V4.582C5.5 2.048 7.52-.014 10-.014c2.482 0 4.5 2.062 4.5 4.596V6z" fill="#439CA0"/></g></svg>
110
+ <div id="ecwid-cart"><script type="text/javascript"> xMinicart("style=","id=ecwid-cart"); </script></div>
111
+ </a>
112
+ </div>
113
+ </div>
114
+ <script type="text/javascript">
115
+ if (window.EcwidFloatingShoppingCart) {
116
+ var ecwid_floating_shopping_cart = new EcwidFloatingShoppingCart();
117
+ ecwid_floating_shopping_cart.init();
118
+ }
119
+ </script>
120
+ <!-- /noptimize -->
121
+ <?php
 
122
  }
123
 
124
  public function update( $new_instance, $old_instance ) {
125
  $instance = $old_instance;
126
 
127
+ $instance['position'] = in_array( $new_instance['position'], self::$positions, true )
128
  ? $new_instance['position']
129
  : self::$default_position;
130
 
132
  }
133
 
134
  public function form( $instance ) {
135
+ $instance = wp_parse_args( (array) $instance, array( 'position' => self::$default_position ) );
136
 
137
  $position = $instance['position'];
138
 
139
+ echo '<p>' . esc_html__( 'Position', 'ecwid-shopping-cart' ) . ':</p>';
140
+ echo '<p><label><input type="radio" name="' . esc_attr( $this->get_field_name( 'position' ) ) . '" value="bottomright"'
141
+ . ( $position === 'bottomright' ? ' checked="checked"' : '' ) . '/>'
142
+ . esc_html__( 'Bottom right', 'ecwid-shopping-cart' )
143
  . '</label></p>';
144
 
145
+ echo '<p><label><input type="radio" name="' . esc_attr( $this->get_field_name( 'position' ) ) . '" value="topright"'
146
+ . ( $position === 'topright' ? ' checked="checked"' : '' ) . '/>'
147
+ . esc_html__( 'Top right', 'ecwid-shopping-cart' )
148
  . '</label></p>';
149
 
150
  }
includes/widgets/class-ecwid-widget-products-base.php CHANGED
@@ -35,7 +35,7 @@ abstract class Ecwid_Widget_Products_List_Base extends Ecwid_Widget_Base {
35
  }
36
 
37
  protected function _init( $title, $description, $widget_name = null, $class_name = null ) {
38
- $this->_title = $title;
39
  $this->_description = $description;
40
  if ( is_null( $widget_name ) ) {
41
  $widget_name = strtolower( $title );
@@ -59,7 +59,7 @@ abstract class Ecwid_Widget_Products_List_Base extends Ecwid_Widget_Base {
59
  }
60
  }
61
 
62
- function _render_widget_content( $args, $instance ) {
63
 
64
  $this->_args = $args;
65
  $this->_instance = wp_parse_args( $instance, array( 'number_of_products' => $this->_default ) );
@@ -83,7 +83,7 @@ abstract class Ecwid_Widget_Products_List_Base extends Ecwid_Widget_Base {
83
  }
84
 
85
  protected function _print_widget_content( $instance ) {
86
- $products = $this->_get_products();
87
 
88
  if ( $products ) {
89
  $this->_print_products( $products );
@@ -94,13 +94,15 @@ abstract class Ecwid_Widget_Products_List_Base extends Ecwid_Widget_Base {
94
  protected function _print_js_init() {
95
 
96
  $data_attr = "data-$this->_class_name-initialized";
97
- echo <<<HTML
98
- <script type="text/javascript">
99
- jQuery(document).ready(function() {
100
- jQuery('.$this->_class_name:not([$data_attr=1])').$this->_widget_class().attr('$data_attr', 1);
101
- });
102
- </script>
103
- HTML;
 
 
104
  }
105
 
106
  protected function _print_products( $products ) {
@@ -121,36 +123,36 @@ HTML;
121
  $name = esc_html( $product->name );
122
  $price = $product->price;
123
 
124
- echo <<<HTML
125
- <a class="product" href="$product->link" data-ecwid-page="product" data-ecwid-product-id="$product->id" alt="$name" title="$name">
126
- <div class="ecwid ecwid-SingleProduct ecwid-Product ecwid-Product-$product->id" data-single-product-link="$product->link" itemscope itemtype="http://schema.org/Product" data-single-product-id="$product->id">
127
- <div itemprop="image" data-force-image="$force_image"></div>
128
- <div class="ecwid-title" itemprop="name" content="$name"></div>
129
- <div itemtype="http://schema.org/Offer" itemscope itemprop="offers"><div class="ecwid-productBrowser-price ecwid-price" itemprop="price" content="$price"></div></div>
130
- </div>
131
- <!-- noptimize --><script type="text/javascript">xSingleProduct();</script><!-- /noptimize -->
132
- </a>
133
- HTML;
134
  $next++;
135
  }//end foreach
136
  }
137
 
138
- function update( $new_instance, $old_instance ) {
139
  $instance = $old_instance;
140
 
141
  foreach ( $this->_get_form_fields() as $field ) {
142
  $name = $field['name'];
143
- if ( $name == 'number_of_products' ) {
144
  $instance[ $name ] = $this->_get_valid_number_of_products( $new_instance['number_of_products'] );
145
  } else {
146
- $instance[ $name ] = strip_tags( stripslashes( $new_instance[ $name ] ) );
147
  }
148
  }
149
 
150
  return $instance;
151
  }
152
 
153
- function form( $instance ) {
154
 
155
  $default_args = array();
156
  foreach ( $this->_get_form_fields() as $field ) {
@@ -170,17 +172,17 @@ HTML;
170
 
171
  printf(
172
  $template,
173
- $this->get_field_name( $field['name'] ),
174
- $field['title'],
175
  'width:100%',
176
- $this->get_field_id( $field['name'] ),
177
- $this->get_field_name( $field['name'] ),
178
- $value
179
  );
180
  }
181
  }
182
 
183
- function _get_valid_number_of_products( $num ) {
184
  $num = intval( $num );
185
  if ( $num > $this->_max ) {
186
  $num = $this->_max;
35
  }
36
 
37
  protected function _init( $title, $description, $widget_name = null, $class_name = null ) {
38
+ $this->_title = $title;
39
  $this->_description = $description;
40
  if ( is_null( $widget_name ) ) {
41
  $widget_name = strtolower( $title );
59
  }
60
  }
61
 
62
+ protected function _render_widget_content( $args, $instance ) {
63
 
64
  $this->_args = $args;
65
  $this->_instance = wp_parse_args( $instance, array( 'number_of_products' => $this->_default ) );
83
  }
84
 
85
  protected function _print_widget_content( $instance ) {
86
+ $products = $this->_get_products();
87
 
88
  if ( $products ) {
89
  $this->_print_products( $products );
94
  protected function _print_js_init() {
95
 
96
  $data_attr = "data-$this->_class_name-initialized";
97
+ ?>
98
+ <script type="text/javascript">
99
+ jQuery(document).ready(function() {
100
+ jQuery('.<?php echo esc_js( $this->_class_name ); ?>:not([<?php echo esc_js( $data_attr ); ?>=1])')
101
+ .<?php echo esc_js( $this->_widget_class ); ?>()
102
+ .attr('<?php echo esc_js( $data_attr ); ?>', 1);
103
+ });
104
+ </script>
105
+ <?php
106
  }
107
 
108
  protected function _print_products( $products ) {
123
  $name = esc_html( $product->name );
124
  $price = $product->price;
125
 
126
+ ?>
127
+ <a class="product" href="<?php echo esc_url( $product->link ); ?>" data-ecwid-product-id="<?php echo esc_attr( $product->id ); ?>" alt="<?php echo esc_attr( $name ); ?>" title="<?php echo esc_attr( $name ); ?>" data-ecwid-page="product">
128
+ <div class="ecwid ecwid-SingleProduct ecwid-Product ecwid-Product-<?php echo esc_attr( $product->id ); ?>" data-single-product-link="<?php echo esc_url( $product->link ); ?>" data-single-product-id="<?php echo esc_attr( $product->id ); ?>" itemscope itemtype="http://schema.org/Product">
129
+ <div itemprop="image" data-force-image="<?php echo esc_attr( $force_image ); ?>"></div>
130
+ <div class="ecwid-title" itemprop="name" content="<?php echo esc_attr( $name ); ?>"></div>
131
+ <div itemtype="http://schema.org/Offer" itemscope itemprop="offers"><div class="ecwid-productBrowser-price ecwid-price" itemprop="price" content="<?php echo esc_attr( $price ); ?>"></div></div>
132
+ </div>
133
+ <!-- noptimize --><script type="text/javascript">xSingleProduct();</script><!-- /noptimize -->
134
+ </a>
135
+ <?php
136
  $next++;
137
  }//end foreach
138
  }
139
 
140
+ public function update( $new_instance, $old_instance ) {
141
  $instance = $old_instance;
142
 
143
  foreach ( $this->_get_form_fields() as $field ) {
144
  $name = $field['name'];
145
+ if ( $name === 'number_of_products' ) {
146
  $instance[ $name ] = $this->_get_valid_number_of_products( $new_instance['number_of_products'] );
147
  } else {
148
+ $instance[ $name ] = wp_strip_all_tags( stripslashes( $new_instance[ $name ] ) );
149
  }
150
  }
151
 
152
  return $instance;
153
  }
154
 
155
+ public function form( $instance ) {
156
 
157
  $default_args = array();
158
  foreach ( $this->_get_form_fields() as $field ) {
172
 
173
  printf(
174
  $template,
175
+ esc_attr( $this->get_field_name( $field['name'] ) ),
176
+ esc_html( $field['title'] ),
177
  'width:100%',
178
+ esc_attr( $this->get_field_id( $field['name'] ) ),
179
+ esc_attr( $this->get_field_name( $field['name'] ) ),
180
+ esc_attr( $value )
181
  );
182
  }
183
  }
184
 
185
+ protected function _get_valid_number_of_products( $num ) {
186
  $num = intval( $num );
187
  if ( $num > $this->_max ) {
188
  $num = $this->_max;
includes/widgets/class-ecwid-widget-random-product.php CHANGED
@@ -4,67 +4,68 @@ require_once ECWID_PLUGIN_DIR . '/includes/widgets/class-ecwid-widget-base.php';
4
 
5
  class Ecwid_Widget_Random_Product extends Ecwid_Widget_Base {
6
 
7
- function __construct() {
8
- $widget_ops = array('classname' => 'widget_ecwid_random_product', 'description' => __("Displays a random product from your store to attract customer attention.", 'ecwid-shopping-cart') );
9
- parent::__construct('ecwidrandomproduct', __('Random Product', 'ecwid-shopping-cart'), $widget_ops);
 
 
 
10
 
11
  }
12
 
13
- function _render_widget_content( $args, $instance ) {
14
  $product = Ecwid_Product::get_random_product();
15
-
16
- if (! $product ) {
17
  return '';
18
  }
19
-
20
  $name = esc_attr( $product->name );
21
-
22
  $url = $product->link;
23
-
24
- $content = <<<HTML
25
- <div class="ecwid ecwid-random-product ecwid-SingleProduct-v2 ecwid-SingleProduct-v2-bordered ecwid-SingleProduct-v2-centered ecwid-Product ecwid-Product-$product->id" itemscope itemtype="http://schema.org/Product" data-single-product-id="$product->id">
26
- <a href="$url" data-ecwid-page="product" data-ecwid-product-id="$product->id"><div itemprop="image"></div></a>
27
- <a href="$url" data-ecwid-page="product" data-ecwid-product-id="$product->id"><div class="ecwid-title" itemprop="name" content="$name"></div></a>
28
- <a href="$url" data-ecwid-page="product" data-ecwid-product-id="$product->id"><div itemtype="http://schema.org/Offer" itemscope itemprop="offers">
29
- <div class="ecwid-productBrowser-price ecwid-price" itemprop="price" content="$product->defaultDisplayedPrice" data-spw-price-location="button">
30
- <div itemprop="priceCurrency"></div>
31
- </div>
32
- </div>
33
- </a>
34
  </div>
35
- <script type="text/javascript">xProduct()</script>
36
- HTML;
37
 
38
- $html = '';
39
  $html .= '<div>';
40
 
41
  $html .= '<!-- noptimize -->';
42
  $html .= ecwid_get_scriptjs_code();
43
  $html .= $content;
44
-
45
  $html .= '<!-- /noptimize -->';
46
  $html .= '</div>';
47
 
48
  return $html;
49
  }
50
 
51
- function update($new_instance, $old_instance){
52
- $instance = $old_instance;
53
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
54
 
55
  return $instance;
56
  }
57
 
58
- function form($instance){
59
- $instance = wp_parse_args( (array) $instance, array('title'=>'') );
60
 
61
- $title = htmlspecialchars($instance['title']);
62
 
63
- if (!$title) {
64
- $title = __('Random Product', 'ecwid-shopping-cart');
65
  }
66
-
67
- echo '<p><label for="' . $this->get_field_name('title') . '">' . __('Title:') . ' <input style="width:100%;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>';
68
  }
69
 
70
  }
4
 
5
  class Ecwid_Widget_Random_Product extends Ecwid_Widget_Base {
6
 
7
+ public function __construct() {
8
+ $widget_ops = array(
9
+ 'classname' => 'widget_ecwid_random_product',
10
+ 'description' => __( 'Displays a random product from your store to attract customer attention.', 'ecwid-shopping-cart' ),
11
+ );
12
+ parent::__construct( 'ecwidrandomproduct', __( 'Random Product', 'ecwid-shopping-cart' ), $widget_ops );
13
 
14
  }
15
 
16
+ protected function _render_widget_content( $args, $instance ) {
17
  $product = Ecwid_Product::get_random_product();
18
+
19
+ if ( ! $product ) {
20
  return '';
21
  }
22
+
23
  $name = esc_attr( $product->name );
24
+
25
  $url = $product->link;
26
+
27
+ $content = "<div class='ecwid ecwid-random-product ecwid-SingleProduct-v2 ecwid-SingleProduct-v2-bordered ecwid-SingleProduct-v2-centered ecwid-Product ecwid-Product-$product->id' itemscope itemtype='http://schema.org/Product' data-single-product-id='$product->id'>
28
+ <a href='$url' data-ecwid-page='product' data-ecwid-product-id='$product->id'><div itemprop='image'></div></a>
29
+ <a href='$url' data-ecwid-page='product' data-ecwid-product-id='$product->id'><div class='ecwid-title' itemprop='name' content='$name'></div></a>
30
+ <a href='$url' data-ecwid-page='product' data-ecwid-product-id='$product->id'><div itemtype='http://schema.org/Offer' itemscope itemprop='offers'>
31
+ <div class='ecwid-productBrowser-price ecwid-price' itemprop='price' content='$product->defaultDisplayedPrice' data-spw-price-location='button'>
32
+ <div itemprop='priceCurrency'></div>
33
+ </div>
34
+ </div>
35
+ </a>
 
36
  </div>
37
+ <script type='text/javascript'>xProduct()</script>";
 
38
 
39
+ $html = '';
40
  $html .= '<div>';
41
 
42
  $html .= '<!-- noptimize -->';
43
  $html .= ecwid_get_scriptjs_code();
44
  $html .= $content;
45
+
46
  $html .= '<!-- /noptimize -->';
47
  $html .= '</div>';
48
 
49
  return $html;
50
  }
51
 
52
+ public function update( $new_instance, $old_instance ) {
53
+ $instance = $old_instance;
54
+ $instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
55
 
56
  return $instance;
57
  }
58
 
59
+ public function form( $instance ) {
60
+ $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
61
 
62
+ $title = htmlspecialchars( $instance['title'] );
63
 
64
+ if ( ! $title ) {
65
+ $title = __( 'Random Product', 'ecwid-shopping-cart' );
66
  }
67
+
68
+ echo '<p><label for="' . esc_attr( $this->get_field_name( 'title' ) ) . '">' . esc_html__( 'Title:' ) . ' <input style="width:100%;" id="' . esc_attr( $this->get_field_id( 'title' ) ) . '" name="' . esc_attr( $this->get_field_name( 'title' ) ) . '" type="text" value="' . esc_attr( $title ) . '" /></label></p>';
69
  }
70
 
71
  }
includes/widgets/class-ecwid-widget-recently-viewed.php CHANGED
@@ -1,97 +1,94 @@
1
  <?php
2
 
3
- require_once dirname(__FILE__) . '/class-ecwid-widget-products-base.php';
4
 
5
  class Ecwid_Widget_Recently_Viewed extends Ecwid_Widget_Products_List_Base {
6
-
7
  protected $_widget_class = 'recentlyViewedProducts';
8
-
9
  public function __construct() {
10
  $this->_init(
11
- __('Recently Viewed Products', 'ecwid-shopping-cart'),
12
- __('Displays a list of products recently viewed by the customer to easily return to the products they saw in your shop.', 'ecwid-shopping-cart'),
13
  'ecwid_recently_viewed',
14
  'ecwid-recently-viewed-products'
15
  );
16
-
17
  parent::__construct();
18
 
19
  $recently_viewed = false;
20
- if (isset($_COOKIE['ecwid-shopping-cart-recently-viewed'])) {
21
- $cookie = sanitize_text_field(wp_unslash($_COOKIE['ecwid-shopping-cart-recently-viewed']));
22
- $recently_viewed = json_decode($cookie);
23
  }
24
 
25
- if ($recently_viewed && $recently_viewed->store_id != get_ecwid_store_id() && !is_admin()) {
26
- setcookie('ecwid-shopping-cart-recently-viewed', null, strtotime('-1 day'));
27
  }
28
  }
29
-
30
  public function enqueue() {
31
  parent::enqueue();
32
-
33
  if ( is_active_widget( false, false, $this->id_base ) ) {
34
- wp_enqueue_script($this->_widget_name, ECWID_PLUGIN_URL . 'js/recently-viewed.js', array('ecwid-products-list-js', 'utils'), get_option('ecwid_plugin_version'));
35
- wp_enqueue_style($this->_widget_name, ECWID_PLUGIN_URL . 'css/recently-viewed.css', array(), get_option('ecwid_plugin_version'));
36
  }
37
  }
38
-
39
  protected function _get_products() {
40
  $recently_viewed = false;
41
- if (isset($_COOKIE['ecwid-shopping-cart-recently-viewed'])) {
42
- $cookie = sanitize_text_field(wp_unslash($_COOKIE['ecwid-shopping-cart-recently-viewed']));
43
- $recently_viewed = json_decode($cookie);
44
  }
45
 
46
- if ($recently_viewed && $recently_viewed->store_id != get_ecwid_store_id()) {
47
  $recently_viewed = null;
48
  }
49
 
50
- if ($recently_viewed && isset($recently_viewed->products)) {
51
  $to_load = array();
52
- foreach ($recently_viewed->products as $product_data) {
53
- $product = Ecwid_Product::get_without_loading($product_data->id);
54
- if (!@$product->imageUrl) {
55
  $to_load[] = $product_data->id;
56
  }
57
  }
58
- if (!empty($to_load)) {
59
- Ecwid_Product::preload_by_ids($to_load);
60
  }
61
  } else {
62
  return null;
63
  }
64
 
65
- return array_reverse($recently_viewed->products);
66
  }
67
-
68
- protected function _print_no_products()
69
- {
70
- $store_link_message = empty($instance['store_link_title']) ? __('You have not viewed any product yet. Open store.', 'ecwid-shopping-cart') : $instance['store_link_title'];
71
- echo '<a class="show-if-empty" href="' . Ecwid_Store_Page::get_store_url() . '">' . $store_link_message . '</a>';
72
-
73
- echo <<<HTML
74
- <script type="text/javascript">
75
- jQuery(document).ready(function() {
76
- wpCookies.remove('ecwid-shopping-cart-recently-viewed');
77
- recently_viewed = {products: []};
78
- });
79
- </script>
80
- HTML;
81
-
82
  }
83
 
84
- protected function _get_form_fields()
85
- {
86
  $fields = parent::_get_form_fields();
87
-
88
  $fields[] = array(
89
- 'name' => 'store_link_title',
90
- 'title' => __('Store Link Title', 'ecwid-shopping-cart'),
91
- 'type' => 'text',
92
- 'default' => __('You have not viewed any product yet. Open store.', 'ecwid-shopping-cart')
93
  );
94
-
95
  return $fields;
96
  }
97
  }
1
  <?php
2
 
3
+ require_once dirname( __FILE__ ) . '/class-ecwid-widget-products-base.php';
4
 
5
  class Ecwid_Widget_Recently_Viewed extends Ecwid_Widget_Products_List_Base {
6
+
7
  protected $_widget_class = 'recentlyViewedProducts';
8
+
9
  public function __construct() {
10
  $this->_init(
11
+ __( 'Recently Viewed Products', 'ecwid-shopping-cart' ),
12
+ __( 'Displays a list of products recently viewed by the customer to easily return to the products they saw in your shop.', 'ecwid-shopping-cart' ),
13
  'ecwid_recently_viewed',
14
  'ecwid-recently-viewed-products'
15
  );
16
+
17
  parent::__construct();
18
 
19
  $recently_viewed = false;
20
+ if ( isset( $_COOKIE['ecwid-shopping-cart-recently-viewed'] ) ) {
21
+ $cookie = sanitize_text_field( wp_unslash( $_COOKIE['ecwid-shopping-cart-recently-viewed'] ) );
22
+ $recently_viewed = json_decode( $cookie );
23
  }
24
 
25
+ if ( $recently_viewed && $recently_viewed->store_id != get_ecwid_store_id() && ! is_admin() ) {
26
+ setcookie( 'ecwid-shopping-cart-recently-viewed', null, strtotime( '-1 day' ) );
27
  }
28
  }
29
+
30
  public function enqueue() {
31
  parent::enqueue();
32
+
33
  if ( is_active_widget( false, false, $this->id_base ) ) {
34
+ wp_enqueue_script( $this->_widget_name, ECWID_PLUGIN_URL . 'js/recently-viewed.js', array( 'ecwid-products-list-js', 'utils' ), get_option( 'ecwid_plugin_version' ) );
35
+ wp_enqueue_style( $this->_widget_name, ECWID_PLUGIN_URL . 'css/recently-viewed.css', array(), get_option( 'ecwid_plugin_version' ) );
36
  }
37
  }
38
+
39
  protected function _get_products() {
40
  $recently_viewed = false;
41
+ if ( isset( $_COOKIE['ecwid-shopping-cart-recently-viewed'] ) ) {
42
+ $cookie = sanitize_text_field( wp_unslash( $_COOKIE['ecwid-shopping-cart-recently-viewed'] ) );
43
+ $recently_viewed = json_decode( $cookie );
44
  }
45
 
46
+ if ( $recently_viewed && $recently_viewed->store_id != get_ecwid_store_id() ) {
47
  $recently_viewed = null;
48
  }
49
 
50
+ if ( $recently_viewed && isset( $recently_viewed->products ) ) {
51
  $to_load = array();
52
+ foreach ( $recently_viewed->products as $product_data ) {
53
+ $product = Ecwid_Product::get_without_loading( $product_data->id );
54
+ if ( ! @$product->imageUrl ) { //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
55
  $to_load[] = $product_data->id;
56
  }
57
  }
58
+ if ( ! empty( $to_load ) ) {
59
+ Ecwid_Product::preload_by_ids( $to_load );
60
  }
61
  } else {
62
  return null;
63
  }
64
 
65
+ return array_reverse( $recently_viewed->products );
66
  }
67
+
68
+ protected function _print_no_products() {
69
+ $store_link_message = empty( $instance['store_link_title'] ) ? __( 'You have not viewed any product yet. Open store.', 'ecwid-shopping-cart' ) : $instance['store_link_title'];
70
+ echo '<a class="show-if-empty" href="' . esc_url( Ecwid_Store_Page::get_store_url() ) . '">' . esc_html( $store_link_message ) . '</a>';
71
+
72
+ ?>
73
+ <script type='text/javascript'>
74
+ jQuery(document).ready(function() {
75
+ wpCookies.remove('ecwid-shopping-cart-recently-viewed');
76
+ recently_viewed = {products: []};
77
+ });
78
+ </script>
79
+ <?php
 
 
80
  }
81
 
82
+ protected function _get_form_fields() {
 
83
  $fields = parent::_get_form_fields();
84
+
85
  $fields[] = array(
86
+ 'name' => 'store_link_title',
87
+ 'title' => __( 'Store Link Title', 'ecwid-shopping-cart' ),
88
+ 'type' => 'text',
89
+ 'default' => __( 'You have not viewed any product yet. Open store.', 'ecwid-shopping-cart' ),
90
  );
91
+
92
  return $fields;
93
  }
94
  }
js/frontend.js CHANGED
@@ -2,11 +2,11 @@ window.ec = window.ec || {};
2
  window.ec.config = window.ec.config || {};
3
  window.ec.config.storefrontUrls = window.ec.config.storefrontUrls || {};
4
 
5
- jQuery(document).ready(function() {
6
-
7
- window.ecwidShoppingCartMakeStoreLinksUseApiCall = function($link) {
8
 
9
- $link.on('click', function() {
 
 
10
  if (typeof Ecwid == 'undefined') {
11
  return true;
12
  }
@@ -16,33 +16,33 @@ jQuery(document).ready(function() {
16
  if (!ecwidParams.useJsApiToOpenStoreCategoriesPages) {
17
  return;
18
  }
19
-
20
  var id = jQuery('[data-ecwid-default-category-id]').data('ecwid-default-category-id');
21
  if (id) {
22
- Ecwid.openPage('category', {id:id});
23
  } else {
24
  Ecwid.openPage('category', 0);
25
  }
26
- } else if (page == 'category' ) {
27
  if (ecwidParams.useJsApiToOpenStoreCategoriesPages) {
28
- Ecwid.openPage('category', {id:jQuery(this).data('ecwid-category-id')});
29
  jQuery(this).hide().blur().show();
30
  } else {
31
  return;
32
  }
33
- } else if ( page == 'product' ) {
34
- Ecwid.openPage('product', {id: jQuery(this).data('ecwid-product-id')});
35
  } else {
36
  Ecwid.openPage(page);
37
  }
38
-
39
  return false;
40
  });
41
  };
42
-
43
  ecwidShoppingCartMakeStoreLinksUseApiCall(jQuery("a[data-ecwid-page]"));
44
 
45
- if ( typeof Ecwid != 'undefined' ) {
46
  Ecwid.OnAPILoaded.add(function () {
47
 
48
  var font = window.ec.config.chameleonDefaults
@@ -51,5 +51,5 @@ jQuery(document).ready(function() {
51
  document.cookie = "ec_store_chameleon_font=" + font;
52
  })
53
  };
54
-
55
  });
2
  window.ec.config = window.ec.config || {};
3
  window.ec.config.storefrontUrls = window.ec.config.storefrontUrls || {};
4
 
5
+ jQuery(document).ready(function () {
 
 
6
 
7
+ window.ecwidShoppingCartMakeStoreLinksUseApiCall = function ($link) {
8
+
9
+ $link.click(function () {
10
  if (typeof Ecwid == 'undefined') {
11
  return true;
12
  }
16
  if (!ecwidParams.useJsApiToOpenStoreCategoriesPages) {
17
  return;
18
  }
19
+
20
  var id = jQuery('[data-ecwid-default-category-id]').data('ecwid-default-category-id');
21
  if (id) {
22
+ Ecwid.openPage('category', { id: id });
23
  } else {
24
  Ecwid.openPage('category', 0);
25
  }
26
+ } else if (page == 'category') {
27
  if (ecwidParams.useJsApiToOpenStoreCategoriesPages) {
28
+ Ecwid.openPage('category', { id: jQuery(this).data('ecwid-category-id') });
29
  jQuery(this).hide().blur().show();
30
  } else {
31
  return;
32
  }
33
+ } else if (page == 'product') {
34
+ Ecwid.openPage('product', { id: jQuery(this).data('ecwid-product-id') });
35
  } else {
36
  Ecwid.openPage(page);
37
  }
38
+
39
  return false;
40
  });
41
  };
42
+
43
  ecwidShoppingCartMakeStoreLinksUseApiCall(jQuery("a[data-ecwid-page]"));
44
 
45
+ if (typeof Ecwid != 'undefined') {
46
  Ecwid.OnAPILoaded.add(function () {
47
 
48
  var font = window.ec.config.chameleonDefaults
51
  document.cookie = "ec_store_chameleon_font=" + font;
52
  })
53
  };
54
+
55
  });
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
- === Ecwid Ecommerce Shopping Cart ===
2
  Contributors: Ecwid
3
  Tags: ecommerce, e-commerce, storefront, shopping cart, online store
4
  Requires at least: 4.4
5
  Tested up to: 6.0
6
- Stable tag: 6.10.25
7
 
8
  Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.
9
 
@@ -152,6 +152,11 @@ You can use Ecwid’s built-in import tools to copy your store products from any
152
 
153
  == Changelog ==
154
 
 
 
 
 
 
155
  = 6.10.25 - Jul 25, 2022 =
156
  - Improvements in the plugin code to comply with the WordPress plugin marketplace recommendations.
157
  - A few fixes for compatibility with Divi builder. If you are using the eсommerce widget in the Divi Builder, you may be faced with an issue where the storefront is not displayed. We fixed that, now it should work fine.
1
+ === Ecwid Ecommerce Shopping Cart ===
2
  Contributors: Ecwid
3
  Tags: ecommerce, e-commerce, storefront, shopping cart, online store
4
  Requires at least: 4.4
5
  Tested up to: 6.0
6
+ Stable tag: 6.10.26
7
 
8
  Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.
9
 
152
 
153
  == Changelog ==
154
 
155
+ = 6.10.26 - Aug 16, 2022 =
156
+ - Compatibility improvements with the Elementor builder. If you are using the ecommerce widget in the Elementor builder, you may have encountered an issue where the storefront links in the menu or sitemap are not working properly. We've fixed it.
157
+ - Plugin code improvements to comply with the WordPress plugin marketplace recommendations.
158
+ - Minor fixes and improvements.
159
+
160
  = 6.10.25 - Jul 25, 2022 =
161
  - Improvements in the plugin code to comply with the WordPress plugin marketplace recommendations.
162
  - A few fixes for compatibility with Divi builder. If you are using the eсommerce widget in the Divi Builder, you may be faced with an issue where the storefront is not displayed. We fixed that, now it should work fine.
templates/admin-message.php CHANGED
@@ -1,22 +1,22 @@
1
  <div class="ecwid-message <?php echo esc_attr( $type ); ?>">
2
- <?php if ( $title ): ?>
3
  <div class="ecwid-message-title">
4
  <?php echo esc_html( $title ); ?>
5
  </div>
6
  <?php endif; ?>
7
 
8
  <div class="ecwid-message-content">
9
- <?php echo $message; ?>
10
  </div>
11
 
12
- <?php if ( $primary_button || $secondary_button || $do_not_show_again ): ?>
13
  <div class="ecwid-message-buttons">
14
- <?php if ($primary_button): ?>
15
  <div>
16
  <a
17
  class="button button-primary"
18
  href="<?php echo esc_attr( $primary_url ); ?>"
19
- <?php if ( $primary_blank ): ?>
20
  target="_blank"
21
  <?php endif; ?>
22
  >
@@ -25,13 +25,16 @@
25
  </div>
26
  <?php endif; ?>
27
 
28
- <?php if ( $secondary_button ): ?>
29
  <div>
30
  <a
31
- class="button<?php if ( $secondary_hide ): ?> ecwid-message-hide<?php endif; ?>"
 
 
 
32
  href="<?php echo esc_attr( $secondary_url ); ?>"
33
- name="<?php echo $name; ?>"
34
- <?php if ( $secondary_blank ): ?>
35
  target="_blank"
36
  <?php endif; ?>
37
  >
@@ -40,14 +43,13 @@
40
  </div>
41
  <?php endif; ?>
42
 
43
- <div class="hide-wrapper">
44
- <?php if ( $do_not_show_again ): ?>
45
-
46
- <a class="ecwid-message-hide" name="<?php echo $name; ?>" href="javascript: void(0);">
47
- <?php _e('Never show this message again', 'ecwid-shopping-cart'); ?>
48
  </a>
49
  <?php endif; ?>
50
- </div>
51
  </div>
52
  <?php endif; ?>
53
- </div>
1
  <div class="ecwid-message <?php echo esc_attr( $type ); ?>">
2
+ <?php if ( $title ) : ?>
3
  <div class="ecwid-message-title">
4
  <?php echo esc_html( $title ); ?>
5
  </div>
6
  <?php endif; ?>
7
 
8
  <div class="ecwid-message-content">
9
+ <?php echo wp_kses_post( $message ); ?>
10
  </div>
11
 
12
+ <?php if ( $primary_button || $secondary_button || $do_not_show_again ) : ?>
13
  <div class="ecwid-message-buttons">
14
+ <?php if ( $primary_button ) : ?>
15
  <div>
16
  <a
17
  class="button button-primary"
18
  href="<?php echo esc_attr( $primary_url ); ?>"
19
+ <?php if ( $primary_blank ) : ?>
20
  target="_blank"
21
  <?php endif; ?>
22
  >
25
  </div>
26
  <?php endif; ?>
27
 
28
+ <?php if ( $secondary_button ) : ?>
29
  <div>
30
  <a
31
+ class="button
32
+ <?php if ( $secondary_hide ) : ?>
33
+ ecwid-message-hide
34
+ <?php endif; ?>"
35
  href="<?php echo esc_attr( $secondary_url ); ?>"
36
+ name="<?php echo esc_attr( $name ); ?>"
37
+ <?php if ( $secondary_blank ) : ?>
38
  target="_blank"
39
  <?php endif; ?>
40
  >
43
  </div>
44
  <?php endif; ?>
45
 
46
+ <div class="hide-wrapper">
47
+ <?php if ( $do_not_show_again ) : ?>
48
+ <a class="ecwid-message-hide" name="<?php echo esc_attr( $name ); ?>" href="javascript: void(0);">
49
+ <?php echo esc_html( __( 'Never show this message again', 'ecwid-shopping-cart' ) ); ?>
 
50
  </a>
51
  <?php endif; ?>
52
+ </div>
53
  </div>
54
  <?php endif; ?>
55
+ </div>
templates/debug.php CHANGED
@@ -9,18 +9,18 @@
9
  $all_options = wp_load_alloptions();
10
  ?>
11
 
12
- <a class="button button-primary" href="admin-post.php?action=ecwid_get_debug" style="margin-top:10px"><?php _e( 'Download log file', 'ecwid-shopping-cart' ); ?></a>
13
 
14
  <h2>Active plugins</h2>
15
 
16
  <div>
17
- <?php foreach ( $active_plugins as $path ) : ?>
18
  <div class="section">
19
  <div>
20
- <?php echo $all_plugins[ $path ]['Name']; ?>
21
  </div>
22
  <div>
23
- <?php echo $all_plugins[ $path ]['PluginURI']; ?>
24
  </div>
25
  </div>
26
  <?php endforeach; ?>
@@ -32,10 +32,10 @@
32
  <?php foreach ( $all_plugins as $key => $item ) : ?>
33
  <div class="section">
34
  <div>
35
- <?php echo $item['Name']; ?>
36
  </div>
37
  <div>
38
- <?php echo $item['PluginURI']; ?>
39
  </div>
40
  </div>
41
  <?php endforeach; ?>
@@ -44,17 +44,17 @@
44
  <h2>Theme</h2>
45
 
46
  <div class="section">
47
- <div><?php echo $theme->get( 'Name' ); ?></div>
48
- <div><?php echo $theme->get( 'ThemeURI' ); ?></div>
49
  </div>
50
 
51
  <h2>Api V3 profile test</h2>
52
  <div>
53
  <?php
54
  if ( is_wp_error( $api_v3_profile_results ) ) {
55
- echo 'WP_Error: ' . $api_v3_profile_results->get_error_message();
56
  } else {
57
- echo 'Response status: ' . implode( ' ', $api_v3_profile_results['response'] );
58
  }
59
  ?>
60
  </div>
@@ -65,7 +65,7 @@
65
  if ( isset( $all_options['ecwid_error_log'] ) ) {
66
  foreach ( json_decode( $all_options['ecwid_error_log'], true ) as $key => $item ) :
67
  ?>
68
- <div class="section"><?php echo htmlspecialchars( $item['message'] ); ?><br><br></div>
69
  <?php
70
  endforeach;
71
  }
@@ -76,11 +76,11 @@
76
  <div>
77
  <div class="section">
78
  <div>Theme identification</div>
79
- <div><?php echo ecwid_get_theme_identification(); ?></div>
80
  </div>
81
  <div class="section">
82
  <div>Affiliate Ref ID</div>
83
- <div><?php echo apply_filters( 'ecwid_get_new_store_ref_id', '' ); ?></div>
84
  </div>
85
  </div>
86
  <h2>Options</h2>
@@ -90,10 +90,10 @@
90
  <?php if ( strpos( $key, 'ecwid' ) !== false ) : ?>
91
  <div class="section">
92
  <div>
93
- <?php echo $key; ?>
94
  </div>
95
  <div>
96
- <?php echo htmlspecialchars( $option ); ?>
97
  </div>
98
  </div>
99
  <?php endif; ?>
@@ -104,7 +104,7 @@
104
  <div>
105
  <?php foreach ( Ecwid_Store_Page::get_store_pages_array() as $page_id ) : ?>
106
  <div>
107
- <a target="_blank" href="post.php?post=<?php echo $page_id; ?>&action=edit"><?php echo @get_post( $page_id )->post_name; ?></a>
108
  <?php if ( $page_id == get_option( Ecwid_Store_Page::OPTION_MAIN_STORE_PAGE_ID ) ) : ?>
109
  <b> - main</b>
110
  <?php endif; ?>
@@ -122,11 +122,11 @@
122
  <div>
123
  <?php foreach ( $wl_config_methods as $method ) : ?>
124
  <div class="section">
125
- <div><?php echo str_replace( 'get_', '', $method ); ?></div>
126
  <div>
127
  <?php
128
  if ( method_exists( 'Ecwid_Config', $method ) ) {
129
- echo Ecwid_Config::$method();
130
  }
131
  ?>
132
 
@@ -134,7 +134,7 @@
134
  </div>
135
  <?php endforeach; ?>
136
  <p>
137
- <a href="admin.php?page=ec_debug&ec-reset-plugin-config" style="margin-top:10px"><?php _e( 'Reset plugin config', 'ecwid-shopping-cart' ); ?></a>
138
  </p>
139
  </div>
140
  <?php endif; ?>
9
  $all_options = wp_load_alloptions();
10
  ?>
11
 
12
+ <a class="button button-primary" href="admin-post.php?action=ecwid_get_debug" style="margin-top:10px"><?php esc_html_e( 'Download log file', 'ecwid-shopping-cart' ); ?></a>
13
 
14
  <h2>Active plugins</h2>
15
 
16
  <div>
17
+ <?php foreach ( $active_plugins as $path ) : // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited ?>
18
  <div class="section">
19
  <div>
20
+ <?php echo esc_html( $all_plugins[ $path ]['Name'] ); ?>
21
  </div>
22
  <div>
23
+ <?php echo esc_url( $all_plugins[ $path ]['PluginURI'] ); ?>
24
  </div>
25
  </div>
26
  <?php endforeach; ?>
32
  <?php foreach ( $all_plugins as $key => $item ) : ?>
33
  <div class="section">
34
  <div>
35
+ <?php echo esc_html( $item['Name'] ); ?>
36
  </div>
37
  <div>
38
+ <?php echo esc_url( $item['PluginURI'] ); ?>
39
  </div>
40
  </div>
41
  <?php endforeach; ?>
44
  <h2>Theme</h2>
45
 
46
  <div class="section">
47
+ <div><?php echo esc_html( $theme->get( 'Name' ) ); ?></div>
48
+ <div><?php echo esc_url( $theme->get( 'ThemeURI' ) ); ?></div>
49
  </div>
50
 
51
  <h2>Api V3 profile test</h2>
52
  <div>
53
  <?php
54
  if ( is_wp_error( $api_v3_profile_results ) ) {
55
+ echo 'WP_Error: ' . esc_html( $api_v3_profile_results->get_error_message() );
56
  } else {
57
+ echo 'Response status: ' . esc_html( implode( ' ', $api_v3_profile_results['response'] ) );
58
  }
59
  ?>
60
  </div>
65
  if ( isset( $all_options['ecwid_error_log'] ) ) {
66
  foreach ( json_decode( $all_options['ecwid_error_log'], true ) as $key => $item ) :
67
  ?>
68
+ <div class="section"><?php echo esc_html( $item['message'] ); ?><br><br></div>
69
  <?php
70
  endforeach;
71
  }
76
  <div>
77
  <div class="section">
78
  <div>Theme identification</div>
79
+ <div><?php echo esc_html( ecwid_get_theme_identification() ); ?></div>
80
  </div>
81
  <div class="section">
82
  <div>Affiliate Ref ID</div>
83
+ <div><?php echo esc_html( apply_filters( 'ecwid_get_new_store_ref_id', '' ) ); ?></div>
84
  </div>
85
  </div>
86
  <h2>Options</h2>
90
  <?php if ( strpos( $key, 'ecwid' ) !== false ) : ?>
91
  <div class="section">
92
  <div>
93
+ <?php echo esc_html( $key ); ?>
94
  </div>
95
  <div>
96
+ <?php echo esc_html( $option ); ?>
97
  </div>
98
  </div>
99
  <?php endif; ?>
104
  <div>
105
  <?php foreach ( Ecwid_Store_Page::get_store_pages_array() as $page_id ) : ?>
106
  <div>
107
+ <a target="_blank" href="post.php?post=<?php echo esc_attr( $page_id ); ?>&action=edit"><?php echo esc_html( @get_post( $page_id )->post_name ); ?></a>
108
  <?php if ( $page_id == get_option( Ecwid_Store_Page::OPTION_MAIN_STORE_PAGE_ID ) ) : ?>
109
  <b> - main</b>
110
  <?php endif; ?>
122
  <div>
123
  <?php foreach ( $wl_config_methods as $method ) : ?>
124
  <div class="section">
125
+ <div><?php echo esc_html( str_replace( 'get_', '', $method ) ); ?></div>
126
  <div>
127
  <?php
128
  if ( method_exists( 'Ecwid_Config', $method ) ) {
129
+ echo esc_html( Ecwid_Config::$method() );
130
  }
131
  ?>
132
 
134
  </div>
135
  <?php endforeach; ?>
136
  <p>
137
+ <a href="admin.php?page=ec_debug&ec-reset-plugin-config" style="margin-top:10px"><?php esc_html_e( 'Reset plugin config', 'ecwid-shopping-cart' ); ?></a>
138
  </p>
139
  </div>
140
  <?php endif; ?>
templates/product.php CHANGED
@@ -1,6 +1,3 @@
1
  <?php
2
- $content = <<<HTML
3
- <script>xProductBrowser('defaultProductId=$ecwid_id');</script>
4
- HTML;
5
- echo ecwid_wrap_shortcode_content($content, 'product', array());
6
- ?>
1
  <?php
2
+ $content = "<script>xProductBrowser('defaultProductId=$ecwid_id');</script>";
3
+ echo ecwid_wrap_shortcode_content( $content, 'product', array() );