Skip to content
2 changes: 1 addition & 1 deletion js/public/apbct-react-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/public/apbct-react-bundle.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */

/**
* @license React
Expand Down
11 changes: 8 additions & 3 deletions lib/Cleantalk/Antispam/IntegrationsByClass/Woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,20 @@ public function storeBlockedOrder()
{
global $wpdb;

$query = 'INSERT INTO ' . APBCT_TBL_WC_SPAM_ORDERS . ' (order_details, customer_details)
VALUES (%s, %s)
ON DUPLICATE KEY UPDATE order_details = %s, customer_details = %s';
$current_timestamp = time();
$query = 'INSERT INTO ' . APBCT_TBL_WC_SPAM_ORDERS . ' (order_details, customer_details, order_date)
VALUES (%s, %s, %s)
ON DUPLICATE KEY UPDATE order_details = %s, customer_details = %s, order_date = %s;';

// store blocked order from ajax checkout
if (!empty($_POST)) {
$prepared_query = $wpdb->prepare($query, [
Comment thread
Glomberg marked this conversation as resolved.
json_encode(wc()->session->cart),
json_encode($_POST),
$current_timestamp,
json_encode(wc()->session->cart),
json_encode($_POST),
$current_timestamp,
]);

$wpdb->query($prepared_query);
Expand Down Expand Up @@ -369,8 +372,10 @@ public function storeBlockedOrder()
$prepared_query = $wpdb->prepare($query, [
json_encode(wc()->session->cart),
json_encode($customer_data),
$current_timestamp,
json_encode(wc()->session->cart),
json_encode($customer_data),
$current_timestamp,
]);

$wpdb->query($prepared_query);
Expand Down
53 changes: 50 additions & 3 deletions lib/Cleantalk/ApbctWP/WcSpamOrdersListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function __construct()
public function prepare_items() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
{
$columns = $this->get_columns();
$this->_column_headers = array($columns, array(), array());
$sortable_columns = $this->get_sortable_columns();
$this->_column_headers = array($columns, array(), $sortable_columns);

// @ToDo implement per page dynamic option
/*$per_page_option = ! is_null(get_current_screen()) ? get_current_screen()->get_option(
Expand Down Expand Up @@ -97,12 +98,14 @@ public function prepare_items() // phpcs:ignore PSR1.Methods.CamelCapsMethodNam

$order_details_column = $this->renderOrderDetailsColumn($wc_spam_order->order_details);
$customer_details_column = $this->renderCustomerDetailsColumn($wc_spam_order->customer_details);
$order_date_column = $this->renderOrderDateColumn($wc_spam_order->order_date);

$this->items[] = array(
'cb' => $wc_spam_order->id,
'ct_order_id' => $order_id_column,
'ct_order_details' => $order_details_column,
'ct_customer_details' => $customer_details_column,
'ct_order_date' => $order_date_column,
);
}
}
Expand All @@ -114,15 +117,23 @@ public function get_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.N
'ct_order_id' => esc_html__('ID', 'cleantalk-spam-protect'),
'ct_order_details' => esc_html__('Order details', 'cleantalk-spam-protect'),
'ct_customer_details' => esc_html__('Customer details', 'cleantalk-spam-protect'),
'ct_order_date' => esc_html__('Order date', 'cleantalk-spam-protect'),
);

return $columns;
}

protected function get_sortable_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
{
return array(
'ct_order_date' => array('order_date', false),
);
}

public function get_bulk_actions() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
{
return array(
'delete' => esc_html__('Delete', 'cleantalk-spam-protect')
'delete' => esc_html__('Delete', 'cleantalk-spam-protect')
);
}

Expand Down Expand Up @@ -245,18 +256,54 @@ private function renderCustomerDetailsColumn($customer_details)
return $result;
}

private function renderOrderDateColumn($order_date)
{
if ( ! $order_date ) {
return '-';
}

$timestamp = is_numeric($order_date) ? (int) $order_date : strtotime($order_date);

if ( ! $timestamp ) {
return '-';
}

return sprintf(
'<time datetime="%1$s" title="%2$s">%3$s</time>',
esc_attr(date_i18n('c', $timestamp)), // 2023-02-15T20:25:06+00:00
esc_html(date_i18n('d.m.Y H:i', $timestamp)), // 15.02.2023 20:25
esc_html(date_i18n('M d, Y', $timestamp)) // Feb 15, 2023
);
}

/**
* @return array
*/
private function getWcSpamOrders()
{
global $wpdb;

$result = $wpdb->get_results('SELECT * FROM ' . APBCT_TBL_WC_SPAM_ORDERS, OBJECT);
$orderby = $this->getSqlOrderBy();
$order = Get::getString('order') === 'asc' ? 'ASC' : 'DESC';

$sql = 'SELECT * FROM ' . APBCT_TBL_WC_SPAM_ORDERS;

if ($orderby) {
$sql .= ' ORDER BY ' . $orderby . ' ' . $order;
}

$result = $wpdb->get_results($sql, OBJECT);
Comment thread
Glomberg marked this conversation as resolved.

return is_array($result) ? $result : array();
}

private function getSqlOrderBy()
{
$order_by = Get::getString('orderby');
$allowed_order_by = array_keys($this->get_sortable_columns());
return in_array('ct_' . $order_by, $allowed_order_by) ? $order_by : '';
}

private function removeSpam($ids)
{
global $wpdb;
Expand Down
3 changes: 2 additions & 1 deletion lib/Cleantalk/Common/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class Schema
'id' => 'INT NOT NULL AUTO_INCREMENT',
'order_details' => 'TEXT NULL DEFAULT NULL',
'customer_details' => 'TEXT NULL DEFAULT NULL',
'__indexes' => 'PRIMARY KEY (`id`)',
'order_date' => 'INT UNSIGNED NULL DEFAULT NULL',
Comment thread
Glomberg marked this conversation as resolved.
'__indexes' => 'PRIMARY KEY (`id`), INDEX (`order_date`)',
'__createkey' => 'INT unsigned primary KEY AUTO_INCREMENT FIRST'
Comment thread
Glomberg marked this conversation as resolved.
),
'rate_limits' => array(
Expand Down
Loading