Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Automattic\WooCommerce\Admin\API\Reports\Orders; defined("\x41\x42\x53\12..
Decoded Output download
<?php
namespace Automattic\WooCommerce\Admin\API\Reports\Orders; defined("ABSPATH") || die; use Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; use Automattic\WooCommerce\Admin\API\Reports\SqlQuery; use Automattic\WooCommerce\Admin\API\Reports\Cache; use Automattic\WooCommerce\Admin\API\Reports\TimeInterval; class DataStore extends ReportsDataStore implements DataStoreInterface { public function __construct() { $this->date_column_name = get_option("woocommerce_date_type", "date_paid"); parent::__construct(); } protected static $table_name = "wc_order_stats"; protected $cache_key = "orders"; protected $column_types = array("order_id" => "intval", "parent_id" => "intval", "date_created" => "strval", "date_created_gmt" => "strval", "status" => "strval", "customer_id" => "intval", "net_total" => "floatval", "total_sales" => "floatval", "num_items_sold" => "intval", "customer_type" => "strval"); protected $context = "orders"; protected function assign_report_columns() { $table_name = self::get_db_table_name(); $this->report_columns = array("order_id" => "DISTINCT {$table_name}.order_id", "parent_id" => "{$table_name}.parent_id", "date" => "{$table_name}.{$this->date_column_name} AS date", "date_created" => "{$table_name}.date_created", "date_created_gmt" => "{$table_name}.date_created_gmt", "status" => "REPLACE({$table_name}.status, 'wc-', '') as status", "customer_id" => "{$table_name}.customer_id", "net_total" => "{$table_name}.net_total", "total_sales" => "{$table_name}.total_sales", "num_items_sold" => "{$table_name}.num_items_sold", "customer_type" => "(CASE WHEN {$table_name}.returning_customer = 0 THEN 'new' ELSE 'returning' END) as customer_type"); } protected function add_sql_query_params($query_args) { global $wpdb; $order_stats_lookup_table = self::get_db_table_name(); $order_coupon_lookup_table = $wpdb->prefix . "wc_order_coupon_lookup"; $order_product_lookup_table = $wpdb->prefix . "wc_order_product_lookup"; $order_tax_lookup_table = $wpdb->prefix . "wc_order_tax_lookup"; $operator = $this->get_match_operator($query_args); $where_subquery = array(); $have_joined_products_table = false; $this->add_time_period_sql_params($query_args, $order_stats_lookup_table); $this->get_limit_sql_params($query_args); $this->add_order_by_sql_params($query_args); $status_subquery = $this->get_status_subquery($query_args); if ($status_subquery) { if (empty($query_args["status_is"]) && empty($query_args["status_is_not"])) { $this->subquery->add_sql_clause("where", "AND {$status_subquery}"); } else { $where_subquery[] = $status_subquery; } } $included_orders = $this->get_included_orders($query_args); if ($included_orders) { $where_subquery[] = "{$order_stats_lookup_table}.order_id IN ({$included_orders})"; } $excluded_orders = $this->get_excluded_orders($query_args); if ($excluded_orders) { $where_subquery[] = "{$order_stats_lookup_table}.order_id NOT IN ({$excluded_orders})"; } if ($query_args["customer_type"]) { $returning_customer = "returning" === $query_args["customer_type"] ? 1 : 0; $where_subquery[] = "{$order_stats_lookup_table}.returning_customer = {$returning_customer}"; } $refund_subquery = $this->get_refund_subquery($query_args); $this->subquery->add_sql_clause("from", $refund_subquery["from_clause"]); if ($refund_subquery["where_clause"]) { $where_subquery[] = $refund_subquery["where_clause"]; } $included_coupons = $this->get_included_coupons($query_args); $excluded_coupons = $this->get_excluded_coupons($query_args); if ($included_coupons || $excluded_coupons) { $this->subquery->add_sql_clause("join", "LEFT JOIN {$order_coupon_lookup_table} ON {$order_stats_lookup_table}.order_id = {$order_coupon_lookup_table}.order_id"); } if ($included_coupons) { $where_subquery[] = "{$order_coupon_lookup_table}.coupon_id IN ({$included_coupons})"; } if ($excluded_coupons) { $where_subquery[] = "({$order_coupon_lookup_table}.coupon_id IS NULL OR {$order_coupon_lookup_table}.coupon_id NOT IN ({$excluded_coupons}))"; } $included_products = $this->get_included_products($query_args); $excluded_products = $this->get_excluded_products($query_args); if ($included_products || $excluded_products) { $this->subquery->add_sql_clause("join", "LEFT JOIN {$order_product_lookup_table} product_lookup"); $this->subquery->add_sql_clause("join", "ON {$order_stats_lookup_table}.order_id = product_lookup.order_id"); } if ($included_products) { $this->subquery->add_sql_clause("join", "AND product_lookup.product_id IN ({$included_products})"); $where_subquery[] = "product_lookup.order_id IS NOT NULL"; } if ($excluded_products) { $this->subquery->add_sql_clause("join", "AND product_lookup.product_id IN ({$excluded_products})"); $where_subquery[] = "product_lookup.order_id IS NULL"; } $included_variations = $this->get_included_variations($query_args); $excluded_variations = $this->get_excluded_variations($query_args); if ($included_variations || $excluded_variations) { $this->subquery->add_sql_clause("join", "LEFT JOIN {$order_product_lookup_table} variation_lookup"); $this->subquery->add_sql_clause("join", "ON {$order_stats_lookup_table}.order_id = variation_lookup.order_id"); } if ($included_variations) { $this->subquery->add_sql_clause("join", "AND variation_lookup.variation_id IN ({$included_variations})"); $where_subquery[] = "variation_lookup.order_id IS NOT NULL"; } if ($excluded_variations) { $this->subquery->add_sql_clause("join", "AND variation_lookup.variation_id IN ({$excluded_variations})"); $where_subquery[] = "variation_lookup.order_id IS NULL"; } $included_tax_rates = !empty($query_args["tax_rate_includes"]) ? implode(",", array_map("esc_sql", $query_args["tax_rate_includes"])) : false; $excluded_tax_rates = !empty($query_args["tax_rate_excludes"]) ? implode(",", array_map("esc_sql", $query_args["tax_rate_excludes"])) : false; if ($included_tax_rates || $excluded_tax_rates) { $this->subquery->add_sql_clause("join", "LEFT JOIN {$order_tax_lookup_table} ON {$order_stats_lookup_table}.order_id = {$order_tax_lookup_table}.order_id"); } if ($included_tax_rates) { $where_subquery[] = "{$order_tax_lookup_table}.tax_rate_id IN ({$included_tax_rates})"; } if ($excluded_tax_rates) { $where_subquery[] = "{$order_tax_lookup_table}.tax_rate_id NOT IN ({$excluded_tax_rates}) OR {$order_tax_lookup_table}.tax_rate_id IS NULL"; } $attribute_subqueries = $this->get_attribute_subqueries($query_args); if ($attribute_subqueries["join"] && $attribute_subqueries["where"]) { $this->subquery->add_sql_clause("join", "JOIN {$order_product_lookup_table} ON {$order_stats_lookup_table}.order_id = {$order_product_lookup_table}.order_id"); foreach ($attribute_subqueries["join"] as $attribute_join) { $this->subquery->add_sql_clause("join", $attribute_join); } $where_subquery = array_merge($where_subquery, $attribute_subqueries["where"]); } if (0 < count($where_subquery)) { $this->subquery->add_sql_clause("where", "AND (" . implode(" {$operator} ", $where_subquery) . ")"); } } public function get_data($query_args) { global $wpdb; $defaults = array("per_page" => get_option("posts_per_page"), "page" => 1, "order" => "DESC", "orderby" => $this->date_column_name, "before" => TimeInterval::default_before(), "after" => TimeInterval::default_after(), "fields" => "*", "product_includes" => array(), "product_excludes" => array(), "coupon_includes" => array(), "coupon_excludes" => array(), "tax_rate_includes" => array(), "tax_rate_excludes" => array(), "customer_type" => null, "status_is" => array(), "extended_info" => false, "refunds" => null, "order_includes" => array(), "order_excludes" => array()); $query_args = wp_parse_args($query_args, $defaults); $this->normalize_timezones($query_args, $defaults); $cache_key = $this->get_cache_key($query_args); $data = $this->get_cached_data($cache_key); if (false === $data) { $this->initialize_queries(); $data = (object) array("data" => array(), "total" => 0, "pages" => 0, "page_no" => 0); $selections = $this->selected_columns($query_args); $params = $this->get_limit_params($query_args); $this->add_sql_query_params($query_args); $db_records_count = (int) $wpdb->get_var("SELECT COUNT( DISTINCT tt.order_id ) FROM (\xa\x9\x9 \x9 {$this->subquery->get_query_statement()}\xa\x9 \x9\x9) AS tt"); if (0 === $params["per_page"]) { $total_pages = 0; } else { $total_pages = (int) ceil($db_records_count / $params["per_page"]); } if ($query_args["page"] < 1 || $query_args["page"] > $total_pages) { $data = (object) array("data" => array(), "total" => $db_records_count, "pages" => 0, "page_no" => 0); return $data; } $this->subquery->clear_sql_clause("select"); $this->subquery->add_sql_clause("select", $selections); $this->subquery->add_sql_clause("order_by", $this->get_sql_clause("order_by")); $this->subquery->add_sql_clause("limit", $this->get_sql_clause("limit")); $orders_data = $wpdb->get_results($this->subquery->get_query_statement(), ARRAY_A); if (null === $orders_data) { return $data; } if ($query_args["extended_info"]) { $this->include_extended_info($orders_data, $query_args); } $orders_data = array_map(array($this, "cast_numbers"), $orders_data); $data = (object) array("data" => $orders_data, "total" => $db_records_count, "pages" => $total_pages, "page_no" => (int) $query_args["page"]); $this->set_cached_data($cache_key, $data); } return $data; } protected function normalize_order_by($order_by) { if ("date" === $order_by) { return $this->date_column_name; } return $order_by; } protected function include_extended_info(&$orders_data, $query_args) { $mapped_orders = $this->map_array_by_key($orders_data, "order_id"); $related_orders = $this->get_orders_with_parent_id($mapped_orders); $order_ids = array_merge(array_keys($mapped_orders), array_keys($related_orders)); $products = $this->get_products_by_order_ids($order_ids); $coupons = $this->get_coupons_by_order_ids(array_keys($mapped_orders)); $customers = $this->get_customers_by_orders($orders_data); $mapped_customers = $this->map_array_by_key($customers, "customer_id"); $mapped_data = array(); foreach ($products as $product) { if (!isset($mapped_data[$product["order_id"]])) { $mapped_data[$product["order_id"]]["products"] = array(); } $is_variation = "0" !== $product["variation_id"]; $product_data = array("id" => $is_variation ? $product["variation_id"] : $product["product_id"], "name" => $product["product_name"], "quantity" => $product["product_quantity"]); if ($is_variation) { $variation = wc_get_product($product_data["id"]); $separator = apply_filters("woocommerce_product_variation_title_attributes_separator", " - ", $variation); if (false === strpos($product_data["name"], $separator)) { $attributes = wc_get_formatted_variation($variation, true, false); $product_data["name"] .= $separator . $attributes; } } $mapped_data[$product["order_id"]]["products"][] = $product_data; if (isset($related_orders[$product["order_id"]])) { $mapped_data[$related_orders[$product["order_id"]]["order_id"]]["products"][] = $product_data; } } foreach ($coupons as $coupon) { if (!isset($mapped_data[$coupon["order_id"]])) { $mapped_data[$product["order_id"]]["coupons"] = array(); } $mapped_data[$coupon["order_id"]]["coupons"][] = array("id" => $coupon["coupon_id"], "code" => wc_format_coupon_code($coupon["coupon_code"])); } foreach ($orders_data as $key => $order_data) { $defaults = array("products" => array(), "coupons" => array(), "customer" => array()); $orders_data[$key]["extended_info"] = isset($mapped_data[$order_data["order_id"]]) ? array_merge($defaults, $mapped_data[$order_data["order_id"]]) : $defaults; if ($order_data["customer_id"] && isset($mapped_customers[$order_data["customer_id"]])) { $orders_data[$key]["extended_info"]["customer"] = $mapped_customers[$order_data["customer_id"]]; } } } protected function get_orders_with_parent_id($orders) { $related_orders = array(); foreach ($orders as $order) { if ("0" !== $order["parent_id"]) { $related_orders[$order["parent_id"]] = $order; } } return $related_orders; } protected function map_array_by_key($array, $key) { $mapped = array(); foreach ($array as $item) { $mapped[$item[$key]] = $item; } return $mapped; } protected function get_products_by_order_ids($order_ids) { global $wpdb; $order_product_lookup_table = $wpdb->prefix . "wc_order_product_lookup"; $included_order_ids = implode(",", $order_ids); $products = $wpdb->get_results("SELECT\xa\x9 \x9 order_id,
product_id,
\x9 variation_id,\xa\x9\x9\x9\x9post_title as product_name,
\x9 product_qty as product_quantity\xa \x9 FROM {$wpdb->posts}\xa JOIN
\x9 \x9{$order_product_lookup_table}
\x9ON {$wpdb->posts}.ID = (
\x9\x9\x9\x9 CASE WHEN variation_id > 0
\x9 \x9 \x9\x9THEN variation_id
\x9\x9\x9 \x9ELSE product_id
\x9\x9\x9\x9 END\xa\x9 \x9)
\x9 WHERE\xa\x9 \x9\x9order_id IN ({$included_order_ids})\xa\x9\x9\x9", ARRAY_A); return $products; } protected function get_customers_by_orders($orders) { global $wpdb; $customer_lookup_table = $wpdb->prefix . "wc_customer_lookup"; $customer_ids = array(); foreach ($orders as $order) { if ($order["customer_id"]) { $customer_ids[] = intval($order["customer_id"]); } } if (empty($customer_ids)) { return array(); } $customer_ids = implode(",", $customer_ids); $customers = $wpdb->get_results("SELECT * FROM {$customer_lookup_table} WHERE customer_id IN ({$customer_ids})", ARRAY_A); return $customers; } protected function get_coupons_by_order_ids($order_ids) { global $wpdb; $order_coupon_lookup_table = $wpdb->prefix . "wc_order_coupon_lookup"; $included_order_ids = implode(",", $order_ids); $coupons = $wpdb->get_results("SELECT order_id, coupon_id, post_title as coupon_code
\x9\x9\x9 FROM {$wpdb->posts}\xa\x9 \x9 JOIN {$order_coupon_lookup_table} ON {$order_coupon_lookup_table}.coupon_id = {$wpdb->posts}.ID\xa \x9\x9WHERE
\x9 \x9order_id IN ({$included_order_ids})\xa\x9\x9\x9 ", ARRAY_A); return $coupons; } public static function get_all_statuses() { global $wpdb; $cache_key = "orders-all-statuses"; $statuses = Cache::get($cache_key); if (false === $statuses) { $table_name = self::get_db_table_name(); $statuses = $wpdb->get_col("SELECT DISTINCT status FROM {$table_name}"); Cache::set($cache_key, $statuses); } return $statuses; } protected function initialize_queries() { $this->clear_all_clauses(); $this->subquery = new SqlQuery($this->context . "_subquery"); $this->subquery->add_sql_clause("select", self::get_db_table_name() . ".order_id"); $this->subquery->add_sql_clause("from", self::get_db_table_name()); } } ?>
Did this file decode correctly?
Original Code
<?php
namespace Automattic\WooCommerce\Admin\API\Reports\Orders; defined("\x41\x42\x53\120\x41\x54\110") || die; use Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; use Automattic\WooCommerce\Admin\API\Reports\SqlQuery; use Automattic\WooCommerce\Admin\API\Reports\Cache; use Automattic\WooCommerce\Admin\API\Reports\TimeInterval; class DataStore extends ReportsDataStore implements DataStoreInterface { public function __construct() { $this->date_column_name = get_option("\x77\157\x6f\143\x6f\155\155\145\162\x63\145\137\144\x61\x74\x65\137\164\x79\160\x65", "\x64\x61\x74\x65\137\x70\x61\x69\144"); parent::__construct(); } protected static $table_name = "\167\x63\137\x6f\x72\x64\145\162\137\x73\x74\x61\164\x73"; protected $cache_key = "\x6f\x72\x64\145\x72\163"; protected $column_types = array("\157\x72\144\x65\162\137\151\144" => "\151\156\164\x76\x61\x6c", "\160\x61\x72\x65\x6e\x74\x5f\x69\x64" => "\x69\156\x74\166\141\x6c", "\x64\141\x74\x65\137\143\x72\145\x61\164\x65\144" => "\163\164\x72\x76\141\x6c", "\144\141\164\145\x5f\x63\162\x65\141\164\x65\x64\x5f\x67\155\164" => "\x73\164\x72\166\x61\154", "\x73\x74\x61\164\x75\x73" => "\x73\164\162\166\141\x6c", "\143\x75\x73\164\x6f\155\145\x72\x5f\151\144" => "\x69\x6e\164\x76\141\154", "\156\145\164\x5f\x74\x6f\x74\x61\154" => "\x66\154\157\141\164\x76\x61\154", "\164\x6f\164\141\x6c\x5f\163\x61\x6c\145\163" => "\x66\x6c\157\x61\x74\x76\x61\154", "\156\x75\x6d\137\151\164\145\x6d\163\137\163\x6f\154\144" => "\x69\156\x74\166\141\154", "\x63\x75\163\x74\x6f\155\x65\162\x5f\x74\x79\x70\x65" => "\x73\x74\162\166\141\154"); protected $context = "\157\x72\x64\x65\x72\163"; protected function assign_report_columns() { $table_name = self::get_db_table_name(); $this->report_columns = array("\157\162\x64\x65\x72\x5f\x69\x64" => "\104\111\123\x54\x49\x4e\x43\x54\x20{$table_name}\56\157\162\x64\145\162\x5f\x69\144", "\x70\141\x72\145\156\164\x5f\151\x64" => "{$table_name}\56\160\141\x72\145\x6e\x74\x5f\x69\x64", "\144\141\x74\x65" => "{$table_name}\56{$this->date_column_name}\40\101\x53\x20\x64\141\164\145", "\x64\x61\164\145\137\x63\x72\x65\x61\x74\145\144" => "{$table_name}\56\x64\x61\x74\145\x5f\143\162\145\141\164\145\x64", "\144\x61\164\x65\137\143\162\x65\x61\x74\145\x64\x5f\147\155\164" => "{$table_name}\x2e\x64\x61\x74\145\137\x63\x72\145\141\x74\x65\x64\137\x67\155\164", "\163\164\x61\x74\165\163" => "\x52\105\120\x4c\x41\103\x45\x28{$table_name}\56\x73\x74\141\x74\165\x73\x2c\x20\x27\x77\x63\55\47\x2c\x20\x27\x27\x29\40\141\x73\40\163\164\x61\164\x75\x73", "\143\x75\163\164\x6f\x6d\x65\x72\137\151\x64" => "{$table_name}\56\x63\165\163\164\157\x6d\x65\162\137\151\144", "\156\145\x74\x5f\164\x6f\164\141\x6c" => "{$table_name}\x2e\156\x65\164\x5f\164\157\x74\x61\x6c", "\x74\x6f\164\141\x6c\x5f\x73\141\154\145\163" => "{$table_name}\56\x74\x6f\x74\141\154\137\163\x61\x6c\145\x73", "\156\165\155\137\x69\164\x65\155\163\137\x73\157\154\144" => "{$table_name}\x2e\x6e\x75\x6d\137\151\164\145\155\163\x5f\163\x6f\154\144", "\x63\x75\163\x74\x6f\155\x65\x72\x5f\x74\171\x70\x65" => "\x28\x43\x41\123\x45\x20\127\110\105\116\x20{$table_name}\56\x72\145\164\x75\x72\x6e\x69\156\147\x5f\x63\x75\x73\x74\157\x6d\x65\162\40\75\40\60\x20\124\x48\x45\116\40\47\x6e\x65\x77\x27\x20\x45\x4c\123\x45\x20\47\162\145\164\165\x72\x6e\x69\x6e\x67\x27\40\105\116\104\x29\x20\141\x73\40\x63\165\163\x74\157\x6d\145\x72\137\x74\x79\x70\x65"); } protected function add_sql_query_params($query_args) { global $wpdb; $order_stats_lookup_table = self::get_db_table_name(); $order_coupon_lookup_table = $wpdb->prefix . "\167\x63\x5f\x6f\162\x64\x65\x72\137\x63\157\x75\160\157\x6e\x5f\x6c\157\x6f\x6b\165\x70"; $order_product_lookup_table = $wpdb->prefix . "\167\x63\137\x6f\x72\144\145\162\x5f\160\162\x6f\x64\x75\x63\164\x5f\154\157\157\x6b\x75\160"; $order_tax_lookup_table = $wpdb->prefix . "\167\143\x5f\x6f\162\x64\x65\162\x5f\164\x61\170\137\154\x6f\157\x6b\165\x70"; $operator = $this->get_match_operator($query_args); $where_subquery = array(); $have_joined_products_table = false; $this->add_time_period_sql_params($query_args, $order_stats_lookup_table); $this->get_limit_sql_params($query_args); $this->add_order_by_sql_params($query_args); $status_subquery = $this->get_status_subquery($query_args); if ($status_subquery) { if (empty($query_args["\163\x74\x61\x74\x75\x73\x5f\x69\x73"]) && empty($query_args["\163\164\141\164\x75\x73\137\x69\x73\137\156\x6f\164"])) { $this->subquery->add_sql_clause("\167\150\x65\x72\145", "\101\116\104\40{$status_subquery}"); } else { $where_subquery[] = $status_subquery; } } $included_orders = $this->get_included_orders($query_args); if ($included_orders) { $where_subquery[] = "{$order_stats_lookup_table}\x2e\157\162\x64\145\x72\137\151\x64\40\111\116\x20\x28{$included_orders}\x29"; } $excluded_orders = $this->get_excluded_orders($query_args); if ($excluded_orders) { $where_subquery[] = "{$order_stats_lookup_table}\56\157\x72\144\x65\x72\137\x69\x64\40\x4e\117\124\x20\111\116\x20\50{$excluded_orders}\x29"; } if ($query_args["\143\x75\x73\164\157\155\x65\x72\137\164\171\x70\x65"]) { $returning_customer = "\162\145\x74\165\x72\x6e\x69\156\147" === $query_args["\143\x75\163\x74\x6f\155\145\162\x5f\x74\x79\x70\145"] ? 1 : 0; $where_subquery[] = "{$order_stats_lookup_table}\56\162\145\164\x75\162\x6e\151\x6e\147\x5f\x63\165\x73\x74\x6f\155\x65\162\40\75\40{$returning_customer}"; } $refund_subquery = $this->get_refund_subquery($query_args); $this->subquery->add_sql_clause("\146\162\157\155", $refund_subquery["\146\x72\157\x6d\137\143\154\141\x75\x73\x65"]); if ($refund_subquery["\x77\150\x65\x72\x65\x5f\143\154\141\165\163\x65"]) { $where_subquery[] = $refund_subquery["\167\x68\x65\162\x65\x5f\143\154\141\165\x73\x65"]; } $included_coupons = $this->get_included_coupons($query_args); $excluded_coupons = $this->get_excluded_coupons($query_args); if ($included_coupons || $excluded_coupons) { $this->subquery->add_sql_clause("\152\x6f\x69\x6e", "\114\105\x46\124\40\112\x4f\x49\116\40{$order_coupon_lookup_table}\40\117\x4e\40{$order_stats_lookup_table}\x2e\157\x72\x64\145\x72\x5f\x69\144\x20\75\40{$order_coupon_lookup_table}\x2e\x6f\x72\x64\x65\162\137\151\144"); } if ($included_coupons) { $where_subquery[] = "{$order_coupon_lookup_table}\56\x63\157\x75\160\x6f\156\x5f\x69\144\x20\x49\x4e\x20\x28{$included_coupons}\51"; } if ($excluded_coupons) { $where_subquery[] = "\x28{$order_coupon_lookup_table}\x2e\x63\157\165\160\x6f\156\137\151\144\x20\111\x53\40\x4e\125\114\114\x20\x4f\x52\40{$order_coupon_lookup_table}\56\143\157\x75\160\157\x6e\x5f\151\x64\x20\x4e\x4f\x54\40\x49\116\x20\x28{$excluded_coupons}\x29\51"; } $included_products = $this->get_included_products($query_args); $excluded_products = $this->get_excluded_products($query_args); if ($included_products || $excluded_products) { $this->subquery->add_sql_clause("\152\x6f\x69\x6e", "\x4c\105\106\x54\x20\x4a\x4f\111\x4e\x20{$order_product_lookup_table}\x20\x70\162\x6f\x64\165\143\x74\137\x6c\157\157\x6b\x75\x70"); $this->subquery->add_sql_clause("\152\157\151\x6e", "\x4f\x4e\40{$order_stats_lookup_table}\x2e\157\x72\x64\145\162\137\151\x64\x20\75\40\x70\162\x6f\144\165\143\164\137\x6c\x6f\157\153\x75\x70\56\x6f\162\x64\x65\x72\137\151\144"); } if ($included_products) { $this->subquery->add_sql_clause("\x6a\157\x69\x6e", "\101\x4e\x44\x20\160\162\157\x64\165\143\164\x5f\x6c\157\x6f\153\x75\160\x2e\160\162\157\x64\165\143\164\x5f\151\x64\40\x49\x4e\x20\x28{$included_products}\x29"); $where_subquery[] = "\x70\162\157\144\165\143\x74\137\154\x6f\x6f\153\x75\x70\x2e\x6f\x72\x64\x65\162\x5f\151\x64\40\x49\x53\x20\116\117\x54\40\116\125\x4c\x4c"; } if ($excluded_products) { $this->subquery->add_sql_clause("\152\157\151\156", "\x41\116\x44\40\160\x72\x6f\x64\165\x63\164\x5f\154\x6f\x6f\153\x75\x70\56\160\162\157\x64\x75\143\x74\x5f\151\144\40\x49\x4e\40\50{$excluded_products}\51"); $where_subquery[] = "\x70\162\x6f\x64\x75\143\164\x5f\154\x6f\x6f\153\165\160\x2e\x6f\162\x64\145\x72\x5f\x69\144\x20\x49\123\40\116\125\x4c\x4c"; } $included_variations = $this->get_included_variations($query_args); $excluded_variations = $this->get_excluded_variations($query_args); if ($included_variations || $excluded_variations) { $this->subquery->add_sql_clause("\x6a\x6f\151\156", "\114\105\106\124\x20\x4a\x4f\111\116\x20{$order_product_lookup_table}\x20\x76\141\162\151\141\164\151\157\156\137\154\157\157\x6b\x75\160"); $this->subquery->add_sql_clause("\152\157\x69\156", "\117\x4e\x20{$order_stats_lookup_table}\56\157\162\x64\145\162\137\151\144\40\x3d\x20\x76\141\162\151\141\164\151\x6f\156\137\154\157\157\x6b\x75\160\x2e\157\162\x64\145\x72\x5f\x69\144"); } if ($included_variations) { $this->subquery->add_sql_clause("\152\x6f\x69\x6e", "\101\x4e\x44\x20\x76\141\162\x69\x61\164\x69\157\156\x5f\154\157\157\153\x75\160\x2e\166\141\x72\x69\x61\x74\151\157\156\137\151\x64\40\x49\x4e\x20\x28{$included_variations}\x29"); $where_subquery[] = "\166\141\162\151\x61\x74\x69\157\156\x5f\x6c\157\x6f\x6b\165\x70\56\157\162\144\145\x72\137\x69\x64\x20\111\x53\40\116\117\124\40\x4e\125\x4c\114"; } if ($excluded_variations) { $this->subquery->add_sql_clause("\152\x6f\x69\156", "\101\x4e\x44\40\x76\x61\162\x69\141\x74\151\x6f\156\137\154\x6f\157\153\165\x70\56\166\141\162\151\x61\164\x69\157\156\x5f\x69\144\x20\x49\116\40\x28{$excluded_variations}\x29"); $where_subquery[] = "\166\141\x72\x69\141\164\151\x6f\x6e\137\x6c\x6f\157\153\x75\x70\56\157\x72\144\x65\162\137\x69\x64\x20\x49\123\x20\116\x55\x4c\114"; } $included_tax_rates = !empty($query_args["\x74\x61\170\137\x72\141\164\145\137\x69\156\x63\x6c\x75\144\x65\x73"]) ? implode("\54", array_map("\145\x73\x63\x5f\x73\161\x6c", $query_args["\164\x61\x78\137\162\x61\164\145\x5f\x69\156\x63\154\x75\x64\145\163"])) : false; $excluded_tax_rates = !empty($query_args["\x74\x61\170\x5f\162\x61\164\x65\x5f\x65\170\x63\x6c\x75\x64\145\163"]) ? implode("\54", array_map("\145\x73\143\x5f\x73\x71\x6c", $query_args["\x74\141\x78\x5f\x72\x61\x74\x65\x5f\145\x78\x63\x6c\165\144\145\x73"])) : false; if ($included_tax_rates || $excluded_tax_rates) { $this->subquery->add_sql_clause("\152\157\151\156", "\114\x45\x46\x54\x20\112\117\x49\116\x20{$order_tax_lookup_table}\40\117\x4e\x20{$order_stats_lookup_table}\x2e\157\162\144\145\x72\x5f\x69\x64\x20\x3d\40{$order_tax_lookup_table}\56\157\x72\144\x65\x72\x5f\151\144"); } if ($included_tax_rates) { $where_subquery[] = "{$order_tax_lookup_table}\x2e\164\141\170\x5f\162\x61\x74\145\137\151\144\40\111\116\x20\x28{$included_tax_rates}\x29"; } if ($excluded_tax_rates) { $where_subquery[] = "{$order_tax_lookup_table}\56\164\x61\x78\137\162\x61\164\x65\137\151\x64\40\x4e\x4f\124\40\x49\x4e\40\x28{$excluded_tax_rates}\x29\40\117\122\40{$order_tax_lookup_table}\56\x74\141\x78\137\x72\x61\164\x65\x5f\x69\x64\x20\x49\123\40\116\125\x4c\x4c"; } $attribute_subqueries = $this->get_attribute_subqueries($query_args); if ($attribute_subqueries["\x6a\157\x69\x6e"] && $attribute_subqueries["\167\x68\145\x72\x65"]) { $this->subquery->add_sql_clause("\x6a\x6f\151\x6e", "\112\117\111\116\x20{$order_product_lookup_table}\40\117\x4e\x20{$order_stats_lookup_table}\x2e\x6f\162\144\x65\x72\137\x69\144\40\75\40{$order_product_lookup_table}\56\x6f\x72\x64\145\162\137\151\144"); foreach ($attribute_subqueries["\x6a\157\x69\156"] as $attribute_join) { $this->subquery->add_sql_clause("\152\x6f\151\x6e", $attribute_join); } $where_subquery = array_merge($where_subquery, $attribute_subqueries["\x77\150\x65\x72\x65"]); } if (0 < count($where_subquery)) { $this->subquery->add_sql_clause("\167\x68\x65\x72\145", "\101\116\x44\40\x28" . implode("\40{$operator}\40", $where_subquery) . "\51"); } } public function get_data($query_args) { global $wpdb; $defaults = array("\160\x65\x72\137\160\141\147\x65" => get_option("\160\157\x73\x74\163\x5f\160\145\162\x5f\160\x61\147\145"), "\160\141\x67\x65" => 1, "\157\162\x64\145\x72" => "\x44\x45\123\x43", "\157\x72\x64\x65\x72\142\171" => $this->date_column_name, "\x62\145\146\157\x72\145" => TimeInterval::default_before(), "\141\x66\164\x65\x72" => TimeInterval::default_after(), "\x66\151\145\154\144\163" => "\x2a", "\160\x72\157\x64\165\143\x74\x5f\x69\x6e\143\x6c\165\x64\x65\x73" => array(), "\160\x72\157\144\165\143\164\x5f\x65\x78\x63\x6c\x75\144\x65\x73" => array(), "\143\x6f\x75\160\x6f\x6e\x5f\x69\x6e\143\154\165\x64\x65\x73" => array(), "\x63\x6f\165\160\x6f\x6e\x5f\145\x78\x63\x6c\165\144\x65\x73" => array(), "\x74\141\170\x5f\x72\141\164\145\137\x69\x6e\x63\x6c\x75\144\x65\x73" => array(), "\x74\x61\x78\137\162\x61\x74\145\137\x65\170\143\154\x75\x64\145\163" => array(), "\x63\x75\x73\164\157\155\145\x72\x5f\164\171\160\145" => null, "\163\x74\141\164\x75\163\x5f\x69\163" => array(), "\145\170\x74\145\x6e\x64\x65\144\137\151\x6e\146\x6f" => false, "\x72\145\146\165\x6e\144\x73" => null, "\157\x72\x64\x65\x72\x5f\151\156\143\154\x75\x64\x65\x73" => array(), "\x6f\x72\144\145\162\137\145\x78\x63\154\x75\x64\x65\x73" => array()); $query_args = wp_parse_args($query_args, $defaults); $this->normalize_timezones($query_args, $defaults); $cache_key = $this->get_cache_key($query_args); $data = $this->get_cached_data($cache_key); if (false === $data) { $this->initialize_queries(); $data = (object) array("\144\141\164\x61" => array(), "\164\157\164\141\x6c" => 0, "\160\x61\147\145\163" => 0, "\x70\141\x67\x65\x5f\x6e\157" => 0); $selections = $this->selected_columns($query_args); $params = $this->get_limit_params($query_args); $this->add_sql_query_params($query_args); $db_records_count = (int) $wpdb->get_var("\x53\105\x4c\x45\103\124\x20\x43\x4f\125\x4e\x54\x28\40\x44\111\x53\x54\111\116\103\124\x20\x74\164\x2e\157\162\144\x65\162\x5f\x69\144\x20\51\x20\x46\x52\117\115\40\50\xa\x9\x9\11\x9\11{$this->subquery->get_query_statement()}\xa\x9\11\x9\x9\x29\40\x41\123\40\164\164"); if (0 === $params["\160\145\162\137\160\141\x67\145"]) { $total_pages = 0; } else { $total_pages = (int) ceil($db_records_count / $params["\x70\x65\162\137\160\x61\147\x65"]); } if ($query_args["\160\x61\147\x65"] < 1 || $query_args["\160\x61\147\145"] > $total_pages) { $data = (object) array("\144\141\164\x61" => array(), "\x74\157\164\141\154" => $db_records_count, "\x70\x61\147\145\x73" => 0, "\x70\x61\147\145\x5f\x6e\157" => 0); return $data; } $this->subquery->clear_sql_clause("\x73\x65\154\145\143\164"); $this->subquery->add_sql_clause("\163\145\x6c\145\143\x74", $selections); $this->subquery->add_sql_clause("\x6f\162\x64\145\x72\137\142\171", $this->get_sql_clause("\x6f\x72\x64\145\x72\137\x62\x79")); $this->subquery->add_sql_clause("\154\x69\x6d\x69\x74", $this->get_sql_clause("\x6c\151\155\151\164")); $orders_data = $wpdb->get_results($this->subquery->get_query_statement(), ARRAY_A); if (null === $orders_data) { return $data; } if ($query_args["\x65\x78\x74\145\156\x64\145\144\137\151\x6e\146\157"]) { $this->include_extended_info($orders_data, $query_args); } $orders_data = array_map(array($this, "\x63\x61\x73\164\137\x6e\x75\x6d\x62\x65\162\163"), $orders_data); $data = (object) array("\144\141\164\141" => $orders_data, "\164\157\x74\x61\154" => $db_records_count, "\160\141\x67\145\x73" => $total_pages, "\x70\141\x67\x65\137\x6e\157" => (int) $query_args["\x70\141\147\145"]); $this->set_cached_data($cache_key, $data); } return $data; } protected function normalize_order_by($order_by) { if ("\144\x61\164\x65" === $order_by) { return $this->date_column_name; } return $order_by; } protected function include_extended_info(&$orders_data, $query_args) { $mapped_orders = $this->map_array_by_key($orders_data, "\x6f\x72\x64\x65\162\137\x69\x64"); $related_orders = $this->get_orders_with_parent_id($mapped_orders); $order_ids = array_merge(array_keys($mapped_orders), array_keys($related_orders)); $products = $this->get_products_by_order_ids($order_ids); $coupons = $this->get_coupons_by_order_ids(array_keys($mapped_orders)); $customers = $this->get_customers_by_orders($orders_data); $mapped_customers = $this->map_array_by_key($customers, "\x63\165\x73\x74\157\155\145\162\x5f\151\x64"); $mapped_data = array(); foreach ($products as $product) { if (!isset($mapped_data[$product["\157\162\x64\x65\x72\x5f\x69\144"]])) { $mapped_data[$product["\157\x72\144\145\162\x5f\x69\x64"]]["\160\x72\x6f\x64\x75\143\164\163"] = array(); } $is_variation = "\60" !== $product["\x76\141\162\151\x61\x74\151\157\156\137\x69\144"]; $product_data = array("\151\144" => $is_variation ? $product["\x76\141\162\x69\x61\x74\x69\157\x6e\x5f\151\x64"] : $product["\160\162\157\144\x75\x63\164\x5f\x69\144"], "\x6e\x61\155\145" => $product["\x70\x72\x6f\144\x75\x63\164\137\x6e\x61\x6d\x65"], "\x71\x75\x61\x6e\x74\x69\164\171" => $product["\160\162\157\x64\x75\x63\164\x5f\x71\x75\x61\156\x74\151\164\x79"]); if ($is_variation) { $variation = wc_get_product($product_data["\x69\144"]); $separator = apply_filters("\167\x6f\x6f\x63\157\x6d\155\x65\162\143\x65\137\x70\162\157\x64\x75\143\164\137\x76\x61\162\x69\141\164\151\157\x6e\x5f\164\x69\164\x6c\145\x5f\141\x74\x74\162\x69\142\x75\x74\x65\163\x5f\163\x65\x70\141\162\x61\164\x6f\162", "\x20\x2d\x20", $variation); if (false === strpos($product_data["\156\141\155\145"], $separator)) { $attributes = wc_get_formatted_variation($variation, true, false); $product_data["\x6e\x61\155\145"] .= $separator . $attributes; } } $mapped_data[$product["\x6f\x72\x64\145\162\x5f\x69\144"]]["\x70\x72\x6f\144\x75\x63\164\x73"][] = $product_data; if (isset($related_orders[$product["\157\162\x64\145\162\137\151\144"]])) { $mapped_data[$related_orders[$product["\x6f\x72\x64\x65\x72\x5f\x69\x64"]]["\157\162\144\145\162\x5f\x69\x64"]]["\x70\162\157\144\x75\x63\164\x73"][] = $product_data; } } foreach ($coupons as $coupon) { if (!isset($mapped_data[$coupon["\x6f\x72\x64\x65\162\137\x69\x64"]])) { $mapped_data[$product["\157\x72\x64\x65\x72\137\x69\x64"]]["\143\x6f\x75\x70\157\x6e\x73"] = array(); } $mapped_data[$coupon["\157\x72\144\145\162\137\x69\x64"]]["\143\157\x75\160\x6f\x6e\163"][] = array("\151\144" => $coupon["\143\x6f\x75\x70\157\156\x5f\x69\144"], "\x63\157\x64\145" => wc_format_coupon_code($coupon["\143\157\165\x70\x6f\x6e\137\143\x6f\144\x65"])); } foreach ($orders_data as $key => $order_data) { $defaults = array("\x70\x72\x6f\144\x75\143\x74\163" => array(), "\143\x6f\x75\x70\157\x6e\x73" => array(), "\143\x75\163\x74\157\x6d\x65\162" => array()); $orders_data[$key]["\x65\x78\x74\x65\x6e\144\x65\x64\137\151\156\x66\157"] = isset($mapped_data[$order_data["\157\162\x64\x65\162\137\x69\144"]]) ? array_merge($defaults, $mapped_data[$order_data["\x6f\162\144\x65\x72\x5f\151\144"]]) : $defaults; if ($order_data["\x63\x75\163\x74\157\x6d\x65\162\x5f\x69\x64"] && isset($mapped_customers[$order_data["\x63\165\163\164\x6f\155\x65\x72\137\x69\x64"]])) { $orders_data[$key]["\145\x78\164\145\x6e\x64\x65\144\x5f\151\x6e\x66\157"]["\143\165\x73\164\157\x6d\x65\162"] = $mapped_customers[$order_data["\143\x75\163\x74\157\x6d\x65\162\137\151\x64"]]; } } } protected function get_orders_with_parent_id($orders) { $related_orders = array(); foreach ($orders as $order) { if ("\x30" !== $order["\x70\x61\x72\x65\x6e\x74\x5f\151\x64"]) { $related_orders[$order["\x70\141\x72\145\x6e\x74\137\x69\x64"]] = $order; } } return $related_orders; } protected function map_array_by_key($array, $key) { $mapped = array(); foreach ($array as $item) { $mapped[$item[$key]] = $item; } return $mapped; } protected function get_products_by_order_ids($order_ids) { global $wpdb; $order_product_lookup_table = $wpdb->prefix . "\x77\143\137\x6f\162\144\x65\x72\137\160\162\x6f\144\165\x63\x74\137\x6c\157\x6f\x6b\165\x70"; $included_order_ids = implode("\x2c", $order_ids); $products = $wpdb->get_results("\x53\105\114\105\103\124\xa\x9\11\x9\11\157\x72\144\145\x72\137\x69\x64\54\12\11\11\11\11\x70\162\157\144\165\x63\164\137\151\x64\x2c\12\x9\11\11\11\166\x61\162\x69\x61\164\x69\x6f\x6e\137\x69\144\54\xa\x9\x9\x9\x9\x70\x6f\x73\x74\x5f\164\x69\164\x6c\x65\40\x61\163\x20\160\162\x6f\144\165\143\x74\x5f\x6e\x61\x6d\145\54\12\11\x9\11\11\x70\162\157\144\x75\x63\164\137\161\x74\171\x20\x61\163\x20\x70\162\157\x64\165\143\x74\x5f\x71\165\141\156\164\x69\164\171\xa\11\x9\11\x46\x52\117\x4d\40{$wpdb->posts}\xa\11\11\11\x4a\117\x49\116\12\11\x9\11\x9{$order_product_lookup_table}\12\11\11\11\x9\x4f\x4e\x20{$wpdb->posts}\56\x49\104\x20\x3d\x20\50\12\x9\x9\x9\x9\11\103\101\123\105\x20\x57\x48\105\x4e\40\166\141\162\x69\141\164\x69\157\156\137\x69\x64\x20\x3e\40\x30\12\x9\11\x9\11\x9\x9\124\110\105\116\40\166\141\162\151\141\164\151\x6f\156\137\x69\x64\12\x9\x9\x9\11\11\x9\x45\x4c\x53\x45\x20\x70\x72\157\144\165\143\x74\137\x69\144\12\x9\x9\x9\x9\11\105\116\x44\xa\x9\11\11\x9\x29\12\11\x9\11\127\110\105\x52\x45\xa\x9\11\x9\x9\x6f\x72\144\x65\162\137\x69\x64\x20\x49\x4e\x20\x28{$included_order_ids}\x29\xa\x9\x9\x9", ARRAY_A); return $products; } protected function get_customers_by_orders($orders) { global $wpdb; $customer_lookup_table = $wpdb->prefix . "\x77\x63\137\143\165\x73\164\157\x6d\145\162\x5f\154\157\x6f\153\165\x70"; $customer_ids = array(); foreach ($orders as $order) { if ($order["\143\165\x73\x74\157\155\x65\162\x5f\151\x64"]) { $customer_ids[] = intval($order["\143\x75\163\x74\x6f\x6d\145\162\137\x69\144"]); } } if (empty($customer_ids)) { return array(); } $customer_ids = implode("\54", $customer_ids); $customers = $wpdb->get_results("\123\105\x4c\105\103\124\40\x2a\40\x46\x52\x4f\x4d\x20{$customer_lookup_table}\40\x57\110\x45\x52\x45\40\x63\165\163\164\x6f\x6d\x65\162\137\x69\x64\40\x49\x4e\40\50{$customer_ids}\x29", ARRAY_A); return $customers; } protected function get_coupons_by_order_ids($order_ids) { global $wpdb; $order_coupon_lookup_table = $wpdb->prefix . "\167\143\x5f\x6f\x72\144\x65\x72\x5f\143\x6f\165\160\x6f\156\x5f\154\157\157\x6b\165\160"; $included_order_ids = implode("\54", $order_ids); $coupons = $wpdb->get_results("\123\x45\114\105\x43\124\40\157\162\144\x65\162\x5f\151\144\x2c\40\143\157\x75\160\157\x6e\137\151\x64\x2c\x20\160\x6f\163\164\x5f\164\x69\x74\x6c\145\40\141\x73\x20\x63\x6f\165\x70\x6f\156\137\x63\x6f\144\x65\12\x9\x9\x9\11\x46\122\x4f\x4d\x20{$wpdb->posts}\xa\x9\11\x9\11\112\x4f\x49\116\40{$order_coupon_lookup_table}\40\117\116\x20{$order_coupon_lookup_table}\x2e\x63\157\165\160\x6f\x6e\x5f\x69\x64\x20\x3d\40{$wpdb->posts}\x2e\x49\x44\xa\11\11\x9\x9\x57\110\105\x52\x45\12\11\11\x9\11\x9\157\162\x64\x65\162\x5f\x69\x64\x20\x49\x4e\40\x28{$included_order_ids}\x29\xa\x9\x9\x9\11", ARRAY_A); return $coupons; } public static function get_all_statuses() { global $wpdb; $cache_key = "\157\162\x64\145\x72\163\55\141\x6c\x6c\55\163\164\x61\x74\x75\163\x65\x73"; $statuses = Cache::get($cache_key); if (false === $statuses) { $table_name = self::get_db_table_name(); $statuses = $wpdb->get_col("\123\105\114\x45\x43\124\40\x44\x49\123\124\x49\116\x43\x54\40\163\x74\x61\x74\x75\x73\x20\x46\x52\x4f\115\40{$table_name}"); Cache::set($cache_key, $statuses); } return $statuses; } protected function initialize_queries() { $this->clear_all_clauses(); $this->subquery = new SqlQuery($this->context . "\x5f\x73\x75\142\161\165\x65\162\171"); $this->subquery->add_sql_clause("\163\145\x6c\x65\x63\164", self::get_db_table_name() . "\56\157\162\x64\145\x72\137\x69\x64"); $this->subquery->add_sql_clause("\x66\x72\157\x6d", self::get_db_table_name()); } }
Function Calls
None |
Stats
MD5 | 03dc2bcb80da45b2c2babd994d62ecb9 |
Eval Count | 0 |
Decode Time | 136 ms |