From bb0aaf4d61168f13eb98c48ecc1913a83337867c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Povilas=20Ka=C4=8Dinskas?= Date: Tue, 17 Dec 2019 12:06:32 +0200 Subject: [PATCH] merge new version 2.5.788 --- Trustpilot/config.php | 2 +- Trustpilot/helper.php | 70 +++++++++------- Trustpilot/review/Admin.php | 55 ++++++++----- Trustpilot/review/Orders.php | 75 ++++++++++++------ Trustpilot/review/PastOrders.php | 14 ++-- Trustpilot/review/Plugin.php | 31 ++++---- Trustpilot/review/Products.php | 12 ++- Trustpilot/review/TrustBox.php | 79 ++++++++++++++++--- .../review/api/TrustpilotPluginStatus.php | 7 +- .../review/assets/css/trustpilot.min.css | 1 + .../review/assets/js/headerScript.min.js | 2 + .../review/assets/js/headerScript.min.js.map | 1 + .../review/assets/js/integrationScript.js | 23 ++++++ .../review/assets/js/integrationScript.min.js | 2 + .../assets/js/integrationScript.min.js.map | 1 + .../review/assets/js/thankYouScript.min.js | 2 + .../assets/js/thankYouScript.min.js.map | 1 + Trustpilot/review/assets/js/trustBoxScript.js | 3 +- .../review/assets/js/trustBoxScript.min.js | 2 + .../assets/js/trustBoxScript.min.js.map | 1 + Trustpilot/review/util/TrustpilotLogger.php | 45 +++++++++++ Trustpilot/wc_trustpilot.php | 31 +------- 22 files changed, 319 insertions(+), 141 deletions(-) create mode 100644 Trustpilot/review/assets/css/trustpilot.min.css create mode 100644 Trustpilot/review/assets/js/headerScript.min.js create mode 100644 Trustpilot/review/assets/js/headerScript.min.js.map create mode 100644 Trustpilot/review/assets/js/integrationScript.min.js create mode 100644 Trustpilot/review/assets/js/integrationScript.min.js.map create mode 100644 Trustpilot/review/assets/js/thankYouScript.min.js create mode 100644 Trustpilot/review/assets/js/thankYouScript.min.js.map create mode 100644 Trustpilot/review/assets/js/trustBoxScript.min.js create mode 100644 Trustpilot/review/assets/js/trustBoxScript.min.js.map create mode 100755 Trustpilot/review/util/TrustpilotLogger.php diff --git a/Trustpilot/config.php b/Trustpilot/config.php index d2757c8..4e86cdf 100755 --- a/Trustpilot/config.php +++ b/Trustpilot/config.php @@ -8,7 +8,7 @@ define('TRUSTPILOT_GENERAL_CONFIGURATION', 'general'); define('TRUSTPILOT_TRUSTBOX_CONFIGURATION', 'trustbox'); define('TRUSTPILOT_INTEGRATION_KEY', 'key'); -define('TRUSTPILOT_PLUGIN_VERSION', '2.5.763'); +define('TRUSTPILOT_PLUGIN_VERSION', '2.5.788'); define('TRUSTPILOT_SCRIPT', 'TrustpilotScriptUrl'); define('TRUSTPILOT_INTEGRATION_APP', 'IntegrationAppUrl'); define('TRUSTPILOT_WIDGET_SCRIPT', 'WidgetScriptUrl'); diff --git a/Trustpilot/helper.php b/Trustpilot/helper.php index 5f1b301..e6dcfb2 100755 --- a/Trustpilot/helper.php +++ b/Trustpilot/helper.php @@ -1,9 +1,12 @@ $page, )); return str_replace(['http:', 'https:'],'', get_home_url()); } catch (\Exception $e) { $message = 'Unable to find URL for a page ' . $page; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'page' => $page, )); return str_replace(['http:', 'https:'],'', get_home_url()); @@ -85,7 +88,7 @@ function trustpilot_get_landing_url() { return get_home_url(); } -function trustpilot_get_category_url() { +function trustpilot_get_first_category() { $category_args = array( 'taxonomy' => 'product_cat', 'childless' => true, @@ -96,8 +99,16 @@ function trustpilot_get_category_url() { ); $categories = (array) get_categories($category_args); if (is_array($categories) && !empty($categories)) { - $firstCategory = (object) array_values($categories)[0]; - return get_term_link($firstCategory->term_id, 'product_cat'); + return (object)array_values($categories)[0]; + } else { + return false; + } +} + +function trustpilot_get_category_url() { + $category = trustpilot_get_first_category(); + if ($category) { + return get_term_link($category->term_id, 'product_cat'); } else { return get_permalink(trustpilot_get_page_id('shop')); } @@ -130,7 +141,7 @@ function trustpilot_get_first_product() { $posts = get_posts($product_args); - if (!empty($posts)) { + if (!empty($posts) && function_exists('wc_get_product')) { return wc_get_product($posts[0]); } else { @@ -161,44 +172,47 @@ function trustpilot_get_page_id($page) { } function trustpilot_get_product_sku() { - $product = trustpilot_get_first_product(); $skus = array(); - array_push($skus, TRUSTPILOT_PRODUCT_ID_PREFIX . trustpilot_get_inventory_attribute('id', $product)); + if ( is_plugin_active('woocommerce/woocommerce.php') ) { + $product = trustpilot_get_first_product(); + array_push($skus, TRUSTPILOT_PRODUCT_ID_PREFIX . trustpilot_get_inventory_attribute('id', $product)); - if (!empty($product)) { - array_push($skus, trustpilot_get_inventory_attribute('sku', $product)); + if (!empty($product)) { + array_push($skus, trustpilot_get_inventory_attribute('sku', $product)); + } } return implode(',', $skus); } function trustpilot_get_product_name() { - $product = trustpilot_get_first_product(); - if (!empty($product)) { - if (method_exists($product, 'get_name')) { - return $product->get_name(); - } else { - return $product->get_title(); + if ( is_plugin_active('woocommerce/woocommerce.php') ) { + $product = trustpilot_get_first_product(); + if (!empty($product)) { + if (method_exists($product, 'get_name')) { + return $product->get_name(); + } else { + return $product->get_title(); + } } - } else { - return ''; } + return ''; } /** * WooCommerce get version number */ function trustpilot_get_woo_version_number() { - if ( ! function_exists( 'get_plugins' ) ) { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); - } - - $plugin_folder = get_plugins( '/' . 'woocommerce' ); - $plugin_file = 'woocommerce.php'; + if ( is_plugin_active('woocommerce/woocommerce.php') ) { + $plugin_folder = get_plugins( '/' . 'woocommerce' ); + $plugin_file = 'woocommerce.php'; - if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) { - return $plugin_folder[$plugin_file]['Version']; + if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) { + return $plugin_folder[$plugin_file]['Version']; + } else { + return NULL; + } } else { - return NULL; + return get_bloginfo('version'); } } diff --git a/Trustpilot/review/Admin.php b/Trustpilot/review/Admin.php index 41984ed..2bb8f2e 100755 --- a/Trustpilot/review/Admin.php +++ b/Trustpilot/review/Admin.php @@ -9,6 +9,7 @@ * @link https://trustpilot.com * @copyright 2018 Trustpilot */ + namespace Trustpilot\Review; /** * @subpackage Admin @@ -61,13 +62,10 @@ private function do_hooks() { add_action( 'wp_ajax_reload_trustpilot_settings', array( $this, 'wc_reload_trustpilot_settings' ) ); add_action( 'wp_ajax_check_product_skus', array( $this, 'trustpilot_check_product_skus' ) ); add_action( 'wp_ajax_get_signup_data', array( $this, 'trustpilot_get_signup_data' ) ); + add_action( 'wp_ajax_get_category_product_info', array( $this, 'trustpilot_get_category_product_info')); // Add the options page and menu item. add_action( 'admin_menu', array( $this, 'trustpilot_menu' ) ); - // Include Http client - include(plugin_dir_path( __FILE__ ) . 'api/TrustpilotHttpClient.php'); - include(plugin_dir_path( __FILE__ ) . 'api/TrustpilotPluginStatus.php'); - include(plugin_dir_path( __FILE__ ) . 'util/Logger.php'); } public function trustpilot_save_changes() { @@ -151,6 +149,16 @@ public function trustpilot_get_signup_data() { die(); } + public function trustpilot_get_category_product_info() { + $trustbox = TrustBox::get_instance(); + $products = Products::get_instance(); + $category = trustpilot_get_first_category(); + $categoryProducts = $category ? $products->trustpilot_get_products(16, 1, $category) : array(); + $results = base64_encode(json_encode($trustbox->get_category_product_info($categoryProducts))); + echo $results; + die(); + } + private function trustpilot_get_past_orders_info() { $orders = PastOrders::get_instance(); $info = $orders->get_past_orders_info(); @@ -173,9 +181,9 @@ private function trustpilot_resync_failed_orders() { */ public function enqueue_admin_styles($hook) { if ($hook == 'toplevel_page_woocommerce-trustpilot-settings-page') { - wp_enqueue_style( 'trustpilotSettingsStylesheet', plugins_url('/assets/css/trustpilot.css', __FILE__)); + wp_enqueue_style( 'trustpilotSettingsStylesheet', plugins_url('/assets/css/trustpilot.min.css', __FILE__)); } - wp_enqueue_style('trustpilotSideLogoStylesheet', plugins_url('/assets/css/trustpilot.css', __FILE__)); + wp_enqueue_style('trustpilotSideLogoStylesheet', plugins_url('/assets/css/trustpilot.min.css', __FILE__)); } /** @@ -185,7 +193,7 @@ public function enqueue_admin_scripts($hook) { if ( 'toplevel_page_woocommerce-trustpilot-settings-page' != $hook ) { return; } - wp_enqueue_script( 'boot_js', plugins_url('/assets/js/integrationScript.js', __FILE__ )); + wp_enqueue_script( 'boot_js', plugins_url('/assets/js/integrationScript.min.js', __FILE__ )); wp_localize_script('boot_js', 'trustpilot_integration_settings', array( 'TRUSTPILOT_INTEGRATION_APP_URL' => $this->get_integration_app_url(), )); @@ -220,16 +228,18 @@ public function get_product_identification_options() { $fields = array('none', 'sku', 'id'); $optionalFields = array('upc', 'isbn', 'brand'); $dynamicFields = array('mpn', 'gtin'); - $attrs = array_map(function ($t) { return $t->attribute_name; }, wc_get_attribute_taxonomies()); - foreach ($attrs as $attr) { - foreach ($optionalFields as $field) { - if ($attr == $field && !in_array($field, $fields)) { - array_push($fields, $field); + if (is_plugin_active('woocommerce/woocommerce.php')) { + $attrs = array_map(function ($t) { return $t->attribute_name; }, wc_get_attribute_taxonomies()); + foreach ($attrs as $attr) { + foreach ($optionalFields as $field) { + if ($attr == $field && !in_array($field, $fields)) { + array_push($fields, $field); + } } - } - foreach ($dynamicFields as $field) { - if (stripos($attr, $field) !== false) { - array_push($fields, $attr); + foreach ($dynamicFields as $field) { + if (stripos($attr, $field) !== false) { + array_push($fields, $attr); + } } } } @@ -261,8 +271,10 @@ public function get_business_information() { private function load_iframe() { $pageUrls = new \stdClass(); $pageUrls->landing = trustpilot_get_page_url('landing'); - $pageUrls->category = trustpilot_get_page_url('category'); - $pageUrls->product = trustpilot_get_page_url('product'); + if (is_plugin_active('woocommerce/woocommerce.php')) { + $pageUrls->category = trustpilot_get_page_url('category'); + $pageUrls->product = trustpilot_get_page_url('product'); + } $urls = trustpilot_get_field('trustpilot_page_urls'); $customTrustBoxes = json_encode(trustpilot_get_field('trustpilot_custom_TrustBoxes')); $pageUrls = (object) array_merge((array) $urls, (array) $pageUrls); @@ -277,6 +289,7 @@ private function load_iframe() { $productIdentificationOptions = $this->get_product_identification_options(); $configuration_scope_tree = base64_encode(json_encode($this->get_configuration_scope_tree())); $pluginStatus = base64_encode(json_encode(trustpilot_get_field(TRUSTPILOT_PLUGIN_STATUS))); + $mode = is_plugin_active('woocommerce/woocommerce.php') ? '' : 'data-mode=\'trustbox-only\''; return " @@ -373,12 +388,12 @@ private function get_integration_app_url() { $protocol = $this->get_protocol(); } catch (\Throwable $e) { // For PHP 7 $message = 'Unable get protocol of the website switching to default: ' . $protocol; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'protocol' => $protocol, )); } catch (\Exception $e) { // For PHP 5 $message = 'Unable get protocol of the website switching to default: ' . $protocol; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'protocol' => $protocol, )); } diff --git a/Trustpilot/review/Orders.php b/Trustpilot/review/Orders.php index 45d4182..51f8ef9 100755 --- a/Trustpilot/review/Orders.php +++ b/Trustpilot/review/Orders.php @@ -10,6 +10,8 @@ * @copyright 2018 Trustpilot */ +use Trustpilot\Review\TrustpilotLogger; + namespace Trustpilot\Review; define('WITH_PRODUCT_DATA', 'WITH_PRODUCT_DATA'); @@ -42,8 +44,10 @@ public static function get_instance() { * Handle WP actions and filters. */ private function do_hooks() { - add_action( 'woocommerce_order_status_changed', array( $this, 'trustpilot_orderStatusChange' )); - add_action( 'woocommerce_thankyou', array( $this, 'trustpilot_thankYouPageLoaded' )); + if ( is_plugin_active('woocommerce/woocommerce.php') ) { + add_action( 'woocommerce_order_status_changed', array( $this, 'trustpilot_orderStatusChange' )); + add_action( 'woocommerce_thankyou', array( $this, 'trustpilot_thankYouPageLoaded' )); + } } /** @@ -75,7 +79,7 @@ public function trustpilot_orderStatusChange($order_id) { } } catch (\Throwable $e) { $message = 'Unable to send invitation for order id: ' . $order_id; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'key' => $key, 'orderId' => $order_id, 'orderStatus' => $order_status, @@ -83,7 +87,7 @@ public function trustpilot_orderStatusChange($order_id) { )); } catch (\Exception $e) { $message = 'Unable to send invitation for order id: ' . $order_id; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'key' => $key, 'orderId' => $order_id, 'orderStatus' => $order_status, @@ -116,12 +120,12 @@ public function trustpilot_thankYouPageLoaded($order_id) { $invitation['currency'] = $order->get_currency(); } catch (\Throwable $e) { $message = 'Unable to collect ROI data on frontend checkout for order id: ' . $order_id; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'orderId' => $order_id, )); } catch (\Exception $e) { $message = 'Unable to collect ROI data on frontend checkout for order id: ' . $order_id; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'orderId' => $order_id, )); } @@ -130,7 +134,7 @@ public function trustpilot_thankYouPageLoaded($order_id) { $invitation['payloadType'] = 'OrderStatusUpdate'; } - wp_register_script('tp-invitation', plugins_url('assets/js/thankYouScript.js', __FILE__)); + wp_register_script('tp-invitation', plugins_url('assets/js/thankYouScript.min.js', __FILE__)); wp_localize_script('tp-invitation', 'trustpilot_order_data', array(TRUSTPILOT_ORDER_DATA => $invitation)); wp_enqueue_script ('tp-invitation'); } @@ -156,13 +160,13 @@ private function handle_single_response($response, $order) { } } catch (\Throwable $e) { $message = 'Unable to update past orders for order id: ' . $order['referenceId']; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'referenceId' => $order['referenceId'], 'responseCode' => $response['code'], )); } catch (\Exception $e) { $message = 'Unable to update past orders for order id: ' . $order['referenceId']; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'referenceId' => $order['referenceId'], 'responseCode' => $response['code'], )); @@ -179,13 +183,13 @@ public function trustpilot_get_invitation_by_order_id($order_id, $hook, $collect $invitation = $this->trustpilot_get_invitation($order, $hook, $collect_product_data); } catch (\Throwable $e) { $message = 'Unable to get invitation by order id: ' . $order_id; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'orderId' => $order_id, 'hook' => $hook, )); } catch (\Exception $e) { $message = 'Unable to get invitation by order id: ' . $order_id; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'orderId' => $order_id, 'hook' => $hook, )); @@ -292,10 +296,10 @@ private function getProducts($order) { } } catch (\Throwable $e) { $message = 'Unable to get products.'; - Logger::error($e, $message); + TrustpilotLogger::error($e, $message); } catch (\Exception $e) { $message = 'Unable to get products.'; - Logger::error($e, $message); + TrustpilotLogger::error($e, $message); } return $products; } @@ -328,7 +332,7 @@ private function get_order_id($order){ } public function get_all_wc_orders($args){ - if(function_exists('wc_get_orders')){ + if (function_exists('wc_get_orders')) { return wc_get_orders($args); } else { return trustpilot_legacy_get_all_wc_orders($args); @@ -352,13 +356,26 @@ public function get_product_categories($product) { */ public function get_product_image_urls($product) { $image_urls = array(); + $product_id = null; + if (method_exists($product, 'get_id')) { + $product_id = $product->get_id(); + } else { + $product_id = $product->id; + } - $url = $this->trustpilot_get_product_image_url($product->get_id()); + $url = $this->trustpilot_get_product_image_url($product_id); if ($url) { array_push($image_urls, $url); } - $attachment_ids = $product->get_gallery_image_ids(); + $attachment_ids = null; + + if (method_exists($product, 'get_gallery_image_ids')) { + $attachment_ids = $product->get_gallery_image_ids(); + } else { + $attachment_ids = $product->get_gallery_attachment_ids(); + } + foreach($attachment_ids as $attachment_id) { $url = wp_get_attachment_url($attachment_id); if ($url) { @@ -368,7 +385,11 @@ public function get_product_image_urls($product) { if ($product->get_type() === 'variation') { $parent = wc_get_product($product->get_parent_id()); - $attachment_ids = $parent->get_gallery_image_ids(); + if (method_exists($parent, 'get_gallery_image_ids')) { + $attachment_ids = $parent->get_gallery_image_ids(); + } else { + $attachment_ids = $parent->get_gallery_attachment_ids(); + } foreach($attachment_ids as $attachment_id) { $url = wp_get_attachment_url($attachment_id); if ($url) { @@ -392,15 +413,19 @@ public function get_product_tags($product) { } public function get_product_description($product) { - $description = $product->get_description(); - if (empty($description)) { - if ($product->get_type() === 'variation') { - $parent = wc_get_product($product->get_parent_id()); - $description = $parent->get_description() ? $parent->get_description() : $parent->get_short_description(); - } else { - $description = $product->get_short_description(); + if (method_exists($product, 'get_description')) { + $description = $product->get_description(); + if (empty($description)) { + if ($product->get_type() === 'variation') { + $parent = wc_get_product($product->get_parent_id()); + $description = $parent->get_description() ? $parent->get_description() : $parent->get_short_description(); + } else { + $description = $product->get_short_description(); + } } + return strip_shortcodes(wp_strip_all_tags($description)); } - return wp_strip_all_tags($description); + + return null; } } diff --git a/Trustpilot/review/PastOrders.php b/Trustpilot/review/PastOrders.php index fcc74fa..ac6dce2 100755 --- a/Trustpilot/review/PastOrders.php +++ b/Trustpilot/review/PastOrders.php @@ -10,6 +10,8 @@ * @copyright 2018 Trustpilot */ +use Trustpilot\Review\TrustpilotLogger; + namespace Trustpilot\Review; /** @@ -75,12 +77,12 @@ public function sync($period_in_days) { } } catch (\Throwable $e) { $message = 'Failed to sync past orders.'; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'periodInDays' => $period_in_days, )); } catch (\Exception $e) { $message = 'Failed to sync past orders.'; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'periodInDays' => $period_in_days, )); } @@ -126,10 +128,10 @@ public function resync() { } } catch (\Throwable $e) { $message = 'Failed to resync failed orders.'; - Logger::error($e, $message); + TrustpilotLogger::error($e, $message); } catch (\Exception $e) { $message = 'Failed to resync failed orders.'; - Logger::error($e, $message); + TrustpilotLogger::error($e, $message); } update_option('sync_in_progress', 'false'); } @@ -189,14 +191,14 @@ private function trustpilot_get_orders_for_period($period_in_days, $collect_prod } } catch (\Throwable $e) { $message = 'Unable to get invitation data for past orders period: ' . $period_in_days; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'periodInDays' => $period_in_days, 'collectProductData' => $collect_product_data, 'pageId' => $pageId, )); } catch (\Exception $e) { $message = 'Unable to get invitation data for past orders period: ' . $period_in_days; - Logger::error($e, $message, array( + TrustpilotLogger::error($e, $message, array( 'periodInDays' => $period_in_days, 'collectProductData' => $collect_product_data, 'pageId' => $pageId, diff --git a/Trustpilot/review/Plugin.php b/Trustpilot/review/Plugin.php index e9c9fad..5bf78e1 100755 --- a/Trustpilot/review/Plugin.php +++ b/Trustpilot/review/Plugin.php @@ -12,6 +12,8 @@ namespace Trustpilot\Review; +include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + /** * @subpackage Plugin */ @@ -137,21 +139,18 @@ private function do_hooks() { } public function trustpilot_load_js($hook){ - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); - if ( is_plugin_active('woocommerce/woocommerce.php') ) { - wp_register_script('tp-js', plugins_url('assets/js/headerScript.js', __FILE__)); - $key = trustpilot_get_settings(TRUSTPILOT_GENERAL_CONFIGURATION)->key; - wp_localize_script('tp-js', 'trustpilot_settings', array( - TRUSTPILOT_INTEGRATION_KEY => $key, - TRUSTPILOT_SCRIPT => TRUSTPILOT_SCRIPT_URL, - TRUSTPILOT_INTEGRATION_APP => TRUSTPILOT_INTEGRATION_APP_URL, - TRUSTPILOT_PREVIEW_SCRIPT => TRUSTPILOT_PREVIEW_SCRIPT_URL, - TRUSTPILOT_PREVIEW_CSS => TRUSTPILOT_PREVIEW_CSS_URL, - TRUSTPILOT_WP_PREVIEW_CSS => TRUSTPILOT_WP_PREVIEW_CSS_URL, - TRUSTPILOT_WIDGET_SCRIPT => TRUSTPILOT_WIDGET_SCRIPT_URL, - )); - wp_enqueue_script('tp-js'); - wp_enqueue_script('widget-bootstrap', TRUSTPILOT_WIDGET_SCRIPT_URL, null, null); - } + wp_register_script('tp-js', plugins_url('assets/js/headerScript.min.js', __FILE__)); + $key = trustpilot_get_settings(TRUSTPILOT_GENERAL_CONFIGURATION)->key; + wp_localize_script('tp-js', 'trustpilot_settings', array( + TRUSTPILOT_INTEGRATION_KEY => $key, + TRUSTPILOT_SCRIPT => TRUSTPILOT_SCRIPT_URL, + TRUSTPILOT_INTEGRATION_APP => TRUSTPILOT_INTEGRATION_APP_URL, + TRUSTPILOT_PREVIEW_SCRIPT => TRUSTPILOT_PREVIEW_SCRIPT_URL, + TRUSTPILOT_PREVIEW_CSS => TRUSTPILOT_PREVIEW_CSS_URL, + TRUSTPILOT_WP_PREVIEW_CSS => TRUSTPILOT_WP_PREVIEW_CSS_URL, + TRUSTPILOT_WIDGET_SCRIPT => TRUSTPILOT_WIDGET_SCRIPT_URL, + )); + wp_enqueue_script('tp-js'); + wp_enqueue_script('widget-bootstrap', TRUSTPILOT_WIDGET_SCRIPT_URL, null, null); } } diff --git a/Trustpilot/review/Products.php b/Trustpilot/review/Products.php index 6d209c2..10e4e24 100755 --- a/Trustpilot/review/Products.php +++ b/Trustpilot/review/Products.php @@ -34,7 +34,7 @@ public static function get_instance() { return self::$instance; } - private function trustpilot_get_products($limit, $page) { + public function trustpilot_get_products($limit, $page, $category = null) { if (function_exists('wc_get_products')) { $product_args = array( 'visibility' => 'visible', @@ -43,7 +43,11 @@ private function trustpilot_get_products($limit, $page) { 'orderby' => 'id', 'page' => $page, ); - + + if ($category) { + $product_args['category'] = array($category->name); + } + return wc_get_products($product_args); } else { $page = $page - 1; @@ -55,6 +59,10 @@ private function trustpilot_get_products($limit, $page) { 'offset' => $page * $limit, ); + if ($category) { + $product_args['category'] = $category->cat_ID; + } + $posts = get_posts($product_args); $products = array(); if (!empty($posts)) { diff --git a/Trustpilot/review/TrustBox.php b/Trustpilot/review/TrustBox.php index 6e469f7..30d8646 100755 --- a/Trustpilot/review/TrustBox.php +++ b/Trustpilot/review/TrustBox.php @@ -23,6 +23,7 @@ class TrustBox { * @var string */ protected $plugin_name = 'Trustpilot-review'; + protected $products = null; /** * Instance of this class. @@ -65,41 +66,93 @@ public function get_plugin_version() { return $this->plugin_version; } + private function do_hooks() { add_action ( 'wp_enqueue_scripts', array( $this, 'load_trustbox' ) ); + add_action( 'posts_results', array( $this, 'get_current_category_products' )); } public function getPage() { - if (is_product()) { - return 'product'; - } else if (is_product_category()) { - return 'category'; - } else if (is_front_page()) { - return 'landing'; + if (is_plugin_active('woocommerce/woocommerce.php')) { + if (is_product()) { + return 'product'; + } else if (is_product_category()) { + return 'category'; + } else if (is_front_page()) { + return 'landing'; + } + } else { + if (is_front_page()) { + return 'landing'; + } } } - public function load_trustbox(){ + public function load_trustbox($results){ $trustbox = trustpilot_get_settings(TRUSTPILOT_TRUSTBOX_CONFIGURATION); $settings = array( 'page' => $this->getPage(), 'sku' => $this->getSku(), 'name' => $this->getName() ); - $trusboxes = isset($trustbox->trustboxes) ? $trustbox->trustboxes : array(); + $trusboxes = array( + "trustboxes" => isset($trustbox->trustboxes) ? $trustbox->trustboxes : array(), + ); + if ($this->getPage() == 'category') { + $trusboxes['categoryProductsData'] = $this->get_category_product_info($this->products); + } $this->load_trustboxes($settings, $trusboxes); + return $results; } public function getName() { - if (is_product()) { + if (is_plugin_active('woocommerce/woocommerce.php') && is_product()) { $product = wc_get_product( get_the_id() ); return method_exists($product, 'get_name') ? $product->get_name() : $product->get_title(); } return null; } + public function get_current_category_products($results) { + if ($this->getPage() == 'category') { + $products = array(); + foreach ($results as $result) { + if ($result->post_type == 'product') { + $product = wc_get_product($result->ID); + array_push($products, $product); + } + } + $this->products = $products; + } + return $results; + } + + public function get_category_product_info($products) { + $info = array(); + foreach ($products as $product) { + $data = new \stdClass(); + $data->productUrl = get_permalink( $product->get_id() ); + $data->id = $product->get_id(); + $data->sku = trustpilot_get_inventory_attribute('sku', $product);; + $data->name = $product->get_name(); + $variation_ids = $product->get_children(); + if ($variation_ids) { + $data->variationIds = $variation_ids; + $data->variationSkus = array(); + + foreach ($variation_ids as $variation_id) { + $variation = wc_get_product($variation_id); + $sku = trustpilot_get_inventory_attribute('sku', $variation); + array_push($data->variationSkus, $sku); + } + } + array_push($info, $data); + } + return $info; + } + public function getSku() { - if (is_product()) { + if (is_plugin_active('woocommerce/woocommerce.php') && is_product()) { $product = wc_get_product( get_the_id() ); if ($product->is_type('variable')) { // make a list of product sku plus skus of all variations @@ -133,10 +186,10 @@ public function getSku() { } } - function load_trustboxes($settings, $trustbox){ - wp_register_script('trustbox', plugins_url('assets/js/trustBoxScript.js', __FILE__)); + function load_trustboxes($settings, $trustboxes){ + wp_register_script('trustbox', plugins_url('assets/js/trustBoxScript.min.js', __FILE__)); wp_localize_script('trustbox', 'trustbox_settings', $settings); - wp_localize_script('trustbox', 'trustpilot_trustbox_settings', array("trustboxes" => $trustbox)); + wp_localize_script('trustbox', 'trustpilot_trustbox_settings', $trustboxes); wp_enqueue_script ('trustbox'); } } diff --git a/Trustpilot/review/api/TrustpilotPluginStatus.php b/Trustpilot/review/api/TrustpilotPluginStatus.php index e442eb0..a3974f0 100755 --- a/Trustpilot/review/api/TrustpilotPluginStatus.php +++ b/Trustpilot/review/api/TrustpilotPluginStatus.php @@ -8,8 +8,11 @@ class TrustpilotPluginStatus public function checkPluginStatus($origin) { $settings = trustpilot_get_field(TRUSTPILOT_PLUGIN_STATUS); - if (in_array(parse_url($origin, PHP_URL_HOST), $settings->blockedDomains)) { - return $settings->pluginStatus; + if (isset($settings->blockedDomains)) { + $blockedDomains = $settings->blockedDomains; + if (is_array($blockedDomains) && in_array(parse_url($origin, PHP_URL_HOST), $blockedDomains)) { + return $settings->pluginStatus; + } } return self::SUCCESSFUL_STATUS; } diff --git a/Trustpilot/review/assets/css/trustpilot.min.css b/Trustpilot/review/assets/css/trustpilot.min.css new file mode 100644 index 0000000..c947b4b --- /dev/null +++ b/Trustpilot/review/assets/css/trustpilot.min.css @@ -0,0 +1 @@ +.trustpilot{margin-bottom:.5rem}#toplevel_page_woocommerce-trustpilot-settings-page div.wp-menu-image{background:url('../images/logo.svg') !important;background-size:22px 20px !important;background-repeat:no-repeat !important;background-position:center !important;padding:0 0 0 0 !important}#toplevel_page_woocommerce-trustpilot-settings-page div.wp-menu-image::before{content:none}.form-table th{width:300px}.buttons-container{width:501px}#save_trustpilot_settings{float:right;margin-left:5px} \ No newline at end of file diff --git a/Trustpilot/review/assets/js/headerScript.min.js b/Trustpilot/review/assets/js/headerScript.min.js new file mode 100644 index 0000000..f0b1bb6 --- /dev/null +++ b/Trustpilot/review/assets/js/headerScript.min.js @@ -0,0 +1,2 @@ +function inIframe(){try{return window.self!==window.top}catch(t){return!1}}function tryParseJson(t){if("string"==typeof t)try{return JSON.parse(t)}catch(t){return!1}return!1}!function(t,e,r,s,n){t.TrustpilotObject=n,t.tp=t.tp||function(){(t.tp.q=t.tp.q||[]).push(arguments)},a=e.createElement(r),a.async=1,a.src=s,a.type="text/java"+r,f=e.getElementsByTagName(r)[0],f.parentNode.insertBefore(a,f)}(window,document,"script",trustpilot_settings.TrustpilotScriptUrl,"tp"),tp("register",trustpilot_settings.key),inIframe()&&window.addEventListener("message",function(t){var e=new URL(window.location).hostname;if(t.data&&-1!==t.origin.indexOf(e))if("undefined"!=typeof TrustpilotPreview){if("string"!=typeof t.data||"submit"!==t.data)return jsonData=tryParseJson(t.data),void(jsonData&&(jsonData.trustbox?TrustpilotPreview.setSettings(jsonData.trustbox):jsonData.customised&&TrustpilotPreview.updateActive(jsonData.customised)));TrustpilotPreview.sendTrustboxes()}else{var r=tryParseJson(t.data);if(r&&r.trustboxes){var s=document.createElement("script");s.type="text/javascript",s.onload=function(){const e=t.source.parent.document.getElementById("configuration_iframe").contentWindow;TrustpilotPreview.init([trustpilot_settings.PreviewCssUrl,trustpilot_settings.PreviewWPCssUrl],r,e,t.source)},s.src=trustpilot_settings.PreviewScriptUrl,document.head.appendChild(s)}}}); +//# sourceMappingURL=headerScript.min.js.map diff --git a/Trustpilot/review/assets/js/headerScript.min.js.map b/Trustpilot/review/assets/js/headerScript.min.js.map new file mode 100644 index 0000000..ff3a71a --- /dev/null +++ b/Trustpilot/review/assets/js/headerScript.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["headerScript.js"],"names":["inIframe","window","self","top","e","tryParseJson","str","JSON","parse","w","d","s","r","n","TrustpilotObject","q","push","arguments","a","createElement","async","src","type","f","getElementsByTagName","parentNode","insertBefore","document","trustpilot_settings","tp","addEventListener","adminOrign","URL","location","hostname","data","origin","indexOf","TrustpilotPreview","jsonData","trustbox","setSettings","customised","updateActive","sendTrustboxes","settings","trustboxes","p","onload","iFrame","source","parent","getElementById","contentWindow","init","head","appendChild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ef,kBAAkBgB,MAAM1B,oBAAmC,cAAGA,oBAAqC,iBAAIiB,EAAUI,EAAQ7C,EAAE8C,SAE/HH,EAAE1B,IAAMO,oBAAsC,iBAC9CD,SAAS4B,KAAKC,YAAYT","file":"headerScript.min.js"} \ No newline at end of file diff --git a/Trustpilot/review/assets/js/integrationScript.js b/Trustpilot/review/assets/js/integrationScript.js index 6bdf562..f316224 100755 --- a/Trustpilot/review/assets/js/integrationScript.js +++ b/Trustpilot/review/assets/js/integrationScript.js @@ -53,6 +53,9 @@ function receiveInternalData(e) { if (jsonData && jsonData.type === 'updatePageUrls') { submitSettings(jsonData); } + if (jsonData && jsonData.type === 'loadCategoryProductInfo') { + requestCategoryInfo(); + } if (jsonData && jsonData.type === 'newTrustBox') { submitSettings(jsonData); } @@ -222,6 +225,25 @@ function submitSettings(parsedData) { xhr.send(encodeSettings(data)); } +function requestCategoryInfo() { + const data = { + action: 'get_category_product_info' + }; + const xhr = new XMLHttpRequest(); + xhr.open('POST', ajaxurl); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + if (xhr.status >= 400) { + console.log(`callback error: ${xhr.response} ${xhr.status}`); + } else { + window.postMessage(xhr.response, window.origin); + } + } + }; + xhr.send(encodeSettings(data)); +} + function updateIframeSize(settings) { const iframe = document.getElementById('configuration_iframe'); if (iframe) { @@ -248,6 +270,7 @@ function sendSettings() { settings.isFromMarketplace = attrs.isFromMarketplace; settings.configurationScopeTree = JSON.parse(atob(attrs.configurationScopeTree)); settings.pluginStatus = JSON.parse(atob(attrs.pluginStatus)); + settings.mode = attrs.mode; if (settings.trustbox.trustboxes && attrs.sku) { for (trustbox of settings.trustbox.trustboxes) { diff --git a/Trustpilot/review/assets/js/integrationScript.min.js b/Trustpilot/review/assets/js/integrationScript.min.js new file mode 100644 index 0000000..fd33535 --- /dev/null +++ b/Trustpilot/review/assets/js/integrationScript.min.js @@ -0,0 +1,2 @@ +function receiveSettings(t){if(t.origin===location.origin)return receiveInternalData(t);if(t.origin!==checkProtocol(trustpilot_integration_settings.TRUSTPILOT_INTEGRATION_APP_URL))return;const e=t.data;if("string"==typeof e)if(e.startsWith("sync:")||e.startsWith("showPastOrdersInitial:")){const t=e.split(":"),n={action:"handle_past_orders"};n[t[0]]=t[1],this.submitPastOrdersCommand(n)}else if(e.startsWith("resync")){const t={action:"handle_past_orders",resync:"resync"};this.submitPastOrdersCommand(t)}else if(e.startsWith("issynced")){const t={action:"handle_past_orders",issynced:"issynced"};this.submitPastOrdersCommand(t)}else if(e.startsWith("check_product_skus")){const t=e.split(":"),n={action:"check_product_skus"};n.skuSelector=t[1],this.submitCheckProductSkusCommand(n)}else"signup_data"===e?this.sendSignupData():"update"===e?updateplugin():"reload"===e?reloadSettings():e&&tryParseJson(e)&&JSON.parse(e).TrustBoxPreviewMode?TrustBoxPreviewMode(e):handleJSONMessage(e)}function receiveInternalData(t){const e=t.data;if(e&&"string"==typeof e&&tryParseJson(e)){const t=JSON.parse(e);t&&"updatePageUrls"===t.type&&submitSettings(t),t&&"loadCategoryProductInfo"===t.type&&requestCategoryInfo(),t&&"newTrustBox"===t.type&&submitSettings(t)}}function handleJSONMessage(t){if(tryParseJson(t)){const e=JSON.parse(t);if(e.window)this.updateIframeSize(e);else if("submit"===e.type)this.submitSettings(e);else if(e.trustbox){document.getElementById("trustbox_preview_frame").contentWindow.postMessage(JSON.stringify(e.trustbox),"*")}}}function encodeSettings(t){let e="";for(const n in t)e+=`${n}=${t[n]}&`;return e.substring(0,e.length-1)}function getFormValues(t){let e={};for(const n in t.elements){const s=t.elements[n];"INPUT"===s.nodeName&&(e[s.name]=s.value)}return e}function tryParseJson(t){try{JSON.parse(t)}catch(t){return!1}return!0}function submitPastOrdersCommand(t){const e=new XMLHttpRequest;e.open("POST",ajaxurl,!0),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.onreadystatechange=function(){4===e.readyState&&(e.status>=400?console.log(`callback error: ${e.response} ${e.status}`):sendPastOrdersInfo(e.response))},e.send(encodeSettings(t))}function submitCheckProductSkusCommand(t){const e=new XMLHttpRequest;e.open("POST",ajaxurl),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.onreadystatechange=function(){if(4===e.readyState)if(e.status>=400)console.log(`callback error: ${e.response} ${e.status}`);else{const t=document.getElementById("configuration_iframe");t.contentWindow.postMessage(e.response,t.dataset.transfer)}},e.send(encodeSettings(t))}function sendSignupData(){const t=new XMLHttpRequest;t.open("POST",ajaxurl),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){if(4===t.readyState)if(t.status>=400)console.log(`callback error: ${t.response} ${t.status}`);else{const e=document.getElementById("configuration_iframe"),n=JSON.stringify({trustpilot_signup_data:t.response});e.contentWindow.postMessage(n,e.dataset.transfer)}},t.send(encodeSettings({action:"get_signup_data"}))}function updateplugin(){const t=new XMLHttpRequest;t.open("POST",ajaxurl),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send(encodeSettings({action:"update_trustpilot_plugin"}))}function TrustBoxPreviewMode(t){const e=JSON.parse(t),n=document.getElementById("trustpilot-trustbox-preview");e.TrustBoxPreviewMode.enable?n.hidden=!1:n.hidden=!0}function reloadSettings(){const t=new XMLHttpRequest;t.open("POST",ajaxurl),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){if(4===t.readyState)if(t.status>=400)console.log(`callback error: ${t.response} ${t.status}`);else{const e=document.getElementById("configuration_iframe");e.contentWindow.postMessage(t.response,e.dataset.transfer)}},t.send(encodeSettings({action:"reload_trustpilot_settings"}))}function submitSettings(t){let e={action:"handle_save_changes"};"updatePageUrls"===t.type?e.pageUrls=encodeURIComponent(JSON.stringify(t.pageUrls)):"newTrustBox"===t.type?e.customTrustBoxes=encodeURIComponent(JSON.stringify(t)):(e.settings=encodeURIComponent(JSON.stringify(t.settings)),document.getElementById("trustbox_preview_frame").dataset.settings=btoa(e.settings));const n=new XMLHttpRequest;n.open("POST",ajaxurl),n.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),n.send(encodeSettings(e))}function requestCategoryInfo(){const t=new XMLHttpRequest;t.open("POST",ajaxurl),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){4===t.readyState&&(t.status>=400?console.log(`callback error: ${t.response} ${t.status}`):window.postMessage(t.response,window.origin))},t.send(encodeSettings({action:"get_category_product_info"}))}function updateIframeSize(t){const e=document.getElementById("configuration_iframe");e&&(e.height=t.window.height+"px")}function sendSettings(){const t=document.getElementById("configuration_iframe"),e=t.dataset,n=JSON.parse(atob(e.settings));if(n.trustbox||(n.trustbox={}),n.trustbox.pageUrls=JSON.parse(atob(e.pageUrls)),n.pluginVersion=e.pluginVersion,n.source=e.source,n.version=e.version,n.basis="plugin",n.productIdentificationOptions=JSON.parse(e.productIdentificationOptions),n.isFromMarketplace=e.isFromMarketplace,n.configurationScopeTree=JSON.parse(atob(e.configurationScopeTree)),n.pluginStatus=JSON.parse(atob(e.pluginStatus)),n.mode=e.mode,n.trustbox.trustboxes&&e.sku)for(trustbox of n.trustbox.trustboxes)trustbox.sku=e.sku;if(n.trustbox.trustboxes&&e.name)for(trustbox of n.trustbox.trustboxes)trustbox.name=e.name;t.contentWindow.postMessage(JSON.stringify(n),checkProtocol(e.transfer))}function checkProtocol(t){if(t.startsWith("//")){return window.location.protocol+t}return t}function sendPastOrdersInfo(t){const e=document.getElementById("configuration_iframe"),n=e.dataset;void 0===t&&(t=n.pastOrders),e.contentWindow.postMessage(t,checkProtocol(n.transfer))}window.addEventListener("message",this.receiveSettings); +//# sourceMappingURL=integrationScript.min.js.map diff --git a/Trustpilot/review/assets/js/integrationScript.min.js.map b/Trustpilot/review/assets/js/integrationScript.min.js.map new file mode 100644 index 0000000..b5ffb2c --- /dev/null +++ b/Trustpilot/review/assets/js/integrationScript.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["integrationScript.js"],"names":["receiveSettings","e","origin","location","receiveInternalData","checkProtocol","trustpilot_integration_settings","TRUSTPILOT_INTEGRATION_APP_URL","data","startsWith","split","action","this","submitPastOrdersCommand","resync","issynced","submitCheckProductSkusCommand","sendSignupData","updateplugin","reloadSettings","tryParseJson","JSON","parse","TrustBoxPreviewMode","handleJSONMessage","jsonData","type","submitSettings","requestCategoryInfo","parsedData","window","updateIframeSize","trustbox","document","getElementById","contentWindow","postMessage","stringify","encodeSettings","settings","encodedString","setting","substring","length","getFormValues","form","values","el","elements","element","nodeName","name","value","str","xhr","XMLHttpRequest","open","ajaxurl","setRequestHeader","onreadystatechange","readyState","status","console","log","response","sendPastOrdersInfo","send","iframe","dataset","transfer","message","trustpilot_signup_data","div","enable","hidden","pageUrls","encodeURIComponent","customTrustBoxes","btoa","height","sendSettings","attrs","atob","pluginVersion","source","version","basis","productIdentificationOptions","isFromMarketplace","configurationScopeTree","pluginStatus","mode","trustboxes","sku","url","protocol","undefined","pastOrders","addEventListener"],"mappings":"AAEA,SAASA,gBAAgBC,GACrB,GAAIA,EAAEC,SAAWC,SAASD,OACtB,OAAOE,oBAAoBH,GAE/B,GAAIA,EAAEC,SAAWG,cAAcC,gCAAgCC,gCAC3D,OAEJ,MAAMC,EAAOP,EAAEO,KACf,GAAoB,iBAATA,EAGX,GAAIA,EAAKC,WAAW,UAAYD,EAAKC,WAAW,0BAA2B,CACvE,MAAMC,EAAQF,EAAKE,MAAM,KACnBC,GACNA,OAAmB,sBACnBA,EAAOD,EAAM,IAAMA,EAAM,GACzBE,KAAKC,wBAAwBF,QAC1B,GAAIH,EAAKC,WAAW,UAAW,CAClC,MAAME,GACNA,OAAmB,qBACnBG,OAAmB,UACnBF,KAAKC,wBAAwBF,QAC1B,GAAIH,EAAKC,WAAW,YAAa,CACpC,MAAME,GACNA,OAAmB,qBACnBI,SAAqB,YACrBH,KAAKC,wBAAwBF,QAC1B,GAAIH,EAAKC,WAAW,sBAAuB,CAC9C,MAAMC,EAAQF,EAAKE,MAAM,KACnBC,G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AAWtF,KAAKZ","file":"integrationScript.min.js"} \ No newline at end of file diff --git a/Trustpilot/review/assets/js/thankYouScript.min.js b/Trustpilot/review/assets/js/thankYouScript.min.js new file mode 100644 index 0000000..47ce2d5 --- /dev/null +++ b/Trustpilot/review/assets/js/thankYouScript.min.js @@ -0,0 +1,2 @@ +document.addEventListener("DOMContentLoaded",function(){tp("createInvitation",trustpilot_order_data.OrderData)}); +//# sourceMappingURL=thankYouScript.min.js.map diff --git a/Trustpilot/review/assets/js/thankYouScript.min.js.map b/Trustpilot/review/assets/js/thankYouScript.min.js.map new file mode 100644 index 0000000..9a91045 --- /dev/null +++ b/Trustpilot/review/assets/js/thankYouScript.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["thankYouScript.js"],"names":["document","addEventListener","tp","trustpilot_order_data"],"mappings":"AAAAA,SAASC,iBAAiB,mBAAoB,WAC1CC,GAAG,mBAAoBC,sBAAiC","file":"thankYouScript.min.js"} \ No newline at end of file diff --git a/Trustpilot/review/assets/js/trustBoxScript.js b/Trustpilot/review/assets/js/trustBoxScript.js index 76c5e9b..bbab70b 100755 --- a/Trustpilot/review/assets/js/trustBoxScript.js +++ b/Trustpilot/review/assets/js/trustBoxScript.js @@ -17,7 +17,8 @@ function renderTrustboxes() { trustpilot_trustbox_settings.trustboxes = trustpilot_trustbox_settings.trustboxes.filter(function(trustBox) { return page === trustBox.page || trimTrailingSlashes(trustBox.page) === trimTrailingSlashes(location.origin + location.pathname) - || trustBox.page === btoa(location.origin + location.pathname).toLowerCase(); + || trustBox.page === btoa(location.origin + location.pathname).toLowerCase() + || trustBox.page === btoa(trimTrailingSlashes(location.origin + location.pathname)).toLowerCase(); }); if (document.readyState !== "complete") { diff --git a/Trustpilot/review/assets/js/trustBoxScript.min.js b/Trustpilot/review/assets/js/trustBoxScript.min.js new file mode 100644 index 0000000..6a934d1 --- /dev/null +++ b/Trustpilot/review/assets/js/trustBoxScript.min.js @@ -0,0 +1,2 @@ +function addNamesAndSkusToTrustboxes(){const t=trustbox_settings.sku||"",s=trustbox_settings.name||"",o=[t];for(var e in trustpilot_trustbox_settings.trustboxes)trustpilot_trustbox_settings.trustboxes[e].sku=o.join(","),trustpilot_trustbox_settings.trustboxes[e].name=s}function renderTrustboxes(){const t=trustbox_settings.page||"";"product"===t&&addNamesAndSkusToTrustboxes(),trustpilot_trustbox_settings.trustboxes=trustpilot_trustbox_settings.trustboxes.filter(function(s){return t===s.page||trimTrailingSlashes(s.page)===trimTrailingSlashes(location.origin+location.pathname)||s.page===btoa(location.origin+location.pathname).toLowerCase()||s.page===btoa(trimTrailingSlashes(location.origin+location.pathname)).toLowerCase()}),"complete"!==document.readyState&&window.addEventListener("load",()=>{tp("trustBox",trustpilot_trustbox_settings)}),tp("trustBox",trustpilot_trustbox_settings)}function trimTrailingSlashes(t){return"string"==typeof t?t.replace(/\/+$/,""):t}renderTrustboxes(); +//# sourceMappingURL=trustBoxScript.min.js.map diff --git a/Trustpilot/review/assets/js/trustBoxScript.min.js.map b/Trustpilot/review/assets/js/trustBoxScript.min.js.map new file mode 100644 index 0000000..fdde4f9 --- /dev/null +++ b/Trustpilot/review/assets/js/trustBoxScript.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["trustBoxScript.js"],"names":["addNamesAndSkusToTrustboxes","sku","trustbox_settings","name","skus","trustBox","trustpilot_trustbox_settings","trustboxes","join","renderTrustboxes","page","filter","trimTrailingSlashes","location","origin","pathname","btoa","toLowerCase","document","readyState","window","addEventListener","tp","url","replace"],"mappings":"AACA,SAASA,8BACL,MAAMC,EAAMC,kBAAkBD,KAAO,GAC/BE,EAAOD,kBAAkBC,MAAQ,GACjCC,GAAQH,GACd,IAAK,IAAII,KAAYC,6BAA6BC,WAC9CD,6BAA6BC,WAAWF,GAAUJ,IAAMG,EAAKI,KAAK,KAClEF,6BAA6BC,WAAWF,GAAUF,KAAOA,EAIjE,SAASM,mBACL,MAAMC,EAAOR,kBAAkBQ,MAAQ,GAC1B,YAATA,GACAV,8BAEJM,6BAA6BC,WAAaD,6BAA6BC,WAAWI,OAAO,SAASN,GAC9F,OAAOK,IAASL,EAASK,MAClBE,oBAAoBP,EAASK,QAAUE,oBAAoBC,SAASC,OAASD,SAASE,WACtFV,EAASK,OAASM,KAAKH,SAASC,OAASD,SAASE,UAAUE,eAC5DZ,EAASK,OAASM,KAAKJ,oBAAoBC,SAASC,OAASD,SAASE,WAAWE,gBAGhE,aAAxBC,SAASC,YACTC,OAAOC,iBAAiB,OAAQ,KAC3BC,GAAG,WAAYhB,gCAGxBgB,GAAG,WAAYhB,8BAGnB,SAASM,oBAAoBW,GACzB,MAAmB,iBAARA,EACAA,EAAIC,QAAQ,OAAQ,IAExBD,EAGXd","file":"trustBoxScript.min.js"} \ No newline at end of file diff --git a/Trustpilot/review/util/TrustpilotLogger.php b/Trustpilot/review/util/TrustpilotLogger.php new file mode 100755 index 0000000..57b1cb7 --- /dev/null +++ b/Trustpilot/review/util/TrustpilotLogger.php @@ -0,0 +1,45 @@ + 'WordPress-WooCommerce', + 'version' => TRUSTPILOT_PLUGIN_VERSION, + 'error' => $e->getMessage(), + 'method' => TrustpilotLogger::getMethodName($e), + 'description' => $description, + 'variables' => $optional, + 'trace' => $e->getTraceAsString(), + ); + + $trustpilot_api = new TrustpilotHttpClient(TRUSTPILOT_API_URL); + $trustpilot_api->postLog($errorObject); + + // Don't log stack trace locally + $localErrorObject = $errorObject; + unset($localErrorObject['trace']); + + if ( is_plugin_active('woocommerce/woocommerce.php') ) { + if (function_exists('wc_get_logger')) { + $logger = wc_get_logger(); + $logger->error(json_encode($localErrorObject), array('source' => 'trustpilot-reviews')); + } + } else { + error_log(json_encode($localErrorObject)); + } + } + + private static function getMethodName($e) { + $trace = $e->getTrace(); + if (array_key_exists(0, $trace)) { + $firstNode = $trace[0]; + if (array_key_exists('function', $firstNode)) { + return $firstNode['function']; + } + } + return ''; + } +} \ No newline at end of file diff --git a/Trustpilot/wc_trustpilot.php b/Trustpilot/wc_trustpilot.php index cc1eae9..03aca7e 100755 --- a/Trustpilot/wc_trustpilot.php +++ b/Trustpilot/wc_trustpilot.php @@ -12,7 +12,7 @@ * @wordpress-plugin * Plugin Name: Trustpilot-reviews * Description: Trustpilot-reviews helps Woocommerce store owners generate a ton of reviews for their products. - * Version: 2.5.763 + * Version: 2.5.788 * Author: Trustpilot * Author URI: https://trustpilot.com * Text Domain: Trustpilot-reviews @@ -20,8 +20,6 @@ * License URI: https://www.afl.org/licenses/afl-3.0.txt */ - - namespace Trustpilot\Review; // If this file is called directly, abort. @@ -29,31 +27,10 @@ die; } -/** - * Check if WooCommerce is active - **/ -function trustpilot_woocommerce_missing_wc_notice() { - echo " -
-

- Trustpilot plugin requires WooCommerce to be installed and active. - Please add Woocommerce plugin to your Wordpress page under Plugins section. - After installaing and activating plugin you will be able to activate Trustpilot plugin also. -

-
- "; -} - -$blog_plugins = get_option( 'active_plugins', array() ); -$site_plugins = is_multisite() ? (array) maybe_unserialize( get_site_option('active_sitewide_plugins' ) ) : array(); -if ( ! ( in_array( 'woocommerce/woocommerce.php', $blog_plugins ) - || isset( $site_plugins['woocommerce/woocommerce.php'] ) ) ) -{ - add_action( 'admin_notices', 'Trustpilot\\Review\\trustpilot_woocommerce_missing_wc_notice' ); - return; -} - include( plugin_dir_path( __FILE__ ) . './config.php'); +include( plugin_dir_path( __FILE__ ) . './review/api/TrustpilotPluginStatus.php'); +include( plugin_dir_path( __FILE__ ) . './review/api/TrustpilotHttpClient.php'); +include( plugin_dir_path( __FILE__ ) . './review/util/TrustpilotLogger.php'); include( plugin_dir_path( __FILE__ ) . './helper.php'); include( plugin_dir_path( __FILE__ ) . './legacy.php'); define( 'TRUSTPILOT_REVIEWS_VERSION', TRUSTPILOT_PLUGIN_VERSION );