v2.0 版本重写

新增多项改进
This commit is contained in:
文派备案 2025-05-23 16:10:39 +08:00
parent 31bf7145ea
commit fbebd6ea2f
12 changed files with 4241 additions and 2180 deletions

View file

@ -10,46 +10,12 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Get pagination parameters
$per_page = isset( $_GET['logs_per_page'] ) ? absint( $_GET['logs_per_page'] ) : 50;
$paged = isset( $_GET['logs_paged'] ) ? absint( $_GET['logs_paged'] ) : 1;
$offset = ( $paged - 1 ) * $per_page;
// Get action filter
$action_filter = isset( $_GET['log_action'] ) ? sanitize_text_field( $_GET['log_action'] ) : '';
// Build WHERE clause for filtering
$where = array();
if ( ! empty( $action_filter ) ) {
$where[] = $wpdb->prepare( "action = %s", $action_filter );
}
$where_sql = $where ? ' WHERE ' . implode( ' AND ', $where ) : '';
// Count total logs for pagination
$total_logs = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_LOGS . $where_sql );
$total_pages = ceil( $total_logs / $per_page );
// Get logs with pagination
$logs = $wpdb->get_results( $wpdb->prepare(
"SELECT * FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_LOGS . $where_sql . " ORDER BY timestamp DESC LIMIT %d, %d",
$offset,
$per_page
));
// Get available actions for filter
$actions = $wpdb->get_col( "SELECT DISTINCT action FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_LOGS );
if ( ! $logs ) {
echo '<div class="notice notice-info"><p>' . esc_html__( 'No domain mapping logs available.', 'wp-domain-mapping' ) . '</p></div>';
return;
}
// This file is included from dm_domain_logs() function
?>
<div class="tablenav top">
<form method="GET" id="logs-filter-form" class="logs-filter">
<input type="hidden" name="page" value="domains" />
<input type="hidden" name="tab" value="domain-logs" />
<div class="alignleft actions">
<label for="log_action" class="screen-reader-text"><?php esc_html_e( 'Filter by action', 'wp-domain-mapping' ); ?></label>
@ -57,21 +23,7 @@ if ( ! $logs ) {
<option value=""><?php esc_html_e( 'All actions', 'wp-domain-mapping' ); ?></option>
<?php foreach ( $actions as $action ) : ?>
<option value="<?php echo esc_attr( $action ); ?>" <?php selected( $action_filter, $action ); ?>>
<?php
switch ( $action ) {
case 'add':
esc_html_e( 'Added', 'wp-domain-mapping' );
break;
case 'edit':
esc_html_e( 'Updated', 'wp-domain-mapping' );
break;
case 'delete':
esc_html_e( 'Deleted', 'wp-domain-mapping' );
break;
default:
echo esc_html( ucfirst( $action ) );
}
?>
<?php echo esc_html( dm_format_action_name( $action ) ); ?>
</option>
<?php endforeach; ?>
</select>
@ -79,7 +31,7 @@ if ( ! $logs ) {
<input type="submit" class="button" value="<?php esc_attr_e( 'Filter', 'wp-domain-mapping' ); ?>" />
<?php if ( ! empty( $action_filter ) ) : ?>
<a href="<?php echo esc_url( add_query_arg( array( 'page' => 'domains', 'tab' => 'domain-logs' ), admin_url( 'network/sites.php' ) ) ); ?>" class="button">
<a href="<?php echo esc_url( add_query_arg( array( 'page' => 'domains' ), admin_url( 'network/sites.php' ) ) ); ?>" class="button">
<?php esc_html_e( 'Clear', 'wp-domain-mapping' ); ?>
</a>
<?php endif; ?>
@ -136,19 +88,8 @@ if ( ! $logs ) {
: sprintf( esc_html__( 'User #%d', 'wp-domain-mapping' ), $log->user_id );
// Format action for display
switch ( $log->action ) {
case 'add':
$action_display = '<span class="log-action log-action-add">' . esc_html__( 'Added', 'wp-domain-mapping' ) . '</span>';
break;
case 'edit':
$action_display = '<span class="log-action log-action-edit">' . esc_html__( 'Updated', 'wp-domain-mapping' ) . '</span>';
break;
case 'delete':
$action_display = '<span class="log-action log-action-delete">' . esc_html__( 'Deleted', 'wp-domain-mapping' ) . '</span>';
break;
default:
$action_display = '<span class="log-action">' . esc_html( ucfirst( $log->action ) ) . '</span>';
}
$action_display = dm_format_action_name( $log->action );
$action_class = 'log-action-' . $log->action;
// Get site name
$site_name = get_blog_option( $log->blog_id, 'blogname', '' );
@ -166,7 +107,11 @@ if ( ! $logs ) {
?>
<tr>
<td class="column-user"><?php echo $username; ?></td>
<td class="column-action"><?php echo $action_display; ?></td>
<td class="column-action">
<span class="log-action <?php echo esc_attr( $action_class ); ?>">
<?php echo esc_html( $action_display ); ?>
</span>
</td>
<td class="column-domain">
<a href="<?php echo esc_url( dm_ensure_protocol( $log->domain ) ); ?>" target="_blank">
<?php echo esc_html( $log->domain ); ?>
@ -216,73 +161,3 @@ if ( ! $logs ) {
</div>
</div>
<?php endif; ?>
<style>
/* Logs table styles */
.logs-filter {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.logs-table .column-user,
.logs-table .column-site {
width: 15%;
}
.logs-table .column-action {
width: 10%;
}
.logs-table .column-date {
width: 15%;
}
.log-action {
display: inline-block;
padding: 2px 8px;
border-radius: 3px;
font-size: 12px;
font-weight: bold;
}
.log-action-add {
background-color: #dff0d8;
color: #3c763d;
}
.log-action-edit {
background-color: #d9edf7;
color: #31708f;
}
.log-action-delete {
background-color: #f2dede;
color: #a94442;
}
/* Pagination */
.tablenav-pages a,
.tablenav-pages span.current {
display: inline-block;
min-width: 17px;
padding: 3px 5px 7px;
background: #f0f0f1;
font-size: 16px;
line-height: 1;
font-weight: 400;
text-align: center;
text-decoration: none;
}
.tablenav-pages span.current {
background: #007cba;
color: #fff;
border-color: #007cba;
}
.displaying-num {
margin-left: 10px;
color: #555;
}
</style>