v1.8.1
This commit is contained in:
parent
7b7fff5246
commit
b6a55a7f04
27 changed files with 2221 additions and 45 deletions
102
includes/Network/AuditPage.php
Normal file
102
includes/Network/AuditPage.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/**
|
||||
* Network admin aggregated Audit page.
|
||||
*
|
||||
* @package MediaRightsAudit\Network
|
||||
*/
|
||||
|
||||
namespace MediaRightsAudit\Network;
|
||||
|
||||
use MediaRightsAudit\Core\NetworkDatabase;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the aggregated media audit list for the network admin.
|
||||
*
|
||||
* Queries the network mirror table to show all media across all sites with
|
||||
* a "Site" column identifying the origin of each attachment.
|
||||
*/
|
||||
class AuditPage {
|
||||
|
||||
/**
|
||||
* Renders the network Audit page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render(): void {
|
||||
if ( ! current_user_can( 'manage_network_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to access this page.', 'robotstxt-mediaaudit' ) );
|
||||
}
|
||||
|
||||
$table = new NetworkListTable( false );
|
||||
$table->prepare_items();
|
||||
|
||||
$stats = $this->get_network_stats();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php esc_html_e( 'Network Media Audit', 'robotstxt-mediaaudit' ); ?></h1>
|
||||
|
||||
<div class="mra-stats">
|
||||
<?php
|
||||
$this->stat_box( $stats['total_indexed'], __( 'Total Indexed', 'robotstxt-mediaaudit' ), '' );
|
||||
$this->stat_box( $stats['total_matches'], __( 'External Matches', 'robotstxt-mediaaudit' ), '' );
|
||||
$this->stat_box( $stats['total_alert'], __( 'Active Alerts', 'robotstxt-mediaaudit' ), '' );
|
||||
$this->stat_box( $stats['total_sites'], __( 'Sites', 'robotstxt-mediaaudit' ), '' );
|
||||
?>
|
||||
</div>
|
||||
|
||||
<form method="get">
|
||||
<input type="hidden" name="page" value="robotstxt-mediaaudit-network" />
|
||||
<?php $table->display(); ?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a single stat box.
|
||||
*
|
||||
* @param int $value Numeric value.
|
||||
* @param string $label Short label.
|
||||
* @param string $sub Optional sub-label.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function stat_box( int $value, string $label, string $sub ): void {
|
||||
echo '<div class="mra-stat-box">';
|
||||
echo '<strong>' . esc_html( number_format_i18n( $value ) ) . '</strong>';
|
||||
echo '<span>' . esc_html( $label ) . '</span>';
|
||||
if ( '' !== $sub ) {
|
||||
echo '<small>' . esc_html( $sub ) . '</small>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns aggregate stats from the network mirror table.
|
||||
*
|
||||
* @return array{total_indexed: int, total_matches: int, total_alert: int, total_sites: int}
|
||||
*/
|
||||
private function get_network_stats(): array {
|
||||
global $wpdb;
|
||||
|
||||
$table = NetworkDatabase::table_name();
|
||||
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$total_indexed = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" );
|
||||
$total_matches = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}` WHERE external_status = 'matches'" );
|
||||
$total_alert = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}` WHERE has_alert = 1 AND is_dismissed = 0" );
|
||||
$total_sites = (int) $wpdb->get_var( "SELECT COUNT(DISTINCT site_id) FROM `{$table}`" );
|
||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
|
||||
return array(
|
||||
'total_indexed' => $total_indexed,
|
||||
'total_matches' => $total_matches,
|
||||
'total_alert' => $total_alert,
|
||||
'total_sites' => $total_sites,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue