Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 45 additions & 33 deletions src/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,6 @@ public function menu(): void {
[ $this, 'render_entities' ]
);

$this->hooks[] = add_submenu_page(
self::SLUG,
__( 'Activity', 'aggregate-it' ),
__( 'Activity', 'aggregate-it' ),
'manage_options',
self::SLUG . '-activity',
[ $this, 'render_activity' ]
);

$this->hooks[] = add_submenu_page(
self::SLUG,
__( 'Settings', 'aggregate-it' ),
Expand Down Expand Up @@ -176,17 +167,59 @@ public function assets( string $hook ): void {
}

public function render_dashboard(): void {
$s = $this->plugin->settings();
$tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'overview'; // phpcs:ignore WordPress.Security.NonceVerification
$tabs = [
'overview' => __( 'Overview', 'aggregate-it' ),
'activity' => __( 'Activity', 'aggregate-it' ),
];
if ( ! isset( $tabs[ $tab ] ) ) {
$tab = 'overview';
}

$setup = [
$s = $this->plugin->settings();
$setup = [
'provider' => $s->provider_key() !== 'mock' && $s->api_key() !== '',
'feeds' => (bool) $this->plugin->sources()->all(),
'types' => (bool) $this->plugin->rules()->post_types(),
];
$show_setup = ! get_option( 'aggregate_it_setup_dismissed' ) && ( ! $setup['provider'] || ! $setup['feeds'] );
$can_seed = $this->plugin->seed_enabled();

require AGGREGATE_IT_PATH . 'src/Admin/views/dashboard.php';
if ( $tab === 'activity' ) {
// phpcs:disable WordPress.Security.NonceVerification
$per_page = 50;
$page = max( 1, (int) ( $_GET['paged'] ?? 1 ) );
$filters = [
'level' => isset( $_GET['level'] ) ? sanitize_key( wp_unslash( $_GET['level'] ) ) : '',
'type' => isset( $_GET['type'] ) ? sanitize_key( wp_unslash( $_GET['type'] ) ) : '',
'item_id' => (int) ( $_GET['item'] ?? 0 ),
'search' => isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '',
];
// phpcs:enable WordPress.Security.NonceVerification
$total = ActivityLog::count( $filters );
$rows = ActivityLog::query( $filters, $per_page, ( $page - 1 ) * $per_page );
$pages = (int) max( 1, ceil( $total / $per_page ) );
$levels = [ 'info', 'warning', 'error' ];
$types = array_merge( Pipeline::default_order(), [ Schema::STATE_DEAD_LETTER ] );
}

echo '<div class="wrap aggregate-it">';
echo '<div class="ai-head"><h1>' . esc_html__( 'Aggregate It', 'aggregate-it' ) . '</h1></div>';
echo '<nav class="nav-tab-wrapper ai-tabs">';
foreach ( $tabs as $key => $label ) {
printf(
'<a href="%s" class="nav-tab%s">%s</a>',
esc_url( admin_url( 'admin.php?page=' . self::SLUG . ( $key === 'overview' ? '' : '&tab=' . $key ) ) ),
$tab === $key ? ' nav-tab-active' : '',
esc_html( $label )
);
}
echo '</nav>';

$tab_embedded = true;
require AGGREGATE_IT_PATH . 'src/Admin/views/' . ( $tab === 'activity' ? 'activity.php' : 'dashboard.php' );

echo '</div>';
}

public function handle_dismiss_setup(): void {
Expand Down Expand Up @@ -904,27 +937,6 @@ public function handle_save_settings(): void {
$this->redirect( self::SLUG . '-settings', 'saved' );
}

public function render_activity(): void {
// phpcs:disable WordPress.Security.NonceVerification
$per_page = 50;
$page = max( 1, (int) ( $_GET['paged'] ?? 1 ) );
$filters = [
'level' => isset( $_GET['level'] ) ? sanitize_key( wp_unslash( $_GET['level'] ) ) : '',
'type' => isset( $_GET['type'] ) ? sanitize_key( wp_unslash( $_GET['type'] ) ) : '',
'item_id' => (int) ( $_GET['item'] ?? 0 ),
'search' => isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '',
];
// phpcs:enable WordPress.Security.NonceVerification

$total = ActivityLog::count( $filters );
$rows = ActivityLog::query( $filters, $per_page, ( $page - 1 ) * $per_page );
$pages = (int) max( 1, ceil( $total / $per_page ) );
$levels = [ 'info', 'warning', 'error' ];
$types = array_merge( Pipeline::default_order(), [ Schema::STATE_DEAD_LETTER ] );

require AGGREGATE_IT_PATH . 'src/Admin/views/activity.php';
}

public function handle_bulk_add_sources(): void {
$this->guard( 'aggregate_it_bulk_add_sources' );

Expand Down
14 changes: 5 additions & 9 deletions src/Admin/views/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@

defined( 'ABSPATH' ) || exit;

$base = admin_url( 'admin.php?page=aggregate-it-activity' );
$base = admin_url( 'admin.php?page=aggregate-it&tab=activity' );

$label_for = static function ( string $state ): string {
return $state === '' ? '' : ucwords( str_replace( '_', ' ', $state ) );
};
?>
<div class="wrap aggregate-it">
<div class="ai-head">
<h1><?php esc_html_e( 'Activity', 'aggregate-it' ); ?></h1>
</div>

<form method="get" class="ai-act-filters">
<input type="hidden" name="page" value="aggregate-it-activity">
<input type="hidden" name="page" value="aggregate-it">
<input type="hidden" name="tab" value="activity">
<?php if ( $filters['item_id'] ) : ?>
<input type="hidden" name="item" value="<?php echo esc_attr( (string) $filters['item_id'] ); ?>">
<?php endif; ?>
Expand Down Expand Up @@ -98,7 +94,8 @@
<?php
$qs = array_filter(
[
'page' => 'aggregate-it-activity',
'page' => 'aggregate-it',
'tab' => 'activity',
'level' => $filters['level'],
'type' => $filters['type'],
'item' => $filters['item_id'] ?: '',
Expand All @@ -116,7 +113,6 @@
<?php if ( $page < $pages ) : ?><a class="button" href="<?php echo $page_url( $page + 1 ); ?>"><?php esc_html_e( 'Older', 'aggregate-it' ); ?> ›</a><?php endif; ?>
</p>
<?php endif; ?>
</div>

<script>
window.addEventListener( 'load', function () {
Expand Down
7 changes: 2 additions & 5 deletions src/Admin/views/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
* @var bool $show_setup
*/
?>
<div class="wrap aggregate-it" id="aggregate-it-app">
<div id="aggregate-it-app">

<div class="ai-head">
<h1><?php esc_html_e( 'Aggregate It', 'aggregate-it' ); ?></h1>
<div class="ai-actions">
<div class="ai-actions">
<span class="post-state" id="ai-provider-pill"></span>
<span class="post-state ai-hidden" id="ai-paused-pill" role="status">
<?php esc_html_e( 'Daily cost limit reached — paused', 'aggregate-it' ); ?>
Expand All @@ -25,7 +23,6 @@
<button class="button ai-hidden" id="ai-resume" type="button"><?php esc_html_e( 'Resume', 'aggregate-it' ); ?></button>
<button class="button button-primary" id="ai-refresh" type="button"><?php esc_html_e( 'Refresh', 'aggregate-it' ); ?></button>
</div>
</div>

<?php if ( ! empty( $show_setup ) ) : ?>
<div class="postbox ai-setup">
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/views/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}

$post_action = esc_url( admin_url( 'admin-post.php' ) );
$activity_url = admin_url( 'admin.php?page=aggregate-it-activity&type=' . rawurlencode( \AggregateIt\Database\Schema::STATE_ENTITY_LINKED ) );
$activity_url = admin_url( 'admin.php?page=aggregate-it&tab=activity&type=' . rawurlencode( \AggregateIt\Database\Schema::STATE_ENTITY_LINKED ) );

$cards = [
[ 'n' => $summary['hubs'], 'label' => __( 'Topic hubs', 'aggregate-it' ) ],
Expand Down
Loading