Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Build the `<url>` tag for a given URL.
- *
- * @param array $url Array of parts that make up this entry.
- * @param Renderer $renderer Sitemap renderer class object.
- * @return string
- */
- public function sitemap_url( $url, $renderer ) {
- $output = $renderer->newline( '<url>', 1 );
- $output .= $renderer->newline( '<loc>' . $renderer->encode_url_rfc3986( htmlspecialchars( $url['loc'] ) ) . '</loc>', 2 );
- if ( ! empty( $url['videos'] ) ) {
- foreach ( $url['videos'] as $video ) {
- $date = null;
- if ( ! empty( $video['publication_date'] ) ) {
- // Create a DateTime object date in the correct timezone.
- $date = $renderer->timezone->format_date( $video['publication_date'] );
- }
- $output .= $renderer->newline( '<video:video>', 2 );
- $output .= $renderer->add_cdata( $video['title'], 'video:title', 3 );
- $output .= empty( $date ) ? '' : $renderer->newline( '<video:publication_date>' . htmlspecialchars( $date ) . '</video:publication_date>', 3 );
- $output .= $renderer->add_cdata( $video['description'], 'video:description', 3 );
- if ( ! empty( $video['player_loc'] ) ) {
- $output .= $renderer->newline( '<video:player_loc>' . esc_url( $video['player_loc'] ) . '</video:player_loc>', 3 );
- }
- foreach ( [ 'thumbnail_loc', 'content_loc' ] as $prop ) {
- if ( empty( $video[ $prop ] ) ) {
- continue;
- }
- /**
- * Filter the video content and thumbnail location:
- * - rank_math/sitemap/video/thumbnail_loc
- * - rank_math/sitemap/video/content_loc
- */
- $value = $this->do_filter( "sitemap/video/{$prop}", $video[ $prop ] );
- $output .= $renderer->newline( "<video:{$prop}>" . esc_url( $value ) . "</video:{$prop}>", 3 );
- }
- if ( ! empty( $video['tags'] ) ) {
- $tags = explode( ', ', $video['tags'] );
- foreach ( $tags as $tag ) {
- $output .= $renderer->add_cdata( $tag, 'video:tag', 3 );
- }
- }
- $output .= $renderer->add_cdata( $video['modification_date'], 'video:modification_date', 3 );
- if ( ! empty( $video['rating'] ) ) {
- $output .= $renderer->newline( '<video:rating>' . absint( $video['rating'] ) . '</video:rating>', 3 );
- }
- if ( ! empty( $video['duration'] ) ) {
- $output .= $renderer->newline( '<video:duration>' . esc_html( $video['duration'] ) . '</video:duration>', 3 );
- }
- $output .= $renderer->newline( '<video:family_friendly>' . $video['family_friendly'] . '</video:family_friendly>', 3 );
- $output .= $renderer->newline( '<video:uploader info="' . get_author_posts_url( $url['author'] ) . '">' . ent2ncr( esc_html( get_the_author_meta( 'display_name', $url['author'] ) ) ) . '</video:uploader>', 3 );
- $output .= $renderer->newline( '</video:video>', 2 );
- }
- }
- $output .= $renderer->newline( '</url>', 1 );
- /**
- * Filters the output for the sitemap url tag.
- *
- * @param string $output The output for the sitemap url tag.
- * @param array $url The sitemap url array on which the output is based.
- */
- return $this->do_filter( 'sitemap_url', $output, $url );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement