args_width( $args ), $this->args_height( $args ) ); return '' !== $html ? $html : $result; } /** * Ensure oEmbed HTML is always our local iframe (REST proxy path). * * @param string|false $html Remote/derived HTML. * @param string $url Source URL. * @param string|array $args Args. * @return string|false */ public function filter_oembed_result( $html, $url, $args ) { if ( ! Dadan_Url::is_dadan_url( $url ) ) { return $html; } $local = Dadan_Fallback::render_from_url( $url, $this->args_width( $args ), $this->args_height( $args ) ); return '' !== $local ? $local : $html; } /** * @param string|array $args oEmbed args. * @return int */ private function args_width( $args ) { if ( is_array( $args ) ) { if ( ! empty( $args['width'] ) ) { return absint( $args['width'] ); } if ( ! empty( $args['maxwidth'] ) ) { return absint( $args['maxwidth'] ); } } return 640; } /** * @param string|array $args oEmbed args. * @return int */ private function args_height( $args ) { unset( $args ); // DADAN-18: WP fills height/maxheight with 1.5×width for auto-embeds. // Pass 0 so Dadan_Fallback uses 16:9. return 0; } /** * Replace remote oEmbed HTML with a locally built iframe when the URL is Dadan. * * @param string $result The oEmbed HTML result. * @param object $data A data object result from the oEmbed provider. * @param string $url The URL passed to the oEmbed provider. * @return string */ public function filter_oembed_dataparse( $result, $data, $url ) { if ( ! Dadan_Url::is_dadan_url( $url ) ) { return $result; } $width = 640; $height = 360; $title = ''; if ( is_object( $data ) ) { if ( isset( $data->width ) && is_numeric( $data->width ) ) { $width = (int) $data->width; } if ( isset( $data->height ) && is_numeric( $data->height ) ) { $height = (int) $data->height; } if ( ! empty( $data->title ) && is_string( $data->title ) ) { $title = $data->title; } } $html = Dadan_Fallback::render_from_url( $url, $width, $height, $title ); return '' !== $html ? $html : $result; } /** * Last-resort sanitize of cached/embed HTML for Dadan URLs. * * @param string|false $cached_html The cached HTML result, stored in post meta. * @param string $url The attempted embed URL. * @param array $attr An array of shortcode attributes. * @param int $post_id Post ID. * @return string|false */ public function filter_embed_oembed_html( $cached_html, $url, $attr, $post_id ) { unset( $post_id ); if ( ! Dadan_Url::is_dadan_url( $url ) ) { return $cached_html; } $width = isset( $attr['width'] ) ? absint( $attr['width'] ) : 640; // DADAN-18: $attr height is WP's portrait default — ignore; use 16:9. $height = 0; $html = Dadan_Fallback::render_from_url( $url, $width, $height ); if ( '' !== $html ) { return $html; } return $cached_html; } /** * When remote oEmbed fails, WP falls back to a link — replace with local iframe. * * @param string $output Default link HTML. * @param string $url Attempted embed URL. * @return string */ public function filter_embed_maybe_make_link( $output, $url ) { if ( ! Dadan_Url::is_dadan_url( $url ) ) { return $output; } $html = Dadan_Fallback::render_from_url( $url ); return '' !== $html ? $html : $output; } }