Plugin Directory

Changeset 3116030


Ignore:
Timestamp:
07/11/2024 05:39:00 AM (21 months ago)
Author:
Ecwid
Message:

Update to version 6.12.15 from GitHub

Location:
ecwid-shopping-cart
Files:
22 edited
1 copied

Legend:

Unmodified
Added
Removed
  • ecwid-shopping-cart/tags/6.12.15/ecwid-shopping-cart.php

    r3110860 r3116030  
    66Text Domain: ecwid-shopping-cart
    77Author: Ecwid Ecommerce
    8 Version: 6.12.14
     8Version: 6.12.15
    99Author URI: https://ecwid.to/ecwid-site
    1010License: GPLv2 or later
     
    24132413   
    24142414    $query_params = array(
    2415         'hidden_categories' => true
     2415        'hidden_categories' => true,
     2416        'responseFields' => 'total,count,items(id,name,url,enabled,parentId)'
    24162417    );
    24172418
     
    24482449        }
    24492450    }
    2450    
    2451     $parents = array();
    24522451
    24532452    $result = array();
  • ecwid-shopping-cart/tags/6.12.15/includes/class-ecwid-admin-storefront-page.php

    r3002218 r3116030  
    3333
    3434        if ( $page_id && ! isset( $page_status ) ) {
    35 
    3635            $page_data = self::get_page_data( $page_id );
    3736            extract( $page_data, EXTR_PREFIX_ALL, 'page' );
     
    7170
    7271            $api = new Ecwid_Api_V3();
    73             $res = $api->get_products( array() );
     72            $res = $api->get_products( array( 'responseFields' => 'total,count,items(id,name)' ) );
    7473            if ( $res ) {
    7574                $products       = $res->items;
     
    9796        wp_enqueue_script( 'ecwid-admin-storefront-js', ECWID_PLUGIN_URL . 'js/admin-storefront.js', array(), get_option( 'ecwid_plugin_version' ) );
    9897
    99         wp_localize_script(
    100             'ecwid-admin-storefront-js',
    101             'EcwidAdminStorefront',
    102             array(
    103                 '_ajax_nonce' => wp_create_nonce( self::NONCE_SLUG )
    104             )
    105         );
     98        wp_localize_script(
     99            'ecwid-admin-storefront-js',
     100            'EcwidAdminStorefront',
     101            array(
     102                '_ajax_nonce' => wp_create_nonce( self::NONCE_SLUG ),
     103            )
     104        );
    106105
    107106        Ecwid_Admin_UI_Framework::print_fix_js();
     
    131130
    132131    public function ajax_set_status() {
    133         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    134             die();
    135         }
     132        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     133            die();
     134        }
    136135
    137136        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    173172
    174173    public function ajax_set_store_on_front() {
    175         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    176             die();
    177         }
     174        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     175            die();
     176        }
    178177
    179178        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    208207
    209208    public function ajax_set_mainpage() {
    210         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    211             die();
    212         }
     209        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     210            die();
     211        }
    213212
    214213        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    245244
    246245    public function ajax_set_display_cart_icon() {
    247         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    248             die();
    249         }
     246        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     247            die();
     248        }
    250249
    251250        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    266265
    267266    public function ajax_set_page_slug() {
    268         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    269             die();
    270         }
     267        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     268            die();
     269        }
    271270
    272271        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    316315
    317316    public function ajax_create_page() {
    318         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    319             die();
    320         }
     317        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     318            die();
     319        }
    321320
    322321        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    480479
    481480        if ( version_compare( $version, '5.0' ) < 0 ) {
    482 
    483481            if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
    484482                return true;
     
    573571            }
    574572
    575             echo sprintf( '<li><a%s>%s</a></li>', wp_kses_post( $attributes ), esc_html( $text ) );
     573            printf( '<li><a%s>%s</a></li>', wp_kses_post( $attributes ), esc_html( $text ) );
    576574        }//end foreach
    577575    }
  • ecwid-shopping-cart/tags/6.12.15/includes/class-ecwid-nav-menus.php

    r3021774 r3116030  
    241241                    $posts  = array();
    242242                    $api    = new Ecwid_Api_V3();
    243                     $result = $api->get_categories( array( 'parent' => 0 ) );
     243                    $result = $api->get_categories(
     244                        array(
     245                            'parent'         => 0,
     246                            'responseFields' => 'total,count,items(id,name,url,nameTranslated,orderBy)',
     247                        )
     248                    );
    244249
    245250                    if ( $result && $result->count > 0 ) {
  • ecwid-shopping-cart/tags/6.12.15/includes/class-ecwid-seo-links.php

    r3110860 r3116030  
    330330
    331331    public function build_rewrite_rules( $rules ) {
    332         $new_rules = array();
     332        $new_rules        = array();
     333        $additional_rules = array();
    333334
    334335        $all_base_urls = $this->_build_all_base_urls();
  • ecwid-shopping-cart/tags/6.12.15/includes/class-ecwid-static-page.php

    r3110860 r3116030  
    181181                $cached_data->cssFiles = array( $dynamic_css ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
    182182
    183                 EcwidPlatform::store_in_static_pages_cache( $url, $cached_data );
     183                EcwidPlatform::save_in_static_pages_cache( $url, $cached_data );
    184184            }
    185185
     
    222222            }
    223223
     224            EcwidPlatform::encode_fields_with_emoji(
     225                $fetched_data,
     226                array( 'htmlCode', 'metaDescriptionHtml', 'ogTagsHtml', 'jsonLDHtml' )
     227            );
     228
    224229            if ( isset( $fetched_data->lastUpdated ) ) {
    225230                $last_update = substr( $fetched_data->lastUpdated, 0, -3 );
     
    230235
    231236            EcwidPlatform::invalidate_static_pages_cache_from( $last_update );
    232             EcwidPlatform::store_in_static_pages_cache( $url, $fetched_data );
     237            EcwidPlatform::save_in_static_pages_cache( $url, $fetched_data );
    233238
    234239            return $fetched_data;
  • ecwid-shopping-cart/tags/6.12.15/includes/gutenberg/class-ecwid-gutenberg-block-store.php

    r3093942 r3116030  
    287287        }//end foreach
    288288
    289         $categories = ecwid_get_categories_for_selector();
    290 
    291         if ( $categories ) {
    292             $attributes['default_category_id']['values'] = array(
    293                 array(
    294                     'value' => '0',
    295                     'title' => __( 'Store root category', 'ecwid-shopping-cart' ),
    296                 ),
    297             );
    298             foreach ( $categories as $category ) {
    299                 if ( empty( $category->enabled ) ) {
    300                     continue;
    301                 }
    302 
    303                 $attributes['default_category_id']['values'][] = array(
    304                     'value' => $category->id,
    305                     'title' => $category->name,
     289        if ( is_admin() ) {
     290            $categories = ecwid_get_categories_for_selector();
     291
     292            if ( $categories ) {
     293                $attributes['default_category_id']['values'] = array(
     294                    array(
     295                        'value' => '0',
     296                        'title' => __( 'Store root category', 'ecwid-shopping-cart' ),
     297                    ),
    306298                );
    307             }
    308 
    309             $attributes['default_category_id']['default'] = '';
    310         } else {
    311             $api  = new Ecwid_Api_V3();
    312             $cats = $api->get_categories( array() );
    313 
    314             if ( $cats && $cats->total == 0 ) {
    315                 unset( $attributes['default_category_id'] );
    316             }
     299                foreach ( $categories as $category ) {
     300                    if ( empty( $category->enabled ) ) {
     301                        continue;
     302                    }
     303
     304                    $attributes['default_category_id']['values'][] = array(
     305                        'value' => $category->id,
     306                        'title' => $category->name,
     307                    );
     308                }
     309
     310                $attributes['default_category_id']['default'] = '';
     311            } else {
     312                $api  = new Ecwid_Api_V3();
     313                $cats = $api->get_categories( array() );
     314
     315                if ( $cats && $cats->total == 0 ) {
     316                    unset( $attributes['default_category_id'] );
     317                }
     318            }//end if
    317319        }//end if
    318320
  • ecwid-shopping-cart/tags/6.12.15/includes/themes/class-ecwid-theme-base.php

    r2813294 r3116030  
    6868
    6969        if ( in_array( 'title', $props, true ) ) {
    70 
    7170            $store_page_params = Ecwid_Store_Page::get_store_page_params();
    7271
    73             if ( @$store_page_params['product_details_show_product_name'] ) {
     72            if ( ! empty( $store_page_params['product_details_show_product_name'] ) ) {
    7473                add_filter( 'option_' . Ecwid_Store_Page::OPTION_REPLACE_TITLE, '__return_false' );
    7574            }
     
    126125        );
    127126    }
    128 
    129127}
  • ecwid-shopping-cart/tags/6.12.15/lib/ecwid_api_v3.php

    r3059103 r3116030  
    164164        }
    165165
    166         $passthru = array( 'offset', 'limit', 'parent', 'baseUrl', 'cleanUrls', 'hidden_categories' );
     166        $passthru = array( 'offset', 'limit', 'parent', 'baseUrl', 'cleanUrls', 'hidden_categories', 'responseFields' );
    167167        foreach ( $passthru as $name ) {
    168168            if ( array_key_exists( $name, $input_params ) ) {
     
    190190        if ( ! $result ) {
    191191            $result = EcwidPlatform::fetch_url( $url, $options );
    192         }
    193 
    194         if ( $result['code'] != '200' ) {
    195             return false;
    196         }
    197 
    198         EcwidPlatform::store_in_categories_cache( $url, $result );
     192
     193            if ( $result['code'] != '200' ) {
     194                return false;
     195            }
     196
     197            // PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     198            $data = json_decode( $result['data'] );
     199
     200            if ( ! empty( $data->items ) ) {
     201                foreach ( $data->items as &$item ) {
     202                    $item = EcwidPlatform::encode_fields_with_emoji(
     203                        $item,
     204                        array( 'name', 'nameTranslated', 'description', 'descriptionTranslated', 'seoTitle', 'seoTitleTranslated', 'seoDescription', 'seoDescriptionTranslated', 'alt' )
     205                    );
     206                }
     207            }
     208
     209            $result['data'] = wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
     210            // end PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     211
     212            EcwidPlatform::store_in_categories_cache( $url, $result );
     213        }//end if
    199214
    200215        $result = json_decode( $result['data'] );
     
    249264        if ( ! $result ) {
    250265            $result = EcwidPlatform::fetch_url( $url, $options );
    251         }
    252 
    253         if ( $result['code'] != '200' ) {
    254             return false;
    255         }
    256 
    257         EcwidPlatform::store_in_categories_cache( $url, $result );
     266
     267            if ( $result['code'] != '200' ) {
     268                return false;
     269            }
     270
     271            // PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     272            $data = json_decode( $result['data'] );
     273            if ( ! empty( $data ) ) {
     274                $data = EcwidPlatform::encode_fields_with_emoji(
     275                    $data,
     276                    array( 'name', 'nameTranslated', 'description', 'descriptionTranslated', 'seoTitle', 'seoTitleTranslated', 'seoDescription', 'seoDescriptionTranslated', 'alt' )
     277                );
     278            }
     279            // end PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     280
     281            $result['data'] = wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
     282
     283            EcwidPlatform::store_in_categories_cache( $url, $result );
     284        }//end if
    258285
    259286        $result = json_decode( $result['data'] );
     
    398425        $params = array();
    399426
    400         $passthru = array( 'updatedFrom', 'offset', 'limit', 'sortBy', 'keyword', 'createdFrom', 'createdTo', 'sku', 'enabled' );
     427        $passthru = array( 'updatedFrom', 'offset', 'limit', 'sortBy', 'keyword', 'createdFrom', 'createdTo', 'sku', 'enabled', 'responseFields' );
    401428
    402429        foreach ( $passthru as $name ) {
     
    601628
    602629        $profile = json_decode( $result['data'] );
     630
     631        // PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     632        if ( ! empty( $profile ) ) {
     633            $profile->settings = EcwidPlatform::encode_fields_with_emoji(
     634                $profile->settings,
     635                array( 'storeName', 'storeDescription', 'storeDescriptionTranslated', 'rootCategorySeoTitleTranslated', 'rootCategorySeoDescription', 'rootCategorySeoDescriptionTranslated' )
     636            );
     637        }
     638        // end PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
    603639
    604640        EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 10 * MINUTE_IN_SECONDS );
  • ecwid-shopping-cart/tags/6.12.15/lib/ecwid_catalog.php

    r2640505 r3116030  
    11<?php
    22
    3 class EcwidCatalog
    4 {
    5     var $store_id = 0;
     3class EcwidCatalog {
     4
     5    var $store_id       = 0;
    66    var $store_base_url = '';
    77
    8     public function __construct($store_id, $store_base_url)
    9     {
    10         $this->store_id = intval($store_id);
    11         $this->store_base_url = $store_base_url;   
     8    public function __construct( $store_id, $store_base_url ) {
     9        $this->store_id       = intval( $store_id );
     10        $this->store_base_url = $store_base_url;
    1211    }
    1312
    14     public function warmup_store_page( $category_id )
    15     {
     13    public function warmup_store_page( $category_id ) {
    1614        $this->_get_data_for_category( $category_id, null );
    1715    }
    18    
    19     public function get_product($id)
    20     {
    21         $result = $this->_get_data_for_product($id);
    2216
    23         if ( !$result ) {
     17    public function get_product( $id ) {
     18        $result = $this->_get_data_for_product( $id );
     19
     20        if ( ! $result ) {
    2421            return '';
    2522        }
    26        
     23
    2724        ob_start();
    2825        $product = $result->product;
    2926        $formats = $result->formats;
    30         require dirname(__FILE__) . '/html-catalog-templates/product.php';
    31 
    32         $return = ob_get_contents();
    33         ob_end_clean();
    34        
    35         return $return;
    36     }
    37 
    38     public function get_category($id)
    39     {
    40         $offset = ( isset($_GET['offset']) ) ? intval($_GET['offset']) : 0;
    41         $data = $this->_get_data_for_category( $id, $offset );
    42        
    43         if ( !$data ) {
    44             return '';
    45         }
    46        
    47         $main_category = null;
    48         if ($id > 0) {
    49             $main_category = $data->main_category;
    50         }
    51         $categories = $data->categories;
    52         $products = $data->products;
    53         $formats = $data->formats;
    54        
    55         ob_start();
    56         require dirname(__FILE__) . '/html-catalog-templates/category.php';
     27        require __DIR__ . '/html-catalog-templates/product.php';
    5728
    5829        $return = ob_get_contents();
     
    6233    }
    6334
    64     protected function _get_data_for_product( $id )
    65     {
     35    public function get_category( $id ) {
     36        $offset = ( isset( $_GET['offset'] ) ) ? intval( $_GET['offset'] ) : 0;
     37        $data   = $this->_get_data_for_category( $id, $offset );
     38
     39        if ( ! $data ) {
     40            return '';
     41        }
     42
     43        $main_category = null;
     44        if ( $id > 0 ) {
     45            $main_category = $data->main_category;
     46        }
     47        $categories = $data->categories;
     48        $products   = $data->products;
     49        $formats    = $data->formats;
     50
     51        ob_start();
     52        require __DIR__ . '/html-catalog-templates/category.php';
     53
     54        $return = ob_get_contents();
     55        ob_end_clean();
     56
     57        return $return;
     58    }
     59
     60    protected function _get_data_for_product( $id ) {
    6661        if ( Ecwid_Api_V3::is_available() ) {
    6762            $api = new Ecwid_Api_V3();
    68            
     63
    6964            $product = Ecwid_Product::get_by_id( $id );
    70            
     65
    7166            $profile = $api->get_store_profile();
    72            
    73             if (!$profile) {
     67
     68            if ( ! $profile ) {
    7469                return null;
    7570            }
    76            
     71
    7772            return (object) array(
    7873                'product' => $product,
    79                 'formats' => @$profile->formatsAndUnits
     74                'formats' => @$profile->formatsAndUnits,
    8075            );
    81         } 
    82        
     76        }
     77
    8378        return null;
    8479    }
    85    
    86     protected function _get_data_for_category( $id, $offset = 0 )
    87     {
     80
     81    protected function _get_data_for_category( $id, $offset = 0 ) {
    8882        if ( Ecwid_Api_V3::is_available() ) {
    8983            $api = new Ecwid_Api_V3();
    90            
     84
    9185            $main_category = null;
    92             if ($id > 0) {
     86            if ( $id > 0 ) {
    9387                $main_category = $api->get_category( $id );
    9488            }
    9589
    9690            $get_categories_params = array(
    97                 'parent' => $id
     91                'parent' => $id,
    9892            );
    99             if ($offset && $offset > 0) {
     93            if ( $offset && $offset > 0 ) {
    10094                $get_categories_params['offset'] = $offset;
    10195            }
    10296            $categories = $api->get_categories( $get_categories_params );
    103            
     97
    10498            $get_products_params = array(
    105                 'category' => $id
     99                'category' => $id,
    106100            );
    107             if ($offset) {
     101            if ( $offset ) {
    108102                $get_products_params['offset'] = $offset;
    109103            }
    110104            $products = $api->search_products( $get_products_params );
    111            
     105
    112106            $profile = $api->get_store_profile();
    113            
    114             if ( is_null( $profile ) || !isset( $categories->items ) || !isset( $products->items ) ) {
     107
     108            if ( is_null( $profile ) || ! isset( $categories->items ) || ! isset( $products->items ) ) {
    115109                return null;
    116110            }
    117            
     111
    118112            return (object) array(
    119113                'main_category' => $main_category,
    120                 'categories' => $categories->items,
    121                 'products' => $products->items,
    122                 'formats' => @$profile->formatsAndUnits
     114                'categories'    => $categories->items,
     115                'products'      => $products->items,
     116                'formats'       => @$profile->formatsAndUnits,
    123117            );
    124         } 
    125        
     118        }//end if
     119
    126120        return null;
    127121    }
    128    
    129     public function parse_escaped_fragment($escaped_fragment)
    130     {
    131         $fragment = urldecode($escaped_fragment);
    132         $return = array();
    133122
    134         if (preg_match('/^(\/~\/)([a-z]+)\/(.*)$/', $fragment, $matches)) {
    135             parse_str($matches[3], $return);
     123    public function parse_escaped_fragment( $escaped_fragment ) {
     124        $fragment = urldecode( $escaped_fragment );
     125        $return   = array();
     126
     127        if ( preg_match( '/^(\/~\/)([a-z]+)\/(.*)$/', $fragment, $matches ) ) {
     128            parse_str( $matches[3], $return );
    136129            $return['mode'] = $matches[2];
    137         } elseif (preg_match('!.*/(p|c)/([0-9]*)!', $fragment, $matches)) {
    138             if (count($matches) == 3 && in_array($matches[1], array('p', 'c'))) {
    139                 $return  = array(
     130        } elseif ( preg_match( '!.*/(p|c)/([0-9]*)!', $fragment, $matches ) ) {
     131            if ( count( $matches ) == 3 && in_array( $matches[1], array( 'p', 'c' ) ) ) {
     132                $return = array(
    140133                    'mode' => 'p' == $matches[1] ? 'product' : 'category',
    141                     'id' => $matches[2]
     134                    'id'   => $matches[2],
    142135                );
    143136            }
  • ecwid-shopping-cart/tags/6.12.15/lib/ecwid_platform.php

    r3110860 r3116030  
    226226            )
    227227        );
    228         self::encode_emoji( $value );
    229228
    230229        set_transient( 'ecwid_' . $name, $value, $expires_after );
    231230    }
    232231
     232    public static function encode_fields_with_emoji( $data, $properties = array() ) {
     233        if ( ! is_object( $data ) ) {
     234            return $data;
     235        }
     236
     237        if ( ! is_array( $properties ) ) {
     238            return $data;
     239        }
     240
     241        foreach ( $properties as $property ) {
     242            if ( ! empty( $data->$property ) ) {
     243                if ( is_string( $data->$property ) ) {
     244                    $data->$property = wp_encode_emoji( $data->$property );
     245                } else {
     246                    self::encode_emoji( $data->$property );
     247                }
     248            }
     249        }
     250        return $data;
     251    }
     252
    233253    public static function encode_emoji( &$item, $key = false ) { //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
     254        if ( empty( $item ) ) {
     255            return;
     256        }
     257
    234258        if ( is_object( $item ) || is_array( $item ) ) {
    235259            array_walk_recursive( $item, 'self::encode_emoji' );
     
    306330        }
    307331
    308         if ( $return['code'] == 200 ) {
     332        if ( $return['code'] == 200 && $api_check_retry_after !== 0 ) {
    309333            update_option( self::OPTION_ECWID_CHECK_API_RETRY_AFTER, 0 );
    310334        }
     
    377401
    378402    public static function store_in_products_cache( $url, $data ) {
    379         self::store_in_cache( $url, 'products', $data, WEEK_IN_SECONDS );
     403        self::save_in_cache( $url, 'products', $data, WEEK_IN_SECONDS );
    380404    }
    381405
    382406    public static function store_in_categories_cache( $url, $data ) {
    383         self::store_in_cache( $url, 'categories', $data, WEEK_IN_SECONDS );
    384     }
    385 
    386     public static function store_in_static_pages_cache( $url, $data ) {
    387         self::store_in_cache( $url, 'catalog', $data, WEEK_IN_SECONDS );
    388     }
    389 
    390     protected static function store_in_cache( $url, $type, $data, $expires_after ) {
     407        self::save_in_cache( $url, 'categories', $data, WEEK_IN_SECONDS );
     408    }
     409
     410    public static function save_in_static_pages_cache( $url, $data ) {
     411        self::save_in_cache( $url, 'catalog', $data, WEEK_IN_SECONDS );
     412    }
     413
     414    protected static function save_in_cache( $url, $type, $data, $expires_after ) {
    391415        $name = self::_build_cache_name( $url, $type );
    392416
  • ecwid-shopping-cart/tags/6.12.15/readme.txt

    r3112458 r3116030  
    154154
    155155== Changelog ==
     156= 6.12.15 - Jul 10, 2024 =
     157- After the last update, the our ecommerce plugin could cause an issue with urls and an issue with loading the admin area. We have fixed these issues.
     158
    156159= 6.12.14 - Jul 2, 2024 =
    157160- Fixed issues with slow loading of storefront pages that were observed in certain scenarios when using our ecommerce plugin.
  • ecwid-shopping-cart/trunk/ecwid-shopping-cart.php

    r3110860 r3116030  
    66Text Domain: ecwid-shopping-cart
    77Author: Ecwid Ecommerce
    8 Version: 6.12.14
     8Version: 6.12.15
    99Author URI: https://ecwid.to/ecwid-site
    1010License: GPLv2 or later
     
    24132413   
    24142414    $query_params = array(
    2415         'hidden_categories' => true
     2415        'hidden_categories' => true,
     2416        'responseFields' => 'total,count,items(id,name,url,enabled,parentId)'
    24162417    );
    24172418
     
    24482449        }
    24492450    }
    2450    
    2451     $parents = array();
    24522451
    24532452    $result = array();
  • ecwid-shopping-cart/trunk/includes/class-ecwid-admin-storefront-page.php

    r3002218 r3116030  
    3333
    3434        if ( $page_id && ! isset( $page_status ) ) {
    35 
    3635            $page_data = self::get_page_data( $page_id );
    3736            extract( $page_data, EXTR_PREFIX_ALL, 'page' );
     
    7170
    7271            $api = new Ecwid_Api_V3();
    73             $res = $api->get_products( array() );
     72            $res = $api->get_products( array( 'responseFields' => 'total,count,items(id,name)' ) );
    7473            if ( $res ) {
    7574                $products       = $res->items;
     
    9796        wp_enqueue_script( 'ecwid-admin-storefront-js', ECWID_PLUGIN_URL . 'js/admin-storefront.js', array(), get_option( 'ecwid_plugin_version' ) );
    9897
    99         wp_localize_script(
    100             'ecwid-admin-storefront-js',
    101             'EcwidAdminStorefront',
    102             array(
    103                 '_ajax_nonce' => wp_create_nonce( self::NONCE_SLUG )
    104             )
    105         );
     98        wp_localize_script(
     99            'ecwid-admin-storefront-js',
     100            'EcwidAdminStorefront',
     101            array(
     102                '_ajax_nonce' => wp_create_nonce( self::NONCE_SLUG ),
     103            )
     104        );
    106105
    107106        Ecwid_Admin_UI_Framework::print_fix_js();
     
    131130
    132131    public function ajax_set_status() {
    133         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    134             die();
    135         }
     132        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     133            die();
     134        }
    136135
    137136        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    173172
    174173    public function ajax_set_store_on_front() {
    175         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    176             die();
    177         }
     174        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     175            die();
     176        }
    178177
    179178        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    208207
    209208    public function ajax_set_mainpage() {
    210         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    211             die();
    212         }
     209        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     210            die();
     211        }
    213212
    214213        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    245244
    246245    public function ajax_set_display_cart_icon() {
    247         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    248             die();
    249         }
     246        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     247            die();
     248        }
    250249
    251250        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    266265
    267266    public function ajax_set_page_slug() {
    268         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    269             die();
    270         }
     267        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     268            die();
     269        }
    271270
    272271        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    316315
    317316    public function ajax_create_page() {
    318         if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
    319             die();
    320         }
     317        if ( ! check_ajax_referer( self::NONCE_SLUG ) ) {
     318            die();
     319        }
    321320
    322321        if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
     
    480479
    481480        if ( version_compare( $version, '5.0' ) < 0 ) {
    482 
    483481            if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
    484482                return true;
     
    573571            }
    574572
    575             echo sprintf( '<li><a%s>%s</a></li>', wp_kses_post( $attributes ), esc_html( $text ) );
     573            printf( '<li><a%s>%s</a></li>', wp_kses_post( $attributes ), esc_html( $text ) );
    576574        }//end foreach
    577575    }
  • ecwid-shopping-cart/trunk/includes/class-ecwid-nav-menus.php

    r3021774 r3116030  
    241241                    $posts  = array();
    242242                    $api    = new Ecwid_Api_V3();
    243                     $result = $api->get_categories( array( 'parent' => 0 ) );
     243                    $result = $api->get_categories(
     244                        array(
     245                            'parent'         => 0,
     246                            'responseFields' => 'total,count,items(id,name,url,nameTranslated,orderBy)',
     247                        )
     248                    );
    244249
    245250                    if ( $result && $result->count > 0 ) {
  • ecwid-shopping-cart/trunk/includes/class-ecwid-seo-links.php

    r3110860 r3116030  
    330330
    331331    public function build_rewrite_rules( $rules ) {
    332         $new_rules = array();
     332        $new_rules        = array();
     333        $additional_rules = array();
    333334
    334335        $all_base_urls = $this->_build_all_base_urls();
  • ecwid-shopping-cart/trunk/includes/class-ecwid-static-page.php

    r3110860 r3116030  
    181181                $cached_data->cssFiles = array( $dynamic_css ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
    182182
    183                 EcwidPlatform::store_in_static_pages_cache( $url, $cached_data );
     183                EcwidPlatform::save_in_static_pages_cache( $url, $cached_data );
    184184            }
    185185
     
    222222            }
    223223
     224            EcwidPlatform::encode_fields_with_emoji(
     225                $fetched_data,
     226                array( 'htmlCode', 'metaDescriptionHtml', 'ogTagsHtml', 'jsonLDHtml' )
     227            );
     228
    224229            if ( isset( $fetched_data->lastUpdated ) ) {
    225230                $last_update = substr( $fetched_data->lastUpdated, 0, -3 );
     
    230235
    231236            EcwidPlatform::invalidate_static_pages_cache_from( $last_update );
    232             EcwidPlatform::store_in_static_pages_cache( $url, $fetched_data );
     237            EcwidPlatform::save_in_static_pages_cache( $url, $fetched_data );
    233238
    234239            return $fetched_data;
  • ecwid-shopping-cart/trunk/includes/gutenberg/class-ecwid-gutenberg-block-store.php

    r3093942 r3116030  
    287287        }//end foreach
    288288
    289         $categories = ecwid_get_categories_for_selector();
    290 
    291         if ( $categories ) {
    292             $attributes['default_category_id']['values'] = array(
    293                 array(
    294                     'value' => '0',
    295                     'title' => __( 'Store root category', 'ecwid-shopping-cart' ),
    296                 ),
    297             );
    298             foreach ( $categories as $category ) {
    299                 if ( empty( $category->enabled ) ) {
    300                     continue;
    301                 }
    302 
    303                 $attributes['default_category_id']['values'][] = array(
    304                     'value' => $category->id,
    305                     'title' => $category->name,
     289        if ( is_admin() ) {
     290            $categories = ecwid_get_categories_for_selector();
     291
     292            if ( $categories ) {
     293                $attributes['default_category_id']['values'] = array(
     294                    array(
     295                        'value' => '0',
     296                        'title' => __( 'Store root category', 'ecwid-shopping-cart' ),
     297                    ),
    306298                );
    307             }
    308 
    309             $attributes['default_category_id']['default'] = '';
    310         } else {
    311             $api  = new Ecwid_Api_V3();
    312             $cats = $api->get_categories( array() );
    313 
    314             if ( $cats && $cats->total == 0 ) {
    315                 unset( $attributes['default_category_id'] );
    316             }
     299                foreach ( $categories as $category ) {
     300                    if ( empty( $category->enabled ) ) {
     301                        continue;
     302                    }
     303
     304                    $attributes['default_category_id']['values'][] = array(
     305                        'value' => $category->id,
     306                        'title' => $category->name,
     307                    );
     308                }
     309
     310                $attributes['default_category_id']['default'] = '';
     311            } else {
     312                $api  = new Ecwid_Api_V3();
     313                $cats = $api->get_categories( array() );
     314
     315                if ( $cats && $cats->total == 0 ) {
     316                    unset( $attributes['default_category_id'] );
     317                }
     318            }//end if
    317319        }//end if
    318320
  • ecwid-shopping-cart/trunk/includes/themes/class-ecwid-theme-base.php

    r2813294 r3116030  
    6868
    6969        if ( in_array( 'title', $props, true ) ) {
    70 
    7170            $store_page_params = Ecwid_Store_Page::get_store_page_params();
    7271
    73             if ( @$store_page_params['product_details_show_product_name'] ) {
     72            if ( ! empty( $store_page_params['product_details_show_product_name'] ) ) {
    7473                add_filter( 'option_' . Ecwid_Store_Page::OPTION_REPLACE_TITLE, '__return_false' );
    7574            }
     
    126125        );
    127126    }
    128 
    129127}
  • ecwid-shopping-cart/trunk/lib/ecwid_api_v3.php

    r3059103 r3116030  
    164164        }
    165165
    166         $passthru = array( 'offset', 'limit', 'parent', 'baseUrl', 'cleanUrls', 'hidden_categories' );
     166        $passthru = array( 'offset', 'limit', 'parent', 'baseUrl', 'cleanUrls', 'hidden_categories', 'responseFields' );
    167167        foreach ( $passthru as $name ) {
    168168            if ( array_key_exists( $name, $input_params ) ) {
     
    190190        if ( ! $result ) {
    191191            $result = EcwidPlatform::fetch_url( $url, $options );
    192         }
    193 
    194         if ( $result['code'] != '200' ) {
    195             return false;
    196         }
    197 
    198         EcwidPlatform::store_in_categories_cache( $url, $result );
     192
     193            if ( $result['code'] != '200' ) {
     194                return false;
     195            }
     196
     197            // PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     198            $data = json_decode( $result['data'] );
     199
     200            if ( ! empty( $data->items ) ) {
     201                foreach ( $data->items as &$item ) {
     202                    $item = EcwidPlatform::encode_fields_with_emoji(
     203                        $item,
     204                        array( 'name', 'nameTranslated', 'description', 'descriptionTranslated', 'seoTitle', 'seoTitleTranslated', 'seoDescription', 'seoDescriptionTranslated', 'alt' )
     205                    );
     206                }
     207            }
     208
     209            $result['data'] = wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
     210            // end PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     211
     212            EcwidPlatform::store_in_categories_cache( $url, $result );
     213        }//end if
    199214
    200215        $result = json_decode( $result['data'] );
     
    249264        if ( ! $result ) {
    250265            $result = EcwidPlatform::fetch_url( $url, $options );
    251         }
    252 
    253         if ( $result['code'] != '200' ) {
    254             return false;
    255         }
    256 
    257         EcwidPlatform::store_in_categories_cache( $url, $result );
     266
     267            if ( $result['code'] != '200' ) {
     268                return false;
     269            }
     270
     271            // PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     272            $data = json_decode( $result['data'] );
     273            if ( ! empty( $data ) ) {
     274                $data = EcwidPlatform::encode_fields_with_emoji(
     275                    $data,
     276                    array( 'name', 'nameTranslated', 'description', 'descriptionTranslated', 'seoTitle', 'seoTitleTranslated', 'seoDescription', 'seoDescriptionTranslated', 'alt' )
     277                );
     278            }
     279            // end PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     280
     281            $result['data'] = wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
     282
     283            EcwidPlatform::store_in_categories_cache( $url, $result );
     284        }//end if
    258285
    259286        $result = json_decode( $result['data'] );
     
    398425        $params = array();
    399426
    400         $passthru = array( 'updatedFrom', 'offset', 'limit', 'sortBy', 'keyword', 'createdFrom', 'createdTo', 'sku', 'enabled' );
     427        $passthru = array( 'updatedFrom', 'offset', 'limit', 'sortBy', 'keyword', 'createdFrom', 'createdTo', 'sku', 'enabled', 'responseFields' );
    401428
    402429        foreach ( $passthru as $name ) {
     
    601628
    602629        $profile = json_decode( $result['data'] );
     630
     631        // PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
     632        if ( ! empty( $profile ) ) {
     633            $profile->settings = EcwidPlatform::encode_fields_with_emoji(
     634                $profile->settings,
     635                array( 'storeName', 'storeDescription', 'storeDescriptionTranslated', 'rootCategorySeoTitleTranslated', 'rootCategorySeoDescription', 'rootCategorySeoDescriptionTranslated' )
     636            );
     637        }
     638        // end PLUGINS-6870 there's some cases when data are not cached because emojis, need to encode
    603639
    604640        EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 10 * MINUTE_IN_SECONDS );
  • ecwid-shopping-cart/trunk/lib/ecwid_catalog.php

    r2640505 r3116030  
    11<?php
    22
    3 class EcwidCatalog
    4 {
    5     var $store_id = 0;
     3class EcwidCatalog {
     4
     5    var $store_id       = 0;
    66    var $store_base_url = '';
    77
    8     public function __construct($store_id, $store_base_url)
    9     {
    10         $this->store_id = intval($store_id);
    11         $this->store_base_url = $store_base_url;   
     8    public function __construct( $store_id, $store_base_url ) {
     9        $this->store_id       = intval( $store_id );
     10        $this->store_base_url = $store_base_url;
    1211    }
    1312
    14     public function warmup_store_page( $category_id )
    15     {
     13    public function warmup_store_page( $category_id ) {
    1614        $this->_get_data_for_category( $category_id, null );
    1715    }
    18    
    19     public function get_product($id)
    20     {
    21         $result = $this->_get_data_for_product($id);
    2216
    23         if ( !$result ) {
     17    public function get_product( $id ) {
     18        $result = $this->_get_data_for_product( $id );
     19
     20        if ( ! $result ) {
    2421            return '';
    2522        }
    26        
     23
    2724        ob_start();
    2825        $product = $result->product;
    2926        $formats = $result->formats;
    30         require dirname(__FILE__) . '/html-catalog-templates/product.php';
    31 
    32         $return = ob_get_contents();
    33         ob_end_clean();
    34        
    35         return $return;
    36     }
    37 
    38     public function get_category($id)
    39     {
    40         $offset = ( isset($_GET['offset']) ) ? intval($_GET['offset']) : 0;
    41         $data = $this->_get_data_for_category( $id, $offset );
    42        
    43         if ( !$data ) {
    44             return '';
    45         }
    46        
    47         $main_category = null;
    48         if ($id > 0) {
    49             $main_category = $data->main_category;
    50         }
    51         $categories = $data->categories;
    52         $products = $data->products;
    53         $formats = $data->formats;
    54        
    55         ob_start();
    56         require dirname(__FILE__) . '/html-catalog-templates/category.php';
     27        require __DIR__ . '/html-catalog-templates/product.php';
    5728
    5829        $return = ob_get_contents();
     
    6233    }
    6334
    64     protected function _get_data_for_product( $id )
    65     {
     35    public function get_category( $id ) {
     36        $offset = ( isset( $_GET['offset'] ) ) ? intval( $_GET['offset'] ) : 0;
     37        $data   = $this->_get_data_for_category( $id, $offset );
     38
     39        if ( ! $data ) {
     40            return '';
     41        }
     42
     43        $main_category = null;
     44        if ( $id > 0 ) {
     45            $main_category = $data->main_category;
     46        }
     47        $categories = $data->categories;
     48        $products   = $data->products;
     49        $formats    = $data->formats;
     50
     51        ob_start();
     52        require __DIR__ . '/html-catalog-templates/category.php';
     53
     54        $return = ob_get_contents();
     55        ob_end_clean();
     56
     57        return $return;
     58    }
     59
     60    protected function _get_data_for_product( $id ) {
    6661        if ( Ecwid_Api_V3::is_available() ) {
    6762            $api = new Ecwid_Api_V3();
    68            
     63
    6964            $product = Ecwid_Product::get_by_id( $id );
    70            
     65
    7166            $profile = $api->get_store_profile();
    72            
    73             if (!$profile) {
     67
     68            if ( ! $profile ) {
    7469                return null;
    7570            }
    76            
     71
    7772            return (object) array(
    7873                'product' => $product,
    79                 'formats' => @$profile->formatsAndUnits
     74                'formats' => @$profile->formatsAndUnits,
    8075            );
    81         } 
    82        
     76        }
     77
    8378        return null;
    8479    }
    85    
    86     protected function _get_data_for_category( $id, $offset = 0 )
    87     {
     80
     81    protected function _get_data_for_category( $id, $offset = 0 ) {
    8882        if ( Ecwid_Api_V3::is_available() ) {
    8983            $api = new Ecwid_Api_V3();
    90            
     84
    9185            $main_category = null;
    92             if ($id > 0) {
     86            if ( $id > 0 ) {
    9387                $main_category = $api->get_category( $id );
    9488            }
    9589
    9690            $get_categories_params = array(
    97                 'parent' => $id
     91                'parent' => $id,
    9892            );
    99             if ($offset && $offset > 0) {
     93            if ( $offset && $offset > 0 ) {
    10094                $get_categories_params['offset'] = $offset;
    10195            }
    10296            $categories = $api->get_categories( $get_categories_params );
    103            
     97
    10498            $get_products_params = array(
    105                 'category' => $id
     99                'category' => $id,
    106100            );
    107             if ($offset) {
     101            if ( $offset ) {
    108102                $get_products_params['offset'] = $offset;
    109103            }
    110104            $products = $api->search_products( $get_products_params );
    111            
     105
    112106            $profile = $api->get_store_profile();
    113            
    114             if ( is_null( $profile ) || !isset( $categories->items ) || !isset( $products->items ) ) {
     107
     108            if ( is_null( $profile ) || ! isset( $categories->items ) || ! isset( $products->items ) ) {
    115109                return null;
    116110            }
    117            
     111
    118112            return (object) array(
    119113                'main_category' => $main_category,
    120                 'categories' => $categories->items,
    121                 'products' => $products->items,
    122                 'formats' => @$profile->formatsAndUnits
     114                'categories'    => $categories->items,
     115                'products'      => $products->items,
     116                'formats'       => @$profile->formatsAndUnits,
    123117            );
    124         } 
    125        
     118        }//end if
     119
    126120        return null;
    127121    }
    128    
    129     public function parse_escaped_fragment($escaped_fragment)
    130     {
    131         $fragment = urldecode($escaped_fragment);
    132         $return = array();
    133122
    134         if (preg_match('/^(\/~\/)([a-z]+)\/(.*)$/', $fragment, $matches)) {
    135             parse_str($matches[3], $return);
     123    public function parse_escaped_fragment( $escaped_fragment ) {
     124        $fragment = urldecode( $escaped_fragment );
     125        $return   = array();
     126
     127        if ( preg_match( '/^(\/~\/)([a-z]+)\/(.*)$/', $fragment, $matches ) ) {
     128            parse_str( $matches[3], $return );
    136129            $return['mode'] = $matches[2];
    137         } elseif (preg_match('!.*/(p|c)/([0-9]*)!', $fragment, $matches)) {
    138             if (count($matches) == 3 && in_array($matches[1], array('p', 'c'))) {
    139                 $return  = array(
     130        } elseif ( preg_match( '!.*/(p|c)/([0-9]*)!', $fragment, $matches ) ) {
     131            if ( count( $matches ) == 3 && in_array( $matches[1], array( 'p', 'c' ) ) ) {
     132                $return = array(
    140133                    'mode' => 'p' == $matches[1] ? 'product' : 'category',
    141                     'id' => $matches[2]
     134                    'id'   => $matches[2],
    142135                );
    143136            }
  • ecwid-shopping-cart/trunk/lib/ecwid_platform.php

    r3110860 r3116030  
    226226            )
    227227        );
    228         self::encode_emoji( $value );
    229228
    230229        set_transient( 'ecwid_' . $name, $value, $expires_after );
    231230    }
    232231
     232    public static function encode_fields_with_emoji( $data, $properties = array() ) {
     233        if ( ! is_object( $data ) ) {
     234            return $data;
     235        }
     236
     237        if ( ! is_array( $properties ) ) {
     238            return $data;
     239        }
     240
     241        foreach ( $properties as $property ) {
     242            if ( ! empty( $data->$property ) ) {
     243                if ( is_string( $data->$property ) ) {
     244                    $data->$property = wp_encode_emoji( $data->$property );
     245                } else {
     246                    self::encode_emoji( $data->$property );
     247                }
     248            }
     249        }
     250        return $data;
     251    }
     252
    233253    public static function encode_emoji( &$item, $key = false ) { //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
     254        if ( empty( $item ) ) {
     255            return;
     256        }
     257
    234258        if ( is_object( $item ) || is_array( $item ) ) {
    235259            array_walk_recursive( $item, 'self::encode_emoji' );
     
    306330        }
    307331
    308         if ( $return['code'] == 200 ) {
     332        if ( $return['code'] == 200 && $api_check_retry_after !== 0 ) {
    309333            update_option( self::OPTION_ECWID_CHECK_API_RETRY_AFTER, 0 );
    310334        }
     
    377401
    378402    public static function store_in_products_cache( $url, $data ) {
    379         self::store_in_cache( $url, 'products', $data, WEEK_IN_SECONDS );
     403        self::save_in_cache( $url, 'products', $data, WEEK_IN_SECONDS );
    380404    }
    381405
    382406    public static function store_in_categories_cache( $url, $data ) {
    383         self::store_in_cache( $url, 'categories', $data, WEEK_IN_SECONDS );
    384     }
    385 
    386     public static function store_in_static_pages_cache( $url, $data ) {
    387         self::store_in_cache( $url, 'catalog', $data, WEEK_IN_SECONDS );
    388     }
    389 
    390     protected static function store_in_cache( $url, $type, $data, $expires_after ) {
     407        self::save_in_cache( $url, 'categories', $data, WEEK_IN_SECONDS );
     408    }
     409
     410    public static function save_in_static_pages_cache( $url, $data ) {
     411        self::save_in_cache( $url, 'catalog', $data, WEEK_IN_SECONDS );
     412    }
     413
     414    protected static function save_in_cache( $url, $type, $data, $expires_after ) {
    391415        $name = self::_build_cache_name( $url, $type );
    392416
  • ecwid-shopping-cart/trunk/readme.txt

    r3112458 r3116030  
    154154
    155155== Changelog ==
     156= 6.12.15 - Jul 10, 2024 =
     157- After the last update, the our ecommerce plugin could cause an issue with urls and an issue with loading the admin area. We have fixed these issues.
     158
    156159= 6.12.14 - Jul 2, 2024 =
    157160- Fixed issues with slow loading of storefront pages that were observed in certain scenarios when using our ecommerce plugin.
Note: See TracChangeset for help on using the changeset viewer.