change_frequency, $this->get_location(), $this->get_priority(), $this->get_last_modified(), $this->get_images() ); } /** * @param string $change_frequency * * @return $this */ public function set_change_frequency( $change_frequency ) { $this->change_frequency = $change_frequency; return $this; } /** * @return float */ public function get_priority() { return $this->priority; } /** * @param float $priority * * @return $this */ public function set_priority( $priority ) { $this->priority = $priority; return $this; } /** * @return array */ public function get_images() { return $this->images; } /** * @param array $images * * @return $this */ public function set_images( $images ) { $this->images = $images; return $this; } protected function format_priority( $priority ) { return sprintf( '%.1f', $priority ); } private function images_xml() { $images = array(); foreach ( $this->get_images() as $image ) { $images[] = $this->image_xml( $image ); } return join( "\n", $images ); } private function image_xml( $image ) { $text = ! empty( $image['title'] ) ? $image['title'] : (string) smartcrawl_get_array_value( $image, 'alt' ); $src = (string) smartcrawl_get_array_value( $image, 'src' ); $image_tag = ''; $image_tag .= '' . esc_url( $src ) . ''; $image_tag .= '' . ent2ncr( esc_attr( $text ) ) . ''; $image_tag .= ""; return $image_tag; } public function to_xml() { $tags = array(); $location = $this->get_location(); if ( empty( $location ) ) { Smartcrawl_Logger::error( 'Sitemap item with empty location found' ); return ''; } $tags[] = sprintf( '%s', esc_url( $location ) ); // Last modified date $tags[] = sprintf( '%s', $this->format_timestamp( $this->get_last_modified() ) ); // Change frequency $change_frequency = $this->get_change_frequency(); if ( ! empty( $change_frequency ) ) { $tags[] = sprintf( '%s', strtolower( $change_frequency ) ); } // Priority $priority = $this->get_priority(); if ( ! empty( $priority ) ) { $tags[] = sprintf( '%s', $this->format_priority( $priority ) ); } // Images $images = $this->images_xml(); if ( ! empty( $images ) ) { $tags[] = $images; } return sprintf( "\n%s\n", implode( "\n", $tags ) ); } }