v0.6.1
This commit is contained in:
parent
8a85a4d9af
commit
e9782eaa82
1 changed files with 1711 additions and 440 deletions
|
|
@ -24,7 +24,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
*
|
||||
* @var int
|
||||
*/
|
||||
private int $per_page = 20;
|
||||
private $per_page = 20;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -44,7 +44,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns(): array {
|
||||
public function get_columns() {
|
||||
return array(
|
||||
'created_at' => __( 'Date', 'robotstxt-telemetry' ),
|
||||
'method' => __( 'Method', 'robotstxt-telemetry' ),
|
||||
|
|
@ -56,7 +56,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
/**
|
||||
* Prepare items for display.
|
||||
*/
|
||||
public function prepare_items(): void {
|
||||
public function prepare_items() {
|
||||
global $wpdb;
|
||||
|
||||
$table_name = Robotstxt_Telemetry_DB::get_table_name();
|
||||
|
|
@ -79,14 +79,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
|
||||
$this->items = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; list output is never cached.
|
||||
$wpdb->prepare(
|
||||
'SELECT * FROM %i
|
||||
WHERE ( %s = \'\' OR method = %s )
|
||||
AND ( %s = \'\' OR host = %s )
|
||||
AND ( %s = \'\' OR created_at >= %s )
|
||||
AND ( %s = \'\' OR created_at <= %s )
|
||||
ORDER BY created_at DESC
|
||||
LIMIT %d OFFSET %d',
|
||||
$table_name,
|
||||
"SELECT * FROM {$table_name} WHERE ( %s = '' OR method = %s ) AND ( %s = '' OR host = %s ) AND ( %s = '' OR created_at >= %s ) AND ( %s = '' OR created_at <= %s ) ORDER BY created_at DESC LIMIT %d OFFSET %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
|
||||
$method,
|
||||
$method,
|
||||
$host,
|
||||
|
|
@ -103,12 +96,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
|
||||
$total = (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; pagination count is never cached.
|
||||
$wpdb->prepare(
|
||||
'SELECT COUNT(*) FROM %i
|
||||
WHERE ( %s = \'\' OR method = %s )
|
||||
AND ( %s = \'\' OR host = %s )
|
||||
AND ( %s = \'\' OR created_at >= %s )
|
||||
AND ( %s = \'\' OR created_at <= %s )',
|
||||
$table_name,
|
||||
"SELECT COUNT(*) FROM {$table_name} WHERE ( %s = '' OR method = %s ) AND ( %s = '' OR host = %s ) AND ( %s = '' OR created_at >= %s ) AND ( %s = '' OR created_at <= %s )", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
|
||||
$method,
|
||||
$method,
|
||||
$host,
|
||||
|
|
@ -135,14 +123,14 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
* @param string $column_name Column name.
|
||||
* @return string
|
||||
*/
|
||||
public function column_default( $item, $column_name ): string {
|
||||
public function column_default( $item, $column_name ) {
|
||||
switch ( $column_name ) {
|
||||
case 'created_at':
|
||||
return esc_html( $item[ $column_name ] ?? '' );
|
||||
return esc_html( isset( $item[ $column_name ] ) ? $item[ $column_name ] : '' );
|
||||
case 'method':
|
||||
case 'host':
|
||||
case 'path':
|
||||
return esc_html( $item[ $column_name ] ?? '' );
|
||||
return esc_html( isset( $item[ $column_name ] ) ? $item[ $column_name ] : '' );
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
|
@ -154,7 +142,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
* @param array $item Item data.
|
||||
* @return string
|
||||
*/
|
||||
public function column_created_at( $item ): string {
|
||||
public function column_created_at( $item ) {
|
||||
$log_id = (int) $item['id'];
|
||||
|
||||
$view_url = add_query_arg(
|
||||
|
|
@ -163,7 +151,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
'action' => 'view',
|
||||
'log' => $log_id,
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
Robotstxt_Telemetry_Network::base_url()
|
||||
);
|
||||
|
||||
$delete_url = wp_nonce_url(
|
||||
|
|
@ -173,7 +161,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
'action' => 'delete',
|
||||
'log' => $log_id,
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
Robotstxt_Telemetry_Network::base_url()
|
||||
),
|
||||
'robotstxt_telemetry_delete_log_' . $log_id
|
||||
);
|
||||
|
|
@ -192,7 +180,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
* @param array $item Item data.
|
||||
* @return string
|
||||
*/
|
||||
public function column_url( $item ): string {
|
||||
public function column_url( $item ) {
|
||||
if ( empty( $item['url'] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
|
@ -202,8 +190,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
return esc_html( $item['url'] );
|
||||
}
|
||||
|
||||
$scheme = $parsed_url['scheme'] ?? 'https';
|
||||
$path = $parsed_url['path'] ?? '';
|
||||
$scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] : 'https';
|
||||
$path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
|
||||
$port = isset( $parsed_url['port'] ) ? ':' . (int) $parsed_url['port'] : '';
|
||||
$base = sprintf( '%s://%s%s%s', $scheme, $parsed_url['host'], $port, $path );
|
||||
|
||||
|
|
@ -216,7 +204,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
* @param array $item Item data.
|
||||
* @return string
|
||||
*/
|
||||
private function format_params_column( array $item ): string {
|
||||
private function format_params_column( $item ) {
|
||||
$params = array();
|
||||
|
||||
if ( ! empty( $item['url'] ) ) {
|
||||
|
|
@ -227,12 +215,12 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
}
|
||||
}
|
||||
|
||||
$query_params = $this->decode_json_params( $item['query_json'] ?? '' );
|
||||
$query_params = $this->decode_json_params( isset( $item['query_json'] ) ? $item['query_json'] : '' );
|
||||
if ( ! empty( $query_params ) ) {
|
||||
$params = array_merge( $params, $query_params );
|
||||
}
|
||||
|
||||
$body_params = $this->decode_json_params( $item['body_json'] ?? '' );
|
||||
$body_params = $this->decode_json_params( isset( $item['body_json'] ) ? $item['body_json'] : '' );
|
||||
if ( ! empty( $body_params ) ) {
|
||||
$params = array_merge( $params, $body_params );
|
||||
}
|
||||
|
|
@ -266,7 +254,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
* @param string $value JSON string.
|
||||
* @return array
|
||||
*/
|
||||
private function decode_json_params( string $value ): array {
|
||||
private function decode_json_params( $value ) {
|
||||
if ( empty( $value ) ) {
|
||||
return array();
|
||||
}
|
||||
|
|
@ -296,7 +284,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
*
|
||||
* @param string $which Top or bottom.
|
||||
*/
|
||||
public function extra_tablenav( $which ): void {
|
||||
public function extra_tablenav( $which ) {
|
||||
if ( 'top' !== $which ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -354,7 +342,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
* @param string $key Filter key.
|
||||
* @return string
|
||||
*/
|
||||
private function get_filter_value( string $key ): string {
|
||||
private function get_filter_value( $key ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list filters.
|
||||
if ( ! isset( $_GET[ $key ] ) ) {
|
||||
return '';
|
||||
|
|
@ -369,7 +357,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
* @param string|null $value Date string.
|
||||
* @return string|null
|
||||
*/
|
||||
private function sanitize_date_filter( ?string $value ): ?string {
|
||||
private function sanitize_date_filter( $value ) {
|
||||
if ( empty( $value ) ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue