render_header( $post_id ); // Player container. $html .= '
'; // Player components. $html .= $this->render_play_button( $post_id ); $html .= $this->render_timeline( $post_id ); $html .= $this->render_time_display(); $html .= $this->render_volume_controls( $post_id ); $html .= $this->render_branding(); $html .= $this->render_audio_element( $post_id, $audio_url ); $html .= '
'; // Close container. return $html; } /** * Renders player header with branding and statistics * * @param int|null $post_id Post ID for statistics. * @return string Header HTML. */ public function render_header( ?int $post_id = null ): string { // Check if branding should be hidden (WordPress compliance). $hide_branding = get_option( 'accessibility_audio_tts_hide_branding', false ); if ( $hide_branding ) { return ''; } $html = '
'; // Get listening statistics. $listening_count = $this->get_listening_count( $post_id ); // Build header text with listening count. $header_text = $this->build_header_text( $listening_count ); // Show link to plugin page when branding is enabled. $html .= '' . esc_html( $header_text ) . ''; $html .= '
'; return $html; } /** * Renders play/pause button * * @param int $post_id Post ID for unique element IDs. * @return string Play button HTML. */ public function render_play_button( int $post_id ): string { return sprintf( '', esc_attr__( 'Play', 'accessibility-audio-tts-text-to-speech-for-articles' ), $post_id, $this->get_play_icon_svg(), esc_html__( 'Play', 'accessibility-audio-tts-text-to-speech-for-articles' ) ); } /** * Renders timeline/progress bar * * @param int $post_id Post ID for unique element IDs. * @return string Timeline HTML. */ public function render_timeline( int $post_id ): string { return sprintf( '
', esc_attr__( 'Playback progress bar', 'accessibility-audio-tts-text-to-speech-for-articles' ), $post_id ); } /** * Renders time display * * @return string Time display HTML. */ public function render_time_display(): string { return '
0:00 / 0:00
'; } /** * Renders volume controls * * @param int $post_id Post ID for unique element IDs. * @return string Volume controls HTML. */ public function render_volume_controls( int $post_id ): string { return sprintf( '
', esc_attr__( 'Mute', 'accessibility-audio-tts-text-to-speech-for-articles' ), $post_id, $this->get_volume_icon_svg(), esc_html__( 'Mute', 'accessibility-audio-tts-text-to-speech-for-articles' ), esc_attr__( 'Volume control', 'accessibility-audio-tts-text-to-speech-for-articles' ), $post_id ); } /** * Renders branding section * * @return string Branding HTML. */ public function render_branding(): string { $site_icon = get_site_icon_url( 64 ); if ( empty( $site_icon ) ) { return ''; } return sprintf( '
', esc_url( $site_icon ), esc_attr( get_bloginfo( 'name' ) ) ); } /** * Renders audio element * * @param int $post_id Post ID for unique element IDs. * @param string $audio_url URL to the audio file. * @return string Audio element HTML. */ public function render_audio_element( int $post_id, string $audio_url ): string { $lazy = 'anonymous' === \Accessibility_Audio_TTS\Core\Privacy_Settings::get( 'analytics_mode' ); if ( $lazy ) { $audio_url = \Accessibility_Audio_TTS\Core\Audio_Access::url( $post_id ); } return sprintf( '', $lazy ? 'none' : 'metadata', $lazy ? '1' : '0', $post_id, $post_id, $post_id, esc_url( $audio_url ), esc_html__( 'Your browser does not support the audio player.', 'accessibility-audio-tts-text-to-speech-for-articles' ) ); } /** * Gets listening count for a post * * @param int|null $post_id Post ID. * @return int Listening count. */ private function get_listening_count( ?int $post_id ): int { if ( ! $post_id || 'consented' !== \Accessibility_Audio_TTS\Core\Privacy_Settings::get( 'analytics_mode' ) ) { return 0; } // Check if Listening_Statistics class exists. if ( ! class_exists( 'Accessibility_Audio_TTS\Admin\Listening_Statistics' ) ) { return 0; } try { $listening_stats = new Listening_Statistics(); $stats = $listening_stats->get_post_listening_stats( $post_id ); return $stats['total_listens'] ?? 0; } catch ( \Throwable $e ) { // Log error and return 0 if statistics cannot be retrieved. if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { accessibility_audio_tts_debug_log( 'AAT: Error getting listening statistics: ' . $e->getMessage() ); } return 0; } } /** * Builds header text with listening count * * @param int $listening_count Number of listens. * @return string Header text. */ private function build_header_text( int $listening_count ): string { $header_text = __( 'Audio Player', 'accessibility-audio-tts-text-to-speech-for-articles' ); if ( $listening_count > 0 ) { /* translators: %d is the number of listens over 5 seconds */ $listens_text = sprintf( /* translators: auto */ _n( '%d listen', '%d listens', $listening_count, 'accessibility-audio-tts-text-to-speech-for-articles' ), number_format( $listening_count ) ); $header_text .= ' | ' . $listens_text; } return $header_text; } /** * Gets play icon SVG * * @return string SVG markup. */ private function get_play_icon_svg(): string { return ''; } /** * Gets volume icon SVG * * @return string SVG markup. */ private function get_volume_icon_svg(): string { return ''; } }