Plugin Directory

Changeset 3159867


Ignore:
Timestamp:
09/30/2024 12:56:53 PM (18 months ago)
Author:
ali2woo
Message:

new plugin version

Location:
ali2woo-lite/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • ali2woo-lite/trunk/alinext-lite.php

    r3141581 r3159867  
    66Text Domain: ali2woo
    77Domain Path: /languages
    8 Version: 3.4.3
     8Version: 3.4.4
    99Author: Ali2Woo Team
    1010Author URI: https://ali2woo.com/dropshipping-plugin/
     
    1212Requires at least: 5.9
    1313Tested up to: 6.6
    14 WC tested up to: 9.2
     14WC tested up to: 9.3
    1515WC requires at least: 5.0
    1616Requires PHP: 8.0
  • ali2woo-lite/trunk/assets/js/admin_script.js

    r3114382 r3159867  
    171171
    172172    jQuery('#a2wl-modal-country-from-select').html('')
    173     if(country_from_list.length>0){
     173    if (country_from_list.length>0) {
    174174        jQuery(".modal-shipping").addClass('with-country-from')
    175175        jQuery.each(country_from_list, function (i, c) {
     
    177177        });
    178178        jQuery('#a2wl-modal-country-from-select').val(country_from).trigger('change');
    179     }else{
     179    } else {
    180180        jQuery(".modal-shipping").removeClass('with-country-from')
    181181    }
     
    191191    html += '</tbody></table>';
    192192    jQuery('.modal-shipping .shipping-method').html(html);
     193    if (tmp_data.shipping.length > 0) {
     194        jQuery(".modal-shipping .select_method:checked").trigger('change');
     195    }
     196
    193197}
    194198
  • ali2woo-lite/trunk/changelog.txt

    r3141586 r3159867  
    290290* Add compatibility with WooCommerce 9.2.* 
    291291
     2923.4.4
     293* Add compatibility with WooCommerce 9.3.*
     294* Add server max execution time and memory limit checks on the System Info page
     295* Enhance product background loader (should work faster even on cheap hosting plans)
     296* Fix shipping loader (premium plugin version)
     297* Fix built-in store products` search
     298* Fix issue causing Wordfence notice
     299
  • ali2woo-lite/trunk/includes/classes/controller/ReviewFrontendController.php

    r2937267 r3159867  
    1515    function __construct() {
    1616        add_action('wp_enqueue_scripts', array($this, 'assets'));
    17         add_filter('comment_text', array($this, 'comment_text'), 10, 2);
     17        add_filter('comment_text', [$this, 'comment_text'], 10, 2);
    1818        add_filter('get_avatar_url', array($this, 'get_avatar_url'), 1, 3);
    1919    }
     
    4444
    4545    function comment_text($comment_text, $comment = null) {
     46        if (is_null($comment)) {
     47            return $comment_text;
     48        }
    4649
    4750        if (get_setting('review_show_image_list')) {
     
    5255                $comment_text .= "<div class='a2wl_review_images'>";
    5356                foreach ($image_list as $img) {
    54                     if(is_array($img)){
     57                    if (is_array($img)) {
    5558                        $comment_text .= "<a class='fancybox' rel='group{$comment->comment_ID}' href='{$img['image']}'><img width='{$thumb_width}' src='{$img['thumb']}'/></a>"; 
    56                     }else{
     59                    } else{
    5760                        $comment_text .= "<a class='fancybox' rel='group{$comment->comment_ID}' href='{$img}'><img width='{$thumb_width}' src='{$img}'/></a>";   
    5861                    }
     
    6164            }
    6265        }
     66
    6367        return $comment_text;
    6468    }
  • ali2woo-lite/trunk/includes/classes/controller/SettingPageController.php

    r3129531 r3159867  
    1111namespace AliNext_Lite;;
    1212
    13     class SettingPageController extends AbstractAdminPage
    14     {
    15         public function __construct()
    16         {
    17             parent::__construct(esc_html__('Settings', 'ali2woo'), esc_html__('Settings', 'ali2woo'), 'import', 'a2wl_setting', 30);
    18 
    19             add_filter('a2wl_setting_view', array($this, 'setting_view'));
    20             add_filter('a2wl_configure_lang_data', array($this, 'configure_lang_data'));
    21         }
    22 
    23         public function configure_lang_data($lang_data)
    24         {
    25             if ($this->is_current_page()) {
    26                 $lang_data = array(
    27                     /* translators: %d is replaced with "digit" */
    28                     'process_loading_d_of_d_erros_d' => _x('Process loading %d of %d. Errors: %d.', 'Status', 'ali2woo'),
    29                     /* translators: %d is replaced with "digit" */
    30                     'load_button_text' => _x('Load %d images', 'Status', 'ali2woo'),
    31                     'all_images_loaded_text' => _x('All images loaded', 'Status', 'ali2woo'),
    32                     'leave_blank_to_allow_all_countries' => esc_html__('leave blank to allow all countries', 'ali2woo'),
    33                 );
    34             }
    35             return $lang_data;
    36         }
    37 
    38         public function render($params = []): void
    39         {
    40             if (!empty($_POST)) {
    41                 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
    42             }
    43 
    44             if (!current_user_can('manage_options')) {
    45                 wp_die($this->getErrorTextNoPermissions());
    46             }
    47 
    48             /** @var PermanentAlertService $PermanentAlertService  */
    49             $PermanentAlertService = A2WL()->getDI()->get('AliNext_Lite\PermanentAlertService');
    50 
    51             $current_module = $_REQUEST['subpage'] ?? 'common';
    52             $this->model_put("PermanentAlerts", $PermanentAlertService->getAll());
    53             $this->model_put("modules", $this->getModules());
    54             $this->model_put("current_module", $current_module);
    55 
    56             $this->include_view([
    57                 "settings/settings_head.php",
    58                 apply_filters('a2wl_setting_view', $current_module),
    59                 "settings/settings_footer.php"
    60             ]);
    61         }
    62 
    63         public function getModules()
    64         {
    65             return apply_filters('a2wl_setting_modules', array(
    66                 array('id' => 'common', 'name' => esc_html__('Common settings', 'ali2woo')),
    67                 array('id' => 'account', 'name' => esc_html__('Account settings', 'ali2woo')),
    68                 array('id' => 'price_formula', 'name' => esc_html__('Pricing Rules', 'ali2woo')),
    69                 array('id' => 'reviews', 'name' => esc_html__('Reviews settings', 'ali2woo')),
    70                 array('id' => 'shipping', 'name' => esc_html__('Shipping settings', 'ali2woo')),
    71                 array('id' => 'phrase_filter', 'name' => esc_html__('Phrase Filtering', 'ali2woo')),
    72                 array('id' => 'chrome_api', 'name' => esc_html__('API Keys', 'ali2woo')),
    73                 array('id' => 'system_info', 'name' => esc_html__('System Info', 'ali2woo')),
    74             ));
    75         }
    76 
    77         public function setting_view($current_module)
    78         {
    79             $view = "";
    80             switch ($current_module) {
    81                 case 'common':
    82                     $view = $this->common_handle();
     13class SettingPageController extends AbstractAdminPage
     14{
     15    public const FIELD_FIELD_NO_AVATAR_PHOTO = 'a2wl_review_noavatar_photo';
     16
     17    public function __construct()
     18    {
     19        parent::__construct(
     20            esc_html__('Settings', 'ali2woo'),
     21            esc_html__('Settings', 'ali2woo'),
     22            'import', 'a2wl_setting', 30
     23        );
     24
     25        add_filter('a2wl_setting_view', [$this, 'setting_view']);
     26        add_filter('a2wl_configure_lang_data', array($this, 'configure_lang_data'));
     27    }
     28
     29    public function configure_lang_data($lang_data)
     30    {
     31        if ($this->is_current_page()) {
     32            $lang_data = array(
     33                /* translators: %d is replaced with "digit" */
     34                'process_loading_d_of_d_erros_d' => _x('Process loading %d of %d. Errors: %d.', 'Status', 'ali2woo'),
     35                /* translators: %d is replaced with "digit" */
     36                'load_button_text' => _x('Load %d images', 'Status', 'ali2woo'),
     37                'all_images_loaded_text' => _x('All images loaded', 'Status', 'ali2woo'),
     38                'leave_blank_to_allow_all_countries' => esc_html__('leave blank to allow all countries', 'ali2woo'),
     39            );
     40        }
     41        return $lang_data;
     42    }
     43
     44    public function render($params = []): void
     45    {
     46        if (!empty($_POST)) {
     47            check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
     48        }
     49
     50        if (!current_user_can('manage_options')) {
     51            wp_die($this->getErrorTextNoPermissions());
     52        }
     53
     54        /** @var PermanentAlertService $PermanentAlertService  */
     55        $PermanentAlertService = A2WL()->getDI()->get('AliNext_Lite\PermanentAlertService');
     56
     57        $current_module = $_REQUEST['subpage'] ?? 'common';
     58        $this->model_put("PermanentAlerts", $PermanentAlertService->getAll());
     59        $this->model_put("modules", $this->getModules());
     60        $this->model_put("current_module", $current_module);
     61
     62        $this->include_view([
     63            "settings/settings_head.php",
     64            apply_filters('a2wl_setting_view', $current_module),
     65            "settings/settings_footer.php"
     66        ]);
     67    }
     68
     69    public function getModules()
     70    {
     71        return apply_filters('a2wl_setting_modules', array(
     72            array('id' => 'common', 'name' => esc_html__('Common settings', 'ali2woo')),
     73            array('id' => 'account', 'name' => esc_html__('Account settings', 'ali2woo')),
     74            array('id' => 'price_formula', 'name' => esc_html__('Pricing Rules', 'ali2woo')),
     75            array('id' => 'reviews', 'name' => esc_html__('Reviews settings', 'ali2woo')),
     76            array('id' => 'shipping', 'name' => esc_html__('Shipping settings', 'ali2woo')),
     77            array('id' => 'phrase_filter', 'name' => esc_html__('Phrase Filtering', 'ali2woo')),
     78            array('id' => 'chrome_api', 'name' => esc_html__('API Keys', 'ali2woo')),
     79            array('id' => 'system_info', 'name' => esc_html__('System Info', 'ali2woo')),
     80        ));
     81    }
     82
     83    public function setting_view($current_module): string
     84    {
     85        $view = "";
     86        switch ($current_module) {
     87            case 'common':
     88                $view = $this->common_handle();
     89                break;
     90            case 'account':
     91                $view = $this->account_handle();
     92                break;
     93            case 'price_formula':
     94                $view = $this->price_formula();
     95                break;
     96            case 'reviews':
     97                $view = $this->reviews();
     98                break;
     99            case 'shipping':
     100                $view = $this->shipping();
     101                break;
     102            case 'phrase_filter':
     103                $view = $this->phrase_filter();
     104                break;
     105            case 'chrome_api':
     106                $view = $this->chrome_api();
     107                break;
     108            case 'system_info':
     109                $view = $this->system_info();
     110                break;
     111        }
     112        return $view;
     113    }
     114
     115    private function common_handle(): string
     116    {
     117        if (!empty($_POST)) {
     118            check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
     119        }
     120
     121        if (isset($_POST['setting_form'])) {
     122            settings()->auto_commit(false);
     123            set_setting('item_purchase_code', isset($_POST['a2wl_item_purchase_code']) ? wp_unslash($_POST['a2wl_item_purchase_code']) : '');
     124
     125            set_setting('import_language', isset($_POST['a2w_import_language']) ? wp_unslash($_POST['a2w_import_language']) : 'en');
     126
     127            if (isset($_POST['a2w_local_currency'])) {
     128                $currency = isset($_POST['a2w_local_currency']) ? wp_unslash($_POST['a2w_local_currency']) : 'USD';
     129                set_setting('local_currency', $currency);
     130                update_option('woocommerce_currency', $currency);
     131            }
     132
     133            set_setting('default_product_type', isset($_POST['a2wl_default_product_type']) ? wp_unslash($_POST['a2wl_default_product_type']) : 'simple');
     134            set_setting('default_product_status', isset($_POST['a2wl_default_product_status']) ? wp_unslash($_POST['a2wl_default_product_status']) : 'publish');
     135
     136            set_setting('delivered_order_status', isset($_POST['a2wl_delivered_order_status']) ? wp_unslash($_POST['a2wl_delivered_order_status']) : '');
     137
     138            set_setting('tracking_code_order_status', isset($_POST['a2wl_tracking_code_order_status']) ? wp_unslash($_POST['a2wl_tracking_code_order_status']) : '');
     139
     140            set_setting('placed_order_status', isset($_POST['a2wl_placed_order_status']) ? wp_unslash($_POST['a2wl_placed_order_status']) : '');
     141
     142            set_setting('currency_conversion_factor', isset($_POST['a2wl_currency_conversion_factor']) ? wp_unslash($_POST['a2wl_currency_conversion_factor']) : '1');
     143            set_setting('import_product_images_limit', isset($_POST['a2wl_import_product_images_limit']) && intval($_POST['a2wl_import_product_images_limit']) ? intval($_POST['a2wl_import_product_images_limit']) : '');
     144            set_setting('import_extended_attribute', isset($_POST['a2wl_import_extended_attribute']) ? 1 : 0);
     145
     146            set_setting('background_import', isset($_POST['a2wl_background_import']) ? 1 : 0);
     147            set_setting('allow_product_duplication', isset($_POST['a2wl_allow_product_duplication']) ? 1 : 0);
     148            set_setting('convert_attr_case', isset($_POST['a2wl_convert_attr_case']) ? wp_unslash($_POST['a2wl_convert_attr_case']) : 'original');
     149
     150            set_setting('remove_ship_from', isset($_POST['a2wl_remove_ship_from']) ? 1 : 0);
     151            set_setting('default_ship_from', isset($_POST['a2wl_default_ship_from']) ? wp_unslash($_POST['a2wl_default_ship_from']) : 'CN');
     152
     153            set_setting('use_external_image_urls', isset($_POST['a2wl_use_external_image_urls']));
     154            set_setting('not_import_attributes', isset($_POST['a2wl_not_import_attributes']));
     155            set_setting('not_import_description', isset($_POST['a2wl_not_import_description']));
     156            set_setting('not_import_description_images', isset($_POST['a2wl_not_import_description_images']));
     157
     158            set_setting('use_random_stock', isset($_POST['a2wl_use_random_stock']));
     159            if (isset($_POST['a2wl_use_random_stock'])) {
     160                $min_stock = (!empty($_POST['a2wl_use_random_stock_min']) && intval($_POST['a2wl_use_random_stock_min']) > 0) ? intval($_POST['a2wl_use_random_stock_min']) : 1;
     161                $max_stock = (!empty($_POST['a2wl_use_random_stock_max']) && intval($_POST['a2wl_use_random_stock_max']) > 0) ? intval($_POST['a2wl_use_random_stock_max']) : 1;
     162
     163                if ($min_stock > $max_stock) {
     164                    $min_stock = $min_stock + $max_stock;
     165                    $max_stock = $min_stock - $max_stock;
     166                    $min_stock = $min_stock - $max_stock;
     167                }
     168                set_setting('use_random_stock_min', $min_stock);
     169                set_setting('use_random_stock_max', $max_stock);
     170            }
     171
     172            set_setting('auto_update', isset($_POST['a2wl_auto_update']));
     173            set_setting('on_not_available_product', isset($_POST['a2wl_on_not_available_product']) ? wp_unslash($_POST['a2wl_on_not_available_product']) : 'trash');
     174            set_setting('on_not_available_variation', isset($_POST['a2wl_on_not_available_variation']) ? wp_unslash($_POST['a2wl_on_not_available_variation']) : 'trash');
     175            set_setting('on_new_variation_appearance', isset($_POST['a2wl_on_new_variation_appearance']) ? wp_unslash($_POST['a2wl_on_new_variation_appearance']) : 'add');
     176            set_setting('on_price_changes', isset($_POST['a2wl_on_price_changes']) ? wp_unslash($_POST['a2wl_on_price_changes']) : 'update');
     177            set_setting('on_stock_changes', isset($_POST['a2wl_on_stock_changes']) ? wp_unslash($_POST['a2wl_on_stock_changes']) : 'update');
     178            set_setting('untrash_product', isset($_POST['a2wl_untrash_product']));
     179            set_setting('email_alerts', isset($_POST['a2wl_email_alerts']));
     180            set_setting('email_alerts_email', isset($_POST['a2wl_email_alerts_email']) ? wp_unslash($_POST['a2wl_email_alerts_email']) : '');
     181
     182            set_setting('fulfillment_prefship', isset($_POST['a2w_fulfillment_prefship']) ? wp_unslash($_POST['a2w_fulfillment_prefship']) : 'ePacket');
     183            set_setting('fulfillment_phone_code', isset($_POST['a2wl_fulfillment_phone_code']) ? wp_unslash($_POST['a2wl_fulfillment_phone_code']) : '');
     184            set_setting('fulfillment_phone_number', isset($_POST['a2wl_fulfillment_phone_number']) ? wp_unslash($_POST['a2wl_fulfillment_phone_number']) : '');
     185            set_setting('fulfillment_custom_note', isset($_POST['a2wl_fulfillment_custom_note']) ? wp_unslash($_POST['a2wl_fulfillment_custom_note']) : '');
     186            set_setting('fulfillment_cpf_meta_key', isset($_POST['a2wl_fulfillment_cpf_meta_key']) ? wp_unslash($_POST['a2wl_fulfillment_cpf_meta_key']) : '');
     187            set_setting('fulfillment_rut_meta_key', isset($_POST['a2wl_fulfillment_rut_meta_key']) ? wp_unslash($_POST['a2wl_fulfillment_rut_meta_key']) : '');
     188
     189            set_setting('order_translitirate', isset($_POST['a2wl_order_translitirate']));
     190            set_setting('order_third_name', isset($_POST['a2wl_order_third_name']));
     191
     192            settings()->commit();
     193            settings()->auto_commit(true);
     194           
     195        }
     196
     197        $localizator = AliexpressLocalizator::getInstance();
     198        $countryModel = new Country();
     199        $language_model = new Language();
     200        $this->model_put("upgradeTariffUrl", $this->buildUpgradeTariffUrl());
     201        $this->model_put("shipping_options", Utils::get_aliexpress_shipping_options());
     202        $this->model_put("currencies", $localizator->getCurrencies(false));
     203        $this->model_put("custom_currencies", $localizator->getCurrencies(true));
     204        $this->model_put("order_statuses", function_exists('wc_get_order_statuses') ? wc_get_order_statuses() : array());
     205        $this->model_put("shipping_countries", $countryModel->get_countries());
     206        $this->model_put("languages", $language_model->get_languages());
     207
     208        return "settings/common.php";
     209    }
     210
     211    /**
     212     * @return string
     213     */
     214    private function buildUpgradeTariffUrl(): string
     215    {
     216        $url = 'https://ali2woo.com/packages/';
     217        $purchaseCode = get_setting('item_purchase_code');
     218
     219        $urlComponents = [];
     220
     221        if (!a2wl_check_defined('A2WL_HIDE_KEY_FIELDS') && $purchaseCode){
     222            $urlComponents[] = 'purchase_code=' . esc_attr($purchaseCode);
     223        }
     224
     225        $urlComponents[] = 'utm_source=lite&utm_medium=lite&utm_campaign=' . A2WL()->plugin_slug;
     226
     227        return $url . "?" . implode("&", $urlComponents);
     228    }
     229
     230    private function account_handle(): string
     231    {
     232        if (!empty($_POST)) {
     233            check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
     234        }
     235
     236        $account = Account::getInstance();
     237
     238        $token = AliexpressToken::getInstance();
     239
     240        if (isset($_POST['setting_form'])) {
     241            $account->set_account_type(isset($_POST['a2wl_account_type']) && in_array($_POST['a2wl_account_type'], array('aliexpress', 'admitad', 'epn')) ? $_POST['a2wl_account_type'] : 'aliexpress');
     242            $account->use_custom_account(isset($_POST['a2wl_use_custom_account']));
     243            if ($account->custom_account && isset($_POST['a2wl_account_type'])) {
     244                if ($_POST['a2wl_account_type'] == 'aliexpress') {
     245                    $account->save_aliexpress_account(isset($_POST['a2wl_appkey']) ? $_POST['a2wl_appkey'] : '', isset($_POST['a2wl_secretkey']) ? $_POST['a2wl_secretkey'] : '', isset($_POST['a2wl_trackingid']) ? $_POST['a2wl_trackingid'] : '');
     246                } else if ($_POST['a2wl_account_type'] == 'admitad') {
     247                    $account->save_admitad_account(
     248                        $_POST['a2wl_admitad_cashback_url'] ?? '',
     249                        $_POST['a2wl_admitad_account_name'] ?? '',
     250                    );
     251                } else if ($_POST['a2wl_account_type'] == 'epn') {
     252                    $account->save_epn_account(isset($_POST['a2wl_epn_cashback_url']) ? $_POST['a2wl_epn_cashback_url'] : '');
     253                }
     254            }
     255        }
     256
     257        $this->model_put("account", $account);
     258
     259        $this->model_put("tokens", $token->tokens());
     260
     261        return "settings/account.php";
     262    }
     263
     264    private function price_formula(): string
     265    {
     266        $PriceFormulaSettingsRepository= A2WL()->getDI()->get('AliNext_Lite\PriceFormulaSettingsRepository');
     267        $PriceFormulaRepository = A2WL()->getDI()->get('AliNext_Lite\PriceFormulaRepository');
     268        $PriceFormulaSetRepository = A2WL()->getDI()->get('AliNext_Lite\PriceFormulaSetRepository');
     269        $PriceFormulaFactory = A2WL()->getDI()->get('AliNext_Lite\PriceFormulaFactory');
     270        $WoocommerceModel = A2WL()->getDI()->get('AliNext_Lite\Woocommerce');
     271
     272        $formulas = $PriceFormulaRepository->getExtendedFormulas();
     273
     274        if ($formulas) {
     275            $add_formula = $PriceFormulaFactory->createFormula();
     276            $add_formula->min_price = floatval($formulas[count($formulas) - 1]->max_price) + 0.01;
     277            $formulas[] = $add_formula;
     278            $this->model_put("formulas", $formulas);
     279        } else {
     280            $this->model_put("formulas", $PriceFormulaRepository->getDefaultFormulas());
     281        }
     282
     283        $this->model_put("PriceFormulaSets", $PriceFormulaSetRepository->getAll());
     284        //$a2wl_pricing_rules_type
     285        $this->model_put("pricingRuleTypes", PriceFormula::pricing_rules_types());
     286        $this->model_put("PriceFormulaSettingsRepository", $PriceFormulaSettingsRepository);
     287
     288        $this->model_put("default_formula", $PriceFormulaRepository->getDefaultFormula());
     289
     290        $this->model_put('cents', get_setting('price_cents'));
     291        $this->model_put('compared_cents', get_setting('price_compared_cents'));
     292        $this->model_put("categories", $WoocommerceModel->get_categories());
     293
     294        return "settings/price_formula.php";
     295    }
     296
     297    private function reviews(): string
     298    {
     299        if (!empty($_POST)) {
     300            check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
     301        }
     302
     303        if (isset($_POST['setting_form'])) {
     304            settings()->auto_commit(false);
     305            set_setting('load_review', isset($_POST['a2wl_load_review']));
     306            set_setting('review_status', isset($_POST['a2wl_review_status']));
     307            set_setting('review_translated', isset($_POST['a2wl_review_translated']));
     308            set_setting('review_avatar_import', isset($_POST['a2wl_review_avatar_import']));
     309
     310            set_setting('review_schedule_load_period', 'a2wl_15_mins');
     311
     312            //review number fields
     313            $review_number_from = 10;
     314            $review_number_to = 20;
     315
     316            if (isset($_POST['a2wl_review_min_per_product'])) {
     317                $review_number_from = intval($_POST['a2wl_review_min_per_product']);
     318            }
     319
     320            if (isset($_POST['a2wl_review_max_per_product'])) {
     321                $review_number_to = intval($_POST['a2wl_review_max_per_product']);
     322            }
     323
     324            if ($review_number_to < 1) {
     325                $review_number_to = 20;
     326            }
     327
     328            if ($review_number_from < 1 || $review_number_from > $review_number_to) {
     329                $review_number_from = $review_number_to;
     330            }
     331
     332            set_setting('review_min_per_product', $review_number_from);
     333            set_setting('review_max_per_product', $review_number_to);
     334
     335            //clear this meta in all products, it will be recalculated during reviews loading
     336            Review::clear_all_product_max_number_review_meta();
     337
     338            //raiting fields
     339            $raiting_from = 1;
     340            $raiting_to = 5;
     341            if (isset($_POST['a2wl_review_raiting_from'])) {
     342                $raiting_from = intval($_POST['a2wl_review_raiting_from']);
     343            }
     344
     345            if (isset($_POST['a2wl_review_raiting_to'])) {
     346                $raiting_to = intval($_POST['a2wl_review_raiting_to']);
     347            }
     348
     349            if ($raiting_from >= 5) {
     350                $raiting_from = 5;
     351            }
     352
     353            if ($raiting_from < 1 || $raiting_from > $raiting_to) {
     354                $raiting_from = 1;
     355            }
     356
     357            if ($raiting_to >= 5) {
     358                $raiting_to = 5;
     359            }
     360
     361            if ($raiting_to < 1) {
     362                $raiting_to = 1;
     363            }
     364
     365            set_setting('review_raiting_from', $raiting_from);
     366            set_setting('review_raiting_to', $raiting_to);
     367
     368            //update more field
     369            set_setting('review_load_attributes', isset($_POST['a2wl_review_load_attributes']));
     370
     371            set_setting('review_show_image_list', isset($_POST['a2wl_review_show_image_list']));
     372
     373            if (isset($_POST['a2wl_review_show_image_list'])) {
     374                $a2wl_review_thumb_width = intval($_POST['a2wl_review_thumb_width']);
     375
     376                if ($a2wl_review_thumb_width > 0) {
     377                    set_setting('review_thumb_width', $a2wl_review_thumb_width);
     378                } else {
     379                    set_setting('review_thumb_width', 30);
     380                }
     381            }
     382
     383            set_setting('review_skip_empty', isset($_POST['a2wl_review_skip_empty']));
     384            set_setting('review_skip_keywords',
     385                isset($_POST['a2wl_review_skip_keywords']) ? trim(wp_unslash($_POST['a2wl_review_skip_keywords'])) : ''
     386            );
     387
     388            if (!isset($_POST['a2wl_review_country']) || !is_array($_POST['a2wl_review_country'])) {
     389                set_setting('review_country', []);
     390            } else {
     391                set_setting('review_country', $_POST['a2wl_review_country']);
     392            }
     393
     394            set_setting('moderation_reviews', isset($_POST['a2wl_moderation_reviews']));
     395
     396            $checkNoAvatarPhoto = $_FILES && isset($_FILES[self::FIELD_FIELD_NO_AVATAR_PHOTO]) &&
     397                UPLOAD_ERR_OK === $_FILES[self::FIELD_FIELD_NO_AVATAR_PHOTO]['error'];
     398
     399            if ($checkNoAvatarPhoto) {
     400                if (!function_exists('wp_handle_upload')) {
     401                    require_once ABSPATH . 'wp-admin/includes/file.php';
     402                }
     403
     404                $uploadedfile = $_FILES[self::FIELD_FIELD_NO_AVATAR_PHOTO];
     405                $movefile = wp_handle_upload($uploadedfile, ['test_form' => false]);
     406                if ($movefile && !isset($movefile['error'])) {
     407                    set_setting('review_noavatar_photo', $movefile['url']);
     408                } else {
     409                    error_log('review avatar upload error: ' . $movefile['error']);
     410                }
     411            } else {
     412                del_setting('review_noavatar_photo');
     413            }
     414
     415            settings()->commit();
     416            settings()->auto_commit(true);
     417        }
     418
     419        $countryModel = new Country();
     420        $countries = $countryModel->get_countries();
     421
     422        unset($countries[0]);
     423
     424        $this->model_put("reviews_countries", $countries);
     425
     426        return "settings/reviews.php";
     427    }
     428
     429    private function shipping(): string
     430    {
     431        if (!empty($_POST)) {
     432            check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
     433        }
     434
     435        if (isset($_POST['setting_form'])) {
     436
     437            set_setting('aliship_shipto', isset($_POST['a2w_aliship_shipto']) ? wp_unslash($_POST['a2w_aliship_shipto']) : 'US');
     438            set_setting('aliship_frontend', isset($_POST['a2wl_aliship_frontend']));
     439            set_setting('default_shipping_class', !empty($_POST['a2wl_default_shipping_class']) ? $_POST['a2wl_default_shipping_class'] : false);
     440
     441            if (isset($_POST['a2wl_aliship_frontend'])) {
     442
     443                if (isset($_POST['default_rule'])) {
     444                    ShippingPriceFormula::set_default_formula(new ShippingPriceFormula($_POST['default_rule']));
     445                }
     446
     447                set_setting('aliship_selection_type', isset($_POST['a2wl_aliship_selection_type']) ? wp_unslash($_POST['a2wl_aliship_selection_type']) : 'popup');
     448
     449                set_setting('aliship_shipping_type', isset($_POST['a2wl_aliship_shipping_type']) ? wp_unslash($_POST['a2wl_aliship_shipping_type']) : 'new');
     450
     451                set_setting('aliship_shipping_option_text',
     452                    (isset($_POST['a2wl_aliship_shipping_option_text']) && !empty($_POST['a2wl_aliship_shipping_option_text'])) ?
     453                    wp_unslash($_POST['a2wl_aliship_shipping_option_text']) : '[{shipping_cost}] {shipping_company} ({delivery_time}) - {country}');
     454
     455                set_setting('aliship_shipping_label', isset($_POST['a2wl_aliship_shipping_label']) ? wp_unslash($_POST['a2wl_aliship_shipping_label']) : 'Shipping');
     456                set_setting('aliship_free_shipping_label', isset($_POST['a2wl_aliship_free_shipping_label']) ? wp_unslash($_POST['a2wl_aliship_free_shipping_label']) : 'Free Shipping');
     457
     458                set_setting('aliship_product_enable', isset($_POST['a2wl_aliship_product_enable']));
     459
     460                if (isset($_POST['a2wl_aliship_product_enable'])) {
     461                    set_setting('aliship_product_position', isset($_POST['a2wl_aliship_product_position']) ? wp_unslash($_POST['a2wl_aliship_product_position']) : 'after_cart');
     462
     463                    set_setting('aliship_product_not_available_message',
     464                        (isset($_POST['a2wl_aliship_product_not_available_message']) && !empty($_POST['a2wl_aliship_product_not_available_message'])) ?
     465                        wp_unslash($_POST['a2wl_aliship_product_not_available_message']) : 'This product can not be delivered to {country}.');
     466                }
     467
     468                set_setting('aliship_not_available_remove', isset($_POST['a2wl_aliship_not_available_remove']));
     469
     470                set_setting('aliship_not_available_message',
     471                    (isset($_POST['a2wl_aliship_not_available_message']) && !empty($_POST['a2wl_aliship_not_available_message'])) ?
     472                    wp_unslash($_POST['a2wl_aliship_not_available_message']) : '[{shipping_cost}] {delivery_time} - {country}');
     473
     474                $not_available_shipping_cost = (isset($_POST['a2wl_aliship_not_available_cost']) && floatval($_POST['a2wl_aliship_not_available_cost']) >= 0) ? floatval($_POST['a2wl_aliship_not_available_cost']) : 10;
     475
     476                set_setting('aliship_not_available_cost', $not_available_shipping_cost);
     477
     478                $min_time = (isset($_POST['a2wl_aliship_not_available_time_min']) && intval($_POST['a2wl_aliship_not_available_time_min']) > 0) ? intval($_POST['a2wl_aliship_not_available_time_min']) : 20;
     479                $max_time = (isset($_POST['a2wl_aliship_not_available_time_max']) && intval($_POST['a2wl_aliship_not_available_time_max']) > 0) ? intval($_POST['a2wl_aliship_not_available_time_max']) : 30;
     480
     481                set_setting('aliship_not_available_time_min', $min_time);
     482                set_setting('aliship_not_available_time_max', $max_time);
     483
     484            }
     485
     486        }
     487
     488        $countryModel = new Country();
     489
     490        $this->model_put("shipping_countries", $countryModel->get_countries());
     491
     492        $this->model_put("shipping_selection_types", Shipping::get_selection_types());
     493
     494        $this->model_put("shipping_types", Shipping::get_shipping_types());
     495
     496        $this->model_put("selection_position_types", Shipping::get_selection_position_types());
     497
     498        $this->model_put("default_formula", ShippingPriceFormula::get_default_formula());
     499
     500        $shipping_class = get_terms(array('taxonomy' => 'product_shipping_class', 'hide_empty' => false));
     501        $this->model_put("shipping_class", $shipping_class ? $shipping_class : array());
     502
     503        return "settings/shipping.php";
     504    }
     505
     506    private function phrase_filter(): string
     507    {
     508        $phrases = PhraseFilter::load_phrases();
     509
     510        if ($phrases) {
     511            $this->model_put("phrases", $phrases);
     512        } else {
     513            $this->model_put("phrases", array());
     514        }
     515
     516        return "settings/phrase_filter.php";
     517    }
     518
     519    private function chrome_api(): string
     520    {
     521        if (!empty($_POST)) {
     522            check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
     523        }
     524
     525        $api_keys = get_setting('api_keys', array());
     526
     527        if (!empty($_REQUEST['delete-key'])) {
     528            foreach ($api_keys as $k => $key) {
     529                if ($key['id'] === $_REQUEST['delete-key']) {
     530                    unset($api_keys[$k]);
     531                    set_setting('api_keys', $api_keys);
    83532                    break;
    84                 case 'account':
    85                     $view = $this->account_handle();
     533                }
     534            }
     535            wp_redirect(admin_url('admin.php?page=a2wl_setting&subpage=chrome_api'));
     536        } else if (!empty($_POST['a2wl_api_key'])) {
     537            $key_id = $_POST['a2wl_api_key'];
     538            $key_name = !empty($_POST['a2wl_api_key_name']) ? $_POST['a2wl_api_key_name'] : "New key";
     539
     540            $is_new = true;
     541            foreach ($api_keys as &$key) {
     542                if ($key['id'] === $key_id) {
     543                    $key['name'] = $key_name;
     544                    $is_new = false;
    86545                    break;
    87                 case 'price_formula':
    88                     $view = $this->price_formula();
    89                     break;
    90                 case 'reviews':
    91                     $view = $this->reviews();
    92                     break;
    93                 case 'shipping':
    94                     $view = $this->shipping();
    95                     break;
    96                 case 'phrase_filter':
    97                     $view = $this->phrase_filter();
    98                     break;
    99                 case 'chrome_api':
    100                     $view = $this->chrome_api();
    101                     break;
    102                 case 'system_info':
    103                     $view = $this->system_info();
    104                     break;
    105             }
    106             return $view;
    107         }
    108 
    109         private function common_handle()
    110         {
    111             if (!empty($_POST)) {
    112                 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
    113             }
    114 
    115             if (isset($_POST['setting_form'])) {
    116                 settings()->auto_commit(false);
    117                 set_setting('item_purchase_code', isset($_POST['a2wl_item_purchase_code']) ? wp_unslash($_POST['a2wl_item_purchase_code']) : '');
    118 
    119                 set_setting('import_language', isset($_POST['a2w_import_language']) ? wp_unslash($_POST['a2w_import_language']) : 'en');
    120 
    121                 if (isset($_POST['a2w_local_currency'])) {
    122                     $currency = isset($_POST['a2w_local_currency']) ? wp_unslash($_POST['a2w_local_currency']) : 'USD';
    123                     set_setting('local_currency', $currency);
    124                     update_option('woocommerce_currency', $currency);
    125                 }
    126 
    127                 set_setting('default_product_type', isset($_POST['a2wl_default_product_type']) ? wp_unslash($_POST['a2wl_default_product_type']) : 'simple');
    128                 set_setting('default_product_status', isset($_POST['a2wl_default_product_status']) ? wp_unslash($_POST['a2wl_default_product_status']) : 'publish');
    129 
    130                 set_setting('delivered_order_status', isset($_POST['a2wl_delivered_order_status']) ? wp_unslash($_POST['a2wl_delivered_order_status']) : '');
    131 
    132                 set_setting('tracking_code_order_status', isset($_POST['a2wl_tracking_code_order_status']) ? wp_unslash($_POST['a2wl_tracking_code_order_status']) : '');
    133 
    134                 set_setting('placed_order_status', isset($_POST['a2wl_placed_order_status']) ? wp_unslash($_POST['a2wl_placed_order_status']) : '');
    135 
    136                 set_setting('currency_conversion_factor', isset($_POST['a2wl_currency_conversion_factor']) ? wp_unslash($_POST['a2wl_currency_conversion_factor']) : '1');
    137                 set_setting('import_product_images_limit', isset($_POST['a2wl_import_product_images_limit']) && intval($_POST['a2wl_import_product_images_limit']) ? intval($_POST['a2wl_import_product_images_limit']) : '');
    138                 set_setting('import_extended_attribute', isset($_POST['a2wl_import_extended_attribute']) ? 1 : 0);
    139 
    140                 set_setting('background_import', isset($_POST['a2wl_background_import']) ? 1 : 0);
    141                 set_setting('allow_product_duplication', isset($_POST['a2wl_allow_product_duplication']) ? 1 : 0);
    142                 set_setting('convert_attr_case', isset($_POST['a2wl_convert_attr_case']) ? wp_unslash($_POST['a2wl_convert_attr_case']) : 'original');
    143 
    144                 set_setting('remove_ship_from', isset($_POST['a2wl_remove_ship_from']) ? 1 : 0);
    145                 set_setting('default_ship_from', isset($_POST['a2wl_default_ship_from']) ? wp_unslash($_POST['a2wl_default_ship_from']) : 'CN');
    146 
    147                 set_setting('use_external_image_urls', isset($_POST['a2wl_use_external_image_urls']));
    148                 set_setting('not_import_attributes', isset($_POST['a2wl_not_import_attributes']));
    149                 set_setting('not_import_description', isset($_POST['a2wl_not_import_description']));
    150                 set_setting('not_import_description_images', isset($_POST['a2wl_not_import_description_images']));
    151 
    152                 set_setting('use_random_stock', isset($_POST['a2wl_use_random_stock']));
    153                 if (isset($_POST['a2wl_use_random_stock'])) {
    154                     $min_stock = (!empty($_POST['a2wl_use_random_stock_min']) && intval($_POST['a2wl_use_random_stock_min']) > 0) ? intval($_POST['a2wl_use_random_stock_min']) : 1;
    155                     $max_stock = (!empty($_POST['a2wl_use_random_stock_max']) && intval($_POST['a2wl_use_random_stock_max']) > 0) ? intval($_POST['a2wl_use_random_stock_max']) : 1;
    156 
    157                     if ($min_stock > $max_stock) {
    158                         $min_stock = $min_stock + $max_stock;
    159                         $max_stock = $min_stock - $max_stock;
    160                         $min_stock = $min_stock - $max_stock;
     546                }
     547            }
     548
     549            if ($is_new) {
     550                $api_keys[] = array('id' => $key_id, 'name' => $key_name);
     551            }
     552
     553            set_setting('api_keys', $api_keys);
     554
     555            wp_redirect(admin_url('admin.php?page=a2wl_setting&subpage=chrome_api&edit-key=' . $key_id));
     556        } else if (isset($_REQUEST['edit-key'])) {
     557            $api_key = array('id' => md5("a2wkey" . wp_rand() . microtime()), 'name' => "New key");
     558            $is_new = true;
     559            if (empty($_REQUEST['edit-key'])) {
     560                $api_keys[] = $api_key;
     561                set_setting('api_keys', $api_keys);
     562
     563                wp_redirect(admin_url('admin.php?page=a2wl_setting&subpage=chrome_api&edit-key=' . $api_key['id']));
     564            } else if (!empty($_REQUEST['edit-key']) && $api_keys && is_array($api_keys)) {
     565                foreach ($api_keys as $key) {
     566                    if ($key['id'] === $_REQUEST['edit-key']) {
     567                        $api_key = $key;
     568                        $is_new = false;
    161569                    }
    162                     set_setting('use_random_stock_min', $min_stock);
    163                     set_setting('use_random_stock_max', $max_stock);
    164                 }
    165 
    166                 set_setting('auto_update', isset($_POST['a2wl_auto_update']));
    167                 set_setting('on_not_available_product', isset($_POST['a2wl_on_not_available_product']) ? wp_unslash($_POST['a2wl_on_not_available_product']) : 'trash');
    168                 set_setting('on_not_available_variation', isset($_POST['a2wl_on_not_available_variation']) ? wp_unslash($_POST['a2wl_on_not_available_variation']) : 'trash');
    169                 set_setting('on_new_variation_appearance', isset($_POST['a2wl_on_new_variation_appearance']) ? wp_unslash($_POST['a2wl_on_new_variation_appearance']) : 'add');
    170                 set_setting('on_price_changes', isset($_POST['a2wl_on_price_changes']) ? wp_unslash($_POST['a2wl_on_price_changes']) : 'update');
    171                 set_setting('on_stock_changes', isset($_POST['a2wl_on_stock_changes']) ? wp_unslash($_POST['a2wl_on_stock_changes']) : 'update');
    172                 set_setting('untrash_product', isset($_POST['a2wl_untrash_product']));
    173                 set_setting('email_alerts', isset($_POST['a2wl_email_alerts']));
    174                 set_setting('email_alerts_email', isset($_POST['a2wl_email_alerts_email']) ? wp_unslash($_POST['a2wl_email_alerts_email']) : '');
    175 
    176                 set_setting('fulfillment_prefship', isset($_POST['a2w_fulfillment_prefship']) ? wp_unslash($_POST['a2w_fulfillment_prefship']) : 'ePacket');
    177                 set_setting('fulfillment_phone_code', isset($_POST['a2wl_fulfillment_phone_code']) ? wp_unslash($_POST['a2wl_fulfillment_phone_code']) : '');
    178                 set_setting('fulfillment_phone_number', isset($_POST['a2wl_fulfillment_phone_number']) ? wp_unslash($_POST['a2wl_fulfillment_phone_number']) : '');
    179                 set_setting('fulfillment_custom_note', isset($_POST['a2wl_fulfillment_custom_note']) ? wp_unslash($_POST['a2wl_fulfillment_custom_note']) : '');
    180                 set_setting('fulfillment_cpf_meta_key', isset($_POST['a2wl_fulfillment_cpf_meta_key']) ? wp_unslash($_POST['a2wl_fulfillment_cpf_meta_key']) : '');
    181                 set_setting('fulfillment_rut_meta_key', isset($_POST['a2wl_fulfillment_rut_meta_key']) ? wp_unslash($_POST['a2wl_fulfillment_rut_meta_key']) : '');
    182 
    183                 set_setting('order_translitirate', isset($_POST['a2wl_order_translitirate']));
    184                 set_setting('order_third_name', isset($_POST['a2wl_order_third_name']));
    185 
    186                 settings()->commit();
    187                 settings()->auto_commit(true);
    188                
    189             }
    190 
    191             $localizator = AliexpressLocalizator::getInstance();
    192             $countryModel = new Country();
    193             $language_model = new Language();
    194             $this->model_put("upgradeTariffUrl", $this->buildUpgradeTariffUrl());
    195             $this->model_put("shipping_options", Utils::get_aliexpress_shipping_options());
    196             $this->model_put("currencies", $localizator->getCurrencies(false));
    197             $this->model_put("custom_currencies", $localizator->getCurrencies(true));
    198             $this->model_put("order_statuses", function_exists('wc_get_order_statuses') ? wc_get_order_statuses() : array());
    199             $this->model_put("shipping_countries", $countryModel->get_countries());
    200             $this->model_put("languages", $language_model->get_languages());
    201 
    202             return "settings/common.php";
    203         }
    204 
    205         /**
    206          * @return string
    207          */
    208         private function buildUpgradeTariffUrl(): string
    209         {
    210             $url = 'https://ali2woo.com/packages/';
    211             $purchaseCode = get_setting('item_purchase_code');
    212 
    213             $urlComponents = [];
    214 
    215             if (!a2wl_check_defined('A2WL_HIDE_KEY_FIELDS') && $purchaseCode){
    216                 $urlComponents[] = 'purchase_code=' . esc_attr($purchaseCode);
    217             }
    218 
    219             $urlComponents[] = 'utm_source=lite&utm_medium=lite&utm_campaign=' . A2WL()->plugin_slug;
    220 
    221             return $url . "?" . implode("&", $urlComponents);
    222         }
    223 
    224         private function account_handle()
    225         {
    226             if (!empty($_POST)) {
    227                 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
    228             }
    229 
    230             $account = Account::getInstance();
    231 
    232             $token = AliexpressToken::getInstance();
    233 
    234             if (isset($_POST['setting_form'])) {
    235                 $account->set_account_type(isset($_POST['a2wl_account_type']) && in_array($_POST['a2wl_account_type'], array('aliexpress', 'admitad', 'epn')) ? $_POST['a2wl_account_type'] : 'aliexpress');
    236                 $account->use_custom_account(isset($_POST['a2wl_use_custom_account']));
    237                 if ($account->custom_account && isset($_POST['a2wl_account_type'])) {
    238                     if ($_POST['a2wl_account_type'] == 'aliexpress') {
    239                         $account->save_aliexpress_account(isset($_POST['a2wl_appkey']) ? $_POST['a2wl_appkey'] : '', isset($_POST['a2wl_secretkey']) ? $_POST['a2wl_secretkey'] : '', isset($_POST['a2wl_trackingid']) ? $_POST['a2wl_trackingid'] : '');
    240                     } else if ($_POST['a2wl_account_type'] == 'admitad') {
    241                         $account->save_admitad_account(
    242                             $_POST['a2wl_admitad_cashback_url'] ?? '',
    243                             $_POST['a2wl_admitad_account_name'] ?? '',
    244                         );
    245                     } else if ($_POST['a2wl_account_type'] == 'epn') {
    246                         $account->save_epn_account(isset($_POST['a2wl_epn_cashback_url']) ? $_POST['a2wl_epn_cashback_url'] : '');
    247                     }
    248                 }
    249             }
    250 
    251             $this->model_put("account", $account);
    252 
    253             $this->model_put("tokens", $token->tokens());
    254 
    255             return "settings/account.php";
    256         }
    257 
    258         private function price_formula()
    259         {
    260             $PriceFormulaSettingsRepository= A2WL()->getDI()->get('AliNext_Lite\PriceFormulaSettingsRepository');
    261             $PriceFormulaRepository = A2WL()->getDI()->get('AliNext_Lite\PriceFormulaRepository');
    262             $PriceFormulaSetRepository = A2WL()->getDI()->get('AliNext_Lite\PriceFormulaSetRepository');
    263             $PriceFormulaFactory = A2WL()->getDI()->get('AliNext_Lite\PriceFormulaFactory');
    264             $WoocommerceModel = A2WL()->getDI()->get('AliNext_Lite\Woocommerce');
    265 
    266             $formulas = $PriceFormulaRepository->getExtendedFormulas();
    267 
    268             if ($formulas) {
    269                 $add_formula = $PriceFormulaFactory->createFormula();
    270                 $add_formula->min_price = floatval($formulas[count($formulas) - 1]->max_price) + 0.01;
    271                 $formulas[] = $add_formula;
    272                 $this->model_put("formulas", $formulas);
     570                }
     571            }
     572            $this->model_put("api_key", $api_key);
     573            $this->model_put("is_new_api_key", $is_new);
     574        }
     575
     576        $this->model_put("api_keys", $api_keys);
     577
     578        return "settings/chrome.php";
     579    }
     580
     581    private function system_info(): string
     582    {
     583        if (!empty($_POST)) {
     584            check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
     585        }
     586
     587        if (isset($_POST['setting_form'])) {
     588            set_setting('write_info_log', isset($_POST['a2wl_write_info_log']));
     589        }
     590
     591        $server_ip = '-';
     592        if (array_key_exists('SERVER_ADDR', $_SERVER)) {
     593            $server_ip = $_SERVER['SERVER_ADDR'];
     594        } elseif (array_key_exists('LOCAL_ADDR', $_SERVER)) {
     595            $server_ip = $_SERVER['LOCAL_ADDR'];
     596        } elseif (array_key_exists('SERVER_NAME', $_SERVER)) {
     597            $server_ip = gethostbyname($_SERVER['SERVER_NAME']);
     598        } else {
     599            // Running CLI
     600            if (stristr(PHP_OS, 'WIN')) {
     601                $server_ip = gethostbyname(php_uname("n"));
    273602            } else {
    274                 $this->model_put("formulas", $PriceFormulaRepository->getDefaultFormulas());
    275             }
    276 
    277             $this->model_put("PriceFormulaSets", $PriceFormulaSetRepository->getAll());
    278             //$a2wl_pricing_rules_type
    279             $this->model_put("pricingRuleTypes", PriceFormula::pricing_rules_types());
    280             $this->model_put("PriceFormulaSettingsRepository", $PriceFormulaSettingsRepository);
    281 
    282             $this->model_put("default_formula", $PriceFormulaRepository->getDefaultFormula());
    283 
    284             $this->model_put('cents', get_setting('price_cents'));
    285             $this->model_put('compared_cents', get_setting('price_compared_cents'));
    286             $this->model_put("categories", $WoocommerceModel->get_categories());
    287 
    288             return "settings/price_formula.php";
    289         }
    290 
    291         private function reviews()
    292         {
    293             if (!empty($_POST)) {
    294                 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
    295             }
    296 
    297             if (isset($_POST['setting_form'])) {
    298                 settings()->auto_commit(false);
    299                 set_setting('load_review', isset($_POST['a2wl_load_review']));
    300                 set_setting('review_status', isset($_POST['a2wl_review_status']));
    301                 set_setting('review_translated', isset($_POST['a2wl_review_translated']));
    302                 set_setting('review_avatar_import', isset($_POST['a2wl_review_avatar_import']));
    303 
    304                 set_setting('review_schedule_load_period', 'a2wl_15_mins');
    305 
    306                 //review number fields
    307                 $review_number_from = 10;
    308                 $review_number_to = 20;
    309 
    310                 if (isset($_POST['a2wl_review_min_per_product'])) {
    311                     $review_number_from = intval($_POST['a2wl_review_min_per_product']);
    312                 }
    313 
    314                 if (isset($_POST['a2wl_review_max_per_product'])) {
    315                     $review_number_to = intval($_POST['a2wl_review_max_per_product']);
    316                 }
    317 
    318                 if ($review_number_to < 1) {
    319                     $review_number_to = 20;
    320                 }
    321 
    322                 if ($review_number_from < 1 || $review_number_from > $review_number_to) {
    323                     $review_number_from = $review_number_to;
    324                 }
    325 
    326                 set_setting('review_min_per_product', $review_number_from);
    327                 set_setting('review_max_per_product', $review_number_to);
    328 
    329                 //clear this meta in all products, it will be recalculated during reviews loading
    330                 Review::clear_all_product_max_number_review_meta();
    331 
    332                 //raiting fields
    333                 $raiting_from = 1;
    334                 $raiting_to = 5;
    335                 if (isset($_POST['a2wl_review_raiting_from'])) {
    336                     $raiting_from = intval($_POST['a2wl_review_raiting_from']);
    337                 }
    338 
    339                 if (isset($_POST['a2wl_review_raiting_to'])) {
    340                     $raiting_to = intval($_POST['a2wl_review_raiting_to']);
    341                 }
    342 
    343                 if ($raiting_from >= 5) {
    344                     $raiting_from = 5;
    345                 }
    346 
    347                 if ($raiting_from < 1 || $raiting_from > $raiting_to) {
    348                     $raiting_from = 1;
    349                 }
    350 
    351                 if ($raiting_to >= 5) {
    352                     $raiting_to = 5;
    353                 }
    354 
    355                 if ($raiting_to < 1) {
    356                     $raiting_to = 1;
    357                 }
    358 
    359                 set_setting('review_raiting_from', $raiting_from);
    360                 set_setting('review_raiting_to', $raiting_to);
    361 
    362                 //update more field
    363                 set_setting('review_load_attributes', isset($_POST['a2wl_review_load_attributes']));
    364 
    365                 set_setting('review_show_image_list', isset($_POST['a2wl_review_show_image_list']));
    366 
    367                 if (isset($_POST['a2wl_review_show_image_list'])) {
    368                     $a2wl_review_thumb_width = intval($_POST['a2wl_review_thumb_width']);
    369 
    370                     if ($a2wl_review_thumb_width > 0) {
    371                         set_setting('review_thumb_width', $a2wl_review_thumb_width);
    372                     } else {
    373                         set_setting('review_thumb_width', 30);
    374                     }
    375                 }
    376 
    377                 set_setting('review_skip_empty', isset($_POST['a2wl_review_skip_empty']));
    378                 set_setting('review_skip_keywords', isset($_POST['a2wl_review_skip_keywords']) ? trim(wp_unslash($_POST['a2wl_review_skip_keywords'])) : '');
    379 
    380                 if (!isset($_POST['a2wl_review_country']) || !is_array($_POST['a2wl_review_country'])) {
    381                     set_setting('review_country', array());
    382                 } else {
    383                     set_setting('review_country', $_POST['a2wl_review_country']);
    384                 }
    385 
    386                 set_setting('moderation_reviews', isset($_POST['a2wl_moderation_reviews']));
    387 
    388                 if (isset($_FILES) && isset($_FILES['a2wl_review_noavatar_photo']) && 0 === $_FILES['a2wl_review_noavatar_photo']['error']) {
    389 
    390                     if (!function_exists('wp_handle_upload')) {
    391                         require_once ABSPATH . 'wp-admin/includes/file.php';
    392                     }
    393 
    394                     $uploadedfile = $_FILES['a2wl_review_noavatar_photo'];
    395                     $upload_overrides = array('test_form' => false);
    396                     $movefile = wp_handle_upload($uploadedfile, $upload_overrides);
    397                     if ($movefile) {
    398                         set_setting('review_noavatar_photo', $movefile['url']);
    399                     } else {
    400                         echo "Possible file upload attack!\n";
    401                     }
    402                 } else {
    403                     del_setting('review_noavatar_photo');
    404                 }
    405 
    406                 settings()->commit();
    407                 settings()->auto_commit(true);
    408 
    409             }
    410 
    411             $countryModel = new Country();
    412             $countries = $countryModel->get_countries();
    413 
    414             unset($countries[0]);
    415 
    416             $this->model_put("reviews_countries", $countries);
    417 
    418             return "settings/reviews.php";
    419         }
    420 
    421         private function shipping()
    422         {
    423             if (!empty($_POST)) {
    424                 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
    425             }
    426 
    427             if (isset($_POST['setting_form'])) {
    428 
    429                 set_setting('aliship_shipto', isset($_POST['a2w_aliship_shipto']) ? wp_unslash($_POST['a2w_aliship_shipto']) : 'US');
    430                 set_setting('aliship_frontend', isset($_POST['a2wl_aliship_frontend']));
    431                 set_setting('default_shipping_class', !empty($_POST['a2wl_default_shipping_class']) ? $_POST['a2wl_default_shipping_class'] : false);
    432 
    433                 if (isset($_POST['a2wl_aliship_frontend'])) {
    434 
    435                     if (isset($_POST['default_rule'])) {
    436                         ShippingPriceFormula::set_default_formula(new ShippingPriceFormula($_POST['default_rule']));
    437                     }
    438 
    439                     set_setting('aliship_selection_type', isset($_POST['a2wl_aliship_selection_type']) ? wp_unslash($_POST['a2wl_aliship_selection_type']) : 'popup');
    440 
    441                     set_setting('aliship_shipping_type', isset($_POST['a2wl_aliship_shipping_type']) ? wp_unslash($_POST['a2wl_aliship_shipping_type']) : 'new');
    442 
    443                     set_setting('aliship_shipping_option_text',
    444                         (isset($_POST['a2wl_aliship_shipping_option_text']) && !empty($_POST['a2wl_aliship_shipping_option_text'])) ?
    445                         wp_unslash($_POST['a2wl_aliship_shipping_option_text']) : '[{shipping_cost}] {shipping_company} ({delivery_time}) - {country}');
    446 
    447                     set_setting('aliship_shipping_label', isset($_POST['a2wl_aliship_shipping_label']) ? wp_unslash($_POST['a2wl_aliship_shipping_label']) : 'Shipping');
    448                     set_setting('aliship_free_shipping_label', isset($_POST['a2wl_aliship_free_shipping_label']) ? wp_unslash($_POST['a2wl_aliship_free_shipping_label']) : 'Free Shipping');
    449 
    450                     set_setting('aliship_product_enable', isset($_POST['a2wl_aliship_product_enable']));
    451 
    452                     if (isset($_POST['a2wl_aliship_product_enable'])) {
    453                         set_setting('aliship_product_position', isset($_POST['a2wl_aliship_product_position']) ? wp_unslash($_POST['a2wl_aliship_product_position']) : 'after_cart');
    454 
    455                         set_setting('aliship_product_not_available_message',
    456                             (isset($_POST['a2wl_aliship_product_not_available_message']) && !empty($_POST['a2wl_aliship_product_not_available_message'])) ?
    457                             wp_unslash($_POST['a2wl_aliship_product_not_available_message']) : 'This product can not be delivered to {country}.');
    458                     }
    459 
    460                     set_setting('aliship_not_available_remove', isset($_POST['a2wl_aliship_not_available_remove']));
    461 
    462                     set_setting('aliship_not_available_message',
    463                         (isset($_POST['a2wl_aliship_not_available_message']) && !empty($_POST['a2wl_aliship_not_available_message'])) ?
    464                         wp_unslash($_POST['a2wl_aliship_not_available_message']) : '[{shipping_cost}] {delivery_time} - {country}');
    465 
    466                     $not_available_shipping_cost = (isset($_POST['a2wl_aliship_not_available_cost']) && floatval($_POST['a2wl_aliship_not_available_cost']) >= 0) ? floatval($_POST['a2wl_aliship_not_available_cost']) : 10;
    467 
    468                     set_setting('aliship_not_available_cost', $not_available_shipping_cost);
    469 
    470                     $min_time = (isset($_POST['a2wl_aliship_not_available_time_min']) && intval($_POST['a2wl_aliship_not_available_time_min']) > 0) ? intval($_POST['a2wl_aliship_not_available_time_min']) : 20;
    471                     $max_time = (isset($_POST['a2wl_aliship_not_available_time_max']) && intval($_POST['a2wl_aliship_not_available_time_max']) > 0) ? intval($_POST['a2wl_aliship_not_available_time_max']) : 30;
    472 
    473                     set_setting('aliship_not_available_time_min', $min_time);
    474                     set_setting('aliship_not_available_time_max', $max_time);
    475 
    476                 }
    477 
    478             }
    479 
    480             $countryModel = new Country();
    481 
    482             $this->model_put("shipping_countries", $countryModel->get_countries());
    483 
    484             $this->model_put("shipping_selection_types", Shipping::get_selection_types());
    485 
    486             $this->model_put("shipping_types", Shipping::get_shipping_types());
    487 
    488             $this->model_put("selection_position_types", Shipping::get_selection_position_types());
    489 
    490             $this->model_put("default_formula", ShippingPriceFormula::get_default_formula());
    491 
    492             $shipping_class = get_terms(array('taxonomy' => 'product_shipping_class', 'hide_empty' => false));
    493             $this->model_put("shipping_class", $shipping_class ? $shipping_class : array());
    494 
    495             return "settings/shipping.php";
    496         }
    497 
    498         private function phrase_filter()
    499         {
    500             $phrases = PhraseFilter::load_phrases();
    501 
    502             if ($phrases) {
    503                 $this->model_put("phrases", $phrases);
    504             } else {
    505                 $this->model_put("phrases", array());
    506             }
    507 
    508             return "settings/phrase_filter.php";
    509         }
    510 
    511         private function chrome_api()
    512         {
    513             if (!empty($_POST)) {
    514                 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
    515             }
    516 
    517             $api_keys = get_setting('api_keys', array());
    518 
    519             if (!empty($_REQUEST['delete-key'])) {
    520                 foreach ($api_keys as $k => $key) {
    521                     if ($key['id'] === $_REQUEST['delete-key']) {
    522                         unset($api_keys[$k]);
    523                         set_setting('api_keys', $api_keys);
    524                         break;
    525                     }
    526                 }
    527                 wp_redirect(admin_url('admin.php?page=a2wl_setting&subpage=chrome_api'));
    528             } else if (!empty($_POST['a2wl_api_key'])) {
    529                 $key_id = $_POST['a2wl_api_key'];
    530                 $key_name = !empty($_POST['a2wl_api_key_name']) ? $_POST['a2wl_api_key_name'] : "New key";
    531 
    532                 $is_new = true;
    533                 foreach ($api_keys as &$key) {
    534                     if ($key['id'] === $key_id) {
    535                         $key['name'] = $key_name;
    536                         $is_new = false;
    537                         break;
    538                     }
    539                 }
    540 
    541                 if ($is_new) {
    542                     $api_keys[] = array('id' => $key_id, 'name' => $key_name);
    543                 }
    544 
    545                 set_setting('api_keys', $api_keys);
    546 
    547                 wp_redirect(admin_url('admin.php?page=a2wl_setting&subpage=chrome_api&edit-key=' . $key_id));
    548             } else if (isset($_REQUEST['edit-key'])) {
    549                 $api_key = array('id' => md5("a2wkey" . wp_rand() . microtime()), 'name' => "New key");
    550                 $is_new = true;
    551                 if (empty($_REQUEST['edit-key'])) {
    552                     $api_keys[] = $api_key;
    553                     set_setting('api_keys', $api_keys);
    554 
    555                     wp_redirect(admin_url('admin.php?page=a2wl_setting&subpage=chrome_api&edit-key=' . $api_key['id']));
    556                 } else if (!empty($_REQUEST['edit-key']) && $api_keys && is_array($api_keys)) {
    557                     foreach ($api_keys as $key) {
    558                         if ($key['id'] === $_REQUEST['edit-key']) {
    559                             $api_key = $key;
    560                             $is_new = false;
    561                         }
    562                     }
    563                 }
    564                 $this->model_put("api_key", $api_key);
    565                 $this->model_put("is_new_api_key", $is_new);
    566             }
    567 
    568             $this->model_put("api_keys", $api_keys);
    569 
    570             return "settings/chrome.php";
    571         }
    572 
    573         private function system_info()
    574         {
    575             if (!empty($_POST)) {
    576                 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
    577             }
    578 
    579             if (isset($_POST['setting_form'])) {
    580                 set_setting('write_info_log', isset($_POST['a2wl_write_info_log']));
    581             }
    582 
    583             $server_ip = '-';
    584             if (array_key_exists('SERVER_ADDR', $_SERVER)) {
    585                 $server_ip = $_SERVER['SERVER_ADDR'];
    586             } elseif (array_key_exists('LOCAL_ADDR', $_SERVER)) {
    587                 $server_ip = $_SERVER['LOCAL_ADDR'];
    588             } elseif (array_key_exists('SERVER_NAME', $_SERVER)) {
    589                 $server_ip = gethostbyname($_SERVER['SERVER_NAME']);
    590             } else {
    591                 // Running CLI
    592                 if (stristr(PHP_OS, 'WIN')) {
    593                     $server_ip = gethostbyname(php_uname("n"));
    594                 } else {
    595                     $ifconfig = shell_exec('/sbin/ifconfig eth0');
    596                     preg_match('/addr:([\d\.]+)/', $ifconfig, $match);
    597                     $server_ip = $match[1];
    598                 }
    599             }
    600 
    601             $this->model_put("server_ip", $server_ip);
    602 
    603             return "settings/system_info.php";
    604         }
    605     }
     603                $ifconfig = shell_exec('/sbin/ifconfig eth0');
     604                preg_match('/addr:([\d\.]+)/', $ifconfig, $match);
     605                $server_ip = $match[1];
     606            }
     607        }
     608
     609        $this->model_put("server_ip", $server_ip);
     610
     611        return "settings/system_info.php";
     612    }
     613}
  • ali2woo-lite/trunk/includes/classes/controller/TransferPageController.php

    r3111831 r3159867  
    1515    public function __construct()
    1616    {
    17         parent::__construct(esc_html__('Transfer', 'ali2woo'), esc_html__('Transfer', 'ali2woo'), 'import', 'a2wl_transfer', 95);
     17        parent::__construct(
     18            esc_html__('Transfer', 'ali2woo'), esc_html__('Transfer', 'ali2woo'),
     19            'import', 'a2wl_transfer', 95
     20        );
    1821    }
    1922
    20     public function render($params = array())
     23    public function render($params = []): void
    2124    {
    2225        if (!current_user_can('manage_options')) {
     
    2932    }
    3033
    31     private function getSettingsString()
     34    private function getSettingsString(): string
    3235    {
    33         $settings = get_option('a2wl_settings', array());
     36        $settings = get_option('a2wl_settings', []);
    3437
    35         $hash = base64_encode(serialize($settings));
    36 
    37         return $hash;
     38        return base64_encode(serialize($settings));
    3839    }
    3940
    40     private function saveHandler()
     41    private function saveHandler(): void
    4142    {
    4243        if (isset($_POST['transfer_form']) && !empty($_POST['hash'])) {
    4344            check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
    44             if (!$settings = base64_decode($_POST['hash'])) {
    45                 $this->model_put("error", esc_html__('Hash is not correct', 'ali2woo'));
     45
     46            $hash = base64_decode($_POST['hash']);
     47
     48            if (!$hash) {
     49                $this->model_put("error",
     50                    esc_html_x('Hash is not correct', 'error text', 'ali2woo')
     51                );
     52
    4653                return;
    4754            }
    4855
    49             if (!$settings = unserialize($settings)) {
    50                 $this->model_put("error", esc_html__('Hash is not correct', 'ali2woo'));
     56            $settings = unserialize($hash, ['allowed_classes' => false]);
     57
     58            if (!$settings) {
     59                $this->model_put("error",
     60                    esc_html_x('Hash is not correct', 'error text', 'ali2woo')
     61                );
     62
    5163                return;
    5264            }
  • ali2woo-lite/trunk/includes/classes/job/ImportProcess.php

    r3107543 r3159867  
    3636            a2wl_info_log("START_STEP[id:".$item['product_id'].", extId: ".$item['id'].", step: ".$item['step']."]");
    3737
    38             if(substr($item['step'], 0, strlen('reviews')) === 'reviews'){
    39                 if(get_setting('load_review')){
     38            if (str_starts_with($item['step'], 'reviews')) {
     39                if (get_setting('load_review')) {
    4040                    $reviews_model = new Review();
    4141
    4242                    $result = $reviews_model->load($item['product_id'], true, array('step'=>$item['step']));
    4343
    44                     if(!empty($result['new_steps'])) {
     44                    if (!empty($result['new_steps'])) {
    4545                        // add new steps to new queue
    4646                        ImportProcess::create_new_queue($item['product_id'], $item['id'], $result['new_steps'], false);
    47                     }
    48 
    49                     if($item['step']=='reviews'){
    50                         add_filter($this->identifier . '_time_exceeded', array($this, 'finish_iteration'));
    5147                    }
    5248
     
    6965                    unset($woocommerce_model, $product);
    7066
    71                     if(!empty($result['new_steps'])) {
     67                    if (!empty($result['new_steps'])) {
    7268                        // add new steps to new queue
    7369                        ImportProcess::create_new_queue($item['product_id'], $item['id'], $result['new_steps']);
    7470                    }
    7571
    76                     if(
    77                         // (!get_setting('use_external_image_urls') && substr($item['step'], 0, strlen('preload_images')) === 'preload_images') ||
    78                         $item['step']=='finishing'
    79                     ) {
    80                         add_filter($this->identifier . '_time_exceeded', array($this, 'finish_iteration'));
    81                     }
    82                    
    8372                    if ($result['state'] === 'error') {
    8473                        throw new Exception($result['message']);
     
    9685
    9786        return false;
    98     }
    99 
    100     public function finish_iteration($res) {
    101         return true;
    10287    }
    10388
  • ali2woo-lite/trunk/includes/classes/model/Review.php

    r3107543 r3159867  
    88
    99namespace AliNext_Lite;;
     10
     11use WC_Comments;
    1012
    1113class Review {
     
    4749    /**
    4850     * Get reviews and save them in Woocommerce
    49      *
    50      * @param mixed $post_id
    5151     */
    52     public function load($post_id, $force_clean = false, $params = array()) {
     52    public function load(int $post_id, bool $force_clean = false, array $params = []): ?array
     53    {
    5354        global $wpdb;
    5455
    55         $step = isset($params['step'])?$params['step']:false;
     56        $step = $params['step'] ?? false;
    5657
    5758        $external_id = get_post_meta($post_id, "_a2w_external_id", true);
    5859        if (!$external_id) {
    59             return false;
    60         }
    61 
    62         $new_steps = array();
    63 
    64         if($step === false || $step === 'reviews'){
    65             $comment_number = get_comments(array('post_id' => $post_id, 'meta_key' => 'rating', 'count' => true));
    66            
     60            return null;
     61        }
     62
     63        $new_steps = [];
     64
     65        if ($step === false || $step === 'reviews') {
     66            $comment_number = get_comments(
     67                [
     68                    'post_id' => $post_id,
     69                    'meta_key' => 'rating',
     70                    'count' => true
     71                ]
     72            );
     73
    6774            $max_number_reviews_per_product = $this->get_max_reviews_number_by_product($post_id);
    68            
    6975            $remaining_comment_number = $max_number_reviews_per_product - $comment_number;
    7076
     
    8187                    delete_post_meta($post_id, '_wc_rating_count');
    8288
    83                     \WC_Comments::clear_transients($post_id);
    84 
    85                     $nextPageNumber = ($remaining_comment_number < count($res['reviews'])) ? $pageNumber : ($pageNumber + 1);
    86 
    87                     $added_review_cash = array();
     89                    WC_Comments::clear_transients($post_id);
     90
     91                    $nextPageNumber = ($remaining_comment_number < count($res['reviews'])) ?
     92                        $pageNumber :
     93                        ($pageNumber + 1);
     94
     95                    $added_review_cash = [];
    8896
    8997                    foreach ($res['reviews'] as $item) {
     
    101109                        }
    102110
    103                         $review_cache = md5($post_id . $external_id . $item['buyer']['buyerTitle'] . (isset($item['review']['reviewContent'])?$item['review']['reviewContent']:"") . $item['review']['reviewDate']);
    104                         $has_same_comment = $wpdb->get_var($wpdb->prepare("SELECT count(c.comment_ID) FROM {$wpdb->comments} c LEFT JOIN {$wpdb->commentmeta} cm ON (c.comment_ID = cm.comment_id and cm.meta_key='a2wl_cash') WHERE cm.meta_value=%s", $review_cache)) > 0;
     111                        $review_cache = md5(
     112                            $post_id . $external_id . $item['buyer']['buyerTitle'] .
     113                            ( $item['review']['reviewContent'] ?? "" ) . $item['review']['reviewDate']
     114                        );
     115
     116                        $queryTemplate = "SELECT count(c.comment_ID) FROM {$wpdb->comments} c " .
     117                            "LEFT JOIN {$wpdb->commentmeta} cm " .
     118                            "ON (c.comment_ID = cm.comment_id and cm.meta_key='a2wl_cash') " .
     119                            "WHERE cm.meta_value=%s";
     120                        $has_same_comment = $wpdb->get_var($wpdb->prepare($queryTemplate, $review_cache)) > 0;
    105121                        if ($has_same_comment || !empty($added_review_cash[$review_cache])) {
    106122                            continue;
    107123                        }
    108                        
    109                         $tmp_text = ($this->review_translated && isset($item['review']['translation']) && isset($item['review']['translation']['reviewContent']))  ? $item['review']['translation']['reviewContent'] : (isset($item['review']['reviewContent'])?$item['review']['reviewContent']:"");
    110                        
     124
     125
     126                        $tmp_text = ($this->review_translated && isset($item['review']['translation']['reviewContent']))
     127                            ? $item['review']['translation']['reviewContent'] :
     128                            ($item['review']['reviewContent'] ?? "");
     129
    111130                        $tmp_text = trim(str_replace("\\u0000", '', $tmp_text));
    112131                        if ($this->review_load_attributes && isset($item['review']['itemSpecInfo'])) {
    113                             $tmp_text = $tmp_text . "<br/><br/>" . preg_replace('#([\w\-]+:)#', '<b>$1</b>', str_replace(':', ': ', PhraseFilter::apply_filter_to_text($item['review']['itemSpecInfo'])));
    114                             //$tmp_text = $tmp_text . "<br/><br/>" . str_replace(':', ': ', PhraseFilter::apply_filter_to_text($item['review']['itemSpecInfo']));
     132                            $tmp_text = $tmp_text . "<br/><br/>" .
     133                                preg_replace('#([\w\-]+:)#', '<b>$1</b>',
     134                                    str_replace(':', ': ',
     135                                        PhraseFilter::apply_filter_to_text($item['review']['itemSpecInfo'])));
    115136                        }
    116137
    117138                        $maybe_skip_review = $this->maybe_skip_review($tmp_text);
    118139
    119                         if ($maybe_skip_review){
    120                             continue;     
     140                        if ($maybe_skip_review) {
     141                            continue;
    121142                        }
    122143
     
    128149
    129150                        $comment_approved = get_setting('moderation_reviews') ? 0 : 1;
    130                        
    131                         $data = array(
     151
     152                        $data = [
    132153                            'comment_post_ID' => $post_id,
    133154                            'comment_author' => $author,
     
    141162                            'comment_type' => 'review',
    142163                            'comment_approved' => $comment_approved,
    143                         );
     164                        ];
    144165
    145166                        $comment_id = wp_insert_comment($data);
     
    149170                        add_comment_meta($comment_id, 'a2wl_country', $item['buyer']['buyerCountry'], true);
    150171
    151                         if($step === false){
     172                        if ($step === false) {
    152173                            // if this is one thread import, then load images
    153174                            if (get_setting('review_avatar_import')) {
    154                                 $author_photo = isset($item['buyer']['buyerImage']) ? $item['buyer']['buyerImage'] : false;
     175                                $author_photo = $item['buyer']['buyerImage'] ?? false;
    155176                                if ($author_photo !== false) {
    156177                                    $author_photo = $this->helper->image_http_to_https($author_photo);
     
    162183                            }
    163184
    164                             $photo_ids = array();
     185                            $photo_ids = [];
    165186
    166187                            if (get_setting('review_show_image_list')) {
    167                                 $photo_list = !empty($item['review']['reviewImages']) ? (is_array($item['review']['reviewImages']) ? $item['review']['reviewImages'] : array($item['review']['reviewImages'])) : array();
     188
     189                                $photo_list = !empty($item['review']['reviewImages']) ?
     190                                    (is_array($item['review']['reviewImages']) ?
     191                                        $item['review']['reviewImages'] :
     192                                        [$item['review']['reviewImages']]) : [];
    168193
    169194                                foreach ($photo_list as $photo) {
    170195                                    $photo = $this->helper->image_http_to_https($photo);
    171                                     if ($photo_id = $this->attachment_model->create_attachment($post_id, $photo, array('inner_post_id' => $post_id, 'inner_attach_type' => 'comment'))) {
     196                                    if ($photo_id = $this->attachment_model->create_attachment(
     197                                        $post_id,
     198                                        $photo,
     199                                        ['inner_post_id' => $post_id, 'inner_attach_type' => 'comment'])
     200                                    ) {
    172201                                        $photo_ids[] = $photo_id;
    173202                                    }
     
    177206                                }
    178207                            }
    179                         }else{
     208                        } else {
    180209                            // step by step flow. Prepare steps.
    181210                            if (get_setting('review_avatar_import')) {
    182                                 $author_photo = isset($item['buyer']['buyerImage']) ? $item['buyer']['buyerImage'] : false;
     211                                $author_photo = $item['buyer']['buyerImage'] ?? false;
    183212                                if ($author_photo) {
    184213                                    $author_photo = $this->helper->image_http_to_https($author_photo);
     
    188217
    189218                            if (get_setting('review_show_image_list')) {
    190                                 $photo_list = !empty($item['review']['reviewImages']) ? (is_array($item['review']['reviewImages']) ? $item['review']['reviewImages'] : array($item['review']['reviewImages'])) : array();
     219
     220                                $photo_list = !empty($item['review']['reviewImages']) ?
     221                                    (is_array($item['review']['reviewImages']) ?
     222                                        $item['review']['reviewImages'] :
     223                                        [$item['review']['reviewImages']]) : [];
     224
    191225                                foreach ($photo_list as $photo) {
    192226                                    $photo = $this->helper->image_http_to_https($photo);
     
    218252
    219253            //make sure that post comment status is 'open'
    220             $post_arr = array('ID' => $post_id, 'comment_status'=>'open');
     254            $post_arr = [
     255                'ID' => $post_id,
     256                'comment_status'=>'open'
     257            ];
    221258            wp_update_post($post_arr);
    222259
    223260            if ($force_clean) {
    224                 \WC_Comments::clear_transients($post_id);
    225             }               
    226         }
    227 
    228         if(substr($step, 0, strlen('reviews#avatar')) === 'reviews#avatar'){
     261                WC_Comments::clear_transients($post_id);
     262            }
     263        }
     264
     265        if (str_starts_with($step, 'reviews#avatar')) {
    229266            $parts = explode('#', $step, 4);
    230267            if(count($parts)==4){
     
    239276        }
    240277
    241         if(substr($step, 0, strlen('reviews#photo')) === 'reviews#photo') {
     278        if (str_starts_with($step, 'reviews#photo')) {
    242279            $parts = explode('#', $step, 4);
    243             if(count($parts)==4){
     280            if (count($parts) == 4) {
    244281                $comment_id = $parts[2];
    245282                $photo = $parts[3];
    246283
    247                 $photo_id = $this->attachment_model->create_attachment($post_id, $photo, array('inner_post_id' => $post_id, 'inner_attach_type' => 'comment'));
     284                $photo_id = $this->attachment_model->create_attachment($post_id, $photo,
     285                    [
     286                        'inner_post_id' => $post_id,
     287                        'inner_attach_type' => 'comment'
     288                    ]
     289                );
    248290                if ($photo_id) {
    249                     $photo_ids = get_comment_meta( $comment_id, 'a2wl_photo_list', true);
    250                     if($photo_ids){
     291                    $photo_ids = get_comment_meta($comment_id, 'a2wl_photo_list', true);
     292                    if ($photo_ids) {
    251293                        $photo_ids[] = $photo_id;
    252294                        update_comment_meta($comment_id, 'a2wl_photo_list', $photo_ids);
    253                     }else{
    254                         $photo_ids = array($photo_id);
     295                    } else {
     296                        $photo_ids = [
     297                            $photo_id
     298                        ];
    255299                        add_comment_meta($comment_id, 'a2wl_photo_list', $photo_ids, true);
    256300                    }
     
    259303        }
    260304
    261         return ResultBuilder::buildOk(array('new_steps'=>$new_steps));
     305        return ResultBuilder::buildOk(['new_steps' => $new_steps]);
    262306    }
    263307
     
    265309        $result = get_post_meta( $post_id, Constants::product_reviews_max_number_meta(), true);
    266310
    267         if (!$result){           
    268             $result =  wp_rand( $this->max_number_reviews_per_product, $this->min_number_reviews_per_product ); 
     311        if (!$result){
     312            $result =  wp_rand( $this->max_number_reviews_per_product, $this->min_number_reviews_per_product );
    269313            update_post_meta( $post_id, Constants::product_reviews_max_number_meta(), $result );
    270         } 
     314        }
    271315
    272316        return $result;
     
    356400            $query_result = $wpdb->query("UPDATE {$wpdb->postmeta} SET meta_value = 0 WHERE meta_key = '_wc_review_count'");
    357401
    358             \WC_Comments::delete_comments_count_cache();
     402            WC_Comments::delete_comments_count_cache();
    359403        }
    360404    }
     
    386430
    387431        global $wpdb;
    388        
     432
    389433        $wpdb->query(
    390434            $wpdb->prepare(
  • ali2woo-lite/trunk/readme.txt

    r3141586 r3159867  
    1 === AliExpress Dropshipping Plugin – AliNext ===
     1=== AliExpress Dropshipping Plugin for WooCommerce – AliNext ===
    22Contributors: ali2woo
    3 Tags: aliexpress dropshipping, dropshipping, ali2woo, dropship
     3Tags: aliexpress dropshipping, woocommerce dropshipping, dropship
    44Requires at least: 5.9
    55Tested up to: 6.6
     
    88Stable tag: trunk
    99Requires PHP: 8.0
    10 WC tested up to: 9.2
     10WC tested up to: 9.3
    1111WC requires at least: 5.0
    1212
     
    3636- Plugin works based on WooCommerce plugin.
    3737
    38 - You have to generate the access token (aliexpress token) to place or sync orders. You don't need the token to import products. Please [follow our instruction](https://help.ali2woo.com/codex/how-to-get-access-token-from-aliexpress/) in order to generate token.
     38- You have to generate the access token (AliExpress token) to place or sync orders. You don't need the token to import products. Please [follow our instruction](https://help.ali2woo.com/codex/how-to-get-access-token-from-aliexpress/) in order to generate token.
    3939
    4040- Your permalink structure must NOT be "Plain"
     
    4646&#9658; **Import Products**:
    4747
    48 This aliexpress dropshipping plugin imports products from AliExpress with several methods: via a built-in search module or through the free chrome extension. Additionally, it can pull products from selected categories or store pages on AliExpress. Also, if you want to import a specific product only, you can use AliExpress product ID or AliExpress product URL to do that.
     48This AliExpress Dropshipping plugin imports products into WooCommerce using a built-in search module or a free Chrome extension. Additionally, it can pull products from selected categories or store pages on AliExpress. Also, if you want to import a specific product only, you can use AliExpress product ID or AliExpress product URL to do that.
    4949
    5050- **Import from single product page**
     
    6969&#9658; **Split product variants into separate products**:
    7070
    71 The plugin allows splitting product variants. For example: a lot of products on AliExpress come with the "ShipFrom" attribute. Often dropshippers don't want to show this variant for customers. With this feature it's possible to split such a product by the "ShipFrom" attribute. As result you will get separate products without it.
     71The plugin allows splitting product variants. For example: a lot of products on AliExpress come with the "ShipFrom" attribute. Often drop shippers don't want to show this variant for customers. With this feature it's possible to split such a product by the "ShipFrom" attribute. As result you will get separate products without it.
    7272
    7373Please look through the [this article](https://ali2woo.com/codex/how-to-split-product-variants-video/) to understand clearly how splitting feature works.
     
    8080
    8181The product override feature is very helpful if you get a new order for the out-of-stock product and want to fulfill the order from another supplier or vendor on AliExpress.
    82 Also it helps if you have a product that was loaded through other dropshipping tool or it was added manually in Woocommerce and you want to connect the product to some AliExpress item using AliNext
     82Also it helps if you have a product that was loaded through other dropshipping tool or it was added manually in WooCommerce and you want to connect the product to some AliExpress item using AliNext
    8383
    8484Check out an article from the plugin Knowledge Base to know [how to use this feature.](https://ali2woo.com/codex/how-to-change-the-product-supplier/)
     
    9696- **Language**: Set language of product data such as title, description, variations, attributes, etc. Our plugin supports all languages which available on AliExpress.
    9797
    98 - **Currency**: Change the currency of products. AliNxt supports all currencies which AliExpress portal operates with.
     98- **Currency**: Change the currency of products. AliNext supports all currencies which AliExpress portal operates with.
    9999
    100100- **Default product type**: By default the plugin imports product as "Simple/Variable product". In this case, shoppers will stay on your website when they make a purchase else choose the "External/Affiliate Product" option and your visitors will be redirected to AliExpress to finish the purchase.
     
    106106- **Not import description**: Enable this feature if you don't want to import product description from AliExpress.
    107107
    108 - **Don't import images from the description**: If you want to skip images from the product description and don't import them to the wordpress media library, use this option.
    109 
    110 - **Use external image urls**: By default, the plugin keeps product images on your server. If you want to save free space on your server,
     108- **Don't import images from the description**: If you want to skip images from the product description and don't import them to the WordPress media library, use this option.
     109
     110- **Use external image URLs**: By default, the plugin keeps product images on your server. If you want to save free space on your server,
    111111activate this option and the plugin will load an image using an external AliExpress URL. Please note: This feature works if the plugin is active only!
    112112
     
    117117- **Allow product duplication**: Allow the import of an already imported product. This can be useful when you want to override a product with the same product.
    118118
    119 - **Convert case of attributes and their values**: Products may come with different text case of attributes and their values. Enbale this feature to covert all texts to the same case.
     119- **Convert case of attributes and their values**: Products may come with different text case of attributes and their values. Enable this feature to covert all texts to the same case.
    120120
    121121- **Remove "Ship From" attribute**: Use this feature to remove the "Ship From" attribute automatically during product import.
     
    309309== Changelog ==
    310310
     311= 3.4.4 - 2024.09.30 =
     312* Add compatibility with WooCommerce 9.3.*
     313* Add server max execution time and memory limit checks on the System Info page
     314* Enhance product background loader (should work faster even on cheap hosting plans)
     315* Fix shipping loader (premium plugin version)
     316* Fix built-in store products` search
     317* Fix issue causing Wordfence notice
     318
    311319= 3.4.3 - 2024.08.26 =
    312320* Fix bug pricing rules type is not applied on choosing pricing set;
     
    380388* refactor plugin code to improve performance
    381389* fix minor bugs and errors
    382 
    383 = 3.1.4 - 2023.11.23 =
    384 * fix last update time on product update
    385 * fix tracking_id param in aliexpress affiliate links
    386 * fix some warnings related with old style function call
    387390== Upgrade Notice ==
    388391
  • ali2woo-lite/trunk/view/settings/system_info.php

    r3107543 r3159867  
    7373                            <?php $maxExecutionTime = intval(ini_get("max_execution_time")); ?>
    7474                            <?php if ($maxExecutionTime < 30 ): ?>
    75                             <span class="error">Error</span>
     75                            <span class="error">Error (<?php echo $maxExecutionTime; ?> sec)</span>
    7676                            <div class="info-box"
    7777                                 data-toggle="tooltip"
     
    7979                            </div>
    8080                            <?php else: ?>
    81                             <span class="ok">Ok</span>
     81                            <span class="ok">Ok (<?php echo $maxExecutionTime; ?> sec)</span>
    8282                            <?php endif;?>
    8383                        </div>
    8484                    </div>
    8585                </div>
     86
     87                <div class="field field_inline">
     88                    <div class="field__label">
     89                        <label>
     90                            <strong><?php  esc_html_e('Php max memory limit', 'ali2woo'); ?></strong>
     91                        </label>
     92                        <div class="info-box" data-toggle="tooltip" data-title="<?php _ex('Php memory limit', 'setting description', 'ali2woo'); ?>"></div>
     93                    </div>
     94                    <div class="field__input-wrap">
     95                        <div class="form-group input-block no-margin clearfix">
     96                            <?php $memoryLimit = ini_get("memory_limit");
     97                            $memoryLimitInBytes = $memoryLimit ? wp_convert_hr_to_bytes($memoryLimit) : 0;
     98                            $minMemoryLimit = 128 * 1000000; //128 mb;
     99                            $formatMemoryLimit = size_format($memoryLimitInBytes);
     100                            ?>
     101                            <?php if ($memoryLimitInBytes < $minMemoryLimit): ?>
     102                                <span class="error">Error (<?php echo $formatMemoryLimit; ?>)</span>
     103                                <div class="info-box"
     104                                     data-toggle="tooltip"
     105                                     data-title="<?php _ex('You have to increase php memory_limit to 128 MB at least', 'setting description', 'ali2woo'); ?>">
     106                                </div>
     107                            <?php else: ?>
     108                                <span class="ok">Ok (<?php echo $formatMemoryLimit; ?>)</span>
     109                            <?php endif;?>
     110                        </div>
     111                    </div>
     112                </div>
     113
    86114                <div class="field field_inline">
    87115                    <div class="field__label">
Note: See TracChangeset for help on using the changeset viewer.