settings_repository = $settings_repository; $this->integration_status_provider = $integration_status_provider; $this->event_summary_provider = $event_summary_provider; $this->recent_events_provider = $recent_events_provider; } /** * Get dashboard data. * * @return array */ public function get_data(): array { $settings = $this->settings_repository->get_settings(); $integrations = $this->integration_status_provider->get_statuses(); return array( 'protection_status' => $this->get_protection_status( (string) $settings['protection_mode'] ), 'strictness' => $this->get_strictness_label( (string) $settings['strictness'] ), 'integrations' => $integrations, 'summary' => $this->get_integration_summary( $integrations ), 'event_summary' => $this->get_event_summary(), 'recent_events' => $this->get_recent_events( 5 ), 'activity_events' => $this->get_recent_events( 20 ), 'privacy_note' => __( '2o2code Spamless Forms processes checks locally and does not send submissions to an external anti-spam service.', '2o2code-spamless-forms' ), 'event_privacy_note' => __( 'Event logging stores minimal metadata only. Full submissions, raw IP addresses, raw emails, and raw user agents are not stored.', '2o2code-spamless-forms' ), 'next_steps' => array( 'review_settings', 'test_a_form', 'check_diagnostics', ), ); } /** * Get protection status display data. * * @param string $mode Protection mode. * * @return array{key:string,label:string,headline:string,description:string} */ private function get_protection_status( string $mode ): array { if ( SettingsSnapshot::MODE_DISABLED === $mode ) { return array( 'key' => 'disabled', 'label' => __( 'Disabled', '2o2code-spamless-forms' ), 'headline' => __( 'Protection is disabled.', '2o2code-spamless-forms' ), 'description' => __( 'Submissions are allowed and no new Activity events are created.', '2o2code-spamless-forms' ), ); } if ( SettingsSnapshot::MODE_MONITOR === $mode ) { return array( 'key' => 'monitor', 'label' => __( 'Monitor', '2o2code-spamless-forms' ), 'headline' => __( 'Monitor mode is on.', '2o2code-spamless-forms' ), 'description' => __( 'Submissions are not blocked. Spam-related decisions can appear in Activity when event logging is enabled.', '2o2code-spamless-forms' ), ); } return array( 'key' => 'protect', 'label' => __( 'Protect', '2o2code-spamless-forms' ), 'headline' => __( 'Protection is active.', '2o2code-spamless-forms' ), 'description' => __( '2o2code Spamless Forms is protecting enabled integrations with local checks.', '2o2code-spamless-forms' ), ); } /** * Get strictness label. * * @param string $strictness Strictness setting. */ private function get_strictness_label( string $strictness ): string { if ( SettingsSnapshot::STRICTNESS_SAFE === $strictness ) { return __( 'Safe', '2o2code-spamless-forms' ); } if ( SettingsSnapshot::STRICTNESS_STRICT === $strictness ) { return __( 'Strict', '2o2code-spamless-forms' ); } return __( 'Balanced', '2o2code-spamless-forms' ); } /** * Summarize integration status from real settings and availability only. * * @param array> $integrations Integration rows. * * @return array{total:int,available:int,enabled:int} */ private function get_integration_summary( array $integrations ): array { $available = 0; $enabled = 0; foreach ( $integrations as $integration ) { if ( ! empty( $integration['available'] ) ) { ++$available; } if ( ! empty( $integration['enabled'] ) ) { ++$enabled; } } return array( 'total' => count( $integrations ), 'available' => $available, 'enabled' => $enabled, ); } /** * Get real event summary counts. * * @return array{allowed:int,blocked:int,suspicious:int,total:int} */ private function get_event_summary(): array { if ( ! $this->event_summary_provider instanceof EventSummaryProvider ) { return array( 'allowed' => 0, 'blocked' => 0, 'suspicious' => 0, 'total' => 0, ); } return $this->event_summary_provider->get_summary(); } /** * Get recent safe event rows. * * @param int $limit Limit. * * @return array> */ private function get_recent_events( int $limit ): array { if ( ! $this->recent_events_provider instanceof RecentEventsProvider ) { return array(); } return $this->recent_events_provider->get_recent_events( $limit ); } }