$this->render_image( $ad, $ad_space ), 'video' => $this->render_video( $ad, $ad_space ), 'script' => $this->render_html( $ad ), default => '', }; if ( '' === $inner ) { return ''; } // Slider subsequent loads — return raw inner content only, no wrapper if ( $inner_only ) { return $inner; } return match ( $ad_space->ad_format ?? 'banner' ) { 'slider' => $this->wrap_slider( $inner, $ad, $ad_space ), default => $this->wrap_banner( $inner, $ad, $ad_space ), }; } // ------------------------------------------------------------------------- // Format Wrappers — layout determined by ad_space->ad_format // ------------------------------------------------------------------------- // FILE: /d/localserver/ad-fuz/wordpress/wp-content/plugins/ad-fuz/src/Controllers/AdRendererController.php private function wrap_banner( string $inner, array $ad, object $ad_space ): string { $default_html = sprintf( '
%s
', esc_attr( $ad['ad_type'] ), (int) $ad['id'], (int) $ad_space->id, (int) ( $ad['campaign_id'] ?? 0 ), $inner ); $wrapper_html = apply_filters( 'adfuz/ad_renderer/wrap_banner_html', $default_html, $inner, $ad, $ad_space ); return $wrapper_html; } private function wrap_slider2( string $inner, array $ad, object $ad_space ): string { $show_arrows = (bool) ( $ad_space->slider_show_arrows ?? true ); $show_dots = (bool) ( $ad_space->slider_show_dots ?? true ); $prev_arrow = $show_arrows ? '' : ''; $next_arrow = $show_arrows ? '' : ''; $dots = $show_dots ? '
' : ''; $slider_id = 'adfuz-slider-' . wp_generate_uuid4(); $test = sprintf( '
%s
%s
%s %s
', esc_attr( $ad['ad_type'] ), (int) $ad['id'], (int) $ad_space->id, esc_attr( $slider_id ), esc_attr( $ad_space->slider_mode ?? 'manual' ), (int) ( $ad_space->slider_interval ?? 30 ), (int) ( $ad_space->slider_total ?? 1 ), $prev_arrow, $inner, $next_arrow, $dots ); Common::log_file( array( '$test' => $test ) ); return $test; } private function wrap_slider( string $inner, array $ad, object $adspace ): string { Common::log_file( array( '$inner' => $inner ) ); $show_arrows = (bool) ( $adspace->slider_show_arrows ?? true ); $show_dots = (bool) ( $adspace->slider_show_dots ?? true ); $prev_arrow = $show_arrows ? '' : ''; $next_arrow = $show_arrows ? '' : ''; $dots = $show_dots ? '
' : ''; $slider_id = 'adfuz-slider-' . wp_generate_uuid4(); $test = sprintf( '
%s
%s
%s %s
', /* 1 data-adfuz-ad-type */ esc_attr( $ad['ad_type'] ), /* 2 data-adfuz-ad-id */ (int) $ad['id'], /* 3 data-adfuz-space-id */ (int) $adspace->id, /* 4 data-adfuz-campaign-id */ (int) ( $ad['campaign_id'] ?? 0 ), /* 5 data-adfuz-slider-id */ esc_attr( $slider_id ), /* 6 data-adfuz-slider-mode */ esc_attr( $adspace->slider_mode ?? 'manual' ), /* 7 data-adfuz-slider-interval*/ (int) ( $adspace->slider_interval ?? 30 ), /* 8 data-adfuz-slider-total */ (int) ( $adspace->slider_total ?? 1 ), /* 9 prev_arrow */ $prev_arrow, /* 10 inner */ $inner, /* 11 next_arrow */ $next_arrow, /* 12 dots */ $dots ); return $test; } private function render_image( array $ad, object $ad_space ): string { if ( empty( $ad['media_url'] ) ) { return ''; } $html = ''; // Image $html .= sprintf( '
%s
', esc_url( $ad['media_url'] ), esc_attr( $ad['hide_title'] ? '' : $ad['title'] ), absint( $ad_space->width ), absint( $ad_space->height ) ); // Title $html .= $this->render_title( $ad ); // Description $html .= $this->render_description( $ad ); // CTA Link $html .= $this->render_cta( $ad ); return $this->wrap_with_link( $html, $ad ); } // ------------------------------------------------------------------------- // Video Ad // Layout: Video → Title → Description → CTA Link // ------------------------------------------------------------------------- private function render_video( array $ad, object $ad_space ): string { if ( empty( $ad['media_url'] ) ) { return ''; } $width = absint( $ad_space->width ); $height = absint( $ad_space->height ); $html = ''; // Video (embed or self-hosted) if ( $this->is_embed_url( $ad['media_url'] ) ) { $html .= sprintf( '
', esc_url( $this->normalize_embed_url( $ad['media_url'] ) ), $width, $height ); } else { $html .= sprintf( '
', $width, $height, esc_url( $ad['media_url'] ), esc_attr( $this->get_video_mime( $ad['media_url'] ) ) ); } // Title $html .= $this->render_title( $ad ); // Description $html .= $this->render_description( $ad ); // CTA Link $html .= $this->render_cta( $ad ); return $this->wrap_with_link( $html, $ad ); } // ------------------------------------------------------------------------- // HTML / Script Ad // Layout: script_html → Title // No description, no CTA, no link wrap (script handles its own links) // ------------------------------------------------------------------------- private function render_html( array $ad ): string { if ( empty( $ad['script_html'] ) ) { return ''; } $html = ''; $html .= sprintf( '
%s
', wp_kses( $ad['script_html'], Common::script_ad_allowed_html() ) ); $html .= $this->render_title( $ad ); return $html; } // ------------------------------------------------------------------------- // Shared partials // ------------------------------------------------------------------------- /** * Renders the title — shared across all ad types. * Returns empty string if hide_title is truthy. */ private function render_title( array $ad ): string { if ( ! empty( $ad['hide_title'] ) ) { return ''; } if ( empty( $ad['title'] ) ) { return ''; } return sprintf( '

%s

', esc_html( $ad['title'] ) ); } /** * Renders description — for Image and Video only. */ private function render_description( array $ad ): string { if ( empty( $ad['description'] ) ) { return ''; } return sprintf( '

%s

', esc_html( $ad['description'] ) ); } /** * Renders the CTA button/link — for Image and Video only. * Uses cta as link text and target_url as href. */ private function render_cta( array $ad ): string { if ( empty( $ad['cta'] ) || empty( $ad['target_url'] ) ) { return ''; } $pos_class = 'adfuz-cta-' . esc_attr( $ad['cta_position'] ?? 'left' ); return sprintf( '
%s
', $pos_class, esc_url( $ad['target_url'] ), (int) $ad['id'], esc_html( $ad['cta'] ) ); } /** * Wraps the entire ad content in a clickable if target_url is set * AND no CTA is present (avoids nested tags). * If CTA is present, the CTA itself carries the link — no outer wrap needed. */ private function wrap_with_link( string $html, array $ad ): string { if ( empty( $ad['target_url'] ) || ! empty( $ad['cta'] ) ) { return $html; } return sprintf( '%s', esc_url( $ad['target_url'] ), (int) $ad['id'], $html ); } // ------------------------------------------------------------------------- // Video helpers // ------------------------------------------------------------------------- private function is_embed_url( string $url ): bool { return (bool) preg_match( '#(youtube\.com|youtu\.be|vimeo\.com)#i', $url ); } private function normalize_embed_url( string $url ): string { if ( preg_match( '#youtube\.com/watch\?v=([\w\-]+)#i', $url, $m ) ) { return 'https://www.youtube.com/embed/' . $m[1] . '?autoplay=1&mute=1&loop=1&playlist=' . $m[1]; } if ( preg_match( '#youtu\.be/([\w\-]+)#i', $url, $m ) ) { return 'https://www.youtube.com/embed/' . $m[1] . '?autoplay=1&mute=1&loop=1&playlist=' . $m[1]; } if ( preg_match( '#vimeo\.com/(\d+)#i', $url, $m ) ) { return 'https://player.vimeo.com/video/' . $m[1] . '?autoplay=1&muted=1&loop=1'; } return $url; } private function get_video_mime( string $url ): string { $ext = strtolower( pathinfo( wp_parse_url( $url, PHP_URL_PATH ), PATHINFO_EXTENSION ) ); return match ( $ext ) { 'webm' => 'video/webm', 'ogg' => 'video/ogg', 'mov' => 'video/quicktime', default => 'video/mp4', }; } }